Re: [PATCH v4 1/2] x86, lib: Add WBNOINVD helper functions

Dave Hansen
2025-01-22T23:16:38Z

On 1/22/25 11:39, Tom Lendacky wrote:
>> I think you need to do something like.
>>
>> alternative("wbinvd", ".byte 0xf3; wbinvd", X86_FEATURE_WBNOINVD);
> I think "rep; wbinvd" would work as well.

I don't want to bike shed this too much.

But, please, no.

The fact that wbnoinvd can be expressed as "rep; wbinvd" is a
implementation detail. Exposing how it's encoded in the ISA is only
going to add confusion. This:

static __always_inline void wbnoinvd(void)
{
asm volatile(".byte 0xf3,0x0f,0x09\n\t": : :"memory");
}

is perfectly fine and a billion times less confusing than:

asm volatile(".byte 0xf3; wbinvd\n\t": : :"memory");
or
asm volatile("rep; wbinvd\n\t": : :"memory");

It only gets worse if it's mixed in an alternative() with the _actual_
wbinvd.

BTW, I don't think you should be compelled to use alternative() as
opposed to a good old:

if (cpu_feature_enabled(X86_FEATURE_WBNOINVD))
...