On Thu, Nov 25, 2021 at 03:25:09PM +0100, Thomas Gleixner wrote: > On Tue, Aug 03 2021 at 21:32, ira weiny wrote: > > @@ -200,16 +200,14 @@ __setup("init_pkru=", setup_init_pkru); > > */ > > u32 update_pkey_val(u32 pk_reg, int pkey, unsigned int flags) > > { > > - int pkey_shift = pkey * PKR_BITS_PER_PKEY; > > - > > /* Mask out old bit values */ > > - pk_reg &= ~(((1 << PKR_BITS_PER_PKEY) - 1) << pkey_shift); > > + pk_reg &= ~PKR_PKEY_MASK(pkey); > > > > /* Or in new values */ > > if (flags & PKEY_DISABLE_ACCESS) > > - pk_reg |= PKR_AD_BIT << pkey_shift; > > + pk_reg |= PKR_AD_KEY(pkey); > > if (flags & PKEY_DISABLE_WRITE) > > - pk_reg |= PKR_WD_BIT << pkey_shift; > > + pk_reg |= PKR_WD_KEY(pkey); > > I'm not seeing how this is improving that code. Quite the contrary. Fair enough. Even more so when using the code you suggested for pkey_update_pkval(). In that case it boils down to: diff --git a/arch/x86/mm/pkeys.c b/arch/x86/mm/pkeys.c index eb6d6b872652..b7127329d115 100644 --- a/arch/x86/mm/pkeys.c +++ b/arch/x86/mm/pkeys.c @@ -198,7 +198,7 @@ __setup("init_pkru=", setup_init_pkru); */ u32 pkey_update_pkval(u32 pkval, int pkey, u32 accessbits) { - int shift = pkey * PKR_BITS_PER_PKEY; + int shift = PKR_PKEY_SHIFT(pkey); if (WARN_ON_ONCE(accessbits & ~PKEY_ACCESS_MASK)) accessbits &= PKEY_ACCESS_MASK; Better? As to the reason of why to put this patch after the other one. Why would I improve the old pre-refactoring code only to throw it away when moving it to pkey_update_pkval()? This reasoning is even stronger when pkey_update_pkval() is implemented. I agree with Dan regarding the macros though. I think they make it easier to see what is going on without dealing with masks and shifts directly. But I can remove this patch if you feel that strongly about it. Ira > > Thanks, > > tglx