From patchwork Tue Jan 17 21:25:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 44860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2040461wrn; Tue, 17 Jan 2023 15:37:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXumy3Q/8WKn5pAzeir0lAPcqtylKd6vX2Zcip8b7J473Rh7uHMJPyZyx6DEfMbruByGe5Jw X-Received: by 2002:a17:907:989c:b0:86f:cdb1:ea00 with SMTP id ja28-20020a170907989c00b0086fcdb1ea00mr4790770ejc.65.1673998654311; Tue, 17 Jan 2023 15:37:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673998654; cv=none; d=google.com; s=arc-20160816; b=WskWpnlRoynMLG118N8+l5qLGZl3nlRePvYo4H8NqSvcfi6RMyOX2UXsUqnIJ4mJZ9 3B3D8olrzRq0EcSd78TEx4YXOKronYtAZNqOmk9P6e1f5GJfI816oCPeRxuIjq6ngDX6 cvNG1bb3uPAfrbkY+2e7T7xVAfNAonNZm2eLMGmdnjorZWfeughD3yoQ+jhoYiPFkyYC WG+ypmakqUXM30Uc6h1y1WKf3ma+7QEDwXCWu0sYkaUmy3SvgGvnzqBYPC01bChnpMQR BBUZm/6dc09BA3/el1ldT1DVGxNp/VUChwFQKWdMTDOWEdlgHBWa8/jT8xhizZ3pZ3Ux eI5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=gwE2QF/ErBdwWuIXaXoJTpn5NXnQJfCY6SzciOOWEKU=; b=VvrHeVcL2E3XF6629uGYH74IbLGLrGORHq3yQ8qdenREAQwKCa4FI2xt/RAJdFBJt1 gz/ZfPsF6ZIuiA9cTT+qmZcEcNBX0qTplqnpfmDIDybbCN9Szi8wJ7ggXoKoXgm3GLYM SD2+qKAgaXmMJyV5ik8l3dcJNs2DLPAVjX2ufwLZSplugcQCAticnmTBgDhcMYetzDt5 yiFeuTGUaT862VtZJrG2qRoG0bOZHmA9LVC1XkCGHGaXeXpZ6XUQWJqqLg90cU9RTWI4 Y4JEk/pCbq3bqxXFu7qc+Blddy/fl+QON51fHN+WIgkM9ZrNlfhDXNsK9I/7gkOkPbiO ldgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pyTLkl26; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KpbCP7FH; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp16-20020a170906c15000b00870c5d344e3si9226887ejc.139.2023.01.17.15.37.10; Tue, 17 Jan 2023 15:37:34 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=pyTLkl26; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KpbCP7FH; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbjAQXfy (ORCPT + 99 others); Tue, 17 Jan 2023 18:35:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230091AbjAQXex (ORCPT ); Tue, 17 Jan 2023 18:34:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D9C4A1E8; Tue, 17 Jan 2023 13:25:24 -0800 (PST) Date: Tue, 17 Jan 2023 21:25:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673990723; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gwE2QF/ErBdwWuIXaXoJTpn5NXnQJfCY6SzciOOWEKU=; b=pyTLkl26Y9KU6LlKP2U7FJYbDLH68/x/W6o9fLt7VTgY9R31zesEn7I6CrJ6NFtG25ymzP 2yPLmJ/jpuDPu1VE3TK+wGnRNjpAklq8gTHl+HoI7jImnMTzeRBXfyd/o/Wi6DKhpL51Ti KQOrvtuLMNUzzF6TEDAFPNb1e3jX2kZLecbaglkkhBGDJNDpn/xc3v1DKoOPdvUzN+dgMS uuX0lFU0dnX1LGKbLXl6F42qILxb0SxDWDWEwO0rUu0GEeB5FkgQSb4bSeB4Fj9OlHlHdJ m7M8JcWVUV1qCSgAchqzqMkIDtd3D//3WO3JuJyzbDqP7/6LEX2j5NIW5Oo61A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673990723; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gwE2QF/ErBdwWuIXaXoJTpn5NXnQJfCY6SzciOOWEKU=; b=KpbCP7FHyLJTVdu5z/bDm8grCCF6waHYsRbZdJ2vKBgPfcbkkO2p67x5ICZ7HiOg+EuO6I nGsiKns9yX5OtBDA== From: "tip-bot2 for Kim Phillips" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cpu] x86/cpu, kvm: Propagate the AMD Automatic IBRS feature to the guest Cc: Kim Phillips , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230116230159.1511393-8-kim.phillips@amd.com> References: <20230116230159.1511393-8-kim.phillips@amd.com> MIME-Version: 1.0 Message-ID: <167399072266.4906.4758989080281063501.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755222441640546634?= X-GMAIL-MSGID: =?utf-8?q?1755314812876480425?= The following commit has been merged into the x86/cpu branch of tip: Commit-ID: eea6c7957ae7fa2bf90e44c91ef013176db69483 Gitweb: https://git.kernel.org/tip/eea6c7957ae7fa2bf90e44c91ef013176db69483 Author: Kim Phillips AuthorDate: Mon, 16 Jan 2023 17:01:59 -06:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 17 Jan 2023 13:00:12 +01:00 x86/cpu, kvm: Propagate the AMD Automatic IBRS feature to the guest Add the AMD Automatic IBRS feature bit to those being propagated to the guest, and enable the guest EFER bit. Signed-off-by: Kim Phillips Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230116230159.1511393-8-kim.phillips@amd.com --- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/svm/svm.c | 3 +++ arch/x86/kvm/x86.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 56f00d9..6ce0203 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -743,7 +743,7 @@ void kvm_set_cpu_caps(void) kvm_cpu_cap_mask(CPUID_8000_0021_EAX, F(NO_NESTED_DATA_BP) | F(LFENCE_RDTSC) | 0 /* SmmPgCfgLock */ | - F(NULL_SEL_CLR_BASE) | 0 /* PrefetchCtlMsr */ + F(NULL_SEL_CLR_BASE) | F(AUTOIBRS) | 0 /* PrefetchCtlMsr */ ); if (cpu_feature_enabled(X86_FEATURE_LFENCE_RDTSC)) kvm_cpu_cap_set(X86_FEATURE_LFENCE_RDTSC); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 9a194aa..60c7c88 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4969,6 +4969,9 @@ static __init int svm_hardware_setup(void) tsc_aux_uret_slot = kvm_add_user_return_msr(MSR_TSC_AUX); + if (boot_cpu_has(X86_FEATURE_AUTOIBRS)) + kvm_enable_efer_bits(EFER_AUTOIBRS); + /* Check for pause filtering support */ if (!boot_cpu_has(X86_FEATURE_PAUSEFILTER)) { pause_filter_count = 0; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index da4bbd0..8dd0cb2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1685,6 +1685,9 @@ static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data) static bool __kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer) { + if (efer & EFER_AUTOIBRS && !guest_cpuid_has(vcpu, X86_FEATURE_AUTOIBRS)) + return false; + if (efer & EFER_FFXSR && !guest_cpuid_has(vcpu, X86_FEATURE_FXSR_OPT)) return false;