[vfio-users] trouble mapping the pci config space on vfio-pci

Alex Williamson alex.williamson at redhat.com
Fri Oct 30 12:55:31 UTC 2015


On Fri, 2015-10-30 at 12:36 +0100, Christophe Milard wrote:
> Hi
> 
> www.kernel.org/doc/Documentation/vfio.txt says:
> 
> """
> for (i = 0; i < device_info.num_regions; i++) {
> struct vfio_region_info reg = { .argsz = sizeof(reg) };
> 
> reg.index = i;
> 
> ioctl(device, VFIO_DEVICE_GET_REGION_INFO, &reg);
> 
> /* Setup mappings... read/write offsets, mmaps
> * For PCI devices, config space is a region */
> }
> """
> 
> stating that the pci config space could be mapped using mmap, as any other
> regions.
> But, (after failing doing that and) looking
> in linux/drivers/vfio/pci/vfio_pci.c, I can see:
> """
> 
> static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)
> {
> ...        if (index >= VFIO_PCI_ROM_REGION_INDEX)
>                 return -EINVAL;
> """
> 
> As VFIO_PCI_ROM_REGION_INDEX is defined as:
> 
> """
> enum {
>         VFIO_PCI_BAR0_REGION_INDEX,
>         VFIO_PCI_BAR1_REGION_INDEX,
>         VFIO_PCI_BAR2_REGION_INDEX,
>         VFIO_PCI_BAR3_REGION_INDEX,
>         VFIO_PCI_BAR4_REGION_INDEX,
>         VFIO_PCI_BAR5_REGION_INDEX,
>         VFIO_PCI_ROM_REGION_INDEX,
>         VFIO_PCI_CONFIG_REGION_INDEX,
> ...
> """
> 
> The if statment excludes the possibility to map the pci configuration
> region as any normal (BAR) region...
> 
> DId I miss something? How am I supposed to perform the configuration space
> mapping then?

Hi Christophe,

You're missing vfio_region_info.flags, which indicates whether the
region supports read, write, or mmap.  The config space region does not
set the mmap flag.  PCI config space itself may not be mmap capable and
also the virtualization done to config space prevents it being mmap'd.
This is generally not an issue since PCI config space should never be a
performance path for a device.  Thanks,

Alex




More information about the vfio-users mailing list