Inline Encryption Support for UFS
cover Inline Encryption Support for UFS
This patch series adds support for inline encryption to UFS using the inline encryption support in the block layer. It follows the JEDEC UFSHCI v2.1 specification, which defines inline encryption for UFS. This patch series is based on v5.8-rc1.
Patch 1 introduces the crypto registers and struct definitions defined in the UFSHCI v2.1 spec.
Patch 2 introduces functions to manipulate the UFS inline encryption hardware (again in line with the UFSHCI v2.1 spec) via the block layer keyslot manager. Device specific drivers must set the UFSHCD_CAP_CRYPTO in hba->caps before ufshcd_hba_init_crypto is called to opt-in to inline encryption support.
Patch 3 wires up ufshcd.c with the UFS crypto API introduced in Patch 2.
Satya Tangirala (3):
scsi: ufs: UFS driver v2.1 spec crypto additions
scsi: ufs: UFS crypto API
scsi: ufs: Add inline encryption support to UFS
drivers/scsi/ufs/Kconfig | 9 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufshcd-crypto.c | 226 +++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd-crypto.h | 60 ++++++++ drivers/scsi/ufs/ufshcd.c | 46 ++++++- drivers/scsi/ufs/ufshcd.h | 24 ++++ drivers/scsi/ufs/ufshci.h | 67 ++++++++- 7 files changed, 426 insertions(+), 7 deletions(-) create mode 100644 drivers/scsi/ufs/ufshcd-crypto.c create mode 100644 drivers/scsi/ufs/ufshcd-crypto.h
Signature · 1 line
2.27.0.290.gba653c62da-goog
PATCH 1/3 scsi: ufs: UFS driver v2.1 spec crypto additions
Add the crypto registers and structs defined in v2.1 of the JEDEC UFSHCI specification in preparation to add support for inline encryption to UFS.
--- drivers/scsi/ufs/ufshcd.c | 2 ++ drivers/scsi/ufs/ufshcd.h | 6 ++++ drivers/scsi/ufs/ufshci.h | 67 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +2 -0
@@ -4792,6 +4792,8 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)case OCS_MISMATCH_RESP_UPIU_SIZE :case OCS_PEER_COMM_FAILURE :case OCS_FATAL_ERROR : +case OCS_INVALID_CRYPTO_CONFIG : +case OCS_GENERAL_CRYPTO_ERROR :default : result |=DID_ERROR <<16 ; dev_err(hba->dev,
drivers/scsi/ufs/ufshcd.h +6 -0
@@ -564,6 +564,12 @@ enum ufshcd_caps {* provisioned to be used. This would increase the write performance. */ UFSHCD_CAP_WB_EN =1 <<7 , + +/* +* This capability allows the host controller driver to use the +* inline crypto engine, if it is present +*/ + UFSHCD_CAP_CRYPTO = 1 << 8, }; struct ufs_hba_variant_params {
drivers/scsi/ufs/ufshci.h +65 -2
106 lines not on this page · raw message
Signature · 1 line
2.27.0.290.gba653c62da-goog
Re: [PATCH 1/3] scsi: ufs: UFS driver v2.1 spec crypto additions
Quoted 6 lines · Satya Tangirala
Add the crypto registers and structs defined in v2.1 of the JEDEC UFSHCI specification in preparation to add support for inline encryption to UFS.
Signed-off-by Satya Tangirala <[email protected]>Reviewed-by Eric Biggers <[email protected]>
Stanley Chu had made a comment and provided a Reviewed-by at
https://lkml.kernel.org/linux-scsi/1589514936.3197.108.camel@mtkswgap22/.
Looks like that was missed?
- Eric
PATCH 2/3 scsi: ufs: UFS crypto API
In reply to Satya TangiralaIntroduce functions to manipulate UFS inline encryption hardware in line with the JEDEC UFSHCI v2.1 specification and to work with the block keyslot manager.
The UFS crypto API will assume by default that a vendor driver doesn't support UFS crypto, even if the hardware advertises the capability, because a lot of hardware requires some special handling that's not specified in the aforementioned JEDEC spec. Each vendor driver must explicity set hba->caps |= UFSHCD_CAP_CRYPTO before ufshcd_hba_init_crypto is called to opt-in to UFS crypto support.
--- drivers/scsi/ufs/Kconfig | 9 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufshcd-crypto.c | 226 +++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd-crypto.h | 42 ++++++ drivers/scsi/ufs/ufshcd.h | 12 ++ 5 files changed, 290 insertions(+) create mode 100644 drivers/scsi/ufs/ufshcd-crypto.c create mode 100644 drivers/scsi/ufs/ufshcd-crypto.h
drivers/scsi/ufs/Kconfig +9 -0
@@ -160,3 +160,12 @@ config SCSI_UFS_BSG Select this if you need a bsg device node for your UFS controller. If unsure, say N. + +config SCSI_UFS_CRYPTO + bool "UFS Crypto Engine Support" + depends on SCSI_UFSHCD && BLK_INLINE_ENCRYPTION + help + Enable Crypto Engine Support in UFS. + Enabling this makes it possible for the kernel to use the crypto + capabilities of the UFS device (if present) to perform crypto + operations on data being transferred to/from the device.
drivers/scsi/ufs/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o
drivers/scsi/ufs/ufshcd-crypto.c new file +226 -0
226 lines not on this page · raw message
drivers/scsi/ufs/ufshcd-crypto.h new file +42 -0
42 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +12 -0
@@ -57,6 +57,7 @@#include <linux/regulator/consumer.h> #include <linux/bitfield.h> #include <linux/devfreq.h> +#include <linux/keyslot-manager.h> #include "unipro.h" #include <asm/irq.h>
@@ -630,6 +631,10 @@ struct ufs_hba_variant_params {* @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for * device is known or not. * @scsi_block_reqs_cnt: reference counting for scsi block requests +* @crypto_capabilities: Content of crypto capabilities register (0x100) +* @crypto_cap_array: Array of crypto capabilities +* @crypto_cfg_register: Start of the crypto cfg array +* @ksm: the keyslot manager tied to this hba */ struct ufs_hba {void __iomem *mmio_base;
@@ -752,6 +757,13 @@ struct ufs_hba {bool wb_buf_flush_enabled;bool wb_enabled;struct delayed_work rpm_dev_flush_recheck_work; + +#ifdef CONFIG_SCSI_UFS_CRYPTO +union ufs_crypto_capabilities crypto_capabilities; +union ufs_crypto_cap_entry *crypto_cap_array; +u32 crypto_cfg_register; +struct blk_keyslot_manager ksm; +#endif };/* Returns true if clocks can be gated. Otherwise false */
Signature · 1 line
2.27.0.290.gba653c62da-goog
Re: [PATCH 2/3] scsi: ufs: UFS crypto API
Quoted 11 lines · Satya Tangirala
Introduce functions to manipulate UFS inline encryption hardware in line with the JEDEC UFSHCI v2.1 specification and to work with the block keyslot manager.
The UFS crypto API will assume by default that a vendor driver doesn't support UFS crypto, even if the hardware advertises the capability, because a lot of hardware requires some special handling that's not specified in the aforementioned JEDEC spec. Each vendor driver must explicity set
hba->caps|=UFSHCD_CAP_CRYPTObeforeufshcd_hba_init_cryptois called to opt-in to UFS crypto support.
Quoted 2 lines
Signed-off-by Satya Tangirala <[email protected]>Reviewed-by Eric Biggers <[email protected]>
Stanley Chu had made a comment and provided Reviewed-by at
https://lkml.kernel.org/linux-scsi/1589524526.3197.110.camel@mtkswgap22.
Looks like that was missed?
- Eric
PATCH 3/3 scsi: ufs: Add inline encryption support to UFS
In reply to Satya TangiralaWire up ufshcd.c with the UFS Crypto API, the block layer inline encryption additions and the keyslot manager.
--- drivers/scsi/ufs/ufshcd-crypto.h | 18 +++++++++++++ drivers/scsi/ufs/ufshcd.c | 44 ++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 6 +++++ 3 files changed, 63 insertions(+), 5 deletions(-)
drivers/scsi/ufs/ufshcd-crypto.h +18 -0
@@ -10,6 +10,20 @@#include "ufshcd.h" #include "ufshci.h" +static inline void ufshcd_prepare_lrbp_crypto (struct ufs_hba *hba, +struct scsi_cmnd *cmd, +struct ufshcd_lrb *lrbp) +{ +struct request *rq = cmd->request; + +if (rq->crypt_keyslot) { + lrbp->crypto_key_slot =blk_ksm_get_slot_idx (rq->crypt_keyslot); + lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0 ]; + }else { + lrbp->crypto_key_slot =-1 ; + } +} +bool ufshcd_crypto_enable (struct ufs_hba *hba);int ufshcd_hba_init_crypto (struct ufs_hba *hba);
@@ -21,6 +35,10 @@ void ufshcd_crypto_destroy_keyslot_manager(struct ufs_hba *hba);#else /* CONFIG_SCSI_UFS_CRYPTO */ +static inline void ufshcd_prepare_lrbp_crypto (struct ufs_hba *hba, +struct scsi_cmnd *cmd, +struct ufshcd_lrb *lrbp) { } +static inline bool ufshcd_crypto_enable (struct ufs_hba *hba) {return false;
drivers/scsi/ufs/ufshcd.c +39 -5
111 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +6 -0
@@ -184,6 +184,8 @@ struct ufs_pm_lvl_states {* @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation) * @issue_time_stamp: time stamp for debug purposes * @compl_time_stamp: time stamp for statistics +* @crypto_key_slot: the key slot to use for inline crypto (-1 if none) +* @data_unit_num: the data unit number for the first block for inline crypto * @req_abort_skip: skip request abort task flag */ struct ufshcd_lrb {
@@ -208,6 +210,10 @@ struct ufshcd_lrb {bool intr_cmd;ktime_t issue_time_stamp;ktime_t compl_time_stamp; +#ifdef CONFIG_SCSI_UFS_CRYPTO +int crypto_key_slot; +u64 data_unit_num; +#endif bool req_abort_skip; };
Signature · 1 line
2.27.0.290.gba653c62da-goog
Re: [PATCH 3/3] scsi: ufs: Add inline encryption support to UFS
Quoted 4 lines · Satya Tangirala
Wire up
ufshcd.cwith the UFS Crypto API, the block layer inline encryption additions and the keyslot manager.Signed-off-by Satya Tangirala <[email protected]>
I had also given Reviewed-by on this one; looks like that was missed as well :-)
https://lkml.kernel.org/linux-scsi/[email protected]/
- Eric
Re: [PATCH 3/3] scsi: ufs: Add inline encryption support to UFS
Quoted 10 lines · Eric Biggers
Quoted 4 lines · Satya Tangirala
Wire up
ufshcd.cwith the UFS Crypto API, the block layer inline encryption additions and the keyslot manager.Signed-off-by Satya Tangirala <[email protected]>I had also given Reviewed-by on this one; looks like that was missed as well :-)
The UFS comments slipped my mind entirely :( - I addressed them this time.
Quoted 1 line
- Eric
Quoted 21 lines · Satya Tangirala
This patch series adds support for inline encryption to UFS using the inline encryption support in the block layer. It follows the JEDEC UFSHCI v2.1 specification, which defines inline encryption for UFS. This patch series is based on v5.8-rc1.
Patch 1 introduces the crypto registers and struct definitions defined in the UFSHCI v2.1 spec.
Patch 2 introduces functions to manipulate the UFS inline encryption hardware (again in line with the UFSHCI v2.1 spec) via the block layer keyslot manager. Device specific drivers must set the
UFSHCD_CAP_CRYPTOinhba->capsbeforeufshcd_hba_init_cryptois called to opt-in to inline encryption support.Patch 3 wires up
ufshcd.cwith the UFS crypto API introduced in Patch 2.Satya Tangirala (3):
scsi: ufs: UFS driver v2.1 spec crypto additions
scsi: ufs: UFS crypto API
scsi: ufs: Add inline encryption support to UFS
Quoted 10 lines
drivers/scsi/ufs/Kconfig | 9 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufshcd-crypto.c | 226 +++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd-crypto.h | 60 ++++++++ drivers/scsi/ufs/ufshcd.c | 46 ++++++- drivers/scsi/ufs/ufshcd.h | 24 ++++ drivers/scsi/ufs/ufshci.h | 67 ++++++++- 7 files changed, 426 insertions(+), 7 deletions(-) create mode 100644 drivers/scsi/ufs/ufshcd-crypto.c create mode 100644 drivers/scsi/ufs/ufshcd-crypto.h
Note that these patches previously went through a number of iterations as part of the "Inline Encryption Support" patchset (last version was v13:
https://lkml.kernel.org/r/[email protected]). There are no significant changes from v13, right? It would be helpful to mention this in the cover letter.
It would also be helpful to describe how this was tested at least in the cover letter, but maybe in one of the commit messages too. For example I and two other people have tested the Qualcomm ICE support on top of this with
https://lkml.kernel.org/linux-scsi/[email protected]/.
(BTW, I'll be rebasing, re-testing, and re-sending those patches soon.) Mediatek has also tested this with
https://lkml.kernel.org/linux-scsi/[email protected]/.
- Eric