Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp299310imu; Wed, 2 Jan 2019 20:28:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN7waB2xAk1oZS3/BldMVV+OvzutRFFDacfJrsb0IflIeasMVB9sLvqVnjIFUHnoUXm2+qDa X-Received: by 2002:a63:cc12:: with SMTP id x18mr15690037pgf.33.1546489691847; Wed, 02 Jan 2019 20:28:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546489691; cv=none; d=google.com; s=arc-20160816; b=VETgf9BbJfnVcBh2vVO6YTdkJA1V26M4rBWOJult5sB3Z2aCv8NMR+w5P77/dtqKU9 ggzNHGeSuf8v8fANK0FRSGSTM8DMhSAUWFh1FZBoUU3S3f2NhSrDfmkAXAlrWtEDY6u5 /WZNdlWi+4OXoKpZoV0qjgK1dIIJiZVswvaiIZnqpxarQOQuszM3cjWWBbuXsK0ebGUK q/l4BXoIho6vbMtr6L3JxJ7lJ27Ru9TTmTGriyByTZHOo9nl5KJetgSZp9HywzkagNKb mcsoWoOfrdAFZL11t5CV1StjtaG5O8KD0Dy8Hp4VY2/BKM9YsT2Fv2144+4Nj8uCnM5F WzPA== 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 y20si49011708plp.415.2019.01.02.20.27.56; Wed, 02 Jan 2019 20:28:11 -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 S1730307AbfACAuB (ORCPT + 99 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(-) 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 -- 2.17.2