Skip to contentSkip to conversation

mmc: core: don't initialize block size from ext_csd if not present

PATCH In review Peter Collingbourne 3 participants 3 messages Jan 14, 2021 – Jan 15, 2021 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc: core: don't initialize block size from ext_csd if not present

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")
---
 drivers/mmc/core/queue.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/core/queue.c +3 -1
index de7cb0369c30..002426e3cf76 100644
@@ -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);
 	/*
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Peter Collingbourne

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.

Quoted 4 lines
Fixes a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")
Quoted 21 lines
---
 drivers/mmc/core/queue.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/core/queue.c +3 -1
index de7cb0369c30..002426e3cf76 100644
@@ -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 lore raw
In reply to Peter Collingbourne
Quoted 10 lines · Peter Collingbourne

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.

Quoted 4 lines
Fixes a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")

Applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe

Quoted 23 lines
---
 drivers/mmc/core/queue.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/core/queue.c +3 -2
index de7cb0369c30..002426e3cf76 100644
@@ -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