Questions about the VFIO device BAR emulation
Hello Alex, Paolo and all
I have a question about VFIO about the BAR.
Why we have two MemoryRegion for every device’s BAR. I mean in VFIOBAR we have a field ‘mr’.
typedef struct VFIOBAR {
VFIORegion region;
MemoryRegion *mr;
size_t size;
uint8_t type;
bool ioport;
bool mem64;
QLIST_HEAD(, VFIOQuirk) quirks;
} VFIOBAR;And in the field ‘region’ field of VFIOBAR,
We also have a MemoryReion named ‘mem’.
And the ‘VFIOBAR’s mr is just the subregion of ‘VFIOREGION’.
Why here we can’t use just one MR link VFIOREGION’s ‘mem’field to represent the device’s BAR?
Thanks,
Li Qiang
Quoted 16 lines · On Mon, 3 Dec 2018 21:06:00 +0800 Li Qiang <[email protected]> wrote:
Hello Alex, Paolo and all
I have a question about VFIO about the BAR.
Why we have two MemoryRegion for every device’s BAR. I mean in VFIOBAR we have a field ‘mr’.
typedef struct VFIOBAR { VFIORegion region; MemoryRegion *mr; size_t size; uint8_t type; bool ioport; bool mem64; QLIST_HEAD(, VFIOQuirk) quirks; } VFIOBAR;
Quoted 5 lines
And in the field ‘region’ field of VFIOBAR,
We also have a MemoryReion named ‘mem’.
And the ‘VFIOBAR’s mr is just the subregion of ‘VFIOREGION’.Why here we can’t use just one MR link VFIOREGION’s ‘mem’field to represent the device’s BAR?
The answer lives in git history:
commit 3a286732d1563bdb440718d4e68137e06af785dd
Author: Alex Williamson <[email protected]> Date: Tue Feb 6 11:08:25 2018 -0700
vfio/pci: Add base BAR MemoryRegion
Add one more layer to our stack of MemoryRegions, this base region allows us to register BARs independently of the vfio region or to extend the size of BARs which do map to a region. This will be useful when we want hypervisor defined BARs or sections of BARs, for purposes such as relocating MSI-X emulation. We therefore call msix_init() based on this new base MemoryRegion, while the quirks, which only modify regions still operate on those sub-MemoryRegions.