From patchwork Fri Jul 21 20:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 124094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp467281vqg; Fri, 21 Jul 2023 14:12:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlH1LB/C0RoLZgk2v6DKU5SIruqBXn3XZefq9F3Nn+rR67iEfvzo8JmwNR0cYRyl26k/S6X8 X-Received: by 2002:a17:907:a070:b0:993:da91:6e0c with SMTP id ia16-20020a170907a07000b00993da916e0cmr2434876ejc.3.1689973970578; Fri, 21 Jul 2023 14:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689973970; cv=none; d=google.com; s=arc-20160816; b=TunZUliHpMFKM4txZGU7zKAxm2kg4BrXudsrFNFs7E7ruPW+FvvUsnHGyZLXGreQ7O Fl3F1CzWWT0/c5YLSFSfy1Z+/NKFB6nkTbsAdl0/rJYOFSKUait2UVRWh5TA8iSGMqWk dHOy0QKUjOzYQBPSPOQ6ta3KfdNcsYrEQmLdjngWbstC4SqX8B3gnxyHQ7EgR7NAModP JiFkeIK3pK1j6WdSYLYfWpnUWiGQCSi5Mzp/oT7gNvewQlOntp+4g50hnhv2S7iY5uB/ gh3dKUIQIEnbzUvbRFdMiTvRSblnbo76UaQMwc66q9m2sbcgKRInA8jRITOICTcRrwJ1 bOhQ== 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=mHJaGcmVZZrx5eJzID4aSbivNsbcbnHCRBUFTHr46UU=; fh=GitwJflddDxrBBVhnTGEzIZYOBTU7RKSqL+OyCDv/0M=; b=JiZZqQph5yJgfYXm5jB7YuVCt4DG8HSN6zgfHvz3Ky8Un5megs+5/66oEPsYOQgTg4 u2Ph/7hk6T0pLEvcKX/GVK36PRDSJjczRbXfaL5T5mFf6rElAlsp5MC1Wlc0l/sTG/Jc VzWyEUEqaOtXIfk5pE4Q5c9EhxIlwnDig1kdgDDh5tDaxKk5Nv8vepHXornkbKWfuVBX UYNfA1B2CZBNDn26wggS0Ac090cAfQNPn62fiJqg6WKGbQYfX+oduMgn7O/Ypr+NqaWY yd9zAg9/thOGvf5XDz+GDm5eavk3IkK13ziHEfbBV1dt/Ss2zoyeeLIE2kZS/hKOxG0v 1ZzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xFjEUGb0; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lz27-20020a170906fb1b00b0099364d9f0ebsi2716741ejb.559.2023.07.21.14.12.26; Fri, 21 Jul 2023 14:12:50 -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=xFjEUGb0; 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 S231362AbjGUUUi (ORCPT + 99 others); Fri, 21 Jul 2023 16:20:38 -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-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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772066146555613407 X-GMAIL-MSGID: 1772066146555613407 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 != X86_VENDOR_AMD && - boot_cpu_data.x86_vendor != X86_VENDOR_HYGON) { - if (msg) - *msg = "not amd or hygon"; - return 0; - } - - if (!boot_cpu_has(X86_FEATURE_SVM)) { - if (msg) - *msg = "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 = raw_smp_processor_id(); - const char *msg; u64 vm_cr; - if (!cpu_has_svm(&msg)) { - pr_err("SVM not supported by CPU %d, %s\n", cpu, msg); + if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD && + boot_cpu_data.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)) { + pr_err("SVM not supported by CPU %d\n", cpu); return false; }