Skip to contentSkip to conversation

ufs: core: remove encrypt when no data transfer

PATCH In review Ten Gao 2 participants 2 messages Oct 11, 2022

Subsystems (2)
lore
Share & tools
lore

Ten Gao

author
#0 lore raw

PATCH 2/2 ufs: core: remove encrypt when no data transfer

From: Ten Gao <[email protected]>

when there is no data transmission, ufs is unnecessary to encrypt. We need to adjust scsi crypto relation.

---
 drivers/ufs/core/ufshcd-crypto.h | 10 ++++++----
 include/ufs/ufshci.h             |  2 ++
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd-crypto.h +6 -4
index 504cc841540b..5bc2a0cbdfa6 100644
@@ -30,10 +30,12 @@ ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
 				   u32 *dword_1, u32 *dword_3)
 {
 	if (lrbp->crypto_key_slot >= 0) {
-		*dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
-		*dword_0 |= lrbp->crypto_key_slot;
-		*dword_1 = lower_32_bits(lrbp->data_unit_num);
-		*dword_3 = upper_32_bits(lrbp->data_unit_num);
+		if ((*dword_0 & UTRD_DIRECTION) != UTP_NO_DATA_TRANSFER) {
+			*dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
+			*dword_0 |= lrbp->crypto_key_slot;
+			*dword_1 = lower_32_bits(lrbp->data_unit_num);
+			*dword_3 = upper_32_bits(lrbp->data_unit_num);
+		}
 	}
 }
 
include/ufs/ufshci.h +2 -0
index f525566a0864..7dbfeecaa36c 100644
@@ -387,6 +387,8 @@ enum {
 	UTP_DEVICE_TO_HOST	= 0x04000000,
 };
 
+#define UTRD_DIRECTION	0x6000000
+
 /* Overall command status values */
 enum utp_ocs {
 	OCS_SUCCESS			= 0x0,
Signature · 1 line
2.17.1
#1 lore raw
Quoted 21 lines · Ten Gao

From: Ten Gao <[email protected]>

when there is no data transmission, ufs is unnecessary to encrypt. We need to adjust scsi crypto relation.

---
 drivers/ufs/core/ufshcd-crypto.h | 10 ++++++----
 include/ufs/ufshci.h             |  2 ++
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd-crypto.h +0 -2
index 504cc841540b..5bc2a0cbdfa6 100644
@@ -30,10 +30,12 @@ ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
 				   u32 *dword_1, u32 *dword_3)
 {
 	if (lrbp->crypto_key_slot >= 0) {
-		*dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
-		*dword_0 |= lrbp->crypto_key_slot;

drivers/ufs/core/ufshcd-crypto.h ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0, · line 40

Quoted 10 lines
drivers/ufs/core/ufshcd-crypto.h +6 -2
-		*dword_1 = lower_32_bits(lrbp->data_unit_num);
-		*dword_3 = upper_32_bits(lrbp->data_unit_num);
+		if ((*dword_0 & UTRD_DIRECTION) != UTP_NO_DATA_TRANSFER) {
+			*dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
+			*dword_0 |= lrbp->crypto_key_slot;
+			*dword_1 = lower_32_bits(lrbp->data_unit_num);
+			*dword_3 = upper_32_bits(lrbp->data_unit_num);
+		}
 	}
 }

This is very dangerous, as it will silently skip en/decryption. Why was a keyslot assigned in the first place if the I/O doesn't need en/decryption?

- Eric