Return-Path: Received: from mail.linutronix.de (193.142.43.55:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 26 Sep 2019 00:51:29 -0000 Received: from mga04.intel.com ([192.55.52.120]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iDI0G-00052n-2p for speck@linutronix.de; Thu, 26 Sep 2019 02:51:28 +0200 Date: Wed, 25 Sep 2019 17:46:00 -0700 From: Pawan Gupta Subject: [MODERATED] Re: [PATCH v4 02/10] TAAv4 2 Message-ID: <20190926004559.GB16811@guptapadev.amr> References: <20190904055406.GA7212@kroah.com> <20190904074326.GB1321@guptapadev.amr> <20190925221319.5h4c3os5ptm6iaft@treble> MIME-Version: 1.0 In-Reply-To: <20190925221319.5h4c3os5ptm6iaft@treble> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Wed, Sep 25, 2019 at 05:13:19PM -0500, speck for Josh Poimboeuf wrote: > On Fri, Sep 06, 2019 at 02:07:12PM -0700, speck for Dave Hansen wrote: > > On 9/4/19 12:43 AM, speck for Pawan Gupta wrote: > > > On Wed, Sep 04, 2019 at 07:54:06AM +0200, speck for Greg KH wrote: > > >>> +static void tsx_ctrl_check_support(struct cpuinfo_x86 *c) > > >>> +{ > > >>> + u64 ia32_cap = 0; > > >>> + > > >>> + if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES)) > > >>> + rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); > > >>> + > > >>> + if (!(ia32_cap & ARCH_CAP_TSX_CTRL_MSR)) > > >>> + tsx_ctrl_state = TSX_CTRL_NOT_SUPPORTED; > > >> Why isn't this if statement under the if statement above? > > > Because we still have to set tsx_ctrl_state when cpu doesn't support > > > X86_FEATURE_ARCH_CAPABILITIES. > > > > FWIW, I struggled to read this the first time I read it, too. It might > > make sense to break it up like this: > > > > u64 read_ia32_arch_cap(void) > > { > > u64 ia32_cap = 0; > > > > /* Leave the MSR set to all 0's when not supported */ > > if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES)) > > rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); > > > > return ia32_cap; > > } > > > > You could even replace the other places that we read the MSR. They have > > the same pattern. Then do: > > > > static void tsx_ctrl_check_support(struct cpuinfo_x86 *c) > > { > > u64 ia32_cap = read_ia32_arch_cap(); > > > > if (ia32_cap & ARCH_CAP_TSX_CTRL_MSR) > > tsx_ctrl_state = TSX_CTRL_ENABLE; > > } > > > > which takes tsx_ctrl_state out of the 'disable' mode. > > I think it would be even clearer if the compile-time default were > changed to TSX_CTRL_NOT_SUPPORTED. > > Then the logic would be less confusing. For example the reader of the > code doesn't have to remember that ia32_cap is initialized to zero. And > IMO, "not supported" conceptually makes the most sense as a compile-time > default anyway. > > static void tsx_ctrl_check_support(struct cpuinfo_x86 *c) > { > u64 ia32_cap; > > if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES)) { > rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); > > if (ia32_cap & ARCH_CAP_TSX_CTRL_MSR) > tsx_ctrl_state = TSX_CTRL_DISABLE; Below is the order in which tsx_ctrl_state can be modified: 1. Compile time 2. Cmdline parsing (early_param()) 3. TSX_CTRL MSR support check (tsx_ctrl_check_support()) Here we need to handle tsx=on case as well. If we set tsx_ctrl_state to ENABLE/DISABLE in tsx_ctrl_check_support() we could override what user asked for via cmdline. Unless we keep another copy of tsx_ctrl_state, which might add more complexity. I believe tsx_ctrl_check_support() should only change state to NOT_SUPPORTED when TSX_CTRL MSR is not supported. Thanks, Pawan