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 18:02:38 -0000 Received: from mga14.intel.com ([192.55.52.115]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iDY69-0004cv-Kv for speck@linutronix.de; Thu, 26 Sep 2019 20:02:38 +0200 Date: Thu, 26 Sep 2019 10:57:07 -0700 From: Pawan Gupta Subject: [MODERATED] Re: [PATCH v4 03/10] TAAv4 3 Message-ID: <20190926175707.GA23564@guptapadev.amr> References: <5b6df5ee-a5b7-c281-de29-af6544b8abb6@intel.com> <20190906074645.GE13480@guptapadev.amr> <20190925224817.zcmzswojw5tmymul@treble> <20190926011305.GD16811@guptapadev.amr> <20190926023445.afjeaizeloehi6bn@treble> <20190926071554.GA12539@guptapadev.amr> <20190926135409.ki6zrkuyfdspy4r2@treble> MIME-Version: 1.0 In-Reply-To: <20190926135409.ki6zrkuyfdspy4r2@treble> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Thu, Sep 26, 2019 at 08:54:09AM -0500, speck for Josh Poimboeuf wrote: > On Thu, Sep 26, 2019 at 12:15:55AM -0700, speck for Pawan Gupta wrote: > > > Regardless, shouldn't tsx_init() at least be called before > > > cpu_set_bug_bits(), so that X86_BUG_TAA can get set appropriately? > > > > X86_BUG_TAA should be set even when tsx_init() disables TSX. This is to > > indicate that the CPU has the bug but was mitigated by disabling TSX. > > That is why we are calling cpu_set_bug_bits() first to set X86_BUG_TAA > > and then disabling TSX in tsx_init(). Moreover cpu_set_bug_bits() is > > called only by the boot-cpu, and tsx_init() is called per-cpu to disable > > TSX on each CPU. > > Hm, I guess that makes sense. But what if TSX enumeration is disabled > due to a previous kexec? Then the CPUID feature bit (X86_FEATURE_RTM) > won't be set, and thus X86_BUG_TAA won't get set, right? That is correct. > > > If early_init_intel() isn't the right spot, then maybe > > > early_identify_cpu(). > > > > early_identify_cpu() is called for other vendors as well, I think > > init_intel() is the ideal place for calling an Intel specific function. > > Why do we want to move tsx_init() from init_intel()? > > IIUC, the fact that the X86_FEATURE_RTM enumeration can be removed > before kexec means that tsx_init() needs to run early, so that it can > properly detect the enumeration so that X86_BUG_TAA can get set > properly. > > Since tsx_init() can clear X86_FEATURE_RTM even though the CPU supports > it, cpu_set_bug_bits() could check TSX_CTRL_NOT_SUPPORTED instead of > X86_FEATURE_RTM, like: > > if (cpu_has_tsx() && !(ia32_cap & ARCH_CAP_TAA_NO)) > setup_force_cpu_bug(X86_BUG_TAA); > > > where cpu_has_tsx() is just !TSX_CTRL_NOT_SUPPORTED. Yes we need something like this to address kexec like cases where TSX is disabled before the kernel boot. We can probably add a check for TSX_CTRL in cpu_set_bug_bits() as well. cpu_set_bug_bits() { [...] /* * When processor is not mitigated for TAA (TAA_NO=0) set TAA bug when: * - TSX is supported or * - TSX_CTRL is supported * * TSX_CTRL check is needed for cases when TSX could be disabled before * the kernel boot e.g. kexec * TSX_CTRL check alone is not sufficient for cases when the microcode * update is not present; running as guest that don't get TSX_CTRL. */ if ((boot_cpu_has(X86_FEATURE_RTM) || (ia32_cap & ARCH_CAP_TSX_CTRL_MSR)) && !(ia32_cap & ARCH_CAP_TAA_NO)) setup_force_cpu_bug(X86_BUG_TAA); Thanks, Pawan