Commit e40bcf9f authored by Mathias Krause's avatar Mathias Krause Committed by Sean Christopherson

KVM: x86: Ignore CR0.WP toggles in non-paging mode

If paging is disabled, there are no permission bits to emulate.
Micro-optimize this case to avoid unnecessary work.
Suggested-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarMathias Krause <minipli@grsecurity.net>
Link: https://lore.kernel.org/r/20230322013731.102955-4-minipli@grsecurity.netCo-developed-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 01b31714
...@@ -908,14 +908,20 @@ void kvm_post_set_cr0(struct kvm_vcpu *vcpu, unsigned long old_cr0, unsigned lon ...@@ -908,14 +908,20 @@ void kvm_post_set_cr0(struct kvm_vcpu *vcpu, unsigned long old_cr0, unsigned lon
{ {
/* /*
* CR0.WP is incorporated into the MMU role, but only for non-nested, * CR0.WP is incorporated into the MMU role, but only for non-nested,
* indirect shadow MMUs. If TDP is enabled, the MMU's metadata needs * indirect shadow MMUs. If paging is disabled, no updates are needed
* to be updated, e.g. so that emulating guest translations does the * as there are no permission bits to emulate. If TDP is enabled, the
* right thing, but there's no need to unload the root as CR0.WP * MMU's metadata needs to be updated, e.g. so that emulating guest
* doesn't affect SPTEs. * translations does the right thing, but there's no need to unload the
* root as CR0.WP doesn't affect SPTEs.
*/ */
if (tdp_enabled && (cr0 ^ old_cr0) == X86_CR0_WP) { if ((cr0 ^ old_cr0) == X86_CR0_WP) {
kvm_init_mmu(vcpu); if (!(cr0 & X86_CR0_PG))
return; return;
if (tdp_enabled) {
kvm_init_mmu(vcpu);
return;
}
} }
if ((cr0 ^ old_cr0) & X86_CR0_PG) { if ((cr0 ^ old_cr0) & X86_CR0_PG) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment