Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp525720rwb; Wed, 16 Nov 2022 04:21:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf5cEwewZAK/LKTKkPe18AganM92/za6pdal3uzTIlfMfpC7L+aJCkp8DkFvmv5vQ7LHCpSY X-Received: by 2002:a17:90b:3756:b0:20a:92d2:226a with SMTP id ne22-20020a17090b375600b0020a92d2226amr3536182pjb.155.1668601264447; Wed, 16 Nov 2022 04:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668601264; cv=none; d=google.com; s=arc-20160816; b=SwOJAl9Mlkty+O/6DZDVZQhfuuOpcEU4b3GTjzyXEcKUR7DLslY85HxkGQoXKd6nXQ uJtUg26hqya9JWlcToDpN+YecAR13Xq0LCvaXgnPqXJtjRzSg/dYGMvFtgJcZV0NpJeU 6vwHDncW8YcnOCrwFxR6BvBk8/L0v67BafEdMbBz7QeENYLyrikI2krD+TTNkBlkwB2U gjOe4Wkku7hFIaTN8zckOl2zMeIOXOa1jwkhJJrj3l2jOuqJlu9w1QWe423PUwg+WFU8 FJnehETlvIhxvCdj+c4w0G8Qk58AsuQ/Imwa0MocCLrCZMwFqimvZu82kiGeHO5+vjBN a4RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hJKof9wnh/Z0s3rCjN4QwsOtG6Nl0wGK7lB4XoziVvE=; b=k0Ua2dxkP7Rf6wmZRLbed5V3Du+8sLXqmex2nveFiZ59dceIYgFARqBeeU02qPtFOv ZKqzNEKIPzjWAEfHGb3/50EdMP2FIqjGKXYYmZ04lX5VKSNa2hooiA9yvWoHJ85Rt5Dp 9inwY3BSnfNU9m5nItAM1yOdeCsqo0Wm/QzA/g0emrS5Q7g0QGt/gzCvJiTQW8yNtSsA WNr0RS2/fW8uI9z7j5Jbk/O9zkJneqaVsps/9Ff9SpdphyjWi1moGYzmWwoPizhyEcCT QZEZuWSIc6qUbaQiYy1bpIbUQTuKOIIdmTQiXrkXArzX9TTi/CkaeEpYBBwRGXYoo5Tx Wwcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=SLdXhc3S; 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=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a1709026a8900b001870c4c2722si13852749plk.299.2022.11.16.04.20.52; Wed, 16 Nov 2022 04:21:04 -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=@alien8.de header.s=dkim header.b=SLdXhc3S; 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=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233440AbiKPMGj (ORCPT + 91 others); Wed, 16 Nov 2022 07:06:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233036AbiKPMGH (ORCPT ); Wed, 16 Nov 2022 07:06:07 -0500 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD89B1DA; Wed, 16 Nov 2022 03:59:50 -0800 (PST) Received: from zn.tnic (p200300ea9733e74b329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:9733:e74b:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5FBEC1EC032C; Wed, 16 Nov 2022 12:59:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1668599989; h=from:from: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:in-reply-to:in-reply-to: references:references; bh=hJKof9wnh/Z0s3rCjN4QwsOtG6Nl0wGK7lB4XoziVvE=; b=SLdXhc3Ss5eT1lbfU5YcQyKqWJEOt+wwYoPV+OGNdSM6QsU84Lde9VpYVFV+S+wsA5ajq7 d16FjMppb7sG03xasXlJCV5Jd97v85HMuTYo0ezrKK+BwMuOJl3NUJrNVc3F21sqzHkHes ebkVbaj9rSlpxXL180nTPdWifS9TKbg= Date: Wed, 16 Nov 2022 12:59:45 +0100 From: Borislav Petkov To: Kim Phillips , Sean Christopherson Cc: x86@kernel.org, Boris Ostrovsky , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Joao Martins , Jonathan Corbet , Konrad Rzeszutek Wilk , Paolo Bonzini , Thomas Gleixner , David Woodhouse , Greg Kroah-Hartman , Juergen Gross , Peter Zijlstra , Tony Luck , Babu Moger , Tom Lendacky , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] x86/cpufeatures: Add support for cpuid leaf 80000021/EAX (FeatureExt2Eax) Message-ID: References: <20221104213651.141057-1-kim.phillips@amd.com> <20221104213651.141057-2-kim.phillips@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Tue, Nov 15, 2022 at 05:10:50PM -0600, Kim Phillips wrote: > When trying to wire up a scattered host AUTOIBRS version up to > kvm, I couldn't get past all the reverse_cpuid_check() > BUILD_BUGs demanding exclusivity between h/w and "Linux" > (s/w) FEATUREs. I guess something like below. Sean, can you pls check the KVM bits whether I've done them all right? In any case, it seems to work, guest has: processor : 0 vendor_id : AuthenticAMD cpu family : 25 model : 1 model name : AMD EPYC-Milan Processor stepping : 1 flags : ... autoibrs ... --- From: Borislav Petkov Date: Wed, 16 Nov 2022 12:50:08 +0100 Subject: [PATCH] x86/cpu, kvm: Add X86_FEATURE_AUTOIBRS Add AMD AutoIBRS feature bit support. Use a synthetic bit as this is the first bit from the 0x80000021 leaf. Add the corresponding word to KVM's feature machinery so that the bit gets advertized into the guest too. Signed-off-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 18 ++++++++++++------ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 2bc1557dc203..2cf102911241 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -306,6 +306,7 @@ #define X86_FEATURE_RSB_VMEXIT_LITE (11*32+17) /* "" Fill RSB on VM exit when EIBRS is enabled */ #define X86_FEATURE_SGX_EDECCSSA (11*32+18) /* "" SGX EDECCSSA user leaf function */ #define X86_FEATURE_CALL_DEPTH (11*32+19) /* "" Call depth tracking for RSB stuffing */ +#define X86_FEATURE_AUTOIBRS (11*32+20) /* AMD Automatic IBRS */ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index f53944fb8f7f..e20117658c5b 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -45,6 +45,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, { X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 }, + { X86_FEATURE_AUTOIBRS, CPUID_EAX, 8, 0x80000021, 0 }, { X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 }, { 0, 0, 0, 0, 0 } diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index c92c49a0b35b..050bca360731 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -750,6 +750,8 @@ void kvm_set_cpu_caps(void) kvm_cpu_cap_clear(X86_FEATURE_RDTSCP); kvm_cpu_cap_clear(X86_FEATURE_RDPID); } + + kvm_cpu_cap_init_scattered(CPUID_8000_0021_EAX, SF(AUTOIBRS)); } EXPORT_SYMBOL_GPL(kvm_set_cpu_caps); diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 4e5b8444f161..c4801ac84a4a 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -13,6 +13,7 @@ */ enum kvm_only_cpuid_leafs { CPUID_12_EAX = NCAPINTS, + CPUID_8000_0021_EAX, NR_KVM_CPU_CAPS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, @@ -25,6 +26,9 @@ enum kvm_only_cpuid_leafs { #define KVM_X86_FEATURE_SGX2 KVM_X86_FEATURE(CPUID_12_EAX, 1) #define KVM_X86_FEATURE_SGX_EDECCSSA KVM_X86_FEATURE(CPUID_12_EAX, 11) +/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX) */ +#define KVM_X86_FEATURE_AUTOIBRS KVM_X86_FEATURE(CPUID_8000_0021_EAX, 8) + struct cpuid_reg { u32 function; u32 index; @@ -49,6 +53,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_7_1_EAX] = { 7, 1, CPUID_EAX}, [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, + [CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX}, }; /* @@ -75,12 +80,13 @@ static __always_inline void reverse_cpuid_check(unsigned int x86_leaf) */ static __always_inline u32 __feature_translate(int x86_feature) { - if (x86_feature == X86_FEATURE_SGX1) - return KVM_X86_FEATURE_SGX1; - else if (x86_feature == X86_FEATURE_SGX2) - return KVM_X86_FEATURE_SGX2; - else if (x86_feature == X86_FEATURE_SGX_EDECCSSA) - return KVM_X86_FEATURE_SGX_EDECCSSA; + switch (x86_feature) { + case X86_FEATURE_SGX1: return KVM_X86_FEATURE_SGX1; + case X86_FEATURE_SGX2: return KVM_X86_FEATURE_SGX2; + case X86_FEATURE_SGX_EDECCSSA: return KVM_X86_FEATURE_SGX_EDECCSSA; + case X86_FEATURE_AUTOIBRS: return KVM_X86_FEATURE_AUTOIBRS; + default: break; + } return x86_feature; } -- 2.35.1 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette