mmc: core: don't initialize block size from ext_csd if not present
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.
--- drivers/mmc/core/queue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/core/queue.c +3 -1
@@ -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
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_sizefield ofext_csdwas never initialized. This issue was exposed by commit817046ecddbc("block: Alignmax_hw_sectorsto logical blocksize") which causedmax_sectorsandmax_hw_sectorsto be set to 0 after setting the block size to 0, resulting in a kernel panic inbio_splitwhen attempting to read from the device. Fix it by only reading the block size fromext_csdif it is available.
Quoted 4 lines
Fixes a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")Signed-off-by Peter Collingbourne <[email protected]>Reviewed-by Damien Le Moal <[email protected]>
Quoted 21 lines
--- drivers/mmc/core/queue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/mmc/core/queue.c +3
-1@@ -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);/*
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_sizefield ofext_csdwas never initialized. This issue was exposed by commit817046ecddbc("block: Alignmax_hw_sectorsto logical blocksize") which causedmax_sectorsandmax_hw_sectorsto be set to 0 after setting the block size to 0, resulting in a kernel panic inbio_splitwhen attempting to read from the device. Fix it by only reading the block size fromext_csdif it is available.
Quoted 4 lines
Fixes a5075eb94837 ("mmc: block: Allow disabling 512B sector size emulation")Signed-off-by Peter Collingbourne <[email protected]>Reviewed-by Damien Le Moal <[email protected]>
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@@ -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