Re: [PATCH 1/4] pkeys: add API to switch to permissive pkey register
From: Dmitry Vyukov
Date: Mon Feb 24 2025 - 08:28:49 EST
On Fri, 21 Feb 2025 at 18:01, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
>
> On 2/17/25 03:07, Dmitry Vyukov wrote:
> ...
> > /*
> > * If more than 16 keys are ever supported, a thorough audit
> > * will be necessary to ensure that the types that store key
> > @@ -123,4 +125,16 @@ static inline int vma_pkey(struct vm_area_struct *vma)
> > return (vma->vm_flags & vma_pkey_mask) >> VM_PKEY_SHIFT;
> > }
> >
> > +typedef u32 pkey_reg_t;
> > +
> > +static inline pkey_reg_t switch_to_permissive_pkey_reg(void)
> > +{
> > + return write_pkru(0);
> > +}
>
> Just a naming nit: the "switch_to" and "reg" parts of this don't quite
> parse for me. This is writing a _value_ to a register. Maybe:
>
> write_permissive_pkey_val()
> or
> set_permissive_pkey_val()
>
> would be a better name.
Changed them to write_permissive_pkey_val/write_pkey_val in v4.
> > diff --git a/include/linux/pkeys.h b/include/linux/pkeys.h
> > index 86be8bf27b41b..d94a0ae7a784b 100644
> > --- a/include/linux/pkeys.h
> > +++ b/include/linux/pkeys.h
> > @@ -48,4 +48,26 @@ static inline bool arch_pkeys_enabled(void)
> >
> > #endif /* ! CONFIG_ARCH_HAS_PKEYS */
> >
> > +#ifndef CONFIG_ARCH_HAS_PERMISSIVE_PKEY
> > +
> > +/*
> > + * Common name for value of the register that controls access to PKEYs
> > + * (called differently on different arches: PKRU, POR, AMR).
> > + */
> > +typedef int pkey_reg_t;
> Tiny nit: Should this be an unsigned type?
>
> Nobody should be manipulating it, but I'd be surprised if any of the
> architectures have a signed type for it.
Since this is a stub type, can matching the real types do any good
besides masking programming errors?
I've changed it to char in v4 to surface more potential programming errors.