standalone PCI passthrough emulator
Hi,
As the basis of some future development work I've put together a simple standalone emulator to pass through a single type 0 PCI function to a guest so I'm posting here in case anyone else would like a give it a try. So far I've tested with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so it hasn't had that much debugging.
NOTE: there is a known issue where domains are left in zombie state on shutdown. This is likely due to Xen not properly cleaning up MSI mappings, but I'm not yet sure of that.
Things that are missing:
- Decent error paths (it won't cope well if IO/memory mapping hypercalls fail)
- MSI-X support
- Extended config space
Hopefully I'll start to address these soon :-)
Cheers,
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 16 lines
-----Original Message-----
From: Paul Durrant
Sent: 01 March 2019 16:41
To: xen-devel ([email protected]) <[email protected]>
Subject: standalone PCI passthrough emulatorHi,
As the basis of some future development work I've put together a simple standalone emulator to pass
through a single type 0 PCI function to a guest so I'm posting here in case anyone else would like a give it a try. So far I've tested with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so it hasn't had that much debugging.NOTE: there is a known issue where domains are left in zombie state on shutdown. This is likely due
to Xen not properly cleaning up MSI mappings, but I'm not yet sure of that.
Quoted 7 lines
Things that are missing:
- Decent error paths (it won't cope well if IO/memory mapping hypercalls fail)
- MSI-X support
- Extended config spaceHopefully I'll start to address these soon :-)
And having sent that I realize I forgot to add the URL:
http://xenbits.xen.org/gitweb/?p=people/pauldu/xenpt.git;a=summary
Paul
Quoted 4 lines
Cheers,
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines
From: Paul Durrant
Sent: Saturday, March 2, 2019 12:41 AMHi,
As the basis of some future development work I've put together a simple
standalone emulator to pass through a single type 0 PCI function to a guest so I'm posting here in case anyone else would like a give it a try. So far I've tested with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so it hasn't had that much debugging.
How is it different from existing PCI passthrough support in Xen? What is exactly emulated here?
Quoted 5 lines
NOTE: there is a known issue where domains are left in zombie state on
shutdown. This is likely due to Xen not properly cleaning up MSI mappings, but I'm not yet sure of that.
Quoted 8 lines
Things that are missing:
- Decent error paths (it won't cope well if IO/memory mapping hypercalls fail)
- MSI-X support
- Extended config spaceHopefully I'll start to address these soon :-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines
-----Original Message-----
From: Tian, Kevin [mailto:[email protected]]
Sent: 04 March 2019 03:01
To: Paul Durrant <[email protected]>; xen-devel ([email protected]) <xen- [email protected]>
Subject: RE: standalone PCI passthrough emulatorQuoted 5 lines
From: Paul Durrant
Sent: Saturday, March 2, 2019 12:41 AMHi,
Quoted 9 lines
Quoted 5 lines
As the basis of some future development work I've put together a simple
standalone emulator to pass through a single type 0 PCI function to a guest so I'm posting here in case anyone else would like a give it a try. So far I've tested with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so it hasn't had that much debugging.How is it different from existing PCI passthrough support in Xen? What is exactly emulated here?
Essentially it does no more than the current code in QEMU, but that code has become very complex and hard to follow over the years. It's full of magic mask values and I've found at least two pieces of completely dead code whilst looking at it. So, I started this work to provide a small simple base on which to experiment with using VFIO, rather than the existent sysfs node accesses and xenctrl calls. To answer your other question... It's config space that is emulated, as it has to be to deal with BAR address and interrupt translation. Note, there is also a slight advantage in using multiple discreet emulators; emulated I/O can proceed in parallel for multiple vcpus... emulation on behalf of Xen by QEMU is still restricted by a single poll/select loop for all vcpus.
Paul
Quoted 5 lines
Quoted 5 lines
NOTE: there is a known issue where domains are left in zombie state on
shutdown. This is likely due to Xen not properly cleaning up MSI mappings, but I'm not yet sure of that.
Quoted 9 lines
Quoted 8 lines
Things that are missing:
- Decent error paths (it won't cope well if IO/memory mapping hypercalls fail)
- MSI-X support
- Extended config spaceHopefully I'll start to address these soon :-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines
From: Paul Durrant [mailto:[email protected]]
Sent: Monday, March 4, 2019 4:44 PMQuoted 4 lines
-----Original Message-----
From: Tian, Kevin [mailto:[email protected]]
Sent: 04 March 2019 03:01
To: Paul Durrant <[email protected]>; xen-devel (xen-[email protected]) <xen-
Quoted 10 lines
[email protected]>
Subject: RE: standalone PCI passthrough emulatorQuoted 7 lines
From: Paul Durrant
Sent: Saturday, March 2, 2019 12:41 AMHi,
As the basis of some future development work I've put together a simple
standalone emulator to pass through a single type 0 PCI function to aguest so
Quoted 1 line
Quoted 1 line
I'm posting here in case anyone else would like a give it a try. So far I've
tested
Quoted 1 line
Quoted 1 line
with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so
it
Quoted 5 lines
Quoted 1 line
hasn't had that much debugging.
How is it different from existing PCI passthrough support in Xen? What is exactly emulated here?
Quoted 6 lines
Essentially it does no more than the current code in QEMU, but that code has become very complex and hard to follow over the years. It's full of magic mask values and I've found at least two pieces of completely dead code whilst looking at it. So, I started this work to provide a small simple base on which to experiment with using VFIO, rather than the existent sysfs node accesses and xenctrl calls.
Thanks for explanation. I took a quick look at current repo. Looks VFIO support is not added yet, correct? To enable VFIO in Xen, I suppose there will be several major changes:
1. enable your pvIOMMU driver in VFIO. and it needs to be a full-fledge flavor, i.e. supporting per-device remapping capability;
2. make VFIO aware of foreign pages when doing accounting at map/unmap operations;
3. what would Xen device passthrough look like then? Looks now it becomes a hybrid model with some passthrough roles delegated to Dom0 VFIO, while other roles like real IOMMU page table, interrupt handling, etc. are still kept inside Xen.
Quoted 6 lines
To answer your other question... It's config space that is emulated, as it has to be to deal with BAR address and interrupt translation. Note, there is also a slight advantage in using multiple discreet emulators; emulated I/O can proceed in parallel for multiple vcpus... emulation on behalf of Xen by QEMU is still restricted by a single poll/select loop for all vcpus.
thanks to the introduction of ioreq server. :-)
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 43 lines
-----Original Message-----
From: Tian, Kevin [mailto:[email protected]]
Sent: 05 March 2019 02:45
To: Paul Durrant <[email protected]>; xen-devel ([email protected]) <xen- [email protected]>
Subject: RE: standalone PCI passthrough emulatorQuoted 29 lines
From: Paul Durrant [mailto:[email protected]]
Sent: Monday, March 4, 2019 4:44 PMQuoted 4 lines
-----Original Message-----
From: Tian, Kevin [mailto:[email protected]]
Sent: 04 March 2019 03:01
To: Paul Durrant <[email protected]>; xen-devel (xen-[email protected]) <xen-
Quoted 10 lines
[email protected]>
Subject: RE: standalone PCI passthrough emulatorQuoted 7 lines
From: Paul Durrant
Sent: Saturday, March 2, 2019 12:41 AMHi,
As the basis of some future development work I've put together a simple
standalone emulator to pass through a single type 0 PCI function to aguest so
Quoted 1 line
Quoted 1 line
I'm posting here in case anyone else would like a give it a try. So far I've
tested
Quoted 1 line
Quoted 1 line
with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so
it
Quoted 5 lines
Quoted 1 line
hasn't had that much debugging.
How is it different from existing PCI passthrough support in Xen? What is exactly emulated here?
Quoted 6 lines
Essentially it does no more than the current code in QEMU, but that code has become very complex and hard to follow over the years. It's full of magic mask values and I've found at least two pieces of completely dead code whilst looking at it. So, I started this work to provide a small simple base on which to experiment with using VFIO, rather than the existent sysfs node accesses and xenctrl calls.
Quoted 2 lines
Thanks for explanation. I took a quick look at current repo. Looks VFIO support is not added yet, correct?
Yes, as a first step I wanted to duplicate the xenctrl calls used by QEMU and get things going with those. Then I have a base from which I can start to replace things with calls into VFIO.
Quoted 6 lines
To enable VFIO in Xen, I suppose there
will be several major changes:1. enable your pvIOMMU driver in VFIO. and it needs to be a full-fledge flavor, i.e. supporting per-device remapping capability;
I was thinking about this yesterday... The proposed hypercall interface needs to be changed I think; we should have the ability to create an IOMMU group (i.e. the same concept that VFIO has) for a VM, assign devices to groups, and then allow the guest OS to map and unmap pages in groups. Perhaps we make the current hardcoded Xen mappings into 'group 0' (which the guest is not allowed to manipulate - apart from maybe the OS in the h/w domain) and then have devices assigned to that by default. They can then be transferred into other groups by new hypercalls.
Quoted 3 lines
2. make VFIO aware of foreign pages when doing accounting at map/unmap operations;
The hypercalls I'd already proposed should be ok for that; they take a domid and gfn/gref as arguments and take both page and type refs so I think we should be ok there.
Quoted 5 lines
3. what would Xen device passthrough look like then? Looks now it becomes a hybrid model with some passthrough roles delegated to Dom0 VFIO, while other roles like real IOMMU page table, interrupt handling, etc. are still kept inside Xen.
I guess so... not clear. I assume we need to issue any trapped I/O to the device via VFIO so that we can take advantage of MDEV, but we still want the ability for I/O to go directly for pass-through resources. I'd like to work towards a unified (kvm + xen) control plane via VFIO with hypervisor specific detail kept inside the vfio driver as far as possible.
Quoted 8 lines
Quoted 6 lines
To answer your other question... It's config space that is emulated, as it has to be to deal with BAR address and interrupt translation. Note, there is also a slight advantage in using multiple discreet emulators; emulated I/O can proceed in parallel for multiple vcpus... emulation on behalf of Xen by QEMU is still restricted by a single poll/select loop for all vcpus.
thanks to the introduction of ioreq server. :-)
You're welcome :-)
Paul
Quoted 3 lines
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Paul Durrant
Hi,
As the basis of some future development work I've put together a simple standalone emulator to pass through a single type 0 PCI function to a guest so I'm posting here in case anyone else would like a give it a try. So far I've tested with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so it hasn't had that much debugging.
NOTE: there is a known issue where domains are left in zombie state on shutdown. This is likely due to Xen not properly cleaning up MSI mappings, but I'm not yet sure of that.
Quoted 7 lines
Things that are missing:
- Decent error paths (it won't cope well if IO/memory mapping hypercalls fail)
- MSI-X support
- Extended config spaceHopefully I'll start to address these soon :-)
Thanks, this is very interesting.
I've been wondering whether it would be possible to unify this code together with the current vPCI code in Xen, by creating a common/libvpci library that would have the PCI emulation and likely a set of hooks to interact with the real PCI config space and with the guest p2m. Those hooks will obviously be different between the in-Xen version and the user-space Linux version which could use sysfs or VFIO.
I think both code bases are small enough at this point to perform such unification, and leaving this for later is just going to cause more pain.
I'm willing to work on this in a month, since right now I don't have the time. Would you be OK with that?
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 07 March 2019 17:41
To: Paul Durrant <[email protected]>
Cc: xen-devel ([email protected]) <[email protected]>
Subject: Re: [Xen-devel] standalone PCI passthrough emulatorQuoted 3 lines · Paul Durrant
Hi,
As the basis of some future development work I've put together a simple standalone emulator to
pass through a single type 0 PCI function to a guest so I'm posting here in case anyone else would like a give it a try. So far I've tested with AMD FirePro S7150 and NVIDIA K1 GPUs and a Windows 10 guest, so it hasn't had that much debugging.
Quoted 2 lines
NOTE: there is a known issue where domains are left in zombie state on shutdown. This is likely
due to Xen not properly cleaning up MSI mappings, but I'm not yet sure of that.
Quoted 8 lines
Things that are missing:
- Decent error paths (it won't cope well if IO/memory mapping hypercalls fail)
- MSI-X support
- Extended config spaceHopefully I'll start to address these soon :-)
Quoted 9 lines
Thanks, this is very interesting.
I've been wondering whether it would be possible to unify this code together with the current vPCI code in Xen, by creating a common/libvpci library that would have the PCI emulation and likely a set of hooks to interact with the real PCI config space and with the guest p2m. Those hooks will obviously be different between the in-Xen version and the user-space Linux version which could use sysfs or VFIO.
That sounds like a good idea. At one end we'd need a mechanism for feeding in the config accesses; which is IOREQ server for an out-of-xen instance and direct call for an in-xen instance. The other end, as you say, would a set of ops which would need to populated to handle mapping of ports or mem, or binding of interrupts.
Quoted 4 lines
I think both code bases are small enough at this point to perform such unification, and leaving this for later is just going to cause more pain.
Yes, the core is the same and there's no need to keep re-writing it.
Quoted 3 lines
I'm willing to work on this in a month, since right now I don't have the time. Would you be OK with that?
Sure. I have plenty to be getting on with :-)
Cheers,
Paul
Quoted 1 line
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel