From: Tom Lendacky <thomas.lendacky@amd.com>
To: Kevin Loughlin <kevinloughlin@google.com>, linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
seanjc@google.com, pbonzini@redhat.com,
kirill.shutemov@linux.intel.com, kai.huang@intel.com,
ubizjak@gmail.com, jgross@suse.com, kvm@vger.kernel.org,
pgonda@google.com, sidtelang@google.com, mizhang@google.com,
rientjes@google.com, manalinandan@google.com,
szy0127@sjtu.edu.cn
Subject: Re: [PATCH v6 1/2] x86, lib: Add WBNOINVD helper functions
Date: Tue, 4 Feb 2025 10:59:01 -0600 [thread overview]
Message-ID: <27f10680-e0df-7da3-8ef3-22e1b9476728@amd.com> (raw)
In-Reply-To: <20250201000259.3289143-2-kevinloughlin@google.com>
On 1/31/25 18:02, Kevin Loughlin wrote:
> In line with WBINVD usage, add WBONINVD helper functions. For the
> wbnoinvd() helper, fall back to WBINVD if via alternative() if
> X86_FEATURE_WBNOINVD is not present. alternative() ensures
> compatibility with early boot code if needed.
>
> Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> arch/x86/include/asm/smp.h | 7 +++++++
> arch/x86/include/asm/special_insns.h | 19 ++++++++++++++++++-
> arch/x86/lib/cache-smp.c | 12 ++++++++++++
> 3 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
> index ca073f40698f..ecf93a243b83 100644
> --- a/arch/x86/include/asm/smp.h
> +++ b/arch/x86/include/asm/smp.h
> @@ -112,6 +112,7 @@ void native_play_dead(void);
> void play_dead_common(void);
> void wbinvd_on_cpu(int cpu);
> int wbinvd_on_all_cpus(void);
> +int wbnoinvd_on_all_cpus(void);
>
> void smp_kick_mwait_play_dead(void);
>
> @@ -160,6 +161,12 @@ static inline int wbinvd_on_all_cpus(void)
> return 0;
> }
>
> +static inline int wbnoinvd_on_all_cpus(void)
> +{
> + wbnoinvd();
> + return 0;
> +}
> +
> static inline struct cpumask *cpu_llc_shared_mask(int cpu)
> {
> return (struct cpumask *)cpumask_of(0);
> diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
> index 03e7c2d49559..86a903742139 100644
> --- a/arch/x86/include/asm/special_insns.h
> +++ b/arch/x86/include/asm/special_insns.h
> @@ -117,7 +117,24 @@ static inline void wrpkru(u32 pkru)
>
> static __always_inline void wbinvd(void)
> {
> - asm volatile("wbinvd": : :"memory");
> + asm volatile("wbinvd" : : : "memory");
> +}
> +
> +/* Instruction encoding provided for binutils backwards compatibility. */
> +#define WBNOINVD ".byte 0xf3,0x0f,0x09"
> +
> +/*
> + * Cheaper version of wbinvd(). Call when caches
> + * need to be written back but not invalidated.
> + */
> +static __always_inline void wbnoinvd(void)
> +{
> + /*
> + * If WBNOINVD is unavailable, fall back to the compatible but
> + * more destructive WBINVD (which still writes the caches back
> + * but also invalidates them).
> + */
> + alternative("wbinvd", WBNOINVD, X86_FEATURE_WBNOINVD);
> }
>
> static inline unsigned long __read_cr4(void)
> diff --git a/arch/x86/lib/cache-smp.c b/arch/x86/lib/cache-smp.c
> index 7af743bd3b13..7ac5cca53031 100644
> --- a/arch/x86/lib/cache-smp.c
> +++ b/arch/x86/lib/cache-smp.c
> @@ -20,3 +20,15 @@ int wbinvd_on_all_cpus(void)
> return 0;
> }
> EXPORT_SYMBOL(wbinvd_on_all_cpus);
> +
> +static void __wbnoinvd(void *dummy)
> +{
> + wbnoinvd();
> +}
> +
> +int wbnoinvd_on_all_cpus(void)
> +{
> + on_each_cpu(__wbnoinvd, NULL, 1);
> + return 0;
> +}
> +EXPORT_SYMBOL(wbnoinvd_on_all_cpus);
next prev parent reply other threads:[~2025-02-04 16:59 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 22:55 [PATCH v2 0/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-09 22:55 ` [PATCH v2 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-09 22:55 ` [PATCH v2 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-10 8:23 ` Kirill A. Shutemov
2025-01-13 18:47 ` Kevin Loughlin
2025-01-14 7:50 ` Kirill A. Shutemov
2025-01-14 16:12 ` Sean Christopherson
2025-01-17 22:20 ` Kevin Loughlin
2025-01-13 21:46 ` Mingwei Zhang
2025-01-22 0:13 ` [PATCH v3 0/2] " Kevin Loughlin
2025-01-22 0:13 ` [PATCH v3 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-22 0:30 ` Dave Hansen
2025-01-22 0:30 ` Dave Hansen
2025-01-22 1:14 ` Kevin Loughlin
2025-01-22 0:13 ` [PATCH v3 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-22 1:34 ` [PATCH v4 0/2] " Kevin Loughlin
2025-01-22 1:34 ` [PATCH v4 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-22 7:32 ` Kirill A. Shutemov
2025-01-22 19:39 ` Tom Lendacky
2025-01-22 23:16 ` Dave Hansen
2025-01-23 0:06 ` Kevin Loughlin
2025-01-23 0:33 ` Dave Hansen
2025-01-23 0:58 ` Kevin Loughlin
2025-01-23 1:17 ` Kevin Loughlin
2025-01-22 1:34 ` [PATCH v4 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-23 0:24 ` [PATCH v5 0/2] " Kevin Loughlin
2025-01-23 0:24 ` [PATCH v5 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-23 0:36 ` Dave Hansen
2025-01-23 0:55 ` Kevin Loughlin
2025-01-23 0:24 ` [PATCH v5 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-02-26 1:30 ` Sean Christopherson
2025-02-01 0:02 ` [PATCH v6 0/2] " Kevin Loughlin
2025-02-01 0:02 ` [PATCH v6 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-02-04 16:59 ` Tom Lendacky [this message]
2025-02-26 1:26 ` Sean Christopherson
2025-02-26 14:22 ` Borislav Petkov
2025-02-01 0:02 ` [PATCH v6 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-02-04 17:00 ` Tom Lendacky
2025-02-26 1:35 ` [PATCH v5 0/2] " Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27f10680-e0df-7da3-8ef3-22e1b9476728@amd.com \
--to=thomas.lendacky@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=kai.huang@intel.com \
--cc=kevinloughlin@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manalinandan@google.com \
--cc=mingo@redhat.com \
--cc=mizhang@google.com \
--cc=pbonzini@redhat.com \
--cc=pgonda@google.com \
--cc=rientjes@google.com \
--cc=seanjc@google.com \
--cc=sidtelang@google.com \
--cc=szy0127@sjtu.edu.cn \
--cc=tglx@linutronix.de \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox