Skip to content

Commit b78b25f

Browse files
committed
Merge tag 'ata-6.11-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux
Pull ata fixes from Damien Le Moal: - Fix the max segment size and max number of segments supported by the pata_macio driver to fix issues with BIO splitting leading to an overflow of the adapter DMA table (from Michael) - Related to the previous fix, change BUG_ON() calls for incorrect command buffer segmentation into WARN_ON() and an error return (from Michael) * tag 'ata-6.11-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux: ata: pata_macio: Use WARN instead of BUG ata: pata_macio: Fix DMA table overflow
2 parents aa0743a + d4bc0a2 commit b78b25f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

drivers/ata/pata_macio.c

Lines changed: 20 additions & 10 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
@@ -541,7 +554,8 @@ static enum ata_completion_errors pata_macio_qc_prep(struct ata_queued_cmd *qc)
541554

542555
while (sg_len) {
543556
/* table overflow should never happen */
544-
BUG_ON (pi++ >= MAX_DCMDS);
557+
if (WARN_ON_ONCE(pi >= MAX_DCMDS))
558+
return AC_ERR_SYSTEM;
545559

546560
len = (sg_len < MAX_DBDMA_SEG) ? sg_len : MAX_DBDMA_SEG;
547561
table->command = cpu_to_le16(write ? OUTPUT_MORE: INPUT_MORE);
@@ -553,11 +567,13 @@ static enum ata_completion_errors pata_macio_qc_prep(struct ata_queued_cmd *qc)
553567
addr += len;
554568
sg_len -= len;
555569
++table;
570+
++pi;
556571
}
557572
}
558573

559574
/* Should never happen according to Tejun */
560-
BUG_ON(!pi);
575+
if (WARN_ON_ONCE(!pi))
576+
return AC_ERR_SYSTEM;
561577

562578
/* Convert the last command to an input/output */
563579
table--;
@@ -912,16 +928,10 @@ static int pata_macio_do_resume(struct pata_macio_priv *priv)
912928

913929
static const struct scsi_host_template pata_macio_sht = {
914930
__ATA_BASE_SHT(DRV_NAME),
915-
.sg_tablesize = MAX_DCMDS,
931+
.sg_tablesize = PATA_MACIO_SG_TABLESIZE,
916932
/* We may not need that strict one */
917933
.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,
934+
.max_segment_size = PATA_MACIO_MAX_SEGMENT_SIZE,
925935
.device_configure = pata_macio_device_configure,
926936
.sdev_groups = ata_common_sdev_groups,
927937
.can_queue = ATA_DEF_QUEUE,

0 commit comments

Comments
 (0)