From patchwork Wed Jan 9 23:55:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 10754993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6459F6C5 for ; Wed, 9 Jan 2019 23:56:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50F9A28C6F for ; Wed, 9 Jan 2019 23:56:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41A5929289; Wed, 9 Jan 2019 23:56:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B1EA128C6F for ; Wed, 9 Jan 2019 23:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GV+/tRvzp+paqmRtucWCjE6kLQ71L9i5/1j9yFrQeKE=; b=PndL8UiJ3bXXkGZA5Ub1JQkeWI h9IpuYxKWQ/+M4jLOWtokMlGNhU+j7318wPjGiJtvl6Pucp8zQugA4huprserhNZuCCkvPfjvx03S Vn1Txq5x8WHLHTWaE0iDsN9APp24o3iwKhL091hEDoicGSSfZFNwVzInyE1zUxNRVXc10mOrQOUfr caOcq0trvp8NTYxTaxvflVHu7BVWq4BkOhJlydcB+NCbAMaJL2tjkx5G7yS+IrVCtpF7zGwCgViFT 5jEIwIP5RbdOrEyacItqlsQYCDcPfSxfjUx4UFlie7ZilOkwbJ6JUQ+xSGulxJIe/0jcwRH5tfspt XdxQyzAA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ghNhu-0006S6-G4; Wed, 09 Jan 2019 23:56:22 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ghNhR-0005xa-IN for linux-arm-kernel@lists.infradead.org; Wed, 09 Jan 2019 23:55:55 +0000 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 EE8C9EBD; Wed, 9 Jan 2019 15:55:50 -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 019CC3F5AF; Wed, 9 Jan 2019 15:55:49 -0800 (PST) From: Jeremy Linton To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/7] sysfs/cpu: Allow individual architectures to select vulnerabilities Date: Wed, 9 Jan 2019 17:55:38 -0600 Message-Id: <20190109235544.2992426-2-jeremy.linton@arm.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190109235544.2992426-1-jeremy.linton@arm.com> References: <20190109235544.2992426-1-jeremy.linton@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190109_155553_669342_9DDB6C2B X-CRM114-Status: GOOD ( 14.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mlangsdo@redhat.com, "Rafael J . Wysocki" , catalin.marinas@arm.com, will.deacon@arm.com, Ingo Molnar , stefan.wahren@i2se.com, Andi Kleen , julien.thierry@arm.com, steven.price@arm.com, Waiman Long , dave.martin@arm.com, suzuki.poulose@arm.com, marc.zyngier@arm.com, ykaukab@suse.de, Josh Poimboeuf , Thomas Gleixner , shankerd@codeaurora.org, Konrad Rzeszutek Wilk , Jiri Kosina , linux-kernel@vger.kernel.org, Jeremy Linton , Greg Kroah-Hartman MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP As suggested on the list, https://lkml.org/lkml/2019/1/4/282, there are a number of cases where its useful for a system to avoid exporting a sysfs entry for a given vulnerability. This set adds an architecture specific callback which returns the bitmap of vulnerabilities the architecture would like to advertise. Signed-off-by: Jeremy Linton Cc: Greg Kroah-Hartman Cc: Rafael J. Wysocki Cc: Thomas Gleixner Cc: Josh Poimboeuf Cc: Konrad Rzeszutek Wilk Cc: Ingo Molnar Cc: Waiman Long Cc: Andi Kleen Cc: Jiri Kosina --- drivers/base/cpu.c | 19 +++++++++++++++++++ include/linux/cpu.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index eb9443d5bae1..35f6dfb24cd6 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -561,6 +561,11 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = { NULL }; +uint __weak arch_supported_vuln_attr_fields(void) +{ + return VULN_MELTDOWN|VULN_SPECTREV1|VULN_SPECTREV2|VULN_SSB|VULN_L1TF; +} + static const struct attribute_group cpu_root_vulnerabilities_group = { .name = "vulnerabilities", .attrs = cpu_root_vulnerabilities_attrs, @@ -568,6 +573,20 @@ static const struct attribute_group cpu_root_vulnerabilities_group = { static void __init cpu_register_vulnerabilities(void) { + int fld; + int max_fields = ARRAY_SIZE(cpu_root_vulnerabilities_attrs) - 1; + struct attribute **hd = cpu_root_vulnerabilities_attrs; + uint enabled_fields = arch_supported_vuln_attr_fields(); + + /* only enable entries requested by the arch code */ + for (fld = 0; fld < max_fields; fld++) { + if (enabled_fields & 1 << fld) { + *hd = cpu_root_vulnerabilities_attrs[fld]; + hd++; + } + } + *hd = NULL; + if (sysfs_create_group(&cpu_subsys.dev_root->kobj, &cpu_root_vulnerabilities_group)) pr_err("Unable to register CPU vulnerabilities\n"); diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 218df7f4d3e1..5e45814bcc24 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -189,4 +189,11 @@ static inline void cpu_smt_check_topology_early(void) { } static inline void cpu_smt_check_topology(void) { } #endif +/* generic cpu vulnerability attributes */ +#define VULN_MELTDOWN 0x01 +#define VULN_SPECTREV1 0x02 +#define VULN_SPECTREV2 0x04 +#define VULN_SSB 0x08 +#define VULN_L1TF 0x10 + #endif /* _LINUX_CPU_H_ */