Skip to content

Commit

Permalink
bus/pci: align next mapping address on page boundary
Browse files Browse the repository at this point in the history
[ upstream commit d25ab4b ]

Currently, the next address picked by PCI mapping infrastructure
may be page-unaligned due to BAR length being smaller than page size.
This leads to a situation where the requested map address is invalid,
resulting in mmap() call returning an arbitrary address,
which will later interfere with device BAR mapping in secondary processes.

Fix it by always aligning the next requested address on page boundary.

Fixes: c752998 ("pci: introduce library and driver")

Signed-off-by: Xiaofeng Deng <dengxiaofeng@huawei.com>
Signed-off-by: Wangyu (Eric) <seven.wangyu@huawei.com>
Acked-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
Acked-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Gavin Hu <gavin.hu@arm.com>
  • Loading branch information
wangyu01 authored and kevintraynor committed Dec 11, 2019
1 parent 823157f commit db07de2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/bus/pci/linux/pci_uio.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
pci_map_addr = RTE_PTR_ADD(mapaddr,
(size_t)dev->mem_resource[res_idx].len);

pci_map_addr = RTE_PTR_ALIGN(pci_map_addr, sysconf(_SC_PAGE_SIZE));

maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
maps[map_idx].size = dev->mem_resource[res_idx].len;
maps[map_idx].addr = mapaddr;
Expand Down
3 changes: 3 additions & 0 deletions drivers/bus/pci/linux/pci_vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
bar_addr = pci_map_addr;
pci_map_addr = RTE_PTR_ADD(bar_addr, (size_t) reg->size);

pci_map_addr = RTE_PTR_ALIGN(pci_map_addr,
sysconf(_SC_PAGE_SIZE));

maps[i].addr = bar_addr;
maps[i].offset = reg->offset;
maps[i].size = reg->size;
Expand Down

0 comments on commit db07de2

Please sign in to comment.