drivers: misc: Add support for nCipher HSM devices
cover drivers: misc: Add support for nCipher HSM devices
Hi all,
This patch introduces the nCipher Hardware Security Module (HSM) driver into the linux kernel. Upstreaming the driver will allow early adopters of the latest kernel to upgrade and maintain their working systems when using an nCipher PCIe HSM. Further, having this driver in the kernel will be more convenient to our users and make a Linux based solution a more attractive option for others.
Thanks,
Dave Kim
David Kim (1):
drivers: misc: Add support for nCipher HSM devices
MAINTAINERS | 8 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/ncipher/Kconfig | 8 + drivers/misc/ncipher/Makefile | 7 + drivers/misc/ncipher/fsl.c | 911 +++++++++++++++++ drivers/misc/ncipher/fsl.h | 117 +++ drivers/misc/ncipher/hostif.c | 1521 +++++++++++++++++++++++++++++ drivers/misc/ncipher/i21555.c | 553 +++++++++++ drivers/misc/ncipher/i21555.h | 68 ++ drivers/misc/ncipher/solo.h | 316 ++++++ include/uapi/linux/nshield_solo.h | 181 ++++ 12 files changed, 3692 insertions(+) create mode 100644 drivers/misc/ncipher/Kconfig create mode 100644 drivers/misc/ncipher/Makefile create mode 100644 drivers/misc/ncipher/fsl.c create mode 100644 drivers/misc/ncipher/fsl.h create mode 100644 drivers/misc/ncipher/hostif.c create mode 100644 drivers/misc/ncipher/i21555.c create mode 100644 drivers/misc/ncipher/i21555.h create mode 100644 drivers/misc/ncipher/solo.h create mode 100644 include/uapi/linux/nshield_solo.h
Signature · 12 lines
2.24.1 David Kim Senior Software Engineer Tel: +44 1223 703449 nCipher Security One Station Square Cambridge CB1 2GA United Kingdom
PATCH 1/1 drivers: misc: Add support for nCipher HSM devices
From: David Kim <[email protected]>
Introduce the driver for nCipher's Solo and Solo XC range of PCIe hardware security modules (HSM), which provide key creation/management and cryptography services.
--- MAINTAINERS | 8 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/ncipher/Kconfig | 8 + drivers/misc/ncipher/Makefile | 7 + drivers/misc/ncipher/fsl.c | 911 +++++++++++++++++ drivers/misc/ncipher/fsl.h | 117 +++ drivers/misc/ncipher/hostif.c | 1521 +++++++++++++++++++++++++++++ drivers/misc/ncipher/i21555.c | 553 +++++++++++ drivers/misc/ncipher/i21555.h | 68 ++ drivers/misc/ncipher/solo.h | 316 ++++++ include/uapi/linux/nshield_solo.h | 181 ++++ 12 files changed, 3692 insertions(+) create mode 100644 drivers/misc/ncipher/Kconfig create mode 100644 drivers/misc/ncipher/Makefile create mode 100644 drivers/misc/ncipher/fsl.c create mode 100644 drivers/misc/ncipher/fsl.h create mode 100644 drivers/misc/ncipher/hostif.c create mode 100644 drivers/misc/ncipher/i21555.c create mode 100644 drivers/misc/ncipher/i21555.h create mode 100644 drivers/misc/ncipher/solo.h create mode 100644 include/uapi/linux/nshield_solo.h
MAINTAINERS +8 -0
@@ -11319,6 +11319,14 @@ NATSEMI ETHERNET DRIVER (DP8381x) S: Orphan F: drivers/net/ethernet/natsemi/natsemi.c +NCIPHER NSHIELD HARDWARE SECURITY MODULE DRIVERS +M: Tim Magee <[email protected]> +M: David Kim <[email protected]> +M: Hamish Cameron <[email protected]> +L: [email protected] +S: Supported +F: drivers/misc/ncipher/ + NCR 5380 SCSI DRIVERS M: Finn Thain <[email protected]> M: Michael Schmitz <[email protected]>
drivers/misc/Kconfig +1 -0
@@ -480,4 +480,5 @@ source "drivers/misc/cxl/Kconfig" source "drivers/misc/ocxl/Kconfig" source "drivers/misc/cardreader/Kconfig" source "drivers/misc/habanalabs/Kconfig" +source "drivers/misc/ncipher/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -57,3 +57,4 @@ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o +obj-$(CONFIG_NCIPHER) += ncipher/
drivers/misc/ncipher/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# Enable support for nCipher's nShield Solo and Solo XC +config HSM_NCIPHER_NSHIELD_SOLO + tristate "nCipher Solo and Solo XC family of PCIe HSMs" + depends on PCI + help + Select this as built-in or module if you expect to use + a Hardware Security Module from nCipher's Solo or Solo XC range.
drivers/misc/ncipher/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for nCipher nShield HSM drivers +# + +obj-$(CONFIG_HSM_NCIPHER_NSHIELD_SOLO) := nshield_solo.o +nshield_solo-y := hostif.o fsl.o i21555.o
drivers/misc/ncipher/fsl.c new file +911 -0
911 lines not on this page · raw message
drivers/misc/ncipher/fsl.h new file +117 -0
117 lines not on this page · raw message
drivers/misc/ncipher/hostif.c new file +1521 -0
1,521 lines not on this page · raw message
drivers/misc/ncipher/i21555.c new file +553 -0
413 lines not on this page · raw message
drivers/misc/ncipher/i21555.h new file +68 -0
68 lines not on this page · raw message
drivers/misc/ncipher/solo.h new file +316 -0
316 lines not on this page · raw message
include/uapi/linux/nshield_solo.h new file +181 -0
181 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 12 lines
2.24.1 David Kim Senior Software Engineer Tel: +44 1223 703449 nCipher Security One Station Square Cambridge CB1 2GA United Kingdom
Part of the diff is not shown here. View the raw message.
Greg KH
maintainerQuoted 5 lines · Dave Kim
From: David Kim <[email protected]>
Introduce the driver for nCipher's Solo and Solo XC range of PCIe hardware security modules (HSM), which provide key creation/management and cryptography services.
A bit more description of exactly _what_ these devices do would be helpful.
Also, how does userspace interact with the driver? What api(s) are you using/creating? What userspace tools work with the device?
In short, we need more than just a one sentance description to be able to properly review the code and provide text for a user to know what to do with this driver.
Can you fix all that up and send a v2?
thanks,
greg k-h
Greg KH
maintainerQuoted 13 lines · Dave Kim
include/uapi/linux/nshield_solo.h new file +10
-0@@ -0,0 +1,181 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* +* +* nshield_solo.h: UAPI header for driving the nCipher PCI HSMs using the +* nshield_solo module +* +*/ +#ifndef _UAPI_NSHIELD_SOLO_H_ +#define _UAPI_NSHIELD_SOLO_H_ +
include/uapi/linux/nshield_solo.h line 20
Quoted 10 lines
include/uapi/linux/nshield_solo.h new file +10
-0+#include <linux/types.h> +#include <linux/ioctl.h> + +/* Device ioctl struct definitions */ + +/* Result of the ENQUIRY ioctl. */ +struct nfdev_enquiry_str { +__u32 busno;/**< Which bus is the PCI device on. */ +__u8 slotno;/**< Which slot is the PCI device in. */ +__u8 reserved[3 ];/**< for consistent struct alignment */
What is this crazy /**< text?
Please use correct kerneldoc formatting to help document things.
Quoted 30 lines
include/uapi/linux/nshield_solo.h new file +30
-0+}; + +/* Result of the STATS ioctl. */ +struct nfdev_stats_str { +__u32 isr;/**< Count interrupts. */ +__u32 isr_read;/**< Count read interrupts. */ +__u32 isr_write;/**< Count write interrupts. */ +__u32 write_fail;/**< Count write failures. */ +__u32 write_block;/**< Count blocks written. */ +__u32 write_byte;/**< Count bytes written. */ +__u32 read_fail;/**< Count read failures. */ +__u32 read_block;/**< Count blocks read. */ +__u32 read_byte;/**< Count bytes read. */ +__u32 ensure_fail;/**< Count read request failures. */ +__u32 ensure;/**< Count read requests. */ +}; + +/* Result of the STATUS ioctl. */ +struct nfdev_status_str { +__u32 status;/**< Status flags. */ +char error[8 ];/**< Error string. */ +}; + +/* Input to the CONTROL ioctl. */ +struct nfdev_control_str { +__u32 control;/**< Control flags. */ +}; + +/** Index of control bits indicating desired mode +*
include/uapi/linux/nshield_solo.h line 60
Quoted 10 lines
include/uapi/linux/nshield_solo.h new file +10
-0+* Desired mode follows the M_ModuleMode enumeration. +*/ +#define NFDEV_CONTROL_MODE_SHIFT 1 + +/** Detect a backwards-compatible control value +* +* Returns true if the request control value "makes no difference", i.e. +* and the failure of an attempt to set it is therefore uninteresting. +*/ +#define NFDEV_CONTROL_HARMLESS (c) ((c) <= 1)
Why does userspace need this?
include/uapi/linux/nshield_solo.h line 63
Quoted 3 lines
include/uapi/linux/nshield_solo.h new file +3
-0+ +/** Monitor firmware supports MOI control and error reporting +*/
Correct kerneldoc format everywhere please.
Quoted 34 lines
include/uapi/linux/nshield_solo.h new file +34
-0+#define NFDEV_STATUS_MONITOR_MOI 0x0001 + +/** Application firmware supports MOI control and error reporting +*/ +#define NFDEV_STATUS_APPLICATION_MOI 0x0002 + +/** Application firmware running and supports error reporting +*/ +#define NFDEV_STATUS_APPLICATION_RUNNING 0x0004 + +/** HSM failed +* +* Consult error[] for additional information. +*/ +#define NFDEV_STATUS_FAILED 0x0008 + +/** Standard PCI interface. */ +#define NFDEV_IF_STANDARD 0x01 + +/** PCI interface with read replies pushed from device +* via DMA. +*/ +#define NFDEV_IF_PCI_PUSH 0x02 + +/** PCI interface with read replies pushed from device +* and write requests pulled from host via DMA. +*/ +#define NFDEV_IF_PCI_PULL 0x03 + +/** Maximum PCI interface. */ +#define NFDEV_IF_MAX_VERS NFDEV_IF_PCI_PUSH_PULL + +/* platform independent base ioctl numbers */ +
include/uapi/linux/nshield_solo.h line 107
Quoted 10 lines
include/uapi/linux/nshield_solo.h new file +10
-0+enum { +/** Enquiry ioctl. +* \return nfdev_enquiry_str describing the attached device. +*/ +NFDEV_IOCTL_NUM_ENQUIRY =1 , + +/** Channel Update ioctl. +* \deprecated +*/ +NFDEV_IOCTL_NUM_CHUPDATE ,
You have to explicitly set your enums if you want them to work properly in an ioctl. As it is, this will fail in nasty ways you can never debug :(
include/uapi/linux/nshield_solo.h line 112
Quoted 5 lines
include/uapi/linux/nshield_solo.h new file +5
-0+ +/** Ensure Reading ioctl. +* Signal a read request to the device. +* \param (unsigned int) Length of data to be read. +*/
Again, kerneldoc please.
Quoted 44 lines
include/uapi/linux/nshield_solo.h new file +44
-0+NFDEV_IOCTL_NUM_ENSUREREADING , + +/** Device Count ioctl. +* Not implemented for on all platforms. +* \return (int) the number of attached devices. +*/ +NFDEV_IOCTL_NUM_DEVCOUNT , + +/** Internal Debug ioctl. +* Not implemented in release drivers. +*/ +NFDEV_IOCTL_NUM_DEBUG , + +/** PCI Interface Version ioctl. +* \param (int) Maximum PCI interface version +* supported by the user of the device. +*/ +NFDEV_IOCTL_NUM_PCI_IFVERS , + +/** Statistics ioctl. +* \return nfdev_enquiry_str describing the attached device. +*/ +NFDEV_IOCTL_NUM_STATS , + +/** Module control ioctl +* \param (nfdev_control_str) Value to write to HSM +* control register +*/ +NFDEV_IOCTL_NUM_CONTROL , + +/** Module state ioctl +* \return (nfdev_status_str) Values read from HSM +* status/error registers +*/ + NFDEV_IOCTL_NUM_STATUS, +}; + +#define NFDEV_IOCTL_TYPE 0x10 + +#define NFDEV_IOCTL_CHUPDATE \ + _IO(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_CHUPDATE) + +#define NFDEV_IOCTL_ENQUIRY \ + _IOR(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_ENQUIRY, \
include/uapi/linux/nshield_solo.h line 166
Quoted 10 lines
include/uapi/linux/nshield_solo.h new file +10
-0+ struct nfdev_enquiry_str) + +#define NFDEV_IOCTL_ENSUREREADING \ + _IOW(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_ENSUREREADING, int) + +#define NFDEV_IOCTL_ENSUREREADING_BUG3349 \ + _IO(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_ENSUREREADING) + +#define NFDEV_IOCTL_DEBUG \ + _IOW(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_DEBUG, int)
Why do you care about debugging to userspace through an ioctl? Just use debugfs and be done with it, that's what it is there for. Also you can use dynamic debugging (hopefully you already are) and use that kernel-wide api/interface.
Individual drivers should NEVER have custom debugging controls and macros.
include/uapi/linux/nshield_solo.h line 169
Quoted 3 lines
include/uapi/linux/nshield_solo.h new file +3
-0+ +#define NFDEV_IOCTL_PCI_IFVERS \ + _IOW(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_PCI_IFVERS, int)
Can't you get this from the pci device information?
thanks,
greg k-h
Greg KH
maintainerdrivers/misc/ncipher/i21555.h line 16
Quoted 3 lines · Dave Kim
drivers/misc/ncipher/i21555.h new file +3
-0+#ifndef PCI_VENDOR_ID_INTEL +#define PCI_VENDOR_ID_INTEL 0x8086 +#endif
This is already defined by the kernel, no need to do so again.
thanks,
greg k-h
Greg KH
maintainerdrivers/misc/ncipher/hostif.c line 1433
Quoted 10 lines · Dave Kim
drivers/misc/ncipher/hostif.c new file +10
-0+/** +* PCI device ID table. We use the driver_data field to hold an index into +* nfp_drvlist, so bear than in mind when editing either. +*/ +static struct pci_device_id nfp_pci_tbl[] = { + { +PCI_VENDOR_ID_INTEL ,PCI_DEVICE_ID_INTEL_21555 , +PCI_VENDOR_ID_NCIPHER ,PCI_SUBSYSTEM_ID_NFAST_REV1 ,0 , +0 ,/* Ignore class */ +0 /* Index into nfp_drvlist */
Please use the correct PCI_DEVICE() macros, that should work here, right?
And you are grabbing an Intel PCI device id?
drivers/misc/ncipher/hostif.c line 1439
Quoted 6 lines
drivers/misc/ncipher/hostif.c new file +6
-0+ }, + { +PCI_VENDOR_ID_FREESCALE ,PCI_DEVICE_ID_FREESCALE_T1022 , +PCI_VENDOR_ID_NCIPHER ,PCI_SUBSYSTEM_ID_NFAST_REV1 ,0 , +0 ,/* Ignore class */ +1 /* Index into nfp_drvlist */
Again, PCI_DEVICE() macros please.
And kerneldoc everywhere, your commenting format for all of the code is a bit "odd".
thanks,
greg k-h
Hi Greg,
Thanks for the speedy replies. Yes, I will add more background information and make the quick formatting changes for a v2. We'll reply to your other email comments and get those resolved as well. I was trying to be terse but looks like I was too terse. I thought the changelog text should be brief and the cover letter would be more verbose?
Regards,
Dave
________________________________________
From: Greg KH <[email protected]>
Sent: Tuesday, December 17, 2019 1:32 PM
To: Kim, David
Cc: [email protected]; [email protected]; Magee, Tim
Subject: Re: [PATCH 1/1] drivers: misc: Add support for nCipher HSM devices
Quoted 5 lines · Dave Kim
From: David Kim <[email protected]>
Introduce the driver for nCipher's Solo and Solo XC range of PCIe hardware security modules (HSM), which provide key creation/management and cryptography services.
A bit more description of exactly _what_ these devices do would be helpful.
Also, how does userspace interact with the driver? What api(s) are you using/creating? What userspace tools work with the device?
In short, we need more than just a one sentance description to be able to properly review the code and provide text for a user to know what to do with this driver.
Can you fix all that up and send a v2?
thanks,
greg k-h
Greg KH
maintainerQuoted 8 lines · David
Hi Greg,
Thanks for the speedy replies. Yes, I will add more background information and make the quick formatting changes for a v2. We'll reply to your other email comments and get those resolved as well. I was trying to be terse but looks like I was too terse. I thought the changelog text should be brief and the cover letter would be more verbose?
cover letters do not end up in the kernel changelog.
And there's no need for a cover letter for a 1 patch series. Only for multiple patches if it's not obvious what is going on here.
thanks,
greg k-h
Hi Greg,
I'm just about to push v2 of our patch but wanted to address your comments in the emails you raised them in.
Quoted 11 lines
include/uapi/linux/nshield_solo.h line 20
Quoted 8 lines
include/uapi/linux/nshield_solo.h new file +8
-0+ +/* Device ioctl struct definitions */ + +/* Result of the ENQUIRY ioctl. */ +struct nfdev_enquiry_str { +__u32 busno;/**< Which bus is the PCI device on. */ +__u8 slotno;/**< Which slot is the PCI device in. */ +__u8 reserved[3 ];/**< for consistent struct alignment */ What is this crazy /**< text?
Quoted 1 line
Please use correct kerneldoc formatting to help document things.
Done. I've also double checked all the other files. Checkpatch didn't seem to complain about these so we missed them, sorry.
Quoted 5 lines
Quoted 2 lines
+ */
+#defineNFDEV_CONTROL_HARMLESS(c)((c) <= 1)Why does userspace need this?
It doesn't. We've removed that and a couple other leftovers.
Quoted 5 lines
Quoted 5 lines
include/uapi/linux/nshield_solo.h new file +5
-0+enum { +/** Enquiry ioctl. +* \return nfdev_enquiry_str describing the attached device. +*/ +NFDEV_IOCTL_NUM_ENQUIRY =1 ,
Quoted 9 lines
include/uapi/linux/nshield_solo.h line 107
Quoted 5 lines
include/uapi/linux/nshield_solo.h new file +5
-0+ +/** Channel Update ioctl. +* \deprecated +*/ + NFDEV_IOCTL_NUM_CHUPDATE,You have to explicitly set your enums if you want them to work properly in an ioctl. As it is, this will fail in nasty ways you can never debug :(
Thanks, we've set them explicitly and also removed the unnecessary ones.
Quoted 10 lines
include/uapi/linux/nshield_solo.h line 166
Quoted 3 lines
include/uapi/linux/nshield_solo.h new file +3
-0+ +#define NFDEV_IOCTL_DEBUG \ + _IOW(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_DEBUG, int)Why do you care about debugging to userspace through an ioctl? Just use debugfs and be done with it, that's what it is there for. Also you can use dynamic debugging (hopefully you already are) and use that kernel-wide api/interface.
Individual drivers should NEVER have custom debugging controls and macros.
Yes, this was accidentally left in. It's been removed now.
Quoted 7 lines
include/uapi/linux/nshield_solo.h line 169
Quoted 4 lines
include/uapi/linux/nshield_solo.h new file +3
-0+ +#define NFDEV_IOCTL_PCI_IFVERS \ + _IOW(NFDEV_IOCTL_TYPE, NFDEV_IOCTL_NUM_PCI_IFVERS, int)Can't you get this from the pci device information?
Unfortunately not. Each time the device is brought up or has its state changed, the IFVERS is re-negotiated. This call is our means of discovering what IFVER is supported by the currently running firmware.
Thanks,
Dave
Quoted 10 lines
drivers/misc/ncipher/hostif.c
Quoted 9 lines
drivers/misc/ncipher/hostif.c new file +9
-0+/** +* PCI device ID table. We use the driver_data field to hold an +index into +* nfp_drvlist, so bear than in mind when editing either. +*/ +static struct pci_device_id nfp_pci_tbl[] = { +{ +PCI_VENDOR_ID_INTEL ,PCI_DEVICE_ID_INTEL_21555 , +PCI_VENDOR_ID_NCIPHER ,
PCI_SUBSYSTEM_ID_NFAST_REV1, 0,
Quoted 6 lines
Quoted 2 lines
+0, /* Ignore class */
+0 /* Index intonfp_drvlist*/Please use the correct
PCI_DEVICE()macros, that should work here, right?And you are grabbing an Intel PCI device id?
We've removed our redefinition of PCI_VENDOR_ID_INTEL and are now using the PCI_DEVICE_SUB macro to define these structs.
Quoted 4 lines
And kerneldoc everywhere, your commenting format for all of the code is a bit "odd".
All the commenting format should be better now.
Thanks,
Dave
David Kim
Senior Software Engineer
Tel: +44 1223 703449
nCipher Security
One Station Square
Cambridge CB1 2GA
United Kingdom
Quoted 11 lines · Dave Kim
Quoted 4 lines
From: David Kim <[email protected]>
Introduce the driver for nCipher's Solo and Solo XC range of PCIe hardware security modules (HSM), which provide key
creation/management
Quoted 1 line
and cryptography services.
A bit more description of exactly _what_ these devices do would be helpful.
Quoted 9 lines
Also, how does userspace interact with the driver? What api(s) are you using/creating? What userspace tools work with the device?
In short, we need more than just a one sentance description to be able to properly review the code and provide text for a user to know what to do with this driver.
Can you fix all that up and send a v2?
Hi Greg,
I've just now submitted our v2 patch and hopefully it addresses all your initial concerns. I just wanted to let you know that we'll be away for Christmas now until the first week of January.
Thanks for your feedback and have a good end of year.
Regards,
Dave