FPGA Security Manager Class Driver
Subsystems (2)
v6 cover FPGA Security Manager Class Driver
The FPGA Security Manager class driver provides a common API for user-space tools to manage updates for secure FPGA devices. Device drivers that instantiate the FPGA Security Manager class driver will interact with a HW secure update engine in order to transfer new FPGA and BMC images to FLASH so that they will be automatically loaded when the FPGA card reboots.
A significant difference between the FPGA Manager and the FPGA Security Manager is that the FPGA Manager does a live update (Partial Reconfiguration) to a device whereas the FPGA Security Manager updates the FLASH images for the Static Region and the BMC so that they will be loaded the next time the FPGA card boots. Security is enforced by hardware and firmware. The security manager interacts with the firmware to initiate an update, pass in the necessary data, and collect status on the update.
The n3000bmc-secure driver is the first driver to use the FPGA Security Manager. This driver was previously submitted in the same patch set, but has been split out into a separate patch set starting with V2. Future devices will also make use of this common API for secure updates.
In addition to managing secure updates of the FPGA and BMC images, the FPGA Security Manager update process may also be used to program root entry hashes and cancellation keys for the FPGA static region, the FPGA partial reconfiguration region, and the BMC. The image files are self-describing, and contain a header describing the image type.
Secure updates make use of the request_firmware framework, which requires that image files are accessible under /lib/firmware. A request for a secure update returns immediately, while the update itself proceeds in the context of a kernel worker thread. Sysfs files provide a means for monitoring the progress of a secure update and for retrieving error information in the event of a failure.
The API includes a "name" sysfs file to export the name of the parent driver. It also includes an "update" sub-directory containing files that that can be used to instantiate and monitor a secure update.
Changelog v5 -> v6:
- Removed sysfs support and documentation for the display of the flash count, root entry hashes, and code-signing-key cancelation vectors from the class driver. This information can vary by device and will instead be displayed by the device-specific parent driver.
Changelog v4 -> v5:
- Added the devm_fpga_sec_mgr_unregister() function, following recent changes to the fpga_manager() implementation.
- Changed most of the *_show() functions to use sysfs_emit()
instead of sprintf(
- When checking the return values for functions of type enum fpga_sec_err err_code, test for FPGA_SEC_ERR_NONE instead of 0
Changelog v3 -> v4:
- This driver is generic enough that it could be used for non Intel FPGA devices. Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_ Note that this also affects some filenames.
Changelog v2 -> v3:
- Use dev_err() to report invalid progress in sec_progress()
- Use dev_err() to report invalid error code in sec_error()
- Modified sysfs handler check in check_sysfs_handler() to make it more readable.
- Removed unnecessary "goto done"
- Added a comment to explain imgr->driver_unload in ifpga_sec_mgr_unregister()
Changelog v1 -> v2:
- Separated out the MAX10 BMC Security Engine to be submitted in a separate patch-set.
- Bumped documentation dates and versions
- Split ifpga_sec_mgr_register() into create() and register() functions
- Added devm_ifpga_sec_mgr_create()
- Added Documentation/fpga/ifpga-sec-mgr.rst
- Changed progress state "read_file" to "reading"
- Added sec_error() function (similar to sec_progress())
- Removed references to bmc_flash_count & smbus_flash_count (not supported)
- Removed typedefs for imgr ops
- Removed explicit value assignments in enums
- Other minor code cleanup per review comments
Russ Weight (7):
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
.../ABI/testing/sysfs-class-fpga-sec-mgr | 81 +++ 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 | 652 ++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 100 +++ 8 files changed, 899 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
Signature · 1 line
2.25.1
PATCH v6 1/7 fpga: sec-mgr: fpga security manager class driver
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.
---
v6:
- Removed sysfs support and documentation for the display of the flash count, root entry hashes, and code-signing-key cancelation vectors.
v5:
- Added the devm_fpga_sec_mgr_unregister() function, following recent changes to the fpga_manager() implementation.
- Changed some *_show() functions to use sysfs_emit() instead of sprintf(
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_
v3:
- Modified sysfs handler check in check_sysfs_handler() to make it more readable.
v2:
- Bumped documentation dates and versions
- Added Documentation/fpga/ifpga-sec-mgr.rst
- Removed references to bmc_flash_count & smbus_flash_count (not supported)
- Split ifpga_sec_mgr_register() into create() and register() functions
- Added devm_ifpga_sec_mgr_create()
- Removed typedefs for imgr ops
--- .../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: Oct 2020 +KernelVersion: 5.11 +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
@@ -6919,6 +6919,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
@@ -215,4 +215,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.25.1
Moritz Fischer
maintainerRe: [PATCH v6 1/7] fpga: sec-mgr: fpga security manager class driver
Hi Russ,
Quoted 76 lines · Russ Weight
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]>Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v6:
- Removed sysfs support and documentation for the display of the flash count, root entry hashes, and code-signing-key cancelation vectors.
v5:
- Added thedevm_fpga_sec_mgr_unregister()function, following recent changes to thefpga_manager()implementation.
- Changed some*_show()functions to usesysfs_emit()instead of sprintf(
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr,IFPGA_->FPGA_,ifpga_tofpga_
v3:
- Modified sysfs handler check incheck_sysfs_handler()to make it more readable.
v2:
- Bumped documentation dates and versions
- AddedDocumentation/fpga/ifpga-sec-mgr.rst
- Removed references tobmc_flash_count&smbus_flash_count(not supported)
- Splitifpga_sec_mgr_register()intocreate()andregister()functions
- Addeddevm_ifpga_sec_mgr_create()
- Removed typedefs for imgr ops--- .../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.hDocumentation/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: Oct 2020 +KernelVersion: 5.11 +Contact: Russ Weight <[email protected]> +Description: Name of low level fpga security manager driver.Documentation/fpga/fpga-sec-mgr.rst new file +11
-0@@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================================== +FPGA Security Manager Class Driver +======================================== + +The FPGA Security Manager class driver provides a common +API for user-space tools to manage updates for secure FPGA +devices. Device drivers that instantiate the Security +Manager class driver will interact with a HW secure update +engine in order to transfer new FPGA and BMC images to FLASH so
Documentation/fpga/fpga-sec-mgr.rst line 21
Quoted 10 lines
Documentation/fpga/fpga-sec-mgr.rst new file +10
-0+that they will be automatically loaded when the FPGA card reboots. + +A significant difference between the FPGA Manager and the FPGA +Security Manager is that the FPGA Manager does a live update (Partial +Reconfiguration) to a device, whereas the FPGA Security Manager +updates the FLASH images for the Static Region and the BMC so that +they will be loaded the next time the FPGA card boots. Security is +enforced by hardware and firmware. The security manager interacts +with the firmware to initiate an update, pass in the necessary data, +and collect status on the update.
I've always wondered if we could've made this a functionality of an FPGA manager 'non-volatile' node or something.
I guess there might be cases where you can only do either of them, i.e. only update flash or only update at runtime.
Quoted 442 lines
Documentation/fpga/fpga-sec-mgr.rst new file +23
-0+ +In addition to managing secure updates of the FPGA and BMC images, +the FPGA Security Manager update process may also used to +program root entry hashes and cancellation keys for the FPGA static +region, the FPGA partial reconfiguration region, and the BMC. + +Secure updates make use of the request_firmware framework, which +requires that image files are accessible under /lib/firmware. A request +for a secure update returns immediately, while the update itself +proceeds in the context of a kernel worker thread. Sysfs files provide +a means for monitoring the progress of a secure update and for +retrieving error information in the event of a failure. + +Sysfs Attributes +================ + +The API includes a sysfs entry *name* to export the name of the parent +driver. It also includes an *update* sub-directory that can be used to +instantiate and monitor a secure update. + +See `<../ABI/testing/sysfs-class-fpga-sec-mgr>`__ for a full +description of the sysfs attributes for the FPGA Security +Manager.Documentation/fpga/index.rst +1
-0@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + fpga-sec-mgr .. only:: subproject and htmlMAINTAINERS +9
-0@@ -6919,6 +6919,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: Maintaineddrivers/fpga/Kconfig +9
-0@@ -215,4 +215,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 # FPGAdrivers/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.odrivers/fpga/fpga-sec-mgr.c new file +296
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. +*/ + +#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) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name); + +static struct attribute *sec_mgr_attrs[] = { + &dev_attr_name.attr, +NULL , +}; + +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 , +}; + +/** +* 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 +* 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, +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 ; + } + + smgr =kzalloc (sizeof (*smgr),GFP_KERNEL ); +if (!smgr) +return NULL ; + + id =ida_simple_get (&fpga_sec_mgr_ida,0 ,0 ,GFP_KERNEL ); +if (id <0 ) + goto error_kfree; + +mutex_init (&smgr->lock); + + 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); +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); + +error_kfree: +kfree (smgr); + +return NULL ; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_create); + +/** +* 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); + +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; + + ret =device_add (&smgr->dev); +if (ret) + goto error_device; + +dev_info (&smgr->dev,"%s registered\n" , smgr->name); + +return 0 ; + +error_device: +ida_simple_remove (&fpga_sec_mgr_ida, smgr->dev.id); + +return ret; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_register); + +/** +* 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); + +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; + } + + 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) +{ +} + +static int __init fpga_sec_mgr_class_init (void ) +{ +pr_info ("FPGA Security Manager\n" ); + + fpga_sec_mgr_class =class_create (THIS_MODULE ,"fpga_sec_mgr" ); +if (IS_ERR (fpga_sec_mgr_class)) +return PTR_ERR (fpga_sec_mgr_class); + + fpga_sec_mgr_class->dev_groups = fpga_sec_mgr_attr_groups; + fpga_sec_mgr_class->dev_release = fpga_sec_mgr_dev_release; + +return 0 ; +} + +static void __exit fpga_sec_mgr_class_exit(void) +{ +class_destroy (fpga_sec_mgr_class); +ida_destroy (&fpga_sec_mgr_ida); +} + +MODULE_DESCRIPTION ("FPGA Security Manager Driver" ); +MODULE_LICENSE ("GPL v2" ); + +subsys_initcall (fpga_sec_mgr_class_init); +module_exit (fpga_sec_mgr_class_exit)include/linux/fpga/fpga-sec-mgr.h new file +44
-0@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. +*/ +#ifndef _LINUX_FPGA_SEC_MGR_H +#define _LINUX_FPGA_SEC_MGR_H + +#include <linux/device.h> +#include <linux/mutex.h> +#include <linux/types.h> + +struct fpga_sec_mgr ; + +/** +* struct fpga_sec_mgr_ops - device specific operations +*/ +struct fpga_sec_mgr_ops { +}; + +struct fpga_sec_mgr { +const char *name; +struct device dev; +const struct fpga_sec_mgr_ops *sops; +struct mutex lock;/* protect data structure contents */ +void *priv; +}; + +struct fpga_sec_mgr * +fpga_sec_mgr_create (struct device *dev,const char *name, +const struct fpga_sec_mgr_ops *sops,void *priv); + +struct fpga_sec_mgr * +devm_fpga_sec_mgr_create (struct device *dev,const char *name, +const struct fpga_sec_mgr_ops *sops,void *priv); + +int fpga_sec_mgr_register (struct fpga_sec_mgr *smgr); +int devm_fpga_sec_mgr_register (struct device *dev, +struct fpga_sec_mgr *smgr); +void fpga_sec_mgr_unregister (struct fpga_sec_mgr *smgr); +void fpga_sec_mgr_free (struct fpga_sec_mgr *smgr); + +#endif Signature · 1 line
2.25.1
Looks good to me otherwise, let me look at the rest of the series,
Moritz
Re: [PATCH v6 1/7] fpga: sec-mgr: fpga security manager class driver
Quoted 92 lines · Moritz Fischer
Hi Russ,
Quoted 76 lines · Russ Weight
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]>Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v6:
- Removed sysfs support and documentation for the display of the flash count, root entry hashes, and code-signing-key cancelation vectors.
v5:
- Added thedevm_fpga_sec_mgr_unregister()function, following recent changes to thefpga_manager()implementation.
- Changed some*_show()functions to usesysfs_emit()instead of sprintf(
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr,IFPGA_->FPGA_,ifpga_tofpga_
v3:
- Modified sysfs handler check incheck_sysfs_handler()to make it more readable.
v2:
- Bumped documentation dates and versions
- AddedDocumentation/fpga/ifpga-sec-mgr.rst
- Removed references tobmc_flash_count&smbus_flash_count(not supported)
- Splitifpga_sec_mgr_register()intocreate()andregister()functions
- Addeddevm_ifpga_sec_mgr_create()
- Removed typedefs for imgr ops--- .../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.hDocumentation/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: Oct 2020 +KernelVersion: 5.11 +Contact: Russ Weight <[email protected]> +Description: Name of low level fpga security manager driver.Documentation/fpga/fpga-sec-mgr.rst new file +11
-0@@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================================== +FPGA Security Manager Class Driver +======================================== + +The FPGA Security Manager class driver provides a common +API for user-space tools to manage updates for secure FPGA +devices. Device drivers that instantiate the Security +Manager class driver will interact with a HW secure update +engine in order to transfer new FPGA and BMC images to FLASH soDocumentation/fpga/fpga-sec-mgr.rst line 21
Quoted 10 lines
Documentation/fpga/fpga-sec-mgr.rst new file +10
-0+that they will be automatically loaded when the FPGA card reboots. + +A significant difference between the FPGA Manager and the FPGA +Security Manager is that the FPGA Manager does a live update (Partial +Reconfiguration) to a device, whereas the FPGA Security Manager +updates the FLASH images for the Static Region and the BMC so that +they will be loaded the next time the FPGA card boots. Security is +enforced by hardware and firmware. The security manager interacts +with the firmware to initiate an update, pass in the necessary data, +and collect status on the update.I've always wondered if we could've made this a functionality of an FPGA manager 'non-volatile' node or something.
Quoted 2 lines
I guess there might be cases where you can only do either of them, i.e. only update flash or only update at runtime.
Today, in light of Richard Gong's recent patch set, I took another look at the fpga manager, trying to determine what changes would need to be made in the fpga manager order to support secure updates. These are my observations:
(1) For the devices that I am working on, the lower-level drivers are completely different for PR vs image updates to flash. As a result, if we used the fpga-mgr, we would need to create different instances of the fpga-mgr, one for PR and one for secure updates - each supported by a different low-level driver.
(2) For secure updates, our worst case time is 40 minutes. I doubt that it will ever be longer than that, but we need to support that case. For this length of time, we feel that it is important to show some indication of progress to the user during the update. To handle this, we are using a write_blk() function to break up the writes so that the class driver can provide updates during the data transfer (e.g. this much is left to transfer). We have also "backgrounded" the kernel process by spawning a kernel worker thread to do the update. The user, or user-space code, can monitor the progress by polling for status through sysfs.
(3) Also, because of the long updates, it seems necessary to provide a way to cancel the update. For example, if the user accidentally specifies the wrong image file, 40 minutes is too long to wait before they are able to try again. We have provided a way to signal the worker thread to abort when possible.
(4) Another observation is that we are using the same secure update mechanism to program new root-entry-hashes and to cancel code-signing keys. The image type is encoded in the file header. The payload is opaque to host software, so this isn't an issue - just an observation.
So is it worth adding these additional features to the fpga-mgr? Or is it better to keep them separate? To me they seem different enough, that I think it would be cleaner to keep them separate.
Thanks,
- Russ
Quoted 446 lines
Quoted 443 lines
Documentation/fpga/fpga-sec-mgr.rst new file +23
-0+ +In addition to managing secure updates of the FPGA and BMC images, +the FPGA Security Manager update process may also used to +program root entry hashes and cancellation keys for the FPGA static +region, the FPGA partial reconfiguration region, and the BMC. + +Secure updates make use of the request_firmware framework, which +requires that image files are accessible under /lib/firmware. A request +for a secure update returns immediately, while the update itself +proceeds in the context of a kernel worker thread. Sysfs files provide +a means for monitoring the progress of a secure update and for +retrieving error information in the event of a failure. + +Sysfs Attributes +================ + +The API includes a sysfs entry *name* to export the name of the parent +driver. It also includes an *update* sub-directory that can be used to +instantiate and monitor a secure update. + +See `<../ABI/testing/sysfs-class-fpga-sec-mgr>`__ for a full +description of the sysfs attributes for the FPGA Security +Manager.Documentation/fpga/index.rst +1
-0@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + fpga-sec-mgr .. only:: subproject and htmlMAINTAINERS +9
-0@@ -6919,6 +6919,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: Maintaineddrivers/fpga/Kconfig +9
-0@@ -215,4 +215,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 # FPGAdrivers/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.odrivers/fpga/fpga-sec-mgr.c new file +296
-0@@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. +*/ + +#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) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); + +return sysfs_emit (buf,"%s\n" , smgr->name); +} +static DEVICE_ATTR_RO (name); + +static struct attribute *sec_mgr_attrs[] = { + &dev_attr_name.attr, +NULL , +}; + +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 , +}; + +/** +* 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 +* 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, +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 ; + } + + smgr =kzalloc (sizeof (*smgr),GFP_KERNEL ); +if (!smgr) +return NULL ; + + id =ida_simple_get (&fpga_sec_mgr_ida,0 ,0 ,GFP_KERNEL ); +if (id <0 ) + goto error_kfree; + +mutex_init (&smgr->lock); + + 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); +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); + +error_kfree: +kfree (smgr); + +return NULL ; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_create); + +/** +* 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); + +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; + + ret =device_add (&smgr->dev); +if (ret) + goto error_device; + +dev_info (&smgr->dev,"%s registered\n" , smgr->name); + +return 0 ; + +error_device: +ida_simple_remove (&fpga_sec_mgr_ida, smgr->dev.id); + +return ret; +} +EXPORT_SYMBOL_GPL (fpga_sec_mgr_register); + +/** +* 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); + +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; + } + + 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) +{ +} + +static int __init fpga_sec_mgr_class_init (void ) +{ +pr_info ("FPGA Security Manager\n" ); + + fpga_sec_mgr_class =class_create (THIS_MODULE ,"fpga_sec_mgr" ); +if (IS_ERR (fpga_sec_mgr_class)) +return PTR_ERR (fpga_sec_mgr_class); + + fpga_sec_mgr_class->dev_groups = fpga_sec_mgr_attr_groups; + fpga_sec_mgr_class->dev_release = fpga_sec_mgr_dev_release; + +return 0 ; +} + +static void __exit fpga_sec_mgr_class_exit(void) +{ +class_destroy (fpga_sec_mgr_class); +ida_destroy (&fpga_sec_mgr_ida); +} + +MODULE_DESCRIPTION ("FPGA Security Manager Driver" ); +MODULE_LICENSE ("GPL v2" ); + +subsys_initcall (fpga_sec_mgr_class_init); +module_exit (fpga_sec_mgr_class_exit)include/linux/fpga/fpga-sec-mgr.h new file +44
-0@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Security Manager +* +* Copyright (C) 2019-2020 Intel Corporation, Inc. +*/ +#ifndef _LINUX_FPGA_SEC_MGR_H +#define _LINUX_FPGA_SEC_MGR_H + +#include <linux/device.h> +#include <linux/mutex.h> +#include <linux/types.h> + +struct fpga_sec_mgr ; + +/** +* struct fpga_sec_mgr_ops - device specific operations +*/ +struct fpga_sec_mgr_ops { +}; + +struct fpga_sec_mgr { +const char *name; +struct device dev; +const struct fpga_sec_mgr_ops *sops; +struct mutex lock;/* protect data structure contents */ +void *priv; +}; + +struct fpga_sec_mgr * +fpga_sec_mgr_create (struct device *dev,const char *name, +const struct fpga_sec_mgr_ops *sops,void *priv); + +struct fpga_sec_mgr * +devm_fpga_sec_mgr_create (struct device *dev,const char *name, +const struct fpga_sec_mgr_ops *sops,void *priv); + +int fpga_sec_mgr_register (struct fpga_sec_mgr *smgr); +int devm_fpga_sec_mgr_register (struct device *dev, +struct fpga_sec_mgr *smgr); +void fpga_sec_mgr_unregister (struct fpga_sec_mgr *smgr); +void fpga_sec_mgr_free (struct fpga_sec_mgr *smgr); + +#endif Signature · 1 line
2.25.1Looks good to me otherwise, let me look at the rest of the series,
Moritz
Moritz Fischer
maintainerRe: [PATCH v6 1/7] fpga: sec-mgr: fpga security manager class driver
Hi Russ,
Quoted 102 lines · Russ Weight
Quoted 92 lines · Moritz Fischer
Hi Russ,
Quoted 76 lines · Russ Weight
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]>Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v6:
- Removed sysfs support and documentation for the display of the flash count, root entry hashes, and code-signing-key cancelation vectors.
v5:
- Added thedevm_fpga_sec_mgr_unregister()function, following recent changes to thefpga_manager()implementation.
- Changed some*_show()functions to usesysfs_emit()instead of sprintf(
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr,IFPGA_->FPGA_,ifpga_tofpga_
v3:
- Modified sysfs handler check incheck_sysfs_handler()to make it more readable.
v2:
- Bumped documentation dates and versions
- AddedDocumentation/fpga/ifpga-sec-mgr.rst
- Removed references tobmc_flash_count&smbus_flash_count(not supported)
- Splitifpga_sec_mgr_register()intocreate()andregister()functions
- Addeddevm_ifpga_sec_mgr_create()
- Removed typedefs for imgr ops--- .../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.hDocumentation/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: Oct 2020 +KernelVersion: 5.11 +Contact: Russ Weight <[email protected]> +Description: Name of low level fpga security manager driver.Documentation/fpga/fpga-sec-mgr.rst new file +11
-0@@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================================== +FPGA Security Manager Class Driver +======================================== + +The FPGA Security Manager class driver provides a common +API for user-space tools to manage updates for secure FPGA +devices. Device drivers that instantiate the Security +Manager class driver will interact with a HW secure update +engine in order to transfer new FPGA and BMC images to FLASH soDocumentation/fpga/fpga-sec-mgr.rst line 21
Quoted 10 lines
Documentation/fpga/fpga-sec-mgr.rst new file +10
-0+that they will be automatically loaded when the FPGA card reboots. + +A significant difference between the FPGA Manager and the FPGA +Security Manager is that the FPGA Manager does a live update (Partial +Reconfiguration) to a device, whereas the FPGA Security Manager +updates the FLASH images for the Static Region and the BMC so that +they will be loaded the next time the FPGA card boots. Security is +enforced by hardware and firmware. The security manager interacts +with the firmware to initiate an update, pass in the necessary data, +and collect status on the update.I've always wondered if we could've made this a functionality of an FPGA manager 'non-volatile' node or something.
Quoted 2 lines
I guess there might be cases where you can only do either of them, i.e. only update flash or only update at runtime.
Today, in light of Richard Gong's recent patch set, I took another look at the fpga manager, trying to determine what changes would need to be made in the fpga manager order to support secure updates. These are my observations:
Quoted 5 lines
(1) For the devices that I am working on, the lower-level drivers are completely different for PR vs image updates to flash. As a result, if we used the fpga-mgr, we would need to create different instances of the fpga-mgr, one for PR and one for secure updates - each supported by a different low-level driver.
I was mostly thinking about adding a somewhat similar API to the FPGA manager (close to what you're doing), but as I said it was a suggestion.
Quoted 18 lines
(2) For secure updates, our worst case time is 40 minutes. I doubt that it will ever be longer than that, but we need to support that case. For this length of time, we feel that it is important to show some indication of progress to the user during the update. To handle this, we are using a
write_blk()function to break up the writes so that the class driver can provide updates during the data transfer (e.g. this much is left to transfer). We have also "backgrounded" the kernel process by spawning a kernel worker thread to do the update. The user, or user-space code, can monitor the progress by polling for status through sysfs.(3) Also, because of the long updates, it seems necessary to provide a way to cancel the update. For example, if the user accidentally specifies the wrong image file, 40 minutes is too long to wait before they are able to try again. We have provided a way to signal the worker thread to abort when possible.
Quoted 8 lines
(4) Another observation is that we are using the same secure update mechanism to program new root-entry-hashes and to cancel code-signing keys. The image type is encoded in the file header. The payload is opaque to host software, so this isn't an issue - just an observation.
So is it worth adding these additional features to the fpga-mgr? Or is it better to keep them separate? To me they seem different enough, that I think it would be cleaner to keep them separate.
Yeah, I think that's fine. Thanks for taking another look, though.
Cheers,
Moritz
PATCH v6 2/7 fpga: sec-mgr: enable secure updates
In reply to Russ WeightExtend 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.
---
v6:
- Changed "security update" to "secure update" in commit message
v5:
- When checking the return values for functions of type enum fpga_sec_err err_code, test for FPGA_SEC_ERR_NONE instead of 0
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_
v3:
- Removed unnecessary "goto done"
- Added a comment to explain imgr->driver_unload in ifpga_sec_mgr_unregister()
v2:
- Bumped documentation date and version
- Removed explicit value assignments in enums
- Other minor code cleanup per review comments
--- .../ABI/testing/sysfs-class-fpga-sec-mgr | 13 ++ drivers/fpga/fpga-sec-mgr.c | 164 ++++++++++++++++++ include/linux/fpga/fpga-sec-mgr.h | 49 ++++++ 3 files changed, 226 insertions(+)
Documentation/ABI/testing/sysfs-class-fpga-sec-mgr +13 -0
@@ -3,3 +3,16 @@ Date: Oct 2020 KernelVersion: 5.11 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: Oct 2020 +KernelVersion: 5.11 +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 +164 -0
209 lines not on this page · raw message
include/linux/fpga/fpga-sec-mgr.h +49 -0
71 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v6 2/7] fpga: sec-mgr: enable secure updates
Hi Russ,
Just stumbled upon the below when preparing to upstream some Silicom changes
On 06/11/2020 02.09, Russ Weight wrote:
<snip>
Quoted 27 lines
include/linux/fpga/fpga-sec-mgr.h +13
-0@@ -7,16 +7,57 @@#ifndef _LINUX_FPGA_SEC_MGR_H#define _LINUX_FPGA_SEC_MGR_H +#include <linux/completion.h> #include <linux/device.h> #include <linux/mutex.h> #include <linux/types.h> struct fpga_sec_mgr ; +enum fpga_sec_err { +FPGA_SEC_ERR_NONE , +FPGA_SEC_ERR_HW_ERROR , +FPGA_SEC_ERR_TIMEOUT , +FPGA_SEC_ERR_CANCELED , +FPGA_SEC_ERR_BUSY , +FPGA_SEC_ERR_INVALID_SIZE , +FPGA_SEC_ERR_RW_ERROR , +FPGA_SEC_ERR_WEAROUT , +FPGA_SEC_ERR_FILE_READ , +FPGA_SEC_ERR_MAX +};
<snip>
include/linux/fpga/fpga-sec-mgr.h line 61
Quoted 10 lines
include/linux/fpga/fpga-sec-mgr.h +9
-0+ +/* Update progress codes */ +enum fpga_sec_prog { +FPGA_SEC_PROG_IDLE , +FPGA_SEC_PROG_READING , +FPGA_SEC_PROG_PREPARING , +FPGA_SEC_PROG_WRITING , +FPGA_SEC_PROG_PROGRAMMING , +FPGA_SEC_PROG_MAX };
Shouldn't this enum and the fpga_sec_err above be indexed starting from 0, to make comparison with FPGA_SEC_ERR_MAX and
FPGA_SEC_PROG_MAX correct?
// Martin
Re: [PATCH v6 2/7] fpga: sec-mgr: enable secure updates
In reply to Russ WeightHi Russ,
I found another thing while testing this...
On 06/11/2020 02.09, Russ Weight wrote:
<snip>
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c +6
-0+static ssize_t filename_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct fpga_sec_mgr *smgr =to_sec_mgr (dev); +int ret = count; +
drivers/fpga/fpga-sec-mgr.c struct fpga_sec_mgr_devres { · line 131
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c +10
-0+if (count ==0 || count >=PATH_MAX ) +return -EINVAL ; + +mutex_lock (&smgr->lock); +if (smgr->driver_unload || smgr->progress !=FPGA_SEC_PROG_IDLE ) { + ret = -EBUSY ; + goto unlock_exit; + } + + smgr->filename =kstrndup (buf, count -1 ,GFP_KERNEL );
The count - 1 is meant to remove a trailing newline, but opae-sdk writes the filename without newline, so better do it conditionally...
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c +10
-0+if (!smgr->filename) { + ret = -ENOMEM ; + goto unlock_exit; + } + + smgr->err_code =FPGA_SEC_ERR_NONE ; + smgr->progress =FPGA_SEC_PROG_READING ; +reinit_completion (&smgr->update_done); +schedule_work (&smgr->work); +
drivers/fpga/fpga-sec-mgr.c struct fpga_sec_mgr_devres { · line 151
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c +10
-0+unlock_exit: +mutex_unlock (&smgr->lock); +return ret; +} +static DEVICE_ATTR_WO (filename); + +static struct attribute *sec_mgr_update_attrs[] = { + &dev_attr_filename.attr, +NULL , +};
Thanks,
Martin
Re: [PATCH v6 2/7] fpga: sec-mgr: enable secure updates
Thanks Martin. I'll work on a fix for this.
- Russ
Quoted 50 lines · Martin Hundebøll
Hi Russ,
I found another thing while testing this...
On 06/11/2020 02.09, Russ Weight wrote:
<snip>
Quoted 6 lines
drivers/fpga/fpga-sec-mgr.c +6
-0+static ssize_t filename_store (struct device *dev,struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + int ret = count; +drivers/fpga/fpga-sec-mgr.c struct fpga_sec_mgr_devres { · line 131
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c +10
-0+ if (count == 0 || count >= PATH_MAX) + return -EINVAL; + + mutex_lock(&smgr->lock); + if (smgr->driver_unload || smgr->progress != FPGA_SEC_PROG_IDLE) { + ret = -EBUSY; + goto unlock_exit; + } + + smgr->filename = kstrndup(buf, count - 1, GFP_KERNEL);The
count - 1is meant to remove a trailing newline, but opae-sdk writes the filename without newline, so better do it conditionally...Quoted 10 lines
+ if (!smgr->filename) {
+ ret =-ENOMEM;
+ gotounlock_exit;
+ }drivers/fpga/fpga-sec-mgr.c +6
-0+ + smgr->err_code = FPGA_SEC_ERR_NONE; + smgr->progress = FPGA_SEC_PROG_READING; + reinit_completion(&smgr->update_done); + schedule_work(&smgr->work); +drivers/fpga/fpga-sec-mgr.c struct fpga_sec_mgr_devres { · line 151
Quoted 10 lines
drivers/fpga/fpga-sec-mgr.c +10
-0+unlock_exit: + mutex_unlock(&smgr->lock); + return ret; +} +static DEVICE_ATTR_WO (filename); + +static struct attribute *sec_mgr_update_attrs[] = { + &dev_attr_filename.attr, + NULL, +};Thanks,
Martin
Re: [PATCH v6 2/7] fpga: sec-mgr: enable secure updates
Hi Russ,
Quoted 1 line · Russ Weight
Thanks Martin. I'll work on a fix for this.
Attached is my in-house fix.
// Martin
Quoted 43 lines · Martin Hundebøll
Quoted 42 lines
Hi Russ,
I found another thing while testing this...
On 06/11/2020 02.09, Russ Weight wrote:
<snip>
Quoted 6 lines
(quoted diff) +6
-0+static ssize_t filename_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + int ret = count; +Review
Quoted 10 lines
(quoted diff) +10
-0+ if (count == 0 || count >= PATH_MAX) + return -EINVAL; + + mutex_lock(&smgr->lock); + if (smgr->driver_unload || smgr->progress != FPGA_SEC_PROG_IDLE) { + ret = -EBUSY; + goto unlock_exit; + } + + smgr->filename = kstrndup(buf, count - 1, GFP_KERNEL);The
count - 1is meant to remove a trailing newline, but opae-sdk writes the filename without newline, so better do it conditionally...Quoted 15 lines
+ if (!smgr->filename) {
+ ret =-ENOMEM;
+ gotounlock_exit;
+ }(quoted diff) +11
-0+ + smgr->err_code = FPGA_SEC_ERR_NONE; + smgr->progress = FPGA_SEC_PROG_READING; + reinit_completion(&smgr->update_done); + schedule_work(&smgr->work); + +unlock_exit: + mutex_unlock(&smgr->lock); + return ret; +} +static DEVICE_ATTR_WO(filename);
Quoted 9 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ +static struct attribute *sec_mgr_update_attrs[] = { + &dev_attr_filename.attr, + NULL, +};Thanks,
Martin
From 23113231c7819b2e99854cac1ec4370b06db442c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= <[email protected]>
Date: Thu, 26 Nov 2020 14:19:51 +0100
Subject: [PATCH] fpga: fpga-sec-mgr: handle trailing newline in filename_store
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The copying of the filename written to the sysfs unconditionally remove the last character, as (I assume) if it were a newline char. For the most cases this is true (e.g. when using echo in the shell), but some software writes the filename without a trailing newline, in which the firmware load obviously fails.
Fix this by checking for a newline char, and replacing it with '\0' if found.
--- drivers/fpga/fpga-sec-mgr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/fpga/fpga-sec-mgr.c +5 -1
@@ -423,12 +423,16 @@ static ssize_t filename_store(struct device *dev, struct device_attribute *attr, goto unlock_exit; } - smgr->filename =kstrndup (buf, count -1 ,GFP_KERNEL ); + smgr->filename =kstrndup (buf, count,GFP_KERNEL );if (!smgr->filename) { ret = -ENOMEM ; goto unlock_exit; } +/* remove trailing newline */ +if (smgr->filename[count -1 ] =='\n' ) + smgr->filename[count -1 ] ='\0' ; + smgr->err_code =FPGA_SEC_ERR_NONE ; smgr->hw_errinfo =0 ; smgr->request_cancel = false;
Signature · 1 line
2.29.2
Re: [PATCH v6 2/7] fpga: sec-mgr: enable secure updates
Quoted 36 lines · Martin Hundebøll
Hi Russ,
Quoted 1 line · Russ Weight
Thanks Martin. I'll work on a fix for this.
Attached is my in-house fix.
// Martin
Quoted 27 lines · Martin Hundebøll
Quoted 26 lines
Hi Russ,
I found another thing while testing this...
On 06/11/2020 02.09, Russ Weight wrote:
<snip>
Quoted 6 lines
(quoted diff) +6
-0+static ssize_t filename_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + int ret = count; +Review
Quoted 10 lines
(quoted diff) +10
-0+ if (count == 0 || count >= PATH_MAX) + return -EINVAL; + + mutex_lock(&smgr->lock); + if (smgr->driver_unload || smgr->progress != FPGA_SEC_PROG_IDLE) { + ret = -EBUSY; + goto unlock_exit; + } + + smgr->filename = kstrndup(buf, count - 1, GFP_KERNEL);The
count - 1is meant to remove a trailing newline, but opae-sdk writes the filename without newline, so better do it conditionally...
After looking at how kstrndup() is used elsewhere, and after doing some experimentation, I think the best fix may be to just remove the "- 1":
smgr->filename = kstrndup(buf, count, GFP_KERNEL);
The code shouldn't have assumed a "\n", and I don't think the kernel should be required to do white-space cleanup.
Does this fix seem OK to you?
- Russ
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 11 lines
+ if (!smgr->filename) {
+ ret =-ENOMEM;
+ gotounlock_exit;
+ }(quoted diff) +6
-0+ + smgr->err_code = FPGA_SEC_ERR_NONE; + smgr->progress = FPGA_SEC_PROG_READING; + reinit_completion(&smgr->update_done); + schedule_work(&smgr->work); +Review
Quoted 10 lines
(quoted diff) +10
-0+unlock_exit: + mutex_unlock(&smgr->lock); + return ret; +} +static DEVICE_ATTR_WO(filename); + +static struct attribute *sec_mgr_update_attrs[] = { + &dev_attr_filename.attr, + NULL, +};Thanks,
Martin
Re: [PATCH v6 2/7] fpga: sec-mgr: enable secure updates
Hi Russ,
Quoted 40 lines · Russ Weight
Quoted 34 lines · Martin Hundebøll
Hi Russ,
Quoted 1 line · Russ Weight
Thanks Martin. I'll work on a fix for this.
Attached is my in-house fix.
// Martin
Quoted 26 lines · Martin Hundebøll
Quoted 25 lines
Hi Russ,
I found another thing while testing this...
On 06/11/2020 02.09, Russ Weight wrote:
<snip>
Quoted 6 lines
(quoted diff) +6
-0+static ssize_t filename_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fpga_sec_mgr *smgr = to_sec_mgr(dev); + int ret = count; +Review
Quoted 10 lines
(quoted diff) +10
-0+ if (count == 0 || count >= PATH_MAX) + return -EINVAL; + + mutex_lock(&smgr->lock); + if (smgr->driver_unload || smgr->progress != FPGA_SEC_PROG_IDLE) { + ret = -EBUSY; + goto unlock_exit; + } + + smgr->filename = kstrndup(buf, count - 1, GFP_KERNEL);The
count - 1is meant to remove a trailing newline, but opae-sdk writes the filename without newline, so better do it conditionally...After looking at how
kstrndup()is used elsewhere, and after doing some experimentation, I think the best fix may be to just remove the "- 1":
Quoted 6 lines
smgr->filename=kstrndup(buf, count, GFP_KERNEL);The code shouldn't have assumed a "\n", and I don't think the kernel should be required to do white-space cleanup.
Does this fix seem OK to you?
Since we always use opae-sdk to write the filename, we wouldn't even notice.
While your'e at it, kerneldoc in mm/util.c suggests to use kmemdup_nul() when the size is known.
// Martin
PATCH v6 3/7 fpga: sec-mgr: expose sec-mgr update status
In reply to Russ WeightExtend 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.
---
v6:
- No change
v5:
- Use new function sysfs_emit() in the status_show() function
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_
v3:
- Use a local variable to read progress once in status_show()
- Use dev_err to report invalid progress status
v2:
- Bumped documentation date and version
- Changed progress state "read_file" to "reading"
--- .../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: Oct 2020 +KernelVersion: 5.11 +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.25.1
PATCH v6 4/7 fpga: sec-mgr: expose sec-mgr update errors
In reply to Russ WeightExtend 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.
---
v6:
- No change
v5:
- Use new function sysfs_emit() in the error_show() function
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_
v3:
- Use dev_err() for invalid error code in sec_error()
v2:
- Bumped documentation date and version
- Added warning to sec_progress() for invalid progress status
- Added sec_error() function (similar to sec_progress())
--- .../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: Oct 2020 +KernelVersion: 5.11 +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
@@ -71,6 +71,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.25.1
PATCH v6 5/7 fpga: sec-mgr: expose sec-mgr update size
In reply to Russ WeightExtend 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.
---
v6:
- No change
v5:
- Use new function sysfs_emit() in the remaining_size_show() function
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: imgr -> smgr, ifpga_ to fpga_
v3:
- No change
v2:
- Bumped documentation date and version
--- 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: Oct 2020 +KernelVersion: 5.11 +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: Oct 2020 KernelVersion: 5.11
drivers/fpga/fpga-sec-mgr.c +10 -0
@@ -204,6 +204,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) {
@@ -240,6 +249,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.25.1
PATCH v6 6/7 fpga: sec-mgr: enable cancel of secure update
In reply to Russ WeightExtend 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.
---
v6:
- No change
v5:
- No change
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_
v3:
- No change
v2:
- Bumped documentation date and version
- Minor code cleanup per review comments
--- .../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: Oct 2020 +KernelVersion: 5.11 +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: Oct 2020 KernelVersion: 5.11
drivers/fpga/fpga-sec-mgr.c +55 -4
104 lines not on this page · raw message
include/linux/fpga/fpga-sec-mgr.h +1 -0
@@ -73,6 +73,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.25.1
PATCH v6 7/7 fpga: sec-mgr: expose hardware error info
In reply to Russ WeightExtend 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.
---
v6:
- No change
v5:
- No change
v4:
- Changed from "Intel FPGA Security Manager" to FPGA Security Manager" and removed unnecessary references to "Intel".
- Changed: iops -> sops, imgr -> smgr, IFPGA_ -> FPGA_, ifpga_ to fpga_
v3:
- No change
v2:
- Bumped documentation date and version
--- .../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: Oct 2020 +KernelVersion: 5.11 +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
@@ -38,10 +38,17 @@ static void set_error(struct fpga_sec_mgr *smgr, enum fpga_sec_err err_code) smgr->err_code = err_code; } +static void 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) {set_error (smgr, err_code); +set_hw_errinfo (smgr); smgr->sops->cancel (smgr); }
@@ -227,6 +234,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) {
@@ -258,6 +282,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);
@@ -292,18 +317,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);
@@ -48,6 +51,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 */
@@ -73,6 +77,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.25.1