Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp319355pxa; Thu, 27 Aug 2020 03:18:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwg8YzGeRcBfnvF8/oKAdysgvQcBbQXR9qxqqnLya8Vsgri4sZOZ1vIgvnuPeI05wh8lcm X-Received: by 2002:a17:906:e8f:: with SMTP id p15mr16904327ejf.290.1598523507770; Thu, 27 Aug 2020 03:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598523507; cv=none; d=google.com; s=arc-20160816; b=FSGJ3VpEl6bjAeVUpzgrABBtCL+zt24TUX8k5nFnK6mp09hyIHQHO6+lfXYTPmezIO 2s99tcWs4W7PM5u0PDPpVD4sUjol0NJp+nRgFo2atSryV9h5RNl08DtE7a0jqba6KgJO xsUIX3YAkkCNQoxgD+I6EVHo1VLUDGnKbunGwyFNKmE97wgQbINkeWJ+OaXdX4WuuZCh 7sdXP8MQnK7rG5im/wc3K2zOs/PI5kzH2JUCQxDzUrlqwcCiTwAPxhp2G7oOfxFfVuss 5kzC7QyxQ0pJgKrBvIVkJjBkegfWgDS8+Vnk7gkH5Tdx6NInsm0kQ6YYQlgVb/4HeeQ9 vVpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=QlaW0aWCx8slYF0m6x6+UnTX+8CinY7a8KebYRFydgw=; b=yGrCqRUBWoSK69Z/s4UHvp3SEFf2ctiRae1nmhobklfD/Om0qWj96tCppIVtwScQYC p+51pKwQ7DUSjfcEgeeKUy3GCUTAJPrGYELZnqoiQzYcY9Rz9N3m+52CrCKXEG4d9hns wn2cYpqowbetn6yb65zJub/KJu2vZkKFDMMI2YYDEQyZ6X/7B8YjvQgP9CncEHhN1kcm JD9SiJ9bcIVU+Gt7d1Nc4usE3IvonjEyDjCwGBCqIeqdq6LMUHZTYdjeWBrHIU44YWw/ XD4z2iyTTyjTf7mntqEKL4aXohyGNxkQZJDrHjL8esQZF+ATlHdsPXEH0gXsEjAfH6n0 DzJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si1104353edh.341.2020.08.27.03.18.05; Thu, 27 Aug 2020 03:18:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728868AbgH0KP7 (ORCPT + 99 others); Thu, 27 Aug 2020 06:15:59 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:42609 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727897AbgH0KPl (ORCPT ); Thu, 27 Aug 2020 06:15:41 -0400 Received: from mail-qk1-f178.google.com ([209.85.222.178]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPSA (Nemesis) id 1MXY6b-1k7EjF27d1-00YwRu for ; Thu, 27 Aug 2020 12:15:38 +0200 Received: by mail-qk1-f178.google.com with SMTP id u3so5321133qkd.9 for ; Thu, 27 Aug 2020 03:15:38 -0700 (PDT) X-Gm-Message-State: AOAM5313IQgaB9CrcH4STsbn76UssYC5BUhgnbfqugXfRxcVUBnmLSup zm0Y4uiJPvoM4vZdF56tCd47hO43KXwK1kbY99c= X-Received: by 2002:a37:b942:: with SMTP id j63mr18167411qkf.138.1598523337360; Thu, 27 Aug 2020 03:15:37 -0700 (PDT) MIME-Version: 1.0 References: <20200820145117.8348-1-daniel.gutson@eclypsium.com> In-Reply-To: <20200820145117.8348-1-daniel.gutson@eclypsium.com> From: Arnd Bergmann Date: Thu, 27 Aug 2020 12:15:21 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] Platform lockdown information in sysfs (v2) To: Daniel Gutson Cc: Derek Kiernan , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Greg Kroah-Hartman , Mauro Carvalho Chehab , "linux-kernel@vger.kernel.org" , Richard Hughes , Alex Bazhaniuk Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:ODR9pjc7whQH0JW1v7iW0KyUXm7FDdIpDPSvsgCyDbIjsOaKhwQ kkvVNmfM7gp18lJKyKg10YQrIZvgB+/c3RZfzXlPuI8J2RWTqRGJanKYajgl+IApSXyQjiw kvviFBK94KTT3RFrfJfSuK7gqgMy3Dlt3d5POC66pUFaFPpmKBzgxKSo/Xr9SyxOyTA8N0T gTHqrjCIPCZoz5xZiZHOg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:C0mUOtjFBpk=:c0M059xJJNfBjPL+pnFdEP twXe31XRQhZRVCnkkj8RaFHjZU+fNrOdVXbNX57m6/7nV9c9JH09eyLMVAEQeOghx47XOua/H sWJ5EKrQg0/x0bMkBoe3CcK1C6LL1ndc6uU9AtAgHEcbbGXqj4zUYiiaHlkcFVMI7I9LwQphl 7pXZzhVL/xtb8qWTaPmAJwcyYyOLiDBKyswJQg4VIpQ1tXhP7f5n5WBoYdztV+mq4emXbTqlR 7t2ojHnp06VXuIARloS6us812ZJcGmFAdvC0zgsQAi7n5ihhEL1/c0+N2Iqn1iwBH1ds10SDI azYVtYz8beIlm5PzHBHGqy+Wob0iwj3xjnDkyO/snFSTTc5RtpKgqhktX9vfpkz3AhNeUtoYw 4ID5BEDBbK3rs+IQ/uIOyVo9T41QtdXTa1gtd7dRpMCfmyVUpaX0cSd0JJgWlQfeUU+EBtEvP MjbephVJjmXb4MfsZV9Hj1rE/uqSqqaBweAvQHwLW+50gDe4wb1oI/WEaDMpfOVenuo72Q6Ip 7EIgdDXiw1K9D7EzCrxdU+73mIYTI7rjpJbiV+5xmwpuo7LlFFC1ZItNxo1eIkW+25L7GJ7Kc ilYEuls4pFP7hUTSney3G2Fzap0pWvLQIqT9ljNGor2dHNSI1IG0rnqQ8N+tsfjgezL2plWMM Fcskacol84dB+tG62TZ66Qk/X4TDBHREiL7jHt9w+hH2B+l3vbkD/AcQckwkABt/4MZBYu5s2 DjAC0s1Osjrh1OLJDwEbqDgQ9AQNaK1+5ji0yLAw5nmBwnfZmq94Szo/VJK1ZBe8DFxgajN8e 8qtnrTQxjL1nNmlioIAKTNXIhU3kDNBcuBfzh+aa0dnSqIp5WxgclYZ6TCK1NNPfdgP7O41 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 20, 2020 at 4:51 PM Daniel Gutson wrote: > > This patch exports information about the platform lockdown > firmware configuration in the sysfs filesystem. > In this initial patch, I include some configuration attributes > for the system SPI chip. > > This initial version exports the BIOS Write Enable (bioswe), > BIOS Lock Enable (ble), and the SMM BIOS Write Protect (SMM_BWP) > fields of the BIOS Control register. The idea is to keep adding more > flags, not only from the BC but also from other registers in following > versions. > > The goal is that the attributes are avilable to fwupd when SecureBoot > is turned on. > > The patch provides a new misc driver, as proposed in the previous patch, > that provides a registration function for HW Driver devices to register > class_attributes. > In this case, the intel SPI flash chip (intel-spi) registers three > class_attributes corresponding to the fields mentioned above. > > This version of the patch replaces class attributes by device > attributes. > > Signed-off-by: Daniel Gutson This looks much better than before, thanks for addressing the feedback. > diff --git a/Documentation/ABI/stable/sysfs-class-platform-lockdown b/Documentation/ABI/stable/sysfs-class-platform-lockdown > new file mode 100644 > index 000000000000..3fe75d775a42 > --- /dev/null > +++ b/Documentation/ABI/stable/sysfs-class-platform-lockdown > @@ -0,0 +1,23 @@ > +What: /sys/class/platform-lockdown/bioswe platform-lockdown is a much better name than the previous suggestions. I'm still hoping for an even better suggestion. Like everything the term "lockdown" is also overloaded a bit, with the other common meaning referring to the effort to give root users less privilege than the kernel itself, see https://lwn.net/Articles/750730/ Shouldn't there be a device name between the class name ("platform-lockdown") and the attribute name? > +PLATFORM LOCKDOWN ATTRIBUTES MODULE > +M: Daniel Gutson > +S: Supported > +F: Documentation/ABI/sysfs-class-platform-lockdown > +F: drivers/misc/platform-lockdown-attrs.c > +F: include/linux/platform_data/platform-lockdown-attrs.h include/linux/platform_data/ is not the right place for the header, this is defined to be the place for defining properties of devices that are created from old-style board files. Just put the header into include/linux/ directly. the host. > > +config PLATFORM_LOCKDOWN_ATTRS > + tristate "Platform lockdown information in the sysfs" > + depends on SYSFS > + help > + This kernel module is a helper driver to provide information about > + platform lockdown settings and configuration. > + This module is used by other device drivers -such as the intel-spi- > + to publish the information in /sys/class/platform-lockdown. Maybe mention fwupd in the description in some form. > + > +static struct class platform_lockdown_class = { > + .name = "platform-lockdown", > + .owner = THIS_MODULE, > +}; > + > +struct device *register_platform_lockdown_data_device(struct device *parent, > + const char *name) > +{ > + return device_create(&platform_lockdown_class, parent, MKDEV(0, 0), > + NULL, name); > +} > +EXPORT_SYMBOL_GPL(register_platform_lockdown_data_device); > + > +void unregister_platform_lockdown_data_device(struct device *dev) > +{ > + device_unregister(dev); > +} > +EXPORT_SYMBOL_GPL(unregister_platform_lockdown_data_device); > + > +int register_platform_lockdown_attribute(struct device *dev, > + struct device_attribute *dev_attr) > +{ > + return device_create_file(dev, dev_attr); > +} > +EXPORT_SYMBOL_GPL(register_platform_lockdown_attribute); > + > +void register_platform_lockdown_attributes(struct device *dev, > + struct device_attribute dev_attrs[]) > +{ > + u32 idx = 0; > + > + while (dev_attrs[idx].attr.name != NULL) { > + register_platform_lockdown_attribute(dev, &dev_attrs[idx]); > + idx++; > + } There is a bit of a race with creating the device first and then the attributes. Generally it seems better to me to use device_create_with_groups() instead so the device shows up with all attributes in place already. > +void register_platform_lockdown_custom_attributes(struct device *dev, > + void *custom_attrs, > + size_t dev_attr_offset, > + size_t custom_attr_size) This interface seems to be overly complex, I would hope it can be avoided. > +static ssize_t cnl_spi_attr_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + u32 bcr; > + struct cnl_spi_attr *cnl_spi_attr = container_of(attr, > + struct cnl_spi_attr, dev_attr); > + > + if (class_child_device != dev) > + return -EIO; > + > + if (dev->parent == NULL) > + return -EIO; > + > + if (pci_read_config_dword(container_of(dev->parent, struct pci_dev, dev), > + BCR, &bcr) != PCIBIOS_SUCCESSFUL) > + return -EIO; > + > + return sprintf(buf, "%d\n", (int)!!(bcr & cnl_spi_attr->mask)); > +} If I understand it right, that complexity comes from attempting to have a single show callback for three different flags. To me that actually feels more complicated than having an attribute group with three similar but simpler show callbacks. > static void intel_spi_pci_remove(struct pci_dev *pdev) > { > + if (class_child_device != NULL) { Please avoid the global variable here and just add a member in the per-device data. > + unregister_platform_lockdown_custom_attributes( > + class_child_device, > + cnl_spi_attrs, > + offsetof(struct cnl_spi_attr, dev_attr), > + sizeof(struct cnl_spi_attr)); > + > + unregister_platform_lockdown_data_device(class_child_device); It should be possible to just destroy the attributes as part of unregister_platform_lockdown_data_device. Arnd