Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2139275imm; Thu, 19 Jul 2018 14:00:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfoCP1wSvDRMraBy5qZ9CnZSmZqwHLiywMPM31nbwz9MM352XW8oCxgjX/0P+eoaontxMhN X-Received: by 2002:a17:902:7e06:: with SMTP id b6-v6mr11517524plm.230.1532034012972; Thu, 19 Jul 2018 14:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532034012; cv=none; d=google.com; s=arc-20160816; b=jueFmxldfhRHIRKrLQiKKxSf4MvPgvgP33rzxvdhRCr/Oj8UHgaCG+5xcR+GWDhtbF mCBUwJO96yPoJG2jPMVU8v9WyPCER/OP83uy3j6owIz8VJ6mASNEmADyxI+jYgiCJeIy 39MQWOf6epeEic2P3Uqg/uyYhHZ+YEnIv5E/Gg1I5x+NuypqSgsZjaW7PrmZGhWhDtVX gN5dSRh0yCxCp60o8/dG357ss8eQ3I5V8ddDNK/WERKPVpY/q1u9VtcVH31s38XEHd3w RMo8vP5b23/LlsDhIcC2jGxzob5Fv/jo4HKRL0sKbxS09OJvuwLhChYeS5cKfNY4xX2X 4SOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=PvvRFnKNuUxrKTf0X0mQiwHoDIj6deGguQ/JTqZ2pgY=; b=zXB7mOQxCdYR0QJfteh6R6j6F9dXgaDJ3eqmqcCWgJxQ19COBrg6BZiHt38ybk4bif NkudKrcHlZz2l+bYa/0mVHmxUExeOYVxfFK3A7TZ+R5fBihv6HxgmbFLs6jK0zRv2FLY Gubsjhwq+1Qply73BtXyreY8eDQ27kQdNeafojTHDGGuSWsuZ++AZN3br+jvk4y5hkVF 3IRwfxEIL7LN8aVHotyjk5PoiLalkeInM7PxJp8XZSyXfvamxbCLTqIgJJGe1ao7oDgU bI97qVXi5eoRL1o20x8PIfJjo+CCPADUegKf9gXKiw0EWa9k50ext2Sd0sR34H1sIcbd m6gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=mT1lh7vk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 190-v6si126895pfu.343.2018.07.19.13.59.58; Thu, 19 Jul 2018 14:00:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=mT1lh7vk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731292AbeGSVmR (ORCPT + 99 others); Thu, 19 Jul 2018 17:42:17 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51078 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730628AbeGSVmQ (ORCPT ); Thu, 19 Jul 2018 17:42:16 -0400 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 w6JKsdnF156901; Thu, 19 Jul 2018 20:56:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=PvvRFnKNuUxrKTf0X0mQiwHoDIj6deGguQ/JTqZ2pgY=; b=mT1lh7vkCMbWl5eVQfoEV6XH4Kpi/DfidZ3q05dbyUuxk6y7BY1UEFNbr1DX16JGB/Le cCyJmFqUBCKRyqAwIfy5aj1HK5rRfRqyZExZYOyrPCqFmtQVXLhbiVFYJUodxSvZRv3j 6ZMNXsikIOg4qji5NdE42XQ/g29U6kCw7FkhGPHkIdWf1x/HIell0Z29DloLgOsIDAGp 7dwC0mj1yELA3Bc4U/66cKcspulHNdpUSR8txDMLblwakzQR7iwqCpQXGOq3ogkefDlC 68N8p1484t2BEM7bzhQ9zQxQHnHtCqFqRLrLnXjQOvUWcO2FCL/tmdsmt9HTGsOMZLz0 yg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2k9yjx8uur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Jul 2018 20:56:31 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w6JKuTsg001091 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Jul 2018 20:56:30 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6JKuSJN027488; Thu, 19 Jul 2018 20:56:28 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Jul 2018 20:56:28 +0000 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux@armlinux.org.uk, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, john.stultz@linaro.org, sboyd@codeaurora.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, douly.fnst@cn.fujitsu.com, peterz@infradead.org, prarit@redhat.com, feng.tang@intel.com, pmladek@suse.com, gnomes@lxorguk.ukuu.org.uk, linux-s390@vger.kernel.org, pasha.tatashin@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, pbonzini@redhat.com Subject: [PATCH v15 09/26] x86: initialize static branching early Date: Thu, 19 Jul 2018 16:55:28 -0400 Message-Id: <20180719205545.16512-10-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180719205545.16512-1-pasha.tatashin@oracle.com> References: <20180719205545.16512-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8959 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807190218 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org static branching is useful to hot-patch branches that are used in hot path, but are infrequently changed. x86 clock framework is one example that uses static branches to setup the best clock during boot and never change it again. Since we plan to enable clock early, we need static branching functionality early as well. static branching requires patching nop instructions, thus, we need arch_init_ideal_nops() to be called prior to jump_label_init() Here we do all the necessary steps to call arch_init_ideal_nops after early_cpu_init(). Signed-off-by: Pavel Tatashin Suggested-by: Peter Zijlstra Reviewed-by: Borislav Petkov --- arch/x86/kernel/cpu/amd.c | 13 +++++++----- arch/x86/kernel/cpu/common.c | 38 +++++++++++++++++++----------------- arch/x86/kernel/setup.c | 4 ++-- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 38915fbfae73..b732438c1a1e 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -232,8 +232,6 @@ static void init_amd_k7(struct cpuinfo_x86 *c) } } - set_cpu_cap(c, X86_FEATURE_K7); - /* calling is from identify_secondary_cpu() ? */ if (!c->cpu_index) return; @@ -617,6 +615,14 @@ static void early_init_amd(struct cpuinfo_x86 *c) early_init_amd_mc(c); +#ifdef CONFIG_X86_32 + if (c->x86 == 6) + set_cpu_cap(c, X86_FEATURE_K7); +#endif + + if (c->x86 >= 0xf) + set_cpu_cap(c, X86_FEATURE_K8); + rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy); /* @@ -863,9 +869,6 @@ static void init_amd(struct cpuinfo_x86 *c) init_amd_cacheinfo(c); - if (c->x86 >= 0xf) - set_cpu_cap(c, X86_FEATURE_K8); - if (cpu_has(c, X86_FEATURE_XMM2)) { unsigned long long val; int ret; diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index eb4cb3efd20e..71281ac43b15 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1015,6 +1015,24 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN); } +/* + * The NOPL instruction is supposed to exist on all CPUs of family >= 6; + * unfortunately, that's not true in practice because of early VIA + * chips and (more importantly) broken virtualizers that are not easy + * to detect. In the latter case it doesn't even *fail* reliably, so + * probing for it doesn't even work. Disable it completely on 32-bit + * unless we can find a reliable way to detect all the broken cases. + * Enable it explicitly on 64-bit for non-constant inputs of cpu_has(). + */ +static void detect_nopl(struct cpuinfo_x86 *c) +{ +#ifdef CONFIG_X86_32 + clear_cpu_cap(c, X86_FEATURE_NOPL); +#else + set_cpu_cap(c, X86_FEATURE_NOPL); +#endif +} + /* * Do minimum CPU detection early. * Fields really needed: vendor, cpuid_level, family, model, mask, @@ -1089,6 +1107,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) */ if (!pgtable_l5_enabled()) setup_clear_cpu_cap(X86_FEATURE_LA57); + + detect_nopl(c); } void __init early_cpu_init(void) @@ -1124,24 +1144,6 @@ void __init early_cpu_init(void) early_identify_cpu(&boot_cpu_data); } -/* - * The NOPL instruction is supposed to exist on all CPUs of family >= 6; - * unfortunately, that's not true in practice because of early VIA - * chips and (more importantly) broken virtualizers that are not easy - * to detect. In the latter case it doesn't even *fail* reliably, so - * probing for it doesn't even work. Disable it completely on 32-bit - * unless we can find a reliable way to detect all the broken cases. - * Enable it explicitly on 64-bit for non-constant inputs of cpu_has(). - */ -static void detect_nopl(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_X86_32 - clear_cpu_cap(c, X86_FEATURE_NOPL); -#else - set_cpu_cap(c, X86_FEATURE_NOPL); -#endif -} - static void detect_null_seg_behavior(struct cpuinfo_x86 *c) { #ifdef CONFIG_X86_64 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index da1dbd99cb6e..7490de925a81 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -866,6 +866,8 @@ void __init setup_arch(char **cmdline_p) idt_setup_early_traps(); early_cpu_init(); + arch_init_ideal_nops(); + jump_label_init(); early_ioremap_init(); setup_olpc_ofw_pgd(); @@ -1268,8 +1270,6 @@ void __init setup_arch(char **cmdline_p) mcheck_init(); - arch_init_ideal_nops(); - register_refined_jiffies(CLOCK_TICK_RATE); #ifdef CONFIG_EFI -- 2.18.0