Content-Type: multipart/mixed; boundary="===============1203215912288084712==" MIME-Version: 1.0 From: oscar.huang at microchip.com Subject: [SPDK] How to do mmio correctly when vfio-pci is used? Date: Thu, 17 Sep 2020 07:17:32 +0000 Message-ID: <20200917071732.2750.3970@ml01.vlan13.01.org> List-ID: To: spdk@lists.01.org --===============1203215912288084712== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi, Gugus, = I have a simple SPDK application, which maps a device BAR, and write some d= ata onto the device with spdk_mmio_write_8 function. The code flow is like = this: ... spdk_pci_device_map_bar(dev, bir, &virBarAddr, &phys, &size); addrToWrite =3D virBarAddr + offset; //offset is where I'd like to write = data in the device memory spdk_mmio_write_8(addrToWrite, data); ... The code has been working with uio_pci_generic. But recently when I switche= d to vfio-pci (iommu enabled), I got a segmentation fault the program was e= xecuting that spdk_mmio_write_8 function. = If I do the following, the program can run: ... spdk_pci_device_map_bar(dev, bir, &virBarAddr, &phys, &size); physAddr =3D phys +offset; int fd =3D open("/dev/mem", O_RDWR | O_SYNC); void *map_base =3D mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd= , physAddr & ~MAP_MASK); addrToWrite =3D (uint64_t)map_base + (physAddr & MAP_MASK); spdk_mmio_write_8(addrToWrite, data); ... I don't understand why it is so. Basically I need a routine to map device p= hysical address to process virtual address, and then call spdk_mmio_write_x= functions. It looks like the virtual address from spdk_pci_device_map_bar = cannot be used. I noticed the virtual address from spdk_pci_device_map_bar = was 0x2010008000, but the one by mmap was 0x7ffff7fef000, very different. = Is there a unified mmio approach that works for both uio_pci_generic and vf= io_pci? --===============1203215912288084712==--