FPGA Security Manager for 5.14
Subsystems (3)
Moritz Fischer
maintainercover FPGA Security Manager for 5.14
Hi Greg,
please consider these patches for inclusion into 5.14.
Russ' changes introduce a new framework that enables secure updates of FPGA devices boot configuration by interacting with the secure HW engine.
The use cases for the FPGA Security Manager which deals with the update of the permanent image for the FPGA device do not overlap enough with the FPGA Manage use case (runtime updates of the currently loaded image) to warrant a tighter coupling.
Its first user is m10bmc-sec driver supporting the Intel MAX 10 BMC device.
Thanks,
Moritz
Russ Weight (12):
fpga: sec-mgr: fpga security manager class driver
fpga: sec-mgr: enable secure updates
fpga: sec-mgr: expose sec-mgr update status
fpga: sec-mgr: expose sec-mgr update errors
fpga: sec-mgr: expose sec-mgr update size
fpga: sec-mgr: enable cancel of secure update
fpga: sec-mgr: expose hardware error info
fpga: m10bmc-sec: create max10 bmc secure update driver
fpga: m10bmc-sec: expose max10 flash update count
fpga: m10bmc-sec: expose max10 canceled keys in sysfs
fpga: m10bmc-sec: add max10 secure update functions
fpga: m10bmc-sec: add max10 get_hw_errinfo callback func
.../ABI/testing/sysfs-class-fpga-sec-mgr | 81 +++ .../testing/sysfs-driver-intel-m10-bmc-secure | 61 ++ Documentation/fpga/fpga-sec-mgr.rst | 44 ++ Documentation/fpga/index.rst | 1 + MAINTAINERS | 11 + drivers/fpga/Kconfig | 20 + drivers/fpga/Makefile | 6 + drivers/fpga/fpga-sec-mgr.c | 648 ++++++++++++++++++ drivers/fpga/intel-m10-bmc-secure.c | 550 +++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 99 +++ 10 files changed, 1521 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga-sec-mgr create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-secure create mode 100644 Documentation/fpga/fpga-sec-mgr.rst create mode 100644 drivers/fpga/fpga-sec-mgr.c create mode 100644 drivers/fpga/intel-m10-bmc-secure.c create mode 100644 include/linux/fpga/fpga-sec-mgr.h
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 1/12 fpga: sec-mgr: fpga security manager class driver
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 5 + Documentation/fpga/fpga-sec-mgr.rst | 44 +++ Documentation/fpga/index.rst | 1 + MAINTAINERS | 9 + drivers/fpga/Kconfig | 9 + drivers/fpga/Makefile | 3 + drivers/fpga/fpga-sec-mgr.c | 296 ++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 44 +++ 8 files changed, 411 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga-sec-mgr create mode 100644 Documentation/fpga/fpga-sec-mgr.rst create mode 100644 drivers/fpga/fpga-sec-mgr.c create mode 100644 include/linux/fpga/fpga-sec-mgr.h
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr new file +5 -0
@@ -0,0 +1,5 @@ +What: /sys/class/fpga_sec_mgr/fpga_secX/name +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Name of low level fpga security manager driver.
Documentation/fpga/fpga-sec-mgr.rst new file +44 -0
44 lines not on this page · raw message
Documentation/fpga/index.rst +1 -0
@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + fpga-sec-mgr .. only:: subproject and html
MAINTAINERS +9 -0
@@ -7136,6 +7136,15 @@ F: Documentation/fpga/ F: drivers/fpga/ F: include/linux/fpga/ +FPGA SECURITY MANAGER DRIVERS +M: Russ Weight <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +F: Documentation/fpga/fpga-sec-mgr.rst +F: drivers/fpga/fpga-sec-mgr.c +F: include/linux/fpga/fpga-sec-mgr.h + FPU EMULATOR M: Bill Metzenthen <[email protected]> S: Maintained
drivers/fpga/Kconfig +9 -0
@@ -234,4 +234,13 @@ config FPGA_MGR_ZYNQMP_FPGA to configure the programmable logic(PL) through PS on ZynqMP SoC. +config FPGA_SEC_MGR + tristate "FPGA Security Manager" + help + The Security Manager class driver presents a common + user API for managing secure updates for FPGA + devices, including flash images for the FPGA static + region and for the BMC. Select this option to enable + updates for secure FPGA devices. + endif # FPGA
drivers/fpga/Makefile +3 -0
@@ -21,6 +21,9 @@ obj-$(CONFIG_FPGA_MGR_ZYNQMP_FPGA) += zynqmp-fpga.o obj-$(CONFIG_ALTERA_PR_IP_CORE) += altera-pr-ip-core.o obj-$(CONFIG_ALTERA_PR_IP_CORE_PLAT) += altera-pr-ip-core-plat.o +# FPGA Security Manager Framework +obj-$(CONFIG_FPGA_SEC_MGR) += fpga-sec-mgr.o + # FPGA Bridge Drivers obj-$(CONFIG_FPGA_BRIDGE) += fpga-bridge.o obj-$(CONFIG_SOCFPGA_FPGA_BRIDGE) += altera-hps2fpga.o altera-fpga2sdram.o
drivers/fpga/fpga-sec-mgr.c new file +296 -0
296 lines not on this page · raw message
include/linux/fpga/fpga-sec-mgr.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>
Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
drivers/fpga/fpga-sec-mgr.c line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.cdrivers/fpga/fpga-sec-mgr.c new file +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc.
What year is it? :(
Quoted 15 lines
drivers/fpga/fpga-sec-mgr.c new file +15
-0+*/ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA (fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { +struct fpga_sec_mgr *smgr; +}; +
drivers/fpga/fpga-sec-mgr.c line 30
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+#define to_sec_mgr (d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name);
What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 4 lines
drivers/fpga/fpga-sec-mgr.c new file +4
-0+ +static struct attribute *sec_mgr_attrs[] = { + &dev_attr_name.attr, +NULL ,
drivers/fpga/fpga-sec-mgr.c line 44
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+}; + +static struct attribute_group sec_mgr_attr_group = { + .attrs = sec_mgr_attrs, +}; + +static const struct attribute_group *fpga_sec_mgr_attr_groups[] = { + &sec_mgr_attr_group, +NULL , +};
ATTRIBUTE_GROUPS()?
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c new file +8
-0+ +/** +* fpga_sec_mgr_create - create and initialize an FPGA +* security manager struct +* +* @dev: fpga security manager device from pdev +* @name: fpga security manager name +* @sops: pointer to a structure of fpga callback functions
drivers/fpga/fpga-sec-mgr.c line 62
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+* @priv: fpga security manager private data +* +* The caller of this function is responsible for freeing the struct +* with ifpg_sec_mgr_free(). Using devm_fpga_sec_mgr_create() instead +* is recommended. +* +* Return: pointer to struct fpga_sec_mgr or NULL +*/ +struct fpga_sec_mgr * +fpga_sec_mgr_create(struct device *dev, const char *name,
Where is the "device" coming from here? If it's a parent, call it "parent".
Quoted 5 lines
drivers/fpga/fpga-sec-mgr.c new file +5
-0+ const struct fpga_sec_mgr_ops *sops, void *priv) +{ + struct fpga_sec_mgr *smgr; +int id, ret; +
drivers/fpga/fpga-sec-mgr.c line 77
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+if (!name || !strlen (name)) { +dev_err (dev,"Attempt to register with no name!\n" ); +return NULL ; + } + + smgr =kzalloc (sizeof (*smgr),GFP_KERNEL ); +if (!smgr) +return NULL ; + + id =ida_simple_get (&fpga_sec_mgr_ida,0 ,0 ,GFP_KERNEL );
I think we have to only use xarray() calls now, no more new IDA/IDR calls please.
Quoted 5 lines
drivers/fpga/fpga-sec-mgr.c new file +5
-0+if (id <0 ) + goto error_kfree; + +mutex_init (&smgr->lock); +
drivers/fpga/fpga-sec-mgr.c line 92
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+ smgr->name = name; + smgr->priv = priv; + smgr->sops = sops; + +device_initialize (&smgr->dev); + smgr->dev.class = fpga_sec_mgr_class; + smgr->dev.parent = dev; + smgr->dev.id = id; + + ret =dev_set_name (&smgr->dev,"fpga_sec%d" , id);
There's your name :)
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+if (ret) { +dev_err (dev,"Failed to set device name: fpga_sec%d\n" , id); + goto error_device; + } + +return smgr;
drivers/fpga/fpga-sec-mgr.c line 108
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+ +error_device: +ida_simple_remove (&fpga_sec_mgr_ida, id); + +error_kfree: +kfree (smgr); + +return NULL ; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_create);
Why did you not register the device here.
drivers/fpga/fpga-sec-mgr.c line 121
Quoted 13 lines
drivers/fpga/fpga-sec-mgr.c new file +13
-0+ +/** +* fpga_sec_mgr_free - free an FPGA security manager created +* with fpga_sec_mgr_create() +* +* @smgr: FPGA security manager structure +*/ +void fpga_sec_mgr_free (struct fpga_sec_mgr *smgr) +{ +ida_simple_remove (&fpga_sec_mgr_ida, smgr->dev.id); +kfree (smgr); +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_free);
Oh look, memory leaks! :(
More below...
Quoted 54 lines
drivers/fpga/fpga-sec-mgr.c new file +54
-0+ +static void devm_fpga_sec_mgr_release (struct device *dev,void *res) +{ +struct fpga_sec_mgr_devres *dr = res; + +fpga_sec_mgr_free (dr->smgr); +} + +/** +* devm_fpga_sec_mgr_create - create and initialize an FPGA +* security manager struct +* +* @dev: fpga security manager device from pdev +* @name: fpga security manager name +* @sops: pointer to a structure of fpga callback functions +* @priv: fpga security manager private data +* +* This function is intended for use in a FPGA Security manager +* driver's probe function. After the security manager driver creates +* the fpga_sec_mgr struct with devm_fpga_sec_mgr_create(), it should +* register it with devm_fpga_sec_mgr_register(). +* The fpga_sec_mgr struct allocated with this function will be freed +* automatically on driver detach. +* +* Return: pointer to struct fpga_sec_mgr or NULL +*/ +struct fpga_sec_mgr * +devm_fpga_sec_mgr_create (struct device *dev,const char *name, +const struct fpga_sec_mgr_ops *sops,void *priv) +{ +struct fpga_sec_mgr_devres *dr; + + dr =devres_alloc (devm_fpga_sec_mgr_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return NULL ; + + dr->smgr =fpga_sec_mgr_create (dev, name, sops, priv); +if (!dr->smgr) { +devres_free (dr); +return NULL ; + } + +devres_add (dev, dr); + +return dr->smgr; +} +EXPORT_SYMBOL_GPL (devm_fpga_sec_mgr_create); + +/** +* fpga_sec_mgr_register - register an FPGA security manager +* +* @smgr: fpga security manager struct +* +* Return: 0 on success, negative error code otherwise.
drivers/fpga/fpga-sec-mgr.c line 185
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+*/ +int fpga_sec_mgr_register (struct fpga_sec_mgr *smgr) +{ +int ret; + + ret =device_add (&smgr->dev); +if (ret) + goto error_device; + +dev_info (&smgr->dev,"%s registered\n" , smgr->name);
Drivers, if working properly, are quiet. Please remove all dev_info() mess from here (and the series).
Quoted 11 lines
drivers/fpga/fpga-sec-mgr.c new file +11
-0+ +return 0 ; + +error_device: +ida_simple_remove (&fpga_sec_mgr_ida, smgr->dev.id); + +return ret; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_register); + +/**
drivers/fpga/fpga-sec-mgr.c line 206
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+* fpga_sec_mgr_unregister - unregister an FPGA security manager +* +* @mgr: fpga manager struct +* +* This function is intended for use in an FPGA security manager +* driver's remove() function. +*/ +void fpga_sec_mgr_unregister (struct fpga_sec_mgr *smgr) +{ +dev_info (&smgr->dev,"%s %s\n" , __func__, smgr->name);
Like this, not needed.
Quoted 54 lines
drivers/fpga/fpga-sec-mgr.c new file +54
-0+ +device_unregister (&smgr->dev); +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_unregister); + +static int fpga_sec_mgr_devres_match (struct device *dev,void *res, +void *match_data) +{ +struct fpga_sec_mgr_devres *dr = res; + +return match_data == dr->smgr; +} + +static void devm_fpga_sec_mgr_unregister (struct device *dev,void *res) +{ +struct fpga_sec_mgr_devres *dr = res; + +fpga_sec_mgr_unregister (dr->smgr); +} + +/** +* devm_fpga_sec_mgr_register - resource managed variant of +* fpga_sec_mgr_register() +* +* @dev: managing device for this FPGA security manager +* @smgr: fpga security manager struct +* +* This is the devres variant of fpga_sec_mgr_register() for which the +* unregister function will be called automatically when the managing +* device is detached. +*/ +int devm_fpga_sec_mgr_register (struct device *dev,struct fpga_sec_mgr *smgr) +{ +struct fpga_sec_mgr_devres *dr; +int ret; + +/* +* Make sure that the struct fpga_sec_mgr * that is passed in is +* managed itself. +*/ +if (WARN_ON (!devres_find (dev, devm_fpga_sec_mgr_release, + fpga_sec_mgr_devres_match, smgr))) +return -EINVAL ; + + dr =devres_alloc (devm_fpga_sec_mgr_unregister,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =fpga_sec_mgr_register (smgr); +if (ret) { +devres_free (dr); +return ret; + } +
drivers/fpga/fpga-sec-mgr.c line 270
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+ dr->smgr = smgr; +devres_add (dev, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_fpga_sec_mgr_register); + +static void fpga_sec_mgr_dev_release (struct device *dev) +{ +}
There used to be some lovely documentation in the kernel that said I was allowed to yell at anyone who did something like this. But that's removed, so I'll just be quiet and ask you to think about why you would ever want to provide an empty function, just to make the kernel core "be quiet". Did you perhaps think you were smarter than the kobject core and this was the proper solution to make it "shut up" with it's crazy warning that some over-eager developer added? Or perhaps, that warning was there on purpose, lovingly hand-added to help provide a HUGE HINT that not providing a REAL release function was wrong.
You are now required to go and fix this whole series, and get someone from Intel with some real knowledge of the driver model to sign off on it, before you are allowed to post the series in public again.
greg k-h
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.cdrivers/fpga/fpga-sec-mgr.c new file +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 20 lines
Quoted 20 lines
drivers/fpga/fpga-sec-mgr.c new file +19
-0+*/ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA (fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { +struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr (d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show (struct device *dev, +struct device_attribute *attr,char *buf)
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 30
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Quoted 17 lines
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +4
-0+ +static struct attribute *sec_mgr_attrs[] = { + &dev_attr_name.attr, +NULL ,drivers/fpga/fpga-sec-mgr.c line 44
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+}; + +static struct attribute_group sec_mgr_attr_group = { + .attrs = sec_mgr_attrs, +}; + +static const struct attribute_group *fpga_sec_mgr_attr_groups[] = { + &sec_mgr_attr_group, +NULL , +};
ATTRIBUTE_GROUPS()?
Yes - I'll fix this.
Quoted 13 lines
Quoted 13 lines
drivers/fpga/fpga-sec-mgr.c new file +12
-0+ +/** +* fpga_sec_mgr_create - create and initialize an FPGA +* security manager struct +* +* @dev: fpga security manager device from pdev +* @name: fpga security manager name +* @sops: pointer to a structure of fpga callback functions +* @priv: fpga security manager private data +* +* The caller of this function is responsible for freeing the struct +* with ifpg_sec_mgr_free(). Using devm_fpga_sec_mgr_create() instead
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 62
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+* is recommended. +* +* Return: pointer to struct fpga_sec_mgr or NULL +*/ +struct fpga_sec_mgr * +fpga_sec_mgr_create(struct device *dev, const char *name,Where is the "device" coming from here? If it's a parent, call it "parent".
I'll change it to "parent".
Quoted 10 lines
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +9
-0+ const struct fpga_sec_mgr_ops *sops, void *priv) +{ + struct fpga_sec_mgr *smgr; +int id, ret; + +if (!name || !strlen (name)) { +dev_err (dev,"Attempt to register with no name!\n" ); +return NULL ; + }
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 77
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+ + smgr =kzalloc (sizeof (*smgr),GFP_KERNEL ); +if (!smgr) +return NULL ; + + id =ida_simple_get (&fpga_sec_mgr_ida,0 ,0 ,GFP_KERNEL );I think we have to only use
xarray()calls now, no more new IDA/IDR calls please.
Thanks - I'll look into changing this to use xarray().
Quoted 27 lines
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +5
-0+if (id <0 ) + goto error_kfree; + +mutex_init (&smgr->lock); +drivers/fpga/fpga-sec-mgr.c line 92
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+ smgr->name = name; + smgr->priv = priv; + smgr->sops = sops; + +device_initialize (&smgr->dev); + smgr->dev.class = fpga_sec_mgr_class; + smgr->dev.parent = dev; + smgr->dev.id = id; + + ret =dev_set_name (&smgr->dev,"fpga_sec%d" , id);There's your name :)
Quoted 9 lines
drivers/fpga/fpga-sec-mgr.c new file +9
-0+if (ret) { +dev_err (dev,"Failed to set device name: fpga_sec%d\n" , id); + goto error_device; + } + +return smgr; + +error_device: +ida_simple_remove (&fpga_sec_mgr_ida, id);
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 108
Quoted 7 lines
drivers/fpga/fpga-sec-mgr.c new file +7
-0+ +error_kfree: +kfree (smgr); + +return NULL ; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_create);Why did you not register the device here.
My original implementation created and registered the device in a single function:
https://marc.info/?l=linux-fpga&m=159926365226264&w=2
It was split up to conform to the conventions used by other class drivers in the FPGA
framework: fpga-mgr.c, fpga-bridge.c, fpga-region.c
Quoted 77 lines
Quoted 4 lines
drivers/fpga/fpga-sec-mgr.c new file +3
-0+ +/** +* fpga_sec_mgr_free - free an FPGA security manager created drivers/fpga/fpga-sec-mgr.c line 121
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+* with fpga_sec_mgr_create() +* +* @smgr: FPGA security manager structure +*/ +void fpga_sec_mgr_free (struct fpga_sec_mgr *smgr) +{ +ida_simple_remove (&fpga_sec_mgr_ida, smgr->dev.id); +kfree (smgr); +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_free);Oh look, memory leaks! :(
More below...
Quoted 58 lines
drivers/fpga/fpga-sec-mgr.c new file +58
-0+ +static void devm_fpga_sec_mgr_release (struct device *dev,void *res) +{ +struct fpga_sec_mgr_devres *dr = res; + +fpga_sec_mgr_free (dr->smgr); +} + +/** +* devm_fpga_sec_mgr_create - create and initialize an FPGA +* security manager struct +* +* @dev: fpga security manager device from pdev +* @name: fpga security manager name +* @sops: pointer to a structure of fpga callback functions +* @priv: fpga security manager private data +* +* This function is intended for use in a FPGA Security manager +* driver's probe function. After the security manager driver creates +* the fpga_sec_mgr struct with devm_fpga_sec_mgr_create(), it should +* register it with devm_fpga_sec_mgr_register(). +* The fpga_sec_mgr struct allocated with this function will be freed +* automatically on driver detach. +* +* Return: pointer to struct fpga_sec_mgr or NULL +*/ +struct fpga_sec_mgr * +devm_fpga_sec_mgr_create (struct device *dev,const char *name, +const struct fpga_sec_mgr_ops *sops,void *priv) +{ +struct fpga_sec_mgr_devres *dr; + + dr =devres_alloc (devm_fpga_sec_mgr_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return NULL ; + + dr->smgr =fpga_sec_mgr_create (dev, name, sops, priv); +if (!dr->smgr) { +devres_free (dr); +return NULL ; + } + +devres_add (dev, dr); + +return dr->smgr; +} +EXPORT_SYMBOL_GPL (devm_fpga_sec_mgr_create); + +/** +* fpga_sec_mgr_register - register an FPGA security manager +* +* @smgr: fpga security manager struct +* +* Return: 0 on success, negative error code otherwise. +*/ +int fpga_sec_mgr_register (struct fpga_sec_mgr *smgr) +{ +int ret;
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 185
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+ + ret =device_add (&smgr->dev); +if (ret) + goto error_device; + +dev_info (&smgr->dev,"%s registered\n" , smgr->name);Drivers, if working properly, are quiet. Please remove all
dev_info()mess from here (and the series).
OK - I'll remove the dev_info calls.
Quoted 89 lines
Quoted 12 lines
drivers/fpga/fpga-sec-mgr.c new file +11
-0+ +return 0 ; + +error_device: +ida_simple_remove (&fpga_sec_mgr_ida, smgr->dev.id); + +return ret; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_register); + +/** drivers/fpga/fpga-sec-mgr.c line 206
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+* fpga_sec_mgr_unregister - unregister an FPGA security manager +* +* @mgr: fpga manager struct +* +* This function is intended for use in an FPGA security manager +* driver's remove() function. +*/ +void fpga_sec_mgr_unregister (struct fpga_sec_mgr *smgr) +{ +dev_info (&smgr->dev,"%s %s\n" , __func__, smgr->name);Like this, not needed.
Quoted 54 lines
drivers/fpga/fpga-sec-mgr.c new file +54
-0+ +device_unregister (&smgr->dev); +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_unregister); + +static int fpga_sec_mgr_devres_match (struct device *dev,void *res, +void *match_data) +{ +struct fpga_sec_mgr_devres *dr = res; + +return match_data == dr->smgr; +} + +static void devm_fpga_sec_mgr_unregister (struct device *dev,void *res) +{ +struct fpga_sec_mgr_devres *dr = res; + +fpga_sec_mgr_unregister (dr->smgr); +} + +/** +* devm_fpga_sec_mgr_register - resource managed variant of +* fpga_sec_mgr_register() +* +* @dev: managing device for this FPGA security manager +* @smgr: fpga security manager struct +* +* This is the devres variant of fpga_sec_mgr_register() for which the +* unregister function will be called automatically when the managing +* device is detached. +*/ +int devm_fpga_sec_mgr_register (struct device *dev,struct fpga_sec_mgr *smgr) +{ +struct fpga_sec_mgr_devres *dr; +int ret; + +/* +* Make sure that the struct fpga_sec_mgr * that is passed in is +* managed itself. +*/ +if (WARN_ON (!devres_find (dev, devm_fpga_sec_mgr_release, + fpga_sec_mgr_devres_match, smgr))) +return -EINVAL ; + + dr =devres_alloc (devm_fpga_sec_mgr_unregister,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =fpga_sec_mgr_register (smgr); +if (ret) { +devres_free (dr); +return ret; + } +drivers/fpga/fpga-sec-mgr.c line 270
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c new file +10
-0+ dr->smgr = smgr; +devres_add (dev, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_fpga_sec_mgr_register); + +static void fpga_sec_mgr_dev_release (struct device *dev) +{ +}There used to be some lovely documentation in the kernel that said I was
Quoted 8 lines
allowed to yell at anyone who did something like this. But that's removed, so I'll just be quiet and ask you to think about why you would ever want to provide an empty function, just to make the kernel core "be quiet". Did you perhaps think you were smarter than the kobject core and this was the proper solution to make it "shut up" with it's crazy warning that some over-eager developer added? Or perhaps, that warning was there on purpose, lovingly hand-added to help provide a HUGE HINT that not providing a REAL release function was wrong.
In my original submission, this function was populated.
https://marc.info/?l=linux-fpga&m=159926365226264&w=2
Again, I was conforming to conventions used in the other class drivers in the FPGA framework, all of which have an empty *_dev_release() function:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n782
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-bridge.c#n476
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-region.c#n317
- Russ
Quoted 6 lines
You are now required to go and fix this whole series, and get someone from Intel with some real knowledge of the driver model to sign off on it, before you are allowed to post the series in public again.
greg k-h
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 58 lines · Russ Weight
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.cdrivers/fpga/fpga-sec-mgr.c new file +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 20 lines
Quoted 20 lines
drivers/fpga/fpga-sec-mgr.c new file +19
-0+*/ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA (fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { +struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr (d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show (struct device *dev, +struct device_attribute *attr,char *buf)Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 30
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 2 lines
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
How is "name" a "parent"? To find the parent, just walk up the sysfs tree.
Quoted 4 lines
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Maybe that needs to be fixed as well :)
But, why re-implement the same thing and not just use the existing class framework and code?
Quoted 8 lines
Quoted 2 lines
drivers/fpga/fpga-sec-mgr.c line 108
Quoted 1 line
drivers/fpga/fpga-sec-mgr.c new file +1
-0+EXPORT_SYMBOL_GPL (fpga_sec_mgr_create);Why did you not register the device here.
My original implementation created and registered the device in a single function:
https://marc.info/?l=linux-fpga&m=159926365226264&w=2
It was split up to conform to the conventions used by other class drivers in the FPGA
framework:fpga-mgr.c,fpga-bridge.c,fpga-region.c
If you don't need things to be split, don't split it. Or better yet, use the existing code.
Quoted 14 lines
Quoted 9 lines
There used to be some lovely documentation in the kernel that said I was allowed to yell at anyone who did something like this. But that's removed, so I'll just be quiet and ask you to think about why you would ever want to provide an empty function, just to make the kernel core "be quiet". Did you perhaps think you were smarter than the kobject core and this was the proper solution to make it "shut up" with it's crazy warning that some over-eager developer added? Or perhaps, that warning was there on purpose, lovingly hand-added to help provide a HUGE HINT that not providing a REAL release function was wrong.
In my original submission, this function was populated.
Quoted 7 lines
Again, I was conforming to conventions used in the other class drivers in the FPGA framework, all of which have an empty
*_dev_release()function:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n782
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-bridge.c#n476
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-region.c#n317
Oh wow, that's totally wrong and broken, thanks for pointing it out. Please fix that up first.
thanks,
greg k-h
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 63 lines · Greg KH
Quoted 57 lines · Russ Weight
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.cdrivers/fpga/fpga-sec-mgr.c new file +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 19 lines
Quoted 19 lines
drivers/fpga/fpga-sec-mgr.c new file +19
-0+*/ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA (fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { +struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr (d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show (struct device *dev, +struct device_attribute *attr,char *buf)Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 30
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 2 lines
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
How is "name" a "parent"? To find the parent, just walk up the sysfs tree.
Quoted 8 lines
Quoted 4 lines
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Maybe that needs to be fixed as well :)
But, why re-implement the same thing and not just use the existing class framework and code?
I did the exercise of trying to merge the new functionality into the fpga-mgr.c code, but there was so little commonality that it was beginning to look like a dual-personality driver. The only thing that could be shared was the registration/unregistration of the driver. It seemed cleaner to have it as a separate class driver.
- Russ
Quoted 39 lines
Quoted 10 lines
Quoted 4 lines
drivers/fpga/fpga-sec-mgr.c line 108
Quoted 3 lines
drivers/fpga/fpga-sec-mgr.c new file +1
-0+EXPORT_SYMBOL_GPL (fpga_sec_mgr_create);Why did you not register the device here.
My original implementation created and registered the device in a single function:
https://marc.info/?l=linux-fpga&m=159926365226264&w=2
It was split up to conform to the conventions used by other class drivers in the FPGA
framework:fpga-mgr.c,fpga-bridge.c,fpga-region.cIf you don't need things to be split, don't split it. Or better yet, use the existing code.
Quoted 13 lines
Quoted 9 lines
There used to be some lovely documentation in the kernel that said I was allowed to yell at anyone who did something like this. But that's removed, so I'll just be quiet and ask you to think about why you would ever want to provide an empty function, just to make the kernel core "be quiet". Did you perhaps think you were smarter than the kobject core and this was the proper solution to make it "shut up" with it's crazy warning that some over-eager developer added? Or perhaps, that warning was there on purpose, lovingly hand-added to help provide a HUGE HINT that not providing a REAL release function was wrong.
In my original submission, this function was populated.
Quoted 7 lines
Again, I was conforming to conventions used in the other class drivers in the FPGA framework, all of which have an empty
*_dev_release()function:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n782
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-bridge.c#n476
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-region.c#n317Oh wow, that's totally wrong and broken, thanks for pointing it out. Please fix that up first.
thanks,
greg k-h
Tom Rix
reviewerRe: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 73 lines · Russ Weight
Quoted 63 lines · Greg KH
Quoted 57 lines · Russ Weight
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.cdrivers/fpga/fpga-sec-mgr.c new file +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 19 lines
Quoted 19 lines
drivers/fpga/fpga-sec-mgr.c new file +19
-0+*/ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA (fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { +struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr (d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show (struct device *dev, +struct device_attribute *attr,char *buf)Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 30
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 2 lines
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
How is "name" a "parent"? To find the parent, just walk up the sysfs tree.
Quoted 8 lines
Quoted 4 lines
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Maybe that needs to be fixed as well :)
But, why re-implement the same thing and not just use the existing class framework and code?
Quoted 7 lines
I did the exercise of trying to merge the new functionality into the
fpga-mgr.ccode, but there was so little commonality that it was beginning to look like a dual-personality driver. The only thing that could be shared was the registration/unregistration of the driver. It seemed cleaner to have it as a separate class driver.- Russ
I'll post a patch in a bit that does nothing new but refactor fpga-mgr's ops into 'partial update' and 'full update'
existing stuff in partial
security update stuff in full
Tom
Quoted 39 lines
Quoted 39 lines
Quoted 10 lines
Quoted 4 lines
drivers/fpga/fpga-sec-mgr.c line 108
Quoted 3 lines
drivers/fpga/fpga-sec-mgr.c new file +1
-0+EXPORT_SYMBOL_GPL (fpga_sec_mgr_create);Why did you not register the device here.
My original implementation created and registered the device in a single function:
https://marc.info/?l=linux-fpga&m=159926365226264&w=2
It was split up to conform to the conventions used by other class drivers in the FPGA
framework:fpga-mgr.c,fpga-bridge.c,fpga-region.cIf you don't need things to be split, don't split it. Or better yet, use the existing code.
Quoted 13 lines
Quoted 9 lines
There used to be some lovely documentation in the kernel that said I was allowed to yell at anyone who did something like this. But that's removed, so I'll just be quiet and ask you to think about why you would ever want to provide an empty function, just to make the kernel core "be quiet". Did you perhaps think you were smarter than the kobject core and this was the proper solution to make it "shut up" with it's crazy warning that some over-eager developer added? Or perhaps, that warning was there on purpose, lovingly hand-added to help provide a HUGE HINT that not providing a REAL release function was wrong.
In my original submission, this function was populated.
Quoted 7 lines
Again, I was conforming to conventions used in the other class drivers in the FPGA framework, all of which have an empty
*_dev_release()function:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n782
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-bridge.c#n476
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-region.c#n317Oh wow, that's totally wrong and broken, thanks for pointing it out. Please fix that up first.
thanks,
greg k-h
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 83 lines · Tom Rix
Quoted 73 lines · Russ Weight
Quoted 63 lines · Greg KH
Quoted 57 lines · Russ Weight
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.cdrivers/fpga/fpga-sec-mgr.c new file +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 19 lines
Quoted 19 lines
drivers/fpga/fpga-sec-mgr.c new file +19
-0+*/ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA (fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { + struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr (d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show (struct device *dev, + struct device_attribute *attr, char *buf)Quoted 8 lines
drivers/fpga/fpga-sec-mgr.c line 30
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c new file +6
-0+{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + + return sysfs_emit(buf, "%s\n", smgr->name); +} +static DEVICE_ATTR_RO (name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 2 lines
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
How is "name" a "parent"? To find the parent, just walk up the sysfs tree.
Quoted 8 lines
Quoted 4 lines
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Maybe that needs to be fixed as well :)
But, why re-implement the same thing and not just use the existing class framework and code?
Quoted 7 lines
I did the exercise of trying to merge the new functionality into the
fpga-mgr.ccode, but there was so little commonality that it was beginning to look like a dual-personality driver. The only thing that could be shared was the registration/unregistration of the driver. It seemed cleaner to have it as a separate class driver.- Russ
Quoted 7 lines
I'll post a patch in a bit that does nothing new but refactor fpga-mgr's ops into 'partial update' and 'full update'
existing stuff in partial
security update stuff in full
Tom
FYI: I just posted patches that remove the managed resource functions and populate the class dev_release functions for fpga_mgr.c, fpga_region.c, and fpga_bridge.c.
https://marc.info/?l=linux-fpga&m=162155904229400&w=2
https://marc.info/?l=linux-fpga&m=162155904329404&w=2
https://marc.info/?l=linux-fpga&m=162155904529409&w=2
https://marc.info/?l=linux-fpga&m=162155904529412&w=2
- Russ
Quoted 41 lines
Quoted 40 lines
Quoted 40 lines
Quoted 11 lines
Quoted 5 lines
drivers/fpga/fpga-sec-mgr.c line 108
Quoted 4 lines
drivers/fpga/fpga-sec-mgr.c new file +1
-0+EXPORT_SYMBOL_GPL (fpga_sec_mgr_create);Why did you not register the device here.
My original implementation created and registered the device in a single function:
https://marc.info/?l=linux-fpga&m=159926365226264&w=2
It was split up to conform to the conventions used by other class drivers in the FPGA
framework:fpga-mgr.c,fpga-bridge.c,fpga-region.cIf you don't need things to be split, don't split it. Or better yet, use the existing code.
Quoted 13 lines
Quoted 9 lines
There used to be some lovely documentation in the kernel that said I was allowed to yell at anyone who did something like this. But that's removed, so I'll just be quiet and ask you to think about why you would ever want to provide an empty function, just to make the kernel core "be quiet". Did you perhaps think you were smarter than the kobject core and this was the proper solution to make it "shut up" with it's crazy warning that some over-eager developer added? Or perhaps, that warning was there on purpose, lovingly hand-added to help provide a HUGE HINT that not providing a REAL release function was wrong.
In my original submission, this function was populated.
Quoted 7 lines
Again, I was conforming to conventions used in the other class drivers in the FPGA framework, all of which have an empty
*_dev_release()function:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n782
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-bridge.c#n476
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-region.c#n317Oh wow, that's totally wrong and broken, thanks for pointing it out. Please fix that up first.
thanks,
greg k-h
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 93 lines · Russ Weight
Quoted 83 lines · Tom Rix
Quoted 73 lines · Russ Weight
Quoted 63 lines · Greg KH
Quoted 57 lines · Russ Weight
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
Review line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.c(quoted diff) +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * FPGA Security Manager + * + * Copyright (C) 2019-2020 Intel Corporation, Inc.What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 19 lines
Quoted 19 lines
(quoted diff) +19
-0+ */ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA(fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { + struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr(d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show(struct device *dev, + struct device_attribute *attr, char *buf)Quoted 8 lines
Review line 30
Quoted 6 lines
(quoted diff) +6
-0+{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + + return sysfs_emit(buf, "%s\n", smgr->name); +} +static DEVICE_ATTR_RO(name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 2 lines
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
How is "name" a "parent"? To find the parent, just walk up the sysfs tree.
Quoted 8 lines
Quoted 4 lines
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Maybe that needs to be fixed as well :)
But, why re-implement the same thing and not just use the existing class framework and code?
Quoted 7 lines
I did the exercise of trying to merge the new functionality into the
fpga-mgr.ccode, but there was so little commonality that it was beginning to look like a dual-personality driver. The only thing that could be shared was the registration/unregistration of the driver. It seemed cleaner to have it as a separate class driver.- Russ
Quoted 7 lines
I'll post a patch in a bit that does nothing new but refactor fpga-mgr's ops into 'partial update' and 'full update'
existing stuff in partial
security update stuff in full
Tom
Quoted 8 lines
FYI: I just posted patches that remove the managed resource functions and populate the class
dev_releasefunctions forfpga_mgr.c,fpga_region.c, andfpga_bridge.c.https://marc.info/?l=linux-fpga&m=162155904229400&w=2
https://marc.info/?l=linux-fpga&m=162155904329404&w=2
https://marc.info/?l=linux-fpga&m=162155904529409&w=2
https://marc.info/?l=linux-fpga&m=162155904529412&w=2
You forgot to cc: me :(
I guess you didn't want me to point out the fact that you forgot to go through the proper internal Intel patch review process first, before asking others to review your changes?
{sigh}
greg k-h
Re: [PATCH 01/12] fpga: sec-mgr: fpga security manager class driver
Quoted 97 lines · Greg KH
Quoted 88 lines · Russ Weight
Quoted 79 lines · Tom Rix
Quoted 78 lines · Russ Weight
Quoted 63 lines · Greg KH
Quoted 57 lines · Russ Weight
Hi Greg,
Quoted 18 lines · Greg KH
Quoted 10 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create the FPGA Security Manager class driver. The security manager provides interfaces to manage secure updates for the FPGA and BMC images that are stored in FLASH. The driver can also be used to update root entry hashes and to cancel code signing keys. The image type is encoded in the image file and is decoded by the HW/FW secure update engine.
Signed-off-by Russ Weight <[email protected]>Russ, you know the Intel rules here, why did you not get someone who has knowledge of the kernel's driver model to review your patches before sending them out?
Basic driver model review comments below, I'm stopping after reviewing this one as there's some big failures here...
Quoted 8 lines
Review line 5
Quoted 7 lines
+++
b/drivers/fpga/fpga-sec-mgr.c(quoted diff) +5
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * FPGA Security Manager + * + * Copyright (C) 2019-2020 Intel Corporation, Inc.What year is it? :(
Thanks - I'll fix the copyright dates.
Quoted 19 lines
Quoted 19 lines
(quoted diff) +19
-0+ */ + +#include <linux/fpga/fpga-sec-mgr.h> +#include <linux/idr.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> + +static DEFINE_IDA(fpga_sec_mgr_ida); +static struct class *fpga_sec_mgr_class; + +struct fpga_sec_mgr_devres { + struct fpga_sec_mgr *smgr; +}; + +#define to_sec_mgr(d) container_of(d, struct fpga_sec_mgr, dev) + +static ssize_t name_show(struct device *dev, + struct device_attribute *attr, char *buf)Quoted 8 lines
Review line 30
Quoted 6 lines
(quoted diff) +6
-0+{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + + return sysfs_emit(buf, "%s\n", smgr->name); +} +static DEVICE_ATTR_RO(name);What is wrong with the name of the device? Please just use that and do not have a "second name" of the thing.
Quoted 2 lines
The purpose was to display the name of the parent driver. Should I change "name" to "parent"? Or drop this altogether?
How is "name" a "parent"? To find the parent, just walk up the sysfs tree.
Quoted 8 lines
Quoted 4 lines
Please note that in this and other cases, I have been conforming to conventions already used in FPGA Manager class driver:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/fpga/fpga-mgr.c#n397
Maybe that needs to be fixed as well :)
But, why re-implement the same thing and not just use the existing class framework and code?
I did the exercise of trying to merge the new functionality into the
fpga-mgr.ccode, but there was so little commonality that it was beginning to look like a dual-personality driver. The only thing that could be shared was the registration/unregistration of the driver. It seemed cleaner to have it as a separate class driver.Quoted 8 lines
Quoted 1 line
- Russ
I'll post a patch in a bit that does nothing new but refactor fpga-mgr's ops into 'partial update' and 'full update'
existing stuff in partial
security update stuff in full
Tom
Quoted 8 lines
FYI: I just posted patches that remove the managed resource functions and populate the class
dev_releasefunctions forfpga_mgr.c,fpga_region.c, andfpga_bridge.c.https://marc.info/?l=linux-fpga&m=162155904229400&w=2
https://marc.info/?l=linux-fpga&m=162155904329404&w=2
https://marc.info/?l=linux-fpga&m=162155904529409&w=2
https://marc.info/?l=linux-fpga&m=162155904529412&w=2
Quoted 5 lines
You forgot to cc: me :(
I guess you didn't want me to point out the fact that you forgot to go through the proper internal Intel patch review process first, before asking others to review your changes?
I didn't CC you because I thought you would want the patches to be vetted on the linux-fpga mail list (which includes Intel folks) and approved by Moritz before looking at them. I gave you the FYI here because you requested the changes and I wanted to let you know that they are in progress.
Quoted 4 lines
{sigh}
greg k-h
Moritz Fischer
maintainerPATCH 2/12 fpga: sec-mgr: enable secure updates
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
The write of the filename will return immediately, and the update will begin in the context of a kernel worker thread. This tool utilizes the request_firmware framework, which requires that the image file reside under /lib/firmware.
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 13 ++ drivers/fpga/fpga-sec-mgr.c | 160 ++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 48 ++++++ 3 files changed, 221 insertions(+)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +13 -0
@@ -3,3 +3,16 @@ Date: June 2021 KernelVersion: 5.14 Contact: Russ Weight <[email protected]> Description: Name of low level fpga security manager driver. + +What: /sys/class/fpga_sec_mgr/fpga_secX/update/filename +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Write only. Write the filename of an image + file to this sysfs file to initiate a secure + update. The file must have an appropriate header + which, among other things, identifies the target + for the update. This mechanism is used to update + BMC images, BMC firmware, Static Region images, + and Root Entry Hashes, and to cancel Code Signing + Keys (CSK).
drivers/fpga/fpga-sec-mgr.c +160 -0
203 lines not on this page · raw message
include/linux/fpga/fpga-sec-mgr.h +48 -0
70 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
Why is userspace responsible for triggering this? Passing a "filename" into the kernel and having it do something with it is ripe for major problems, please do not.
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 9 lines · Greg KH
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
Quoted 4 lines
Why is userspace responsible for triggering this? Passing a "filename" into the kernel and having it do something with it is ripe for major problems, please do not.
I am using the "request_firmware" framework, which accepts a filename and finds the firmware file under /lib/firmware.
Is this not an acceptable use for request_firmware?
- Russ
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 14 lines · Russ Weight
Quoted 9 lines · Greg KH
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
Quoted 4 lines
Why is userspace responsible for triggering this? Passing a "filename" into the kernel and having it do something with it is ripe for major problems, please do not.
Quoted 6 lines
I am using the "
request_firmware" framework, which accepts a filename and finds the firmware file under/lib/firmware.Is this not an acceptable use for
request_firmware?- Russ
Hi Greg,
The dev_release fixes that you asked for in the FPGA Manager, Bridge, and Region code are almost complete. I'm trying to get back to the FPGA security manager patch set. Your previous comments challenged some basic assumptions. If it is OK, I would like to get some clarity before I rework the patches.
Overview: The goal is to pass signed data to the PCIe FPGA Card's BMC. BMC firmware will authenticate the data and disposition it. In our case, FPGA image data, root entry hashes, and cancellation keys are authenticated and then stored in FLASH memory. The patchset contains both a class driver and a platform driver.
Example Output of Current Driver:
[root@psera2-dell24 update]# echo -n intel/dcp_2_0_page0_0x2020002000000237_signed.bin > filename [root@psera2-dell24 update]# while :; do cat status remaining_size ; sleep 3; done preparing
8094720
<- snip ->
writing
8012800
<- snip ->
programming
0
<- snip ->
programming
0
<- snip ->
idle
0
^C
[root@psera2-dell24 update]# cat error
[root@psera2-dell24 update]#
Assumptions:
(1) request_firmware(). We had assumed that making use of the existing request_firmware() would be preferred. This requires providing a filename under /lib/firmware to the framework. You commented (above): "Passing a 'filename' into the kernel and having it do something with it is ripe for problems, please do not." Unless you have additional comments on this, I will plan to NOT use the request_firmware framework.
(2) sysfs interface. We had assumed that a sysfs interface would be preferred. If I am not passing a filename, then I think my only option with sysfs is to use a binary attribute and cat the data in. Is that acceptable, or would it be better to use IOCTLs to pass the data?
(3) Platform Driver. This driver is for the BMC on the FPGA Card. I think that is similar to the SOC model. This is actually a sub-driver for the MAX10 BMC driver. Other platform drivers (e.g. hwmon) have already been accepted as subdrivers for the BMC. Is the platform driver the right approach? If not, can you please point me in the right direction?
(4) Kernel worker thread: The worst case update is currently about 45 minutes (newer implementations are shorter). We chose to do the data transfer in a kernel worker thread and then make it possible for userspace to monitor the progress (currently via sysfs). Any concerns about doing the transfer in a background thread?
(5) New vs modified driver: Perhaps "FPGA Security Manager" is not a good name. Simply put, the driver passes signed data from the host to the Card BMC for authentication and disposition. I looked at merging the class driver with the FPGA Manager, but:
a) Secure updates make no use of the existing FPGA Manager code (FPGA state management, etc). The only similarity is in the ops data structure.
b) Because of the kernel worker thread the driver remove functionality adds complexity that is not helpful to the FPGA Manager.
I can, of course, combine the drivers anyway if you think that is better.
I appreciate any feedback/direction you can give.
Thanks,
- Russ
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 24 lines · Russ Weight
Quoted 14 lines · Russ Weight
Quoted 9 lines · Greg KH
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
Quoted 4 lines
Why is userspace responsible for triggering this? Passing a "filename" into the kernel and having it do something with it is ripe for major problems, please do not.
Quoted 6 lines
I am using the "
request_firmware" framework, which accepts a filename and finds the firmware file under/lib/firmware.Is this not an acceptable use for
request_firmware?- Russ
Quoted 7 lines
Hi Greg,
The
dev_releasefixes that you asked for in the FPGA Manager, Bridge, and Region code are almost complete. I'm trying to get back to the FPGA security manager patch set. Your previous comments challenged some basic assumptions. If it is OK, I would like to get some clarity before I rework the patches.
Note, I do not have the time, nor the inclination, to help your company out with design reviews at this point in time. If you have questions about this, please discuss it with the open source managers at Intel, they know the current situation quite well.
I am glad to review patches that have gone through the proper internal Intel patch review process and then sent out to the community.
That being said, I will make one comment on your questions below:
Quoted 6 lines
(1)
request_firmware(). We had assumed that making use of the existingrequest_firmware()would be preferred. This requires providing a filename under/lib/firmwareto the framework. You commented (above): "Passing a 'filename' into the kernel and having it do something with it is ripe for problems, please do not." Unless you have additional comments on this, I will plan to NOT use therequest_firmwareframework.
request_firmware() should always be used for requesting firmware for a device. Having an api where you write a random filename to a sysfs file and have that loaded by the kernel seems ripe for disaster though, I can not think of any other in-kernel user of the firmware api that does this. Or are there examples that I have just missed?
thanks,
greg k-h
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 30 lines · Greg KH
Quoted 21 lines · Russ Weight
Quoted 19 lines · Russ Weight
Quoted 9 lines · Greg KH
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
Quoted 4 lines
Why is userspace responsible for triggering this? Passing a "filename" into the kernel and having it do something with it is ripe for major problems, please do not.
I am using the "
request_firmware" framework, which accepts a filename and finds the firmware file under/lib/firmware.Is this not an acceptable use for
request_firmware?Quoted 8 lines
Quoted 1 line
- Russ
Hi Greg,
The
dev_releasefixes that you asked for in the FPGA Manager, Bridge, and Region code are almost complete. I'm trying to get back to the FPGA security manager patch set. Your previous comments challenged some basic assumptions. If it is OK, I would like to get some clarity before I rework the patches.
Quoted 7 lines
Note, I do not have the time, nor the inclination, to help your company out with design reviews at this point in time. If you have questions about this, please discuss it with the open source managers at Intel, they know the current situation quite well.
I am glad to review patches that have gone through the proper internal Intel patch review process and then sent out to the community.
For what it is worth, these patches _were_ reviewed internally before they were submitted to the public list. The first public submission (Sep 2020) included review tags. I was asked to remove them and let them be added back during the public review:
https://marc.info/?l=linux-fpga&m=159926670526828&w=2
Unfortunately, Intel review tags were not volunteered during the public review, and it didn't occur to me to solicit the tags before the patches were forwarded on to you by Moritz.
Most notably, Yilun and Hao contributed to the review both internally and publicly. They are both listed in the MAINTAINERS file:
Xu Yilun <[email protected]>
Wu Hao <[email protected]>
All issues/comments were resolved before the patches were sent to you.
Quoted 8 lines
That being said, I will make one comment on your questions below:
Quoted 6 lines
(1)
request_firmware(). We had assumed that making use of the existingrequest_firmware()would be preferred. This requires providing a filename under/lib/firmwareto the framework. You commented (above): "Passing a 'filename' into the kernel and having it do something with it is ripe for problems, please do not." Unless you have additional comments on this, I will plan to NOT use therequest_firmwareframework.
Quoted 5 lines
request_firmware()should always be used for requesting firmware for a device. Having an api where you write a random filename to a sysfs file and have that loaded by the kernel seems ripe for disaster though, I can not think of any other in-kernel user of the firmware api that does this. Or are there examples that I have just missed?
I found an instance of a driver that allows the firmware filename (under /lib/firmware) to be changed via sysfs:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-class-mic#n107
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-class-mic#n117
I get why it seems dangerous to provide a /lib/firmware filename via sysfs and have the system automatically transfer that data to a device. I'm just trying to figure out if there is a preferred/less-dangerous way to do what we are trying to do.
Our objective is to allow the user to provide a new, signed FPGA image that can be loaded on the fly (think cloud environment). The PCIe FPGA card authenticates the image data with encryption keys; the host-side software is not trusted by the device. So, other than checking the data size, host software just passes the data through.
I think our usage is firmware-like, but it doesn't exactly fit the current usage of request_firmware(). The firmware filename isn't hardwired into the driver and the image isn't loaded at probe time.
If the request_firmware() implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?
- Russ
Quoted 4 lines
thanks,
greg k-h
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 52 lines · Russ Weight
Quoted 30 lines · Greg KH
Quoted 21 lines · Russ Weight
Quoted 19 lines · Russ Weight
Quoted 9 lines · Greg KH
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/filename sysfs node that can be used to initiate a secure update. The filename of a secure update file (BMC image, FPGA image, Root Entry Hash image, or Code Signing Key cancellation image) can be written to this sysfs entry to cause a secure update to occur.
Quoted 4 lines
Why is userspace responsible for triggering this? Passing a "filename" into the kernel and having it do something with it is ripe for major problems, please do not.
I am using the "
request_firmware" framework, which accepts a filename and finds the firmware file under/lib/firmware.Is this not an acceptable use for
request_firmware?Quoted 8 lines
Quoted 1 line
- Russ
Hi Greg,
The
dev_releasefixes that you asked for in the FPGA Manager, Bridge, and Region code are almost complete. I'm trying to get back to the FPGA security manager patch set. Your previous comments challenged some basic assumptions. If it is OK, I would like to get some clarity before I rework the patches.Quoted 7 lines
Note, I do not have the time, nor the inclination, to help your company out with design reviews at this point in time. If you have questions about this, please discuss it with the open source managers at Intel, they know the current situation quite well.
I am glad to review patches that have gone through the proper internal Intel patch review process and then sent out to the community.
For what it is worth, these patches _were_ reviewed internally before they were submitted to the public list. The first public submission (Sep 2020) included review tags. I was asked to remove them and let them be added back during the public review:
https://marc.info/?l=linux-fpga&m=159926670526828&w=2
Unfortunately, Intel review tags were not volunteered during the public review, and it didn't occur to me to solicit the tags before the patches were forwarded on to you by Moritz.
Quoted 7 lines
Most notably, Yilun and Hao contributed to the review both internally and publicly. They are both listed in the
MAINTAINERSfile:Xu Yilun <[email protected]>
Wu Hao <[email protected]>All issues/comments were resolved before the patches were sent to you.
That's fine and wonderful, but not what I was talking about here at all.
Again, I am willing to review patches, but not take the time out to comment on general design decisions like this for the reasons stated in the past.
Quoted 14 lines
Quoted 8 lines
That being said, I will make one comment on your questions below:
Quoted 6 lines
(1)
request_firmware(). We had assumed that making use of the existingrequest_firmware()would be preferred. This requires providing a filename under/lib/firmwareto the framework. You commented (above): "Passing a 'filename' into the kernel and having it do something with it is ripe for problems, please do not." Unless you have additional comments on this, I will plan to NOT use therequest_firmwareframework.Quoted 5 lines
request_firmware()should always be used for requesting firmware for a device. Having an api where you write a random filename to a sysfs file and have that loaded by the kernel seems ripe for disaster though, I can not think of any other in-kernel user of the firmware api that does this. Or are there examples that I have just missed?
Quoted 5 lines
I found an instance of a driver that allows the firmware filename (under
/lib/firmware) to be changed via sysfs:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-class-mic#n107
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-class-mic#n117
Ah, another Intel driver wanting to do bad things, nice example :)
Quoted 11 lines
I get why it seems dangerous to provide a
/lib/firmwarefilename via sysfs and have the system automatically transfer that data to a device. I'm just trying to figure out if there is a preferred/less-dangerous way to do what we are trying to do.Our objective is to allow the user to provide a new, signed FPGA image that can be loaded on the fly (think cloud environment). The PCIe FPGA card authenticates the image data with encryption keys; the host-side software is not trusted by the device. So, other than checking the data size, host software just passes the data through.
Quoted 6 lines
I think our usage is firmware-like, but it doesn't exactly fit the current usage of
request_firmware(). The firmware filename isn't hardwired into the driver and the image isn't loaded at probe time.If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?
There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
thanks,
greg k-h
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Perhaps the name, fpga security manager, is wrong? Maybe something like fpga_sec_image_xfer is better?
- Russ
Quoted 3 lines
thanks,
greg k-h
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 9 lines · Russ Weight
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
Quoted 6 lines
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use
request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.
Ah, yes, a "normal" write command might be best for this as that can be properly containerized and controlled.
Quoted 19 lines
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
Quoted 7 lines
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Perhaps the name, fpga security manager, is wrong? Maybe something like
fpga_sec_image_xferis better?
It does not sound like this has anything to do with "security", and rather is just a normal firmware upload, so "fpga_image_upload()" perhaps?
naming is hard,
greg k-h
Moritz Fischer
maintainerRe: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 44 lines · Greg KH
Quoted 9 lines · Russ Weight
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
Quoted 6 lines
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use
request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.Ah, yes, a "normal" write command might be best for this as that can be properly containerized and controlled.
Quoted 24 lines
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Quoted 6 lines
Quoted 2 lines
Perhaps the name, fpga security manager, is wrong? Maybe something like
fpga_sec_image_xferis better?It does not sound like this has anything to do with "security", and rather is just a normal firmware upload, so "
fpga_image_upload()" perhaps?
I had originally suggested 'load' and 'persist' or 'load' and 'update or something of that sort.
Taking one step back, maybe the case could be made for a generic 'persistent firmware' update framework that addresses use-cases that require updating firmware that may take extended periods of time.
A similar case that comes to mind would be writing firmware to an external flash on a Renesas xHCI controller, or updating the BMC firmware for a plug-in card with BMC.
- Moritz
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 52 lines · Moritz Fischer
Quoted 44 lines · Greg KH
Quoted 9 lines · Russ Weight
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
Quoted 6 lines
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use
request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.Ah, yes, a "normal" write command might be best for this as that can be properly containerized and controlled.
Quoted 24 lines
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Quoted 6 lines
Quoted 2 lines
Perhaps the name, fpga security manager, is wrong? Maybe something like
fpga_sec_image_xferis better?It does not sound like this has anything to do with "security", and rather is just a normal firmware upload, so "
fpga_image_upload()" perhaps?
Quoted 6 lines
I had originally suggested 'load' and 'persist' or 'load' and 'update or something of that sort.
Taking one step back, maybe the case could be made for a generic 'persistent firmware' update framework that addresses use-cases that require updating firmware that may take extended periods of time.
There should not be a problem with using the existing firmware layer for images that take long periods of time, as long as you are not wanting to see any potential progress :)
So how about just adding anything missing to the existing firmware subsystem. It's attempting to handle all use cases already, if it is missing one, no harm in adding more options there...
thanks,
greg k-h
Moritz Fischer
maintainerRe: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 60 lines · Greg KH
Quoted 52 lines · Moritz Fischer
Quoted 44 lines · Greg KH
Quoted 9 lines · Russ Weight
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
Quoted 6 lines
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use
request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.Ah, yes, a "normal" write command might be best for this as that can be properly containerized and controlled.
Quoted 24 lines
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Quoted 6 lines
Quoted 2 lines
Perhaps the name, fpga security manager, is wrong? Maybe something like
fpga_sec_image_xferis better?It does not sound like this has anything to do with "security", and rather is just a normal firmware upload, so "
fpga_image_upload()" perhaps?Quoted 6 lines
I had originally suggested 'load' and 'persist' or 'load' and 'update or something of that sort.
Taking one step back, maybe the case could be made for a generic 'persistent firmware' update framework that addresses use-cases that require updating firmware that may take extended periods of time.
Quoted 7 lines
There should not be a problem with using the existing firmware layer for images that take long periods of time, as long as you are not wanting to see any potential progress :)
So how about just adding anything missing to the existing firmware subsystem. It's attempting to handle all use cases already, if it is missing one, no harm in adding more options there...
Even better if we can do that. It would have a limited overlap with existing functionality, though.
- Moritz
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
In reply to Greg KHQuoted 54 lines · Greg KH
Quoted 47 lines · Moritz Fischer
Quoted 41 lines · Greg KH
Quoted 7 lines · Russ Weight
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
Quoted 6 lines
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use
request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.Ah, yes, a "normal" write command might be best for this as that can be properly containerized and controlled.
Quoted 24 lines
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Quoted 5 lines
Quoted 2 lines
Perhaps the name, fpga security manager, is wrong? Maybe something like
fpga_sec_image_xferis better?It does not sound like this has anything to do with "security", and rather is just a normal firmware upload, so "
fpga_image_upload()" perhaps?Quoted 6 lines
I had originally suggested 'load' and 'persist' or 'load' and 'update or something of that sort.
Taking one step back, maybe the case could be made for a generic 'persistent firmware' update framework that addresses use-cases that require updating firmware that may take extended periods of time.
Quoted 7 lines
There should not be a problem with using the existing firmware layer for images that take long periods of time, as long as you are not wanting to see any potential progress :)
So how about just adding anything missing to the existing firmware subsystem. It's attempting to handle all use cases already, if it is missing one, no harm in adding more options there...
Hi Greg,
We have had a lot of internal (to Intel) discussion about how to organize the support for uploading FPGA images. It would be helpful to know which of the following two options you find the least disturbing :-)
Background: We are uploading signed, self-describing images that are authenticated and dispositioned by the Card BMC. These could result in FLASH updates for FPGA images, BMC images, firmware, or security keys. They could also result in a temporary authentication certificate being loaded into RAM as part of a multi-step key provisioning process.
Options:
(a) A single API that facilitates the upload of a data stream without analyzing the stream contents, relying on the lower-level driver and/or HW to accept or reject the data.
(b) Multiple, targeted APIs (e.g. IOCTL_FPGA_IMAGE_UPDATE, IOCTL_BMC_IMAGE_UPDATE, IOCTL_KEY_UPDATE, IOCTL_KEY_CANCEL) that each interpret the stream type and reject them if they don't correspond to the API target.
Do you have a preference between (a) and (b)?
Thanks,
- Russ
Quoted 3 lines
thanks,
greg k-h
Re: [PATCH 02/12] fpga: sec-mgr: enable secure updates
Quoted 78 lines · Russ Weight
Quoted 54 lines · Greg KH
Quoted 47 lines · Moritz Fischer
Quoted 41 lines · Greg KH
Quoted 7 lines · Russ Weight
Quoted 5 lines · Greg KH
Quoted 2 lines
If the
request_firmware()implementation is not acceptable, then would you agree that an IOCTL implementation is our best option?There is no difference in the end between using an ioctl, or a sysfs file, to provide the filename of your firmware, don't get hung up on that.
Quoted 6 lines
I meant to suggest that passing file data (not a filename) through an IOCTL might be better for this use case than trying to use
request_firmware. We have to, somehow, allow the user to point us to the desired image data (which could be a root-entry-hash, or an FPGA image). We can't really use a fixed filename modified by device version as many of the devices do.Ah, yes, a "normal" write command might be best for this as that can be properly containerized and controlled.
Quoted 24 lines
Quoted 7 lines
By providing a "filename", you are going around all of the namespace and other "container" protection that the kernel provides, and allowing processes to potentially load files that are normally outside of their scope to the hardware. If you are willing to allow that security "escape", wonderful, but you better document the heck out of it and explain why this is allowed for your special hardware and use case.
Quoted 7 lines
As you are expecting this to work "in the cloud", I do not think that the operators of such hardware are really going to be all that happy to see this type of interface given these reasons.
What is wrong with the current fpga firmware api that somehow is lacking for your special hardware, that other devices do not have to worry about?
The existing framework wants to update the live image in the FPGA, whereas for this device, we are passing signed data to BMC firmware which will store it in FLASH to be loaded on a subsequent boot of the card.
The existing framework needs to manage FPGA state, whereas for this device, it is just a transfer of signed data. We also have to handle a total transfer/authentication time of up to 45 minutes, so we are using a kernel worker thread for the update.
Quoted 5 lines
Quoted 2 lines
Perhaps the name, fpga security manager, is wrong? Maybe something like
fpga_sec_image_xferis better?It does not sound like this has anything to do with "security", and rather is just a normal firmware upload, so "
fpga_image_upload()" perhaps?Quoted 6 lines
I had originally suggested 'load' and 'persist' or 'load' and 'update or something of that sort.
Taking one step back, maybe the case could be made for a generic 'persistent firmware' update framework that addresses use-cases that require updating firmware that may take extended periods of time.
Quoted 7 lines
There should not be a problem with using the existing firmware layer for images that take long periods of time, as long as you are not wanting to see any potential progress :)
So how about just adding anything missing to the existing firmware subsystem. It's attempting to handle all use cases already, if it is missing one, no harm in adding more options there...
Hi Greg,
We have had a lot of internal (to Intel) discussion about how to organize the support for uploading FPGA images. It would be helpful to know which of the following two options you find the least disturbing :-)
Background: We are uploading signed, self-describing images that are authenticated and dispositioned by the Card BMC. These could result in FLASH updates for FPGA images, BMC images, firmware, or security keys. They could also result in a temporary authentication certificate being loaded into RAM as part of a multi-step key provisioning process.
Quoted 4 lines
Options:
(a) A single API that facilitates the upload of a data stream without analyzing the stream contents, relying on the lower-level driver and/or HW to accept or reject the data.
That is the firmware api we have today, please use that like all other drivers should be using.
Quoted 4 lines
(b) Multiple, targeted APIs (e.g.
IOCTL_FPGA_IMAGE_UPDATE,IOCTL_BMC_IMAGE_UPDATE,IOCTL_KEY_UPDATE,IOCTL_KEY_CANCEL) that each interpret the stream type and reject them if they don't correspond to the API target.
Please no, do not make a zillion "custom" ioctls. That way lies madness. Will you want to maintain them all for the next 30+ years?
thanks,
greg k-h
Moritz Fischer
maintainerPATCH 3/12 fpga: sec-mgr: expose sec-mgr update status
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/status sysfs node that can be polled and read to monitor the progress of an ongoing secure update. Sysfs_notify() is used to signal transitions between different phases of the update process.
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 11 +++++ drivers/fpga/fpga-sec-mgr.c | 42 +++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +11 -0
@@ -16,3 +16,14 @@ Description: Write only. Write the filename of an image BMC images, BMC firmware, Static Region images, and Root Entry Hashes, and to cancel Code Signing Keys (CSK). + +What: /sys/class/fpga_sec_mgr/fpga_secX/update/status +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read-only. Returns a string describing the current + status of an update. The string will be one of the + following: idle, reading, preparing, writing, + programming. Userspace code can poll on this file, + as it will be signaled by sysfs_notify() on each + state change.
drivers/fpga/fpga-sec-mgr.c +38 -4
84 lines not on this page · raw message
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 4/12 fpga: sec-mgr: expose sec-mgr update errors
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/error sysfs node that can be read for error information when a secure update fails.
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 17 ++++ drivers/fpga/fpga-sec-mgr.c | 83 ++++++++++++++++--- include/linux/fpga/fpga-sec-mgr.h | 1 + 3 files changed, 89 insertions(+), 12 deletions(-)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +17 -0
@@ -27,3 +27,20 @@ Description: Read-only. Returns a string describing the current programming. Userspace code can poll on this file, as it will be signaled by sysfs_notify() on each state change. + +What: /sys/class/fpga_sec_mgr/fpga_secX/update/error +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read-only. Returns a string describing the failure + of a secure update. This string will be in the form + of <STATUS>:<ERROR>, where <STATUS> will be one of + the status strings described for the status sysfs + file and <ERROR> will be one of the following: + hw-error, timeout, user-abort, device-busy, + invalid-file-size, read-write-error, flash-wearout, + file-read-error. The error sysfs file is only + meaningful when the secure update engine is in the + idle state. If this file is read while a secure + update is in progress, then the read will fail with + EBUSY.
drivers/fpga/fpga-sec-mgr.c +71 -12
125 lines not on this page · raw message
include/linux/fpga/fpga-sec-mgr.h +1 -0
@@ -70,6 +70,7 @@ struct fpga_sec_mgr {const u8 *data;/* pointer to update data */ u32 remaining_size;/* size remaining to transfer */ enum fpga_sec_prog progress; +enum fpga_sec_prog err_state;/* progress state at time of failure */ enum fpga_sec_err err_code;/* security manager error code */ bool driver_unload;void *priv;
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 5/12 fpga: sec-mgr: expose sec-mgr update size
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/remaining_size sysfs node that can be read to determine how much data remains to be transferred to the secure update engine. This file can be used to monitor progress during the "writing" phase of an update.
--- Documentation/ABI/testing/sysfs-class-fpga-sec-mgr | 11 +++++++++++ drivers/fpga/fpga-sec-mgr.c | 10 ++++++++++ 2 files changed, 21 insertions(+)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +11 -0
@@ -28,6 +28,17 @@ Description: Read-only. Returns a string describing the current as it will be signaled by sysfs_notify() on each state change. +What: /sys/class/fpga_sec_mgr/fpga_secX/update/remaining_size +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read-only. Returns the size of data that remains to + be written to the secure update engine. The size + value is initialized to the full size of the file + image and the value is updated periodically during + the "writing" phase of the update. + Format: "%u". + What: /sys/class/fpga_sec_mgr/fpga_secX/update/error Date: June 2021 KernelVersion: 5.14
drivers/fpga/fpga-sec-mgr.c +10 -0
@@ -198,6 +198,15 @@ error_show(struct device *dev, struct device_attribute *attr, char *buf) }static DEVICE_ATTR_RO (error); +static ssize_t remaining_size_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%u\n" , smgr->remaining_size); +} +static DEVICE_ATTR_RO (remaining_size); +static ssize_t filename_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) {
@@ -234,6 +243,7 @@ static struct attribute *sec_mgr_update_attrs[] = { &dev_attr_filename.attr, &dev_attr_status.attr, &dev_attr_error.attr, + &dev_attr_remaining_size.attr, NULL, };
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 6/12 fpga: sec-mgr: enable cancel of secure update
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an update/cancel sysfs file that can be written to request that an update be canceled. The write may return EBUSY if the update has progressed to the point that it cannot be canceled by software or ENODEV if there is no update in progress.
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 10 ++++ drivers/fpga/fpga-sec-mgr.c | 59 +++++++++++++++++-- include/linux/fpga/fpga-sec-mgr.h | 1 + 3 files changed, 66 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +10 -0
@@ -17,6 +17,16 @@ Description: Write only. Write the filename of an image and Root Entry Hashes, and to cancel Code Signing Keys (CSK). +What: /sys/class/fpga_sec_mgr/fpga_secX/update/cancel +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Write-only. Write a "1" to this file to request + that a current update be canceled. This request + will be rejected (EBUSY) if the programming phase + has already started or (ENODEV) if there is no + update in progress. + What: /sys/class/fpga_sec_mgr/fpga_secX/update/status Date: June 2021 KernelVersion: 5.14
drivers/fpga/fpga-sec-mgr.c +55 -4
103 lines not on this page · raw message
include/linux/fpga/fpga-sec-mgr.h +1 -0
@@ -72,6 +72,7 @@ struct fpga_sec_mgr {enum fpga_sec_prog progress;enum fpga_sec_prog err_state;/* progress state at time of failure */ enum fpga_sec_err err_code;/* security manager error code */ +bool request_cancel;bool driver_unload;void *priv; };
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 7/12 fpga: sec-mgr: expose hardware error info
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an optional update/hw_errinfo sysfs node that can be used to retrieve 64 bits of device specific error information following a secure update failure.
The underlying driver must provide a get_hw_errinfo() callback function to enable this feature. This data is treated as opaque by the class driver. It is left to user-space software or support personnel to interpret this data.
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 14 +++++++ drivers/fpga/fpga-sec-mgr.c | 38 +++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 5 +++ 3 files changed, 57 insertions(+)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +14 -0
@@ -65,3 +65,17 @@ Description: Read-only. Returns a string describing the failure idle state. If this file is read while a secure update is in progress, then the read will fail with EBUSY. + +What: /sys/class/fpga_sec_mgr/fpga_secX/update/hw_errinfo +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read-only. Returns a 64 bit error value providing + hardware specific information that may be useful in + debugging errors that occur during FPGA image updates. + This file is only visible if the underlying device + supports it. The hw_errinfo value is only accessible + when the secure update engine is in the idle state. + If this file is read while a secure update is in + progress, then the read will fail with EBUSY. + Format: "0x%llx".
drivers/fpga/fpga-sec-mgr.c +38 -0
@@ -36,10 +36,17 @@ static void fpga_sec_set_error(struct fpga_sec_mgr *smgr, enum fpga_sec_err err_ smgr->err_code = err_code; } +static void fpga_sec_set_hw_errinfo (struct fpga_sec_mgr *smgr) +{ +if (smgr->sops->get_hw_errinfo) + smgr->hw_errinfo = smgr->sops->get_hw_errinfo (smgr); +} +static void fpga_sec_dev_error (struct fpga_sec_mgr *smgr,enum fpga_sec_err err_code) {fpga_sec_set_error (smgr, err_code); +fpga_sec_set_hw_errinfo (smgr); smgr->sops->cancel (smgr); }
@@ -221,6 +228,23 @@ error_show(struct device *dev, struct device_attribute *attr, char *buf) }static DEVICE_ATTR_RO (error); +static ssize_t +hw_errinfo_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); +int ret; + +mutex_lock (&smgr->lock); +if (smgr->progress !=FPGA_SEC_PROG_IDLE ) + ret = -EBUSY ; +else + ret =sysfs_emit (buf,"0x%llx\n" , smgr->hw_errinfo); +mutex_unlock (&smgr->lock); + +return ret; +} +static DEVICE_ATTR_RO (hw_errinfo); +static ssize_t remaining_size_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -252,6 +276,7 @@ static ssize_t filename_store(struct device *dev, struct device_attribute *attr, } smgr->err_code =FPGA_SEC_ERR_NONE ; + smgr->hw_errinfo =0 ; smgr->request_cancel = false; smgr->progress =FPGA_SEC_PROG_READING ;reinit_completion (&smgr->update_done);
@@ -286,18 +311,31 @@ static ssize_t cancel_store(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_WO (cancel); +static umode_t +sec_mgr_update_visible (struct kobject *kobj,struct attribute *attr,int n) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (kobj_to_dev (kobj)); + +if (attr == &dev_attr_hw_errinfo.attr && !smgr->sops->get_hw_errinfo) +return 0 ; + +return attr->mode; +} +static struct attribute *sec_mgr_update_attrs[] = { &dev_attr_filename.attr, &dev_attr_cancel.attr, &dev_attr_status.attr, &dev_attr_error.attr, &dev_attr_remaining_size.attr, + &dev_attr_hw_errinfo.attr,NULL , };static struct attribute_group sec_mgr_update_attr_group = { .name ="update" , .attrs = sec_mgr_update_attrs, + .is_visible = sec_mgr_update_visible, }; static ssize_t name_show(struct device *dev,
include/linux/fpga/fpga-sec-mgr.h +5 -0
@@ -40,6 +40,9 @@ enum fpga_sec_err {* function and is called at the completion * of the update, whether success or failure, * if the prepare function succeeded. +* @get_hw_errinfo: Optional: Return u64 hw specific error info. +* The software err_code may used to determine +* whether the hw error info is applicable. */ struct fpga_sec_mgr_ops {enum fpga_sec_err (*prepare)(struct fpga_sec_mgr *smgr);
@@ -47,6 +50,7 @@ struct fpga_sec_mgr_ops {enum fpga_sec_err (*poll_complete)(struct fpga_sec_mgr *smgr);enum fpga_sec_err (*cancel)(struct fpga_sec_mgr *smgr);void (*cleanup)(struct fpga_sec_mgr *smgr); +u64 (*get_hw_errinfo)(struct fpga_sec_mgr *smgr); };/* Update progress codes */
@@ -72,6 +76,7 @@ struct fpga_sec_mgr {enum fpga_sec_prog progress;enum fpga_sec_prog err_state;/* progress state at time of failure */ enum fpga_sec_err err_code;/* security manager error code */ +u64 hw_errinfo;/* 64 bits of HW specific error info */ bool request_cancel;bool driver_unload;void *priv;
Signature · 1 line
2.31.1
Re: [PATCH 07/12] fpga: sec-mgr: expose hardware error info
Quoted 11 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an optional update/hw_errinfo sysfs node that can be used to retrieve 64 bits of device specific error information following a secure update failure.
The underlying driver must provide a
get_hw_errinfo()callback function to enable this feature. This data is treated as opaque by the class driver. It is left to user-space software or support personnel to interpret this data.
No, you don't provide "opaque" data to userspace, that's a sure way to make it such that no one knows what this data is supposed to be, and so it can not be maintained at all.
Quoted 57 lines
Signed-off-by Russ Weight <[email protected]>Reviewed-by Tom Rix <[email protected]>Signed-off-by Moritz Fischer <[email protected]>--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 14 +++++++ drivers/fpga/fpga-sec-mgr.c | 38 +++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 5 +++ 3 files changed, 57 insertions(+)Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +14
-0@@ -65,3 +65,17 @@ Description: Read-only. Returns a string describing the failure idle state. If this file is read while a secure update is in progress, then the read will fail with EBUSY. + +What: /sys/class/fpga_sec_mgr/fpga_secX/update/hw_errinfo +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read-only. Returns a 64 bit error value providing + hardware specific information that may be useful in + debugging errors that occur during FPGA image updates. + This file is only visible if the underlying device + supports it. The hw_errinfo value is only accessible + when the secure update engine is in the idle state. + If this file is read while a secure update is in + progress, then the read will fail with EBUSY. + Format: "0x%llx".drivers/fpga/fpga-sec-mgr.c +7
-0@@ -36,10 +36,17 @@ static void fpga_sec_set_error(struct fpga_sec_mgr *smgr, enum fpga_sec_err err_ smgr->err_code = err_code; } +static void fpga_sec_set_hw_errinfo (struct fpga_sec_mgr *smgr) +{ +if (smgr->sops->get_hw_errinfo) + smgr->hw_errinfo = smgr->sops->get_hw_errinfo (smgr); +} +static void fpga_sec_dev_error (struct fpga_sec_mgr *smgr,enum fpga_sec_err err_code) {fpga_sec_set_error (smgr, err_code); +fpga_sec_set_hw_errinfo (smgr); smgr->sops->cancel (smgr); }@@ -221,6 +228,23 @@ error_show(struct device *dev, struct device_attribute *attr, char *buf) }static DEVICE_ATTR_RO (error);
drivers/fpga/fpga-sec-mgr.c error_show(struct device *dev, struct device_attribute *attr, char *buf) · line 239
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c +9
-0+static ssize_t +hw_errinfo_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); +int ret; + +mutex_lock (&smgr->lock); +if (smgr->progress !=FPGA_SEC_PROG_IDLE ) + ret = -EBUSY ;
Why does the state matter here?
greg k-h
Re: [PATCH 07/12] fpga: sec-mgr: expose hardware error info
Quoted 8 lines · Greg KH
Quoted 7 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Extend the FPGA Security Manager class driver to include an optional update/hw_errinfo sysfs node that can be used to retrieve 64 bits of device specific error information following a secure update failure.
Quoted 7 lines
Quoted 4 lines
The underlying driver must provide a
get_hw_errinfo()callback function to enable this feature. This data is treated as opaque by the class driver. It is left to user-space software or support personnel to interpret this data.No, you don't provide "opaque" data to userspace, that's a sure way to make it such that no one knows what this data is supposed to be, and so it can not be maintained at all.
My intent was that the data be opaque to the class driver layer, but not to the parent driver or to the user-space code (which could process the data based on the device type).
If this is not appropriate, it is an optional feature and can be removed.
Quoted 57 lines
Quoted 57 lines
Signed-off-by Russ Weight <[email protected]>Reviewed-by Tom Rix <[email protected]>Signed-off-by Moritz Fischer <[email protected]>--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 14 +++++++ drivers/fpga/fpga-sec-mgr.c | 38 +++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 5 +++ 3 files changed, 57 insertions(+)Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +14
-0@@ -65,3 +65,17 @@ Description: Read-only. Returns a string describing the failure idle state. If this file is read while a secure update is in progress, then the read will fail with EBUSY. + +What: /sys/class/fpga_sec_mgr/fpga_secX/update/hw_errinfo +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read-only. Returns a 64 bit error value providing + hardware specific information that may be useful in + debugging errors that occur during FPGA image updates. + This file is only visible if the underlying device + supports it. The hw_errinfo value is only accessible + when the secure update engine is in the idle state. + If this file is read while a secure update is in + progress, then the read will fail with EBUSY. + Format: "0x%llx".drivers/fpga/fpga-sec-mgr.c +7
-0@@ -36,10 +36,17 @@ static void fpga_sec_set_error(struct fpga_sec_mgr *smgr, enum fpga_sec_err err_ smgr->err_code = err_code; } +static void fpga_sec_set_hw_errinfo (struct fpga_sec_mgr *smgr) +{ +if (smgr->sops->get_hw_errinfo) + smgr->hw_errinfo = smgr->sops->get_hw_errinfo (smgr); +} +static void fpga_sec_dev_error (struct fpga_sec_mgr *smgr,enum fpga_sec_err err_code) {fpga_sec_set_error (smgr, err_code); +fpga_sec_set_hw_errinfo (smgr); smgr->sops->cancel (smgr); }@@ -221,6 +228,23 @@ error_show(struct device *dev, struct device_attribute *attr, char *buf) }static DEVICE_ATTR_RO (error);
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c error_show(struct device *dev, struct device_attribute *attr, char *buf) · line 239
Quoted 9 lines
drivers/fpga/fpga-sec-mgr.c +9
-0+static ssize_t +hw_errinfo_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); +int ret; + +mutex_lock (&smgr->lock); +if (smgr->progress !=FPGA_SEC_PROG_IDLE ) + ret = -EBUSY ;Why does the state matter here?
The transfer and validation of image data can take up to 40 minutes for the N3000 acceleration card, so the transfer of data and the monitoring of the update are happening in a worker thread. The hw_errinfo data is only valid when the update engine is in the IDLE state. Returning EBUSY if the update is still in progress simplifies the locking model.
- Russ
Quoted 2 lines
greg k-h
Moritz Fischer
maintainerPATCH 8/12 fpga: m10bmc-sec: create max10 bmc secure update driver
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Create a platform driver that can be invoked as a sub driver for the Intel MAX10 BMC in order to support secure updates. This sub-driver will invoke an instance of the FPGA Security Manager class driver in order to expose sysfs interfaces for managing and monitoring secure updates to FPGA and BMC images.
This patch creates the MAX10 BMC Secure Update driver and provides sysfs files for displaying the current root entry hashes for the FPGA static region, the FPGA PR region, and the MAX10 BMC.
--- .../testing/sysfs-driver-intel-m10-bmc-secure | 29 ++++ MAINTAINERS | 2 + drivers/fpga/Kconfig | 11 ++ drivers/fpga/Makefile | 3 + drivers/fpga/intel-m10-bmc-secure.c | 135 ++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-secure create mode 100644 drivers/fpga/intel-m10-bmc-secure.c
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-secure new file +29 -0
@@ -0,0 +1,29 @@ +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/sr_root_entry_hash +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns the root entry hash for the static + region if one is programmed, else it returns the + string: "hash not programmed". This file is only + visible if the underlying device supports it. + Format: "0x%x". + +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/pr_root_entry_hash +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns the root entry hash for the partial + reconfiguration region if one is programmed, else it + returns the string: "hash not programmed". This file + is only visible if the underlying device supports it. + Format: "0x%x". + +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/bmc_root_entry_hash +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns the root entry hash for the BMC image + if one is programmed, else it returns the string: + "hash not programmed". This file is only visible if the + underlying device supports it. + Format: "0x%x".
MAINTAINERS +2 -0
@@ -7141,8 +7141,10 @@ M: Russ Weight <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +F: Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-secure F: Documentation/fpga/fpga-sec-mgr.rst F: drivers/fpga/fpga-sec-mgr.c +F: drivers/fpga/intel-m10-bmc-secure.c F: include/linux/fpga/fpga-sec-mgr.h FPU EMULATOR
drivers/fpga/Kconfig +11 -0
@@ -243,4 +243,15 @@ config FPGA_SEC_MGR region and for the BMC. Select this option to enable updates for secure FPGA devices. +config IFPGA_M10_BMC_SECURE + tristate "Intel MAX10 BMC Secure Update driver" + depends on MFD_INTEL_M10_BMC && FPGA_SEC_MGR + help + Secure update support for the Intel MAX10 board management + controller. + + This is a subdriver of the Intel MAX10 board management controller + (BMC) and provides support for secure updates for the BMC image, + the FPGA image, the Root Entry Hashes, etc. + endif # FPGA
drivers/fpga/Makefile +3 -0
@@ -24,6 +24,9 @@ obj-$(CONFIG_ALTERA_PR_IP_CORE_PLAT) += altera-pr-ip-core-plat.o # FPGA Security Manager Framework obj-$(CONFIG_FPGA_SEC_MGR) += fpga-sec-mgr.o +# FPGA Secure Update Drivers +obj-$(CONFIG_IFPGA_M10_BMC_SECURE) += intel-m10-bmc-secure.o + # FPGA Bridge Drivers obj-$(CONFIG_FPGA_BRIDGE) += fpga-bridge.o obj-$(CONFIG_SOCFPGA_FPGA_BRIDGE) += altera-hps2fpga.o altera-fpga2sdram.o
drivers/fpga/intel-m10-bmc-secure.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 08/12] fpga: m10bmc-sec: create max10 bmc secure update driver
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create a platform driver that can be invoked as a sub driver for the Intel MAX10 BMC in order to support secure updates. This sub-driver will invoke an instance of the FPGA Security Manager class driver in order to expose sysfs interfaces for managing and monitoring secure updates to FPGA and BMC images.
No, please NEVER create a platform device for something that is not actually a platform device. That's a huge abuse of the platform device code.
Please use the proper api for this if you need it, hint, it's NOT the platform device code. Your Intel reviewer should have told you what it is when they saw a changelog comment like this....
greg k-h
Re: [PATCH 08/12] fpga: m10bmc-sec: create max10 bmc secure update driver
Quoted 9 lines · Greg KH
Quoted 8 lines · Moritz Fischer
From: Russ Weight <[email protected]>
Create a platform driver that can be invoked as a sub driver for the Intel MAX10 BMC in order to support secure updates. This sub-driver will invoke an instance of the FPGA Security Manager class driver in order to expose sysfs interfaces for managing and monitoring secure updates to FPGA and BMC images.
Quoted 7 lines
No, please NEVER create a platform device for something that is not actually a platform device. That's a huge abuse of the platform device code.
Please use the proper api for this if you need it, hint, it's NOT the platform device code. Your Intel reviewer should have told you what it is when they saw a changelog comment like this....
I was following the design of the n3000bmc-hwmon driver, which was recently accepted upstream.
The MAX10 BMC driver lists sub-devices here, including my device (n3000bmc-secure) and the n3000bmc-hwmon device:
The HWMON sub-driver is implemented as a platform driver here:
Is the HWMON driver implemented incorrectly? Or is there something fundamentally different in what I am trying to do? Can you point me in the right direction? What type of device should this be?
Thanks,
- Russ
Quoted 2 lines
greg k-h
Moritz Fischer
maintainerPATCH 9/12 fpga: m10bmc-sec: expose max10 flash update count
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the MAX10 BMC Secure Update driver to provide a sysfs file to expose the flash update count for the FPGA user image.
--- .../testing/sysfs-driver-intel-m10-bmc-secure | 8 ++++ drivers/fpga/intel-m10-bmc-secure.c | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+)
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-secure +8 -0
@@ -27,3 +27,11 @@ Description: Read only. Returns the root entry hash for the BMC image "hash not programmed". This file is only visible if the underlying device supports it. Format: "0x%x". + +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/flash_count +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns number of times the secure update + staging area has been flashed. + Format: "%u".
drivers/fpga/intel-m10-bmc-secure.c +37 -0
@@ -11,6 +11,7 @@#include <linux/mfd/intel-m10-bmc.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/slab.h> struct m10bmc_sec {struct device *dev;
@@ -78,7 +79,43 @@ DEVICE_ATTR_SEC_REH_RO(bmc, BMC_PROG_MAGIC, BMC_PROG_ADDR, BMC_REH_ADDR);DEVICE_ATTR_SEC_REH_RO (sr,SR_PROG_MAGIC ,SR_PROG_ADDR ,SR_REH_ADDR );DEVICE_ATTR_SEC_REH_RO (pr,PR_PROG_MAGIC ,PR_PROG_ADDR ,PR_REH_ADDR ); +#define FLASH_COUNT_SIZE 4096/* count stored as inverted bit vector */ + +static ssize_t flash_count_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct m10bmc_sec *sec =dev_get_drvdata (dev); +unsigned int stride, num_bits; +u8 *flash_buf; +int cnt, ret; + + stride =regmap_get_reg_stride (sec->m10bmc->regmap); + num_bits =FLASH_COUNT_SIZE *8 ; + + flash_buf =kmalloc (FLASH_COUNT_SIZE ,GFP_KERNEL ); +if (!flash_buf) +return -ENOMEM ; + +WARN_ON (FLASH_COUNT_SIZE % stride); + ret =regmap_bulk_read (sec->m10bmc->regmap,STAGING_FLASH_COUNT , + flash_buf,FLASH_COUNT_SIZE / stride); +if (ret) { +dev_err (sec->dev, +"failed to read flash count: %x cnt %x: %d\n" , +STAGING_FLASH_COUNT ,FLASH_COUNT_SIZE / stride, ret); + goto exit_free; + } + cnt = num_bits -bitmap_weight ((unsigned long *)flash_buf, num_bits); + +exit_free: +kfree (flash_buf); + +return ret ? :sysfs_emit (buf,"%u\n" , cnt); +} +static DEVICE_ATTR_RO (flash_count); +static struct attribute *m10bmc_security_attrs[] = { + &dev_attr_flash_count.attr, &dev_attr_bmc_root_entry_hash.attr, &dev_attr_sr_root_entry_hash.attr, &dev_attr_pr_root_entry_hash.attr,
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 10/12 fpga: m10bmc-sec: expose max10 canceled keys in sysfs
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the MAX10 BMC Secure Update driver to provide sysfs files to expose the canceled code signing key (CSK) bit vectors. These use the standard bitmap list format (e.g. 1,2-6,9).
--- .../testing/sysfs-driver-intel-m10-bmc-secure | 24 ++++++++++ drivers/fpga/intel-m10-bmc-secure.c | 48 +++++++++++++++++++ 2 files changed, 72 insertions(+)
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-secure +24 -0
@@ -28,6 +28,30 @@ Description: Read only. Returns the root entry hash for the BMC image underlying device supports it. Format: "0x%x". +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/sr_canceled_csks +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns a list of indices for canceled code + signing keys for the static region. The standard bitmap + list format is used (e.g. "1,2-6,9"). + +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/pr_canceled_csks +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns a list of indices for canceled code + signing keys for the partial reconfiguration region. The + standard bitmap list format is used (e.g. "1,2-6,9"). + +What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/bmc_canceled_csks +Date: June 2021 +KernelVersion: 5.14 +Contact: Russ Weight <[email protected]> +Description: Read only. Returns a list of indices for canceled code + signing keys for the BMC. The standard bitmap list format + is used (e.g. "1,2-6,9"). + What: /sys/bus/platform/drivers/intel-m10bmc-secure/.../security/flash_count Date: June 2021 KernelVersion: 5.14
drivers/fpga/intel-m10-bmc-secure.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 11/12 fpga: m10bmc-sec: add max10 secure update functions
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the MAX10 BMC Secure Update driver to include the functions that enable secure updates of BMC images, FPGA images, etc.
--- drivers/fpga/intel-m10-bmc-secure.c | 310 +++++++++++++++++++++++++++- 1 file changed, 309 insertions(+), 1 deletion(-)
drivers/fpga/intel-m10-bmc-secure.c +309 -1
@@ -180,7 +180,315 @@ static const struct attribute_group *m10bmc_sec_attr_groups[] = { NULL, }; -static const struct fpga_sec_mgr_ops m10bmc_sops = { }; +static void log_error_regs (struct m10bmc_sec *sec,u32 doorbell) +{ +u32 auth_result; + +dev_err (sec->dev,"RSU error status: 0x%08x\n" , doorbell); + +if (!m10bmc_sys_read (sec->m10bmc,M10BMC_AUTH_RESULT , &auth_result)) +dev_err (sec->dev,"RSU auth result: 0x%08x\n" , auth_result); +} + +static enum fpga_sec_err rsu_check_idle (struct m10bmc_sec *sec) +{ +u32 doorbell; +int ret; + + ret =m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + +if (rsu_prog (doorbell) !=RSU_PROG_IDLE && +rsu_prog (doorbell) !=RSU_PROG_RSU_DONE ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_BUSY ; + } + +return FPGA_SEC_ERR_NONE ; +} + +static inline bool rsu_start_done (u32 doorbell) +{ +u32 status, progress; + +if (doorbell &DRBL_RSU_REQUEST ) +return false; + + status =rsu_stat (doorbell); +if (status ==RSU_STAT_ERASE_FAIL || status ==RSU_STAT_WEAROUT ) +return true; + + progress =rsu_prog (doorbell); +if (progress !=RSU_PROG_IDLE && progress !=RSU_PROG_RSU_DONE ) +return true; + +return false; +} + +static enum fpga_sec_err rsu_update_init (struct m10bmc_sec *sec) +{ +u32 doorbell, status; +int ret; + + ret =regmap_update_bits (sec->m10bmc->regmap, +M10BMC_SYS_BASE +M10BMC_DOORBELL , +DRBL_RSU_REQUEST |DRBL_HOST_STATUS , +DRBL_RSU_REQUEST | +FIELD_PREP (DRBL_HOST_STATUS , +HOST_STATUS_IDLE )); +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + + ret =regmap_read_poll_timeout (sec->m10bmc->regmap, +M10BMC_SYS_BASE +M10BMC_DOORBELL , + doorbell, +rsu_start_done (doorbell), +NIOS_HANDSHAKE_INTERVAL_US , +NIOS_HANDSHAKE_TIMEOUT_US ); + +if (ret == -ETIMEDOUT ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_TIMEOUT ; + }else if (ret) { +return FPGA_SEC_ERR_RW_ERROR ; + } + + status =rsu_stat (doorbell); +if (status ==RSU_STAT_WEAROUT ) { +dev_warn (sec->dev,"Excessive flash update count detected\n" ); +return FPGA_SEC_ERR_WEAROUT ; + }else if (status ==RSU_STAT_ERASE_FAIL ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_HW_ERROR ; + } + +return FPGA_SEC_ERR_NONE ; +} + +static enum fpga_sec_err rsu_prog_ready (struct m10bmc_sec *sec) +{ +unsigned long poll_timeout; +u32 doorbell, progress; +int ret; + + ret =m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + + poll_timeout = jiffies +msecs_to_jiffies (RSU_PREP_TIMEOUT_MS ); +while (rsu_prog (doorbell) ==RSU_PROG_PREPARE ) { +msleep (RSU_PREP_INTERVAL_MS ); +if (time_after (jiffies, poll_timeout)) +break ; + + ret =m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + } + + progress =rsu_prog (doorbell); +if (progress ==RSU_PROG_PREPARE ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_TIMEOUT ; + }else if (progress !=RSU_PROG_READY ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_HW_ERROR ; + } + +return FPGA_SEC_ERR_NONE ; +} + +static enum fpga_sec_err rsu_send_data (struct m10bmc_sec *sec) +{ +u32 doorbell; +int ret; + + ret =regmap_update_bits (sec->m10bmc->regmap, +M10BMC_SYS_BASE +M10BMC_DOORBELL , +DRBL_HOST_STATUS , +FIELD_PREP (DRBL_HOST_STATUS , +HOST_STATUS_WRITE_DONE )); +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + + ret =regmap_read_poll_timeout (sec->m10bmc->regmap, +M10BMC_SYS_BASE +M10BMC_DOORBELL , + doorbell, +rsu_prog (doorbell) !=RSU_PROG_READY , +NIOS_HANDSHAKE_INTERVAL_US , +NIOS_HANDSHAKE_TIMEOUT_US ); + +if (ret == -ETIMEDOUT ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_TIMEOUT ; + }else if (ret) { +return FPGA_SEC_ERR_RW_ERROR ; + } + +switch (rsu_stat (doorbell)) { +case RSU_STAT_NORMAL : +case RSU_STAT_NIOS_OK : +case RSU_STAT_USER_OK : +case RSU_STAT_FACTORY_OK : +break ; +default : +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_HW_ERROR ; + } + +return FPGA_SEC_ERR_NONE ; +} + +static int rsu_check_complete (struct m10bmc_sec *sec,u32 *doorbell) +{ +if (m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , doorbell)) +return -EIO ; + +switch (rsu_stat (*doorbell)) { +case RSU_STAT_NORMAL : +case RSU_STAT_NIOS_OK : +case RSU_STAT_USER_OK : +case RSU_STAT_FACTORY_OK : +break ; +default : +return -EINVAL ; + } + +switch (rsu_prog (*doorbell)) { +case RSU_PROG_IDLE : +case RSU_PROG_RSU_DONE : +return 0 ; +case RSU_PROG_AUTHENTICATING : +case RSU_PROG_COPYING : +case RSU_PROG_UPDATE_CANCEL : +case RSU_PROG_PROGRAM_KEY_HASH : +return -EAGAIN ; +default : +return -EINVAL ; + } +} + +static enum fpga_sec_err m10bmc_sec_prepare (struct fpga_sec_mgr *smgr) +{ +struct m10bmc_sec *sec = smgr->priv; +enum fpga_sec_err ret; + +if (smgr->remaining_size >M10BMC_STAGING_SIZE ) +return FPGA_SEC_ERR_INVALID_SIZE ; + + ret =rsu_check_idle (sec); +if (ret !=FPGA_SEC_ERR_NONE ) +return ret; + + ret =rsu_update_init (sec); +if (ret !=FPGA_SEC_ERR_NONE ) +return ret; + +return rsu_prog_ready (sec); +} + +#define WRITE_BLOCK_SIZE 0x4000/* Update remaining_size every 0x4000 bytes */ + +static enum fpga_sec_err +m10bmc_sec_write_blk (struct fpga_sec_mgr *smgr,u32 offset) +{ +struct m10bmc_sec *sec = smgr->priv; +unsigned int stride =regmap_get_reg_stride (sec->m10bmc->regmap); +u32 doorbell, blk_size; +int ret; + + ret =m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +if (ret) { +return FPGA_SEC_ERR_RW_ERROR ; + }else if (rsu_prog (doorbell) !=RSU_PROG_READY ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_HW_ERROR ; + } + + blk_size =min_t (u32, smgr->remaining_size,WRITE_BLOCK_SIZE ); + ret =regmap_bulk_write (sec->m10bmc->regmap, +M10BMC_STAGING_BASE + offset, + (void *)smgr->data + offset, + (blk_size + stride -1 ) / stride); + +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + + smgr->remaining_size -= blk_size; +return FPGA_SEC_ERR_NONE ; +} + +/* +* m10bmc_sec_poll_complete() is called after handing things off to +* the BMC firmware. Depending on the type of update, it could be +* 30+ minutes before the BMC firmware completes the update. The +* smgr->driver_unload check allows the driver to be unloaded, +* but the BMC firmware will continue the update and no further +* secure updates can be started for this device until the update +* is complete. +*/ +static enum fpga_sec_err m10bmc_sec_poll_complete (struct fpga_sec_mgr *smgr) +{ +struct m10bmc_sec *sec = smgr->priv; +unsigned long poll_timeout; +enum fpga_sec_err result; +u32 doorbell; +int ret; + + result =rsu_send_data (sec); +if (result !=FPGA_SEC_ERR_NONE ) +return result; + + poll_timeout = jiffies +msecs_to_jiffies (RSU_COMPLETE_TIMEOUT_MS ); +do { +msleep (RSU_COMPLETE_INTERVAL_MS ); + ret =rsu_check_complete (sec, &doorbell); +if (smgr->driver_unload) +return FPGA_SEC_ERR_CANCELED ; + }while (ret == -EAGAIN && !time_after (jiffies, poll_timeout)); + +if (ret == -EAGAIN ) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_TIMEOUT ; + }else if (ret == -EIO ) { +return FPGA_SEC_ERR_RW_ERROR ; + }else if (ret) { +log_error_regs (sec, doorbell); +return FPGA_SEC_ERR_HW_ERROR ; + } + +return FPGA_SEC_ERR_NONE ; +} + +static enum fpga_sec_err m10bmc_sec_cancel (struct fpga_sec_mgr *smgr) +{ +struct m10bmc_sec *sec = smgr->priv; +u32 doorbell; +int ret; + + ret =m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +if (ret) +return FPGA_SEC_ERR_RW_ERROR ; + +if (rsu_prog (doorbell) !=RSU_PROG_READY ) +return FPGA_SEC_ERR_BUSY ; + + ret =regmap_update_bits (sec->m10bmc->regmap, +M10BMC_SYS_BASE +M10BMC_DOORBELL , +DRBL_HOST_STATUS , +FIELD_PREP (DRBL_HOST_STATUS , +HOST_STATUS_ABORT_RSU )); + +return ret ?FPGA_SEC_ERR_RW_ERROR :FPGA_SEC_ERR_NONE ; +} + +static const struct fpga_sec_mgr_ops m10bmc_sops = { + .prepare = m10bmc_sec_prepare, + .write_blk = m10bmc_sec_write_blk, + .poll_complete = m10bmc_sec_poll_complete, + .cancel = m10bmc_sec_cancel, +};static int m10bmc_secure_probe (struct platform_device *pdev) {
Signature · 1 line
2.31.1
Moritz Fischer
maintainerPATCH 12/12 fpga: m10bmc-sec: add max10 get_hw_errinfo callback func
In reply to Moritz FischerFrom: Russ Weight <[email protected]>
Extend the MAX10 BMC Secure Update driver to include a function that returns 64 bits of additional HW specific data for errors that require additional information. This callback function enables the hw_errinfo sysfs node in the Intel Security Manager class driver.
--- drivers/fpga/intel-m10-bmc-secure.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/fpga/intel-m10-bmc-secure.c +22 -0
@@ -483,11 +483,33 @@ static enum fpga_sec_err m10bmc_sec_cancel(struct fpga_sec_mgr *smgr)return ret ?FPGA_SEC_ERR_RW_ERROR :FPGA_SEC_ERR_NONE ; } +#define HW_ERRINFO_POISON GENMASK(31, 0) +static u64 m10bmc_sec_hw_errinfo (struct fpga_sec_mgr *smgr) +{ +struct m10bmc_sec *sec = smgr->priv; +u32 auth_result =HW_ERRINFO_POISON ; +u32 doorbell =HW_ERRINFO_POISON ; + +switch (smgr->err_code) { +case FPGA_SEC_ERR_HW_ERROR : +case FPGA_SEC_ERR_TIMEOUT : +case FPGA_SEC_ERR_BUSY : +case FPGA_SEC_ERR_WEAROUT : +m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +m10bmc_sys_read (sec->m10bmc,M10BMC_AUTH_RESULT , &auth_result); + +return (u64 )doorbell <<32 | (u64 )auth_result; +default : +return 0 ; + } +} +static const struct fpga_sec_mgr_ops m10bmc_sops = { .prepare = m10bmc_sec_prepare, .write_blk = m10bmc_sec_write_blk, .poll_complete = m10bmc_sec_poll_complete, .cancel = m10bmc_sec_cancel, + .get_hw_errinfo = m10bmc_sec_hw_errinfo, };static int m10bmc_secure_probe (struct platform_device *pdev)
Signature · 1 line
2.31.1