[RFC PATCH v3 0/3] xl: Allow PCI devices to be passthrough'd via Qemu command line

Thierry Escande posted 3 patches 2 days, 5 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20260410150333.1533568-1-thierry.escande@vates.tech
docs/man/xl-pci-configuration.5.pod | 17 ++++++
docs/man/xl.cfg.5.pod.in            |  6 ++
tools/include/libxl.h               |  1 +
tools/libs/light/libxl_dm.c         | 85 +++++++++++++++++++++++++++++
tools/libs/light/libxl_internal.h   |  7 +++
tools/libs/light/libxl_pci.c        | 57 +++++++++++++------
tools/libs/light/libxl_types.idl    |  1 +
tools/libs/util/libxlu_pci.c        |  2 +
tools/xl/xl_parse.c                 |  5 ++
9 files changed, 163 insertions(+), 18 deletions(-)
[RFC PATCH v3 0/3] xl: Allow PCI devices to be passthrough'd via Qemu command line
Posted by Thierry Escande 2 days, 5 hours ago
This series adds support for a new 'hotplug' option for PCI devices to be
passthrough'd to guests.

The current mechanism for device passthrough uses QMP device_add command
to hot-plug PCI devices to the guest Qemu instance. This is an issue for
guests running on Q35 chipset (preliminary support posted at [1]) since the
Q35 PCI root bus does not support hotplug. Devices could be hotplugged to
a secondary PCI bus but Xen only support 1 PCI bus for now.

The 'hotplug' option allows to control how devices are attached to the
guest, either by using the legacy QMP mechanism (this is the default) or by
passing it directly to the Qemu command line using xen-pci-passthrough
device.

Example usage in cfg file:
 pci = [ "00:03.0,seize=1,hotplug=0" ]

Since Qemu -device option accepts parameters in json format, this
patchset adds a new internal function libxl__device_pci_get_qmp_json() that
generates the device json object used for both QMP hotplug and command line
passing.

Also, to handle the assignable PCI device list, the function
libxl_pci_assignable() is renamed as libxl_device_pci_assignable() and is
made available from libxl.h for access in libxl_dm.c. 2 other functions are
also exported internally: libxl__pciback_dev_is_assigned() and
libxl__device_pci_assignable_add().

This has been successfully tested on Xen 4.22-dev and Qemu 10.0 running
Debian VMs in both Bios and UEFI mode with a passthrough'd nvme disk.
Disabling the hotplug mechanism might be made mandatory for Q35 machines
later, once Q35 support is merged upstream.

[1] https://lore.kernel.org/xen-devel/20260313163455.790692-1-thierry.escande@vates.tech/

Changes in v2:
- Add support for YAJL json parser

Changes in v3:
- Move code block of device command line parameters creation
- Better handling of pci device assignation

Thierry Escande (3):
  xl: Add pci device hotplug option
  libxl: Allow PCI device passthrough using -device Qemu command line
  docs: provide description for pci hotplug option

 docs/man/xl-pci-configuration.5.pod | 17 ++++++
 docs/man/xl.cfg.5.pod.in            |  6 ++
 tools/include/libxl.h               |  1 +
 tools/libs/light/libxl_dm.c         | 85 +++++++++++++++++++++++++++++
 tools/libs/light/libxl_internal.h   |  7 +++
 tools/libs/light/libxl_pci.c        | 57 +++++++++++++------
 tools/libs/light/libxl_types.idl    |  1 +
 tools/libs/util/libxlu_pci.c        |  2 +
 tools/xl/xl_parse.c                 |  5 ++
 9 files changed, 163 insertions(+), 18 deletions(-)

-- 
2.53.0



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Re: [RFC PATCH v3 0/3] xl: Allow PCI devices to be passthrough'd via Qemu command line
Posted by Marek Marczykowski-Górecki 2 days ago
On Fri, Apr 10, 2026 at 03:03:45PM +0000, Thierry Escande wrote:
> This series adds support for a new 'hotplug' option for PCI devices to be
> passthrough'd to guests.
> 
> The current mechanism for device passthrough uses QMP device_add command
> to hot-plug PCI devices to the guest Qemu instance. This is an issue for
> guests running on Q35 chipset (preliminary support posted at [1]) since the
> Q35 PCI root bus does not support hotplug. Devices could be hotplugged to
> a secondary PCI bus but Xen only support 1 PCI bus for now.
> 
> The 'hotplug' option allows to control how devices are attached to the
> guest, either by using the legacy QMP mechanism (this is the default) or by
> passing it directly to the Qemu command line using xen-pci-passthrough
> device.
> 
> Example usage in cfg file:
>  pci = [ "00:03.0,seize=1,hotplug=0" ]
> 
> Since Qemu -device option accepts parameters in json format, this
> patchset adds a new internal function libxl__device_pci_get_qmp_json() that
> generates the device json object used for both QMP hotplug and command line
> passing.
> 
> Also, to handle the assignable PCI device list, the function
> libxl_pci_assignable() is renamed as libxl_device_pci_assignable() and is
> made available from libxl.h for access in libxl_dm.c. 2 other functions are
> also exported internally: libxl__pciback_dev_is_assigned() and
> libxl__device_pci_assignable_add().
> 
> This has been successfully tested on Xen 4.22-dev and Qemu 10.0 running
> Debian VMs in both Bios and UEFI mode with a passthrough'd nvme disk.
> Disabling the hotplug mechanism might be made mandatory for Q35 machines
> later, once Q35 support is merged upstream.
> 
> [1] https://lore.kernel.org/xen-devel/20260313163455.790692-1-thierry.escande@vates.tech/

Much better now:
https://gitlab.com/xen-project/people/marmarek/xen/-/pipelines/2444612680

I get now something like this:
libxl: debug: libxl_dm.c:3044:device_model_launch: Domain 1:  -device
libxl: debug: libxl_dm.c:3044:device_model_launch: Domain 1:  {"driver":"xen-pci-passthrough","id":"pci-pt-03_00.0","hostaddr":"0000:03:00.0"}

So, it works :)

> Changes in v2:
> - Add support for YAJL json parser
> 
> Changes in v3:
> - Move code block of device command line parameters creation
> - Better handling of pci device assignation
> 
> Thierry Escande (3):
>   xl: Add pci device hotplug option
>   libxl: Allow PCI device passthrough using -device Qemu command line
>   docs: provide description for pci hotplug option
> 
>  docs/man/xl-pci-configuration.5.pod | 17 ++++++
>  docs/man/xl.cfg.5.pod.in            |  6 ++
>  tools/include/libxl.h               |  1 +
>  tools/libs/light/libxl_dm.c         | 85 +++++++++++++++++++++++++++++
>  tools/libs/light/libxl_internal.h   |  7 +++
>  tools/libs/light/libxl_pci.c        | 57 +++++++++++++------
>  tools/libs/light/libxl_types.idl    |  1 +
>  tools/libs/util/libxlu_pci.c        |  2 +
>  tools/xl/xl_parse.c                 |  5 ++
>  9 files changed, 163 insertions(+), 18 deletions(-)
> 
> -- 
> 2.53.0
> 
> 
> 
> --
> Thierry Escande | Vates XCP-ng Developer
> 
> XCP-ng & Xen Orchestra - Vates solutions
> 
> web: https://vates.tech
> 

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab