On 10/9/20 12:42 PM, ira.weiny@xxxxxxxxx wrote: > Protection Keys User (PKU) and Protection Keys Supervisor (PKS) work > in similar fashions and can share common defines. Could we be a bit less abstract? PKS and PKU each have: 1. A single control register 2. The same number of keys 3. The same number of bits in the register per key 4. Access and Write disable in the same bit locations That means that we can share all the macros that synthesize and manipulate register values between the two features. > +++ b/arch/x86/include/asm/pkeys_common.h > @@ -0,0 +1,11 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_PKEYS_INTERNAL_H > +#define _ASM_X86_PKEYS_INTERNAL_H > + > +#define PKR_AD_BIT 0x1 > +#define PKR_WD_BIT 0x2 > +#define PKR_BITS_PER_PKEY 2 > + > +#define PKR_AD_KEY(pkey) (PKR_AD_BIT << ((pkey) * PKR_BITS_PER_PKEY)) Now that this has moved away from its use-site, it's a bit less self-documenting. Let's add a comment: /* * Generate an Access-Disable mask for the given pkey. Several of these * can be OR'd together to generate pkey register values. */ Once that's in place, along with the updated changelog: Reviewed-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>