Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp742940imu; Fri, 25 Jan 2019 10:08:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN4Qgzit0LdFMwhKKv+QMRFJpK1PbH+4lzj6ezs27gfRpER22c+0M1OjVrH5iNL4cMwOr16x X-Received: by 2002:a17:902:ab84:: with SMTP id f4mr11720041plr.207.1548439726964; Fri, 25 Jan 2019 10:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548439726; cv=none; d=google.com; s=arc-20160816; b=zl8hOb7BM9udCx7xtghrUq/IOW/07ibgeBfXbHT5Y1+pE+q3vd5SL/qR0Y8oFJ+aZt tj1dq+tvbPgJdCohaEhiw+GjWzixmXKWunp6d+8VQt1FnUnbwGNPFVIxbWZpLLWHv+lU ocuQDiqpCJkPqwwiwF5UB7ug1r5s/UDMOPqbx4VG4koEGHjqgoSws5/VqrucIfC+8G37 ZEdD86tWCQHcVLqAmRPDb3fawaEQA443r4q9Vod59ITWyTmTS37n0SpgpiOlpe1w6WiW q4J+ZQE9XdDckyZiJceafyaf7o5JowAw7Wt/ixsGnVIX2vIKP40j3umuEKHA+boElu8Y /nzA== 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:cc:to:from; bh=OyXUeuHhPY6jG2+k0sZgpSp0sLOHTgM4CrFIOJ/sfdU=; b=IgS5sDoXQY9+sGtAV7fzmmitl9aRnhvpWucAk6/n6voydDEcJygdbVQsXGZGTiHH4d yC7BETFEpCBhpNUmqyTvreCQd9QYGEwSQyuKwgPTY0roXXa9LCaYOf1qefNEEUivaDil Khd5h+E3pb11PeWeYPd0gt6FHBkWtvJQlUDyRoHFs9o0bCCsbz2ZH/+hiqM8ljtT4mj8 zxAYvVhJl7okx26bnN617uzj3BtaFzYLxiYxRpMflTQbOollJiYAP0HZLwYcYCci8pPq Icol2HF3ReZ+R+lJxOP3VXN9bt+Dd/WUJ/8H+7aYr2JcWCa9XLEnSJqL7NqVybBZHFpi 8kaA== 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 o10si25529388pgg.373.2019.01.25.10.08.31; Fri, 25 Jan 2019 10:08:46 -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; 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 S1729366AbfAYSHa (ORCPT + 99 others); Fri, 25 Jan 2019 13:07:30 -0500 Received: from foss.arm.com ([217.140.101.70]:51836 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729336AbfAYSH3 (ORCPT ); Fri, 25 Jan 2019 13:07:29 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 00DFB1682; Fri, 25 Jan 2019 10:07:29 -0800 (PST) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 595C13F5AF; Fri, 25 Jan 2019 10:07:28 -0800 (PST) From: Jeremy Linton To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, marc.zyngier@arm.com, suzuki.poulose@arm.com, dave.martin@arm.com, shankerd@codeaurora.org, linux-kernel@vger.kernel.org, ykaukab@suse.de, julien.thierry@arm.com, mlangsdo@redhat.com, steven.price@arm.com, stefan.wahren@i2se.com, Jeremy Linton Subject: [PATCH v4 07/12] arm64: add sysfs vulnerability show for meltdown Date: Fri, 25 Jan 2019 12:07:06 -0600 Message-Id: <20190125180711.1970973-8-jeremy.linton@arm.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190125180711.1970973-1-jeremy.linton@arm.com> References: <20190125180711.1970973-1-jeremy.linton@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Display the mitigation status if active, otherwise assume the cpu is safe unless it doesn't have CSV3 and isn't in our whitelist. Signed-off-by: Jeremy Linton --- arch/arm64/kernel/cpufeature.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index a9e18b9cdc1e..624dfe0b5cdd 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -944,6 +944,8 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) return has_cpuid_feature(entry, scope); } +/* default value is invalid until unmap_kernel_at_el0() runs */ +static bool __meltdown_safe = true; static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, @@ -962,6 +964,16 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, { /* sentinel */ } }; char const *str = "command line option"; + bool meltdown_safe; + + meltdown_safe = is_midr_in_range_list(read_cpuid_id(), kpti_safe_list); + + /* Defer to CPU feature registers */ + if (has_cpuid_feature(entry, scope)) + meltdown_safe = true; + + if (!meltdown_safe) + __meltdown_safe = false; /* * For reasons that aren't entirely clear, enabling KPTI on Cavium @@ -984,12 +996,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return kaslr_offset() > 0; - /* Don't force KPTI for CPUs that are not vulnerable */ - if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) - return false; - - /* Defer to CPU feature registers */ - return !has_cpuid_feature(entry, scope); + return !meltdown_safe; } static void @@ -2055,3 +2062,17 @@ static int __init enable_mrs_emulation(void) } core_initcall(enable_mrs_emulation); + +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (arm64_kernel_unmapped_at_el0()) + return sprintf(buf, "Mitigation: KPTI\n"); + + if (__meltdown_safe) + return sprintf(buf, "Not affected\n"); + + return sprintf(buf, "Vulnerable\n"); +} +#endif -- 2.17.2