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 509FAC54E94 for ; Tue, 24 Jan 2023 01:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232675AbjAXBR7 (ORCPT ); Mon, 23 Jan 2023 20:17:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232654AbjAXBR5 (ORCPT ); Mon, 23 Jan 2023 20:17:57 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C26C93CD for ; Mon, 23 Jan 2023 17:17:55 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id 78so10336335pgb.8 for ; Mon, 23 Jan 2023 17:17:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VdIkKw85QyqR8RnovAWlaOqWkJ4x/84JU+MCLeNY4/w=; b=XnuUpXBYmcbXYIl/WUVnKUIF0/iOyYXTFdKQ6MhIGZ+lSxA6obVt/YUk6NcVR6bE98 2wngsfbss+Q+B/nvpCog6BkcM4EPVNC1c5M+nqGvlw9HQrFsOUhSd8NCEDGWv7pgqsW8 cxJY4aYJ+NYeaZ/uxsxZYNDYAR0gqL0smN+BmlSQ55RamWuHnZfw0cD6H0tJMVXBxFL5 ZDmYesfFMwWm1TWbakB2jCQy9GRGNn1/BvXjU5QBdgiPHJLNQ8nvBSg7/KXWoU6nR6MY rFD06x0IwB3JtsoPmH9fYEDrP3o9ahBgjbJz/zH9LKRDEiiqQXS3B4MWV/e8byXKOXKT H3XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VdIkKw85QyqR8RnovAWlaOqWkJ4x/84JU+MCLeNY4/w=; b=Ld7SfkEXzI41MPHdG6W0zm4nSvtsQHh7fk1BXNLenyV5qcFETn6kIcqxfJxY5yHZRb dW9axjPNaxXecKsbGIe1FMc3gDn13Ml3ngMrd2Vp35pZ2SHaRYSJJaCduGkbBtPmPQug WsYoi6FYlcwbxEf34pg+TJV4XK2chZX1+1jYWGymzP2V8mSaZZmCo2bQilmiaPXdAhDR GelvpDt9q6Tuo+GSuAYGDK5mJ5KMMjpAN2rDlxwPYt7x9UEErVZW87GjMN74dRtd1+aX JzsDsmhElCUL+ezeBQ7GeG8QHUq2p3i6xTnXb/pPpBIVf4clAbZmUWBYjQPtHSzPKMav VOag== X-Gm-Message-State: AO0yUKXMR3EUfvOsadHlA4ajrxiTXX/8N3wC9q4grCQRoDFtocWYyuCM 4YeLi1aRopYIdPE3ELfXlbh52w== X-Google-Smtp-Source: AK7set8fB2T3Yp6e7oXLpQvSuy5QdNrLHtwCWOp1643ps5CardXQOKYuldF9Mty3bq1ODsD5Zz9PEg== X-Received: by 2002:a05:6a00:288b:b0:582:13b5:d735 with SMTP id ch11-20020a056a00288b00b0058213b5d735mr12876pfb.0.1674523074825; Mon, 23 Jan 2023 17:17:54 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id f9-20020a623809000000b0056c2e497b02sm220593pfa.173.2023.01.23.17.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:17:54 -0800 (PST) Date: Tue, 24 Jan 2023 01:17:50 +0000 From: Sean Christopherson To: Kim Phillips Cc: x86@kernel.org, Borislav Petkov , 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 , Tom Lendacky , Alexey Kardashevskiy , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 4/8] x86/cpu, kvm: Move X86_FEATURE_LFENCE_RDTSC to its native leaf Message-ID: References: <20230123225700.2224063-1-kim.phillips@amd.com> <20230123225700.2224063-5-kim.phillips@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230123225700.2224063-5-kim.phillips@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 23, 2023, Kim Phillips wrote: > The LFENCE always serializing feature bit was defined as scattered > LFENCE_RDTSC and its native leaf bit position open-coded for KVM. > Add it to its newly added CPUID leaf 0x80000021 EAX proper. > > Drop the bit description comments now it's more self-describing. > > Also, in amd_init(), don't bother setting DE_CFG[1] any more. > > Signed-off-by: Kim Phillips > --- > arch/x86/include/asm/cpufeatures.h | 3 ++- > arch/x86/kernel/cpu/amd.c | 2 +- > arch/x86/kvm/cpuid.c | 4 ++-- > 3 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index 7f0fb894e432..4f22d828c753 100644 > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -97,7 +97,7 @@ > #define X86_FEATURE_SYSENTER32 ( 3*32+15) /* "" sysenter in IA32 userspace */ > #define X86_FEATURE_REP_GOOD ( 3*32+16) /* REP microcode works well */ > #define X86_FEATURE_AMD_LBR_V2 ( 3*32+17) /* AMD Last Branch Record Extension Version 2 */ > -#define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) /* "" LFENCE synchronizes RDTSC */ > +/* FREE, was #define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) "" LFENCE synchronizes RDTSC */ > #define X86_FEATURE_ACC_POWER ( 3*32+19) /* AMD Accumulated Power Mechanism */ > #define X86_FEATURE_NOPL ( 3*32+20) /* The NOPL (0F 1F) instructions */ > #define X86_FEATURE_ALWAYS ( 3*32+21) /* "" Always-present feature */ > @@ -430,6 +430,7 @@ > > /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ > #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* "" No Nested Data Breakpoints */ > +#define X86_FEATURE_LFENCE_RDTSC (20*32+ 2) /* "" LFENCE always serializing / synchronizes RDTSC */ > > /* > * BUG word(s) > diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c > index f769d6d08b43..208c2ce8598a 100644 > --- a/arch/x86/kernel/cpu/amd.c > +++ b/arch/x86/kernel/cpu/amd.c > @@ -956,7 +956,7 @@ static void init_amd(struct cpuinfo_x86 *c) > > init_amd_cacheinfo(c); > > - if (cpu_has(c, X86_FEATURE_XMM2)) { > + if (!cpu_has(c, X86_FEATURE_LFENCE_RDTSC) && cpu_has(c, X86_FEATURE_XMM2)) { > /* > * Use LFENCE for execution serialization. On families which > * don't have that MSR, LFENCE is already serializing. > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index 13bd2769fa5a..601eeb03ebc9 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -742,11 +742,11 @@ void kvm_set_cpu_caps(void) > F(SME_COHERENT)); > > kvm_cpu_cap_mask(CPUID_8000_0021_EAX, > - F(NO_NESTED_DATA_BP) | 0 /* SmmPgCfgLock */ | > + F(NO_NESTED_DATA_BP) | F(LFENCE_RDTSC) | 0 /* SmmPgCfgLock */ | > BIT(6) /* NULL_SEL_CLR_BASE */ | 0 /* PrefetchCtlMsr */ > ); > if (cpu_feature_enabled(X86_FEATURE_LFENCE_RDTSC)) > - kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(2) /* LFENCE Always serializing */; > + kvm_cpu_cap_set(X86_FEATURE_LFENCE_RDTSC); Now that LFENCE_RDTSC is in its proper place, the kernel's set_cpu_cap() will effectively sythesize the feature for KVM. I.e. this patch can simply delete the synthesis of the feature. > if (!static_cpu_has_bug(X86_BUG_NULL_SEG)) > kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(6) /* NULL_SEL_CLR_BASE */; > kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(9) /* NO_SMM_CTL_MSR */; > -- > 2.34.1 >