public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Borislav Petkov <bp@alien8.de>
Cc: X86 ML <x86@kernel.org>,
	Kishon VijayAbraham <Kishon.VijayAbraham@amd.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] x86/alternative: Add per-vendor patching
Date: Fri, 27 Oct 2023 20:11:47 +0200	[thread overview]
Message-ID: <20231027181147.GC26550@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20231027153418.GLZTvYejCkXb03rArO@fat_crate.local>

On Fri, Oct 27, 2023 at 05:34:18PM +0200, Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> Date: Fri, 27 Oct 2023 13:34:12 +0200
> 
> Add the capability to apply alternatives not based on a CPU feature but
> on the current vendor the machine is running on.
> 
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> ---
>  arch/x86/include/asm/alternative.h |  7 ++++++-
>  arch/x86/kernel/alternative.c      | 14 +++++++++-----
>  2 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
> index 65f79092c9d9..76750f8b5aba 100644
> --- a/arch/x86/include/asm/alternative.h
> +++ b/arch/x86/include/asm/alternative.h
> @@ -8,8 +8,13 @@
>  
>  #define ALT_FLAGS_SHIFT		16
>  
> -#define ALT_FLAG_NOT		(1 << 0)
> +/* Negate the tested feature flag */
> +#define ALT_FLAG_NOT		BIT(0)
> +/* Check X86_VENDOR_* instead of a feature flag */
> +#define	ALT_FLAG_VENDOR		BIT(1)
> +
>  #define ALT_NOT(feature)	((ALT_FLAG_NOT << ALT_FLAGS_SHIFT) | (feature))
> +#define ALT_VENDOR(x86_vendor)	((ALT_FLAG_VENDOR << ALT_FLAGS_SHIFT) | (x86_vendor))
>  
>  #ifndef __ASSEMBLY__
>  
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index 73be3931e4f0..8b67b5c6090e 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -433,19 +433,23 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
>  
>  		/*
>  		 * Patch if either:
> +		 * - running on the respective x86 vendor
>  		 * - feature is present
>  		 * - feature not present but ALT_FLAG_NOT is set to mean,
>  		 *   patch if feature is *NOT* present.
>  		 */
> -		if (!boot_cpu_has(a->cpuid) == !(a->flags & ALT_FLAG_NOT)) {
> +		if (a->flags & ALT_FLAG_VENDOR) {
> +			if (boot_cpu_data.x86_vendor != a->cpuid) {
> +				optimize_nops(instr, a->instrlen);
> +				continue;
> +			}
> +		} else if (!boot_cpu_has(a->cpuid) == !(a->flags & ALT_FLAG_NOT)) {
>  			optimize_nops(instr, a->instrlen);
>  			continue;
>  		}

But what if I want to do ALT_FLAG_VENDOR | ALT_FLAG_NOT?

/me runs

  parent reply	other threads:[~2023-10-27 18:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22  9:52 [PATCH] x86/barrier: Do not serialize MSR accesses on AMD Borislav Petkov
2023-07-03 12:54 ` Peter Zijlstra
2023-07-04  7:46   ` Borislav Petkov
2023-07-04  9:01     ` Peter Zijlstra
2023-07-04  9:22       ` Borislav Petkov
     [not found]         ` <20231027153327.GKZTvYR3qslaTUjtCT@fat_crate.local>
     [not found]           ` <20231027153418.GLZTvYejCkXb03rArO@fat_crate.local>
2023-10-27 18:11             ` Peter Zijlstra [this message]
2023-10-27 18:25               ` [PATCH 1/2] x86/alternative: Add per-vendor patching Borislav Petkov
     [not found]           ` <20231027153458.GMZTvYou1tlK6HD8/Y@fat_crate.local>
2023-10-27 18:56             ` [PATCH 2/2] x86/barrier: Do not serialize MSR accesses on AMD Peter Zijlstra
2023-10-27 19:16               ` Borislav Petkov
2023-10-27 19:29                 ` Borislav Petkov
2023-10-27 20:09                   ` Andrew Cooper
2023-10-27 20:23                     ` Borislav Petkov
2023-10-29 10:35                       ` [PATCH -v3] " Borislav Petkov
2023-11-02 11:08                     ` [PATCH 2/2] " Borislav Petkov
2023-11-13  8:56 ` [tip: x86/cpu] " tip-bot2 for Borislav Petkov (AMD)
2023-11-13  9:21 ` tip-bot2 for Borislav Petkov (AMD)

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=20231027181147.GC26550@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Kishon.VijayAbraham@amd.com \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --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