* [PATCH v2] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
@ 2025-06-06 10:47 Debraj Mukhopadhyay
2025-06-06 17:59 ` Eric Biggers
0 siblings, 1 reply; 3+ messages in thread
From: Debraj Mukhopadhyay @ 2025-06-06 10:47 UTC (permalink / raw)
To: Ulf Hansson, Adrian Hunter
Cc: linux-mmc, linux-kernel, linux-arm-msm, kernel, Eric Biggers,
Neeraj Soni, Debraj Mukhopadhyay, Ram Prakash Gupta, Nitin Rawat,
Sachin Gupta, Bhaskar Valaboju, Gaurav Kashyap, Sarthak Garg,
Seshu Madhavi Puppala
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_DONT_REPROGRAM 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>
---
Changes in v2:
- Renamed MMC_CAP2_DONT_REPROGRAM to MMC_CAP2_CRYPTO_NO_REPROG for
improved clarity.
- Defined MMC_CAP2_CRYPTO_NO_REPROG for MMC targets that do not support
a Crypto Engine.
- Restricted the usage of struct crypto_profile to MMC devices that
support a Crypto Engine.
Changes in v1:
- Addressed the comments from:
https://lore.kernel.org/lkml/20241006135530.17363-3-
quic_spuppala@quicinc.com/T/#m69c9ab538bd9efd54515646952d0d7d1d7c17690
- Avoided reprogram of keys for Qualcomm SOCs only.
- Ensured reprogram of all keys on host controller reset.
---
drivers/mmc/core/crypto.c | 2 +-
drivers/mmc/host/sdhci-msm.c | 6 ++++++
include/linux/mmc/host.h | 5 +++++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c
index fec4fbf16a5b..d41672e2856e 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 66c0d1ba2a33..ee6783555f2e 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -1920,6 +1920,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;
}
@@ -2497,6 +2498,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 68f09a955a90..af3b3720aa9c 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -459,6 +459,11 @@ struct mmc_host {
#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 */
+#ifdef CONFIG_MMC_CRYPTO
+#define MMC_CAP2_CRYPTO_NO_REPROG (1 << 29) /* Host does not support inline crypto key reprogramming */
+#else
+#define MMC_CAP2_CRYPTO_NO_REPROG 0
+#endif
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] 3+ messages in thread
* Re: [PATCH v2] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
2025-06-06 10:47 [PATCH v2] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume Debraj Mukhopadhyay
@ 2025-06-06 17:59 ` Eric Biggers
2025-07-10 7:58 ` Debraj Mukhopadhyay
0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2025-06-06 17:59 UTC (permalink / raw)
To: Debraj Mukhopadhyay
Cc: Ulf Hansson, Adrian Hunter, linux-mmc, linux-kernel,
linux-arm-msm, kernel, Neeraj Soni, Ram Prakash Gupta,
Nitin Rawat, Sachin Gupta, Bhaskar Valaboju, Gaurav Kashyap,
Sarthak Garg, Seshu Madhavi Puppala
On Fri, Jun 06, 2025 at 04:17:14PM +0530, Debraj Mukhopadhyay wrote:
> Crypto reprogram all keys is called for each MMC runtime
> suspend/resume in current upstream design.
It's called from mmc_set_initial_state(), which is documented as:
/*
* Set initial state after a power cycle or a hw_reset.
*/
Please clarify how that corresponds to "MMC runtime suspend/resume".
> streaming applications have been observed due to this. Add the flag
> MMC_CAP2_DONT_REPROGRAM as part of host->caps2 to control reprogramming
> keys to crypto engine for socs which dont require this feature.
The flag has a different name in the code.
> diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c
> index fec4fbf16a5b..d41672e2856e 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);
Add parentheses around 'host->caps2 & MMC_CAP2_CRYPTO'
> +#ifdef CONFIG_MMC_CRYPTO
> +#define MMC_CAP2_CRYPTO_NO_REPROG (1 << 29) /* Host does not support inline crypto key reprogramming */
> +#else
> +#define MMC_CAP2_CRYPTO_NO_REPROG 0
> +#endif
Well, it does support inline crypto key reprogramming. It just doesn't want the
MMC core driver to handle it. Please update the comment to something like:
/* Host driver handles crypto key reprogramming */
- Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume
2025-06-06 17:59 ` Eric Biggers
@ 2025-07-10 7:58 ` Debraj Mukhopadhyay
0 siblings, 0 replies; 3+ messages in thread
From: Debraj Mukhopadhyay @ 2025-07-10 7:58 UTC (permalink / raw)
To: Eric Biggers
Cc: Ulf Hansson, Adrian Hunter, linux-mmc, linux-kernel,
linux-arm-msm, kernel, Neeraj Soni, Ram Prakash Gupta,
Nitin Rawat, Sachin Gupta, Bhaskar Valaboju, Gaurav Kashyap,
Sarthak Garg
Hi Eric,
Thanks for the review.
Clarifications are given inline below.
On 6/6/2025 11:29 PM, Eric Biggers wrote:
> On Fri, Jun 06, 2025 at 04:17:14PM +0530, Debraj Mukhopadhyay wrote:
>> Crypto reprogram all keys is called for each MMC runtime
>> suspend/resume in current upstream design.
> It's called from mmc_set_initial_state(), which is documented as:
>
> /*
> * Set initial state after a power cycle or a hw_reset.
> */
>
> Please clarify how that corresponds to "MMC runtime suspend/resume".
As part of suspend/resume, mmc regulators are turned off/on -
effectively performing a power cycle, and hence mmc_set_initial_state is
called after runtime suspend/resume.
Call flow:
Suspend: mmc_runtime_suspend() → _mmc_suspend() → mmc_power_off() →
mmc_set_initial_state()
Resume: mmc_runtime_resume() → _mmc_resume() → mmc_power_up() →
mmc_set_initial_state()
>> streaming applications have been observed due to this. Add the flag
>> MMC_CAP2_DONT_REPROGRAM as part of host->caps2 to control reprogramming
>> keys to crypto engine for socs which dont require this feature.
> The flag has a different name in the code.
Ack, will be addressed in the v3 patch.
>> diff --git a/drivers/mmc/core/crypto.c b/drivers/mmc/core/crypto.c
>> index fec4fbf16a5b..d41672e2856e 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);
> Add parentheses around 'host->caps2 & MMC_CAP2_CRYPTO'
Ack, will be addressed in the v3 patch.
>> +#ifdef CONFIG_MMC_CRYPTO
>> +#define MMC_CAP2_CRYPTO_NO_REPROG (1 << 29) /* Host does not support inline crypto key reprogramming */
>> +#else
>> +#define MMC_CAP2_CRYPTO_NO_REPROG 0
>> +#endif
> Well, it does support inline crypto key reprogramming. It just doesn't want the
> MMC core driver to handle it. Please update the comment to something like:
> /* Host driver handles crypto key reprogramming */
>
> - Eric
Ack, will be addressed in the v3 patch.
Thanks,
Debraj
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-10 7:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 10:47 [PATCH v2] mmc: Avoid reprogram all keys to Inline Crypto Engine for MMC runtime suspend resume Debraj Mukhopadhyay
2025-06-06 17:59 ` Eric Biggers
2025-07-10 7:58 ` Debraj Mukhopadhyay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).