Firmware security information in SYSFS
Subsystems (3)
PATCH 1/1 Firmware security information in SYSFS
This patch exports security-related 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 registration functions for HW Driver devices. In this case, the intel SPI flash chip (intel-spi) registers functions so it can export the three attributes mentioned above.
--- .../ABI/stable/sysfs-firmware-security | 23 ++++ MAINTAINERS | 7 ++ drivers/misc/Kconfig | 9 ++ drivers/misc/Makefile | 1 + drivers/misc/firmware_security_data.c | 103 ++++++++++++++++++ drivers/mtd/spi-nor/controllers/Kconfig | 1 + .../mtd/spi-nor/controllers/intel-spi-pci.c | 45 +++++++- drivers/mtd/spi-nor/controllers/intel-spi.c | 92 ++++++++++++---- .../platform_data/firmware_security_data.h | 17 +++ 9 files changed, 277 insertions(+), 21 deletions(-) create mode 100644 Documentation/ABI/stable/sysfs-firmware-security create mode 100644 drivers/misc/firmware_security_data.c create mode 100644 include/linux/platform_data/firmware_security_data.h
Documentation/ABI/stable/sysfs-firmware-security new file +23 -0
@@ -0,0 +1,23 @@ +What: /sys/kernel/firmware-security/bioswe +Date: July 2020 +KernelVersion: 5.8.0 +Contact: Daniel Gutson <[email protected]> +Description: If the system firmware set BIOS Write Enable. + 0: writes disabled, 1: writes enabled. +Users: https://github.com/fwupd/fwupd + +What: /sys/kernel/firmware-security/ble +Date: July 2020 +KernelVersion: 5.8.0 +Contact: Daniel Gutson <[email protected]> +Description: If the system firmware set Bios Lock Enable. + 0: SMM lock disabled, 1: SMM lock enabled. +Users: https://github.com/fwupd/fwupd + +What: /sys/kernel/firmware-security/smm_bwp +Date: July 2020 +KernelVersion: 5.8.0 +Contact: Daniel Gutson <[email protected]> +Description: If the system firmware set SMM Bios Write Protect. + 0: writes disabled unless in SMM, 1: writes enabled. +Users: https://github.com/fwupd/fwupd
MAINTAINERS +7 -0
@@ -6699,6 +6699,13 @@ F: Documentation/firmware_class/ F: drivers/base/firmware_loader/ F: include/linux/firmware.h +FIRMWARE SECURITY DATA +M: Daniel Gutson <[email protected]> +S: Supported +F: Documentation/ABI/sysfs-firmware-security +F: drivers/misc/firmware_security_data.c +F: include/linux/platform_data/firmware_security_data.h + FLASH ADAPTER DRIVER (IBM Flash Adapter 900GB Full Height PCI Flash Card) M: Joshua Morris <[email protected]> M: Philip Kelleher <[email protected]>
drivers/misc/Kconfig +9 -0
@@ -456,6 +456,15 @@ config PVPANIC a paravirtualized device provided by QEMU; it lets a virtual machine (guest) communicate panic events to the host. +config FIRMWARE_SECURITY_DATA + tristate "Firmware security information in the SYSFS" + depends on SYSFS + help + This kernel module is a helper driver to provide information about + firmware security settings and configuration. + This module is used by other device drivers -such as the intel-spi- + to publish the information in /sys/kernel/firmware_security. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -57,3 +57,4 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_UACCE) += uacce/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o +obj-$(CONFIG_FIRMWARE_SECURITY_DATA) += firmware_security_data.o
drivers/misc/firmware_security_data.c new file +103 -0
103 lines not on this page · raw message
drivers/mtd/spi-nor/controllers/Kconfig +1 -0
@@ -45,6 +45,7 @@ config SPI_INTEL_SPI_PCI tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)" depends on X86 && PCI select SPI_INTEL_SPI + select FIRMWARE_SECURITY_DATA help This enables PCI support for the Intel PCH/PCU SPI controller in master mode. This controller is present in modern Intel hardware
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +44 -1
74 lines not on this page · raw message
drivers/mtd/spi-nor/controllers/intel-spi.c +72 -20
192 lines not on this page · raw message
include/linux/platform_data/firmware_security_data.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Firmware security data kernel module +* +* Copyright (C) 2020 Daniel Gutson <[email protected]> +* Copyright (C) 2020 Eclypsium Inc. +*/ +#ifndef FIRMWARE_SECURITY_DATA_H +#define FIRMWARE_SECURITY_DATA_H + +#include <linux/types.h> + +extern int register_firmware_security_data_callback ( +const char *name,ssize_t (*callback)(char *buf,void *private_data), +void *private_data); + +#endif /* FIRMWARE_SECURITY_DATA_H */
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 1 line · Daniel Gutson
+What:
/sys/kernel/firmware-security/bioswe
Ick, I stopped reading right here.
No, this is not where this belongs.
We already have /sys/firmware/, right? And firmware-specific subdirectories below that.
We also have /sys/devices/system/ and I think that would be a much better place for this, as it is easier to work with a real 'struct device' than a "raw" kobject any day. Bonus is you get full support of userspace libraries when you do that, unlike when dealing with kobjects.
Also, this really is a _SPECIFIC_ type of firmware that supports these features, right? Why not call that out too? This is not generic by any means.
thanks,
greg k-h
Arnd Bergmann
maintainerQuoted 11 lines · Greg Kroah-Hartman
Quoted 1 line · Daniel Gutson
+What:
/sys/kernel/firmware-security/biosweIck, I stopped reading right here.
No, this is not where this belongs.
We already have
/sys/firmware/, right? And firmware-specific subdirectories below that.
Quoted 8 lines
We also have
/sys/devices/system/and I think that would be a much better place for this, as it is easier to work with a real 'struct device' than a "raw" kobject any day. Bonus is you get full support of userspace libraries when you do that, unlike when dealing with kobjects.Also, this really is a _SPECIFIC_ type of firmware that supports these features, right? Why not call that out too? This is not generic by any means.
As I suggested in my previous review, I wouldn't worry too much about the user interface at the start, but instead first work out how the hardware support fits in with the existing drivers and once that looks fine decide on how to export it to user space.
I agree the /sys/kernel/firmware-security/bioswe sounds like the wrong place, but I'm not sure if adding any other new directory in sysfs is much better. I think the most promising would be to have it on the sysfs directory for the device it refers to, but let's first see how the information gets into the kernel.
Arnd
Greg Kroah-Hartman
maintainerQuoted 27 lines · Arnd Bergmann
Quoted 11 lines · Greg Kroah-Hartman
Quoted 1 line · Daniel Gutson
+What:
/sys/kernel/firmware-security/biosweIck, I stopped reading right here.
No, this is not where this belongs.
We already have
/sys/firmware/, right? And firmware-specific subdirectories below that.Quoted 8 lines
We also have
/sys/devices/system/and I think that would be a much better place for this, as it is easier to work with a real 'struct device' than a "raw" kobject any day. Bonus is you get full support of userspace libraries when you do that, unlike when dealing with kobjects.Also, this really is a _SPECIFIC_ type of firmware that supports these features, right? Why not call that out too? This is not generic by any means.
As I suggested in my previous review, I wouldn't worry too much about the user interface at the start, but instead first work out how the hardware support fits in with the existing drivers and once that looks fine decide on how to export it to user space.
Quoted 5 lines
I agree the
/sys/kernel/firmware-security/bioswesounds like the wrong place, but I'm not sure if adding any other new directory in sysfs is much better. I think the most promising would be to have it on the sysfs directory for the device it refers to, but let's first see how the information gets into the kernel.
Yes, the directory for the specific device would probably be best, but let's see where that really is :)
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): CAFmMkTFLm9mw5-8Dj_7rhP2KBcLUoJ1WcQCJv5_k+QRsmJPxjg@mail.gmail.com
Greg Kroah-Hartman
maintainerQuoted 46 lines · Daniel Gutson
Quoted 28 lines · Arnd Bergmann
Quoted 11 lines · Greg Kroah-Hartman
Quoted 1 line · Daniel Gutson
+What:
/sys/kernel/firmware-security/biosweIck, I stopped reading right here.
No, this is not where this belongs.
We already have
/sys/firmware/, right? And firmware-specific subdirectories below that.Quoted 8 lines
We also have
/sys/devices/system/and I think that would be a much better place for this, as it is easier to work with a real 'struct device' than a "raw" kobject any day. Bonus is you get full support of userspace libraries when you do that, unlike when dealing with kobjects.Also, this really is a _SPECIFIC_ type of firmware that supports these features, right? Why not call that out too? This is not generic by any means.
As I suggested in my previous review, I wouldn't worry too much about the user interface at the start, but instead first work out how the hardware
support fits in with the existing drivers and once that looks fine decide on how to export it to user space.Quoted 4 lines
I agree the
/sys/kernel/firmware-security/bioswesounds like the wrong place, but I'm not sure if adding any other new directory in sysfs is much better. I think the most promising would be to have it on the sysfs directory for the device it refers to,My idea is to have all the firmware security information together in the same place; this information comes from many devices.
This initial patch involves the SPI Controller, and I don't want to add more stuff until there
is a consensus.
So, do you have a suggestion where to put this information?/sys/devices/system/firmware-security?/sys/firmware/security?
other?
Quoted 1 line
Please advise.
It's fun to focus on things like this, as it's the most visible part, but are you sure the "talk to the hardware" part is working properly?
If so, great, it should be a "class", as that way it is independent of any hardware type, right? Classes show how devices talk to userspace in a common way (input, tty, led, block, etc.) So why is this any different from that?
But worry about the other part first please. And if you ever find yourself using a "raw" kobject, you know you have done something wrong :)
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): CAFmMkTEsm7CRBzEJSCjkhCT7NHvRUXzcgchExbnfFbwPjT0YFg@mail.gmail.com
Greg Kroah-Hartman
maintainerQuoted 66 lines · Daniel Gutson
Quoted 52 lines · Greg Kroah-Hartman
Quoted 10 lines · Daniel Gutson
Quoted 8 lines · Arnd Bergmann
Quoted 6 lines · Greg Kroah-Hartman
Quoted 1 line · Daniel Gutson
+What:
/sys/kernel/firmware-security/biosweIck, I stopped reading right here.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
No, this is not where this belongs.
We already have
/sys/firmware/, right? And firmware-specific subdirectories below that.We also have
/sys/devices/system/and I think that would be a much better place for this, as it is easier to work with a real 'struct device' than a "raw" kobject any day. Bonus is you get full supportof
Quoted 1 line
Quoted 1 line
Quoted 1 line
userspace libraries when you do that, unlike when dealing with
kobjects.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Also, this really is a _SPECIFIC_ type of firmware that supports
these
Quoted 1 line
Quoted 1 line
Quoted 1 line
features, right? Why not call that out too? This is not generic by
any
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
means.
As I suggested in my previous review, I wouldn't worry too much about the user interface at the start, but instead first work out how the hardware
support fits in with the existing drivers and once that looks finedecide
Quoted 18 lines
Quoted 6 lines
on how to export it to user space.
I agree the
/sys/kernel/firmware-security/bioswesounds like the wrong place, but I'm not sure if adding any other new directory in sysfs is much better. I think the most promising would be to have it on the sysfs directory for the device it refers to,My idea is to have all the firmware security information together in the same place; this information comes from many devices.
This initial patch involves the SPI Controller, and I don't want to add more stuff until there
is a consensus.
So, do you have a suggestion where to put this information?/sys/devices/system/firmware-security?/sys/firmware/security?
other?Quoted 5 lines
Quoted 1 line
Please advise.
It's fun to focus on things like this, as it's the most visible part, but are you sure the "talk to the hardware" part is working properly?
Yes.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
If so, great, it should be a "class", as that way it is independent of any hardware type, right? Classes show how devices talk to userspace in a common way (input, tty, led, block, etc.) So why is this any different from that?
Are you suggesting to create a new class, or use an existing one?
Probably a new one, unless you can find an existing one that would fit?
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): CAFmMkTGtG6p48o9qSzYqQs8mJXiGAMw7b5wp2LLAmwcdhn2u4A@mail.gmail.com
Greg Kroah-Hartman
maintainerQuoted 89 lines · Daniel Gutson
Quoted 86 lines · Greg Kroah-Hartman
Quoted 5 lines · Daniel Gutson
Quoted 2 lines · Greg Kroah-Hartman
Quoted 1 line · Daniel Gutson
On Fri, Jul 17, 2020 at 11:41 AM Arnd Bergmann <[email protected]>
Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Daniel Gutson
+What:
/sys/kernel/firmware-security/biosweQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Ick, I stopped reading right here.
No, this is not where this belongs.
We already have
/sys/firmware/, right? And firmware-specific subdirectories below that.We also have
/sys/devices/system/and I think that would be amuch
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
better place for this, as it is easier to work with a real
'struct
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
device' than a "raw" kobject any day. Bonus is you get full
support
Quoted 7 lines
Quoted 7 lines
of
Quoted 1 line
Quoted 1 line
Quoted 1 line
userspace libraries when you do that, unlike when dealing with
kobjects.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Also, this really is a _SPECIFIC_ type of firmware that supports
these
Quoted 1 line
Quoted 1 line
Quoted 1 line
features, right? Why not call that out too? This is not
generic by
Quoted 4 lines
Quoted 4 lines
any
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
means.
As I suggested in my previous review, I wouldn't worry too much
about
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
the user interface at the start, but instead first work out how the hardware
support fits in with the existing drivers and once that looks finedecide
Quoted 3 lines
Quoted 3 lines
on how to export it to user space.
I agree the
/sys/kernel/firmware-security/bioswesounds like thewrong
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
place, but I'm not sure if adding any other new directory in sysfs
is
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
much better. I think the most promising would be to have it on the sysfs directory for the device it refers to,
My idea is to have all the firmware security information together in
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
same place; this information comes from many devices. This initial patch involves the SPI Controller, and I don't want to
add
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
more stuff until there
is a consensus.
So, do you have a suggestion where to put this information?/sys/devices/system/firmware-security?/sys/firmware/security?
other?Quoted 13 lines
Quoted 5 lines
Quoted 1 line
Please advise.
It's fun to focus on things like this, as it's the most visible part, but are you sure the "talk to the hardware" part is working properly?
Yes.
Quoted 3 lines
If so, great, it should be a "class", as that way it is independent of any hardware type, right? Classes show how devices talk to userspace
in
Quoted 5 lines
Quoted 3 lines
a common way (input, tty, led, block, etc.) So why is this any different from that?
Are you suggesting to create a new class, or use an existing one?
Quoted 8 lines
Quoted 2 lines
Probably a new one, unless you can find an existing one that would fit?
IIUC, Arnd Bergmann proposed that I create a class for each device driver (in this case,
for the intel-spi, though I think the class would be spi-nor) and add attributes to it.
In such a case, your proposal and his are different, mutually exclusive.
Classes should be driver agnositic, and you should not have a single class per driver, as that is pretty pointless.
Quoted 2 lines
For me it's easier and makes more sense to have a class for, say, firmware-security (if I understood you correctly).
I still think that's a horrible name, as that is not what you are describing here, but sure, a single class is good.
thanks,
greg k-h
Arnd Bergmann
maintainerQuoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Daniel Gutson
Quoted 11 lines · Greg Kroah-Hartman
Quoted 2 lines
Quoted 2 lines
If so, great, it should be a "class", as that way it is independent of any hardware type, right? Classes show how devices talk to userspace
in
Quoted 5 lines
Quoted 3 lines
a common way (input, tty, led, block, etc.) So why is this any different from that?
Are you suggesting to create a new class, or use an existing one?
Probably a new one, unless you can find an existing one that would fit?
Quoted 8 lines
Quoted 5 lines
IIUC, Arnd Bergmann proposed that I create a class for each device driver (in this case,
for the intel-spi, though I think the class would be spi-nor) and add attributes to it.
In such a case, your proposal and his are different, mutually exclusive.Classes should be driver agnositic, and you should not have a single class per driver, as that is pretty pointless.
Yes, that was of course my suggestion as well. The class is how the interface is shown to user space, and each driver that can provide the functionality would have to register an instance of the class device per physical device.
Quoted 5 lines
Quoted 2 lines
For me it's easier and makes more sense to have a class for, say, firmware-security (if I understood you correctly).
I still think that's a horrible name, as that is not what you are describing here, but sure, a single class is good.
Right, neither the word "firmware" nor the word "security" gives it any sufficiently specific meaning.
Arnd
Arnd Bergmann
maintainerQuoted 17 lines · Daniel Gutson
Quoted 10 lines · Arnd Bergmann
Quoted 4 lines
Also, this really is a _SPECIFIC_ type of firmware that supports these features, right? Why not call that out too? This is not generic by any means.
As I suggested in my previous review, I wouldn't worry too much about the user interface at the start, but instead first work out how the hardware support fits in with the existing drivers and once that looks fine decide on how to export it to user space.
Quoted 4 lines
I agree the
/sys/kernel/firmware-security/bioswesounds like the wrong place, but I'm not sure if adding any other new directory in sysfs is much better. I think the most promising would be to have it on the sysfs directory for the device it refers to,
Quoted 7 lines
My idea is to have all the firmware security information together in the same place; this information comes from many devices. This initial patch involves the SPI Controller, and I don't want to add more stuff until there
is a consensus.
So, do you have a suggestion where to put this information?/sys/devices/system/firmware-security?/sys/firmware/security?
other?
I think it needs to be more specific than this. On a many machines there may be a dozens of things described as "firmware" of some sort, and even more things that relate to "security". You may also have to consider the problem that there may be multiple devices that want to register to this interface to export similar bits of information.
In the two drivers you have changed, there is a device node, so the natural concept would be to either have attributes in that node, or a child device under it with a fixed set of attributes, which can then be referenced as a class device like
/sys/class/${NAME}/${NAME0} -> ../../devices/ci0000:00/0000:00:01.1/0000:01:00.2/${NAME} /sys/devices/ci0000:00/0000:00:01.1/0000:01:00.2/${NAME}/${ATTRIBUTE}
This is easy to implement, and easy to access from user space,
if this works for you, the hardest part may be to decide on what to call it ;-)
Arnd
kernel test robot
build botI love your patch! Yet something to improve:
Hi Daniel,
I love your patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on soc/for-next linus/master v5.8-rc5 next-20200716] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Gutson/Firmware-security-information-in-SYSFS/20200717-071308 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git fadbfc38dde26d31e901c3c85cf01332cb6a2224 config: x86_64-allyesconfig (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ed6b578040a85977026c93bf4188f996148f3218)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/misc/firmware_security_data.c:51:2: error: member reference type 'struct attribute' is not a pointer; did you mean to use '.'?
sysfs_attr_init(new_data->kobj_attr.attr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/sysfs.h:55:8: note: expanded from macro 'sysfs_attr_init'
(attr)->key = &__key; \
~~~~~~^
>> drivers/misc/firmware_security_data.c:51:2: error: expression is not assignable
sysfs_attr_init(new_data->kobj_attr.attr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/sysfs.h:55:14: note: expanded from macro 'sysfs_attr_init'
(attr)->key = &__key; \
~~~~~~~~~~~ ^2 errors generated.
vim +51 drivers/misc/firmware_security_data.c
34
35 int register_firmware_security_data_callback(
36 const char *name, ssize_t (*callback)(char *buf, void *private_data),
37 void *private_data)
38 {
39 int retval;
40
41 struct firmware_security_data *new_data;
42
43 if (name == NULL || name[0] == 0)
44 return -EINVAL;
45
46 new_data = kmalloc(sizeof(struct firmware_security_data), GFP_KERNEL);
47 if (new_data == NULL)
48 return -ENOMEM;
49
50 /* initialize attributes: */
> 51 sysfs_attr_init(new_data->kobj_attr.attr);
52 new_data->kobj_attr.attr.name = name;
53 new_data->kobj_attr.attr.mode = 0664;
54 new_data->kobj_attr.show = internal_callback;
55 new_data->kobj_attr.store = NULL;
56
57 new_data->callback = callback;
58 new_data->private_data = private_data;
59
60 /* attempt to create the file: */
61 retval = sysfs_create_file(firmware_data_kobj,
62 &new_data->kobj_attr.attr);
63 if (retval == 0) {
64 /* append to the list of entries: */
65 INIT_LIST_HEAD(&new_data->list_node);
66 mutex_lock(&entries_mutex);
67 list_add(&new_data->list_node, &entries);
68 mutex_unlock(&entries_mutex);
69 } else {
70 kfree(new_data);
71 }
72
73 return retval;
74 }
75 EXPORT_SYMBOL_GPL(register_firmware_security_data_callback);
76 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Arnd Bergmann
maintainerdrivers/misc/firmware_security_data.c line 37
Quoted 13 lines · Daniel Gutson
drivers/misc/firmware_security_data.c new file +11
-0+static ssize_t internal_callback (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct firmware_security_data *fwsd = + container_of(attr, struct firmware_security_data, kobj_attr); +return fwsd->callback (buf, fwsd->private_data); +} + +int register_firmware_security_data_callback ( +const char *name,ssize_t (*callback)(char *buf,void *private_data), +void *private_data)
Why do you have a callback interface here? I would have expected all the data to be static during the kernel run time, so just passing the information here would make it much simpler.
Quoted 27 lines
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +27
-0+static ssize_t cnl_read_field (char *buf,struct pci_dev *pdev,u32 mask) +{ +u32 bcr; + +if (pci_read_config_dword (pdev,BCR , &bcr) !=PCIBIOS_SUCCESSFUL ) +return -EIO ; + +return sprintf (buf,"%d\n" , (int )!!(bcr & mask)); +} + +static ssize_t cnl_wpd_firmware_security_callbacks (char *buf, +void *private_data) +{ +return cnl_read_field (buf, (struct pci_dev *)private_data,BCR_WPD ); +} + +static ssize_t cnl_ble_firmware_security_callbacks (char *buf, +void *private_data) +{ +return cnl_read_field (buf, (struct pci_dev *)private_data,BCR_BLE ); +} + +static ssize_t cnl_smm_bwp_firmware_security_callbacks (char *buf, +void *private_data) +{ +return cnl_read_field (buf, (struct pci_dev *)private_data,BCR_SMM_BWP ); +}
drivers/mtd/spi-nor/controllers/intel-spi-pci.c static const struct intel_spi_boardinfo cnl_info = { · line 66
Quoted 10 lines
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +10
-0+ +static void register_firmware_security_data_callbacks (struct pci_dev *pdev) +{ +register_firmware_security_data_callback ( +"bioswe" , &cnl_wpd_firmware_security_callbacks, pdev); +register_firmware_security_data_callback ( +"ble" , &cnl_ble_firmware_security_callbacks, pdev); +register_firmware_security_data_callback ( +"smm_bwp" , &cnl_smm_bwp_firmware_security_callbacks, pdev); +}
All of this should probably become a single function that reads the registers and then passes the contents into whatever common function you have that makes them visible to user space.
Quoted 7 lines
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +1
-1@@ -76,7 +119,7 @@ static const struct pci_device_id intel_spi_pci_ids[] = { { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info }, { PCI_VDEVICE(INTEL, 0xa324), (unsigned long)&cnl_info }, { PCI_VDEVICE(INTEL, 0xa3a4), (unsigned long)&bxt_info }, - { }, + {}, };
...
Quoted 7 lines
#include "
intel-spi.h"drivers/mtd/spi-nor/controllers/intel-spi.c +0
-1@@ -48,17 +49,17 @@#define FADDR 0x08#define DLOCK 0x0c -#define FDATA (n) (0x10 + ((n) * 4))
drivers/mtd/spi-nor/controllers/intel-spi.c line 60
Quoted 10 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +2
-1+#define FDATA (n) (0x10 + ((n)*4))#define FRACC 0x50 -#define FREG (n) (0x54 + ((n) * 4)) +#define FREG (n) (0x54 + ((n)*4))#define FREG_BASE_MASK 0x3fff#define FREG_LIMIT_SHIFT 16#define FREG_LIMIT_MASK (0x03fff << FREG_LIMIT_SHIFT)
Accidental whitespace change, please skip these changes?
drivers/mtd/spi-nor/controllers/intel-spi.c struct intel_spi { · line 171
Quoted 10 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +2
-1@@ -161,7 +164,8 @@ struct intel_spi {static bool writeable;module_param (writeable, bool,0 ); -MODULE_PARM_DESC (writeable,"Enable write access to SPI flash chip (default=0)" ); +MODULE_PARM_DESC (writeable, +"Enable write access to SPI flash chip (default=0)" );static void intel_spi_dump_regs (struct intel_spi *ispi) {
This looks like a useful change, but it should be a separate patch.
Quoted 13 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +2
-2@@ -179,8 +183,8 @@ static void intel_spi_dump_regs(struct intel_spi *ispi)dev_dbg (ispi->dev,"DLOCK=0x%08x\n" ,readl (ispi->base +DLOCK ));for (i =0 ; i <16 ; i++) -dev_dbg (ispi->dev,"FDATA(%d)=0x%08x\n" , - i,readl (ispi->base +FDATA (i))); +dev_dbg (ispi->dev,"FDATA(%d)=0x%08x\n" , i, +readl (ispi->base +FDATA (i)));dev_dbg (ispi->dev,"FRACC=0x%08x\n" ,readl (ispi->base +FRACC ));@@ -220,9 +224,8 @@ static void intel_spi_dump_regs(struct intel_spi *ispi) base = value &PR_BASE_MASK ;
drivers/mtd/spi-nor/controllers/intel-spi.c static void intel_spi_dump_regs(struct intel_spi *ispi) · line 231
Quoted 10 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +2
-3dev_dbg (ispi->dev," %02d base: 0x%08x limit: 0x%08x [%c%c]\n" , - i, base <<12 , (limit <<12 ) |0xfff , - value &PR_WPE ?'W' :'.' , - value &PR_RPE ?'R' :'.' ); + i, base <<12 , (limit <<12 ) |0xfff , + value &PR_WPE ?'W' :'.' , value &PR_RPE ?'R' :'.' ); }dev_dbg (ispi->dev,"Flash regions:\n" );
More whitespace changes.
Arnd
A message that is not in the archive (sent off-list or not yet received): CAFmMkTG3rMtmNxYf0jXgGN7zJgK2U8Ogtrd4yH0Ee1rC7pf9Mg@mail.gmail.com
Arnd Bergmann
maintainerQuoted 24 lines · Daniel Gutson
Quoted 16 lines · Arnd Bergmann
drivers/misc/firmware_security_data.c line 37
Quoted 13 lines · Daniel Gutson
drivers/misc/firmware_security_data.c new file +11
-0+static ssize_t internal_callback (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct firmware_security_data *fwsd = + container_of(attr, struct firmware_security_data, kobj_attr); +return fwsd->callback (buf, fwsd->private_data); +} + +int register_firmware_security_data_callback ( +const char *name,ssize_t (*callback)(char *buf,void *private_data), +void *private_data)Why do you have a callback interface here?
Because that was what I understood from you :) and it made sense for me. Callbacks depend on the DID, so it can't be static. The returned value is dynamic too. The callback idea here is like the
show()callback of the kobjects.Quoted 1 line
Quoted 7 lines
Quoted 3 lines
I would have expected
all the data to be static during the kernel run time, so just passing the information here would make it much simpler.What information are you referring to?
Please give me more details about your idea because using a callback is the only solution I can think about.
I still don't understand what the values are that you export. Can you try to describe better what you are actually exporting to user space, and how they change at runtime?
My impression was that the state of the registers you read would be the same if you read them multiple times, at least until you reboot and the firmware has a chance to change them.
Quoted 29 lines
Quoted 19 lines
Quoted 7 lines
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +1
-1@@ -76,7 +119,7 @@ static const struct pci_device_id intel_spi_pci_ids[] = { { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info }, { PCI_VDEVICE(INTEL, 0xa324), (unsigned long)&cnl_info }, { PCI_VDEVICE(INTEL, 0xa3a4), (unsigned long)&bxt_info }, - { }, + {}, };...
Quoted 11 lines
#include "
intel-spi.h"drivers/mtd/spi-nor/controllers/intel-spi.c +1
-1@@ -48,17 +49,17 @@#define FADDR 0x08#define DLOCK 0x0c -#define FDATA (n) (0x10 + ((n) * 4)) +#define FDATA (n) (0x10 + ((n)*4))#define FRACC 0x50Quoted 8 lines
drivers/mtd/spi-nor/controllers/intel-spi.c line 60
Quoted 6 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +1
-1-#define FREG (n) (0x54 + ((n) * 4)) +#define FREG (n) (0x54 + ((n)*4))#define FREG_BASE_MASK 0x3fff#define FREG_LIMIT_SHIFT 16#define FREG_LIMIT_MASK (0x03fff << FREG_LIMIT_SHIFT)Accidental whitespace change, please skip these changes?
Quoted 2 lines
This came from clang-format, I thought it was a requirement so I left this fixed. Should I revert the changes from clang-format?
Yes, you should ensure that newly added code does not introduce incorrect whitespace, but never mix cosmetic changes to existing code with newly added functionality.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +2
-1@@ -161,7 +164,8 @@ struct intel_spi {static bool writeable;module_param (writeable, bool,0 ); -MODULE_PARM_DESC (writeable,"Enable write access to SPI flash chip (default=0)" ); +MODULE_PARM_DESC (writeable, +"Enable write access to SPI flash chip (default=0)" );
Quoted 7 lines
Quoted 4 lines
drivers/mtd/spi-nor/controllers/intel-spi.c struct intel_spi { · line 171
Quoted 2 lines
drivers/mtd/spi-nor/controllers/intel-spi.c +0
-0static void intel_spi_dump_regs (struct intel_spi *ispi) {This looks like a useful change, but it should be a separate patch.
More clang-format.
Ah, I had misread the change, thinking that you added the description, but you really only change the whitespace, and in fact make it worse. ;-)
Arnd
A message that is not in the archive (sent off-list or not yet received): CAFmMkTF23JVfCe-ynBzbYQ_eF=z6fKCPdA6DbTrJ9OFYxGBWkQ@mail.gmail.com
Arnd Bergmann
maintainerQuoted 10 lines · Daniel Gutson
Quoted 4 lines · Arnd Bergmann
My impression was that the state of the registers you read would be the same if you read them multiple times, at least until you reboot and the firmware has a chance to change them.
That's not always the case, for example for the SMI count.
Another example is WPD, a driver (such as the intel-spi for instance) can change its value if it is unlocked. But many others don't change so it might be a good idea to add another function to the API to register constant values.
Ok, if the value can change, then I suppose you can pass a pointer to the 'struct class_attribute' or 'struct file_operations' with the appropriate 'show' callbacks, this should be easier than creating another callback abstraction.
For values that can not change, passing the value should be easier.
Arnd