mmu.h (986c6f7c3fc855032f3457a5a1b7fbcc09c375bb) | mmu.h (d6174299365ddbbf491620c0b8c5ca1a6ef2eea5) |
---|---|
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __KVM_X86_MMU_H 3#define __KVM_X86_MMU_H 4 5#include <linux/kvm_host.h> 6#include "kvm_cache_regs.h" 7#include "cpuid.h" 8 --- 34 unchanged lines hidden (view full) --- 43#define PT64_ROOT_4LEVEL 4 44#define PT32_ROOT_LEVEL 2 45#define PT32E_ROOT_LEVEL 3 46 47#define KVM_MMU_CR4_ROLE_BITS (X86_CR4_PSE | X86_CR4_PAE | X86_CR4_LA57 | \ 48 X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE) 49 50#define KVM_MMU_CR0_ROLE_BITS (X86_CR0_PG | X86_CR0_WP) | 1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __KVM_X86_MMU_H 3#define __KVM_X86_MMU_H 4 5#include <linux/kvm_host.h> 6#include "kvm_cache_regs.h" 7#include "cpuid.h" 8 --- 34 unchanged lines hidden (view full) --- 43#define PT64_ROOT_4LEVEL 4 44#define PT32_ROOT_LEVEL 2 45#define PT32E_ROOT_LEVEL 3 46 47#define KVM_MMU_CR4_ROLE_BITS (X86_CR4_PSE | X86_CR4_PAE | X86_CR4_LA57 | \ 48 X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE) 49 50#define KVM_MMU_CR0_ROLE_BITS (X86_CR0_PG | X86_CR0_WP) |
51#define KVM_MMU_EFER_ROLE_BITS (EFER_LME | EFER_NX) |
|
51 52static __always_inline u64 rsvd_bits(int s, int e) 53{ 54 BUILD_BUG_ON(__builtin_constant_p(e) && __builtin_constant_p(s) && e < s); 55 56 if (__builtin_constant_p(e)) 57 BUILD_BUG_ON(e > 63); 58 else --- 139 unchanged lines hidden (view full) --- 198#ifdef CONFIG_RETPOLINE 199 if (fault.is_tdp) 200 return kvm_tdp_page_fault(vcpu, &fault); 201#endif 202 return vcpu->arch.mmu->page_fault(vcpu, &fault); 203} 204 205/* | 52 53static __always_inline u64 rsvd_bits(int s, int e) 54{ 55 BUILD_BUG_ON(__builtin_constant_p(e) && __builtin_constant_p(s) && e < s); 56 57 if (__builtin_constant_p(e)) 58 BUILD_BUG_ON(e > 63); 59 else --- 139 unchanged lines hidden (view full) --- 199#ifdef CONFIG_RETPOLINE 200 if (fault.is_tdp) 201 return kvm_tdp_page_fault(vcpu, &fault); 202#endif 203 return vcpu->arch.mmu->page_fault(vcpu, &fault); 204} 205 206/* |
206 * Currently, we have two sorts of write-protection, a) the first one 207 * write-protects guest page to sync the guest modification, b) another one is 208 * used to sync dirty bitmap when we do KVM_GET_DIRTY_LOG. The differences 209 * between these two sorts are: 210 * 1) the first case clears MMU-writable bit. 211 * 2) the first case requires flushing tlb immediately avoiding corrupting 212 * shadow page table between all vcpus so it should be in the protection of 213 * mmu-lock. And the another case does not need to flush tlb until returning 214 * the dirty bitmap to userspace since it only write-protects the page 215 * logged in the bitmap, that means the page in the dirty bitmap is not 216 * missed, so it can flush tlb out of mmu-lock. 217 * 218 * So, there is the problem: the first case can meet the corrupted tlb caused 219 * by another case which write-protects pages but without flush tlb 220 * immediately. In order to making the first case be aware this problem we let 221 * it flush tlb if we try to write-protect a spte whose MMU-writable bit 222 * is set, it works since another case never touches MMU-writable bit. 223 * 224 * Anyway, whenever a spte is updated (only permission and status bits are 225 * changed) we need to check whether the spte with MMU-writable becomes 226 * readonly, if that happens, we need to flush tlb. Fortunately, 227 * mmu_spte_update() has already handled it perfectly. 228 * 229 * The rules to use MMU-writable and PT_WRITABLE_MASK: 230 * - if we want to see if it has writable tlb entry or if the spte can be 231 * writable on the mmu mapping, check MMU-writable, this is the most 232 * case, otherwise 233 * - if we fix page fault on the spte or do write-protection by dirty logging, 234 * check PT_WRITABLE_MASK. 235 * 236 * TODO: introduce APIs to split these two cases. 237 */ 238static inline bool is_writable_pte(unsigned long pte) 239{ 240 return pte & PT_WRITABLE_MASK; 241} 242 243/* | |
244 * Check if a given access (described through the I/D, W/R and U/S bits of a 245 * page fault error code pfec) causes a permission fault with the given PTE 246 * access rights (in ACC_* format). 247 * 248 * Return zero if the access does not fault; return the page fault error code 249 * if the access faults. 250 */ 251static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, --- 117 unchanged lines hidden --- | 207 * Check if a given access (described through the I/D, W/R and U/S bits of a 208 * page fault error code pfec) causes a permission fault with the given PTE 209 * access rights (in ACC_* format). 210 * 211 * Return zero if the access does not fault; return the page fault error code 212 * if the access faults. 213 */ 214static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, --- 117 unchanged lines hidden --- |