* [PATCH v2] mmc: core: don't initialize block size from ext_csd if not present
@ 2021-01-14 20:14 Peter Collingbourne
2021-01-15 8:06 ` Adrian Hunter
2021-01-15 12:21 ` Ulf Hansson
0 siblings, 2 replies; 3+ messages in thread
From: Peter Collingbourne @ 2021-01-14 20:14 UTC (permalink / raw)
To: Adrian Hunter, Christoph Hellwig, Linus Walleij, Ulf Hansson
Cc: Peter Collingbourne, linux-mmc, Damien Le Moal
If extended CSD was not available, the eMMC driver would incorrectly
set the block size to 0, as the data_sector_size field of ext_csd
was never initialized. This issue was exposed by commit 817046ecddbc
("block: Align max_hw_sectors to logical blocksize") which caused
max_sectors and max_hw_sectors to be set to 0 after setting the block
size to 0, resulting in a kernel panic in bio_split when attempting
to read from the device. Fix it by only reading the block size from
ext_csd if it is available.
Fixes: a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")
Signed-off-by: Peter Collingbourne <pcc@google.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Link: https://linux-review.googlesource.com/id/If244d178da4d86b52034459438fec295b02d6e60
---
drivers/mmc/core/queue.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
index de7cb0369c30..002426e3cf76 100644
--- a/drivers/mmc/core/queue.c
+++ b/drivers/mmc/core/queue.c
@@ -384,8 +384,10 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
"merging was advertised but not possible");
blk_queue_max_segments(mq->queue, mmc_get_max_segments(host));
- if (mmc_card_mmc(card))
+ if (mmc_card_mmc(card) && card->ext_csd.data_sector_size) {
block_size = card->ext_csd.data_sector_size;
+ WARN_ON(block_size != 512 && block_size != 4096);
+ }
blk_queue_logical_block_size(mq->queue, block_size);
/*
--
2.30.0.284.gd98b1dd5eaa7-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mmc: core: don't initialize block size from ext_csd if not present
2021-01-14 20:14 [PATCH v2] mmc: core: don't initialize block size from ext_csd if not present Peter Collingbourne
@ 2021-01-15 8:06 ` Adrian Hunter
2021-01-15 12:21 ` Ulf Hansson
1 sibling, 0 replies; 3+ messages in thread
From: Adrian Hunter @ 2021-01-15 8:06 UTC (permalink / raw)
To: Peter Collingbourne, Christoph Hellwig, Linus Walleij,
Ulf Hansson
Cc: linux-mmc, Damien Le Moal
On 14/01/21 10:14 pm, Peter Collingbourne wrote:
> If extended CSD was not available, the eMMC driver would incorrectly
> set the block size to 0, as the data_sector_size field of ext_csd
> was never initialized. This issue was exposed by commit 817046ecddbc
> ("block: Align max_hw_sectors to logical blocksize") which caused
> max_sectors and max_hw_sectors to be set to 0 after setting the block
> size to 0, resulting in a kernel panic in bio_split when attempting
> to read from the device. Fix it by only reading the block size from
> ext_csd if it is available.
>
> Fixes: a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
> Link: https://linux-review.googlesource.com/id/If244d178da4d86b52034459438fec295b02d6e60
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> drivers/mmc/core/queue.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> index de7cb0369c30..002426e3cf76 100644
> --- a/drivers/mmc/core/queue.c
> +++ b/drivers/mmc/core/queue.c
> @@ -384,8 +384,10 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
> "merging was advertised but not possible");
> blk_queue_max_segments(mq->queue, mmc_get_max_segments(host));
>
> - if (mmc_card_mmc(card))
> + if (mmc_card_mmc(card) && card->ext_csd.data_sector_size) {
> block_size = card->ext_csd.data_sector_size;
> + WARN_ON(block_size != 512 && block_size != 4096);
> + }
>
> blk_queue_logical_block_size(mq->queue, block_size);
> /*
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mmc: core: don't initialize block size from ext_csd if not present
2021-01-14 20:14 [PATCH v2] mmc: core: don't initialize block size from ext_csd if not present Peter Collingbourne
2021-01-15 8:06 ` Adrian Hunter
@ 2021-01-15 12:21 ` Ulf Hansson
1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2021-01-15 12:21 UTC (permalink / raw)
To: Peter Collingbourne
Cc: Adrian Hunter, Christoph Hellwig, Linus Walleij,
linux-mmc@vger.kernel.org, Damien Le Moal
On Thu, 14 Jan 2021 at 21:14, Peter Collingbourne <pcc@google.com> wrote:
>
> If extended CSD was not available, the eMMC driver would incorrectly
> set the block size to 0, as the data_sector_size field of ext_csd
> was never initialized. This issue was exposed by commit 817046ecddbc
> ("block: Align max_hw_sectors to logical blocksize") which caused
> max_sectors and max_hw_sectors to be set to 0 after setting the block
> size to 0, resulting in a kernel panic in bio_split when attempting
> to read from the device. Fix it by only reading the block size from
> ext_csd if it is available.
>
> Fixes: a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
> Link: https://linux-review.googlesource.com/id/If244d178da4d86b52034459438fec295b02d6e60
Applied for fixes and by adding a stable tag, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/core/queue.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> index de7cb0369c30..002426e3cf76 100644
> --- a/drivers/mmc/core/queue.c
> +++ b/drivers/mmc/core/queue.c
> @@ -384,8 +384,10 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
> "merging was advertised but not possible");
> blk_queue_max_segments(mq->queue, mmc_get_max_segments(host));
>
> - if (mmc_card_mmc(card))
> + if (mmc_card_mmc(card) && card->ext_csd.data_sector_size) {
> block_size = card->ext_csd.data_sector_size;
> + WARN_ON(block_size != 512 && block_size != 4096);
> + }
>
> blk_queue_logical_block_size(mq->queue, block_size);
> /*
> --
> 2.30.0.284.gd98b1dd5eaa7-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-15 12:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-14 20:14 [PATCH v2] mmc: core: don't initialize block size from ext_csd if not present Peter Collingbourne
2021-01-15 8:06 ` Adrian Hunter
2021-01-15 12:21 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox