Skip to content

Commit c4db4f2

Browse files
committed
KVM: SVM: Check that the current CPU supports SVM in kvm_is_svm_supported()
Check "this" CPU instead of the boot CPU when querying SVM support so that the per-CPU checks done during hardware enabling actually function as intended, i.e. will detect issues where SVM isn't support on all CPUs. Disable migration for the use from svm_init() mostly so that the standard accessors for the per-CPU data can be used without getting yelled at by CONFIG_DEBUG_PREEMPT=y sanity checks. Preventing the "disabled by BIOS" error message from reporting the wrong CPU is largely a bonus, as ensuring a stable CPU during module load is a non-goal for KVM. Link: https://lore.kernel.org/all/ZAdxNgv0M6P63odE@google.com Cc: Kai Huang <kai.huang@intel.com> Cc: Chao Gao <chao.gao@intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://lore.kernel.org/r/20230721201859.2307736-15-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 85fd29d commit c4db4f2

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,18 +518,20 @@ static void svm_init_osvw(struct kvm_vcpu *vcpu)
518518
vcpu->arch.osvw.status |= 1;
519519
}
520520

521-
static bool kvm_is_svm_supported(void)
521+
static bool __kvm_is_svm_supported(void)
522522
{
523-
int cpu = raw_smp_processor_id();
523+
int cpu = smp_processor_id();
524+
struct cpuinfo_x86 *c = &cpu_data(cpu);
525+
524526
u64 vm_cr;
525527

526-
if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
527-
boot_cpu_data.x86_vendor != X86_VENDOR_HYGON) {
528+
if (c->x86_vendor != X86_VENDOR_AMD &&
529+
c->x86_vendor != X86_VENDOR_HYGON) {
528530
pr_err("CPU %d isn't AMD or Hygon\n", cpu);
529531
return false;
530532
}
531533

532-
if (!boot_cpu_has(X86_FEATURE_SVM)) {
534+
if (!cpu_has(c, X86_FEATURE_SVM)) {
533535
pr_err("SVM not supported by CPU %d\n", cpu);
534536
return false;
535537
}
@@ -548,9 +550,20 @@ static bool kvm_is_svm_supported(void)
548550
return true;
549551
}
550552

553+
static bool kvm_is_svm_supported(void)
554+
{
555+
bool supported;
556+
557+
migrate_disable();
558+
supported = __kvm_is_svm_supported();
559+
migrate_enable();
560+
561+
return supported;
562+
}
563+
551564
static int svm_check_processor_compat(void)
552565
{
553-
if (!kvm_is_svm_supported())
566+
if (!__kvm_is_svm_supported())
554567
return -EIO;
555568

556569
return 0;

0 commit comments

Comments
 (0)