From patchwork Thu Jan 3 00:49:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 154689 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp127710ljp; Wed, 2 Jan 2019 16:50:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN6djS8WAqnND+3p4233jPaqqLrRJGJaiiRR1QEAJfSVNbZp9e7Wulsy1xJeJA9gpzxywPRg X-Received: by 2002:a62:178f:: with SMTP id 137mr45911077pfx.226.1546476602328; Wed, 02 Jan 2019 16:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546476602; cv=none; d=google.com; s=arc-20160816; b=E3qYsEShitl8Yq3vJNKb+ShO2G1ibCzE71dA2J8p7KdCK/GxfJ1jgQVS42G/AyXxzA Bm18I3TH/g2aQXOzPgJwACOHMfgqlc77Y2L8qD6Ol6C7qxSvPj7JQpdurjqWRMwi225H KEAk9/ufXC5w8ZsQoj3LJmJ5aQCOwtWijPIlCAWDlrmTaYpzTjCs0f0s2O2JlJj0bQdZ Z8AxBitH9JzZevAX0h8ss/BmcuzZl/e9WTYJ2myrrOH4CeBmdGnOeE30aTF2uo6tEMQ9 yaVYLR+3MqLEqakzTgJvkpU5alhZuPiFpeNNIS2vjL5leSNKZ2d/z4ngYpNWI3MXzQyF glYg== 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=Thijdf4j7uhhDudInMr2T0q+S8pMj7VjZf+amntbpso=; b=RwH7mGIb275zCji45e6SUYTMBtIMydlrrbjrkrd1RXxoMydfP6h/5BDVyvOkLmNj4D LQ3SzOfTs6hscCK/qOxDy+VmtZrmybrHmOqEnxPJhne6wJZbZSLkMcUfn5aP9iOGDJSV 2zklztQQwnfjPz9EL6k4BgABftpjp15NL9o3hoEi1rhGRtKYWoTgc7JfbrN8NodD18hk derfdEYoZFHYDD9h8pY/T5vKBas9Q4emQq+d8e/Psr7tFsQx3lRS/7FHDZSpr4+uYI3V o+iC64eMAAG0iUwmzdITYaWbZW0x3+5o+454TIIv9Np/fKLChe74IYZBq557XytsolLQ Ubsg== 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 g1si33378834pld.197.2019.01.02.16.50.02; Wed, 02 Jan 2019 16:50:02 -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 S1730314AbfACAuB (ORCPT + 31 others); Wed, 2 Jan 2019 19:50:01 -0500 Received: from foss.arm.com ([217.140.101.70]:39806 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730205AbfACAtf (ORCPT ); Wed, 2 Jan 2019 19:49:35 -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 9EC4E15AB; Wed, 2 Jan 2019 16:49:34 -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 C869B3F5AF; Wed, 2 Jan 2019 16:49:33 -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, mark.rutland@arm.com, linux-kernel@vger.kernel.org, ykaukab@suse.de, julien.thierry@arm.com, mlangsdo@redhat.com, steven.price@arm.com, Jeremy Linton Subject: [PATCH v2 3/7] arm64: add sysfs vulnerability show for meltdown Date: Wed, 2 Jan 2019 18:49:17 -0600 Message-Id: <20190103004921.1928921-4-jeremy.linton@arm.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190103004921.1928921-1-jeremy.linton@arm.com> References: <20190103004921.1928921-1-jeremy.linton@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a simple state machine which will track whether all the online cores in a machine are vulnerable. Once that is done we have a fairly authoritative view of the machine vulnerability, which allows us to make a judgment about machine safety if it hasn't been mitigated. Signed-off-by: Jeremy Linton --- arch/arm64/kernel/cpufeature.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) -- 2.17.2 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index ab784d7a0083..1f64cbff8456 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -944,6 +944,9 @@ 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; + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ @@ -972,6 +975,12 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, { char const *str = "command line option"; + bool meltdown_safe = is_cpu_meltdown_safe() || + has_cpuid_feature(entry, scope); + + if (!meltdown_safe) + __meltdown_safe = false; + /* * For reasons that aren't entirely clear, enabling KPTI on Cavium * ThunderX leads to apparent I-cache corruption of kernel text, which @@ -993,11 +1002,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; - if (is_cpu_meltdown_safe()) - return false; - - /* Defer to CPU feature registers */ - return !has_cpuid_feature(entry, scope); + return !meltdown_safe; } static void @@ -2065,3 +2070,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 (IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0) && __meltdown_safe) + return sprintf(buf, "Not affected\n"); + + return sprintf(buf, "Unknown\n"); +} +#endif