[dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource
Xia, Chenbo
chenbo.xia at intel.com
Wed Jul 8 15:58:09 CEST 2020
Hi Alvin,
CC the maintainers. Comments below.
> -----Original Message-----
> From: dev <dev-bounces at dpdk.org> On Behalf Of alvinx.zhang at intel.com
> Sent: Wednesday, July 8, 2020 5:25 PM
> To: dev at dpdk.org
> Cc: Xing, Beilei <beilei.xing at intel.com>; Guo, Jia <jia.guo at intel.com>
> Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource
>
> From: Alvin Zhang <alvinx.zhang at intel.com>
>
> When mapping a PCI BAR containing an MSI-X table, some devices do not need
> to actually map this BAR or only need to map part of them, which may cause the
> mapping to fail. Now some checks are added and a non-NULL initial value is set
> to the variable to avoid this situation.
>
> Fixes: 2fd3567e5425 ("pci: use OS generic memory mapping functions")
> Cc: talshn at mellanox.com
>
> Signed-off-by: Alvin Zhang <alvinx.zhang at intel.com>
> ---
> drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
> index fdeb9a8..9143bfc 100644
> --- a/drivers/bus/pci/linux/pci_vfio.c
> +++ b/drivers/bus/pci/linux/pci_vfio.c
> @@ -547,6 +547,14 @@
> bar_index,
> memreg[0].offset, memreg[0].size,
> memreg[1].offset, memreg[1].size);
> +
> + if (memreg[0].size == 0 && memreg[1].size == 0) {
> + /* No need to map this BAR */
> + RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index);
> + bar->size = 0;
> + bar->addr = 0;
> + return 0;
> + }
I'm not sure if this corner case will happen. If you confirmed it,
Just ignore this.
> } else {
> memreg[0].offset = bar->offset;
> memreg[0].size = bar->size;
> @@ -556,7 +564,9 @@
> bar_addr = mmap(bar->addr, bar->size, 0, MAP_PRIVATE |
> MAP_ANONYMOUS | additional_flags, -1, 0);
> if (bar_addr != MAP_FAILED) {
> - void *map_addr = NULL;
> + /* Set non NULL initial value for in case of no PCI mapping */
> + void *map_addr = bar_addr;
> +
I see the issue that this patch wants to fix is based on an old kernel.
In older vfio-pci kernel module, MSI related reg cannot be mmaped
in userspace while in newer kernel it can be. That's why sometimes
it cannot be reproduced (https://bugs.dpdk.org/show_bug.cgi?id=503)
So under the condition of old kernel, there could be an example that
Memreg 0 has size 0 but Memreg 1 has non-zero size, which leads to
Memreg 1 cannot be mmaped.
So I'm fine with this part of code change. As this issue is blocking test,
we should do fast confirm and review.
Thanks,
Chenbo
> if (memreg[0].size) {
> /* actual map of first part */
> map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
> --
> 1.8.3.1
More information about the dev
mailing list