[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <393d84bef4c5896b896ffe94559ebe2d8173a8c5.camel@intel.com>
Date: Mon, 22 May 2023 23:18:45 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "pbonzini@...hat.com" <pbonzini@...hat.com>,
"Christopherson,, Sean" <seanjc@...gle.com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"Gao, Chao" <chao.gao@...el.com>,
"andrew.cooper3@...rix.com" <andrew.cooper3@...rix.com>
Subject: Re: [PATCH v3 14/18] KVM: SVM: Check that the current CPU supports
SVM in kvm_is_svm_supported()
On Fri, 2023-05-12 at 16:50 -0700, Sean Christopherson wrote:
> 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.
"non-goal for KVM (at least for now)" ? :)
>
> Link: https://lore.kernel.org/all/ZAdxNgv0M6P63odE@google.com
> Cc: Kai Huang <kai.huang@...el.com>
> Cc: Chao Gao <chao.gao@...el.com>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
Reviewed-by: Kai Huang <kai.huang@...el.com>
> ---
> arch/x86/kvm/svm/svm.c | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index b347173b4e29..cf5f3880751b 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -523,18 +523,20 @@ static void svm_init_osvw(struct kvm_vcpu *vcpu)
> vcpu->arch.osvw.status |= 1;
> }
>
> -static bool kvm_is_svm_supported(void)
> +static bool __kvm_is_svm_supported(void)
> {
> - int cpu = raw_smp_processor_id();
> + int cpu = smp_processor_id();
> + struct cpuinfo_x86 *c = &cpu_data(cpu);
> +
> u64 vm_cr;
>
> - if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
> - boot_cpu_data.x86_vendor != X86_VENDOR_HYGON) {
> + if (c->x86_vendor != X86_VENDOR_AMD &&
> + c->x86_vendor != X86_VENDOR_HYGON) {
> pr_err("CPU %d isn't AMD or Hygon\n", cpu);
> return false;
> }
>
> - if (!boot_cpu_has(X86_FEATURE_SVM)) {
> + if (!cpu_has(c, X86_FEATURE_SVM)) {
> pr_err("SVM not supported by CPU %d\n", cpu);
> return false;
> }
> @@ -553,9 +555,20 @@ static bool kvm_is_svm_supported(void)
> return true;
> }
>
> +static bool kvm_is_svm_supported(void)
> +{
> + bool supported;
> +
> + migrate_disable();
> + supported = __kvm_is_svm_supported();
> + migrate_enable();
> +
> + return supported;
> +}
> +
> static int svm_check_processor_compat(void)
> {
> - if (!kvm_is_svm_supported())
> + if (!__kvm_is_svm_supported())
> return -EIO;
>
> return 0;
> --
> 2.40.1.606.ga4b1b128d6-goog
>
Powered by blists - more mailing lists