Bits 60 and 61 of TDP SPTEs hold the type of A/D tracking. If bit 7 of the EPTP is set, the CPU uses bit 60 of an EPT leaf as the supervisor shadow-stack permission (SDM Vol. 3C, 31.3.3.2). KVM needs to set that bit in shadow EPT SPTEs to support supervisor shadow-stack control for nested EPT, so it cannot hold software state. Move the A/D tracking type to bits 56 and 57, which are unused since commit be4e45f360a2 ("KVM: x86/mmu: shuffle high bits of SPTEs in preparation for MBEC"). The CPU ignores bit 56. Bit 57 is "verify guest paging" only if the guest-paging verification VM-execution control is set, which KVM never does; bit 61 was in the same situation with the sub-page write permission control. The existing static asserts against the host-writable, MMU-writable and access-tracking bits still hold. No functional change intended. Signed-off-by: Dennis Reußwig --- arch/x86/kvm/mmu/spte.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index e730717824b3..237a0484367a 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -22,16 +22,19 @@ * - bits 52, 54: saved X-R bits for access tracking when EPT does not have A/D * - bits 53 (EPT only): host writable * - bits 55 (EPT only): MMU-writable - * - bits 56-59: unused - * - bits 60-61: type of A/D tracking + * - bits 56-57: type of A/D tracking + * - bits 58-61: unused; bit 60 is the EPT supervisor shadow-stack page bit + * when EPTP[7] is set, so it must not be used for software state * - bits 62 (EPT only): saved XU bit for disabled AD */ /* * TDP SPTES (more specifically, EPT SPTEs) may not have A/D bits, and may also * be restricted to using write-protection (for L2 when CPU dirty logging, i.e. - * PML, is enabled). Use bits 60 and 61 to hold the type of A/D tracking that - * is must be employed for a given TDP SPTE. + * PML, is enabled). Use bits 56 and 57 to hold the type of A/D tracking that + * is must be employed for a given TDP SPTE. Bit 57 is "verify guest paging" + * only if the guest-paging verification VM-execution control is set, which + * KVM never does. * * Note, the "enabled" mask must be '0', as bits 62:52 are _reserved_ for PAE * paging, including NPT PAE. This scheme works because legacy shadow paging @@ -39,7 +42,7 @@ * TDP with CPU dirty logging (PML). If NPT ever gains PML-like support, it * must be restricted to 64-bit KVM. */ -#define SPTE_TDP_AD_SHIFT 60 +#define SPTE_TDP_AD_SHIFT 56 #define SPTE_TDP_AD_MASK (3ULL << SPTE_TDP_AD_SHIFT) #define SPTE_TDP_AD_ENABLED (0ULL << SPTE_TDP_AD_SHIFT) #define SPTE_TDP_AD_DISABLED (1ULL << SPTE_TDP_AD_SHIFT) -- 2.53.0