summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWangyu (Eric) <seven.wangyu@huawei.com>2019-11-13 07:17:30 +0000
committerDavid Marchand <david.marchand@redhat.com>2019-11-14 14:17:48 +0100
commitd25ab4b7f128610cb5310b424c1f608686173f13 (patch)
tree1f32db1049928d6800aba86653163d67ce65b3db
parent08a234788ee548796fd6b394c7e897a2bf1df1b3 (diff)
downloaddpdk-d25ab4b7f128610cb5310b424c1f608686173f13.zip
dpdk-d25ab4b7f128610cb5310b424c1f608686173f13.tar.gz
dpdk-d25ab4b7f128610cb5310b424c1f608686173f13.tar.xz
bus/pci: align next mapping address on page boundary
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: c752998b5e2e ("pci: introduce library and driver") Cc: stable@dpdk.org 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>
-rw-r--r--drivers/bus/pci/linux/pci_uio.c2
-rw-r--r--drivers/bus/pci/linux/pci_vfio.c3
2 files changed, 5 insertions, 0 deletions
diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 6dca05a..097dc19 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -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;
diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index b8faa23..64cd84a 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -750,6 +750,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;