From nobody Thu Sep 18 21:55:07 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AD09C0015E for ; Fri, 21 Jul 2023 20:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231518AbjGUUUj (ORCPT ); Fri, 21 Jul 2023 16:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231460AbjGUUUH (ORCPT ); Fri, 21 Jul 2023 16:20:07 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F303935AB for ; Fri, 21 Jul 2023 13:19:31 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-583a89cccf6so6221507b3.1 for ; Fri, 21 Jul 2023 13:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689970770; x=1690575570; 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=mHJaGcmVZZrx5eJzID4aSbivNsbcbnHCRBUFTHr46UU=; b=xFjEUGb0YeU1GuqO6TMYTw4S8pE3wSKHfAnKkjt80FS5sXpKILObv/a3O3ewHWsGTO /uzvI4F2rqO1kbuzWSa4MliHY9cF1H/Ac9QzYVtv+NpjhbtyPfoNrV+E8v7WZNB/bFw6 ZQ7omF8dzvvNGZgQWyEPIyPC2w4JP9kZNJKLQfZrbxFODjZi5nLgku8ikRETSpBGVBoX oTGOuajDeuXcYaiGo4yFKLgo/FiyRHoPoBqYGCiHsyTHKlkUVEYlJTNm2xlmLZ2ST0En IL9sBALfri08BXauA1hERqbg4OfcffWRTJh4RjhdbbAEe8+cFgFJdJ8ifVoxgauGAZCM iuuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689970770; x=1690575570; 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=mHJaGcmVZZrx5eJzID4aSbivNsbcbnHCRBUFTHr46UU=; b=ED78eCYn1HC4WemdjwIID/SpOYjC/blCWapItl7GwlWNsPSc/PA5B7uy+Y9DlqevML Vu1zrE214JxqP0XuX74JzyJn8cKWuJY0UWCbUw72Y+/V01eUeJjFJsrsPJW3BmdlFMN9 fdULHlq/gS2sppiLmdbaLWotEpU5jkhiNPAdXmRVgcMC4uVOO+ZGnRvnoALvhiyXKiJo e8OoLNGy/cTq02lwZTroGI1+jMQErpy8OY5MvsxFlJS69EgfJ5m8XyucFT+gQllfnD1+ 2NaBVSNcD4eulUMxiGesAOfn7aCkKKvoHYN72hs/8fbjqXmoVEaS0ZUzuPyFLjhXSFGZ j+hw== X-Gm-Message-State: ABy/qLb/I5X3HLYwgLdok7rAspfbQfQKvf1/wnD58tHii4TlH6DExC5V FNTVhfE+h7hA2uFC3i0pt5L0qcjXxQ4= X-Google-Smtp-Source: APBJJlGF70SDbq3ZEJP5RArk6dyLbOvKEAdAx8uwY/2QO3SFNPIUp6BScgv9kfKmHPsrEaR+kwKTcLne1bo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:ac15:0:b0:55d:d5b1:c2bd with SMTP id k21-20020a81ac15000000b0055dd5b1c2bdmr9808ywh.8.1689970770756; Fri, 21 Jul 2023 13:19:30 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 21 Jul 2023 13:18:53 -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-14-seanjc@google.com> Subject: [PATCH v4 13/19] x86/virt: KVM: Open code cpu_has_svm() into 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fold the guts of cpu_has_svm() into kvm_is_svm_supported(), its sole remaining user. No functional change intended. Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/include/asm/virtext.h | 28 ---------------------------- arch/x86/kvm/svm/svm.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h index be50c414efe4..632575e257d8 100644 --- a/arch/x86/include/asm/virtext.h +++ b/arch/x86/include/asm/virtext.h @@ -22,35 +22,7 @@ /* * SVM functions: */ - -/** Check if the CPU has SVM support - * - * You can use the 'msg' arg to get a message describing the problem, - * if the function returns zero. Simply pass NULL if you are not interested - * on the messages; gcc should take care of not generating code for - * the messages on this case. - */ -static inline int cpu_has_svm(const char **msg) -{ - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) { - if (msg) - *msg =3D "not amd or hygon"; - return 0; - } - - if (!boot_cpu_has(X86_FEATURE_SVM)) { - if (msg) - *msg =3D "svm not available"; - return 0; - } - return 1; -} - - /** Disable SVM on the current CPU - * - * You should call this only if cpu_has_svm() returned true. */ static inline void cpu_svm_disable(void) { diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1ae9c2c7eacb..ff6c769aafb2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -521,11 +521,16 @@ static void svm_init_osvw(struct kvm_vcpu *vcpu) static bool kvm_is_svm_supported(void) { int cpu =3D raw_smp_processor_id(); - const char *msg; u64 vm_cr; =20 - if (!cpu_has_svm(&msg)) { - pr_err("SVM not supported by CPU %d, %s\n", cpu, msg); + if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && + boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) { + pr_err("CPU %d isn't AMD or Hygon\n", cpu); + return false; + } + + if (!boot_cpu_has(X86_FEATURE_SVM)) { + pr_err("SVM not supported by CPU %d\n", cpu); return false; } =20 --=20 2.41.0.487.g6d72f3e995-goog