From patchwork Fri Jan 25 18:07:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 156628 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp652954jaa; Fri, 25 Jan 2019 10:08:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN4WMSYyFFLsKLDWoxA0IhIfaT2FFj+DikKiAERoXjK9Q96FVpA2FoRHPTH3KiU24RQ0k+p6 X-Received: by 2002:a62:5fc4:: with SMTP id t187mr12057903pfb.66.1548439683200; Fri, 25 Jan 2019 10:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548439683; cv=none; d=google.com; s=arc-20160816; b=FMnD+MZF4TRZmJLvv0Uz2wpPXYrzxClx/NO1mI5vUb1ljxAzwsSjNV5Do31aDV91cF M1mSFL5176IjHGHvMzlZP1/v2JJv6NgOczIDRYeSiCowa3bCfFsM2I7U7H60YnYzU7xj KzFFRod9bA17nm9d/wlncKZlzmb/JYs23/QtG68JTlRu4mhxmySKsn2chZ2kRMfk7fCt ovSQ+4dr5Wv2pP+3qa1xuH2Y+fwOG5mOaW60NRJu7pauDQC+cBFDC8gRWfn+lMXKx+jV RyBPYODatw2fq3wlCUHHTO9392OHDB3/vW23G2wydjs42WdcvRxeKIWJDfKSbLlpF6bz UI9g== 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 r27si25639723pgl.494.2019.01.25.10.08.02; Fri, 25 Jan 2019 10:08:03 -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 S1729372AbfAYSHb (ORCPT + 31 others); Fri, 25 Jan 2019 13:07:31 -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(-) -- 2.17.2 Reviewed-by: Julien Thierry 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