diff mbox series

[5/5] x86/pkeys: Standardize on u8 for pkey type

Message ID 20220311005742.1060992-6-ira.weiny@intel.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series Pkey User clean up patches | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.

Commit Message

Ira Weiny March 11, 2022, 12:57 a.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

The number of pkeys supported on x86 and powerpc are much smaller than a
u16 value can hold.  It is desirable to standardize on the type for
pkeys.  powerpc currently supports the most pkeys at 32.  u8 is plenty
large for that.

Standardize on the pkey types by changing u16 to u8.

To: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 arch/x86/include/asm/pgtable.h | 4 ++--
 arch/x86/include/asm/pkru.h    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Dave Hansen March 14, 2022, 11:49 p.m. UTC | #1
On 3/10/22 16:57, ira.weiny@intel.com wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> The number of pkeys supported on x86 and powerpc are much smaller than a
> u16 value can hold.  It is desirable to standardize on the type for
> pkeys.  powerpc currently supports the most pkeys at 32.  u8 is plenty
> large for that.
> 
> Standardize on the pkey types by changing u16 to u8.

How widely was this intended to "standardize" things?  Looks like it may
have missed a few spots.

Also if we're worried about the type needing to change or with the wrong
type being used, I guess we could just to a pkey_t typedef.
Ira Weiny March 15, 2022, 3:53 p.m. UTC | #2
On Mon, Mar 14, 2022 at 04:49:12PM -0700, Dave Hansen wrote:
> On 3/10/22 16:57, ira.weiny@intel.com wrote:
> > From: Ira Weiny <ira.weiny@intel.com>
> > 
> > The number of pkeys supported on x86 and powerpc are much smaller than a
> > u16 value can hold.  It is desirable to standardize on the type for
> > pkeys.  powerpc currently supports the most pkeys at 32.  u8 is plenty
> > large for that.
> > 
> > Standardize on the pkey types by changing u16 to u8.
> 
> How widely was this intended to "standardize" things?  Looks like it may
> have missed a few spots.

Sorry I think the commit message is misleading you.  The justification of u8 as
the proper type is that no arch has a need for more than 255 pkeys.

This specific patch was intended to only change x86.  Per that goal I don't see
any other places in x86 which uses u16 after this patch.

$ git grep u16 arch/x86 | grep key
arch/x86/events/intel/uncore_discovery.c:	const u16 *type_id = key;
arch/x86/include/asm/intel_pconfig.h:	u16 keyid;
arch/x86/include/asm/mmu.h:	u16 pkey_allocation_map;
arch/x86/include/asm/pkeys.h:	u16 all_pkeys_mask = ((1U << arch_max_pkey()) - 1);

> 
> Also if we're worried about the type needing to change or with the wrong
> type being used, I guess we could just to a pkey_t typedef.

I'm not 'worried' about it.  But I do think it makes the code cleaner and more
self documenting.

Ira
Dave Hansen March 15, 2022, 4:03 p.m. UTC | #3
On 3/15/22 08:53, Ira Weiny wrote:
> On Mon, Mar 14, 2022 at 04:49:12PM -0700, Dave Hansen wrote:
>> On 3/10/22 16:57, ira.weiny@intel.com wrote:
>>> From: Ira Weiny <ira.weiny@intel.com>
>>>
>>> The number of pkeys supported on x86 and powerpc are much smaller than a
>>> u16 value can hold.  It is desirable to standardize on the type for
>>> pkeys.  powerpc currently supports the most pkeys at 32.  u8 is plenty
>>> large for that.
>>>
>>> Standardize on the pkey types by changing u16 to u8.
>>
>> How widely was this intended to "standardize" things?  Looks like it may
>> have missed a few spots.
> 
> Sorry I think the commit message is misleading you.  The justification of u8 as
> the proper type is that no arch has a need for more than 255 pkeys.
> 
> This specific patch was intended to only change x86.  Per that goal I don't see
> any other places in x86 which uses u16 after this patch.
> 
> $ git grep u16 arch/x86 | grep key
> arch/x86/events/intel/uncore_discovery.c:	const u16 *type_id = key;
> arch/x86/include/asm/intel_pconfig.h:	u16 keyid;
> arch/x86/include/asm/mmu.h:	u16 pkey_allocation_map;
> arch/x86/include/asm/pkeys.h:	u16 all_pkeys_mask = ((1U << arch_max_pkey()) - 1);

I was also looking at the generic mm code.

>> Also if we're worried about the type needing to changY or with the wrong
>> type being used, I guess we could just to a pkey_t typedef.
> 
> I'm not 'worried' about it.  But I do think it makes the code cleaner and more
> self documenting.

Yeah, consistency is good.  Do you mind taking a look at how a pkey_t
would look, and also seeing how much core mm code should use it?
Ira Weiny March 15, 2022, 4:57 p.m. UTC | #4
On Tue, Mar 15, 2022 at 09:03:26AM -0700, Dave Hansen wrote:
> On 3/15/22 08:53, Ira Weiny wrote:
> > On Mon, Mar 14, 2022 at 04:49:12PM -0700, Dave Hansen wrote:
> >> On 3/10/22 16:57, ira.weiny@intel.com wrote:
> >>> From: Ira Weiny <ira.weiny@intel.com>
> >>>
> >>> The number of pkeys supported on x86 and powerpc are much smaller than a
> >>> u16 value can hold.  It is desirable to standardize on the type for
> >>> pkeys.  powerpc currently supports the most pkeys at 32.  u8 is plenty
> >>> large for that.
> >>>
> >>> Standardize on the pkey types by changing u16 to u8.
> >>
> >> How widely was this intended to "standardize" things?  Looks like it may
> >> have missed a few spots.
> > 
> > Sorry I think the commit message is misleading you.  The justification of u8 as
> > the proper type is that no arch has a need for more than 255 pkeys.
> > 
> > This specific patch was intended to only change x86.  Per that goal I don't see
> > any other places in x86 which uses u16 after this patch.
> > 
> > $ git grep u16 arch/x86 | grep key
> > arch/x86/events/intel/uncore_discovery.c:	const u16 *type_id = key;
> > arch/x86/include/asm/intel_pconfig.h:	u16 keyid;
> > arch/x86/include/asm/mmu.h:	u16 pkey_allocation_map;
> > arch/x86/include/asm/pkeys.h:	u16 all_pkeys_mask = ((1U << arch_max_pkey()) - 1);
> 
> I was also looking at the generic mm code.

Ah yea that needs to be sorted out too I think.

> 
> >> Also if we're worried about the type needing to changY or with the wrong
> >> type being used, I guess we could just to a pkey_t typedef.
> > 
> > I'm not 'worried' about it.  But I do think it makes the code cleaner and more
> > self documenting.
> 
> Yeah, consistency is good.  Do you mind taking a look at how a pkey_t
> would look, and also seeing how much core mm code should use it?

I don't mind at all.

Ira
diff mbox series

Patch

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 8a9432fb3802..cb89f1224d8a 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1357,7 +1357,7 @@  static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd)
 }
 #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */
 
-static inline u16 pte_flags_pkey(unsigned long pte_flags)
+static inline u8 pte_flags_pkey(unsigned long pte_flags)
 {
 #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
 	/* ifdef to avoid doing 59-bit shift on 32-bit values */
@@ -1367,7 +1367,7 @@  static inline u16 pte_flags_pkey(unsigned long pte_flags)
 #endif
 }
 
-static inline bool __pkru_allows_pkey(u16 pkey, bool write)
+static inline bool __pkru_allows_pkey(u8 pkey, bool write)
 {
 	u32 pkru = read_pkru();
 
diff --git a/arch/x86/include/asm/pkru.h b/arch/x86/include/asm/pkru.h
index 74f0a2d34ffd..06d088f06229 100644
--- a/arch/x86/include/asm/pkru.h
+++ b/arch/x86/include/asm/pkru.h
@@ -16,13 +16,13 @@  extern u32 init_pkru_value;
 #define pkru_get_init_value()	0
 #endif
 
-static inline bool __pkru_allows_read(u32 pkru, u16 pkey)
+static inline bool __pkru_allows_read(u32 pkru, u8 pkey)
 {
 	int pkru_pkey_bits = pkey * PKRU_BITS_PER_PKEY;
 	return !(pkru & (PKRU_AD_BIT << pkru_pkey_bits));
 }
 
-static inline bool __pkru_allows_write(u32 pkru, u16 pkey)
+static inline bool __pkru_allows_write(u32 pkru, u8 pkey)
 {
 	int pkru_pkey_bits = pkey * PKRU_BITS_PER_PKEY;
 	/*