Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754827AbeAGWP0 (ORCPT + 1 other); Sun, 7 Jan 2018 17:15:26 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:59746 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754703AbeAGWPY (ORCPT ); Sun, 7 Jan 2018 17:15:24 -0500 Date: Sun, 7 Jan 2018 17:14:38 -0500 From: Konrad Rzeszutek Wilk To: Thomas Gleixner Cc: LKML , Linus Torvalds , Greg Kroah-Hartman , Ingo Molnar , Peter Zijlstra , Borislav Petkov , David Woodhouse , Dave Hansen , Will Deacon Subject: Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder Message-ID: <20180107221438.GS21689@char.us.oracle.com> References: <20180107214759.387300853@linutronix.de> <20180107214913.096657732@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180107214913.096657732@linutronix.de> User-Agent: Mutt/1.8.3 (2017-05-23) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8767 signatures=668652 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801070331 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Sun, Jan 07, 2018 at 10:48:00PM +0100, Thomas Gleixner wrote: > As the meltdown/spectre problem affects several CPU architectures, it makes > sense to have common way to express whether a system is affected by a > particular vulnerability or not. If affected the way to express the > mitigation should be common as well. > > Create /sys/devices/system/cpu/vulnerabilities folder and files for > meltdown, spectre_v1 and spectre_v2. > > Allow architectures to override the show function. > > Signed-off-by: Thomas Gleixner > --- > Documentation/ABI/testing/sysfs-devices-system-cpu | 16 +++++++ > drivers/base/Kconfig | 3 + > drivers/base/cpu.c | 48 +++++++++++++++++++++ > include/linux/cpu.h | 7 +++ > 4 files changed, 74 insertions(+) > > --- a/Documentation/ABI/testing/sysfs-devices-system-cpu > +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu > @@ -373,3 +373,19 @@ Contact: Linux kernel mailing list Description: information about CPUs heterogeneity. > > cpu_capacity: capacity of cpu#. > + > +What: /sys/devices/system/cpu/vulnerabilities > + /sys/devices/system/cpu/vulnerabilities/meltdown > + /sys/devices/system/cpu/vulnerabilities/spectre_v1 > + /sys/devices/system/cpu/vulnerabilities/spectre_v2 > +Date: Januar 2018 s/Januar/January/ and with that Reviewed-by: Konrad Rzeszutek Wilk Thank you! > +#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES > + > +ssize_t __weak cpu_show_meltdown(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + return sprintf(buf, "Not affected\n"); > +} > + > +ssize_t __weak cpu_show_spectre_v1(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + return sprintf(buf, "Not affected\n"); > +} > + > +ssize_t __weak cpu_show_spectre_v2(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + return sprintf(buf, "Not affected\n"); > +} > + > +static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); > +static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); > +static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); > + > +static struct attribute *cpu_root_vulnerabilities_attrs[] = { > + &dev_attr_meltdown.attr, > + &dev_attr_spectre_v1.attr, > + &dev_attr_spectre_v2.attr, > + NULL > +}; > + > +static const struct attribute_group cpu_root_vulnerabilities_group = { > + .name = "vulnerabilities", > + .attrs = cpu_root_vulnerabilities_attrs, > +}; > + > +static void __init cpu_register_vulnerabilities(void) > +{ > + if (sysfs_create_group(&cpu_subsys.dev_root->kobj, > + &cpu_root_vulnerabilities_group)) > + pr_err("Unable to register CPU vulnerabilities\n"); > +} > + > +#else > +static inline void cpu_register_vulnerabilities(void) { } > +#endif > + > void __init cpu_dev_init(void) > { > if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups)) > panic("Failed to register CPU subsystem"); > > cpu_dev_register_generic(); > + cpu_register_vulnerabilities(); > } > --- a/include/linux/cpu.h > +++ b/include/linux/cpu.h > @@ -47,6 +47,13 @@ extern void cpu_remove_dev_attr(struct d > extern int cpu_add_dev_attr_group(struct attribute_group *attrs); > extern void cpu_remove_dev_attr_group(struct attribute_group *attrs); > > +extern ssize_t cpu_show_meltdown(struct device *dev, > + struct device_attribute *attr, char *buf); > +extern ssize_t cpu_show_spectre_v1(struct device *dev, > + struct device_attribute *attr, char *buf); > +extern ssize_t cpu_show_spectre_v2(struct device *dev, > + struct device_attribute *attr, char *buf); > + > extern __printf(4, 5) > struct device *cpu_device_create(struct device *parent, void *drvdata, > const struct attribute_group **groups, > >