Skip to content

Commit 5674a76

Browse files
yosrym93sean-jc
authored andcommitted
KVM: nSVM: Propagate SVM_EXIT_CR0_SEL_WRITE correctly for LMSW emulation
When emulating L2 instructions, svm_check_intercept() checks whether a write to CR0 should trigger a synthesized #VMEXIT with SVM_EXIT_CR0_SEL_WRITE. For MOV-to-CR0, SVM_EXIT_CR0_SEL_WRITE is only triggered if any bit other than CR0.MP and CR0.TS is updated. However, according to the APM (24593—Rev. 3.42—March 2024, Table 15-7): The LMSW instruction treats the selective CR0-write intercept as a non-selective intercept (i.e., it intercepts regardless of the value being written). Skip checking the changed bits for x86_intercept_lmsw and always inject SVM_EXIT_CR0_SEL_WRITE. Fixes: cfec82c ("KVM: SVM: Add intercept check for emulated cr accesses") Cc: stable@vger.kernel.org Reported-by: Matteo Rizzo <matteorizzo@google.com> Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev> Link: https://patch.msgid.link/20251024192918.3191141-3-yosry.ahmed@linux.dev Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3d31bdf commit 5674a76

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4546,20 +4546,20 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu,
45464546
INTERCEPT_SELECTIVE_CR0)))
45474547
break;
45484548

4549-
cr0 = vcpu->arch.cr0 & ~SVM_CR0_SELECTIVE_MASK;
4550-
val = info->src_val & ~SVM_CR0_SELECTIVE_MASK;
4551-
4549+
/* LMSW always triggers INTERCEPT_SELECTIVE_CR0 */
45524550
if (info->intercept == x86_intercept_lmsw) {
4553-
cr0 &= 0xfUL;
4554-
val &= 0xfUL;
4555-
/* lmsw can't clear PE - catch this here */
4556-
if (cr0 & X86_CR0_PE)
4557-
val |= X86_CR0_PE;
4551+
icpt_info.exit_code = SVM_EXIT_CR0_SEL_WRITE;
4552+
break;
45584553
}
45594554

4555+
/*
4556+
* MOV-to-CR0 only triggers INTERCEPT_SELECTIVE_CR0 if any bit
4557+
* other than SVM_CR0_SELECTIVE_MASK is changed.
4558+
*/
4559+
cr0 = vcpu->arch.cr0 & ~SVM_CR0_SELECTIVE_MASK;
4560+
val = info->src_val & ~SVM_CR0_SELECTIVE_MASK;
45604561
if (cr0 ^ val)
45614562
icpt_info.exit_code = SVM_EXIT_CR0_SEL_WRITE;
4562-
45634563
break;
45644564
}
45654565
case SVM_EXIT_READ_DR0:

0 commit comments

Comments
 (0)