From: "Sverdlin, Alexander" <alexander.sverdlin@siemens.com>
To: "Haener, Michael" <michael.haener@siemens.com>,
"ulfh@kernel.org" <ulfh@kernel.org>
Cc: "ziniu.wang_1@nxp.com" <ziniu.wang_1@nxp.com>,
"avri.altman@sandisk.com" <avri.altman@sandisk.com>,
"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] mmc: core: saturate erase timeout instead of overflowing
Date: Thu, 26 Nov 2026 15:17:48 +0000 [thread overview]
Message-ID: <a939387aedf0ab45a07b370a56ea735999deb115.camel@siemens.com> (raw)
In-Reply-To: <20261111120759.100830-3-michael.haener@siemens.com>
Hi!
On Wed, 2026-11-11 at 13:07 +0100, Michael Haener wrote:
> With MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME, secure erase/trim requests
> are no longer limited by max_discard, so mmc_mmc_erase_timeout() can be
> called with a qty of several thousand erase groups. The timeout is then
> computed as erase_timeout * sec_erase_mult * qty in 32-bit arithmetic.
>
> With 512KiB erase groups the block layer limits a request to about 4096
> groups, so the product overflows once ERASE_TIMEOUT_MULT * SEC_ERASE_MULT
> exceeds about 3496. The wrapped value can be much shorter than the real
> erase time, making the busy polling give up early with -ETIMEDOUT. No
> card in the quirk list is known to reach that limit today.
>
> Use check_mul_overflow() and saturate at UINT_MAX.
>
> Signed-off-by: Michael Haener <michael.haener@siemens.com>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
> ---
> drivers/mmc/core/core.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 677e445dc48c..9730633dfa81 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -24,6 +24,7 @@
> #include <linux/random.h>
> #include <linux/slab.h>
> #include <linux/of.h>
> +#include <linux/overflow.h>
>
> #include <linux/mmc/card.h>
> #include <linux/mmc/host.h>
> @@ -1568,13 +1569,21 @@ static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
>
> /* Multiplier for secure operations */
> if (arg & MMC_SECURE_ARGS) {
> - if (arg == MMC_SECURE_ERASE_ARG)
> - erase_timeout *= card->ext_csd.sec_erase_mult;
> - else
> - erase_timeout *= card->ext_csd.sec_trim_mult;
> + unsigned int mult = arg == MMC_SECURE_ERASE_ARG ?
> + card->ext_csd.sec_erase_mult :
> + card->ext_csd.sec_trim_mult;
> +
> + if (check_mul_overflow(erase_timeout, mult, &erase_timeout))
> + erase_timeout = UINT_MAX;
> }
>
> - erase_timeout *= qty;
> + /*
> + * With MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME, qty is no longer bound
> + * by max_busy_timeout, so the product can exceed 32 bits. Saturate
> + * instead of wrapping to a too short timeout.
> + */
> + if (check_mul_overflow(erase_timeout, qty, &erase_timeout))
> + erase_timeout = UINT_MAX;
>
> /*
> * Ensure at least a 1 second timeout for SPI as per
--
Alexander Sverdlin
Siemens AG
www.siemens.com
prev parent reply other threads:[~2026-11-26 15:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:07 [PATCH 0/2] mmc: speed up secure erase on ISSI IS22TF128G eMMC Michael Haener
2026-11-11 12:07 ` [PATCH 1/2] mmc: add ISSI IS22TF128G to fixed secure erase time quirk Michael Haener
2026-11-26 15:17 ` Sverdlin, Alexander
2026-11-11 12:07 ` [PATCH 2/2] mmc: core: saturate erase timeout instead of overflowing Michael Haener
2026-11-26 15:17 ` Sverdlin, Alexander [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a939387aedf0ab45a07b370a56ea735999deb115.camel@siemens.com \
--to=alexander.sverdlin@siemens.com \
--cc=avri.altman@sandisk.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=michael.haener@siemens.com \
--cc=ulfh@kernel.org \
--cc=ziniu.wang_1@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®