Skip to content

Commit 8d214c4

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: x86: Reset MMU context if guest toggles CR4.SMAP or CR4.PKE
Reset the MMU context during kvm_set_cr4() if SMAP or PKE is toggled. Recent commits to (correctly) not reload PDPTRs when SMAP/PKE are toggled inadvertantly skipped the MMU context reset due to the mask of bits that triggers PDPTR loads also being used to trigger MMU context resets. Fixes: 427890a ("kvm: x86: Toggling CR4.SMAP does not load PDPTEs in PAE mode") Fixes: cb957ad ("kvm: x86: Toggling CR4.PKE does not load PDPTEs in PAE mode") Cc: Jim Mattson <jmattson@google.com> Cc: Peter Shier <pshier@google.com> Cc: Oliver Upton <oupton@google.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Message-Id: <20200923215352.17756-1-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent ee6fa05 commit 8d214c4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

arch/x86/kvm/x86.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
976976
unsigned long old_cr4 = kvm_read_cr4(vcpu);
977977
unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE |
978978
X86_CR4_SMEP;
979+
unsigned long mmu_role_bits = pdptr_bits | X86_CR4_SMAP | X86_CR4_PKE;
979980

980981
if (kvm_valid_cr4(vcpu, cr4))
981982
return 1;
@@ -1003,7 +1004,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
10031004
if (kvm_x86_ops.set_cr4(vcpu, cr4))
10041005
return 1;
10051006

1006-
if (((cr4 ^ old_cr4) & pdptr_bits) ||
1007+
if (((cr4 ^ old_cr4) & mmu_role_bits) ||
10071008
(!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE)))
10081009
kvm_mmu_reset_context(vcpu);
10091010

0 commit comments

Comments
 (0)