PCI/CMA and SPDM Library
Subsystems (4)
v2 cover PCI/CMA and SPDM Library
Changes since RFC V1:
- Rebase on top of v5.17-rc1.
- Note includes rebase of Ira's v6 DOE set - I haven't made any changes to respond to the review feedback on those patches, purely done a minimal rebase. Only included here to make this easy to try out.
Main purpose of this to provide a working starting point for others interested in alternative transports as I messed up the original v1 posting and unsuprisingly it needed a rebase.
NB: If using github.com/dmtf/spdm_emu : The current version of libspdm
that will checkout as a submodule has expired certificates which have been fixed in libspdm. To test this I regenerated a set using the instructions in the libspdm unit tests directory but hopefully that issue will be resolved soon anyway when they move their libspdm submodule forwards.
v1 Cover letter:
This is an RFC to start discussions about how we support the Component Measurement and Authentication (CMA) ECN (pcisig.com)
CMA provides an adaptation of the data objects and underlying protocol defined in the DMTF SPDM specification to be used to authenticate and conduct run-time measurements of the state of PCI devices (kind of like IMA for devices / firmware). This is done using a Data Object Exchange (DOE) protocol described in the ECN.
The CMA ECN is available from the PCI SIG and SPDM can be found at
https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.1.1.pdf
CMA/SPDM is focused on establishing trust of the device by:
1) Negotiate algorithms supported.
2) Retrieve and check the certificate chain from the device against a suitable signing certificate on the host.
3) Issue a challenge to the device to verify it can sign with the private key associated with the leaf certificate.
4) (Request a measurement of device state)
5) (Establish a secure channel for further measurements or other uses)
6) (Mutual authentication)
This RFC only does steps 1-3
Testing of this patch set has been conducted against QEMU emulation of the device backed by openSPDM emulation of the SPDM protocol.
https://lore.kernel.org/qemu-devel/[email protected]/
Open questions are called out in the individual patches but the big ones are probably:
1) Certificate management.
Current code uses a _cma keyring created by the kernel, into which a suitable root certificate can be inserted from userspace.
A=$(keyctl search %:_cma keyring _cma) evmctl import ecdsaca.cert.der $A
Is this an acceptable way to load the root certificates for this purpose?
The root of the device provided certificate chain is then checked against certificates on this keychain, but is itself (with the other certificates in the chain) loaded into an SPDM instance specific keychain. Currently there is no safe cleanup of this which will need to be fixed.
Using the keychain mechanism provides a very convenient way to manage these certificates and to allow userspace to read them for debug purpose etc, but is this the right use model?
Finally the leaf certificate of this chain is used to check signatures of the rest of the communications with the device.
2) ASNL1 encoder for ECDSA signature
It seems from the openSPDM implementation that for these signatures, the format is a simple pair of raw values. The kernel implementation of ECDSA signature verification assumes ASN1 encoding as seems to be used in x509 certificates. Currently I work around that by encoding the signatures so that the ECDSA code can un-encode them again and use them. This seems slightly silly, but it is minimum impact on current code. Other suggestions welcome.
3) Interface to present to drivers. Currently I'm providing just one exposed function that wraps up all the exhanges until a challenge authentication response from the device. This is done using one possible sequence. I don't think it makes sense to expose the low level components due to the underlying spdm_state updates and there only being a fixed set of valid orderings.
Future patches will raise questions around management of the measurements, but I'll leave those until I have some sort of implementation to shoot at. The 'on probe' use in the CXL driver is only one likely time when authentication would be needed.
Note I'm new to a bunch of the areas of the kernel this touches, so have probably done things that are totally wrong.
CC list is best effort to identify those who 'might' care. Please share with anyone I've missed.
Thanks,
Jonathan
Ira Weiny (7):
PCI: Replace magic constant for PCI Sig Vendor ID PCI/DOE: Introduce pci_doe_create_doe_devices cxl/pci: Create DOE auxiliary devices cxl/pci: Find the DOE mailbox which supports CDAT cxl/cdat: Introduce cdat_hdr_valid() cxl/mem: Retry reading CDAT on failure cxl/cdat: Parse out DSMAS data from CDAT table
Jonathan Cameron (7):
PCI: Add vendor ID for the PCI SIG
PCI/DOE: Add Data Object Exchange Aux Driver
cxl/mem: Read CDAT table
lib/asn1_encoder: Add a function to encode many byte integer values.
spdm: Introduce a library for DMTF SPDM
PCI/CMA: Initial support for Component Measurement and Authentication
ECN
cxl/pci: Add really basic CMA authentication support.
drivers/cxl/Kconfig | 2 + drivers/cxl/cdat.h | 120 ++++ drivers/cxl/core/memdev.c | 141 ++++ drivers/cxl/cxl.h | 3 + drivers/cxl/cxlmem.h | 29 + drivers/cxl/pci.c | 213 +++++- drivers/pci/Kconfig | 19 + drivers/pci/Makefile | 5 + drivers/pci/cma.c | 105 +++ drivers/pci/doe.c | 798 ++++++++++++++++++++++ drivers/pci/probe.c | 2 +- include/linux/asn1_encoder.h | 3 + include/linux/pci-cma.h | 19 + include/linux/pci-doe.h | 63 ++ include/linux/pci_ids.h | 1 + include/linux/spdm.h | 104 +++ include/uapi/linux/pci_regs.h | 29 +- lib/Kconfig | 3 + lib/Makefile | 2 + lib/asn1_encoder.c | 54 ++ lib/spdm.c | 1196 +++++++++++++++++++++++++++++++++ 21 files changed, 2908 insertions(+), 3 deletions(-) create mode 100644 drivers/cxl/cdat.h create mode 100644 drivers/pci/cma.c create mode 100644 drivers/pci/doe.c create mode 100644 include/linux/pci-cma.h create mode 100644 include/linux/pci-doe.h create mode 100644 include/linux/spdm.h create mode 100644 lib/spdm.c
Signature · 1 line
2.32.0
RFC PATCH v2 1/14 PCI: Add vendor ID for the PCI SIG
This ID is used in DOE headers to identify protocols that are defined within the PCI Express Base Specification.
Specified in Table 7-x2 of the Data Object Exchange ECN (approved 12 March 2020) available from https://members.pcisig.com/wg/PCI-SIG/document/14143
--- include/linux/pci_ids.h | 1 + 1 file changed, 1 insertion(+)
include/linux/pci_ids.h +1 -0
@@ -149,6 +149,7 @@#define PCI_CLASS_OTHERS 0xff/* Vendors and devices. Sort key: vendor first, device next. */ +#define PCI_VENDOR_ID_PCI_SIG 0x0001#define PCI_VENDOR_ID_LOONGSON 0x0014
Signature · 1 line
2.32.0
RFC PATCH v2 2/14 PCI: Replace magic constant for PCI Sig Vendor ID
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
Based on Bjorn's suggestion[1], now that the PCI Sig Vendor ID is defined the define should be used in pci_bus_crs_vendor_id() rather than the hard coded magic value.
Replace the magic value in pci_bus_crs_vendor_id() with PCI_VENDOR_ID_PCI_SIG.
[1] https://lore.kernel.org/linux-cxl/20211117215044.GA1777828@bhelgaas/
--- drivers/pci/probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/probe.c +1 -1
@@ -2312,7 +2312,7 @@ EXPORT_SYMBOL(pci_alloc_dev);static bool pci_bus_crs_vendor_id (u32 l) { -return (l &0xffff ) ==0x0001 ; +return (l &0xffff ) ==PCI_VENDOR_ID_PCI_SIG ; } static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l,
Signature · 1 line
2.32.0
RFC PATCH v2 3/14 PCI/DOE: Add Data Object Exchange Aux Driver
In reply to Jonathan CameronIntroduced in a PCI ECN [1], DOE provides a config space based mailbox with standard protocol discovery. Each mailbox is accessed through a DOE Extended Capability.
Define an auxiliary device driver which control DOE auxiliary devices registered on the auxiliary bus.
A DOE mailbox is allowed to support any number of protocols while some DOE protocol specifications apply additional restrictions.
The protocols supported are queried and cached. pci_doe_supports_prot() can be used to determine if the DOE device supports the protocol specified.
A synchronous interface is provided in pci_doe_exchange_sync() to perform a single query / response exchange from the driver through the device specified.
Testing was conducted against QEMU using:
https://lore.kernel.org/qemu-devel/[email protected]/
This code is based on Jonathan's V4 series here:
https://lore.kernel.org/linux-cxl/[email protected]/
[1] https://members.pcisig.com/wg/PCI-SIG/document/14143
Data Object Exchange (DOE) - Approved 12 March 2020
--- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 3 + drivers/pci/doe.c | 675 ++++++++++++++++++++++++++++++++++ include/linux/pci-doe.h | 60 +++ include/uapi/linux/pci_regs.h | 29 +- 5 files changed, 776 insertions(+), 1 deletion(-)
drivers/pci/Kconfig +10 -0
@@ -118,6 +118,16 @@ config XEN_PCIDEV_FRONTEND The PCI device frontend driver allows the kernel to import arbitrary PCI devices from a PCI backend to support PCI driver domains. +config PCI_DOE_DRIVER + tristate "PCI Data Object Exchange (DOE) driver" + select AUXILIARY_BUS + help + Driver for DOE auxiliary devices. + + DOE provides a simple mailbox in PCI config space that is used by a + number of different protocols. DOE is defined in the Data Object + Exchange ECN to the PCIe r5.0 spec. + config PCI_ATS bool
drivers/pci/Makefile +3 -0
@@ -29,8 +29,11 @@ obj-$(CONFIG_PCI_STUB) += pci-stub.o obj-$(CONFIG_PCI_PF_STUB) += pci-pf-stub.o obj-$(CONFIG_PCI_ECAM) += ecam.o obj-$(CONFIG_PCI_P2PDMA) += p2pdma.o +obj-$(CONFIG_PCI_DOE_DRIVER) += pci-doe.o obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o +pci-doe-y := doe.o + # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/
drivers/pci/doe.c new file +675 -0
675 lines not on this page · raw message
include/linux/pci-doe.h new file +60 -0
60 lines not on this page · raw message
include/uapi/linux/pci_regs.h +28 -1
@@ -736,7 +736,8 @@#define PCI_EXT_CAP_ID_DVSEC 0x23/* Designated Vendor-Specific */ #define PCI_EXT_CAP_ID_DLF 0x25/* Data Link Feature */ #define PCI_EXT_CAP_ID_PL_16GT 0x26/* Physical Layer 16.0 GT/s */ -#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PL_16GT +#define PCI_EXT_CAP_ID_DOE 0x2E/* Data Object Exchange */ +#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_DOE#define PCI_EXT_CAP_DSN_SIZEOF 12#define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
@@ -1102,4 +1103,30 @@#define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK 0x000000F0#define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT 4 +/* Data Object Exchange */ +#define PCI_DOE_CAP 0x04/* DOE Capabilities Register */ +#define PCI_DOE_CAP_INT 0x00000001/* Interrupt Support */ +#define PCI_DOE_CAP_IRQ 0x00000ffe/* Interrupt Message Number */ +#define PCI_DOE_CTRL 0x08/* DOE Control Register */ +#define PCI_DOE_CTRL_ABORT 0x00000001/* DOE Abort */ +#define PCI_DOE_CTRL_INT_EN 0x00000002/* DOE Interrupt Enable */ +#define PCI_DOE_CTRL_GO 0x80000000/* DOE Go */ +#define PCI_DOE_STATUS 0x0c/* DOE Status Register */ +#define PCI_DOE_STATUS_BUSY 0x00000001/* DOE Busy */ +#define PCI_DOE_STATUS_INT_STATUS 0x00000002/* DOE Interrupt Status */ +#define PCI_DOE_STATUS_ERROR 0x00000004/* DOE Error */ +#define PCI_DOE_STATUS_DATA_OBJECT_READY 0x80000000/* Data Object Ready */ +#define PCI_DOE_WRITE 0x10/* DOE Write Data Mailbox Register */ +#define PCI_DOE_READ 0x14/* DOE Read Data Mailbox Register */ + +/* DOE Data Object - note not actually registers */ +#define PCI_DOE_DATA_OBJECT_HEADER_1_VID 0x0000ffff +#define PCI_DOE_DATA_OBJECT_HEADER_1_TYPE 0x00ff0000 +#define PCI_DOE_DATA_OBJECT_HEADER_2_LENGTH 0x0003ffff + +#define PCI_DOE_DATA_OBJECT_DISC_REQ_3_INDEX 0x000000ff +#define PCI_DOE_DATA_OBJECT_DISC_RSP_3_VID 0x0000ffff +#define PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL 0x00ff0000 +#define PCI_DOE_DATA_OBJECT_DISC_RSP_3_NEXT_INDEX 0xff000000 +#endif /* LINUX_PCI_REGS_H */
Signature · 1 line
2.32.0
RFC PATCH v2 4/14 PCI/DOE: Introduce pci_doe_create_doe_devices
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
CXL and/or PCI devices can define DOE mailboxes. Normally the kernel will want to maintain control of all of these mailboxes. However, under a limited number of use cases users may want to allow user space access to some of these mailboxes while the kernel retains control of the rest. An example of this is for CXL Compliance Testing (see CXL 2.0 14.16.4 Compliance Mode DOE) which offers a mechanism to set different test modes for a device.
Rather than re-invent the wheel the architecture creates auxiliary devices for each DOE mailbox which can then be driven by a generic DOE mailbox driver. If access to an individual mailbox is required by user space the driver for that mailbox can be unloaded and access handed to user space.
Create the helper pci_doe_create_doe_devices() which iterates each DOE mailbox found in the device and creates a DOE auxiliary device on the auxiliary bus. While doing so ensure that the auxiliary DOE driver loads to drive that device.
--- drivers/pci/doe.c | 123 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-doe.h | 3 + 2 files changed, 126 insertions(+)
drivers/pci/doe.c +123 -0
@@ -383,6 +383,128 @@ static void pci_doe_task_complete(void *private)complete (private); } +static void pci_doe_free_irq_vectors (void *data) +{ +pci_free_irq_vectors (data); +} + +static DEFINE_IDA (pci_doe_adev_ida); + +static void pci_doe_dev_release (struct device *dev) +{ +struct auxiliary_device *adev =container_of (dev, + struct auxiliary_device, + dev); + struct pci_doe_dev *doe_dev = container_of(adev, struct pci_doe_dev, + adev); + +ida_free (&pci_doe_adev_ida, adev->id); +kfree (doe_dev); +} + +static void pci_doe_destroy_device (void *ad) +{ +auxiliary_device_delete (ad); +auxiliary_device_uninit (ad); +} + +/** +* pci_doe_create_doe_devices - Create auxiliary DOE devices for all DOE +* mailboxes found +* @pci_dev: The PCI device to scan for DOE mailboxes +* +* There is no coresponding destroy of these devices. This function associates +* the DOE auxiliary devices created with the pci_dev passed in. That +* association is device managed (devm_*) such that the DOE auxiliary device +* lifetime is always greater than or equal to the lifetime of the pci_dev. +* +* RETURNS: 0 on success -ERRNO on failure. +*/ +int pci_doe_create_doe_devices (struct pci_dev *pdev) +{ +struct device *dev = &pdev->dev; +int irqs, rc; +u16 pos =0 ; + +/* +* An implementation may support an unknown number of interrupts. +* Assume that number is not that large and request them all. +*/ + irqs =pci_msix_vec_count (pdev); + rc =pci_alloc_irq_vectors (pdev, irqs, irqs,PCI_IRQ_MSIX ); +if (rc != irqs) { +/* No interrupt available - carry on */ +pci_dbg (pdev,"No interrupts available for DOE\n" ); + }else { +/* +* Enabling bus mastering is require for MSI/MSIx. It could be +* done later within the DOE initialization, but as it +* potentially has other impacts keep it here when setting up +* the IRQ's. +*/ +pci_set_master (pdev); + rc =devm_add_action_or_reset (dev, + pci_doe_free_irq_vectors, + pdev); +if (rc) +return rc; + } + + pos =pci_find_next_ext_capability (pdev, pos,PCI_EXT_CAP_ID_DOE ); + +while (pos >0 ) { +struct auxiliary_device *adev; +struct pci_doe_dev *new_dev; +int id; + + new_dev =kzalloc (sizeof (*new_dev),GFP_KERNEL ); +if (!new_dev) +return -ENOMEM ; + + new_dev->pdev = pdev; + new_dev->cap_offset = pos; + +/* Set up struct auxiliary_device */ + adev = &new_dev->adev; + id =ida_alloc (&pci_doe_adev_ida,GFP_KERNEL ); +if (id <0 ) { +kfree (new_dev); +return -ENOMEM ; + } + + adev->id = id; + adev->name =DOE_DEV_NAME ; + adev->dev.release = pci_doe_dev_release; + adev->dev.parent = dev; + +if (auxiliary_device_init (adev)) { +pci_doe_dev_release (&adev->dev); +return -EIO ; + } + +if (auxiliary_device_add (adev)) { +auxiliary_device_uninit (adev); +return -EIO ; + } + + rc =devm_add_action_or_reset (dev, pci_doe_destroy_device, adev); +if (rc) +return rc; + +if (device_attach (&adev->dev) !=1 ) { +dev_err (&adev->dev, +"Failed to attach a driver to DOE device %d\n" , + adev->id); +return -ENODEV ; + } + + pos =pci_find_next_ext_capability (pdev, pos,PCI_EXT_CAP_ID_DOE ); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (pci_doe_create_doe_devices); +/** * pci_doe_exchange_sync() - Send a request, then wait for and receive a * response
@@ -639,6 +761,7 @@ static void pci_doe_remove(struct auxiliary_device *aux_dev) }static const struct auxiliary_device_id pci_doe_auxiliary_id_table[] = { + {.name ="pci_doe.doe" , }, {}, };
include/linux/pci-doe.h +3 -0
@@ -13,6 +13,8 @@ #ifndef LINUX_PCI_DOE_H #define LINUX_PCI_DOE_H +#define DOE_DEV_NAME "doe" + struct pci_doe_protocol { u16 vid; u8 type;
@@ -53,6 +55,7 @@ struct pci_doe_dev { };/* Library operations */ +int pci_doe_create_doe_devices (struct pci_dev *pdev);int pci_doe_exchange_sync (struct pci_doe_dev *doe_dev,struct pci_doe_exchange *ex);bool pci_doe_supports_prot (struct pci_doe_dev *doe_dev,u16 vid,u8 type);
Signature · 1 line
2.32.0
RFC PATCH v2 5/14 cxl/pci: Create DOE auxiliary devices
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
CXL devices will need DOE mailbox access to read things like CDAT.
Call the PCI core helper to find all DOE mailboxes on the device and create the auxiliary devices for those mailboxes.
sysfs shows this relationship. Starting with a qemu system with 2 memory devices mem0 and mem1.
$ ls -l /sys/bus/cxl/devices/mem* lrwxrwxrwx 1 root root 0 Jan 25 16:15 /sys/bus/cxl/devices/mem0 -> ../../../devices/pci0000:34/0000:34:00.0/0000:35:00.0/mem0 lrwxrwxrwx 1 root root 0 Jan 25 16:15 /sys/bus/cxl/devices/mem1 -> ../../../devices/pci0000:34/0000:34:01.0/0000:36:00.0/mem1
$ ls -l /sys/bus/auxiliary/devices/ total 0 lrwxrwxrwx 1 root root 0 Jan 25 16:16 pci_doe.doe.0 -> ../../../devices/pci0000:34/0000:34:00.0/0000:35:00.0/pci_doe.doe.0 lrwxrwxrwx 1 root root 0 Jan 25 16:16 pci_doe.doe.1 -> ../../../devices/pci0000:34/0000:34:01.0/0000:36:00.0/pci_doe.doe.1 lrwxrwxrwx 1 root root 0 Jan 25 16:16 pci_doe.doe.2 -> ../../../devices/pci0000:34/0000:34:01.0/0000:36:00.0/pci_doe.doe.2 lrwxrwxrwx 1 root root 0 Jan 25 16:16 pci_doe.doe.3 -> ../../../devices/pci0000:34/0000:34:00.0/0000:35:00.0/pci_doe.doe.3
$ ls -l /sys/bus/auxiliary/drivers total 0 drwxr-xr-x 2 root root 0 Jan 25 16:15 pci_doe.pci_doe
--- drivers/cxl/Kconfig | 1 + drivers/cxl/pci.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
drivers/cxl/Kconfig +1 -0
@@ -16,6 +16,7 @@ if CXL_BUS config CXL_MEM tristate "CXL.mem: Memory Devices" default CXL_BUS + select PCI_DOE_DRIVER help The CXL.mem protocol allows a device to act as a provider of "System RAM" and/or "Persistent Memory" that is fully coherent
drivers/cxl/pci.c +13 -0
@@ -6,6 +6,7 @@#include <linux/mutex.h> #include <linux/list.h> #include <linux/pci.h> +#include <linux/pci-doe.h> #include <linux/io.h> #include "cxlmem.h" #include "pci.h"
@@ -471,6 +472,14 @@ static int cxl_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,return rc; } +static int cxl_setup_doe_devices (struct cxl_dev_state *cxlds) +{ +struct device *dev = cxlds->dev; +struct pci_dev *pdev =to_pci_dev (dev); + +return pci_doe_create_doe_devices (pdev); +} +static int cxl_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct cxl_register_map map;
@@ -497,6 +506,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; + rc =cxl_setup_doe_devices (cxlds); +if (rc) +return rc; + rc =cxl_map_regs (cxlds, &map);if (rc)return rc;
Signature · 1 line
2.32.0
RFC PATCH v2 6/14 cxl/pci: Find the DOE mailbox which supports CDAT
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
Memory devices need the CDAT data from the device. This data is read from a DOE mailbox which supports the CDAT protocol.
Search the DOE auxiliary devices for the one which supports the CDAT protocol. Cache that device to be used for future queries.
--- drivers/cxl/cxl.h | 3 +++ drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-)
drivers/cxl/cxl.h +3 -0
@@ -75,6 +75,9 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr)#define CXLDEV_MBOX_BG_CMD_STATUS_OFFSET 0x18#define CXLDEV_MBOX_PAYLOAD_OFFSET 0x20 +#define CXL_DOE_PROTOCOL_COMPLIANCE 0 +#define CXL_DOE_PROTOCOL_TABLE_ACCESS 2 +/* * Using struct_group() allows for per register-block-type helper routines, * without requiring block-type agnostic code to include the prefix.
drivers/cxl/cxlmem.h +2 -0
@@ -97,6 +97,7 @@ struct cxl_mbox_cmd {* Currently only memory devices are represented. * * @dev: The device associated with this CXL state +* @cdat_doe: Auxiliary DOE device capabile of reading CDAT * @regs: Parsed register blocks * @payload_size: Size of space for payload * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
@@ -124,6 +125,7 @@ struct cxl_mbox_cmd {struct cxl_dev_state {struct device *dev; +struct pci_doe_dev *cdat_doe;struct cxl_regs regs;size_t payload_size;
drivers/cxl/pci.c +42 -1
54 lines not on this page · raw message
Signature · 1 line
2.32.0
RFC PATCH v2 7/14 cxl/mem: Read CDAT table
In reply to Jonathan CameronThe OS will need CDAT data from the CXL devices to properly set up interleave sets.
Search the DOE driver/devices attached to the CXL device for one which supports the CDAT protocol. If found, read the CDAT data from that mailbox.
Currently this is only supported by a PCI CXL object through a DOE mailbox which supports CDAT. But any cxl_mem type object can provide this data later if need be. For example for testing.
Cache this data for later parsing. Provide a sysfs binary attribute to allow dumping of the CDAT.
Binary dumping is modeled on /sys/firmware/ACPI/tables/
The ability to dump this table will be very useful for emulation of real devices once they become available as QEMU CXL type 3 device emulation will be able to load this file in.
This does not support table updates at runtime. It will always provide whatever was there when first cached. Handling of table updates can be implemented later.
Once there are more users, this code can move out to driver/cxl/cdat.c or similar.
Finally create a complete list of DOE defines within cdat.h for anyone wishing to decode the CDAT table.
--- drivers/cxl/cdat.h | 97 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/memdev.c | 56 ++++++++++++++++++++++ drivers/cxl/cxlmem.h | 25 ++++++++++ drivers/cxl/pci.c | 87 +++++++++++++++++++++++++++++++++++ 4 files changed, 265 insertions(+)
drivers/cxl/cdat.h new file +97 -0
@@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CXL_CDAT_H__ +#define __CXL_CDAT_H__ + +/* +* Coherent Device Attribute table (CDAT) +* +* Specification available from UEFI.org +* +* Whilst CDAT is defined as a single table, the access via DOE maiboxes is +* done one entry at a time, where the first entry is the header. +*/ + +#define CXL_DOE_TABLE_ACCESS_REQ_CODE 0x000000ff +#define CXL_DOE_TABLE_ACCESS_REQ_CODE_READ 0 +#define CXL_DOE_TABLE_ACCESS_TABLE_TYPE 0x0000ff00 +#define CXL_DOE_TABLE_ACCESS_TABLE_TYPE_CDATA 0 +#define CXL_DOE_TABLE_ACCESS_ENTRY_HANDLE 0xffff0000 + +/* +* CDAT entries are little endian and are read from PCI config space which +* is also little endian. +* As such, on a big endian system these will have been reversed. +* This prevents us from making easy use of packed structures. +* Style form pci_regs.h +*/ + +#define CDAT_HEADER_LENGTH_DW 4 +#define CDAT_HEADER_LENGTH_BYTES (CDAT_HEADER_LENGTH_DW * sizeof(u32)) +#define CDAT_HEADER_DW0_LENGTH 0xffffffff +#define CDAT_HEADER_DW1_REVISION 0x000000ff +#define CDAT_HEADER_DW1_CHECKSUM 0x0000ff00 +/* CDAT_HEADER_DW2_RESERVED */ +#define CDAT_HEADER_DW3_SEQUENCE 0xffffffff + +/* All structures have a common first DW */ +#define CDAT_STRUCTURE_DW0_TYPE 0x000000ff +#define CDAT_STRUCTURE_DW0_TYPE_DSMAS 0 +#define CDAT_STRUCTURE_DW0_TYPE_DSLBIS 1 +#define CDAT_STRUCTURE_DW0_TYPE_DSMSCIS 2 +#define CDAT_STRUCTURE_DW0_TYPE_DSIS 3 +#define CDAT_STRUCTURE_DW0_TYPE_DSEMTS 4 +#define CDAT_STRUCTURE_DW0_TYPE_SSLBIS 5 + +#define CDAT_STRUCTURE_DW0_LENGTH 0xffff0000 + +/* Device Scoped Memory Affinity Structure */ +#define CDAT_DSMAS_DW1_DSMAD_HANDLE 0x000000ff +#define CDAT_DSMAS_DW1_FLAGS 0x0000ff00 +#define CDAT_DSMAS_DPA_OFFSET (entry) ((u64)((entry)[3]) << 32 | (entry)[2]) +#define CDAT_DSMAS_DPA_LEN (entry) ((u64)((entry)[5]) << 32 | (entry)[4]) +#define CDAT_DSMAS_NON_VOLATILE (flags) ((flags & 0x04) >> 2) + +/* Device Scoped Latency and Bandwidth Information Structure */ +#define CDAT_DSLBIS_DW1_HANDLE 0x000000ff +#define CDAT_DSLBIS_DW1_FLAGS 0x0000ff00 +#define CDAT_DSLBIS_DW1_DATA_TYPE 0x00ff0000 +#define CDAT_DSLBIS_BASE_UNIT (entry) ((u64)((entry)[3]) << 32 | (entry)[2]) +#define CDAT_DSLBIS_DW4_ENTRY_0 0x0000ffff +#define CDAT_DSLBIS_DW4_ENTRY_1 0xffff0000 +#define CDAT_DSLBIS_DW5_ENTRY_2 0x0000ffff + +/* Device Scoped Memory Side Cache Information Structure */ +#define CDAT_DSMSCIS_DW1_HANDLE 0x000000ff +#define CDAT_DSMSCIS_MEMORY_SIDE_CACHE_SIZE (entry) \ + ((u64)((entry)[3]) << 32 | (entry)[2]) +#define CDAT_DSMSCIS_DW4_MEMORY_SIDE_CACHE_ATTRS 0xffffffff + +/* Device Scoped Initiator Structure */ +#define CDAT_DSIS_DW1_FLAGS 0x000000ff +#define CDAT_DSIS_DW1_HANDLE 0x0000ff00 + +/* Device Scoped EFI Memory Type Structure */ +#define CDAT_DSEMTS_DW1_HANDLE 0x000000ff +#define CDAT_DSEMTS_DW1_EFI_MEMORY_TYPE_ATTR 0x0000ff00 +#define CDAT_DSEMTS_DPA_OFFSET (entry) ((u64)((entry)[3]) << 32 | (entry)[2]) +#define CDAT_DSEMTS_DPA_LENGTH (entry) ((u64)((entry)[5]) << 32 | (entry)[4]) + +/* Switch Scoped Latency and Bandwidth Information Structure */ +#define CDAT_SSLBIS_DW1_DATA_TYPE 0x000000ff +#define CDAT_SSLBIS_BASE_UNIT (entry) ((u64)((entry)[3]) << 32 | (entry)[2]) +#define CDAT_SSLBIS_ENTRY_PORT_X (entry, i) ((entry)[4 + (i) * 2] & 0x0000ffff) +#define CDAT_SSLBIS_ENTRY_PORT_Y (entry, i) (((entry)[4 + (i) * 2] & 0xffff0000) >> 16) +#define CDAT_SSLBIS_ENTRY_LAT_OR_BW (entry, i) ((entry)[4 + (i) * 2 + 1] & 0x0000ffff) + +/** +* struct cxl_cdat - CXL CDAT data +* +* @table: cache of CDAT table +* @length: length of cached CDAT table +*/ +struct cxl_cdat { +void *table; +size_t length; +}; + +#endif /* !__CXL_CDAT_H__ */
drivers/cxl/core/memdev.c +56 -0
86 lines not on this page · raw message
drivers/cxl/cxlmem.h +25 -0
@@ -5,6 +5,7 @@#include <uapi/linux/cxl_mem.h> #include <linux/cdev.h> #include "cxl.h" +#include "cdat.h" /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */ #define CXLMDEV_STATUS_OFFSET 0x0
@@ -40,6 +41,7 @@ struct cxl_memdev {struct device dev;struct cdev cdev;struct cxl_dev_state *cxlds; +struct cxl_cdat cdat;int id; };
@@ -118,6 +120,10 @@ struct cxl_mbox_cmd {* @next_volatile_bytes: volatile capacity change pending device reset * @next_persistent_bytes: persistent capacity change pending device reset * @mbox_send: @dev specific transport for transmitting mailbox commands +* @cdat_get_length: @dev specific function for reading the CDAT table length +* returns -errno if CDAT not supported on this device +* @cdat_read_table: @dev specific function for reading the table +* returns -errno if CDAT not supported on this device * * See section 8.2.9.5.2 Capacity Configuration and Label Storage for * details on capacity parameters.
@@ -148,6 +154,9 @@ struct cxl_dev_state {u64 next_persistent_bytes;int (*mbox_send)(struct cxl_dev_state *cxlds,struct cxl_mbox_cmd *cmd); +int (*cdat_get_length)(struct cxl_dev_state *cxlds,size_t *length); +int (*cdat_read_table)(struct cxl_dev_state *cxlds, +struct cxl_cdat *cdat); };enum cxl_opcode {
@@ -266,4 +275,20 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds);struct cxl_dev_state *cxl_dev_state_create (struct device *dev);void set_exclusive_cxl_commands (struct cxl_dev_state *cxlds,unsigned long *cmds);void clear_exclusive_cxl_commands (struct cxl_dev_state *cxlds,unsigned long *cmds); + +static inline int cxl_mem_cdat_get_length (struct cxl_dev_state *cxlds,size_t *length) +{ +if (cxlds->cdat_get_length) +return cxlds->cdat_get_length (cxlds, length); +return -EOPNOTSUPP ; +} + +static inline int cxl_mem_cdat_read_table (struct cxl_dev_state *cxlds, +struct cxl_cdat *cdat) +{ +if (cxlds->cdat_read_table) +return cxlds->cdat_read_table (cxlds, cdat); +return -EOPNOTSUPP ; +} +#endif /* __CXL_MEM_H__ */
drivers/cxl/pci.c +87 -0
105 lines not on this page · raw message
Signature · 1 line
2.32.0
RFC PATCH v2 8/14 cxl/cdat: Introduce cdat_hdr_valid()
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
The CDAT data is protected by a checksum which should be checked when the CDAT is read to ensure it is valid. In addition the lengths specified should be checked.
Introduce cdat_hdr_valid() to check the checksum. While at it check and store the sequence number.
--- drivers/cxl/cdat.h | 2 ++ drivers/cxl/pci.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
drivers/cxl/cdat.h +2 -0
@@ -88,10 +88,12 @@* * @table: cache of CDAT table * @length: length of cached CDAT table +* @seq: Last read Sequence number of the CDAT table */ struct cxl_cdat {void *table;size_t length; +u32 seq; };#endif /* !__CXL_CDAT_H__ */
drivers/cxl/pci.c +32 -0
@@ -522,6 +522,35 @@ static int cxl_setup_doe_devices(struct cxl_dev_state *cxlds)return 0 ; } +static bool cxl_cdat_hdr_valid (struct device *dev,struct cxl_cdat *cdat) +{ +u32 *table = cdat->table; +u8 *data8 = cdat->table; +u32 length, seq; +u8 check; +int i; + + length =FIELD_GET (CDAT_HEADER_DW0_LENGTH , table[0 ]); +if (length <CDAT_HEADER_LENGTH_BYTES ) +return false; + +if (length > cdat->length) +return false; + + seq =FIELD_GET (CDAT_HEADER_DW3_SEQUENCE , table[3 ]); + +/* Store the sequence for now. */ +if (cdat->seq != seq) { +dev_info (dev,"CDAT seq change %x -> %x\n" , cdat->seq, seq); + cdat->seq = seq; + } + +for (check =0 , i =0 ; i < length; i++) + check += data8[i]; + +return check ==0 ; +} +#define CDAT_DOE_REQ (entry_handle) \ (FIELD_PREP(CXL_DOE_TABLE_ACCESS_REQ_CODE, \ CXL_DOE_TABLE_ACCESS_REQ_CODE_READ) | \
@@ -594,6 +623,9 @@ static int cxl_cdat_read_table(struct cxl_dev_state *cxlds, }while (entry_handle !=0xFFFF ); +if (!cxl_cdat_hdr_valid (cxlds->dev, cdat)) +return -EIO ; +return 0 ; }
Signature · 1 line
2.32.0
RFC PATCH v2 9/14 cxl/mem: Retry reading CDAT on failure
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
The CDAT read may fail for a number of reasons but mainly it is possible to get different parts of a valid state. The checksum in the CDAT table protects against this.
Now that the checksum is validated issue a retry if the CDAT read fails. For now 2 retries are implemented.
--- drivers/cxl/core/memdev.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/cxl/core/memdev.c +16 -1
@@ -312,7 +312,8 @@ static const struct file_operations cxl_memdev_fops = { .llseek = noop_llseek, }; -static int read_cdat_data (struct cxl_memdev *cxlmd,struct cxl_dev_state *cxlds) +static int __read_cdat_data (struct cxl_memdev *cxlmd, +struct cxl_dev_state *cxlds) {struct device *dev = &cxlmd->dev;size_t cdat_length;
@@ -327,6 +328,20 @@ static int read_cdat_data(struct cxl_memdev *cxlmd, struct cxl_dev_state *cxlds)return cxl_mem_cdat_read_table (cxlds, &cxlmd->cdat); } +static int read_cdat_data (struct cxl_memdev *cxlmd, +struct cxl_dev_state *cxlds) +{ +int retries =2 ; +int rc; + +while (--retries) { + rc =__read_cdat_data (cxlmd, cxlds); +if (!rc) +break ; + } +return rc; +} +struct cxl_memdev *devm_cxl_add_memdev (struct cxl_dev_state *cxlds) {struct cxl_memdev *cxlmd;
Signature · 1 line
2.32.0
RFC PATCH v2 10/14 cxl/cdat: Parse out DSMAS data from CDAT table
In reply to Jonathan CameronFrom: Ira Weiny <[email protected]>
CXL memory devices need the information in the Device Scoped Memory Affinity Structure (DSMAS). This information is contained within the CDAT table buffer which is already read and cached.
Parse and cache DSMAS data from the CDAT table. Store this data in unmarshaled struct dsmas data structures for ease of use.
--- drivers/cxl/cdat.h | 21 ++++++++++++ drivers/cxl/core/memdev.c | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+)
drivers/cxl/cdat.h +21 -0
@@ -83,17 +83,38 @@#define CDAT_SSLBIS_ENTRY_PORT_Y (entry, i) (((entry)[4 + (i) * 2] & 0xffff0000) >> 16)#define CDAT_SSLBIS_ENTRY_LAT_OR_BW (entry, i) ((entry)[4 + (i) * 2 + 1] & 0x0000ffff) +/** +* struct cxl_dsmas - host unmarshaled version of DSMAS data +* +* As defined in the Coherent Device Attribute Table (CDAT) specification this +* represents a single DSMAS entry in that table. +* +* @dpa_base: The lowest DPA address associated with this DSMAD +* @dpa_length: Length in bytes of this DSMAD +* @non_volatile: If set, the memory region represents Non-Volatile memory +*/ +struct cxl_dsmas { +u64 dpa_base; +u64 dpa_length; +/* Flags */ +u8 non_volatile:1 ; +}; +/** * struct cxl_cdat - CXL CDAT data * * @table: cache of CDAT table * @length: length of cached CDAT table * @seq: Last read Sequence number of the CDAT table +* @dsmas_ary: Array of DSMAS entries as parsed from the CDAT table +* @nr_dsmas: Number of entries in dsmas_ary */ struct cxl_cdat {void *table;size_t length;u32 seq; +struct cxl_dsmas *dsmas_ary; +int nr_dsmas; };#endif /* !__CXL_CDAT_H__ */
drivers/cxl/core/memdev.c +70 -0
88 lines not on this page · raw message
Signature · 1 line
2.32.0
RFC PATCH v2 11/14 lib/asn1_encoder: Add a function to encode many byte integer values.
In reply to Jonathan CameronAn example is the encoding of ECC signatures used by the ECDSA signature verification code. A user is the new SPDM support where raw signatures are returned by the responder. These can then be encoded so that we can pass them to signature_verify()
--- include/linux/asn1_encoder.h | 3 ++ lib/asn1_encoder.c | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
include/linux/asn1_encoder.h +3 -0
@@ -19,6 +19,9 @@ unsigned char * asn1_encode_tag(unsigned char *data, const unsigned char *end_data, u32 tag, const unsigned char *string, int len);unsigned char * +asn1_encode_integer_large_positive (unsigned char *data,const unsigned char *end_data, +u32 tag,const unsigned char *integer,int len); +unsigned char *asn1_encode_octet_string (unsigned char *data,const unsigned char *end_data,const unsigned char *string,u32 len);
lib/asn1_encoder.c +54 -0
60 lines not on this page · raw message
Signature · 1 line
2.32.0
RFC PATCH v2 12/14 spdm: Introduce a library for DMTF SPDM
In reply to Jonathan CameronThe Security Protocol and Data Model (SPDM) defines messages, data objects and sequences for performing message exchanges between devices over various transports and physical media.
As the kernel supports several possible transports (mctp, PCI DOE) introduce a library than can in turn be used with all those transports.
There are a large number of open questions around how we do this that need to be resolved. These include:
* Key chain management
- Current approach is to use a keychain provide as part of per transport initialization for the root certificates which are assumed to be loaded into that keychain, perhaps in an initrd script.
- Each SPDM instance then has its own keychain to manage its certificates. It may make sense to drop this, but that looks like it will make a lot of the standard infrastructure harder to use.
* ECC algorithms needing ASN1 encoded signatures. I'm struggling to find any specification that actual 'requires' that choice vs raw data, so my guess is that this is a question of existing usecases (x509 certs seem to use this form, but CHALLENGE_AUTH SPDM seems to use raw data). I'm not sure whether we are better off just encoding the signature in ASN1 as currently done in this series, or if it is worth a tweaking things in the crypto layers.
* Lots of options in actual implementation to look at.
--- include/linux/spdm.h | 104 ++++ lib/Kconfig | 3 + lib/Makefile | 2 + lib/spdm.c | 1196 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1305 insertions(+)
include/linux/spdm.h new file +104 -0
@@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* DMTF Security Protocol and Data Model +* +* Copyright (C) 2021 Huawei +* Jonathan Cameron <[email protected]> +*/ + +#ifndef _SPDM_H_ +#define _SPDM_H_ + +#include <linux/types.h> + +enum spdm_base_hash_algo { + spdm_base_hash_sha_256 =0 , + spdm_base_hash_sha_384 =1 , + spdm_base_hash_sha_512 =2 , + spdm_base_hash_sha3_256 =3 , + spdm_base_hash_sha3_384 =4 , + spdm_base_hash_sha3_512 =5 , +}; + +enum spdm_meas_hash_algo { + spdm_meas_hash_raw =0 , + spdm_meas_hash_sha_256 =1 , + spdm_meas_hash_sha_384 =2 , + spdm_meas_hash_sha_512 =3 , + spdm_meas_hash_sha3_256 =4 , + spdm_meas_hash_sha3_384 =5 , + spdm_meas_hash_sha3_512 =6 , +}; + +enum spdm_base_asym_algo { + spdm_asym_rsassa_2048 =0 , + spdm_asym_rsapss_2048 =1 , + spdm_asym_rsassa_3072 =2 , + spdm_asym_rsapss_3072 =3 , + spdm_asym_ecdsa_ecc_nist_p256 =4 , + spdm_asym_rsassa_4096 =5 , + spdm_asym_rsapss_4096 =6 , + spdm_asym_ecdsa_ecc_nist_p384 =7 , + spdm_asym_ecdsa_ecc_nist_p521 =8 +}; + +struct crypto_shash ; +struct shash_desc ; +struct key ; +struct device ; + +/* +* The SPDM specification does not actually define this as the header +* but all messages have the same first 4 named fields. +* Note however that the meaning of param1 and param2 is message dependent. +*/ +struct spdm_header { +u8 version; +u8 code;/* requestresponsecode */ +u8 param1; +u8 param2; +}; + +struct spdm_exchange { +struct spdm_header *request_pl; +size_t request_pl_sz; +struct spdm_header *response_pl; +size_t response_pl_sz; +u8 code;/* Overwrites the request code */ +}; + +struct spdm_state { +enum spdm_meas_hash_algo measurement_hash_alg; +enum spdm_base_asym_algo base_asym_alg; +enum spdm_base_hash_algo base_hash_alg; +struct key *leaf_key; +size_t h;/* base hash length - H in specification */ +size_t s;/* base asymmetric signature length - S in specification */ +u32 responder_caps; + +/* +* The base hash algorithm is not know until we reach the +* NEGOTIATE_ALGORITHMS response. +* The CHALLENGE_AUTH response handling requires a digest of all +* prior messages in the sequence. As such cache the messages in @a until +* they can be used as the first input to the hash function. +* Once the hash is known it can be updated as each additional req/rsp +* becomes available. +*/ +void *a; +size_t a_length; +struct crypto_shash *shash; +struct shash_desc *desc; + +struct key *root_keyring;/* Keyring against which to check the root */ +struct key *keyring;/* used to store certs from device */ + +/* Transport specific */ +struct device *dev;/* For error reporting only */ +void *transport_priv; +int (*transport_ex)(void *priv,struct spdm_exchange *spdm_ex); +}; + +int spdm_authenticate (struct spdm_state *spdm_state); +int spdm_measurements_get (struct spdm_state *spdm_state); +#endif
lib/Kconfig +3 -0
@@ -729,3 +729,6 @@ config PLDMFW config ASN1_ENCODER tristate + +config SPDM + tristate
lib/Makefile +2 -0
@@ -289,6 +289,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o obj-$(CONFIG_ASN1) += asn1_decoder.o obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o +obj-$(CONFIG_SPDM) += spdm.o + obj-$(CONFIG_FONT_SUPPORT) += fonts/ hostprogs := gen_crc32table
lib/spdm.c new file +1196 -0
1,196 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [RFC PATCH v2 12/14] spdm: Introduce a library for DMTF SPDM
include/linux/spdm.h line 4
Quoted 7 lines · Jonathan Cameron
include/linux/spdm.h new file +4
-0@@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* DMTF Security Protocol and Data Model +*
Please amend this comment at the top of both spdm.h and spdm.c with a link to https://www.dmtf.org/dsp/DSP0274
so the casual reader knows the document number and knows where to find the spec.
include/linux/spdm.h line 60
Quoted 6 lines
include/linux/spdm.h new file +6
-0+struct spdm_header { +u8 version; +u8 code;/* requestresponsecode */ +u8 param1; +u8 param2; +};
I think you need to add __packed to all of the message structs to ensure the compiler doesn't add padding anywhere.
include/linux/spdm.h line 66
Quoted 5 lines
include/linux/spdm.h new file +5
-0+struct spdm_exchange { +struct spdm_header *request_pl; +size_t request_pl_sz; +struct spdm_header *response_pl; +size_t response_pl_sz;
I assume "pl" means payload. This isn't accurate as the spec defines payload as the message body only (i.e. sans header).
I'd just omit the "_pl" suffix.
include/linux/spdm.h line 103
Quoted 1 line
include/linux/spdm.h new file +1
-0+int spdm_measurements_get (struct spdm_state *spdm_state);
That function is declared in spdm.h but there's no implementation provided in this patch. Probably a leftover from an older iteration?
lib/Makefile obj-$(CONFIG_PERCPU_TEST) += percpu_test.o · line 292
Quoted 7 lines
lib/Makefile +1
-0@@ -289,6 +289,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o obj-$(CONFIG_ASN1) += asn1_decoder.o obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o +obj-$(CONFIG_SPDM) += spdm.o
It certainly seems wise to put this in lib/ so that it can be used by other buses as well once they add encryption/authentication. It's clearly not a PCIe-only feature.
I'm thinking of USB specifically since the USB Authentication Spec seems to have served as a blueprint for SPDM.
I'd suggest to only include a forward declaration of struct spdm_state in spdm.h to avoid exposing internals. I'd further suggest to expose one function to allocate & initialize an spdm_state. By initialize I mean that a transport function pointer is passed in which is stored in struct spdm_state. The transport function performs one request/response transaction. I think you should not mark the dev pointer in struct spdm_state as "For error reporting only", rather that's the device with which an SPDM exchange is performed. The transport function should use that dev pointer instead of duplicating the pointer in transport_priv.
Authenticating a device would thus encompass two function calls, one to allocate & initialize spdm_state, another one to perform SPDM session setup (which does authentication).
Encryption would encompass a third function call to set up IDE.
lib/Makefile obj-$(CONFIG_PERCPU_TEST) += percpu_test.o · line 295
Quoted 3 lines
lib/Makefile +3
-0+ spdm_state->measurement_hash_alg = __ffs(le16_to_cpu(rsp->measurement_hash_algo)); + spdm_state->base_asym_alg = __ffs(le16_to_cpu(rsp->base_asym_sel)); + spdm_state->base_hash_alg = __ffs(le16_to_cpu(rsp->base_hash_sel));
The weaker algorithms are represented by lower bits, so this selects the weakest supported algorithm. Wouldn't we want the opposite? I guess that's a policy decision that user space should decide...
Thanks,
Lukas
RFC PATCH v2 13/14 PCI/CMA: Initial support for Component Measurement and Authentication ECN
In reply to Jonathan CameronThis currently very much a PoC. Currently the SPDM library only provides a single function to allow a challenge / authentication of the PCI EP.
SPDM exchanges must occur in one of a small set of valid squences over which the message digest used in authentication is built up. Placing that complexity in the SPDM library seems like a good way to enforce that logic, without having to do it for each transport.
--- drivers/pci/Kconfig | 9 ++++ drivers/pci/Makefile | 2 + drivers/pci/cma.c | 105 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-cma.h | 19 ++++++++ 4 files changed, 135 insertions(+)
drivers/pci/Kconfig +9 -0
@@ -128,6 +128,15 @@ config PCI_DOE_DRIVER number of different protocols. DOE is defined in the Data Object Exchange ECN to the PCIe r5.0 spec. +config PCI_CMA + tristate "PCI Component Measurement and Authentication" + select PCI_DOE + select ASN1_ENCODER + select SPDM + help + This enables library support for the PCI Component Measurement and + Authentication ECN. This uses DMTF SPDM 1.1 + config PCI_ATS bool
drivers/pci/Makefile +2 -0
@@ -30,9 +30,11 @@ obj-$(CONFIG_PCI_PF_STUB) += pci-pf-stub.o obj-$(CONFIG_PCI_ECAM) += ecam.o obj-$(CONFIG_PCI_P2PDMA) += p2pdma.o obj-$(CONFIG_PCI_DOE_DRIVER) += pci-doe.o +obj-$(CONFIG_PCI_CMA) += pci-cma.o obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o pci-doe-y := doe.o +pci-cma-y := cma.o # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/
drivers/pci/cma.c new file +105 -0
105 lines not on this page · raw message
include/linux/pci-cma.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Component Measurement and Authentication was added as an ECN to the +* PCIe r5.0 spec. +* +* Copyright (C) 2021 Huawei +* Jonathan Cameron <[email protected]> +*/ + +#ifndef _PCI_CMA_H_ +#define _PCI_CMA_H_ +struct pci_doe_dev ; +struct spdm_state ; + +void pci_cma_init (struct pci_doe_dev *doe_dev,struct spdm_state *spdm_state); + +int pci_cma_authenticate (struct spdm_state *spdm_state); + +#endif
Signature · 1 line
2.32.0
RFC PATCH v2 14/14 cxl/pci: Add really basic CMA authentication support.
In reply to Jonathan CameronThis is just for purposes of poking the CMA / SPDM code. What exactly the model in the driver looks like is still to be worked out.
Note the PROBE_FORCE_SYNCHRONOUS is a workaround to avoid warnings about trying to load an additional crypto module whilst doing an asychronous probe.
--- drivers/cxl/Kconfig | 1 + drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 40 +++++++++++++++++++++++++++++++++++++++- lib/spdm.c | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-)
drivers/cxl/Kconfig +1 -0
@@ -17,6 +17,7 @@ config CXL_MEM tristate "CXL.mem: Memory Devices" default CXL_BUS select PCI_DOE_DRIVER + select PCI_CMA help The CXL.mem protocol allows a device to act as a provider of "System RAM" and/or "Persistent Memory" that is fully coherent
drivers/cxl/cxlmem.h +2 -0
@@ -100,6 +100,7 @@ struct cxl_mbox_cmd {* * @dev: The device associated with this CXL state * @cdat_doe: Auxiliary DOE device capabile of reading CDAT +* @cma_doe: Component measurement and authentication mailbox * @regs: Parsed register blocks * @payload_size: Size of space for payload * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
@@ -132,6 +133,7 @@ struct cxl_dev_state {struct device *dev;struct pci_doe_dev *cdat_doe; +struct pci_doe_dev *cma_doe;struct cxl_regs regs;size_t payload_size;
drivers/cxl/pci.c +39 -1
@@ -1,9 +1,14 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2020 Intel Corporation. All rights reserved. */ #include <linux/io-64-nonatomic-lo-hi.h> +//#include <uapi/linux/cxl_mem.h> +#include <linux/security.h> +#include <linux/pci-cma.h> +//#include <linux/debugfs.h> #include <linux/module.h> #include <linux/sizes.h> #include <linux/mutex.h> +#include <linux/spdm.h> #include <linux/list.h> #include <linux/pci.h> #include <linux/pci-doe.h>
@@ -494,6 +499,26 @@ static int cxl_match_cdat_doe_device(struct device *dev, const void *data)return 0 ; } +static int cxl_match_cma_doe_device (struct device *dev,const void *data) +{ +const struct cxl_dev_state *cxlds = data; +struct auxiliary_device *adev; +struct pci_doe_dev *doe_dev; + +/* First determine if this auxiliary device belongs to the cxlds */ +if (cxlds->dev != dev->parent) +return 0 ; + + adev =to_auxiliary_dev (dev); + doe_dev = container_of(adev, struct pci_doe_dev, adev); + +/* If it is one of ours check for the CMA protocol */ +if (pci_doe_supports_prot (doe_dev,PCI_VENDOR_ID_PCI_SIG ,1 ))//hack +return 1 ; + +return 0 ; +} +static int cxl_setup_doe_devices (struct cxl_dev_state *cxlds) {struct device *dev = cxlds->dev;
@@ -519,6 +544,10 @@ static int cxl_setup_doe_devices(struct cxl_dev_state *cxlds) cxlds->cdat_doe = doe_dev; } + adev =auxiliary_find_device (NULL , cxlds, &cxl_match_cma_doe_device); +if (adev) + cxlds->cma_doe = container_of(adev, struct pci_doe_dev, adev); +return 0 ; }
@@ -643,6 +672,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)struct cxl_register_map map;struct cxl_memdev *cxlmd;struct cxl_dev_state *cxlds; +struct spdm_state spdm_state;int rc;/*
@@ -670,6 +700,14 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)cxl_initialize_cdat_callbacks (cxlds); +/* CMA is optional - policy control will be needed */ +if (cxlds->cma_doe) { +pci_cma_init (cxlds->cma_doe, &spdm_state); + rc =pci_cma_authenticate (&spdm_state); +if (rc) +return rc; + } + rc =cxl_map_regs (cxlds, &map);if (rc)return rc;
@@ -712,7 +750,7 @@ static struct pci_driver cxl_pci_driver = { .id_table = cxl_mem_pci_tbl, .probe = cxl_pci_probe, .driver = { - .probe_type = PROBE_PREFER_ASYNCHRONOUS, + .probe_type = PROBE_FORCE_SYNCHRONOUS, }, };
lib/spdm.c +1 -1
@@ -921,7 +921,7 @@ static int spdm_get_certificate(struct spdm_state *spdm_state)key_ref_to_ptr (key2)->payload.data[asym_auth]; key =find_asymmetric_key (spdm_state->root_keyring, sig->auth_ids[0 ], - sig->auth_ids[1 ], false); + sig->auth_ids[1 ],NULL , false);if (IS_ERR (key)) {dev_err (spdm_state->dev,"Unable to retrieve signing certificate from _cma keyring\n" );
Signature · 1 line
2.32.0