Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5058892imm; Tue, 7 Aug 2018 11:55:34 -0700 (PDT) X-Google-Smtp-Source: AA+uWPweqTRI1UPTmmmO1ELxK4GsJ2j334rALrgfaofqMGeEcCPjyE67oWZpiLvs/0nx4n1OVhnf X-Received: by 2002:a17:902:9884:: with SMTP id s4-v6mr2428955plp.127.1533668134350; Tue, 07 Aug 2018 11:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533668134; cv=none; d=google.com; s=arc-20160816; b=Lsuc6yERI+XRhwcW4sqRl9lkP7IZm7e/7/2KZ/piFQz8x58cxiCTDqqIFK/hhycjKr CUIXIZ0RMsIGS1WI4MWxU94F86DUPg4r6qUOYHhpJsMhnxj1aI8Vi9NSPbLJ8Pt48hEN o9TYocWT8vs1XGRF63AaLl8GsXJrtfcpDubamSRk+uN+Dd7JPRcnD8wYjXRbtOUH4MM3 DjYiPkXYZWFFevR5GKdPXkflef3Webgef6byJd3XoCqkH4DgpNiAdzwI6QSeyLNVDQYv HocSpwfgAmWRg0JcvqDEwURYw4RrKKKIbwqchuZO1taXRG37VeQL3sdWPHc4DMJXOg9P 2xbA== 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:arc-authentication-results; bh=S2lgT72gK2AIzXkLPw048K29jQ4fiAnQOZcqdN7Na6s=; b=SJPEwN7v9zg0sNGHh56KmoxsiHQXu2HPpR0BXpYS5ztofxIROwBIg0v7A8GtAgFEjq VzANBI4P6Dd2ejHrD8D1F85nyNZs5o45TovMjtpdYY9ko6e9v16hu7bl+5ocNP9CW4KP eoMRafzMMZzMhVbcE6hrU0R/3ucUH7C7I+kUIaSeshcqt0/Iv+lFqpji14dBzSO14hZb Ml3kmohBTEABOIy210pbHLDi7/WakbEa1faB7tt/ZfcXwl7Or7Sku5YKO2KtGOHPHFZI v/F5ot9ix0ykmASINRLhbGdP6USz/h4lqyUxtyPIk0YHdytJljiTqeH7wXWkl1GD9Kcj An6Q== 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 n9-v6si1821764pff.370.2018.08.07.11.55.19; Tue, 07 Aug 2018 11:55:34 -0700 (PDT) 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 S2389662AbeHGUah (ORCPT + 99 others); Tue, 7 Aug 2018 16:30:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:48604 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725881AbeHGUah (ORCPT ); Tue, 7 Aug 2018 16:30:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 12093AD04; Tue, 7 Aug 2018 18:15:02 +0000 (UTC) From: Mian Yousaf Kaukab To: will.deacon@arm.com, marc.zyngier@arm.com Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robert.richter@cavium.com, cwu@amperecomputing.com, Mian Yousaf Kaukab Subject: [PATCH 4/6] arm64: add sysfs vulnerability show for spectre v2 Date: Tue, 7 Aug 2018 20:14:17 +0200 Message-Id: <20180807181419.15690-5-ykaukab@suse.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180807181419.15690-1-ykaukab@suse.de> References: <20180807181419.15690-1-ykaukab@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Only report mitigation present if hardening callback has been successfully installed. Signed-off-by: Mian Yousaf Kaukab --- arch/arm64/kernel/cpu_errata.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 92616431ae4e..8469d3be7b15 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -481,7 +481,8 @@ multi_entry_cap_cpu_enable(const struct arm64_cpu_capabilities *entry) caps->cpu_enable(caps); } -#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +#if defined(CONFIG_HARDEN_BRANCH_PREDICTOR) || \ + defined(CONFIG_GENERIC_CPU_VULNERABILITIES) /* * List of CPUs where we need to issue a psci call to @@ -712,4 +713,35 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, return sprintf(buf, "Mitigation: __user pointer sanitization\n"); } +ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, + char *buf) +{ + u64 pfr0; + struct bp_hardening_data *data; + + pfr0 = read_cpuid(ID_AA64PFR0_EL1); + if (cpuid_feature_extract_unsigned_field(pfr0, ID_AA64PFR0_CSV2_SHIFT)) + return sprintf(buf, "Not affected\n"); + + if (cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR)) { + /* + * Hardware is vulnerable. Lets check if bp hardening callback + * has been successfully installed + */ + data = arm64_get_bp_hardening_data(); + if (data && data->fn) + return sprintf(buf, + "Mitigation: Branch predictor hardening"); + else + /* For example SMCCC_VERSION_1_0 */ + return sprintf(buf, "Vulnerable\n"); + } + + /* In case CONFIG_HARDEN_BRANCH_PREDICTOR is not enabled */ + if (is_midr_in_range_list(read_cpuid_id(), arm64_bp_harden_smccc_cpus)) + return sprintf(buf, "Vulnerable\n"); + + return sprintf(buf, "Not affected\n"); +} + #endif -- 2.11.0