Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: SVM: Skip OSVW MSR reads if KVM is treating all errata as present

Don't bother reading the OSVW MSRs if osvw_len is already zero, i.e. if
KVM is already treating all errata as present, in which case the positive
path of the if-statement is one giant nop.

Opportunistically update the comment to more thoroughly explain how the
MSRs work and why the code does what it does.

Link: https://patch.msgid.link/20251113231420.1695919-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+12 -2
+12 -2
arch/x86/kvm/svm/svm.c
··· 543 543 544 544 545 545 /* 546 - * Get OSVW bits. 546 + * Get OS-Visible Workarounds (OSVW) bits. 547 547 * 548 548 * Note that it is possible to have a system with mixed processor 549 549 * revisions and therefore different OSVW bits. If bits are not the same 550 550 * on different processors then choose the worst case (i.e. if erratum 551 551 * is present on one processor and not on another then assume that the 552 552 * erratum is present everywhere). 553 + * 554 + * Note #2! The OSVW MSRs are used to communciate that an erratum is 555 + * NOT present! Software must assume erratum as present if its bit is 556 + * set in OSVW_STATUS *or* the bit number exceeds OSVW_ID_LENGTH. If 557 + * either RDMSR fails, simply zero out the length to treat all errata 558 + * as being present. Similarly, use the *minimum* length across all 559 + * CPUs, not the maximum length. 560 + * 561 + * If the length is zero, then is KVM already treating all errata as 562 + * being present and there's nothing left to do. 553 563 */ 554 - if (cpu_has(&boot_cpu_data, X86_FEATURE_OSVW)) { 564 + if (osvw_len && cpu_has(&boot_cpu_data, X86_FEATURE_OSVW)) { 555 565 u64 len, status = 0; 556 566 int err; 557 567