Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp380296rwo; Fri, 21 Jul 2023 13:26:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlENVt467dEr2VtQeOMkCIzX0I/kAT+dHo1JLAZOaNmCOuHrU8dIyK8fKIWtARdAJuxEaAve X-Received: by 2002:a17:906:116:b0:978:928:3b99 with SMTP id 22-20020a170906011600b0097809283b99mr2633844eje.46.1689971185787; Fri, 21 Jul 2023 13:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689971185; cv=none; d=google.com; s=arc-20160816; b=QtIhkH1IF6TCSL3DPNT6Iwg3XRSNa0Ub6hxP1DVrg2FgEIdH5Po9Lwv5oUsf4Z37GB oa75MrNycW+/ZVG5aS0bIe63WjvLpjc92xhS3SbHnCmUfmqjAWwit0M8pn05BCwPRMeM T0w0aEOiPxBJJgjwXLhPFxBxc7T9d7j1DB1/ilPoFqNTvTU4fsXPEdvbaugOnFJ21Tw3 OgdkhWBROt6uAvcuEDw3zG23fnE+Mbh2U64kMp+ZmWHjw27xD23GP4pBXOBO0YuPaOLm o2jCIdC0KU9SAxAVSAHCbtE4TSWgiwV09jMfCh9ZhdmeiaPNz4RWbwvYsRnveTNXeOPI s/bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=uhoBWFPCBOgYgQs9Wbxf7anLd8UMxgDqXbWpH+bX2KY=; fh=GitwJflddDxrBBVhnTGEzIZYOBTU7RKSqL+OyCDv/0M=; b=Ta7o9RiUgQ/731rvnnZCPt3EoH53EXb73Rdbe7eUhzCGLztASSnpxqptp+Cpujyr9J VEUvP0kFXrqU4PUFrzaB1CbRlHgHFKxDNP6vCw0cafy6PE7zHdvA86yqLsYDeOej1CG8 Q3iD5tfeAfknVKZwueQJMlvpnfDYzGzjOj2jvYCHQuRl8QRZ8htj30+mnXcGTJbj7Oyo IRrpu8h71fqa0kB6v9Q9ud6q0qCf3IfS32l/llP8yVmAt2QIUT0Fs9AuXLZk1L7SQUip iAxT9NKb+fqL2YyxD9fGmhAqPetZK8bPQk9HNis1J483J3eDnjePcX3MOefIxAA+4E9F 6tqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=BqJBwjEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v27-20020a170906339b00b00992f7fe9c0bsi2705472eja.328.2023.07.21.13.26.01; Fri, 21 Jul 2023 13:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=BqJBwjEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbjGUUUc (ORCPT + 99 others); Fri, 21 Jul 2023 16:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231439AbjGUUUF (ORCPT ); Fri, 21 Jul 2023 16:20:05 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F5664216 for ; Fri, 21 Jul 2023 13:19:33 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c5a479bc2d4so2186020276.1 for ; Fri, 21 Jul 2023 13:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689970772; x=1690575572; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=uhoBWFPCBOgYgQs9Wbxf7anLd8UMxgDqXbWpH+bX2KY=; b=BqJBwjEk+/zhFp4v5DrxQNReQVSoNlh/Bn0hUbsO8ZiEO/etbAIosjlClY7b6ifBBy wi3HDJfJE+jUUceINpJHN6wSTWbqUmyfzZi1k/JQKHiIJGwA7j6u5reIne4DWb5D1UeB p7pcAuNqF4vndeC9wIz/8uWHcddezeQhI8tep358HE0tpXUoAcue+Ghl6YEpRZEzbO/U J3+qH1Zc8yvKpVjIjnIx/75G7nRlmV863pOmIuyo9J3xyzA50nbAtEa0Myyb9v3ipxpH kDIyKNilgiU1a4xzVdhXo9++dIWuAlATjktwg3RONaxNWlAzAQafqJVzTHbU6vE4FJ1e d34g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689970772; x=1690575572; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uhoBWFPCBOgYgQs9Wbxf7anLd8UMxgDqXbWpH+bX2KY=; b=ioPM0KVZdVzr750WNG+NuaMelMGwhJd6klo0H6CLm7AtcHPPs49o1WIXUuD5ax9uiH anZML967yc8GhY297JQpXwuEBVZZezLGyQOkEb8BaCBtG5cLF9CVw2OapMyXe7eOz5XL 6L1+HNeMYuhot2dt8Gp+Y7IDQZxMpSz75qmaGVC5tk4piVE9P/5eIgVDx3dBVmupoWsX qsZqHS67nExZfNZXEwRZJcCtq1iBJTFK4kspH2F6Mo+VBggVvwgM9agWAQeW1oz+62KU DJLBmryrZsjxQ69N9SEYuslGFR8A+q4Kagvcl3vUvMFuwGx5pqoZAUTnt8OqpyFJhQSB Z1Bw== X-Gm-Message-State: ABy/qLbSm38lnt9zS73T52AvEvPT8+sa/m2sKB83tjTuJtuxTxXvKLDZ RkyYRe3ENsbFRo+bQT+RVSMKmoXjiLg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:40cf:0:b0:cc7:b850:7f2 with SMTP id n198-20020a2540cf000000b00cc7b85007f2mr19598yba.5.1689970772756; Fri, 21 Jul 2023 13:19:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 21 Jul 2023 13:18:54 -0700 In-Reply-To: <20230721201859.2307736-1-seanjc@google.com> Mime-Version: 1.0 References: <20230721201859.2307736-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230721201859.2307736-15-seanjc@google.com> Subject: [PATCH v4 14/19] KVM: SVM: Check that the current CPU supports SVM in kvm_is_svm_supported() From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Andrew Cooper , Kai Huang , Chao Gao Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Chao Gao Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- 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 ff6c769aafb2..9e449167e71b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -518,18 +518,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; } @@ -548,9 +550,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.41.0.487.g6d72f3e995-goog