allow pass-through devices to share GSI
cover allow pass-through devices to share GSI
As discussed recently in the thread "[rfc 00/18] ioemu: use devfn instead of slots as the unit for passthrough", it would be useful if pass-through devices could share GSI.
The motivation for this is:
* Allow multi-function devices to be passed through as multi-function devices
- This implies that the devices may have functions that use INTB, C or D.
With the current scheme this would clash with the GSI of INTA on
device 13, 14, 15, 21, 22, 23, 29 ,30 and 31.
The INTX, device to GSI mapping is described in
xen/include/asm-x86/hvm/irq.h as:
#define hvm_pci_intx_gsi(dev, intx) \
(((((dev)<<2) + ((dev)>>3) + (intx)) & 31) + 16)
And is illustrated in this diagram
http://lists.xensource.com/archives/html/xen-devel/2009-02/pngmIO1Sm0VEX.png* Allow more than two pass-through devices.
- This will place more contention on the GSI-space, and allocation becomes a lot simpler if GSI sharing is allowed.
Signature · 3 lines
Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
RFC 1/2 pt_irq_time_out() should act on all machine_irq
In pt_irq_time_out() the following code loops through all used guest_gsi:
list_for_each_entry ( digl, &irq_map->digl_list, list )
{
guest_gsi = digl->gsi;
machine_gsi = dpci->girq[guest_gsi].machine_gsi;
...
}And a little later on machine_gsi is used. That is the last machine_gsi found is used, rather than all of the machine_gsi that are found.
This seems to be incorrect to me,
but I am unsure of how to test this.
This code appears to have been introduced in
"vt-d: Support intra-domain shared interrupt" by Weidong Han.
xen/drivers/passthrough/io.c +22 -4
@@ -37,6 +37,9 @@ static void pt_irq_time_out(void *data)struct hvm_irq_dpci *dpci =NULL ;struct dev_intx_gsi_link *digl;uint32_t device, intx; +DECLARE_BITMAP (machine_gsi_map,NR_IRQS ); + +bitmap_zero (machine_gsi_map,NR_IRQS );spin_lock (&irq_map->dom->event_lock);
@@ -46,16 +49,31 @@ static void pt_irq_time_out(void *data) { guest_gsi = digl->gsi; machine_gsi = dpci->girq[guest_gsi].machine_gsi; +set_bit (machine_gsi, machine_gsi_map); device = digl->device; intx = digl->intx;hvm_pci_intx_deassert (irq_map->dom, device, intx); } -clear_bit (machine_gsi, dpci->dirq_mask); - vector =domain_irq_to_vector (irq_map->dom, machine_gsi); - dpci->mirq[machine_gsi].pending =0 ; +for ( machine_gsi =find_first_bit (machine_gsi_map,NR_IRQS ); + machine_gsi <NR_IRQS ; + machine_gsi =find_next_bit (machine_gsi_map,NR_IRQS , + machine_gsi +1 ) ) + { +clear_bit (machine_gsi, dpci->dirq_mask); + vector =domain_irq_to_vector (irq_map->dom, machine_gsi); + dpci->mirq[machine_gsi].pending =0 ; + } +spin_unlock (&irq_map->dom->event_lock); -pirq_guest_eoi (irq_map->dom, machine_gsi); + +for ( machine_gsi =find_first_bit (machine_gsi_map,NR_IRQS ); + machine_gsi <NR_IRQS ; + machine_gsi =find_next_bit (machine_gsi_map,NR_IRQS , + machine_gsi +1 ) ) + { +pirq_guest_eoi (irq_map->dom, machine_gsi); + } } int pt_irq_create_bind_vtd(
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
RE: [rfc 1/2] pt_irq_time_out() should act on all machine_irq
Quoted 10 lines · Simon Horman
In
pt_irq_time_out()the following code loops through all usedguest_gsi:list_for_each_entry ( digl, &irq_map->digl_list, list ) { guest_gsi = digl->gsi; machine_gsi = dpci->girq[guest_gsi].machine_gsi; ... }
Quoted 7 lines
And a little later on
machine_gsiis used. That is the lastmachine_gsifound is used, rather than all of themachine_gsithat are found.This seems to be incorrect to me,
but I am unsure of how to test this.
Timer is set for each machine GSI, so all the machine_gsi found in loop are the same. More than one devices may share machine GSI, but assume they won't share guest gsi. digl_list contains all guest GSIs which are correspond to this a machine GSI.
Now you want pass-throughed devices share guest gsi, you needs to change it obviously. Your below change looks fine for me.
Regards,
Weidong
Quoted 59 lines
This code appears to have been introduced in
"vt-d: Support intra-domain shared interrupt" by Weidong Han.Cc Weidong Han <[email protected]>Cc Yuji Shimada <[email protected]>Signed-off-by Simon Horman <[email protected]>Index:
xen-unstable.hg/xen/drivers/passthrough/io.c
===================================================================
---xen-unstable.hg.orig/xen/drivers/passthrough/io.c2009-03-09
12:44:48.000000000 +1100 +++xen-unstable.hg/xen/drivers/passthrough/io.c2009-03-0912:58:28.000000000 +1100 @@ -37,6 +37,9 @@ static void pt_irq_time_out(void *data) struct hvm_irq_dpci *dpci = NULL; struct dev_intx_gsi_link *digl; uint32_t device, intx;xen/drivers/passthrough/io.c +22
-5+DECLARE_BITMAP (machine_gsi_map,NR_IRQS ); + +bitmap_zero (machine_gsi_map,NR_IRQS );spin_lock (&irq_map->dom->event_lock);@@ -46,16 +49,31 @@ static void pt_irq_time_out(void *data) { guest_gsi = digl->gsi; machine_gsi = dpci->girq[guest_gsi].machine_gsi; +set_bit (machine_gsi, machine_gsi_map); device = digl->device; intx = digl->intx;hvm_pci_intx_deassert (irq_map->dom, device, intx); } -clear_bit (machine_gsi, dpci->dirq_mask); - vector =domain_irq_to_vector (irq_map->dom, machine_gsi); - dpci->mirq[machine_gsi].pending =0 ; +for ( machine_gsi =find_first_bit (machine_gsi_map,NR_IRQS ); + machine_gsi <NR_IRQS ; + machine_gsi =find_next_bit (machine_gsi_map,NR_IRQS , + machine_gsi +1 ) ) + { +clear_bit (machine_gsi, dpci->dirq_mask); + vector =domain_irq_to_vector (irq_map->dom, machine_gsi); + dpci->mirq[machine_gsi].pending =0 ; + } +spin_unlock (&irq_map->dom->event_lock); -pirq_guest_eoi (irq_map->dom, machine_gsi); + +for ( machine_gsi =find_first_bit (machine_gsi_map,NR_IRQS ); + machine_gsi <NR_IRQS ; + machine_gsi =find_next_bit (machine_gsi_map,NR_IRQS , + machine_gsi +1 ) ) + { +pirq_guest_eoi (irq_map->dom, machine_gsi); + } } int pt_irq_create_bind_vtd( --
Re: RE: [rfc 1/2] pt_irq_time_out() should act on all machine_irq
Quoted 15 lines · Weidong
Quoted 14 lines · Simon Horman
In
pt_irq_time_out()the following code loops through all usedguest_gsi:list_for_each_entry ( digl, &irq_map->digl_list, list ) { guest_gsi = digl->gsi; machine_gsi = dpci->girq[guest_gsi].machine_gsi; ... }And a little later on
machine_gsiis used. That is the lastmachine_gsifound is used, rather than all of themachine_gsithat are found.
Quoted 8 lines
Quoted 3 lines
This seems to be incorrect to me, but I am unsure of how to test this.
Timer is set for each machine GSI, so all the
machine_gsifound in loop are the same. More than one devices may share machine GSI, but assume they won't share guest gsi.digl_listcontains all guest GSIs which are correspond to this a machine GSI.
Ok, thanks. I understand now.
Quoted 3 lines
Now you want pass-throughed devices share guest gsi, you needs to change it obviously. Your below change looks fine for me.
Thanks
Signature · 3 lines
Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
RFC 2/2 allow pass-through devices to share GSI
In reply to Simon HormanAllow multiple pass-through devices to use the same guest_gsi.
The motivation for this is:
* Allow multi-function devices to be passed through as multi-function devices
- This implies that the devices may have functions that use INTB, C or D.
With the current scheme this would clash with the GSI of INTA on
device 13, 14, 15, 21, 22, 23, 29 ,30 and 31.
The INTX, device to GSI mapping is described in
xen/include/asm-x86/hvm/irq.h as:
#define hvm_pci_intx_gsi(dev, intx) \
(((((dev)<<2) + ((dev)>>3) + (intx)) & 31) + 16)
And is illustrated in this diagram
http://lists.xensource.com/archives/html/xen-devel/2009-02/pngmIO1Sm0VEX.png* Allow more than two pass-through devices.
- This will place more contention on the GSI-space, and allocation becomes a lot simpler if GSI sharing is allowed.
---
This seems to work.
Tested by changing the GSI mapping so that dev 6 and 7 both use the same GSI. Then passign through two ethernet MICs. I was able to ping using both NICs and confirmed with some debugging code that they were assigned the same guest GSI.
xen/drivers/passthrough/io.c | 111 ++++++++++++++++++++++++++---------------- xen/include/xen/hvm/irq.h | 4 - 2 files changed, 71 insertions(+), 44 deletions(-)
xen/include/xen/hvm/irq.h +2 -2
@@ -60,7 +60,7 @@ struct hvm_mirq_dpci_mapping { };struct hvm_girq_dpci_mapping { -uint8_t valid; +struct list_head list;uint8_t device;uint8_t intx;uint8_t machine_gsi;
@@ -75,7 +75,7 @@ struct hvm_irq_dpci {DECLARE_BITMAP (mapping,NR_IRQS );struct hvm_mirq_dpci_mapping mirq[NR_IRQS ];/* Guest IRQ to guest device/intx mapping. */ -struct hvm_girq_dpci_mapping girq[NR_IRQS ]; +struct list_head girq[NR_IRQS ];uint8_t msi_gvec_pirq[NR_VECTORS ];DECLARE_BITMAP (dirq_mask,NR_IRQS );/* Record of mapped ISA IRQs */
xen/drivers/passthrough/io.c +69 -42
183 lines not on this page · raw message
Signature · 4 lines
-- Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en