Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2276888ybh; Fri, 17 Jul 2020 13:53:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyokRaqOo00ygypKY3YX9oLwITmFY5qwrEsKr6FjpH6IbxQt2RK2N3nlKVoWR+7EGhyU+cg X-Received: by 2002:a17:906:1986:: with SMTP id g6mr10876642ejd.404.1595019211925; Fri, 17 Jul 2020 13:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595019211; cv=none; d=google.com; s=arc-20160816; b=rKHJ1Vnbk5LVnFexbDpivqNYODZKsSLBFF6lG3QanYGVqBUtrpUrI+5lydf0GSw9W4 BnuenwCQYNBGok0nCwMrETvT7Wzt5R0dHUr4udU012xzcUKTnA6ze+P9RB4IRCsEm3hG n+XhQMAk3T6XJocWjGbIkG8p/+/V0eL2CMfiDbTrwCa9uzRXqVInKPmtKYtQGgedh2r2 9P7WXFYs0NZtBjBbO27a5YA+iRw8BiTeYP1sKwVtL2IR/syEiOsmowb2vcl2Dgz8z3Xp 4olcjt3lb9x0bg7H8oDQYxWIL67tU/OIgQ3UJMH3hrVeD8wSmQd7WgNYH1E+BktFupd1 G8Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=TgH632fxuwZ97MtCO+VvOuwH+Ug7r/MkqNNXVmK2kx8=; b=QPpTH4wAGWKcxui8Jrw5urhut1N3dp4YvY2gVBGPwD+WvaCkyXb23una8ufLbm8dER tyO9f4U8guTokpb+WarIob+5Xeqjrjb7c+l9C6izcSFhL0+1dyHn+OzBAmosh/Wzssoe EHWgHmW7sdkAAM9fcAUCU39qhbYCJsTZ7xepBRykIhWDpETVaH89SNi5VYJ2OReXANZW MtIkMoq1n54tEbYaT1PnyaAL5P9+2FA8r80K+CA96jn/m5tZeGgvlfjAR5o9sz3yPUkm OL9xZaBHjhrMI5JccU+BpCAHwGErufLV1wkBEBfv9/hzarrTseJ86jzMY1wMO1ZEulSc mSdg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si5854245eje.309.2020.07.17.13.53.08; Fri, 17 Jul 2020 13:53:31 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbgGQUw5 (ORCPT + 99 others); Fri, 17 Jul 2020 16:52:57 -0400 Received: from mga02.intel.com ([134.134.136.20]:46328 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbgGQUw4 (ORCPT ); Fri, 17 Jul 2020 16:52:56 -0400 IronPort-SDR: ccA0VIC++hRfB2yVjVzT0UNATUk+loJD2acJHKdhTFZ4OKGwpEK+F83LJq+fQWDJm9Ked4c9Mb kMNsLfgJyHVg== X-IronPort-AV: E=McAfee;i="6000,8403,9685"; a="137785235" X-IronPort-AV: E=Sophos;i="5.75,364,1589266800"; d="scan'208";a="137785235" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2020 13:52:55 -0700 IronPort-SDR: 690U0n6opbZ/Ur7zkVu//anEQ7MRj2sHCRzWpKkvX0jU9VzxrjihvaQr+xK5iBUfhEQqvlrfq5 HGUS8jcEky3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,364,1589266800"; d="scan'208";a="326947980" Received: from iweiny-desk2.sc.intel.com ([10.3.52.147]) by orsmga007.jf.intel.com with ESMTP; 17 Jul 2020 13:52:55 -0700 Date: Fri, 17 Jul 2020 13:52:55 -0700 From: Ira Weiny To: Peter Zijlstra Cc: 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: <20200717205254.GQ3008823@iweiny-DESK2.sc.intel.com> References: <20200717072056.73134-1-ira.weiny@intel.com> <20200717072056.73134-3-ira.weiny@intel.com> <20200717085442.GX10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717085442.GX10769@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.11.1 (2018-12-01) 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 10:54:42AM +0200, Peter Zijlstra wrote: > On Fri, Jul 17, 2020 at 12:20:41AM -0700, ira.weiny@intel.com wrote: > > +/* > > + * Get a new pkey register value from the user values specified. > > + * > > + * Kernel users use the same flags as user space: > > + * PKEY_DISABLE_ACCESS > > + * PKEY_DISABLE_WRITE > > + */ > > +u32 get_new_pkr(u32 old_pkr, int pkey, unsigned long init_val) > > +{ > > + int pkey_shift = (pkey * PKR_BITS_PER_PKEY); > > + u32 new_pkr_bits = 0; > > + > > + /* Set the bits we need in the register: */ > > + if (init_val & PKEY_DISABLE_ACCESS) > > + new_pkr_bits |= PKR_AD_BIT; > > + if (init_val & PKEY_DISABLE_WRITE) > > + new_pkr_bits |= PKR_WD_BIT; > > + > > + /* Shift the bits in to the correct place: */ > > + new_pkr_bits <<= pkey_shift; > > + > > + /* Mask off any old bits in place: */ > > + old_pkr &= ~((PKR_AD_BIT | PKR_WD_BIT) << pkey_shift); > > + > > + /* Return the old part along with the new part: */ > > + return old_pkr | new_pkr_bits; > > +} > > This is unbelievable junk... > > 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. On the code I think this is fair. I've also updated the calling function to be a bit cleaner as well. However, I think the name 'update' is a bit misleading. Here is the new calling code: ... pkru = read_pkru(); pkru = update_pkey_reg(pkru, pkey, init_val); write_pkru(pkru); ... I think it is odd to have a function called update_pkey_reg() called right before a write_pkru(). Can we call this update_pkey_value? or just 'val'? Because write_pkru() actually updates the register. Thanks for the review, Ira