* [PATCH RESEND v4] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
@ 2026-05-29 9:26 Neeraj Soni
2026-05-29 10:19 ` Jie Gan
0 siblings, 1 reply; 4+ messages in thread
From: Neeraj Soni @ 2026-05-29 9:26 UTC (permalink / raw)
To: ebiggers, ulf.hansson, adrian.hunter
Cc: quic_dmukhopa, quic_rampraka, quic_nitirawa, quic_sachgupt,
quic_bhaskarv, quic_gaurkash, quic_sartgarg, linux-mmc,
linux-kernel, linux-arm-msm, neeraj.soni
From: Debraj Mukhopadhyay <quic_dmukhopa@quicinc.com>
Crypto reprogram all keys is called for each MMC runtime
suspend/resume in current upstream design. If this is implemented
as a non-interruptible call to TEE for security, the cpu core is
blocked for execution while this call executes although the crypto
engine already has the keys. For example, glitches in audio/video
streaming applications have been observed due to this. Add the flag
MMC_CAP2_CRYPTO_NO_REPROG as part of host->caps2 to control reprogramming
keys to crypto engine for socs which dont require this feature.
Signed-off-by: Seshu Madhavi Puppala <quic_spuppala@quicinc.com>
Co-developed-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
Co-developed-by: Sarthak Garg <quic_sartgarg@quicinc.com>
Signed-off-by: Sarthak Garg <quic_sartgarg@quicinc.com>
Signed-off-by: Debraj Mukhopadhyay <quic_dmukhopa@quicinc.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20260116121004.1829223-1-neeraj.soni@oss.qualcomm.com
Signed-off-by: Neeraj Soni <neeraj.soni@oss.qualcomm.com>
---
drivers/mmc/core/crypto.c | 2 +-
drivers/mmc/host/sdhci-msm.c | 6 ++++++
include/linux/mmc/host.h | 5 +----
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c
index fec4fbf16a5b..a5a90bfc634e 100644
--- a/drivers/mmc/core/crypto.c
+++ b/drivers/mmc/core/crypto.c
@@ -15,7 +15,7 @@
void mmc_crypto_set_initial_state(struct mmc_host *host)
{
/* Reset might clear all keys, so reprogram all the keys. */
- if (host->caps2 & MMC_CAP2_CRYPTO)
+ if ((host->caps2 & MMC_CAP2_CRYPTO) && !(host->caps2 & MMC_CAP2_CRYPTO_NO_REPROG))
blk_crypto_reprogram_all_keys(&host->crypto_profile);
}
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 4e5edbf2fc9b..2ccb63dde9c1 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -1949,6 +1949,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
}
mmc->caps2 |= MMC_CAP2_CRYPTO;
+ mmc->caps2 |= MMC_CAP2_CRYPTO_NO_REPROG;
return 0;
}
@@ -2526,6 +2527,11 @@ static int sdhci_msm_gcc_reset(struct device *dev, struct sdhci_host *host)
usleep_range(200, 210);
reset_control_put(reset);
+#ifdef CONFIG_MMC_CRYPTO
+ if (host->mmc->caps2 & MMC_CAP2_CRYPTO)
+ blk_crypto_reprogram_all_keys(&host->mmc->crypto_profile);
+#endif
+
return ret;
}
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index e0e2c265e5d1..2fd76f966e24 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -457,12 +457,9 @@ struct mmc_host {
#define MMC_CAP2_CQE_DCMD (1 << 24) /* CQE can issue a direct command */
#define MMC_CAP2_AVOID_3_3V (1 << 25) /* Host must negotiate down from 3.3V */
#define MMC_CAP2_MERGE_CAPABLE (1 << 26) /* Host can merge a segment over the segment size */
-#ifdef CONFIG_MMC_CRYPTO
#define MMC_CAP2_CRYPTO (1 << 27) /* Host supports inline encryption */
-#else
-#define MMC_CAP2_CRYPTO 0
-#endif
#define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT entry at a non-standard location */
+#define MMC_CAP2_CRYPTO_NO_REPROG (1 << 29) /* Host handles inline crypto key reprogramming */
bool uhs2_sd_tran; /* UHS-II flag for SD_TRAN state */
bool uhs2_app_cmd; /* UHS-II flag for APP command */
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH RESEND v4] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
2026-05-29 9:26 [PATCH RESEND v4] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume Neeraj Soni
@ 2026-05-29 10:19 ` Jie Gan
2026-05-29 10:35 ` Neeraj Soni
0 siblings, 1 reply; 4+ messages in thread
From: Jie Gan @ 2026-05-29 10:19 UTC (permalink / raw)
To: Neeraj Soni, ebiggers, ulf.hansson, adrian.hunter
Cc: quic_dmukhopa, quic_rampraka, quic_nitirawa, quic_sachgupt,
quic_bhaskarv, quic_gaurkash, quic_sartgarg, linux-mmc,
linux-kernel, linux-arm-msm
On 5/29/2026 5:26 PM, Neeraj Soni wrote:
> From: Debraj Mukhopadhyay <quic_dmukhopa@quicinc.com>
>
> Crypto reprogram all keys is called for each MMC runtime
> suspend/resume in current upstream design. If this is implemented
> as a non-interruptible call to TEE for security, the cpu core is
> blocked for execution while this call executes although the crypto
> engine already has the keys. For example, glitches in audio/video
> streaming applications have been observed due to this. Add the flag
> MMC_CAP2_CRYPTO_NO_REPROG as part of host->caps2 to control reprogramming
> keys to crypto engine for socs which dont require this feature.
>
> Signed-off-by: Seshu Madhavi Puppala <quic_spuppala@quicinc.com>
> Co-developed-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
> Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
> Co-developed-by: Sarthak Garg <quic_sartgarg@quicinc.com>
> Signed-off-by: Sarthak Garg <quic_sartgarg@quicinc.com>
> Signed-off-by: Debraj Mukhopadhyay <quic_dmukhopa@quicinc.com>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
> Link: https://lore.kernel.org/r/20260116121004.1829223-1-neeraj.soni@oss.qualcomm.com
> Signed-off-by: Neeraj Soni <neeraj.soni@oss.qualcomm.com>
> ---
> drivers/mmc/core/crypto.c | 2 +-
> drivers/mmc/host/sdhci-msm.c | 6 ++++++
> include/linux/mmc/host.h | 5 +----
> 3 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c
> index fec4fbf16a5b..a5a90bfc634e 100644
> --- a/drivers/mmc/core/crypto.c
> +++ b/drivers/mmc/core/crypto.c
> @@ -15,7 +15,7 @@
> void mmc_crypto_set_initial_state(struct mmc_host *host)
> {
> /* Reset might clear all keys, so reprogram all the keys. */
> - if (host->caps2 & MMC_CAP2_CRYPTO)
> + if ((host->caps2 & MMC_CAP2_CRYPTO) && !(host->caps2 & MMC_CAP2_CRYPTO_NO_REPROG))
> blk_crypto_reprogram_all_keys(&host->crypto_profile);
> }
>
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 4e5edbf2fc9b..2ccb63dde9c1 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -1949,6 +1949,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
> }
>
> mmc->caps2 |= MMC_CAP2_CRYPTO;
> + mmc->caps2 |= MMC_CAP2_CRYPTO_NO_REPROG;
> return 0;
> }
>
> @@ -2526,6 +2527,11 @@ static int sdhci_msm_gcc_reset(struct device *dev, struct sdhci_host *host)
> usleep_range(200, 210);
> reset_control_put(reset);
>
> +#ifdef CONFIG_MMC_CRYPTO
> + if (host->mmc->caps2 & MMC_CAP2_CRYPTO)
Always false at this point. The first set of the host->mmc->caps2 is
later in the sdhci_msm_cqe_add_host.
Thanks,
Jie
> + blk_crypto_reprogram_all_keys(&host->mmc->crypto_profile);
> +#endif
> +
> return ret;
> }
>
> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> index e0e2c265e5d1..2fd76f966e24 100644
> --- a/include/linux/mmc/host.h
> +++ b/include/linux/mmc/host.h
> @@ -457,12 +457,9 @@ struct mmc_host {
> #define MMC_CAP2_CQE_DCMD (1 << 24) /* CQE can issue a direct command */
> #define MMC_CAP2_AVOID_3_3V (1 << 25) /* Host must negotiate down from 3.3V */
> #define MMC_CAP2_MERGE_CAPABLE (1 << 26) /* Host can merge a segment over the segment size */
> -#ifdef CONFIG_MMC_CRYPTO
> #define MMC_CAP2_CRYPTO (1 << 27) /* Host supports inline encryption */
> -#else
> -#define MMC_CAP2_CRYPTO 0
> -#endif
> #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT entry at a non-standard location */
> +#define MMC_CAP2_CRYPTO_NO_REPROG (1 << 29) /* Host handles inline crypto key reprogramming */
>
> bool uhs2_sd_tran; /* UHS-II flag for SD_TRAN state */
> bool uhs2_app_cmd; /* UHS-II flag for APP command */
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH RESEND v4] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
2026-05-29 10:19 ` Jie Gan
@ 2026-05-29 10:35 ` Neeraj Soni
2026-07-23 23:01 ` Eric Biggers
0 siblings, 1 reply; 4+ messages in thread
From: Neeraj Soni @ 2026-05-29 10:35 UTC (permalink / raw)
To: Jie Gan, ebiggers, ulf.hansson, adrian.hunter
Cc: quic_dmukhopa, quic_rampraka, quic_nitirawa, quic_sachgupt,
quic_bhaskarv, quic_gaurkash, quic_sartgarg, linux-mmc,
linux-kernel, linux-arm-msm
On 5/29/2026 3:49 PM, Jie Gan wrote:
>
>
> On 5/29/2026 5:26 PM, Neeraj Soni wrote:
>> From: Debraj Mukhopadhyay <quic_dmukhopa@quicinc.com>
>>
>> Crypto reprogram all keys is called for each MMC runtime
>> suspend/resume in current upstream design. If this is implemented
>> as a non-interruptible call to TEE for security, the cpu core is
>> blocked for execution while this call executes although the crypto
>> engine already has the keys. For example, glitches in audio/video
>> streaming applications have been observed due to this. Add the flag
>> MMC_CAP2_CRYPTO_NO_REPROG as part of host->caps2 to control reprogramming
>> keys to crypto engine for socs which dont require this feature.
>>
>> Signed-off-by: Seshu Madhavi Puppala <quic_spuppala@quicinc.com>
>> Co-developed-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
>> Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
>> Co-developed-by: Sarthak Garg <quic_sartgarg@quicinc.com>
>> Signed-off-by: Sarthak Garg <quic_sartgarg@quicinc.com>
>> Signed-off-by: Debraj Mukhopadhyay <quic_dmukhopa@quicinc.com>
>> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
>> Link: https://lore.kernel.org/r/20260116121004.1829223-1-neeraj.soni@oss.qualcomm.com
>> Signed-off-by: Neeraj Soni <neeraj.soni@oss.qualcomm.com>
>> ---
>> drivers/mmc/core/crypto.c | 2 +-
>> drivers/mmc/host/sdhci-msm.c | 6 ++++++
>> include/linux/mmc/host.h | 5 +----
>> 3 files changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c
>> index fec4fbf16a5b..a5a90bfc634e 100644
>> --- a/drivers/mmc/core/crypto.c
>> +++ b/drivers/mmc/core/crypto.c
>> @@ -15,7 +15,7 @@
>> void mmc_crypto_set_initial_state(struct mmc_host *host)
>> {
>> /* Reset might clear all keys, so reprogram all the keys. */
>> - if (host->caps2 & MMC_CAP2_CRYPTO)
>> + if ((host->caps2 & MMC_CAP2_CRYPTO) && !(host->caps2 & MMC_CAP2_CRYPTO_NO_REPROG))
>> blk_crypto_reprogram_all_keys(&host->crypto_profile);
>> }
>> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
>> index 4e5edbf2fc9b..2ccb63dde9c1 100644
>> --- a/drivers/mmc/host/sdhci-msm.c
>> +++ b/drivers/mmc/host/sdhci-msm.c
>> @@ -1949,6 +1949,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
>> }
>> mmc->caps2 |= MMC_CAP2_CRYPTO;
>> + mmc->caps2 |= MMC_CAP2_CRYPTO_NO_REPROG;
>> return 0;
>> }
>> @@ -2526,6 +2527,11 @@ static int sdhci_msm_gcc_reset(struct device *dev, struct sdhci_host *host)
>> usleep_range(200, 210);
>> reset_control_put(reset);
>> +#ifdef CONFIG_MMC_CRYPTO
>> + if (host->mmc->caps2 & MMC_CAP2_CRYPTO)
>
> Always false at this point. The first set of the host->mmc->caps2 is later in the sdhci_msm_cqe_add_host.
>
Yes for cold boot this is true and Crypto reprogram is not needed. This patch addreses the use cases like
runtime suspend resume, deep sleep / Quick boot (DS/QB) and suspend to disk (aka hibernation) use cases
where the runtime context is preserved either in dynamic memory (DS/QB) or in secondry memory (hibernation).
This is tested internally on SAR1250P chipset for hibernation and DS/QB.
> Thanks,
> Jie
>
>> + blk_crypto_reprogram_all_keys(&host->mmc->crypto_profile);
>> +#endif
>> +
>> return ret;
>> }
>> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
>> index e0e2c265e5d1..2fd76f966e24 100644
>> --- a/include/linux/mmc/host.h
>> +++ b/include/linux/mmc/host.h
>> @@ -457,12 +457,9 @@ struct mmc_host {
>> #define MMC_CAP2_CQE_DCMD (1 << 24) /* CQE can issue a direct command */
>> #define MMC_CAP2_AVOID_3_3V (1 << 25) /* Host must negotiate down from 3.3V */
>> #define MMC_CAP2_MERGE_CAPABLE (1 << 26) /* Host can merge a segment over the segment size */
>> -#ifdef CONFIG_MMC_CRYPTO
>> #define MMC_CAP2_CRYPTO (1 << 27) /* Host supports inline encryption */
>> -#else
>> -#define MMC_CAP2_CRYPTO 0
>> -#endif
>> #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT entry at a non-standard location */
>> +#define MMC_CAP2_CRYPTO_NO_REPROG (1 << 29) /* Host handles inline crypto key reprogramming */
>> bool uhs2_sd_tran; /* UHS-II flag for SD_TRAN state */
>> bool uhs2_app_cmd; /* UHS-II flag for APP command */
>
Regards
Neeraj
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH RESEND v4] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
2026-05-29 10:35 ` Neeraj Soni
@ 2026-07-23 23:01 ` Eric Biggers
0 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2026-07-23 23:01 UTC (permalink / raw)
To: Neeraj Soni
Cc: Jie Gan, ulf.hansson, adrian.hunter, quic_dmukhopa, quic_rampraka,
quic_nitirawa, quic_sachgupt, quic_bhaskarv, quic_gaurkash,
quic_sartgarg, linux-mmc, linux-kernel, linux-arm-msm
On Fri, May 29, 2026 at 04:05:52PM +0530, Neeraj Soni wrote:
> Yes for cold boot this is true and Crypto reprogram is not needed. This patch addreses the use cases like
> runtime suspend resume, deep sleep / Quick boot (DS/QB) and suspend to disk (aka hibernation) use cases
> where the runtime context is preserved either in dynamic memory (DS/QB) or in secondry memory (hibernation).
> This is tested internally on SAR1250P chipset for hibernation and DS/QB.
But sdhci_msm_gcc_reset() is called only from the driver probe function
(sdhci_msm_probe()), before MMC_CAP2_CRYPTO is set. So Jie's comment is
correct: the new key reprogramming path is dead code. And as per the
following comment, key reprogramming is still needed in some cases
(https://lore.kernel.org/linux-mmc/42797330-868a-bfcd-e0bb-b5f0dd3eeb16@oss.qualcomm.com/).
So doesn't this patch break the sdhci-msm driver?
I'm also skeptical of the following change, which seems unrelated to the
rest of the patch:
> -#ifdef CONFIG_MMC_CRYPTO
> #define MMC_CAP2_CRYPTO (1 << 27) /* Host supports inline encryption */
> -#else
> -#define MMC_CAP2_CRYPTO 0
> -#endif
Because of that, mtk-sd sets MMC_CAP2_CRYPTO even when
CONFIG_MMC_CRYPTO=n. That makes CQHCI_CRYPTO_GENERAL_ENABLE be used
even when CONFIG_MMC_CRYPTO=n.
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-23 23:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 9:26 [PATCH RESEND v4] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume Neeraj Soni
2026-05-29 10:19 ` Jie Gan
2026-05-29 10:35 ` Neeraj Soni
2026-07-23 23:01 ` Eric Biggers
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.