Re: [PATCH 1/4] x86/asm: inline constant inputs in rdpkru(), wrpkru()
From: Alexey Dobriyan
Date: Fri Mar 07 2025 - 11:20:05 EST
On Thu, Mar 06, 2025 at 01:35:01PM -0800, Dave Hansen wrote:
> On 3/6/25 13:07, Alexey Dobriyan wrote:
> > static inline void wrpkru(u32 pkru)
> > {
> > - u32 ecx = 0, edx = 0;
> > -
> > /*
> > * "wrpkru" instruction. Loads contents in EAX to PKRU,
> > * requires that ecx = edx = 0.
> > */
> > asm volatile(".byte 0x0f,0x01,0xef\n\t"
> > - : : "a" (pkru), "c"(ecx), "d"(edx));
> > + : : "a" (pkru), "c" (0), "d" (0));
> > }
>
> Hey Alexey,
>
> I appreciate the patch. But I do like how it's written currently. I
> honestly kinda wish it went even further and did:
>
> u32 eax = pkru;
I _think_ you can write "eax" (pkru) .
I don't like the comment either. It just reiterates the SDM.
Trailing \n\t too -- they don't do anything in one-liners.
The function is basically:
// wrpkru
asm volatile (
".byte 0x0f,0x01,0xef"
:
: "a" (pkru), "d" (0) , "c" (0)
);