From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from userp2120.oracle.com ([156.151.31.85]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f9jBJ-0006fM-9i for speck@linutronix.de; Sat, 21 Apr 2018 05:27:22 +0200 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3L3RBpq123586 for ; Sat, 21 Apr 2018 03:27:14 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2hdrxpevt1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 21 Apr 2018 03:27:13 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3L3RDYV022395 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 21 Apr 2018 03:27:13 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3L3RD46006056 for ; Sat, 21 Apr 2018 03:27:13 GMT Date: Fri, 20 Apr 2018 23:27:07 -0400 From: Konrad Rzeszutek Wilk Subject: [MODERATED] Re: [patch 07/11] [PATCH v2 07/10] Linux Patch #7 Message-ID: <20180421032701.GA4490@localhost.localdomain> References: <20180420022613.270943302@localhost.localdomain> <20180420174242.GO13977@pd.tnic> MIME-Version: 1.0 In-Reply-To: <20180420174242.GO13977@pd.tnic> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Fri, Apr 20, 2018 at 07:42:42PM +0200, speck for Borislav Petkov wrote: > On Thu, Apr 19, 2018 at 10:25:47PM -0400, speck for konrad.wilk_at_oracle.com wrote: > > x86/cpu: Add fix_this_cpu to be called _after_ check_bugs and at BSP. > > > > We do a lot of things in the check_bugs() - one of the first > > things we do is identify_boot_cpu() which calls identify_cpu() > > which calls this_cpu->init. > > > > Once identify_boot_cpu() is done _then_ it walks through the > > spectre_v2_select_mitigation() and alternative_assembler(). > > > > If there are some CPU fix ups _after_ spectre_v2 is done > > we can't activate those on the BSP as we have already > > called 'this_cpu->init'. Hence add a new function to > > fixup CPUs. > > Konrad, this is still unnecessary and adding superfluous complexity to > an already crazy early boot path. Let me clarify the flow: > > First you are on the BSP: > > setup_arch() > |-> early_cpu_init > |-> early_identify_cpu > |-> cpu_set_bug_bits > > now you have all the X86_BUG bits set so that you can test them in the > functions later. I am not worrying about the X86_BUG, I am thinking about the X86_FEATURE_MDD. See below. > > Then, you're still on the BSP and can do check_bugs() with all cmdline > options picking apart etc etc. > > setup_arch() > |-> check_bugs() > |-> ssb_select_mitigation() > |-> identify_boot_cpu() <--- HERE you call ->c_init() on the BSP > |-> spectre_v2_select_mitigation > > In that order! > > So, all you wanna do works without adding this new function pointer. With that I will need to add in early_init_amd the code to set_cpu_cap(c, X86_FEATURE_MDD) based on reading the MSR_AMD64_LS_CFG. That is needed as the 'ssb_select_mitigation' ends calling ssb_parse_cmdline which immediately exits if: 381 static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void) .. 391 if (!boot_cpu_has(X86_FEATURE_MDD)) <=== 392 return SSB_CMD_NONE; Adding this: diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index e207eb2e8011..6a800a71b6c0 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -676,6 +676,15 @@ static void early_init_amd(struct cpuinfo_x86 *c) set_cpu_bug(c, X86_BUG_AMD_E400); early_detect_mem_encrypt(c); + + switch (c->x86) { + case 0x15: + case 0x16: + case 0x17: + if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &msr_MSR_AMD64_LS_CFG_val)) + set_cpu_cap(c, X86_FEATURE_MDD); + default: + } } static void init_amd_k8(struct cpuinfo_x86 *c) in conjunction with your flow will make it work just fine.