Skip to content

Commit 822c802

Browse files
mpedamien-lemoal
authored andcommitted
ata: pata_macio: Fix DMA table overflow
Kolbjørn and Jonáš reported that their 32-bit PowerMacs were crashing in pata-macio since commit 09fe2bf ("ata: pata_macio: Fix max_segment_size with PAGE_SIZE == 64K"). For example: kernel BUG at drivers/ata/pata_macio.c:544! Oops: Exception in kernel mode, sig: 5 [#1] BE PAGE_SIZE=4K MMU=Hash SMP NR_CPUS=2 DEBUG_PAGEALLOC PowerMac ... NIP pata_macio_qc_prep+0xf4/0x190 LR pata_macio_qc_prep+0xfc/0x190 Call Trace: 0xc1421660 (unreliable) ata_qc_issue+0x14c/0x2d4 __ata_scsi_queuecmd+0x200/0x53c ata_scsi_queuecmd+0x50/0xe0 scsi_queue_rq+0x788/0xb1c __blk_mq_issue_directly+0x58/0xf4 blk_mq_plug_issue_direct+0x8c/0x1b4 blk_mq_flush_plug_list.part.0+0x584/0x5e0 __blk_flush_plug+0xf8/0x194 __submit_bio+0x1b8/0x2e0 submit_bio_noacct_nocheck+0x230/0x304 btrfs_work_helper+0x200/0x338 process_one_work+0x1a8/0x338 worker_thread+0x364/0x4c0 kthread+0x100/0x104 start_kernel_thread+0x10/0x14 That commit increased max_segment_size to 64KB, with the justification that the SCSI core was already using that size when PAGE_SIZE == 64KB, and that there was existing logic to split over-sized requests. However with a sufficiently large request, the splitting logic causes each sg to be split into two commands in the DMA table, leading to overflow of the DMA table, triggering the BUG_ON(). With default settings the bug doesn't trigger, because the request size is limited by max_sectors_kb == 1280, however max_sectors_kb can be increased, and apparently some distros do that by default using udev rules. Fix the bug for 4KB kernels by reverting to the old max_segment_size. For 64KB kernels the sg_tablesize needs to be halved, to allow for the possibility that each sg will be split into two. Fixes: 09fe2bf ("ata: pata_macio: Fix max_segment_size with PAGE_SIZE == 64K") Cc: [email protected] # v6.10+ Reported-by: Kolbjørn Barmen <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reported-by: Jonáš Vidra <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Tested-by: Kolbjørn Barmen <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent fa0db8e commit 822c802

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

drivers/ata/pata_macio.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ static const char* macio_ata_names[] = {
208208
/* Don't let a DMA segment go all the way to 64K */
209209
#define MAX_DBDMA_SEG 0xff00
210210

211+
#ifdef CONFIG_PAGE_SIZE_64KB
212+
/*
213+
* The SCSI core requires the segment size to cover at least a page, so
214+
* for 64K page size kernels it must be at least 64K. However the
215+
* hardware can't handle 64K, so pata_macio_qc_prep() will split large
216+
* requests. To handle the split requests the tablesize must be halved.
217+
*/
218+
#define PATA_MACIO_MAX_SEGMENT_SIZE SZ_64K
219+
#define PATA_MACIO_SG_TABLESIZE (MAX_DCMDS / 2)
220+
#else
221+
#define PATA_MACIO_MAX_SEGMENT_SIZE MAX_DBDMA_SEG
222+
#define PATA_MACIO_SG_TABLESIZE MAX_DCMDS
223+
#endif
211224

212225
/*
213226
* Wait 1s for disk to answer on IDE bus after a hard reset
@@ -912,16 +925,10 @@ static int pata_macio_do_resume(struct pata_macio_priv *priv)
912925

913926
static const struct scsi_host_template pata_macio_sht = {
914927
__ATA_BASE_SHT(DRV_NAME),
915-
.sg_tablesize = MAX_DCMDS,
928+
.sg_tablesize = PATA_MACIO_SG_TABLESIZE,
916929
/* We may not need that strict one */
917930
.dma_boundary = ATA_DMA_BOUNDARY,
918-
/*
919-
* The SCSI core requires the segment size to cover at least a page, so
920-
* for 64K page size kernels this must be at least 64K. However the
921-
* hardware can't handle 64K, so pata_macio_qc_prep() will split large
922-
* requests.
923-
*/
924-
.max_segment_size = SZ_64K,
931+
.max_segment_size = PATA_MACIO_MAX_SEGMENT_SIZE,
925932
.device_configure = pata_macio_device_configure,
926933
.sdev_groups = ata_common_sdev_groups,
927934
.can_queue = ATA_DEF_QUEUE,

0 commit comments

Comments
 (0)