[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211208005106.GJ3538886@iweiny-DESK2.sc.intel.com>
Date: Tue, 7 Dec 2021 16:51:06 -0800
From: Ira Weiny <ira.weiny@...el.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>,
Dan Williams <dan.j.williams@...el.com>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Peter Zijlstra <peterz@...radead.org>,
Andy Lutomirski <luto@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>,
Fenghua Yu <fenghua.yu@...el.com>,
Rick Edgecombe <rick.p.edgecombe@...el.com>, x86@...nel.org,
linux-kernel@...r.kernel.org, nvdimm@...ts.linux.dev,
linux-mm@...ck.org
Subject: Re: [PATCH V7 03/18] x86/pks: Add additional PKEY helper macros
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
Powered by blists - more mailing lists