Received: by 10.223.185.116 with SMTP id b49csp1392024wrg; Sun, 11 Feb 2018 10:52:00 -0800 (PST) X-Google-Smtp-Source: AH8x226D2wEd8N55QZNoSFo036zKyN43+6o+52SelXiKOSVAyyP1S2s0cPTcsqOmMv2nVceaZqLG X-Received: by 2002:a17:902:7e43:: with SMTP id a3-v6mr8814132pln.138.1518375120381; Sun, 11 Feb 2018 10:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518375120; cv=none; d=google.com; s=arc-20160816; b=oqGthqOyoAGGJr9VSmUFFziqhLTJU0BiFk9Fm5logxLrvpQOqqg8V2J6JWgP11PahW N+7NoHLXcDJcpqDcI9gYd/BxnFzqvMFWgDQ65JDdzD4ORfFrMYH9hMoyPoTuBZHrNv4P 6qDnMAkS4NbDjg94G5rOCSWr399O/gh35QA7YM0/pPAONQxykAgYSLpE/8knobW5QQ7P 7IiOjDwlWXzOtutTeJPvaNQF7HOidDJOB/OM+0FLw5i1ME+qcGtkZ/LSN0TQHe7U7YTt lbW8U0u+AogS4VWaVAW73mCtRplUuIRF8jLqJPBfUzxmWmywTtzwsN5g1ckO7z2sU6wO gnHg== 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:dkim-signature:arc-authentication-results; bh=DpvqYAWGRafArumRZwMfJclM+TUb2qUA6sk8nYUfw3Y=; b=jNvjpuLVEsCbc40XkKJA7/KssPmwQrVZ3YcAICuIwyzGagZZrj7tkCcj0XfZFeke0+ ipts1PZAphE6Qw5qOVAlLZI1H/wYED1Vq9Rp+0+66ro5Ib7FBenLQjonYQljJU/fgHtt 7G+mU0effgpgJ0oakTUn/yLEJCDTVr9MlmijBG5DoGHDw7ai/Gn9hRDmXALLGTCej/Ei wMw5iP3DXZoKn7OsyKAa5hySgXI/wjCYrGdEW6y2rRVWBjzFGxY7bY+pbhkuc33eI8gy SkxhU+g/7lgyVqUwGV3E1PzvEJVuyxrm9p5DUFF/1usyp6Piei9zdzcSaP2sib9x4QW6 I+Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=JxWulraP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si4234851pgc.593.2018.02.11.10.51.45; Sun, 11 Feb 2018 10:52:00 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b=JxWulraP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753652AbeBKSvE (ORCPT + 99 others); Sun, 11 Feb 2018 13:51:04 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36796 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753551AbeBKSvC (ORCPT ); Sun, 11 Feb 2018 13:51:02 -0500 Received: by mail-wr0-f196.google.com with SMTP id y3so13086860wrh.3; Sun, 11 Feb 2018 10:51:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DpvqYAWGRafArumRZwMfJclM+TUb2qUA6sk8nYUfw3Y=; b=JxWulraPM0D/fOcaFKIUl3ZOMatCFCtwuAj7AY7smAqzCrZx0E7uQOuUamFJUAzlz7 p9zDYjeWkAVoHt6Cp8q+o+9MiO1xZsFLBeotXE1A1M+xd8rCVwtMvT9plyjF5u3PQHpN PMQzz3MqF5uheSeh1lyQH84bzLK+O+PxSKm4mGNgA/eJc4tGHNgvCxjv7BzvnNUBEYs5 ssJ/RAiZL4YVMjrI+hc9OnZi5RKWU2gikag+z4H889iF2rAe8SYfH9laj4BG6qZ5bSAB 6faCjOwDr/U4pr70DJpEYlLmpHCHubLDP3zW2wMGqJmRea0gP2sNEhrylyVEIV54euKi OlNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=DpvqYAWGRafArumRZwMfJclM+TUb2qUA6sk8nYUfw3Y=; b=uI2oIXUk0Z6pl6ojDAbAu5yGRqY28aPcJBEUdlIFLmRSQmnAg0W8WWC0nZRiRRUJeM 2g1UL4sEX16TNqk/4YXsKMsycXG5e2zb/PKX+N7TmIx1BUVahbtEj0q+6hgMeP6N/eqy AcS0txgLve0WANvaomWvs7DArFRsUXaK082Fq6yUw2r5zAGf3eENwueP1zkHBr6Igba+ j/md61JonXz4bKd8JZH89kcNXm8OjTRmt+yV4kwwmfvOVf9tkpeYHRFByAyAIxXVcOfg Oy/BI7kZn6C/mcp2Cb95Im+htRUh6h+TrFDEJwoYWxUs0uCDSwZFt7iB9KgvJs7Dg5p0 iRzA== X-Gm-Message-State: APf1xPCS0/V+3IofilQ8o4+C7irYs3ppc/Tj39ACci2leGacHXjzasN1 eJh1+fMjbWyWRudrPCP/0vcPoA== X-Received: by 10.223.183.39 with SMTP id l39mr1702196wre.214.1518375060866; Sun, 11 Feb 2018 10:51:00 -0800 (PST) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id d195sm4154132wmd.2.2018.02.11.10.50.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Feb 2018 10:51:00 -0800 (PST) Date: Sun, 11 Feb 2018 19:50:57 +0100 From: Ingo Molnar To: David Woodhouse Cc: x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, karahmed@amazon.de, sironi@amazon.de, kvm@vger.kernel.org, torvalds@linux-foundation.org, pbonzini@redhat.com, bp@alien8.de, peterz@infradead.org, jmattson@google.com, rkrcmar@redhat.com, arjan.van.de.ven@intel.com, dave.hansen@intel.com Subject: [PATCH] x86/speculation: Clean up various Spectre related details Message-ID: <20180211185057.rest4bf2ydx7slrk@gmail.com> References: <1518305967-31356-1-git-send-email-dwmw@amazon.co.uk> <1518362359-1005-1-git-send-email-dwmw@amazon.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1518362359-1005-1-git-send-email-dwmw@amazon.co.uk> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * David Woodhouse wrote: > + /* > + * Retpoline means the kernel is safe because it has no indirect > + * branches. But firmware isn't, so use IBRS to protect that. > + */ > + if (boot_cpu_has(X86_FEATURE_IBRS)) { > + setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW); > + pr_info("Enabling Restricted Speculation for firmware calls\n"); > + } I have changed this text to say: pr_info("Spectre mitigation: Restricting branch speculation (enabling IBRS) for firmware calls\n"); In fact while at it I found and improved a few other details as well, such as: * Retpoline means the kernel is safe because it has no indirect - * branches. But firmware isn't, so use IBRS to protect that. + * branches. But we don't know whether the firmware is safe, so + * use IBRS to protect against that: most Spectre related messages are now harmonized: arch/x86/kernel/cpu/bugs.c: pr_info("Spectre mitigation: Filling RSB on context switch\n"); arch/x86/kernel/cpu/bugs.c: pr_info("Spectre mitigation: Enabling Indirect Branch Prediction Barrier (IBPB)\n"); arch/x86/kernel/cpu/bugs.c: pr_info("Spectre mitigation: Restricting branch speculation (enabling IBRS) for firmware calls\n"); Find the full patch below. Thanks, Ingo =========================> From 82c2b2f29691143a05181333f387e786646aa28b Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Sat, 10 Feb 2018 11:51:57 +0100 Subject: [PATCH] x86/speculation: Clean up various Spectre related details Harmonize all the Spectre messages so that a: dmesg | grep -i spectre ... gives us most Spectre related kernel boot messages. Also fix a few other details: - clarify a comment about firmware speculation control - s/KPTI/PTI - remove various line-breaks that made the code uglier Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dan Williams Cc: Dave Hansen Cc: David Woodhouse Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/kernel/cpu/bugs.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 6f6d763225c8..eff45477fcca 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -162,8 +162,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) if (cmdline_find_option_bool(boot_command_line, "nospectre_v2")) return SPECTRE_V2_CMD_NONE; else { - ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, - sizeof(arg)); + ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg)); if (ret < 0) return SPECTRE_V2_CMD_AUTO; @@ -175,8 +174,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) } if (i >= ARRAY_SIZE(mitigation_options)) { - pr_err("unknown option (%s). Switching to AUTO select\n", - mitigation_options[i].option); + pr_err("unknown option (%s). Switching to AUTO select\n", mitigation_options[i].option); return SPECTRE_V2_CMD_AUTO; } } @@ -185,8 +183,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) cmd == SPECTRE_V2_CMD_RETPOLINE_AMD || cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) && !IS_ENABLED(CONFIG_RETPOLINE)) { - pr_err("%s selected but not compiled in. Switching to AUTO select\n", - mitigation_options[i].option); + pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option); return SPECTRE_V2_CMD_AUTO; } @@ -256,14 +253,14 @@ static void __init spectre_v2_select_mitigation(void) goto retpoline_auto; break; } - pr_err("kernel not compiled with retpoline; no mitigation available!"); + pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!"); return; retpoline_auto: if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { retpoline_amd: if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) { - pr_err("LFENCE not serializing. Switching to generic retpoline\n"); + pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n"); goto retpoline_generic; } mode = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD : @@ -281,7 +278,7 @@ static void __init spectre_v2_select_mitigation(void) pr_info("%s\n", spectre_v2_strings[mode]); /* - * If neither SMEP or KPTI are available, there is a risk of + * If neither SMEP or PTI are available, there is a risk of * hitting userspace addresses in the RSB after a context switch * from a shallow call stack to a deeper one. To prevent this fill * the entire RSB, even when using IBRS. @@ -295,30 +292,30 @@ static void __init spectre_v2_select_mitigation(void) if ((!boot_cpu_has(X86_FEATURE_PTI) && !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) { setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); - pr_info("Filling RSB on context switch\n"); + pr_info("Spectre mitigation: Filling RSB on context switch\n"); } /* Initialize Indirect Branch Prediction Barrier if supported */ if (boot_cpu_has(X86_FEATURE_IBPB)) { setup_force_cpu_cap(X86_FEATURE_USE_IBPB); - pr_info("Enabling Indirect Branch Prediction Barrier\n"); + pr_info("Spectre mitigation: Enabling Indirect Branch Prediction Barrier (IBPB)\n"); } /* * Retpoline means the kernel is safe because it has no indirect - * branches. But firmware isn't, so use IBRS to protect that. + * branches. But we don't know whether the firmware is safe, so + * use IBRS to protect against that: */ if (boot_cpu_has(X86_FEATURE_IBRS)) { setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW); - pr_info("Enabling Restricted Speculation for firmware calls\n"); + pr_info("Spectre mitigation: Restricting branch speculation (enabling IBRS) for firmware calls\n"); } } #undef pr_fmt #ifdef CONFIG_SYSFS -ssize_t cpu_show_meltdown(struct device *dev, - struct device_attribute *attr, char *buf) +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) { if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) return sprintf(buf, "Not affected\n"); @@ -327,16 +324,14 @@ ssize_t cpu_show_meltdown(struct device *dev, return sprintf(buf, "Vulnerable\n"); } -ssize_t cpu_show_spectre_v1(struct device *dev, - struct device_attribute *attr, char *buf) +ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) { if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) return sprintf(buf, "Not affected\n"); return sprintf(buf, "Mitigation: __user pointer sanitization\n"); } -ssize_t cpu_show_spectre_v2(struct device *dev, - struct device_attribute *attr, char *buf) +ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) { if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) return sprintf(buf, "Not affected\n");