Re: [PATCH V8 04/44] x86/pkeys: Add additional PKEY helper macros

Ira Weiny
2022-02-02T20:22:02Z

On Fri, Jan 28, 2022 at 02:47:30PM -0800, Dave Hansen wrote:
> On 1/27/22 09:54, ira.weiny@intel.com wrote:
> > +#define PKR_AD_KEY(pkey) (PKR_AD_BIT << PKR_PKEY_SHIFT(pkey))
> > +#define PKR_WD_KEY(pkey) (PKR_WD_BIT << PKR_PKEY_SHIFT(pkey))
>
> I don't _hate_ this, but naming here is wonky for me. PKR_WD_KEY reads
> to me as "pkey register write-disable key", as in, please write-disable
> this key, or maybe "make a write-disable key".

Ok... that is reasonable...

>
> It's generating a mask, so I'd probably name it:
>
> #define PKR_WD_MASK(pkey) (PKR_WD_BIT << PKR_PKEY_SHIFT(pkey))
>
> Which says, "generate a write-disabled mask for this pkey".

I think the confusion comes from me having used these as mask values rather
than what PKR_AD_KEY() was intended to be used for.

In the previous patch PKR_AD_KEY() is used to set up the default user pkey
value...

u32 init_pkru_value = PKR_AD_KEY( 1) | PKR_AD_KEY( 2) | PKR_AD_KEY( 3) |
PKR_AD_KEY( 4) | PKR_AD_KEY( 5) | PKR_AD_KEY( 6) |
PKR_AD_KEY( 7) | PKR_AD_KEY( 8) | PKR_AD_KEY( 9) |
PKR_AD_KEY(10) | PKR_AD_KEY(11) | PKR_AD_KEY(12) |
PKR_AD_KEY(13) | PKR_AD_KEY(14) | PKR_AD_KEY(15);

I'll have to think about it but I don't think I like the following...

u32 init_pkru_value = PKR_AD_MASK( 1) | PKR_AD_MASK( 2) | PKR_AD_MASK( 3) |
PKR_AD_MASK( 4) | PKR_AD_MASK( 5) | PKR_AD_MASK( 6) |
PKR_AD_MASK( 7) | PKR_AD_MASK( 8) | PKR_AD_MASK( 9) |
PKR_AD_MASK(10) | PKR_AD_MASK(11) | PKR_AD_MASK(12) |
PKR_AD_MASK(13) | PKR_AD_MASK(14) | PKR_AD_MASK(15);

It seems odd to me. Does it seem odd to you?

Looking at the final code I think I'm going to just drop the usages in this
patch and add PKR_WD_KEY() where it is used first.

Also, how about PKR_KEY_INIT_{AD|WD|RW}() as a name?

Ira