x86/dpci: bind legacy PCI interrupts to PVHv2 Dom0
v2 cover x86/dpci: bind legacy PCI interrupts to PVHv2 Dom0
Hello,
The following patches allow binding bare-metal GSIs into a PVHv2 Dom0, by snooping on the vIO APICs writes made by Dom0.
This new version has reduced the number of patches from 5 to 3, first two patches introduce the necessary code to bind GSIs into a PVH Dom0, and patch 3 snoops on vIO APIC writes for unmask and binds the GSI to Dom0.
The series has been tested with a PVHv2 Dom0 on a box with 3 IO APICs, although all devices are wired up into the first IO APIC sadly.
A branch with the changes can be found at:
git://xenbits.xen.org/people/royger/xen.git dom0_gsi_v2
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 1/3 x86/physdev: factor out the code to allocate and map a pirq
Move the code to allocate and map a domain pirq (either GSI or MSI) into the x86 irq code base, so that it can be used outside of the physdev ops.
This change shouldn't affect the functionality of the already existing physdev ops.
---
Jan Beulich <[email protected]>
Andrew Cooper <[email protected]>
---
Changes since v1:
- New in this version.
--- xen/arch/x86/irq.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/physdev.c | 124 ++------------------------------ xen/include/asm-x86/irq.h | 5 ++ 3 files changed, 185 insertions(+), 119 deletions(-)
xen/arch/x86/irq.c +175 -0
@@ -2537,3 +2537,178 @@ bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq)return is_hvm_domain (d) && pirq && pirq->arch.hvm.emuirq !=IRQ_UNBOUND ; } + +int allocate_and_map_gsi_pirq (struct domain *d,int *index,int *pirq_p) +{ +int irq, pirq, ret; + +if ( *index <0 || *index >= nr_irqs_gsi ) + { +dprintk (XENLOG_G_ERR ,"dom%d: map invalid irq %d\n" , d->domain_id, + *index); +return -EINVAL ; + } + + irq =domain_pirq_to_irq (current->domain, *index); +if ( irq <=0 ) + { +if (is_hardware_domain (current->domain) ) + irq = *index; +else { +dprintk (XENLOG_G_ERR ,"dom%d: map pirq with incorrect irq!\n" , + d->domain_id); +return -EINVAL ; + } + } + +pcidevs_lock (); +/* Verify or get pirq. */ +spin_lock (&d->event_lock); + pirq =domain_irq_to_pirq (d, irq); + +if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else + { + pirq =get_free_pirq (d,MAP_PIRQ_TYPE_GSI ); +if ( pirq <0 ) + { +dprintk (XENLOG_G_ERR ,"dom%d: no free pirq\n" , d->domain_id); + ret = pirq; + goto done; + } + } + } +else + { +if ( pirq && pirq != *pirq_p ) + { +dprintk (XENLOG_G_ERR ,"dom%d: pirq %d conflicts with irq %d\n" , + d->domain_id, *index, *pirq_p); + ret = -EEXIST ; + goto done; + } +else + pirq = *pirq_p; + } + + ret =map_domain_pirq (d, pirq, irq,MAP_PIRQ_TYPE_GSI ,NULL ); +if ( ret ==0 ) + *pirq_p = pirq; + + done: +spin_unlock (&d->event_lock); +pcidevs_unlock (); +return ret; +} + +int allocate_and_map_msi_pirq (struct domain *d,int *index,int *pirq_p, +struct msi_info *msi) +{ +int irq, pirq, ret, type; + + irq = *index; +if ( irq ==-1 || msi->entry_nr >1 ) + irq =create_irq (NUMA_NO_NODE ); + +if ( irq < nr_irqs_gsi || irq >= nr_irqs ) + { +dprintk (XENLOG_G_ERR ,"dom%d: can't create irq for msi!\n" , + d->domain_id); + ret = -EINVAL ; + goto free_irq; + } + + msi->irq = irq; + type = (msi->entry_nr >1 && !msi->table_base) ?MAP_PIRQ_TYPE_MULTI_MSI + :MAP_PIRQ_TYPE_MSI ; + +pcidevs_lock (); +/* Verify or get pirq. */ +spin_lock (&d->event_lock); + pirq =domain_irq_to_pirq (d, irq); +if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else if ( msi->entry_nr >1 && !msi->table_base ) + { +if ( msi->entry_nr <=0 || msi->entry_nr >32 ) + ret = -EDOM ; +else if ( msi->entry_nr !=1 && !iommu_intremap ) + ret = -EOPNOTSUPP ; +else + { +while ( msi->entry_nr & (msi->entry_nr -1 ) ) + msi->entry_nr += msi->entry_nr & -msi->entry_nr; + pirq =get_free_pirqs (d, msi->entry_nr); + ret =0 ; +if ( pirq <0 ) + { +while ( (msi->entry_nr >>=1 ) >1 ) +if (get_free_pirqs (d, msi->entry_nr) >0 ) +break ; +dprintk (XENLOG_G_ERR ,"dom%d: no block of %d free pirqs\n" , + d->domain_id, msi->entry_nr <<1 ); + ret = pirq; + } + } +if ( ret <0 ) + goto done; + } +else + { + pirq =get_free_pirq (d, type); +if ( pirq <0 ) + { +dprintk (XENLOG_G_ERR ,"dom%d: no free pirq\n" , d->domain_id); + ret = pirq; + goto done; + } + } + } +else + { +if ( pirq && pirq != *pirq_p ) + { +dprintk (XENLOG_G_ERR ,"dom%d: pirq %d conflicts with irq %d\n" , + d->domain_id, *index, *pirq_p); + ret = -EEXIST ; + goto done; + } +else + pirq = *pirq_p; + } + + ret =map_domain_pirq (d, pirq, irq, type, msi); +if ( ret ==0 ) + *pirq_p = pirq; + + done: +spin_unlock (&d->event_lock); +pcidevs_unlock (); + free_irq: +if ( ret !=0 && + ((msi->entry_nr >1 && !msi->table_base) || *index ==-1 ) ) +destroy_irq (irq); +return ret; +} +
xen/arch/x86/physdev.c +5 -119
148 lines not on this page · raw message
xen/include/asm-x86/irq.h +5 -0
@@ -200,4 +200,9 @@ bool_t cpu_has_pending_apic_eoi(void);static inline void arch_move_irqs (struct vcpu *v) { } +struct msi_info ; +int allocate_and_map_gsi_pirq (struct domain *d,int *index,int *pirq_p); +int allocate_and_map_msi_pirq (struct domain *d,int *index,int *pirq_p, +struct msi_info *msi); +#endif /* _ASM_HW_IRQ_H */
Signature · 7 lines
2.11.0 (Apple Git-81) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 1/3] x86/physdev: factor out the code to allocate and map a pirq
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
xen/arch/x86/irq.c +7
-0+int allocate_and_map_gsi_pirq (struct domain *d,int *index,int *pirq_p) +{ +int irq, pirq, ret; + +if ( *index <0 || *index >= nr_irqs_gsi ) + { + dprintk(XENLOG_G_ERR, "dom%d: map invalid irq %d\n", d->domain_id,
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2557
Quoted 10 lines
xen/arch/x86/irq.c +10
-0+ *index); +return -EINVAL ; + } + + irq =domain_pirq_to_irq (current->domain, *index); +if ( irq <=0 ) + { +if (is_hardware_domain (current->domain) ) + irq = *index; +else {
Please adjust coding style issues like the brace placement here.
Quoted 38 lines
xen/arch/x86/irq.c +38
-0+pcidevs_lock (); +/* Verify or get pirq. */ +spin_lock (&d->event_lock); + pirq =domain_irq_to_pirq (d, irq); + +if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else + { + pirq =get_free_pirq (d,MAP_PIRQ_TYPE_GSI ); +if ( pirq <0 ) + { +dprintk (XENLOG_G_ERR ,"dom%d: no free pirq\n" , d->domain_id); + ret = pirq; + goto done; + } + } + } +else + { +if ( pirq && pirq != *pirq_p ) + { +dprintk (XENLOG_G_ERR ,"dom%d: pirq %d conflicts with irq %d\n" , + d->domain_id, *index, *pirq_p); + ret = -EEXIST ; + goto done; + } +else
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2611
Quoted 10 lines
xen/arch/x86/irq.c +10
-0+ pirq = *pirq_p; + } + + ret =map_domain_pirq (d, pirq, irq,MAP_PIRQ_TYPE_GSI ,NULL ); +if ( ret ==0 ) + *pirq_p = pirq; + + done: +spin_unlock (&d->event_lock); +pcidevs_unlock ();
All of the code above is being repeated in allocate_and_map_msi_pirq(), merely with the multi-MSI addition. This is too much code duplication for my taste. Additionally, with it being split like this it is then questionable what acquiring the PCI devices lock is good for here (I would think it is needed at most in the MSI case).
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2622
Quoted 8 lines
xen/arch/x86/irq.c +8
-0+int allocate_and_map_msi_pirq (struct domain *d,int *index,int *pirq_p, +struct msi_info *msi) +{ +int irq, pirq, ret, type; + + irq = *index; +if ( irq ==-1 || msi->entry_nr >1 ) + irq =create_irq (NUMA_NO_NODE );
This doesn't look to be an exact equivalent of the original code: Even with MAP_PIRQ_TYPE_MULTI_MSI entry_nr may be 1, and the original code calls create_irq() also in that case. If this is an intended change, the rationale should be provided in the commit message. But as you don't alter map_domain_pirq(), I doubt this is correct.
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2634
Quoted 11 lines
xen/arch/x86/irq.c +11
-0+if ( irq < nr_irqs_gsi || irq >= nr_irqs ) + { +dprintk (XENLOG_G_ERR ,"dom%d: can't create irq for msi!\n" , + d->domain_id); + ret = -EINVAL ; + goto free_irq; + } + + msi->irq = irq; + type = (msi->entry_nr >1 && !msi->table_base) ?MAP_PIRQ_TYPE_MULTI_MSI + :MAP_PIRQ_TYPE_MSI ;
Same here - you're not necessarily reconstructing the type passed into the hypercall.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 1/3] x86/physdev: factor out the code to allocate and map a pirq
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
xen/arch/x86/irq.c +11
-0+int allocate_and_map_gsi_pirq (struct domain *d,int *index,int *pirq_p) +{ +int irq, pirq, ret; + +if ( *index <0 || *index >= nr_irqs_gsi ) + { +dprintk (XENLOG_G_ERR ,"dom%d: map invalid irq %d\n" , d->domain_id, + *index); +return -EINVAL ; + } +
Quoted 8 lines
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2557
Quoted 6 lines
xen/arch/x86/irq.c +6
-0+ irq =domain_pirq_to_irq (current->domain, *index); +if ( irq <=0 ) + { +if (is_hardware_domain (current->domain) ) + irq = *index; +else {Please adjust coding style issues like the brace placement here.
Done.
Quoted 44 lines
Quoted 44 lines
xen/arch/x86/irq.c +44
-0+pcidevs_lock (); +/* Verify or get pirq. */ +spin_lock (&d->event_lock); + pirq =domain_irq_to_pirq (d, irq); + +if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else + { + pirq =get_free_pirq (d,MAP_PIRQ_TYPE_GSI ); +if ( pirq <0 ) + { +dprintk (XENLOG_G_ERR ,"dom%d: no free pirq\n" , d->domain_id); + ret = pirq; + goto done; + } + } + } +else + { +if ( pirq && pirq != *pirq_p ) + { +dprintk (XENLOG_G_ERR ,"dom%d: pirq %d conflicts with irq %d\n" , + d->domain_id, *index, *pirq_p); + ret = -EEXIST ; + goto done; + } +else + pirq = *pirq_p; + } + + ret =map_domain_pirq (d, pirq, irq,MAP_PIRQ_TYPE_GSI ,NULL ); +if ( ret ==0 ) + *pirq_p = pirq;
Quoted 8 lines
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2611
Quoted 4 lines
xen/arch/x86/irq.c +4
-0+ + done: +spin_unlock (&d->event_lock); +pcidevs_unlock ();All of the code above is being repeated in
allocate_and_map_msi_pirq(), merely with the multi-MSI addition. This is too much code duplication for my taste.
I can try to factor this out into a separate helper that's used by both.
Quoted 3 lines
Additionally, with it being split like this it is then questionable what acquiring the PCI devices lock is good for here (I would think it is needed at most in the MSI case).
Right, also I'm not sure why the PCI devices lock is acquired before calling into domain_irq_to_pirq, is that because of lock ordering rules with the domain event lock?
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/irq.c +6
-0+int allocate_and_map_msi_pirq (struct domain *d,int *index,int *pirq_p, +struct msi_info *msi) +{ +int irq, pirq, ret, type; + + irq = *index;
Quoted 8 lines
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2622
Quoted 2 lines
xen/arch/x86/irq.c +2
-0+if ( irq ==-1 || msi->entry_nr >1 ) + irq =create_irq (NUMA_NO_NODE );This doesn't look to be an exact equivalent of the original code: Even with
MAP_PIRQ_TYPE_MULTI_MSIentry_nrmay be 1, and the original code callscreate_irq()also in that case. If this is an intended change, the rationale should be provided in the commit message. But as you don't altermap_domain_pirq(), I doubt this is correct.
My bad then, it's quite hard for me to figure out exactly what's the meaning/usage of those types, since they are not documented anywhere that I can find. physdev.h contains 3 different MSI related types:
* MAP_PIRQ_TYPE_MSI_SEG maps into MAP_PIRQ_TYPE_MSI.
* MAP_PIRQ_TYPE_MULTI_MSI is only available to map MSI interrupts (no MSI-X).
* MAP_PIRQ_TYPE_MSI can map both MSI/MSI-X:
- If table_base != 0 it's a MSI-X interrupt.
- If table_base == 0 it's a single MSI interrupt AND entry_nr must be 1.
Let me know if this is accurate.
Quoted 12 lines
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2634
Quoted 11 lines
xen/arch/x86/irq.c +11
-0+if ( irq < nr_irqs_gsi || irq >= nr_irqs ) + { +dprintk (XENLOG_G_ERR ,"dom%d: can't create irq for msi!\n" , + d->domain_id); + ret = -EINVAL ; + goto free_irq; + } + + msi->irq = irq; + type = (msi->entry_nr >1 && !msi->table_base) ?MAP_PIRQ_TYPE_MULTI_MSI + :MAP_PIRQ_TYPE_MSI ;
Quoted 2 lines
Same here - you're not necessarily reconstructing the type passed into the hypercall.
Right, see my comment above.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 1/3] x86/physdev: factor out the code to allocate and map a pirq
Quoted 58 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 11:47, <[email protected]> wrote:
Quoted 45 lines · Jan Beulich
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
xen/arch/x86/irq.c +44
-0+pcidevs_lock (); +/* Verify or get pirq. */ +spin_lock (&d->event_lock); + pirq =domain_irq_to_pirq (d, irq); + +if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else + { + pirq =get_free_pirq (d,MAP_PIRQ_TYPE_GSI ); +if ( pirq <0 ) + { +dprintk (XENLOG_G_ERR ,"dom%d: no free pirq\n" , d->domain_id); + ret = pirq; + goto done; + } + } + } +else + { +if ( pirq && pirq != *pirq_p ) + { +dprintk (XENLOG_G_ERR ,"dom%d: pirq %d conflicts with irq %d\n" , + d->domain_id, *index, *pirq_p); + ret = -EEXIST ; + goto done; + } +else + pirq = *pirq_p; + } + + ret =map_domain_pirq (d, pirq, irq,MAP_PIRQ_TYPE_GSI ,NULL ); +if ( ret ==0 ) + *pirq_p = pirq;Quoted 8 lines
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2611
Quoted 4 lines
xen/arch/x86/irq.c +4
-0+ + done: +spin_unlock (&d->event_lock); +pcidevs_unlock ();All of the code above is being repeated in
allocate_and_map_msi_pirq(), merely with the multi-MSI addition. This is too much code duplication for my taste.I can try to factor this out into a separate helper that's used by both.
Quoted 7 lines
Quoted 3 lines
Additionally, with it being split like this it is then questionable what acquiring the PCI devices lock is good for here (I would think it is needed at most in the MSI case).
Right, also I'm not sure why the PCI devices lock is acquired before calling into
domain_irq_to_pirq, is that because of lock ordering rules with the domain event lock?
Yes. map_domain_pirq() in the MSI case requires both locks to be held.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/irq.c +6
-0+int allocate_and_map_msi_pirq (struct domain *d,int *index,int *pirq_p, +struct msi_info *msi) +{ +int irq, pirq, ret, type; + + irq = *index;Quoted 8 lines
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2622
Quoted 2 lines
xen/arch/x86/irq.c +2
-0+if ( irq ==-1 || msi->entry_nr >1 ) + irq =create_irq (NUMA_NO_NODE );This doesn't look to be an exact equivalent of the original code: Even with
MAP_PIRQ_TYPE_MULTI_MSIentry_nrmay be 1, and the original code callscreate_irq()also in that case. If this is an intended change, the rationale should be provided in the commit message. But as you don't altermap_domain_pirq(), I doubt this is correct.
Quoted 5 lines
My bad then, it's quite hard for me to figure out exactly what's the meaning/usage of those types, since they are not documented anywhere that I can find.
physdev.hcontains 3 different MSI related types:*
MAP_PIRQ_TYPE_MSI_SEGmaps intoMAP_PIRQ_TYPE_MSI.
This was needed because of the extra segment information which wasn't part of the original MAP_PIRQ_TYPE_MSI. Otherwise the two are identical, so ..
Quoted 6 lines
*
MAP_PIRQ_TYPE_MULTI_MSIis only available to map MSI interrupts (no MSI-X).
*MAP_PIRQ_TYPE_MSIcan map both MSI/MSI-X:
- Iftable_base!= 0 it's a MSI-X interrupt.
- Iftable_base== 0 it's a single MSI interrupt ANDentry_nrmust be 1.Let me know if this is accurate.
... almost - entry_nr when coming in as hypercall argument isn't required to be 1; instead physdev_map_pirq() sets it to 1 when table_base is zero.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 1/3] x86/physdev: factor out the code to allocate and map a pirq
In reply to Roger Pau MonneOn Wed, Apr 19, 2017 at 04:11:26PM +0100, Roger Pau Monne wrote:
[...]
Quoted 19 lines
xen/arch/x86/irq.c +19
-0+if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else if ( msi->entry_nr >1 && !msi->table_base ) + { +if ( msi->entry_nr <=0 || msi->entry_nr >32 ) + ret = -EDOM ; +else if ( msi->entry_nr !=1 && !iommu_intremap ) + ret = -EOPNOTSUPP ; +else
xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2668
Quoted 10 lines
xen/arch/x86/irq.c +10
-0+ { +while ( msi->entry_nr & (msi->entry_nr -1 ) ) + msi->entry_nr += msi->entry_nr & -msi->entry_nr; + pirq =get_free_pirqs (d, msi->entry_nr); + ret =0 ; +if ( pirq <0 ) + { +while ( (msi->entry_nr >>=1 ) >1 ) +if (get_free_pirqs (d, msi->entry_nr) >0 ) +break ;
Maybe I'm missing something, but I think the code above should be:
if ( (pirq = get_free_pirqs(d, msi->entry_nr)) > 0 )
break;Or else the pirq returned by get_free_pirqs is not stored anywhere, and thus pirq will be -ENOSPC even when PIRQs have been allocated.
Let me know if this is true or not, so that I can send a patch to fix the current code (which also has this issue).
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 1/3] x86/physdev: factor out the code to allocate and map a pirq
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 13:52, <[email protected]> wrote:
On Wed, Apr 19, 2017 at 04:11:26PM +0100, Roger Pau Monne wrote:
[...]Quoted 19 lines
xen/arch/x86/irq.c +19
-0+if ( *pirq_p <0 ) + { +if ( pirq ) + { +dprintk (XENLOG_G_ERR ,"dom%d: %d:%d already mapped to %d\n" , + d->domain_id, *index, *pirq_p, pirq); +if ( pirq <0 ) + { + ret = -EBUSY ; + goto done; + } + } +else if ( msi->entry_nr >1 && !msi->table_base ) + { +if ( msi->entry_nr <=0 || msi->entry_nr >32 ) + ret = -EDOM ; +else if ( msi->entry_nr !=1 && !iommu_intremap ) + ret = -EOPNOTSUPP ; +else xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2668
Quoted 10 lines
xen/arch/x86/irq.c +10
-0+ { +while ( msi->entry_nr & (msi->entry_nr -1 ) ) + msi->entry_nr += msi->entry_nr & -msi->entry_nr; + pirq =get_free_pirqs (d, msi->entry_nr); + ret =0 ; +if ( pirq <0 ) + { +while ( (msi->entry_nr >>=1 ) >1 ) +if (get_free_pirqs (d, msi->entry_nr) >0 ) +break ;Maybe I'm missing something, but I think the code above should be:
Quoted 8 lines
if ( (pirq = get_free_pirqs(d, msi->entry_nr)) > 0 ) break;Or else the pirq returned by
get_free_pirqsis not stored anywhere, and thus pirq will be-ENOSPCeven when PIRQs have been allocated.Let me know if this is true or not, so that I can send a patch to fix the current code (which also has this issue).
The code is correct. get_free_pirqs() doesn't alter the slots it finds free, and here we only want to know how many we could allocate at this point (given that we weren't able to allocate as many as were requested).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 2/3 x86/pt: enable binding of GSIs to a PVH Dom0
In reply to Roger Pau MonneAchieve this by expanding pt_irq_create_bind in order to support mapping interrupts of type PT_IRQ_TYPE_PCI to a PVH Dom0. GSIs bound to Dom0 are always identity bound, which means the all the fields inside of the u.pci sub-struct are ignored, and only the machine_irq is actually used in order to determine which GSI the caller wants to bind.
Also, the hvm_irq_dpci struct is not used by a PVH Dom0, since that's used to route interrupts and allow different host to guest GSI mappings, which is not used by a PVH Dom0.
This requires adding some specific handlers for such directly mapped GSIs, which bypass the PCI interrupt routing done by Xen for HVM guests.
Note that currently there's no support for unbinding this interrupts.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v1:
- Remove the PT_IRQ_TYPE_GSI and instead just use PT_IRQ_TYPE_PCI with a hardware domain special casing.
- Check the trigger mode of the Dom0 vIO APIC in order to set the shareable flags in pt_irq_create_bind.
--- xen/arch/x86/hvm/irq.c | 28 ++++++ xen/drivers/passthrough/io.c | 212 ++++++++++++++++++++++++++++++++----------- xen/include/xen/hvm/irq.h | 6 ++ 3 files changed, 195 insertions(+), 51 deletions(-)
xen/arch/x86/hvm/irq.c +28 -0
@@ -126,6 +126,34 @@ void hvm_pci_intx_deassert(spin_unlock (&d->arch.hvm_domain.irq_lock); } +void hvm_gsi_assert (struct domain *d,unsigned int gsi) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); + +ASSERT (gsi < hvm_irq->nr_gsis); +ASSERT (!has_vpic (d)); +spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !hvm_irq->gsi_assert_count[gsi] ) + { + hvm_irq->gsi_assert_count[gsi]++; +assert_gsi (d, gsi); + } +spin_unlock (&d->arch.hvm_domain.irq_lock); +} + +void hvm_gsi_deassert (struct domain *d,unsigned int gsi) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); + +ASSERT (gsi < hvm_irq->nr_gsis); +ASSERT (!has_vpic (d)); +spin_lock (&d->arch.hvm_domain.irq_lock); +if ( hvm_irq->gsi_assert_count[gsi] ) + hvm_irq->gsi_assert_count[gsi]--; +ASSERT (!hvm_irq->gsi_assert_count[gsi]); +spin_unlock (&d->arch.hvm_domain.irq_lock); +} +void hvm_isa_irq_assert (struct domain *d,unsigned int isa_irq) {
xen/drivers/passthrough/io.c +161 -51
330 lines not on this page · raw message
xen/include/xen/hvm/irq.h +6 -0
@@ -40,6 +40,7 @@ struct dev_intx_gsi_link {#define _HVM_IRQ_DPCI_EOI_LATCH_SHIFT 3#define _HVM_IRQ_DPCI_GUEST_PCI_SHIFT 4#define _HVM_IRQ_DPCI_GUEST_MSI_SHIFT 5 +#define _HVM_IRQ_DPCI_IDENTITY_GSI_SHIFT 6#define _HVM_IRQ_DPCI_TRANSLATE_SHIFT 15#define HVM_IRQ_DPCI_MACH_PCI (1 << _HVM_IRQ_DPCI_MACH_PCI_SHIFT)#define HVM_IRQ_DPCI_MACH_MSI (1 << _HVM_IRQ_DPCI_MACH_MSI_SHIFT)
@@ -47,6 +48,7 @@ struct dev_intx_gsi_link {#define HVM_IRQ_DPCI_EOI_LATCH (1 << _HVM_IRQ_DPCI_EOI_LATCH_SHIFT)#define HVM_IRQ_DPCI_GUEST_PCI (1 << _HVM_IRQ_DPCI_GUEST_PCI_SHIFT)#define HVM_IRQ_DPCI_GUEST_MSI (1 << _HVM_IRQ_DPCI_GUEST_MSI_SHIFT) +#define HVM_IRQ_DPCI_IDENTITY_GSI (1 << _HVM_IRQ_DPCI_IDENTITY_GSI_SHIFT)#define HVM_IRQ_DPCI_TRANSLATE (1 << _HVM_IRQ_DPCI_TRANSLATE_SHIFT)#define VMSI_DEST_ID_MASK 0xff
@@ -123,6 +125,10 @@ void hvm_isa_irq_assert(void hvm_isa_irq_deassert (struct domain *d,unsigned int isa_irq); +/* Modify state of GSIs. */ +void hvm_gsi_assert (struct domain *d,unsigned int gsi); +void hvm_gsi_deassert (struct domain *d,unsigned int gsi); +int hvm_set_pci_link_route (struct domain *d,u8 link,u8 isa_irq);int hvm_inject_msi (struct domain *d,uint64_t addr,uint32_t data);
Signature · 7 lines
2.11.0 (Apple Git-81) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify pt_irq_destroy_bind(), so I'm a little puzzled ...
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 133
Quoted 11 lines
xen/arch/x86/hvm/irq.c +5
-0@@ -126,6 +126,34 @@ void hvm_pci_intx_deassert(spin_unlock (&d->arch.hvm_domain.irq_lock); } +void hvm_gsi_assert (struct domain *d,unsigned int gsi) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); + +ASSERT (gsi < hvm_irq->nr_gsis);
This would probably better match the alternative construct in __hvm_pci_intx_assert().
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 134
Quoted 1 line
xen/arch/x86/hvm/irq.c +1
-0+ASSERT (!has_vpic (d));
This doesn't look to be relevant for the rest of the function. Is there a particular reason you've added it? If so, a brief comment might help.
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 138
Quoted 4 lines
xen/arch/x86/hvm/irq.c +4
-0+spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !hvm_irq->gsi_assert_count[gsi] ) + { + hvm_irq->gsi_assert_count[gsi]++;
Why is this an increment instead of a simple write of 1? Or the other way around - why is this not always incrementing, just like __hvm_pci_intx_assert() does? (Symmetric questions then for hvm_gsi_deassert()).
Quoted 4 lines
xen/arch/x86/hvm/irq.c +0
-0@@ -274,10 +289,16 @@ int pt_irq_create_bind(spin_lock (&d->event_lock); hvm_irq_dpci =domain_get_irq_dpci (d);
xen/arch/x86/hvm/irq.c int pt_irq_create_bind( · line 300
Quoted 10 lines
xen/arch/x86/hvm/irq.c +6
-1-if ( hvm_irq_dpci ==NULL ) +if ( hvm_irq_dpci ==NULL && !is_hardware_domain (d) ) {unsigned int i; +/* +* NB: the hardware domain doesn't use a hvm_irq_dpci struct because +* it's only allowed to identity map GSIs, and so the data contained in +* that struct (used to map guest GSIs into machine GSIs and perform +* interrupt routing) it's completely useless for it.
"...) is completely useless to it."
Quoted 63 lines
xen/arch/x86/hvm/irq.c +30
-24@@ -422,35 +443,51 @@ int pt_irq_create_bind(case PT_IRQ_TYPE_PCI :case PT_IRQ_TYPE_MSI_TRANSLATE : { -unsigned int bus = pt_irq_bind->u.pci.bus; -unsigned int device = pt_irq_bind->u.pci.device; -unsigned int intx = pt_irq_bind->u.pci.intx; -unsigned int guest_gsi =hvm_pci_intx_gsi (device, intx); -unsigned int link =hvm_pci_intx_link (device, intx); - struct dev_intx_gsi_link *digl = xmalloc(struct dev_intx_gsi_link); -struct hvm_girq_dpci_mapping *girq = - xmalloc(struct hvm_girq_dpci_mapping); +struct dev_intx_gsi_link *digl =NULL ; +struct hvm_girq_dpci_mapping *girq =NULL ; +unsigned int guest_gsi; -if ( !digl || !girq ) +/* +* Mapping GSIs for the hardware domain is different than doing it for +* an unpriviledged guest, the hardware domain is only allowed to +* identity map GSIs, and as such all the data in the u.pci union is +* discarded. +*/ +if ( !is_hardware_domain (d) ) { -spin_unlock (&d->event_lock); -xfree (girq); -xfree (digl); -return -ENOMEM ; - } +unsigned int link; + + digl = xmalloc(struct dev_intx_gsi_link); + girq = xmalloc(struct hvm_girq_dpci_mapping); + +if ( !digl || !girq ) + { +spin_unlock (&d->event_lock); +xfree (girq); +xfree (digl); +return -ENOMEM ; + } + + girq->bus = digl->bus = pt_irq_bind->u.pci.bus; + girq->device = digl->device = pt_irq_bind->u.pci.device; + girq->intx = digl->intx = pt_irq_bind->u.pci.intx; +list_add_tail (&digl->list, &pirq_dpci->digl_list); - hvm_irq_dpci->link_cnt[link]++; + guest_gsi =hvm_pci_intx_gsi (digl->device, digl->intx); + link =hvm_pci_intx_link (digl->device, digl->intx); - digl->bus = bus; - digl->device = device; - digl->intx = intx; -list_add_tail (&digl->list, &pirq_dpci->digl_list); + hvm_irq_dpci->link_cnt[link]++; - girq->bus = bus; - girq->device = device; - girq->intx = intx; - girq->machine_gsi = pirq; -list_add_tail (&girq->list, &hvm_irq_dpci->girq[guest_gsi]);
xen/arch/x86/hvm/irq.c int pt_irq_create_bind( · line 490
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+ girq->machine_gsi = pirq; +list_add_tail (&girq->list, &hvm_irq_dpci->girq[guest_gsi]); + } +else + { +/* MSI_TRANSLATE is not supported by the hardware domain. */ +ASSERT (pt_irq_bind->irq_type ==PT_IRQ_TYPE_PCI ); + guest_gsi = pirq; +ASSERT (guest_gsi <hvm_domain_irq (d)->nr_gsis); + }
This is dangerous: For one it is impossible to judge the correctness of at least the first of these assertions for the hwdom case without looking at patch 3. And then the domctl path leading here does not exclude the subject domain equaling the calling one, i.e. you potentially assert guest input correctness here. Yes, we have XSA-77 in place, but no, we shouldn't introduce new issues anywhere unless that's entirely unavoidable.
Quoted 5 lines
xen/arch/x86/hvm/irq.c +0
-1@@ -504,10 +567,18 @@ int pt_irq_create_bind(spin_unlock (&d->event_lock);if ( iommu_verbose ) - printk(XENLOG_G_INFO
xen/arch/x86/hvm/irq.c int pt_irq_create_bind( · line 576
Quoted 10 lines
xen/arch/x86/hvm/irq.c +7
-3-"d%d: bind: m_gsi=%u g_gsi=%u dev=%02x.%02x.%u intx=%u\n" , - d->domain_id, pirq, guest_gsi, bus, - PCI_SLOT(device), PCI_FUNC(device), intx); + { +char buf[50 ]; + +if ( !is_hardware_domain (d) ) +snprintf (buf,ARRAY_SIZE (buf)," dev=%02x.%02x.%u intx=%u" , + digl->bus,PCI_SLOT (digl->device), +PCI_FUNC (digl->device), digl->intx);
The buffer array seems heavily over-sized - my counting gives at best slightly over 20 characters you actually need.
Quoted 9 lines
xen/arch/x86/hvm/irq.c +0
-1@@ -522,7 +593,6 @@ int pt_irq_create_bind(int pt_irq_destroy_bind (struct domain *d,xen_domctl_bind_pt_irq_t *pt_irq_bind) { -struct hvm_irq_dpci *hvm_irq_dpci;struct hvm_pirq_dpci *pirq_dpci;unsigned int machine_gsi = pt_irq_bind->machine_irq;struct pirq *pirq;
xen/arch/x86/hvm/irq.c int pt_irq_destroy_bind( · line 627
Quoted 9 lines
xen/arch/x86/hvm/irq.c +3
-3@@ -552,17 +622,15 @@ int pt_irq_destroy_bind(spin_lock (&d->event_lock); - hvm_irq_dpci =domain_get_irq_dpci (d); - -if ( hvm_irq_dpci ==NULL ) + pirq =pirq_info (d, machine_gsi); + pirq_dpci =pirq_dpci (pirq); +if ( pirq_dpci->flags &HVM_IRQ_DPCI_IDENTITY_GSI )
I'm sure we've discussed aspects of this before: pirq_dpci may be NULL here, i.e. you can't blindly dereference it. All other uses in the function indeed have a NULL check first.
xen/arch/x86/hvm/irq.c int pt_irq_destroy_bind( · line 649
Quoted 13 lines
xen/arch/x86/hvm/irq.c +6
-0@@ -570,9 +638,16 @@ int pt_irq_destroy_bind(unsigned int intx = pt_irq_bind->u.pci.intx;unsigned int guest_gsi =hvm_pci_intx_gsi (device, intx);unsigned int link =hvm_pci_intx_link (device, intx); +struct hvm_irq_dpci *hvm_irq_dpci =domain_get_irq_dpci (d);struct hvm_girq_dpci_mapping *girq;struct dev_intx_gsi_link *digl, *tmp; +if ( hvm_irq_dpci ==NULL ) + { +spin_unlock (&d->event_lock); +return -EINVAL ; + }
Moving this check here is a behavioral modification. Perhaps a good one, yet it doesn't belong into this patch. Instead it should be properly reasoned about in a separate patch, if it is a correct thing to do.
xen/arch/x86/hvm/irq.c static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci) · line 899
Quoted 7 lines
xen/arch/x86/hvm/irq.c +1
-2@@ -814,17 +896,12 @@ static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci)spin_unlock (&d->event_lock); } -static void __hvm_dpci_eoi(struct domain *d, - const struct hvm_girq_dpci_mapping *girq, +static void __hvm_pirq_eoi(struct pirq *pirq,
Please drop the double leading underscores.
xen/arch/x86/hvm/irq.c static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci) · line 904
Quoted 11 lines
xen/arch/x86/hvm/irq.c +2
-6const union vioapic_redir_entry *ent) { -struct pirq *pirq =pirq_info (d, girq->machine_gsi); -struct hvm_pirq_dpci *pirq_dpci; - -if ( !hvm_domain_use_pirq (d, pirq) ) -hvm_pci_intx_deassert (d, girq->device, girq->intx); +struct hvm_pirq_dpci *pirq_dpci =pirq_dpci (pirq); - pirq_dpci =pirq_dpci (pirq); +ASSERT (pirq_dpci);
Why is this useful / needed all of the sudden?
Quoted 7 lines
xen/arch/x86/hvm/irq.c +3
-0@@ -839,6 +916,32 @@ static void __hvm_dpci_eoi(struct domain *d,pirq_guest_eoi (pirq); } +static void __hvm_dpci_eoi (struct domain *d, +const struct hvm_girq_dpci_mapping *girq, +const union vioapic_redir_entry *ent)
xen/arch/x86/hvm/irq.c static void __hvm_dpci_eoi(struct domain *d, · line 931
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+{ +struct pirq *pirq =pirq_info (d, girq->machine_gsi); + +if ( !hvm_domain_use_pirq (d, pirq) ) +hvm_pci_intx_deassert (d, girq->device, girq->intx); + +__hvm_pirq_eoi (pirq, ent); +} + +static void __hvm_gsi_eoi(struct domain *d, unsigned int gsi,
Same here for the double underscores. For the pre-existing function I'd leave it up to you whether to also drop them. What I care about is that we don't gain new non-conforming names.
xen/arch/x86/hvm/irq.c static void __hvm_dpci_eoi(struct domain *d, · line 938
Quoted 7 lines
xen/arch/x86/hvm/irq.c +7
-0+ const union vioapic_redir_entry *ent) +{ +struct pirq *pirq =pirq_info (d, gsi); +struct hvm_pirq_dpci *pirq_dpci =pirq_dpci (pirq); + +/* Check if GSI is actually mapped. */ +if ( !pirq_dpci )
Please avoid the local variable when used just once here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...
Yes, I modify pt_irq_destroy_bind to return EOPNOTSUPP when trying to unbind such an interrupt. I can implement the unbind, but it's not going to be used ATM.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/irq.c +0
-0@@ -126,6 +126,34 @@ void hvm_pci_intx_deassert(spin_unlock (&d->arch.hvm_domain.irq_lock); }
Quoted 8 lines
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 133
Quoted 5 lines
xen/arch/x86/hvm/irq.c +5
-0+void hvm_gsi_assert (struct domain *d,unsigned int gsi) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); + +ASSERT (gsi < hvm_irq->nr_gsis);This would probably better match the alternative construct in
__hvm_pci_intx_assert().
OK, changed.
Quoted 5 lines
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 134
Quoted 1 line
xen/arch/x86/hvm/irq.c +1
-0+ASSERT (!has_vpic (d));This doesn't look to be relevant for the rest of the function. Is there a particular reason you've added it? If so, a brief comment might help.
I've added this because hvm_gsi_assert doesn't call assert_irq, so a PIC would not work properly, but it's probably pointless.
Quoted 9 lines
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 138
Quoted 4 lines
xen/arch/x86/hvm/irq.c +4
-0+spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !hvm_irq->gsi_assert_count[gsi] ) + { + hvm_irq->gsi_assert_count[gsi]++;Why is this an increment instead of a simple write of 1? Or the other way around - why is this not always incrementing, just like
__hvm_pci_intx_assert()does? (Symmetric questions then forhvm_gsi_deassert()).
__hvm_pci_intx_{de}assert has an array that tracks the status of each interrupt line, and Xen does the routing based on that (the __test_and_clear_bit at the top of __hvm_pci_intx_assert). That prevents the same line from triggering multiple times, which is not available here, and thus Xen needs to rely on gsi_assert_count in order to know if the GSI is pending or not.
Switched to use a set to 1/0 instead of the increment, which I agree makes this clearer.
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/hvm/irq.c +1
-1@@ -274,10 +289,16 @@ int pt_irq_create_bind(spin_lock (&d->event_lock); hvm_irq_dpci =domain_get_irq_dpci (d); -if ( hvm_irq_dpci ==NULL ) +if ( hvm_irq_dpci ==NULL && !is_hardware_domain (d) ) {unsigned int i;
Quoted 7 lines
xen/arch/x86/hvm/irq.c int pt_irq_create_bind( · line 300
Quoted 5 lines
xen/arch/x86/hvm/irq.c +5
-0+/* +* NB: the hardware domain doesn't use a hvm_irq_dpci struct because +* it's only allowed to identity map GSIs, and so the data contained in +* that struct (used to map guest GSIs into machine GSIs and perform +* interrupt routing) it's completely useless for it. "...) is completely useless to it."
Fixed, thanks.
Quoted 74 lines
Quoted 63 lines
xen/arch/x86/hvm/irq.c +30
-24@@ -422,35 +443,51 @@ int pt_irq_create_bind(case PT_IRQ_TYPE_PCI :case PT_IRQ_TYPE_MSI_TRANSLATE : { -unsigned int bus = pt_irq_bind->u.pci.bus; -unsigned int device = pt_irq_bind->u.pci.device; -unsigned int intx = pt_irq_bind->u.pci.intx; -unsigned int guest_gsi =hvm_pci_intx_gsi (device, intx); -unsigned int link =hvm_pci_intx_link (device, intx); - struct dev_intx_gsi_link *digl = xmalloc(struct dev_intx_gsi_link); -struct hvm_girq_dpci_mapping *girq = - xmalloc(struct hvm_girq_dpci_mapping); +struct dev_intx_gsi_link *digl =NULL ; +struct hvm_girq_dpci_mapping *girq =NULL ; +unsigned int guest_gsi; -if ( !digl || !girq ) +/* +* Mapping GSIs for the hardware domain is different than doing it for +* an unpriviledged guest, the hardware domain is only allowed to +* identity map GSIs, and as such all the data in the u.pci union is +* discarded. +*/ +if ( !is_hardware_domain (d) ) { -spin_unlock (&d->event_lock); -xfree (girq); -xfree (digl); -return -ENOMEM ; - } +unsigned int link; + + digl = xmalloc(struct dev_intx_gsi_link); + girq = xmalloc(struct hvm_girq_dpci_mapping); + +if ( !digl || !girq ) + { +spin_unlock (&d->event_lock); +xfree (girq); +xfree (digl); +return -ENOMEM ; + } + + girq->bus = digl->bus = pt_irq_bind->u.pci.bus; + girq->device = digl->device = pt_irq_bind->u.pci.device; + girq->intx = digl->intx = pt_irq_bind->u.pci.intx; +list_add_tail (&digl->list, &pirq_dpci->digl_list); - hvm_irq_dpci->link_cnt[link]++; + guest_gsi =hvm_pci_intx_gsi (digl->device, digl->intx); + link =hvm_pci_intx_link (digl->device, digl->intx); - digl->bus = bus; - digl->device = device; - digl->intx = intx; -list_add_tail (&digl->list, &pirq_dpci->digl_list); + hvm_irq_dpci->link_cnt[link]++; - girq->bus = bus; - girq->device = device; - girq->intx = intx; - girq->machine_gsi = pirq; -list_add_tail (&girq->list, &hvm_irq_dpci->girq[guest_gsi]);xen/arch/x86/hvm/irq.c int pt_irq_create_bind( · line 490
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+ girq->machine_gsi = pirq; +list_add_tail (&girq->list, &hvm_irq_dpci->girq[guest_gsi]); + } +else + { +/* MSI_TRANSLATE is not supported by the hardware domain. */ +ASSERT (pt_irq_bind->irq_type ==PT_IRQ_TYPE_PCI ); + guest_gsi = pirq; +ASSERT (guest_gsi <hvm_domain_irq (d)->nr_gsis); + }
Quoted 7 lines
This is dangerous: For one it is impossible to judge the correctness of at least the first of these assertions for the hwdom case without looking at patch 3. And then the domctl path leading here does not exclude the subject domain equaling the calling one, i.e. you potentially assert guest input correctness here. Yes, we have XSA-77 in place, but no, we shouldn't introduce new issues anywhere unless that's entirely unavoidable.
OK, let me return error instead to be on the safe side then.
Quoted 18 lines
Quoted 5 lines
xen/arch/x86/hvm/irq.c +0
-1@@ -504,10 +567,18 @@ int pt_irq_create_bind(spin_unlock (&d->event_lock);if ( iommu_verbose ) - printk(XENLOG_G_INFOxen/arch/x86/hvm/irq.c int pt_irq_create_bind( · line 576
Quoted 10 lines
xen/arch/x86/hvm/irq.c +7
-3-"d%d: bind: m_gsi=%u g_gsi=%u dev=%02x.%02x.%u intx=%u\n" , - d->domain_id, pirq, guest_gsi, bus, - PCI_SLOT(device), PCI_FUNC(device), intx); + { +char buf[50 ]; + +if ( !is_hardware_domain (d) ) +snprintf (buf,ARRAY_SIZE (buf)," dev=%02x.%02x.%u intx=%u" , + digl->bus,PCI_SLOT (digl->device), +PCI_FUNC (digl->device), digl->intx);The buffer array seems heavily over-sized - my counting gives at best slightly over 20 characters you actually need.
AFAICT max length should be 21, would you be fine with me setting it to 24 to be safe?
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/hvm/irq.c +0
-1@@ -522,7 +593,6 @@ int pt_irq_create_bind(int pt_irq_destroy_bind (struct domain *d,xen_domctl_bind_pt_irq_t *pt_irq_bind) { -struct hvm_irq_dpci *hvm_irq_dpci;struct hvm_pirq_dpci *pirq_dpci;unsigned int machine_gsi = pt_irq_bind->machine_irq;struct pirq *pirq;@@ -552,17 +622,15 @@ int pt_irq_destroy_bind(spin_lock (&d->event_lock);
Quoted 10 lines
xen/arch/x86/hvm/irq.c int pt_irq_destroy_bind( · line 627
Quoted 6 lines
xen/arch/x86/hvm/irq.c +3
-3- hvm_irq_dpci =domain_get_irq_dpci (d); - -if ( hvm_irq_dpci ==NULL ) + pirq =pirq_info (d, machine_gsi); + pirq_dpci =pirq_dpci (pirq); +if ( pirq_dpci->flags &HVM_IRQ_DPCI_IDENTITY_GSI )I'm sure we've discussed aspects of this before:
pirq_dpcimay be NULL here, i.e. you can't blindly dereference it. All other uses in the function indeed have a NULL check first.
OK, I've removed this and fixed the function so it can unbind HVM_IRQ_DPCI_IDENTITY_GSI.
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/hvm/irq.c +1
-0@@ -570,9 +638,16 @@ int pt_irq_destroy_bind(unsigned int intx = pt_irq_bind->u.pci.intx;unsigned int guest_gsi =hvm_pci_intx_gsi (device, intx);unsigned int link =hvm_pci_intx_link (device, intx); +struct hvm_irq_dpci *hvm_irq_dpci =domain_get_irq_dpci (d);struct hvm_girq_dpci_mapping *girq;struct dev_intx_gsi_link *digl, *tmp;
Quoted 10 lines
xen/arch/x86/hvm/irq.c int pt_irq_destroy_bind( · line 649
Quoted 5 lines
xen/arch/x86/hvm/irq.c +5
-0+if ( hvm_irq_dpci ==NULL ) + { +spin_unlock (&d->event_lock); +return -EINVAL ; + }Moving this check here is a behavioral modification. Perhaps a good one, yet it doesn't belong into this patch. Instead it should be properly reasoned about in a separate patch, if it is a correct thing to do.
I've left it in it's previous place and added a !is_hardware_domain check.
Quoted 9 lines
xen/arch/x86/hvm/irq.c static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci) · line 899
Quoted 7 lines
xen/arch/x86/hvm/irq.c +1
-2@@ -814,17 +896,12 @@ static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci)spin_unlock (&d->event_lock); } -static void __hvm_dpci_eoi(struct domain *d, - const struct hvm_girq_dpci_mapping *girq, +static void __hvm_pirq_eoi(struct pirq *pirq,Please drop the double leading underscores.
Done.
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/hvm/irq.c +1
-5const union vioapic_redir_entry *ent) { -struct pirq *pirq =pirq_info (d, girq->machine_gsi); -struct hvm_pirq_dpci *pirq_dpci; - -if ( !hvm_domain_use_pirq (d, pirq) ) -hvm_pci_intx_deassert (d, girq->device, girq->intx); +struct hvm_pirq_dpci *pirq_dpci =pirq_dpci (pirq);
Quoted 4 lines
xen/arch/x86/hvm/irq.c static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci) · line 904
Quoted 2 lines
xen/arch/x86/hvm/irq.c +1
-1- pirq_dpci =pirq_dpci (pirq); +ASSERT (pirq_dpci);Why is this useful / needed all of the sudden?
Hm, I don't think it's needed, probably just a leftover from when I was testing the patches.
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/hvm/irq.c +9
-0@@ -839,6 +916,32 @@ static void __hvm_dpci_eoi(struct domain *d,pirq_guest_eoi (pirq); } +static void __hvm_dpci_eoi (struct domain *d, +const struct hvm_girq_dpci_mapping *girq, +const union vioapic_redir_entry *ent) +{ +struct pirq *pirq =pirq_info (d, girq->machine_gsi); + +if ( !hvm_domain_use_pirq (d, pirq) ) +hvm_pci_intx_deassert (d, girq->device, girq->intx); +
Quoted 8 lines
xen/arch/x86/hvm/irq.c static void __hvm_dpci_eoi(struct domain *d, · line 931
Quoted 4 lines
xen/arch/x86/hvm/irq.c +4
-0+__hvm_pirq_eoi (pirq, ent); +} + +static void __hvm_gsi_eoi(struct domain *d, unsigned int gsi,Same here for the double underscores. For the pre-existing function I'd leave it up to you whether to also drop them. What I care about is that we don't gain new non-conforming names.
I will leave the others as they are, or else they should be changed in a separate patch.
Quoted 9 lines
xen/arch/x86/hvm/irq.c static void __hvm_dpci_eoi(struct domain *d, · line 938
Quoted 7 lines
xen/arch/x86/hvm/irq.c +7
-0+ const union vioapic_redir_entry *ent) +{ +struct pirq *pirq =pirq_info (d, gsi); +struct hvm_pirq_dpci *pirq_dpci =pirq_dpci (pirq); + +/* Check if GSI is actually mapped. */ +if ( !pirq_dpci )Please avoid the local variable when used just once here.
Done.
Thanks for the review, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 17:55, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Note that currently there's no support for unbinding this interrupts.
Quoted 8 lines
Quoted 4 lines
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...Yes, I modify
pt_irq_destroy_bindto return EOPNOTSUPP when trying to unbind such an interrupt. I can implement the unbind, but it's not going to be used ATM.
Is it not? I can see the mentioned pass-through case to be of no interest, but wouldn't a well behaved kernel perhaps unmap IRQs while shutting down?
Quoted 10 lines
Quoted 9 lines
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 138
Quoted 4 lines
xen/arch/x86/hvm/irq.c +4
-0+spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !hvm_irq->gsi_assert_count[gsi] ) + { + hvm_irq->gsi_assert_count[gsi]++;Why is this an increment instead of a simple write of 1? Or the other way around - why is this not always incrementing, just like
__hvm_pci_intx_assert()does? (Symmetric questions then forhvm_gsi_deassert()).
Quoted 8 lines
__hvm_pci_intx_{de}assert has an array that tracks the status of each interrupt line, and Xen does the routing based on that (the
__test_and_clear_bitat the top of__hvm_pci_intx_assert). That prevents the same line from triggering multiple times, which is not available here, and thus Xen needs to rely ongsi_assert_countin order to know if the GSI is pending or not.Switched to use a set to 1/0 instead of the increment, which I agree makes this clearer.
And altogether this likely would benefit from a comment put somewhere.
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
xen/drivers/passthrough/io.c +0
-1@@ -504,10 +567,18 @@ int pt_irq_create_bind(spin_unlock (&d->event_lock);if ( iommu_verbose ) - printk(XENLOG_G_INFOxen/drivers/passthrough/io.c int pt_irq_create_bind( · line 576
Quoted 10 lines
xen/drivers/passthrough/io.c +7
-3-"d%d: bind: m_gsi=%u g_gsi=%u dev=%02x.%02x.%u intx=%u\n" , - d->domain_id, pirq, guest_gsi, bus, - PCI_SLOT(device), PCI_FUNC(device), intx); + { +char buf[50 ]; + +if ( !is_hardware_domain (d) ) +snprintf (buf,ARRAY_SIZE (buf)," dev=%02x.%02x.%u intx=%u" , + digl->bus,PCI_SLOT (digl->device), +PCI_FUNC (digl->device), digl->intx);The buffer array seems heavily over-sized - my counting gives at best slightly over 20 characters you actually need.
Quoted 2 lines
AFAICT max length should be 21, would you be fine with me setting it to 24 to be safe?
Sure.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 17:55, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...
Quoted 7 lines
Quoted 3 lines
Yes, I modify
pt_irq_destroy_bindto return EOPNOTSUPP when trying to unbind such an interrupt. I can implement the unbind, but it's not going to be used ATM.Is it not? I can see the mentioned pass-through case to be of no interest, but wouldn't a well behaved kernel perhaps unmap IRQs while shutting down?
I guess I haven't explained myself correctly, what I meant is that right now I don't have any use-case for this, I haven't started working on pci-passtrhough for guests, and the Dom0 implementation I have doesn't unbind interrupts on shutdown.
I could unbind them when Dom0 masks the vIO APIC pin, but I think that's going to be awfully slow.
Quoted 16 lines
Quoted 16 lines
Quoted 9 lines
xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 138
Quoted 4 lines
xen/arch/x86/hvm/irq.c +4
-0+spin_lock (&d->arch.hvm_domain.irq_lock); +if ( !hvm_irq->gsi_assert_count[gsi] ) + { + hvm_irq->gsi_assert_count[gsi]++;Why is this an increment instead of a simple write of 1? Or the other way around - why is this not always incrementing, just like
__hvm_pci_intx_assert()does? (Symmetric questions then forhvm_gsi_deassert()).__hvm_pci_intx_{de}assert has an array that tracks the status of each interrupt line, and Xen does the routing based on that (the
__test_and_clear_bitat the top of__hvm_pci_intx_assert). That prevents the same line from triggering multiple times, which is not available here, and thus Xen needs to rely ongsi_assert_countin order to know if the GSI is pending or not.
Quoted 5 lines
Quoted 2 lines
Switched to use a set to 1/0 instead of the increment, which I agree makes this clearer.
And altogether this likely would benefit from a comment put somewhere.
Done.
Thanks.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 10:26, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 17:55, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...Quoted 7 lines
Quoted 3 lines
Yes, I modify
pt_irq_destroy_bindto return EOPNOTSUPP when trying to unbind such an interrupt. I can implement the unbind, but it's not going to be used ATM.Is it not? I can see the mentioned pass-through case to be of no interest, but wouldn't a well behaved kernel perhaps unmap IRQs while shutting down?
Quoted 7 lines
I guess I haven't explained myself correctly, what I meant is that right now I don't have any use-case for this, I haven't started working on pci-passtrhough for guests, and the Dom0 implementation I have doesn't unbind interrupts on shutdown.
I could unbind them when Dom0 masks the vIO APIC pin, but I think that's going to be awfully slow.
Well, doesn't this point out another weakness of the no-physdevops model you advocate for? Implying an unbind from the mask bit being set in an RTE would certainly be undesirable (there are reasons to transiently mask an interrupt, after all). Hence there's no way Dom0 could indicate "I'm done with this interrupt", unless I'm missing something.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 28 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 10:26, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 17:55, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...Quoted 7 lines
Quoted 3 lines
Yes, I modify
pt_irq_destroy_bindto return EOPNOTSUPP when trying to unbind such an interrupt. I can implement the unbind, but it's not going to be used ATM.Is it not? I can see the mentioned pass-through case to be of no interest, but wouldn't a well behaved kernel perhaps unmap IRQs while shutting down?
Quoted 7 lines
I guess I haven't explained myself correctly, what I meant is that right now I don't have any use-case for this, I haven't started working on pci-passtrhough for guests, and the Dom0 implementation I have doesn't unbind interrupts on shutdown.
I could unbind them when Dom0 masks the vIO APIC pin, but I think that's going to be awfully slow.
Quoted 6 lines
Well, doesn't this point out another weakness of the no-physdevops model you advocate for? Implying an unbind from the mask bit being set in an RTE would certainly be undesirable (there are reasons to transiently mask an interrupt, after all). Hence there's no way Dom0 could indicate "I'm done with this interrupt", unless I'm missing something.
The only reason I could see for the hardware domain to unbind an interrupt is when doing pci-passthrough, and there the toolstack is involved, which could unbind the interrupt using the already existing hypercalls.
Just to be clear, my no-physdevops thing is about how guests interact with physical devices when using them in a native way. Things like pci-passthrough (that are not part of how an OS operates) should indeed use hypercalls (because there's no native way to do this).
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 11:34, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 10:26, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 17:55, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...Yes, I modify
pt_irq_destroy_bindto return EOPNOTSUPP when trying tounbind
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
such an interrupt. I can implement the unbind, but it's not going to be
used
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
ATM.
Is it not? I can see the mentioned pass-through case to be of no interest, but wouldn't a well behaved kernel perhaps unmap IRQs while shutting down?
I guess I haven't explained myself correctly, what I meant is that right
now I
Quoted 1 line
Quoted 1 line
don't have any use-case for this, I haven't started working on
pci-passtrhough
Quoted 6 lines
Quoted 5 lines
for guests, and the Dom0 implementation I have doesn't unbind interrupts on shutdown.
I could unbind them when Dom0 masks the vIO APIC pin, but I think that's going to be awfully slow.
Quoted 6 lines
Well, doesn't this point out another weakness of the no-physdevops model you advocate for? Implying an unbind from the mask bit being set in an RTE would certainly be undesirable (there are reasons to transiently mask an interrupt, after all). Hence there's no way Dom0 could indicate "I'm done with this interrupt", unless I'm missing something.
Quoted 3 lines
The only reason I could see for the hardware domain to unbind an interrupt is when doing pci-passthrough, and there the toolstack is involved, which could unbind the interrupt using the already existing hypercalls.
I'm not convinced the tool stack doing this behind the back of the kernel is an acceptable thing to do, even more so when thinking of shared interrupts.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/3] x86/pt: enable binding of GSIs to a PVH Dom0
Quoted 41 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 11:34, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 10:26, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 16.05.17 at 17:55, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Note that currently there's no support for unbinding this interrupts.
Do you plan to deal with that before this changes goes in? Aiui this not working means you can't pass through devices with pin based interrupts once Dom0 chose to bind to them. Otoh hand you modify
pt_irq_destroy_bind(), so I'm a little puzzled ...Yes, I modify
pt_irq_destroy_bindto return EOPNOTSUPP when trying tounbind
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
such an interrupt. I can implement the unbind, but it's not going to be
used
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
ATM.
Is it not? I can see the mentioned pass-through case to be of no interest, but wouldn't a well behaved kernel perhaps unmap IRQs while shutting down?
I guess I haven't explained myself correctly, what I meant is that right
now I
Quoted 1 line
Quoted 1 line
don't have any use-case for this, I haven't started working on
pci-passtrhough
Quoted 12 lines
Quoted 5 lines
for guests, and the Dom0 implementation I have doesn't unbind interrupts on shutdown.
I could unbind them when Dom0 masks the vIO APIC pin, but I think that's going to be awfully slow.
Well, doesn't this point out another weakness of the no-physdevops model you advocate for? Implying an unbind from the mask bit being set in an RTE would certainly be undesirable (there are reasons to transiently mask an interrupt, after all). Hence there's no way Dom0 could indicate "I'm done with this interrupt", unless I'm missing something.
Quoted 7 lines
Quoted 3 lines
The only reason I could see for the hardware domain to unbind an interrupt is when doing pci-passthrough, and there the toolstack is involved, which could unbind the interrupt using the already existing hypercalls.
I'm not convinced the tool stack doing this behind the back of the kernel is an acceptable thing to do, even more so when thinking of shared interrupts.
The toolstack could figure out whether the interrupt is shared or not (edge or level triggered) and then decide whether it needs unbinding or not. The kernel must obviously not be using the device by that point. I'm again not opposed to have an in-kernel (for Dom0) driver for managing passthrough, but I would like to avoid it if possible.
In any case, I think the interface for how Dom0 interacts with interrupts from it's assigned devices vs the interface used to detach devices for pci-passthrough is orthogonal (one can be completely separated from the other).
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 3/3 x86/vioapic: bind interrupts to PVH Dom0
In reply to Roger Pau MonneAdd the glue in order to bind the PVH Dom0 GSI from bare metal. This is done when Dom0 unmasks the vIO APIC pins, by fetching the current pin settings and setting up the PIRQ, which will then be bound to Dom0.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v1:
- Mask the pin on error (instead of panicking).
- Factor out the Dom0 specific code into a function.
- Use the newly introduced allocate_and_map_gsi_pirq instead of physdev_map_pirq.
--- xen/arch/x86/hvm/vioapic.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
xen/arch/x86/hvm/vioapic.c +70 -0
@@ -158,6 +158,62 @@ static int vioapic_read(return X86EMUL_OKAY ; } +static int vioapic_dom0_map_gsi (unsigned int gsi,unsigned int trig, +unsigned int pol) +{ +struct domain *d = current->domain; +xen_domctl_bind_pt_irq_t pt_irq_bind = { + .irq_type =PT_IRQ_TYPE_PCI , + .machine_irq = gsi, + .hvm_domid =DOMID_SELF , + }; +int ret, pirq = gsi; + +ASSERT (is_hardware_domain (d)); + +/* Interrupt has been unmasked, bind it now. */ + ret =mp_register_gsi (gsi, trig, pol); +if ( ret && ret != -EEXIST ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error registering GSI %u: %d\n" , + gsi, ret); + goto error; + } +else if ( ret ) +/* Already in use. */ +return 0 ; + + ret =allocate_and_map_gsi_pirq (d, &pirq, &pirq); +if ( ret ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error mapping GSI %u: %d\n" , + gsi, ret); + goto error; + } + +pcidevs_lock (); + ret =pt_irq_create_bind (d, &pt_irq_bind); +pcidevs_unlock (); +if ( ret ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error binding GSI %u: %d\n" , + gsi, ret); + goto error_unmap; + } + +return 0 ; + + error_unmap: +pcidevs_lock (); +spin_lock (&d->event_lock); +unmap_domain_pirq (d, pirq); +spin_unlock (&d->event_lock); +pcidevs_unlock (); + error: +ASSERT (ret); +return ret; +} +static void vioapic_write_redirent (struct hvm_vioapic *vioapic,unsigned int idx,int top_word,uint32_t val)
@@ -188,6 +244,20 @@ static void vioapic_write_redirent( unmasked = unmasked && !ent.fields.mask; } +if (is_hardware_domain (d) && unmasked ) + { +int ret; + + ret =vioapic_dom0_map_gsi (gsi, ent.fields.trig_mode, + ent.fields.polarity); +if ( ret ) + { +/* Mask the entry again. */ + ent.fields.mask =1 ; + unmasked =0 ; + } + } + *pent = ent;if ( gsi ==0 )
Signature · 7 lines
2.11.0 (Apple Git-81) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 3/3] x86/vioapic: bind interrupts to PVH Dom0
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 161
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/vioapic.c +1
-0@@ -158,6 +158,62 @@ static int vioapic_read(return X86EMUL_OKAY ; } +static int vioapic_dom0_map_gsi(unsigned int gsi, unsigned int trig,
Considering the conditional in the caller, please use hwdom instead of dom0.
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 168
Quoted 7 lines
xen/arch/x86/hvm/vioapic.c +7
-0+ unsigned int pol) +{ +struct domain *d = current->domain; +xen_domctl_bind_pt_irq_t pt_irq_bind = { + .irq_type =PT_IRQ_TYPE_PCI , + .machine_irq = gsi, + .hvm_domid =DOMID_SELF ,
I'm struggling with this field: Did you not notice it's entirely unused? We should really delete it from the interface, as redundant with the domain specifier in the domctl container structure.
Quoted 6 lines
xen/arch/x86/hvm/vioapic.c +6
-0+ }; +int ret, pirq = gsi; + +ASSERT (is_hardware_domain (d)); + +/* Interrupt has been unmasked, bind it now. */
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 184
Quoted 10 lines
xen/arch/x86/hvm/vioapic.c +10
-0+ ret =mp_register_gsi (gsi, trig, pol); +if ( ret && ret != -EEXIST ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error registering GSI %u: %d\n" , + gsi, ret); + goto error; + } +else if ( ret ) +/* Already in use. */ +return 0 ;
I think this would better be
if ( ret == -EEXIST )
return 0;
if ( ret )
....Quoted 11 lines
xen/arch/x86/hvm/vioapic.c +11
-0+ ret =allocate_and_map_gsi_pirq (d, &pirq, &pirq); +if ( ret ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error mapping GSI %u: %d\n" , + gsi, ret); + goto error; + } + +pcidevs_lock (); + ret =pt_irq_create_bind (d, &pt_irq_bind); +pcidevs_unlock ();
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 206
Quoted 10 lines
xen/arch/x86/hvm/vioapic.c +10
-0+if ( ret ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error binding GSI %u: %d\n" , + gsi, ret); + goto error_unmap; + } + +return 0 ; + + error_unmap:
I can live with the "error" label below, but the one above clearly can be avoided quite easily by simply inverting the preceding if().
Also, considering this is Dom0-only, I wonder whether all of the log messages wouldn't better use gprintk().
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 3/3] x86/vioapic: bind interrupts to PVH Dom0
Quoted 11 lines · Jan Beulich
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 161
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:11, <[email protected]> wrote:
xen/arch/x86/hvm/vioapic.c +1
-0@@ -158,6 +158,62 @@ static int vioapic_read(return X86EMUL_OKAY ; } +static int vioapic_dom0_map_gsi(unsigned int gsi, unsigned int trig,Considering the conditional in the caller, please use hwdom instead of dom0.
Done.
Quoted 8 lines
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 168
Quoted 7 lines
xen/arch/x86/hvm/vioapic.c +7
-0+ unsigned int pol) +{ +struct domain *d = current->domain; +xen_domctl_bind_pt_irq_t pt_irq_bind = { + .irq_type =PT_IRQ_TYPE_PCI , + .machine_irq = gsi, + .hvm_domid =DOMID_SELF ,
Quoted 4 lines
I'm struggling with this field: Did you not notice it's entirely unused? We should really delete it from the interface, as redundant with the domain specifier in the domctl container structure.
Right, I've removed it.
Quoted 19 lines
Quoted 6 lines
xen/arch/x86/hvm/vioapic.c +6
-0+ }; +int ret, pirq = gsi; + +ASSERT (is_hardware_domain (d)); + +/* Interrupt has been unmasked, bind it now. */ xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 184
Quoted 10 lines
xen/arch/x86/hvm/vioapic.c +10
-0+ ret =mp_register_gsi (gsi, trig, pol); +if ( ret && ret != -EEXIST ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error registering GSI %u: %d\n" , + gsi, ret); + goto error; + } +else if ( ret ) +/* Already in use. */ +return 0 ;I think this would better be
Quoted 4 lines
if ( ret == -EEXIST )
return 0;
if ( ret )
....Done.
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/hvm/vioapic.c +16
-0+ ret =allocate_and_map_gsi_pirq (d, &pirq, &pirq); +if ( ret ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error mapping GSI %u: %d\n" , + gsi, ret); + goto error; + } + +pcidevs_lock (); + ret =pt_irq_create_bind (d, &pt_irq_bind); +pcidevs_unlock (); +if ( ret ) + { +gdprintk (XENLOG_WARNING ,"vioapic: error binding GSI %u: %d\n" , + gsi, ret); + goto error_unmap;
Quoted 8 lines
xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 206
Quoted 5 lines
xen/arch/x86/hvm/vioapic.c +5
-0+ } + +return 0 ; + + error_unmap:I can live with the "error" label below, but the one above clearly can be avoided quite easily by simply inverting the preceding
if().
I've changed this to:
pcidevs_lock();
ret = pt_irq_create_bind(d, &pt_irq_bind);
if ( ret )
{
gprintk(XENLOG_WARNING, "vioapic: error binding GSI %u: %d\n",
gsi, ret);
spin_lock(&d->event_lock);
unmap_domain_pirq(d, pirq);
spin_unlock(&d->event_lock);
}
pcidevs_unlock();
return ret;And got rid of both labels.
Quoted 2 lines
Also, considering this is Dom0-only, I wonder whether all of the log messages wouldn't better use
gprintk().
Done.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel