Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1593338ybh; Mon, 20 Jul 2020 02:14:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW6LYhTUzmLf9vsgHl3QfKXUPn/qRF6FsY+pNvC/hxj9y4chA2IbMYnA4qADMX4BgRqErE X-Received: by 2002:a17:906:6d4d:: with SMTP id a13mr19249164ejt.146.1595236489654; Mon, 20 Jul 2020 02:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595236489; cv=none; d=google.com; s=arc-20160816; b=Se0Q2vS5BoupBBCDymUGj4qCyil76BPoRsbyPr4JaQup3nfsFFMxKygTCLK2YtjZjU 0WSUU2+/wi5uFmn5jNRzVcBeC0JfzoiNDefHwRBRrIywOemsijazS6orW311vhgyP7y4 //Qs8ZElfXCNfSpUyJWI3p+ybblnEaGxJuEK/TTxSIe6gGdOOMWfITLu1hvVXsZhYX27 KGj5jfGf5vFhFcAOcxvd9Ioqvxb/dlh5KfqwHqmOn/R35vz7dnv/RBqTyHzY+SaTku5C yaxgBLeSNuozLZYVgix8FseUulP5PAESGklwDmILuG9zTV4wPEMRhctrR81HfbqDkCzr +NqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=5tslci/TZCCd1TbRC9GV4KEBZulaQ3nrLO1vcSVnALA=; b=u9eUt8A32g2TDcjrUVh2PQApAVNcLCuZDgSqOrNv+9emWvZZI/IhpLnDDCR8WLW9io +vYayL4W62W/yNvDdgUUAs7WLMMluzW0IFazgKdmR3wXEQnMv3QICnrJBhAc9Nmkr8ax 2Wer+hV+bRwMSr6O1/LIDtoMkejtv6FZr0NY3kuWzzRYAqfmkiaLpVa2OBvGC4q2EcgX H22b83OYyIGn9ScGTjp1CG822Dt5mcu2rSCtgVlxQMyufxmAZ8Lp/1C32491I0ziWTCw FgLIzSHaez3Qi0wSXVb755NOgWS55TIlsgbdOH/rRM3sP5a8ZJpSzP/FYYamJVgQvWX4 6M6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="yeDA/fpz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si10280231eds.487.2020.07.20.02.14.26; Mon, 20 Jul 2020 02:14:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="yeDA/fpz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbgGTJOR (ORCPT + 99 others); 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.