[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250930083137.GH3245006@noisy.programming.kicks-ass.net>
Date: Tue, 30 Sep 2025 10:31:37 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Juergen Gross <jgross@...e.com>
Cc: linux-kernel@...r.kernel.org, x86@...nel.org, llvm@...ts.linux.dev,
xin@...or.com, "H. Peter Anvin" <hpa@...or.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>
Subject: Re: [PATCH v2 09/12] x86/msr: Use the alternatives mechanism for
WRMSR
On Tue, Sep 30, 2025 at 09:03:53AM +0200, Juergen Gross wrote:
> +static __always_inline bool __wrmsrq_constant(u32 msr, u64 val, int type)
> +{
> + BUILD_BUG_ON(!__builtin_constant_p(msr));
> +
> + asm_inline volatile goto(
> + "1:\n"
> + ALTERNATIVE_2(PREPARE_RCX_RDX_FOR_WRMSR
> + "2: ds wrmsr",
> + PREPARE_RCX_RDX_FOR_WRMSR
> + ASM_WRMSRNS,
> + X86_FEATURE_WRMSRNS,
> + ASM_WRMSRNS_IMM,
> + X86_FEATURE_MSR_IMM)
> + _ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) /* For WRMSRNS immediate */
> + _ASM_EXTABLE_TYPE(2b, %l[badmsr], %c[type]) /* For WRMSR(NS) */
> +
> + :
> + : [val] "a" (val), [msr] "i" (msr), [type] "i" (type)
> + : "memory", "ecx", "rdx"
> + : badmsr);
> +
> + return false;
> +
> +badmsr:
> + return true;
> +}
Just wondering, would something this work?
asm_inline volatile goto(
"1:\n"
ALTERNATIVE(PREPARE_RCX_RDX_FOR_WRMSR
"2:\n"
ALTERNATIVE("ds wrmsr",
ASM_WRMSRNS, X86_FEATURE_WRMSRNS),
ASM_WRMSRNS_IMM, X86_FEATURE_MSR_IMM);
_ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) /* For WRMSRNS immediate */
_ASM_EXTABLE_TYPE(2b, %l[badmsr], %c[type]) /* For WRMSR(NS) */
:
: [val] "a" (val), [msr] "i" (msr), [type] "i" (type)
: "memory", "ecx", "rdx"
: badmsr);
Its a bit weird because the nested alternative isn't for the exact same
position I suppose. But I find it a more readable form.
Powered by blists - more mailing lists