From patchwork Thu Dec 6 23:44:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 153075 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp397ljp; Thu, 6 Dec 2018 15:44:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uv5cLcQ9EgVxY6GHRPbTMo7Zl1D9TZZnp4jhEQi88e5XpgJj/D92Ob7fGUN3UR6Kh5WAgC X-Received: by 2002:a62:5486:: with SMTP id i128mr29901504pfb.215.1544139876201; Thu, 06 Dec 2018 15:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544139876; cv=none; d=google.com; s=arc-20160816; b=qD+V6fnCFIvxGr5bwROLIkqqo8kQpt6C9jW5TU5JfSFta9+n6A0tczEg/MN5nbB/sm g1QntO3VjtP55NlHNJvODgOJypL0cjuKxOOpsR4KVF03wPPHPkFK5U/t7LpOIgzKIztq gjGCYvXm85mWvP4bUwEWh3Aa+Za31fyineHgMLLdtLQ67iyIsl7oJfjvwZclQ8gebvUP KTqUBWSNWQl7CKVoMbzYcNsniDanNPKNegs0FBkjYYKYH77w9fZ9MjXyANZTOn6cruVL osHn4VqMMtXZIP7P3M3zrVm8F61WtHi7jeiPfNHkz/QiaTK1m2nXoi1mVxLLZnscCAoS rbmQ== 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=5pvIpj6iXi7TUztHsUmFaXHZSo5o2lghKNIRdL00uAs=; b=M+v0FbPN0yDZe4O0OLut8xC+cfJPlqjD23G0jV9iaC9HhnvPS22FZPR/Jg+f/zNK6B S8xK+ByxZtraI0IIbzWTo1EpWo4FNZGNYfSJfrHvmDmCa3B1o4vVQ7rYrZ7Q412C1NCe hRLNv2UjBqi6ScNjopNZeWrEgu88+nP7r8dX6lIwsgy5XSFSLNeS7G5TePmYHJFfbuv8 ZJOzz4QR3v0aCGg6HWQqekfryRFuYO33FUi6ro2xcFH8T0eavp/NQEdQXxJnjxlbl+DE VX8nZyOfQvov2V317gDBfR0oLmIp4TmcUIg9U/7Qv/wS4qVPotYuKxYG95kujFCp5ZF4 kG1w== 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 o9si1522975pfe.63.2018.12.06.15.44.35; Thu, 06 Dec 2018 15:44:36 -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 S1726412AbeLFXoc (ORCPT + 31 others); Thu, 6 Dec 2018 18:44:32 -0500 Received: from foss.arm.com ([217.140.101.70]:35906 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbeLFXob (ORCPT ); Thu, 6 Dec 2018 18:44:31 -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 1255915AD; Thu, 6 Dec 2018 15:44:31 -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 851EA3F5AF; Thu, 6 Dec 2018 15:44:30 -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, Jeremy Linton Subject: [PATCH 2/6] arm64: add sysfs vulnerability show for meltdown Date: Thu, 6 Dec 2018 17:44:04 -0600 Message-Id: <20181206234408.1287689-3-jeremy.linton@arm.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181206234408.1287689-1-jeremy.linton@arm.com> References: <20181206234408.1287689-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 | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) -- 2.17.2 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 242898395f68..bea9adfef7fa 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -905,6 +905,8 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) return has_cpuid_feature(entry, scope); } +static enum { A64_MELT_UNSET, A64_MELT_SAFE, A64_MELT_UNKN } __meltdown_safe = A64_MELT_UNSET; + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ @@ -928,6 +930,15 @@ 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); + + /* Only safe if all booted cores are known safe */ + if (meltdown_safe && __meltdown_safe == A64_MELT_UNSET) + __meltdown_safe = A64_MELT_SAFE; + else if (!meltdown_safe) + __meltdown_safe = A64_MELT_UNKN; + /* * For reasons that aren't entirely clear, enabling KPTI on Cavium * ThunderX leads to apparent I-cache corruption of kernel text, which @@ -949,11 +960,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 @@ -1920,3 +1927,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 == A64_MELT_SAFE) + return sprintf(buf, "Not affected\n"); + + return sprintf(buf, "Unknown\n"); +} +#endif