Skip to content

Commit 807c274

Browse files
niklas88Vasily Gorbik
authored andcommitted
s390/pci: Fix dev.dma_range_map missing sentinel element
The fixed commit sets up dev.dma_range_map but missed that this is supposed to be an array of struct bus_dma_region with a sentinel element with the size field set to 0 at the end. This would lead to overruns in e.g. dma_range_map_min(). It could also result in wrong translations instead of DMA_MAPPING_ERROR in translate_phys_to_dma() if the paddr were to not fit in the aperture. Fix this by using the dma_direct_set_offset() helper which creates a sentinel for us. Fixes: d236843 ("s390/pci: store DMA offset in bus_dma_region") Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Link: https://lore.kernel.org/r/20250312-fix_dma_map_alloc-v2-1-530108d9de21@linux.ibm.com Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent af6bfcd commit 807c274

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

arch/s390/pci/pci_bus.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,21 @@ static struct zpci_bus *zpci_bus_alloc(int topo, bool topo_is_tid)
287287
static void pci_dma_range_setup(struct pci_dev *pdev)
288288
{
289289
struct zpci_dev *zdev = to_zpci(pdev);
290-
struct bus_dma_region *map;
291-
u64 aligned_end;
290+
u64 aligned_end, size;
291+
dma_addr_t dma_start;
292+
int ret;
292293

293-
map = kzalloc(sizeof(*map), GFP_KERNEL);
294-
if (!map)
295-
return;
296-
297-
map->cpu_start = 0;
298-
map->dma_start = PAGE_ALIGN(zdev->start_dma);
294+
dma_start = PAGE_ALIGN(zdev->start_dma);
299295
aligned_end = PAGE_ALIGN_DOWN(zdev->end_dma + 1);
300-
if (aligned_end >= map->dma_start)
301-
map->size = aligned_end - map->dma_start;
296+
if (aligned_end >= dma_start)
297+
size = aligned_end - dma_start;
302298
else
303-
map->size = 0;
304-
WARN_ON_ONCE(map->size == 0);
299+
size = 0;
300+
WARN_ON_ONCE(size == 0);
305301

306-
pdev->dev.dma_range_map = map;
302+
ret = dma_direct_set_offset(&pdev->dev, 0, dma_start, size);
303+
if (ret)
304+
pr_err("Failed to allocate DMA range map for %s\n", pci_name(pdev));
307305
}
308306

309307
void pcibios_bus_add_device(struct pci_dev *pdev)

0 commit comments

Comments
 (0)