From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3990C433EF for ; Wed, 8 Dec 2021 06:11:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B87C6B0071; Wed, 8 Dec 2021 01:10:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1684D6B0073; Wed, 8 Dec 2021 01:10:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02F1C6B0074; Wed, 8 Dec 2021 01:10:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay032.a.hostedemail.com [64.99.140.32]) by kanga.kvack.org (Postfix) with ESMTP id E48486B0071 for ; Wed, 8 Dec 2021 01:10:50 -0500 (EST) Received: by unirelay02.hostedemail.com (Postfix, from userid 108) id 62E86202A6; Wed, 8 Dec 2021 05:33:00 +0000 (UTC) Received: by unirelay02.hostedemail.com (Postfix, from userid 108) id 14D83206EB; Wed, 8 Dec 2021 02:23:59 +0000 (UTC) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B9B0320F16 for ; Wed, 8 Dec 2021 00:51:09 +0000 (UTC) X-FDA: 78892797858.01.A1471AF Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf23.hostedemail.com (Postfix) with ESMTP id B3172900009B for ; Wed, 8 Dec 2021 00:51:08 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10191"; a="218410304" X-IronPort-AV: E=Sophos;i="5.87,295,1631602800"; d="scan'208";a="218410304" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2021 16:51:07 -0800 X-IronPort-AV: E=Sophos;i="5.87,295,1631602800"; d="scan'208";a="580353148" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2021 16:51:07 -0800 Date: Tue, 7 Dec 2021 16:51:06 -0800 From: Ira Weiny To: Thomas Gleixner Cc: Dave Hansen , Dan Williams , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , "H. Peter Anvin" , Fenghua Yu , Rick Edgecombe , x86@kernel.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-mm@kvack.org Subject: Re: [PATCH V7 03/18] x86/pks: Add additional PKEY helper macros Message-ID: <20211208005106.GJ3538886@iweiny-DESK2.sc.intel.com> References: <20210804043231.2655537-1-ira.weiny@intel.com> <20210804043231.2655537-4-ira.weiny@intel.com> <87lf1cl3cq.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lf1cl3cq.ffs@tglx> User-Agent: Mutt/1.11.1 (2018-12-01) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B3172900009B X-Stat-Signature: jqgnxqsuc7md33kxtgfke37wbhcsqsij Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf23.hostedemail.com: domain of ira.weiny@intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=ira.weiny@intel.com X-HE-Tag: 1638924668-273022 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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