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,URIBL_BLOCKED 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 8976CC433E0 for ; Mon, 20 Jul 2020 09:14:17 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C1C02080D for ; Mon, 20 Jul 2020 09:14:17 +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 5C1C02080D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3FB1D123757CC; Mon, 20 Jul 2020 02:14:17 -0700 (PDT) Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=peterz@infradead.org; receiver= Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 97E54123757C8 for ; Mon, 20 Jul 2020 02:14:15 -0700 (PDT) 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 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-Disposition: inline In-Reply-To: <1f9586df-cabb-c743-1eeb-f44c73459fb5@intel.com> Message-ID-Hash: UPT2R4GBMWTQM6MQIR2CDUQOLU5F5PTJ X-Message-ID-Hash: UPT2R4GBMWTQM6MQIR2CDUQOLU5F5PTJ X-MailFrom: peterz@infradead.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Fenghua Yu , x86@kernel.org, Dave Hansen , 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 X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org 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 E9419C433EB for ; Mon, 20 Jul 2020 09:14:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6A6322482 for ; Mon, 20 Jul 2020 09:14:18 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728006AbgGTJOR (ORCPT ); Mon, 20 Jul 2020 05:14:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbgGTJOQ (ORCPT ); Mon, 20 Jul 2020 05:14:16 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47CCC061794; Mon, 20 Jul 2020 02:14:16 -0700 (PDT) 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.