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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE00DC433E6 for ; Mon, 20 Jul 2020 09:14:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 93C9E2080D for ; Mon, 20 Jul 2020 09:14:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="yeDA/fpz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93C9E2080D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 205836B0003; Mon, 20 Jul 2020 05:14:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18F7F6B0005; Mon, 20 Jul 2020 05:14:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 055216B0006; Mon, 20 Jul 2020 05:14:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id E02FD6B0003 for ; Mon, 20 Jul 2020 05:14:09 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8787E18327DD5 for ; Mon, 20 Jul 2020 09:14:09 +0000 (UTC) X-FDA: 77057892618.11.robin46_4113bda26f23 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 3A123184875BA for ; Mon, 20 Jul 2020 09:14:09 +0000 (UTC) X-HE-Tag: robin46_4113bda26f23 X-Filterd-Recvd-Size: 4302 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Jul 2020 09:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5tslci/TZCCd1TbRC9GV4KEBZulaQ3nrLO1vcSVnALA=; b=yeDA/fpzF7U+Gx0dfEISR0uEJP 34s0go7buhwmKs+qfROqytezUisi+mIVzYOopOlh7jd8hd/A8NmwGJQP62l4fkskjxzgP/3Zr1kP3 fpHrpD6jAStfySdu8sisLTHK+VawELwg5EH1SUKP6Xf0R4hV+bVaGJZcMkTltk5GAq1RCzgJtgDXj 6p7px9Fk/TED3Wn0qRz89MByrHWQJ34kMcQyS6gnFlqMxVmyFWWBYZjWrGeyUinopPED96tPKbEX5 haGFO6Ts4sH3KLy4rA0v0lyercBCENxzUu284Q6fY9ISQ0j0a5yKEvG4vJQ1vA9MDW5QjZaiEXI61 hHxtIL+A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxRrz-0005aJ-SK; Mon, 20 Jul 2020 09:14:00 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 223193010C8; Mon, 20 Jul 2020 11:13:57 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 00B3A23646C00; Mon, 20 Jul 2020 11:13:56 +0200 (CEST) Date: Mon, 20 Jul 2020 11:13:56 +0200 From: Peter Zijlstra To: Dave Hansen Cc: ira.weiny@intel.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Fenghua Yu , x86@kernel.org, Dave Hansen , Dan Williams , Vishal Verma , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH RFC V2 02/17] x86/fpu: Refactor arch_set_user_pkey_access() for PKS support Message-ID: <20200720091356.GL10769@hirez.programming.kicks-ass.net> References: <20200717072056.73134-1-ira.weiny@intel.com> <20200717072056.73134-3-ira.weiny@intel.com> <20200717085442.GX10769@hirez.programming.kicks-ass.net> <1f9586df-cabb-c743-1eeb-f44c73459fb5@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1f9586df-cabb-c743-1eeb-f44c73459fb5@intel.com> X-Rspamd-Queue-Id: 3A123184875BA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 Fri, Jul 17, 2020 at 03:36:12PM -0700, Dave Hansen wrote: > On 7/17/20 1:54 AM, Peter Zijlstra wrote: > > This is unbelievable junk... > > Ouch! > > This is from the original user pkeys implementation. The thing I fell over most was new in this patch; the naming of that function. It doesn't 'get' anything, nor does it allocate anything, so 'new' is out the window too. > > How about something like: > > > > u32 update_pkey_reg(u32 pk_reg, int pkey, unsigned int flags) > > { > > int pkey_shift = pkey * PKR_BITS_PER_PKEY; > > > > pk_reg &= ~(((1 << PKR_BITS_PER_PKEY) - 1) << pkey_shift); > > > > if (flags & PKEY_DISABLE_ACCESS) > > pk_reg |= PKR_AD_BIT << pkey_shift; > > if (flags & PKEY_DISABLE_WRITE) > > pk_reg |= PKR_WD_BIT << pkey_shift; > > > > return pk_reg; > > } > > > > Then we at least have a little clue wtf the thing does.. Yes I started > > with a rename and then got annoyed at the implementation too. > > That's fine, if some comments get added. I'm not sure what you would want commented; the code is trivial. > It looks correct to me but > probably compiles down to pretty much the same thing as what was there. > FWIW, I prefer the explicit masking off of two bit values to implicit > masking off with a mask generated from PKR_BITS_PER_PKEY. It's > certainly more compact, but I usually don't fret over the lines of code. This way you're sure there are no bits missed. Both the shift and mask use the same value.