qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC QEMU PATCH v3 0/1] Support device passthrough when dom0 is PVH on Xen
@ 2023-12-10 16:52 Jiqian Chen
  2023-12-10 16:52 ` [RFC QEMU PATCH v3 1/1] xen: Use gsi instead of irq for mapping pirq Jiqian Chen
  0 siblings, 1 reply; 4+ messages in thread
From: Jiqian Chen @ 2023-12-10 16:52 UTC (permalink / raw)
  To: Stefano Stabellini, Anthony Perard, Paul Durrant, qemu-devel
  Cc: xen-devel, Xenia Ragiadakou, Stewart Hildebrand, Alex Deucher,
	Huang Rui, Honglei Huang, Julia Zhang, Jiqian Chen

Hi All,
v2->v3 changes:
* du to changes in the implementation of the second patch on kernel side(that adds a new sysfs for gsi instead of a new syscall), so read gsi number from the sysfs of gsi.


v3 patch on kernel side:
https://lore.kernel.org/lkml/20231210161519.1550860-1-Jiqian.Chen@amd.com/T/#t
v3 patch on Xen side:
https://lore.kernel.org/xen-devel/20231210164009.1551147-1-Jiqian.Chen@amd.com/T/#t


Below is the description of v2 cover letter:
This patch is the v2 of the implementation of passthrough when dom0 is PVH on Xen.
Issues we encountered:
1. failed to map pirq for gsi
Problem: qemu will call xc_physdev_map_pirq() to map a passthrough device’s gsi to pirq in function xen_pt_realize(). But failed.

Reason: According to the implement of xc_physdev_map_pirq(), it needs gsi instead of irq, but qemu pass irq to it and treat irq as gsi, it is got from file /sys/bus/pci/devices/xxxx:xx:xx.x/irq in function xen_host_pci_device_get(). But actually the gsi number is not equal with irq. On PVH dom0, when it allocates irq for a gsi in function acpi_register_gsi_ioapic(), allocation is dynamic, and follow the principle of applying first, distributing first. And if you debug the kernel codes(see function __irq_alloc_descs), you will find the irq number is allocated from small to large by order, but the applying gsi number is not, gsi 38 may come before gsi 28, that causes gsi 38 get a smaller irq number than gsi 28, and then gsi != irq.

Solution: we can record the relation between gsi and irq, then when userspace(qemu) want to use gsi, we can do a translation. The third patch of kernel(xen/privcmd: Add new syscall to get gsi from irq) records all the relations in acpi_register_gsi_xen_pvh() when dom0 initialize pci devices, and provide a syscall for userspace to get the gsi from irq. The third patch of xen(tools: Add new function to get gsi from irq) add a new function xc_physdev_gsi_from_irq() to call the new syscall added on kernel side.
And then userspace can use that function to get gsi. Then xc_physdev_map_pirq() will success.

This v2 on qemu side is the same as the v1 ( qemu https://lore.kernel.org/xen-devel/20230312092244.451465-19-ray.huang@amd.com/), just call
xc_physdev_gsi_from_irq() to get gsi from irq.

v2 on kernel side:
https://lore.kernel.org/lkml/20231124103123.3263471-1-Jiqian.Chen@amd.com/T/#t

v2 on Xen side:
https://lore.kernel.org/xen-devel/20231124104136.3263722-1-Jiqian.Chen@amd.com/T/#t


Jiqian Chen (1):
  xen: Use gsi instead of irq for mapping pirq

 hw/xen/xen-host-pci-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFC QEMU PATCH v3 1/1] xen: Use gsi instead of irq for mapping pirq
  2023-12-10 16:52 [RFC QEMU PATCH v3 0/1] Support device passthrough when dom0 is PVH on Xen Jiqian Chen
@ 2023-12-10 16:52 ` Jiqian Chen
  2023-12-11 15:33   ` Roger Pau Monné
  0 siblings, 1 reply; 4+ messages in thread
From: Jiqian Chen @ 2023-12-10 16:52 UTC (permalink / raw)
  To: Stefano Stabellini, Anthony Perard, Paul Durrant, qemu-devel
  Cc: xen-devel, Xenia Ragiadakou, Stewart Hildebrand, Alex Deucher,
	Huang Rui, Honglei Huang, Julia Zhang, Jiqian Chen, Huang Rui

In PVH dom0, it uses the linux local interrupt mechanism,
when it allocs irq for a gsi, it is dynamic, and follow
the principle of applying first, distributing first. And
the irq number is alloced from small to large, but the
applying gsi number is not, may gsi 38 comes before gsi
28, that causes the irq number is not equal with the gsi
number. And when passthrough a device, qemu wants to use
gsi to map pirq, xen_pt_realize->xc_physdev_map_pirq, but
the gsi number is got from file
/sys/bus/pci/devices/<sbdf>/irq in current code, so it
will fail when mapping.

Use real gsi number read from gsi sysfs.

Co-developed-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
---
 hw/xen/xen-host-pci-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
index 8c6e9a1716..e270ac2631 100644
--- a/hw/xen/xen-host-pci-device.c
+++ b/hw/xen/xen-host-pci-device.c
@@ -364,7 +364,7 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
     }
     d->device_id = v;
 
-    xen_host_pci_get_dec_value(d, "irq", &v, errp);
+    xen_host_pci_get_dec_value(d, "gsi", &v, errp);
     if (*errp) {
         goto error;
     }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC QEMU PATCH v3 1/1] xen: Use gsi instead of irq for mapping pirq
  2023-12-10 16:52 ` [RFC QEMU PATCH v3 1/1] xen: Use gsi instead of irq for mapping pirq Jiqian Chen
@ 2023-12-11 15:33   ` Roger Pau Monné
  2023-12-12  6:37     ` Chen, Jiqian
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2023-12-11 15:33 UTC (permalink / raw)
  To: Jiqian Chen
  Cc: Stefano Stabellini, Anthony Perard, Paul Durrant, qemu-devel,
	xen-devel, Xenia Ragiadakou, Stewart Hildebrand, Alex Deucher,
	Huang Rui, Honglei Huang, Julia Zhang

On Mon, Dec 11, 2023 at 12:52:40AM +0800, Jiqian Chen wrote:
> In PVH dom0, it uses the linux local interrupt mechanism,
> when it allocs irq for a gsi, it is dynamic, and follow
> the principle of applying first, distributing first. And
> the irq number is alloced from small to large, but the
> applying gsi number is not, may gsi 38 comes before gsi
> 28, that causes the irq number is not equal with the gsi
> number. And when passthrough a device, qemu wants to use
> gsi to map pirq, xen_pt_realize->xc_physdev_map_pirq, but
> the gsi number is got from file
> /sys/bus/pci/devices/<sbdf>/irq in current code, so it
> will fail when mapping.
> 
> Use real gsi number read from gsi sysfs.
> 
> Co-developed-by: Huang Rui <ray.huang@amd.com>
> Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
> ---
>  hw/xen/xen-host-pci-device.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
> index 8c6e9a1716..e270ac2631 100644
> --- a/hw/xen/xen-host-pci-device.c
> +++ b/hw/xen/xen-host-pci-device.c
> @@ -364,7 +364,7 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
>      }
>      d->device_id = v;
>  
> -    xen_host_pci_get_dec_value(d, "irq", &v, errp);
> +    xen_host_pci_get_dec_value(d, "gsi", &v, errp);

Don't you need to fallthrough to use the irq number on failure?
Otherwise passthrough won't work on older Linux versions that don't
expose the gsi node.

Thanks, Roger.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC QEMU PATCH v3 1/1] xen: Use gsi instead of irq for mapping pirq
  2023-12-11 15:33   ` Roger Pau Monné
@ 2023-12-12  6:37     ` Chen, Jiqian
  0 siblings, 0 replies; 4+ messages in thread
From: Chen, Jiqian @ 2023-12-12  6:37 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Stefano Stabellini, Anthony Perard, Paul Durrant,
	qemu-devel@nongnu.org, xen-devel@lists.xenproject.org,
	Ragiadakou, Xenia, Hildebrand, Stewart, Deucher, Alexander,
	Huang, Ray, Huang, Honglei1, Zhang, Julia, Chen, Jiqian

On 2023/12/11 23:33, Roger Pau Monné wrote:
> On Mon, Dec 11, 2023 at 12:52:40AM +0800, Jiqian Chen wrote:
>> In PVH dom0, it uses the linux local interrupt mechanism,
>> when it allocs irq for a gsi, it is dynamic, and follow
>> the principle of applying first, distributing first. And
>> the irq number is alloced from small to large, but the
>> applying gsi number is not, may gsi 38 comes before gsi
>> 28, that causes the irq number is not equal with the gsi
>> number. And when passthrough a device, qemu wants to use
>> gsi to map pirq, xen_pt_realize->xc_physdev_map_pirq, but
>> the gsi number is got from file
>> /sys/bus/pci/devices/<sbdf>/irq in current code, so it
>> will fail when mapping.
>>
>> Use real gsi number read from gsi sysfs.
>>
>> Co-developed-by: Huang Rui <ray.huang@amd.com>
>> Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
>> ---
>>  hw/xen/xen-host-pci-device.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
>> index 8c6e9a1716..e270ac2631 100644
>> --- a/hw/xen/xen-host-pci-device.c
>> +++ b/hw/xen/xen-host-pci-device.c
>> @@ -364,7 +364,7 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
>>      }
>>      d->device_id = v;
>>  
>> -    xen_host_pci_get_dec_value(d, "irq", &v, errp);
>> +    xen_host_pci_get_dec_value(d, "gsi", &v, errp);
> 
> Don't you need to fallthrough to use the irq number on failure?
> Otherwise passthrough won't work on older Linux versions that don't
> expose the gsi node.
You are right, I will use the irq if there isn't a gsi sysfs, in next version. Thank you.

> 
> Thanks, Roger.

-- 
Best regards,
Jiqian Chen.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-12  6:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-10 16:52 [RFC QEMU PATCH v3 0/1] Support device passthrough when dom0 is PVH on Xen Jiqian Chen
2023-12-10 16:52 ` [RFC QEMU PATCH v3 1/1] xen: Use gsi instead of irq for mapping pirq Jiqian Chen
2023-12-11 15:33   ` Roger Pau Monné
2023-12-12  6:37     ` Chen, Jiqian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).