* [PATCH 2/2] ufs: core: remove encrypt when no data transfer
@ 2022-10-11 7:21 Ten Gao
2022-10-11 16:57 ` Eric Biggers
0 siblings, 1 reply; 2+ messages in thread
From: Ten Gao @ 2022-10-11 7:21 UTC (permalink / raw)
To: Alim Akhtar, Avri Altman, Bart Van Assche,
James E . J . Bottomley, Bean Huo, Adrian Hunter
Cc: Martin K . Petersen, Mike Snitzer, Ulf Hansson, Eric Biggers,
Kiwoong Kim, linux-scsi, linux-kernel
From: Ten Gao <ten.gao@unisoc.com>
when there is no data transmission, ufs is unnecessary to encrypt.
We need to adjust scsi crypto relation.
Signed-off-by: Ten Gao <ten.gao@unisoc.com>
---
drivers/ufs/core/ufshcd-crypto.h | 10 ++++++----
include/ufs/ufshci.h | 2 ++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/ufs/core/ufshcd-crypto.h b/drivers/ufs/core/ufshcd-crypto.h
index 504cc841540b..5bc2a0cbdfa6 100644
--- a/drivers/ufs/core/ufshcd-crypto.h
+++ b/drivers/ufs/core/ufshcd-crypto.h
@@ -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);
+ }
}
}
diff --git a/include/ufs/ufshci.h b/include/ufs/ufshci.h
index f525566a0864..7dbfeecaa36c 100644
--- a/include/ufs/ufshci.h
+++ b/include/ufs/ufshci.h
@@ -387,6 +387,8 @@ enum {
UTP_DEVICE_TO_HOST = 0x04000000,
};
+#define UTRD_DIRECTION 0x6000000
+
/* Overall command status values */
enum utp_ocs {
OCS_SUCCESS = 0x0,
--
2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2/2] ufs: core: remove encrypt when no data transfer
2022-10-11 7:21 [PATCH 2/2] ufs: core: remove encrypt when no data transfer Ten Gao
@ 2022-10-11 16:57 ` Eric Biggers
0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2022-10-11 16:57 UTC (permalink / raw)
To: Ten Gao
Cc: Alim Akhtar, Avri Altman, Bart Van Assche,
James E . J . Bottomley, Bean Huo, Adrian Hunter,
Martin K . Petersen, Mike Snitzer, Ulf Hansson, Kiwoong Kim,
linux-scsi, linux-kernel
On Tue, Oct 11, 2022 at 03:21:26PM +0800, Ten Gao wrote:
> From: Ten Gao <ten.gao@unisoc.com>
>
> when there is no data transmission, ufs is unnecessary to encrypt.
> We need to adjust scsi crypto relation.
>
> Signed-off-by: Ten Gao <ten.gao@unisoc.com>
> ---
> drivers/ufs/core/ufshcd-crypto.h | 10 ++++++----
> include/ufs/ufshci.h | 2 ++
> 2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/ufs/core/ufshcd-crypto.h b/drivers/ufs/core/ufshcd-crypto.h
> index 504cc841540b..5bc2a0cbdfa6 100644
> --- a/drivers/ufs/core/ufshcd-crypto.h
> +++ b/drivers/ufs/core/ufshcd-crypto.h
> @@ -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);
> + }
> }
> }
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-11 16:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 7:21 [PATCH 2/2] ufs: core: remove encrypt when no data transfer Ten Gao
2022-10-11 16:57 ` Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®