Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2460868imm; Thu, 7 Jun 2018 10:59:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLHm4imL3HO2qdGJwFH6Rstal3GrdGtAjAsv+c9T03Z77musWF2gsx43cYPKHk1BqwMC+ro X-Received: by 2002:a62:90db:: with SMTP id q88-v6mr1597370pfk.186.1528394351879; Thu, 07 Jun 2018 10:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528394351; cv=none; d=google.com; s=arc-20160816; b=naolEiqp+mpzwn38WW+hsjnfN8R03ctR5TuVz6i7tk80SlCCZsPF/Q/83c3ATRTQfo O/G5mtBAASlsHWpmI++wswOypsxNBHuScgesBB35Y6Aq1l+QYdZEj6WEUY3yg5KtEIDg 9oui5vPiBYvIkPlcspbx5uCR2Ncn0mAco5YNpXFPLnR/YRde4QFzp3YKEQFaAHHABVAc +v54lVneobWnFKdb4PMdEE72ANsyo2IyT1p3/27Hv5eTBTuxkrUoDgGV4ZLQzLgRSQJ6 ikbCKN7WMJOpEejvK77aOYA5WbRUDkT6vwCS4Hx+Wy7vO4VjmzgSJbHyqUcqukMu7v+3 xHtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=3kwEMSZ6NGth47NKpHqWDr+AXdq3ofoqpvp4U7frILY=; b=OvoU+SAMSmPzlDKUwjG55sxcSiMQRyItuU0Pm6ZbXzcLx30+ZFJ7/cJfsseoCzErGD +nHpQbAccR3gsJBLHDkWf+A3qeYHldtzvBdasvkCXJKTIB7/TYFTFirALoPCy3atQ14P mmhCnsBssE96NpUl2ea/HcQtct2vBQZ9o/RQ+VYNxLv8PMMVfwfGsAgbXQ06X+ZUv+Cu 1Zt9p2pQHqsjdDbSekdr7BI5qRuVpSJXwhNhoQxz03NWUvnuF49uWhy9Oc+y3DcVu4cC 21uIVFosVGhNnGmmOh9qmc/fH20ZqDjy7jGDJNKyDwtVfzQHg04pDhBrcAoFEQH31s9F 0VOQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t69-v6si26962959pgd.55.2018.06.07.10.58.57; Thu, 07 Jun 2018 10:59:11 -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; 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 S935272AbeFGOxJ (ORCPT + 99 others); Thu, 7 Jun 2018 10:53:09 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40937 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934580AbeFGOxG (ORCPT ); Thu, 7 Jun 2018 10:53:06 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvby-0005a0-S0; Thu, 07 Jun 2018 15:09:59 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvay-0002je-Oj; Thu, 07 Jun 2018 15:08:56 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, gregkh@linux-foundation.org, ak@linux.intel.com, "Dave Hansen" , torvalds@linux-foundation.org, "Thomas Gleixner" , karahmed@amazon.de, arjan@linux.intel.com, gnomes@lxorguk.ukuu.org.uk, "Greg Kroah-Hartman" , tim.c.chen@linux.intel.com, pbonzini@redhat.com, peterz@infradead.org, "Borislav Petkov" , bp@alien8.de, "David Woodhouse" , ashok.raj@intel.com Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 044/410] x86/pti: Do not enable PTI on CPUs which are not vulnerable to Meltdown In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: David Woodhouse commit fec9434a12f38d3aeafeb75711b71d8a1fdef621 upstream. Also, for CPUs which don't speculate at all, don't report that they're vulnerable to the Spectre variants either. Leave the cpu_no_meltdown[] match table with just X86_VENDOR_AMD in it for now, even though that could be done with a simple comparison, on the assumption that we'll have more to add. Based on suggestions from Dave Hansen and Alan Cox. Signed-off-by: David Woodhouse Signed-off-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Reviewed-by: Borislav Petkov Acked-by: Dave Hansen Cc: gnomes@lxorguk.ukuu.org.uk Cc: ak@linux.intel.com Cc: ashok.raj@intel.com Cc: karahmed@amazon.de Cc: arjan@linux.intel.com Cc: torvalds@linux-foundation.org Cc: peterz@infradead.org Cc: bp@alien8.de Cc: pbonzini@redhat.com Cc: tim.c.chen@linux.intel.com Cc: gregkh@linux-foundation.org Link: https://lkml.kernel.org/r/1516896855-7642-6-git-send-email-dwmw@amazon.co.uk Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- arch/x86/kernel/cpu/common.c | 48 ++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -41,6 +41,8 @@ #include #include #include +#include +#include #ifdef CONFIG_X86_LOCAL_APIC #include @@ -761,6 +763,41 @@ static void identify_cpu_without_cpuid(s #endif } +static const __initdata struct x86_cpu_id cpu_no_speculation[] = { + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CEDARVIEW, X86_FEATURE_ANY }, + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CLOVERVIEW, X86_FEATURE_ANY }, + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_LINCROFT, X86_FEATURE_ANY }, + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PENWELL, X86_FEATURE_ANY }, + { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PINEVIEW, X86_FEATURE_ANY }, + { X86_VENDOR_CENTAUR, 5 }, + { X86_VENDOR_INTEL, 5 }, + { X86_VENDOR_NSC, 5 }, + { X86_VENDOR_ANY, 4 }, + {} +}; + +static const __initdata struct x86_cpu_id cpu_no_meltdown[] = { + { X86_VENDOR_AMD }, + {} +}; + +static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c) +{ + u64 ia32_cap = 0; + + if (x86_match_cpu(cpu_no_meltdown)) + return false; + + if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES)) + rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); + + /* Rogue Data Cache Load? No! */ + if (ia32_cap & ARCH_CAP_RDCL_NO) + return false; + + return true; +} + /* * Do minimum CPU detection early. * Fields really needed: vendor, cpuid_level, family, model, mask, @@ -809,11 +846,12 @@ static void __init early_identify_cpu(st setup_force_cpu_cap(X86_FEATURE_ALWAYS); - if (c->x86_vendor != X86_VENDOR_AMD) - setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN); - - setup_force_cpu_bug(X86_BUG_SPECTRE_V1); - setup_force_cpu_bug(X86_BUG_SPECTRE_V2); + if (!x86_match_cpu(cpu_no_speculation)) { + if (cpu_vulnerable_to_meltdown(c)) + setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN); + setup_force_cpu_bug(X86_BUG_SPECTRE_V1); + setup_force_cpu_bug(X86_BUG_SPECTRE_V2); + } } void __init early_cpu_init(void)