Skip to contentSkip to conversation

x86/dpci: bind legacy PCI interrupts to PVHv2 Dom0

PATCH Superseded Roger Pau Monne 2 participants 12 messages May 17, 2017 – Jun 1, 2017

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 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.

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_v3

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

PATCH v3 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.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v2:
- Factor out the code to allocate the pirq.
- Fix coding style issues.
- Do not take the pci lock to bind a GSI.
- Pass a type parameter to the MSI bind function.

Changes since v1:
- New in this version.

---
 xen/arch/x86/irq.c        | 159 ++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/physdev.c    | 124 ++----------------------------------
 xen/include/asm-x86/irq.h |   5 ++
 3 files changed, 169 insertions(+), 119 deletions(-)
xen/arch/x86/irq.c +159 -0
index 676ba5216f..4590e85303 100644
@@ -2537,3 +2537,162 @@ 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; 
 }
+
+static int allocate_pirq(struct domain *d, int pirq, int irq, int type,
+                         int *nr)
+{
+    int current_pirq;
+
+    ASSERT(spin_is_locked(&d->event_lock));
+    current_pirq = domain_irq_to_pirq(d, irq);
+    if ( pirq < 0 )
+    {
+        if ( current_pirq )
+        {
+            dprintk(XENLOG_G_ERR, "dom%d: %d:%d already mapped to %d\n",
+                    d->domain_id, irq, pirq, current_pirq);
+            if ( current_pirq < 0 )
+                return -EBUSY;
+        }
+        else if ( type == MAP_PIRQ_TYPE_MULTI_MSI )
+        {
+            if ( *nr <= 0 || *nr > 32 )
+                return -EDOM;
+            else if ( *nr != 1 && !iommu_intremap )
+                return -EOPNOTSUPP;
+            else
+            {
+                while ( *nr & (*nr - 1) )
+                    *nr += *nr & -*nr;
+                pirq = get_free_pirqs(d, *nr);
+                if ( pirq < 0 )
+                {
+                    while ( (*nr >>= 1) > 1 )
+                        if ( get_free_pirqs(d, *nr) > 0 )
+                            break;
+                    dprintk(XENLOG_G_ERR, "dom%d: no block of %d free pirqs\n",
+                            d->domain_id, *nr << 1);
+                }
+            }
+        }
+        else
+        {
+            pirq = get_free_pirq(d, type);
+            if ( pirq < 0 )
+                dprintk(XENLOG_G_ERR, "dom%d: no free pirq\n", d->domain_id);
+        }
+    }
+    else if ( current_pirq && pirq != current_pirq )
+    {
+        dprintk(XENLOG_G_ERR, "dom%d: irq %d already mapped to pirq %d\n",
+                d->domain_id, irq, current_pirq);
+        pirq = -EEXIST;
+    }
+
+    return pirq;
+}
+
+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;
+        }
+    }
+
+    /* Verify or get pirq. */
+    spin_lock(&d->event_lock);
+    pirq = allocate_pirq(d, *pirq_p, irq, MAP_PIRQ_TYPE_GSI, 0);
+    if ( pirq < 0 )
+    {
+        ret = pirq;
+        goto done;
+    }
+
+    ret = map_domain_pirq(d, pirq, irq, MAP_PIRQ_TYPE_GSI, NULL);
+    if ( ret == 0 )
+        *pirq_p = pirq;
+
+ done:
+    spin_unlock(&d->event_lock);
+    return ret;
+}
+
+int allocate_and_map_msi_pirq(struct domain *d, int *index, int *pirq_p,
+                              int type, struct msi_info *msi)
+{
+    int irq, pirq, ret;
+
+    switch ( type )
+    {
+    case MAP_PIRQ_TYPE_MSI:
+        if ( !msi->table_base )
+            msi->entry_nr = 1;
+        irq = *index;
+        if ( irq == -1 )
+    case MAP_PIRQ_TYPE_MULTI_MSI:
+            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);
+            return -EINVAL;
+        }
+
+        msi->irq = irq;
+        break;
+
+    default:
+        dprintk(XENLOG_G_ERR, "dom%d: wrong pirq type %x\n",
+                d->domain_id, type);
+        return -EINVAL;
+    }
+
+    msi->irq = irq;
+
+    pcidevs_lock();
+    /* Verify or get pirq. */
+    spin_lock(&d->event_lock);
+    pirq = allocate_pirq(d, *pirq_p, irq, type, &msi->entry_nr);
+    if ( pirq < 0 )
+    {
+        ret = pirq;
+        goto done;
+    }
+
+    ret = map_domain_pirq(d, pirq, irq, type, msi);
+    if ( ret == 0 )
+        *pirq_p = pirq;
+
+ done:
+    spin_unlock(&d->event_lock);
+    pcidevs_unlock();
+    if ( ret != 0 )
+        switch ( type )
+        {
+        case MAP_PIRQ_TYPE_MSI:
+            if ( *index == -1 )
+        case MAP_PIRQ_TYPE_MULTI_MSI:
+                destroy_irq(irq);
+            break;
+        }
+    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
index ef625ebb13..d8d965b642 100644
@@ -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,
+                              int type, 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
#2 lore raw

Re: [PATCH v3 for-next 1/3] x86/physdev: factor out the code to allocate and map a pirq

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:
xen/arch/x86/irq.c +4 -0
@@ -2537,3 +2537,162 @@ 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; 
 }
+
+static int allocate_pirq(struct domain *d, int pirq, int irq, int type,
+                         int *nr)
+{

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2553

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+    int current_pirq;
+
+    ASSERT(spin_is_locked(&d->event_lock));
+    current_pirq = domain_irq_to_pirq(d, irq);
+    if ( pirq < 0 )
+    {
+        if ( current_pirq )
+        {
+            dprintk(XENLOG_G_ERR, "dom%d: %d:%d already mapped to %d\n",
+                    d->domain_id, irq, pirq, current_pirq);

Instead of "irq" the old code did pass "*index", i.e. a Dom0 kernel specified value (which is going to be more useful, as any problem here will need to be diagnosed in the Dom0 kernel). The two values are identical only if, in the GSI case, domain_pirq_to_irq(current->domain, *index) in allocate_and_map_gsi_pirq() returned a negative value.

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2563

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+            if ( current_pirq < 0 )
+                return -EBUSY;
+        }
+        else if ( type == MAP_PIRQ_TYPE_MULTI_MSI )
+        {
+            if ( *nr <= 0 || *nr > 32 )
+                return -EDOM;
+            else if ( *nr != 1 && !iommu_intremap )
+                return -EOPNOTSUPP;
+            else

Pointless "else" (twice).

Quoted 16 lines
xen/arch/x86/irq.c +16 -0
+            {
+                while ( *nr & (*nr - 1) )
+                    *nr += *nr & -*nr;
+                pirq = get_free_pirqs(d, *nr);
+                if ( pirq < 0 )
+                {
+                    while ( (*nr >>= 1) > 1 )
+                        if ( get_free_pirqs(d, *nr) > 0 )
+                            break;
+                    dprintk(XENLOG_G_ERR, "dom%d: no block of %d free pirqs\n",
+                            d->domain_id, *nr << 1);
+                }
+            }
+        }
+        else
+        {

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2589

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+            pirq = get_free_pirq(d, type);
+            if ( pirq < 0 )
+                dprintk(XENLOG_G_ERR, "dom%d: no free pirq\n", d->domain_id);
+        }
+    }
+    else if ( current_pirq && pirq != current_pirq )
+    {
+        dprintk(XENLOG_G_ERR, "dom%d: irq %d already mapped to pirq %d\n",
+                d->domain_id, irq, current_pirq);
+        pirq = -EEXIST;

"return -EEXIST" please, to match the direct returns you use further up.

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2595

Quoted 6 lines
xen/arch/x86/irq.c +6 -0
+    }
+
+    return pirq;
+}
+
+int allocate_and_map_gsi_pirq(struct domain *d, int *index, int *pirq_p)

Neither here nor in the MSI sibling you ever write to *index, so there's no need for the parameter to have pointer type.

Quoted 16 lines
xen/arch/x86/irq.c +16 -0
+{
+    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

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2621

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+        {
+            dprintk(XENLOG_G_ERR, "dom%d: map pirq with incorrect irq!\n",
+                    d->domain_id);
+            return -EINVAL;
+        }
+    }
+
+    /* Verify or get pirq. */
+    spin_lock(&d->event_lock);
+    pirq = allocate_pirq(d, *pirq_p, irq, MAP_PIRQ_TYPE_GSI, 0);

The last parameter of allocate_pirq() is a pointer, so you really mean NULL here.

Quoted 4 lines
xen/arch/x86/irq.c +4 -0
+    if ( pirq < 0 )
+    {
+        ret = pirq;
+        goto done;

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2635

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+    }
+
+    ret = map_domain_pirq(d, pirq, irq, MAP_PIRQ_TYPE_GSI, NULL);
+    if ( ret == 0 )
+        *pirq_p = pirq;
+
+ done:
+    spin_unlock(&d->event_lock);
+    return ret;
+}

Blank line before final return statement please.

Quoted 19 lines
xen/arch/x86/irq.c +19 -0
+int allocate_and_map_msi_pirq(struct domain *d, int *index, int *pirq_p,
+                              int type, struct msi_info *msi)
+{
+    int irq, pirq, ret;
+
+    switch ( type )
+    {
+    case MAP_PIRQ_TYPE_MSI:
+        if ( !msi->table_base )
+            msi->entry_nr = 1;
+        irq = *index;
+        if ( irq == -1 )
+    case MAP_PIRQ_TYPE_MULTI_MSI:
+            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);

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2665

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+            return -EINVAL;
+        }
+
+        msi->irq = irq;
+        break;
+
+    default:
+        dprintk(XENLOG_G_ERR, "dom%d: wrong pirq type %x\n",
+                d->domain_id, type);
+        return -EINVAL;

This really should be an ASSERT_UNREACHABLE() (with the return statement kept).

Quoted 23 lines
xen/arch/x86/irq.c +23 -0
+    }
+
+    msi->irq = irq;
+
+    pcidevs_lock();
+    /* Verify or get pirq. */
+    spin_lock(&d->event_lock);
+    pirq = allocate_pirq(d, *pirq_p, irq, type, &msi->entry_nr);
+    if ( pirq < 0 )
+    {
+        ret = pirq;
+        goto done;
+    }
+
+    ret = map_domain_pirq(d, pirq, irq, type, msi);
+    if ( ret == 0 )
+        *pirq_p = pirq;
+
+ done:
+    spin_unlock(&d->event_lock);
+    pcidevs_unlock();
+    if ( ret != 0 )
+        switch ( type )

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2698

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+        {
+        case MAP_PIRQ_TYPE_MSI:
+            if ( *index == -1 )
+        case MAP_PIRQ_TYPE_MULTI_MSI:
+                destroy_irq(irq);
+            break;
+        }
+    return ret;
+}
+

Please don't end a file with a blank line.

Quoted 34 lines
xen/arch/x86/physdev.c +1 -2
index eec4a41231..e99fd9a35f 100644
@@ -92,8 +92,7 @@ int physdev_map_pirq(domid_t domid, int type, int *index, 
 int *pirq_p,
                      struct msi_info *msi)
 {
     struct domain *d = current->domain;
-    int pirq, irq, ret = 0;
-    void *map_data = NULL;
+    int ret;
 
     if ( domid == DOMID_SELF && is_hvm_domain(d) && has_pirq(d) )
     {
xen/arch/x86/physdev.c +0 -14
@@ -119,135 +118,22 @@ int physdev_map_pirq(domid_t domid, int type, int 
 *index, int *pirq_p,
     switch ( type )
     {
     case MAP_PIRQ_TYPE_GSI:
-        if ( *index < 0 || *index >= nr_irqs_gsi )
-        {
-            dprintk(XENLOG_G_ERR, "dom%d: map invalid irq %d\n",
-                    d->domain_id, *index);
-            ret = -EINVAL;
-            goto free_domain;
-        }
-
-        irq = domain_pirq_to_irq(current->domain, *index);
-        if ( irq <= 0 )
-        {
-            if ( is_hardware_domain(current->domain) )
-                irq = *index;
-            else {

xen/arch/x86/physdev.c int physdev_map_pirq(domid_t domid, int type, int · line 124

Quoted 10 lines
xen/arch/x86/physdev.c +1 -7
-                dprintk(XENLOG_G_ERR, "dom%d: map pirq with incorrect irq!\n",
-                        d->domain_id);
-                ret = -EINVAL;
-                goto free_domain;
-            }
-        }
+        ret = allocate_and_map_gsi_pirq(d, index, pirq_p);
         break;
-
     case MAP_PIRQ_TYPE_MSI:

Please don't delete the blank lines between case blocks, even if the blocks are much smaller now.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v3 for-next 1/3] x86/physdev: factor out the code to allocate and map a pirq

Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:
xen/arch/x86/irq.c +13 -0
@@ -2537,3 +2537,162 @@ 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; 
 }
+
+static int allocate_pirq(struct domain *d, int pirq, int irq, int type,
+                         int *nr)
+{
+    int current_pirq;
+
+    ASSERT(spin_is_locked(&d->event_lock));
+    current_pirq = domain_irq_to_pirq(d, irq);
+    if ( pirq < 0 )
+    {
+        if ( current_pirq )
+        {
+            dprintk(XENLOG_G_ERR, "dom%d: %d:%d already mapped to %d\n",
Quoted 8 lines

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2553

Quoted 1 line
xen/arch/x86/irq.c +1 -0
+                    d->domain_id, irq, pirq, current_pirq);

Instead of "irq" the old code did pass "*index", i.e. a Dom0 kernel specified value (which is going to be more useful, as any problem here will need to be diagnosed in the Dom0 kernel). The two values are identical only if, in the GSI case, domain_pirq_to_irq(current->domain, *index) in allocate_and_map_gsi_pirq() returned a negative value.

I guess I can propagate index into this function, I haven't done that because it's only used by the error message, but not the code itself.

When I used the physdev hypoercalls in the past I think I was always setting index == GSI IIRC.

Quoted 11 lines

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2563

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+            if ( current_pirq < 0 )
+                return -EBUSY;
+        }
+        else if ( type == MAP_PIRQ_TYPE_MULTI_MSI )
+        {
+            if ( *nr <= 0 || *nr > 32 )
+                return -EDOM;
+            else if ( *nr != 1 && !iommu_intremap )
+                return -EOPNOTSUPP;
+            else
Quoted 1 line

Pointless "else" (twice).

Done (and re-indented the section below).

Quoted 27 lines
Quoted 16 lines
xen/arch/x86/irq.c +16 -0
+            {
+                while ( *nr & (*nr - 1) )
+                    *nr += *nr & -*nr;
+                pirq = get_free_pirqs(d, *nr);
+                if ( pirq < 0 )
+                {
+                    while ( (*nr >>= 1) > 1 )
+                        if ( get_free_pirqs(d, *nr) > 0 )
+                            break;
+                    dprintk(XENLOG_G_ERR, "dom%d: no block of %d free pirqs\n",
+                            d->domain_id, *nr << 1);
+                }
+            }
+        }
+        else
+        {

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2589

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+            pirq = get_free_pirq(d, type);
+            if ( pirq < 0 )
+                dprintk(XENLOG_G_ERR, "dom%d: no free pirq\n", d->domain_id);
+        }
+    }
+    else if ( current_pirq && pirq != current_pirq )
+    {
+        dprintk(XENLOG_G_ERR, "dom%d: irq %d already mapped to pirq %d\n",
+                d->domain_id, irq, current_pirq);
+        pirq = -EEXIST;
Quoted 2 lines

"return -EEXIST" please, to match the direct returns you use further up.

Ack.

Quoted 9 lines

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2595

Quoted 6 lines
xen/arch/x86/irq.c +6 -0
+    }
+
+    return pirq;
+}
+
+int allocate_and_map_gsi_pirq(struct domain *d, int *index, int *pirq_p)

Neither here nor in the MSI sibling you ever write to *index, so there's no need for the parameter to have pointer type.

Done

Quoted 30 lines
Quoted 16 lines
xen/arch/x86/irq.c +16 -0
+{
+    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

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2621

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+        {
+            dprintk(XENLOG_G_ERR, "dom%d: map pirq with incorrect irq!\n",
+                    d->domain_id);
+            return -EINVAL;
+        }
+    }
+
+    /* Verify or get pirq. */
+    spin_lock(&d->event_lock);
+    pirq = allocate_pirq(d, *pirq_p, irq, MAP_PIRQ_TYPE_GSI, 0);

The last parameter of allocate_pirq() is a pointer, so you really mean NULL here.

Quoted 16 lines
Quoted 4 lines
xen/arch/x86/irq.c +4 -0
+    if ( pirq < 0 )
+    {
+        ret = pirq;
+        goto done;

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2635

Quoted 10 lines
xen/arch/x86/irq.c +10 -0
+    }
+
+    ret = map_domain_pirq(d, pirq, irq, MAP_PIRQ_TYPE_GSI, NULL);
+    if ( ret == 0 )
+        *pirq_p = pirq;
+
+ done:
+    spin_unlock(&d->event_lock);
+    return ret;
+}

Blank line before final return statement please.

Fixed both of the above.

Quoted 24 lines
Quoted 24 lines
xen/arch/x86/irq.c +24 -0
+int allocate_and_map_msi_pirq(struct domain *d, int *index, int *pirq_p,
+                              int type, struct msi_info *msi)
+{
+    int irq, pirq, ret;
+
+    switch ( type )
+    {
+    case MAP_PIRQ_TYPE_MSI:
+        if ( !msi->table_base )
+            msi->entry_nr = 1;
+        irq = *index;
+        if ( irq == -1 )
+    case MAP_PIRQ_TYPE_MULTI_MSI:
+            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);
+            return -EINVAL;
+        }
+
+        msi->irq = irq;
+        break;
Quoted 8 lines

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2665

Quoted 5 lines
xen/arch/x86/irq.c +5 -0
+
+    default:
+        dprintk(XENLOG_G_ERR, "dom%d: wrong pirq type %x\n",
+                d->domain_id, type);
+        return -EINVAL;

This really should be an ASSERT_UNREACHABLE() (with the return statement kept).

Fixed.

Quoted 27 lines
Quoted 27 lines
xen/arch/x86/irq.c +27 -0
+    }
+
+    msi->irq = irq;
+
+    pcidevs_lock();
+    /* Verify or get pirq. */
+    spin_lock(&d->event_lock);
+    pirq = allocate_pirq(d, *pirq_p, irq, type, &msi->entry_nr);
+    if ( pirq < 0 )
+    {
+        ret = pirq;
+        goto done;
+    }
+
+    ret = map_domain_pirq(d, pirq, irq, type, msi);
+    if ( ret == 0 )
+        *pirq_p = pirq;
+
+ done:
+    spin_unlock(&d->event_lock);
+    pcidevs_unlock();
+    if ( ret != 0 )
+        switch ( type )
+        {
+        case MAP_PIRQ_TYPE_MSI:
+            if ( *index == -1 )
+        case MAP_PIRQ_TYPE_MULTI_MSI:
Quoted 8 lines

xen/arch/x86/irq.c bool_t hvm_domain_use_pirq(const struct domain *d, const struct pirq *pirq) · line 2698

Quoted 6 lines
xen/arch/x86/irq.c +6 -0
+                destroy_irq(irq);
+            break;
+        }
+    return ret;
+}
+

Please don't end a file with a blank line.

Fixed, and I've also added a new line before the return statement.

Quoted 39 lines
Quoted 39 lines
xen/arch/x86/physdev.c +1 -2
index eec4a41231..e99fd9a35f 100644
@@ -92,8 +92,7 @@ int physdev_map_pirq(domid_t domid, int type, int *index, 
 int *pirq_p,
                      struct msi_info *msi)
 {
     struct domain *d = current->domain;
-    int pirq, irq, ret = 0;
-    void *map_data = NULL;
+    int ret;
 
     if ( domid == DOMID_SELF && is_hvm_domain(d) && has_pirq(d) )
     {
xen/arch/x86/physdev.c +0 -19
@@ -119,135 +118,22 @@ int physdev_map_pirq(domid_t domid, int type, int 
 *index, int *pirq_p,
     switch ( type )
     {
     case MAP_PIRQ_TYPE_GSI:
-        if ( *index < 0 || *index >= nr_irqs_gsi )
-        {
-            dprintk(XENLOG_G_ERR, "dom%d: map invalid irq %d\n",
-                    d->domain_id, *index);
-            ret = -EINVAL;
-            goto free_domain;
-        }
-
-        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);
-                ret = -EINVAL;
-                goto free_domain;
-            }
Quoted 8 lines

xen/arch/x86/physdev.c int physdev_map_pirq(domid_t domid, int type, int *index, int *pirq_p, · line 123

Quoted 5 lines
xen/arch/x86/physdev.c +1 -2
-        }
+        ret = allocate_and_map_gsi_pirq(d, index, pirq_p);
         break;
-
     case MAP_PIRQ_TYPE_MSI:

Please don't delete the blank lines between case blocks, even if the blocks are much smaller now.

Fixed (and the one below).

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

PATCH v3 2/3 x86/pt: enable binding of GSIs to a PVH Dom0

In reply to Roger Pau Monne

Achieve 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.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v2:
- Turn the assert in hvm_gsi_{de}assert into an assert_unreachable (like it's done in __hvm_pci_intx_{de}assert.
- Do not increase/decrease gsi_assert_count, instead set it to 1/0.
- Fix a comment grammar error.
- Convert the pt_irq_create_bind asserts for bind type and pirq range into an error path.
- Reduce the size of the message buffers, 24 should be enough.
- Allow pt_irq_create_bind to unbind hardware domain GSIs.
- s/__hvm_pirq_eoi/hvm_pirq_eoi/.
- Remove ASSERT(pirq_dpci) from hvm_pirq_eoi.
- Remove pirq_dpci local variable from hvm_gsi_eoi (it's used only once).
- s/__hvm_gsi_eoi/hvm_gsi_eoi/.
- Add a comment to document hvm_gsi_assert usage of gsi_assert_count.

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       |  43 ++++++++
 xen/drivers/passthrough/io.c | 242 +++++++++++++++++++++++++++++++------------
 xen/include/xen/hvm/irq.h    |   6 ++
 3 files changed, 225 insertions(+), 66 deletions(-)
xen/arch/x86/hvm/irq.c +43 -0
index 86255847a6..6d40d1f94f 100644
@@ -126,6 +126,49 @@ 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);
+
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
+
+    /*
+     * __hvm_pci_intx_{de}assert uses an array to track the status of each
+     * interrupt line, and Xen does the routing and GSI assertion based on
+     * that. This 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.
+     */
+    spin_lock(&d->arch.hvm_domain.irq_lock);
+    if ( !hvm_irq->gsi_assert_count[gsi] )
+    {
+        hvm_irq->gsi_assert_count[gsi] = 1;
+        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);
+
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
+
+    spin_lock(&d->arch.hvm_domain.irq_lock);
+    if ( hvm_irq->gsi_assert_count[gsi] )
+        hvm_irq->gsi_assert_count[gsi] = 0;
+    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 +176 -66

357 lines not on this page · raw message

xen/include/xen/hvm/irq.h +6 -0
index 671a6f2e06..0d2c72c109 100644
@@ -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
#5 lore raw

Re: [PATCH v3 for-next 2/3] x86/pt: enable binding of GSIs to a PVH Dom0

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:
xen/arch/x86/hvm/irq.c +7 -0
@@ -126,6 +126,49 @@ 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);
+
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();

xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 145

Quoted 10 lines
xen/arch/x86/hvm/irq.c +10 -0
+        return;
+    }
+
+    /*
+     * __hvm_pci_intx_{de}assert uses an array to track the status of each
+     * interrupt line, and Xen does the routing and GSI assertion based on
+     * that. This 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.
+     */

The "which is not available here" part is at least confusing. I'm not even sure whether the "which" is supposed to refer to the array or something else, because you use the exact same array here.

Quoted 4 lines
xen/arch/x86/hvm/irq.c +4 -0
+void hvm_gsi_deassert(struct domain *d, unsigned int gsi)
+{
+    struct hvm_irq *hvm_irq = hvm_domain_irq(d);
+

xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 168

Quoted 10 lines
xen/arch/x86/hvm/irq.c +10 -0
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
+
+    spin_lock(&d->arch.hvm_domain.irq_lock);
+    if ( hvm_irq->gsi_assert_count[gsi] )
+        hvm_irq->gsi_assert_count[gsi] = 0;
+    ASSERT(!hvm_irq->gsi_assert_count[gsi]);

I don't think the if() and ASSERT() are of any use here anymore.

Quoted 24 lines
xen/drivers/passthrough/io.c +14 -0
@@ -164,6 +164,20 @@ static void pt_irq_time_out(void *data)
 
     spin_lock(&irq_map->dom->event_lock);
 
+    if ( irq_map->flags & HVM_IRQ_DPCI_IDENTITY_GSI )
+    {
+        struct pirq *pirq = dpci_pirq(irq_map);
+
+        ASSERT(is_hardware_domain(irq_map->dom));
+        /*
+         * Identity mapped, no need to iterate over the guest GSI list to find
+         * other pirqs sharing the same guest GSI.
+         */
+        irq_map->flags |= HVM_IRQ_DPCI_EOI_LATCH;
+        hvm_gsi_deassert(irq_map->dom, pirq->pirq);
+        goto out;
+    }
+
     dpci = domain_get_irq_dpci(irq_map->dom);
     if ( unlikely(!dpci) )
     {

xen/drivers/passthrough/io.c static void pt_irq_time_out(void *data) · line 203

Quoted 5 lines
xen/drivers/passthrough/io.c +1 -0
@@ -185,6 +199,7 @@ static void pt_irq_time_out(void *data)
         hvm_pci_intx_deassert(irq_map->dom, digl->device, digl->intx);
     }
 
+ out:
     pt_pirq_iterate(irq_map->dom, pt_irq_guest_eoi, NULL);

With the 1:1 mapping, do you really need to go through pt_pirq_iterate() here? I.e. can't you invoke pt_irq_guest_eoi() just once and be done? Or really it probably can be even more straight, as then there also is no point in setting the HVM_IRQ_DPCI_EOI_LATCH flag, but you could rather do directly what pt_irq_guest_eoi() does in its if() body. Otoh I may be missing something here, as I can't see why the code is using pt_pirq_iterate() even before your change.

Quoted 15 lines
xen/drivers/passthrough/io.c +10 -1
@@ -472,7 +510,27 @@ int pt_irq_create_bind(
                 pirq_dpci->flags = HVM_IRQ_DPCI_MAPPED |
                                    HVM_IRQ_DPCI_MACH_PCI |
                                    HVM_IRQ_DPCI_GUEST_PCI;
-                share = BIND_PIRQ__WILL_SHARE;
+                if ( !is_hardware_domain(d) )
+                    share = BIND_PIRQ__WILL_SHARE;
+                else
+                {
+                    unsigned int pin;
+                    struct hvm_vioapic *vioapic = gsi_vioapic(d, guest_gsi,
+                                                              &pin);
+
+                    if ( !vioapic )
+                    {

xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 532

Quoted 10 lines
xen/drivers/passthrough/io.c +10 -0
+                        ASSERT_UNREACHABLE();
+                        return -EINVAL;
+                    }
+                    pirq_dpci->flags |= HVM_IRQ_DPCI_IDENTITY_GSI;
+                    /*
+                     * Check if the corresponding vIO APIC pin is configured
+                     * level or edge trigger, level triggered interrupts will
+                     * be marked as shareable.
+                     */
+                    share = vioapic->redirtbl[pin].fields.trig_mode;

As pointed out during prior review (perhaps of another patch of yours) the trigger mode bit is meaningless for masked RTEs. At the very least an ASSERT() needs to be here for that reason, of course provided masked entries can never be seen here.

xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 550

Quoted 8 lines
xen/drivers/passthrough/io.c +1 -3
@@ -489,9 +547,15 @@ int pt_irq_create_bind(
                  * IRQ_GUEST is not set. As such we can reset 'dom' directly.
                  */
                 pirq_dpci->dom = NULL;
-                list_del(&girq->list);
-                list_del(&digl->list);
-                hvm_irq_dpci->link_cnt[link]--;
+                if ( !is_hardware_domain(d) )

To be honest I'd prefer if you checked digl and/or girq against NULL here, to avoid someone updating the condition above without updating this one in lock step.

Quoted 37 lines
xen/drivers/passthrough/io.c +14 -15
@@ -573,27 +644,30 @@ int pt_irq_destroy_bind(
         struct hvm_girq_dpci_mapping *girq;
         struct dev_intx_gsi_link *digl, *tmp;
 
-        list_for_each_entry ( girq, &hvm_irq_dpci->girq[guest_gsi], list )
+        if ( hvm_irq_dpci )
         {
-            if ( girq->bus         == bus &&
-                 girq->device      == device &&
-                 girq->intx        == intx &&
-                 girq->machine_gsi == machine_gsi )
+            list_for_each_entry ( girq, &hvm_irq_dpci->girq[guest_gsi], list )
             {
-                list_del(&girq->list);
-                xfree(girq);
-                girq = NULL;
-                break;
+                if ( girq->bus         == bus &&
+                     girq->device      == device &&
+                     girq->intx        == intx &&
+                     girq->machine_gsi == machine_gsi )
+                {
+                    list_del(&girq->list);
+                    xfree(girq);
+                    girq = NULL;
+                    break;
+                }
             }
-        }
 
-        if ( girq )
-        {
-            spin_unlock(&d->event_lock);
-            return -EINVAL;
-        }
+            if ( girq )
+            {

xen/drivers/passthrough/io.c int pt_irq_destroy_bind( · line 673

Quoted 10 lines
xen/drivers/passthrough/io.c +5 -1
+                spin_unlock(&d->event_lock);
+                return -EINVAL;
+            }
 
-        hvm_irq_dpci->link_cnt[link]--;
+            hvm_irq_dpci->link_cnt[link]--;
+        }
 
         /* clear the mirq info */
         if ( pirq_dpci && (pirq_dpci->flags & HVM_IRQ_DPCI_MAPPED) )

What you leave untouched here is code freeing something you never allocate for Dom0. While likely this is correct (as the list will always be empty), it is confusing at the same time. Furthermore if you also skip that part, I think you can avoid having to re-indent all the code further up.

Quoted 4 lines
xen/drivers/passthrough/io.c +0 -0
@@ -638,11 +712,15 @@ int pt_irq_destroy_bind(
     if ( what && iommu_verbose )
     {
         unsigned int device = pt_irq_bind->u.pci.device;

xen/drivers/passthrough/io.c int pt_irq_destroy_bind( · line 720

Quoted 10 lines
xen/drivers/passthrough/io.c +5 -4
+        char buf[24] = "";
 
-        printk(XENLOG_G_INFO
-               "d%d %s unmap: m_irq=%u dev=%02x:%02x.%u intx=%u\n",
-               d->domain_id, what, machine_gsi, pt_irq_bind->u.pci.bus,
-               PCI_SLOT(device), PCI_FUNC(device), pt_irq_bind->u.pci.intx);
+        if ( !is_hardware_domain(d) )
+            snprintf(buf, ARRAY_SIZE(buf), " dev=%02x.%02x.%u intx=%u",
+                     pt_irq_bind->u.pci.bus, PCI_SLOT(device),
+                     PCI_FUNC(device), pt_irq_bind->u.pci.intx);

Now that this supports Dom0, you also need to log the segment.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH v3 for-next 2/3] x86/pt: enable binding of GSIs to a PVH Dom0

Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:
xen/arch/x86/hvm/irq.c +13 -0
@@ -126,6 +126,49 @@ 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);
+
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
+
+    /*
+     * __hvm_pci_intx_{de}assert uses an array to track the status of each
+     * interrupt line, and Xen does the routing and GSI assertion based on
Quoted 8 lines

xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 145

Quoted 4 lines
xen/arch/x86/hvm/irq.c +4 -0
+     * that. This 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.
+     */

The "which is not available here" part is at least confusing. I'm not even sure whether the "which" is supposed to refer to the array or something else, because you use the exact same array here.

I agree, it's confusing and badly worded, how about:

__hvm_pci_intx_{de}assert uses a bitfield in pci_intx.i to track the status of each interrupt line, and Xen does the routing and GSI assertion based on that. The value of the pci_intx.i bitmap 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.

Quoted 8 lines
Quoted 8 lines
xen/arch/x86/hvm/irq.c +8 -0
+void hvm_gsi_deassert(struct domain *d, unsigned int gsi)
+{
+    struct hvm_irq *hvm_irq = hvm_domain_irq(d);
+
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();
+        return;
Quoted 8 lines

xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 168

Quoted 6 lines
xen/arch/x86/hvm/irq.c +6 -0
+    }
+
+    spin_lock(&d->arch.hvm_domain.irq_lock);
+    if ( hvm_irq->gsi_assert_count[gsi] )
+        hvm_irq->gsi_assert_count[gsi] = 0;
+    ASSERT(!hvm_irq->gsi_assert_count[gsi]);

I don't think the if() and ASSERT() are of any use here anymore.

Fixed.

Quoted 27 lines
Quoted 27 lines
xen/drivers/passthrough/io.c +14 -0
@@ -164,6 +164,20 @@ static void pt_irq_time_out(void *data)
 
     spin_lock(&irq_map->dom->event_lock);
 
+    if ( irq_map->flags & HVM_IRQ_DPCI_IDENTITY_GSI )
+    {
+        struct pirq *pirq = dpci_pirq(irq_map);
+
+        ASSERT(is_hardware_domain(irq_map->dom));
+        /*
+         * Identity mapped, no need to iterate over the guest GSI list to find
+         * other pirqs sharing the same guest GSI.
+         */
+        irq_map->flags |= HVM_IRQ_DPCI_EOI_LATCH;
+        hvm_gsi_deassert(irq_map->dom, pirq->pirq);
+        goto out;
+    }
+
     dpci = domain_get_irq_dpci(irq_map->dom);
     if ( unlikely(!dpci) )
     {
@@ -185,6 +199,7 @@ static void pt_irq_time_out(void *data)
         hvm_pci_intx_deassert(irq_map->dom, digl->device, digl->intx);
     }
 
Quoted 11 lines

xen/drivers/passthrough/io.c static void pt_irq_time_out(void *data) · line 203

Quoted 2 lines
xen/drivers/passthrough/io.c +1 -0
+ out:
     pt_pirq_iterate(irq_map->dom, pt_irq_guest_eoi, NULL);

With the 1:1 mapping, do you really need to go through pt_pirq_iterate() here? I.e. can't you invoke pt_irq_guest_eoi() just once and be done? Or really it probably can be even more straight, as then there also is no point in setting the HVM_IRQ_DPCI_EOI_LATCH flag, but you could rather do directly what pt_irq_guest_eoi() does in its if() body. Otoh I may be missing something here, as I can't see why the code is using pt_pirq_iterate() even before your change.

I have to admit this is not obviously clear to me (or I'm also missing something), there are too many translation layers and indirections in this code, together with a complete lack of comments.

Previous to my change, pt_irq_time_out iterates over the list of guest devices (digl) bound to a pirq, desserts the interrupt lines and marks all the pirqs bound to the same guest GSI with the EOI_LATCH flag. Finally pt_irq_time_out iterates over the list of guest pirqs and clears (EOI) all the ones marked as EOI_LATCH.

I don't really understand the usefulness of the EOI_LATCH flag, can't pt_irq_time_out just call pt_irq_guest_eoi and avoid the iteration? Something like:

list_for_each_entry ( digl, &irq_map->digl_list, list )

{
    unsigned int guest_gsi = hvm_pci_intx_gsi(digl->device, digl->intx);
    const struct hvm_girq_dpci_mapping *girq;

    list_for_each_entry ( girq, &dpci->girq[guest_gsi], list )
    {
        struct pirq *pirq = pirq_info(irq_map->dom, girq->machine_gsi);

        pirq_dpci(pirq)->masked = 0;
        pirq_dpci(pirq)->pending = 0;
        pirq_guest_eoi(dpci_pirq(pirq));
    }
    hvm_pci_intx_deassert(irq_map->dom, digl->device, digl->intx);
}

I can of course also do something similar for the identity mapping case.

Quoted 22 lines
Quoted 22 lines
xen/drivers/passthrough/io.c +17 -1
@@ -472,7 +510,27 @@ int pt_irq_create_bind(
                 pirq_dpci->flags = HVM_IRQ_DPCI_MAPPED |
                                    HVM_IRQ_DPCI_MACH_PCI |
                                    HVM_IRQ_DPCI_GUEST_PCI;
-                share = BIND_PIRQ__WILL_SHARE;
+                if ( !is_hardware_domain(d) )
+                    share = BIND_PIRQ__WILL_SHARE;
+                else
+                {
+                    unsigned int pin;
+                    struct hvm_vioapic *vioapic = gsi_vioapic(d, guest_gsi,
+                                                              &pin);
+
+                    if ( !vioapic )
+                    {
+                        ASSERT_UNREACHABLE();
+                        return -EINVAL;
+                    }
+                    pirq_dpci->flags |= HVM_IRQ_DPCI_IDENTITY_GSI;
+                    /*
+                     * Check if the corresponding vIO APIC pin is configured
+                     * level or edge trigger, level triggered interrupts will
Quoted 8 lines

xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 532

Quoted 3 lines
xen/drivers/passthrough/io.c +3 -0
+                     * be marked as shareable.
+                     */
+                    share = vioapic->redirtbl[pin].fields.trig_mode;

As pointed out during prior review (perhaps of another patch of yours) the trigger mode bit is meaningless for masked RTEs. At the very least an ASSERT() needs to be here for that reason, of course provided masked entries can never be seen here.

pt_irq_create_bind for GSIs will only be called when the hardware domain unmasks the RTE, so an ASSERT is the right choice IMHO.

Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/io.c +0 -0
@@ -489,9 +547,15 @@ int pt_irq_create_bind(
                  * IRQ_GUEST is not set. As such we can reset 'dom' directly.
                  */
                 pirq_dpci->dom = NULL;
Quoted 8 lines

xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 550

Quoted 4 lines
xen/drivers/passthrough/io.c +1 -3
-                list_del(&girq->list);
-                list_del(&digl->list);
-                hvm_irq_dpci->link_cnt[link]--;
+                if ( !is_hardware_domain(d) )

To be honest I'd prefer if you checked digl and/or girq against NULL here, to avoid someone updating the condition above without updating this one in lock step.

I've changed the condition to "girq && digl".

Quoted 45 lines
Quoted 45 lines
xen/drivers/passthrough/io.c +19 -16
@@ -573,27 +644,30 @@ int pt_irq_destroy_bind(
         struct hvm_girq_dpci_mapping *girq;
         struct dev_intx_gsi_link *digl, *tmp;
 
-        list_for_each_entry ( girq, &hvm_irq_dpci->girq[guest_gsi], list )
+        if ( hvm_irq_dpci )
         {
-            if ( girq->bus         == bus &&
-                 girq->device      == device &&
-                 girq->intx        == intx &&
-                 girq->machine_gsi == machine_gsi )
+            list_for_each_entry ( girq, &hvm_irq_dpci->girq[guest_gsi], list )
             {
-                list_del(&girq->list);
-                xfree(girq);
-                girq = NULL;
-                break;
+                if ( girq->bus         == bus &&
+                     girq->device      == device &&
+                     girq->intx        == intx &&
+                     girq->machine_gsi == machine_gsi )
+                {
+                    list_del(&girq->list);
+                    xfree(girq);
+                    girq = NULL;
+                    break;
+                }
             }
-        }
 
-        if ( girq )
-        {
-            spin_unlock(&d->event_lock);
-            return -EINVAL;
-        }
+            if ( girq )
+            {
+                spin_unlock(&d->event_lock);
+                return -EINVAL;
+            }
 
-        hvm_irq_dpci->link_cnt[link]--;
+            hvm_irq_dpci->link_cnt[link]--;
+        }
 
Quoted 8 lines

xen/drivers/passthrough/io.c int pt_irq_destroy_bind( · line 673

Quoted 2 lines
xen/drivers/passthrough/io.c +0 -0
         /* clear the mirq info */
         if ( pirq_dpci && (pirq_dpci->flags & HVM_IRQ_DPCI_MAPPED) )

What you leave untouched here is code freeing something you never allocate for Dom0. While likely this is correct (as the list will always be empty), it is confusing at the same time. Furthermore if you also skip that part, I think you can avoid having to re-indent all the code further up.

I see what you mean, the hvm_irq_dpci condition can be moved to the upper if, since none of what's inside this condition is relevant for the hardware domain case, and will avoid this re-indentation.

Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/io.c +1 -0
@@ -638,11 +712,15 @@ int pt_irq_destroy_bind(
     if ( what && iommu_verbose )
     {
         unsigned int device = pt_irq_bind->u.pci.device;
+        char buf[24] = "";
 
Quoted 10 lines

xen/drivers/passthrough/io.c int pt_irq_destroy_bind( · line 720

Quoted 8 lines
xen/drivers/passthrough/io.c +4 -4
-        printk(XENLOG_G_INFO
-               "d%d %s unmap: m_irq=%u dev=%02x:%02x.%u intx=%u\n",
-               d->domain_id, what, machine_gsi, pt_irq_bind->u.pci.bus,
-               PCI_SLOT(device), PCI_FUNC(device), pt_irq_bind->u.pci.intx);
+        if ( !is_hardware_domain(d) )
+            snprintf(buf, ARRAY_SIZE(buf), " dev=%02x.%02x.%u intx=%u",
+                     pt_irq_bind->u.pci.bus, PCI_SLOT(device),
+                     PCI_FUNC(device), pt_irq_bind->u.pci.intx);

Now that this supports Dom0, you also need to log the segment.

I'm not sure I follow you here, for the Dom case all the fields in u.pci.* are unused, since Xen does an identity mapping of the GSI, but it doesn't know to which device it belongs. That's different for the MSI case, but then this fields are not used anyway.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v3 for-next 2/3] x86/pt: enable binding of GSIs to a PVH Dom0

Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 31.05.17 at 16:29, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:
xen/arch/x86/hvm/irq.c +13 -0
@@ -126,6 +126,49 @@ 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);
+
+    if ( gsi >= hvm_irq->nr_gsis )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
+
+    /*
+     * __hvm_pci_intx_{de}assert uses an array to track the status of each
+     * interrupt line, and Xen does the routing and GSI assertion based on
Quoted 8 lines

xen/arch/x86/hvm/irq.c void hvm_pci_intx_deassert( · line 145

Quoted 4 lines
xen/arch/x86/hvm/irq.c +4 -0
+     * that. This 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.
+     */

The "which is not available here" part is at least confusing. I'm not even sure whether the "which" is supposed to refer to the array or something else, because you use the exact same array here.

Quoted 8 lines

I agree, it's confusing and badly worded, how about:

__hvm_pci_intx_{de}assert uses a bitfield in pci_intx.i to track the status of each interrupt line, and Xen does the routing and GSI assertion based on that. The value of the pci_intx.i bitmap 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.

Well, it's better, but the "which is not available here" still leaves open what the "which" refers to. How about "The value of the pci_intx.i bitmap prevents the same line from triggering multiple times. As we don't use that bitmap for the hardware domain, Xen nneds to ..."?

Quoted 69 lines
Quoted 27 lines
Quoted 27 lines
xen/drivers/passthrough/io.c +14 -0
@@ -164,6 +164,20 @@ static void pt_irq_time_out(void *data)
 
     spin_lock(&irq_map->dom->event_lock);
 
+    if ( irq_map->flags & HVM_IRQ_DPCI_IDENTITY_GSI )
+    {
+        struct pirq *pirq = dpci_pirq(irq_map);
+
+        ASSERT(is_hardware_domain(irq_map->dom));
+        /*
+         * Identity mapped, no need to iterate over the guest GSI list to find
+         * other pirqs sharing the same guest GSI.
+         */
+        irq_map->flags |= HVM_IRQ_DPCI_EOI_LATCH;
+        hvm_gsi_deassert(irq_map->dom, pirq->pirq);
+        goto out;
+    }
+
     dpci = domain_get_irq_dpci(irq_map->dom);
     if ( unlikely(!dpci) )
     {
@@ -185,6 +199,7 @@ static void pt_irq_time_out(void *data)
         hvm_pci_intx_deassert(irq_map->dom, digl->device, digl->intx);
     }
 
Quoted 11 lines

xen/drivers/passthrough/io.c static void pt_irq_time_out(void *data) · line 203

Quoted 2 lines
xen/drivers/passthrough/io.c +1 -0
+ out:
     pt_pirq_iterate(irq_map->dom, pt_irq_guest_eoi, NULL);

With the 1:1 mapping, do you really need to go through pt_pirq_iterate() here? I.e. can't you invoke pt_irq_guest_eoi() just once and be done? Or really it probably can be even more straight, as then there also is no point in setting the HVM_IRQ_DPCI_EOI_LATCH flag, but you could rather do directly what pt_irq_guest_eoi() does in its if() body. Otoh I may be missing something here, as I can't see why the code is using pt_pirq_iterate() even before your change.

I have to admit this is not obviously clear to me (or I'm also missing something), there are too many translation layers and indirections in this code, together with a complete lack of comments.

Previous to my change, pt_irq_time_out iterates over the list of guest devices (digl) bound to a pirq, desserts the interrupt lines and marks all the pirqs bound to the same guest GSI with the EOI_LATCH flag. Finally pt_irq_time_out iterates over the list of guest pirqs and clears (EOI) all the ones marked as EOI_LATCH.

I don't really understand the usefulness of the EOI_LATCH flag, can't pt_irq_time_out just call pt_irq_guest_eoi and avoid the iteration? Something like:

list_for_each_entry ( digl, &irq_map->digl_list, list )

{
    unsigned int guest_gsi = hvm_pci_intx_gsi(digl->device, digl->intx);
    const struct hvm_girq_dpci_mapping *girq;

    list_for_each_entry ( girq, &dpci->girq[guest_gsi], list )
    {
        struct pirq *pirq = pirq_info(irq_map->dom, girq->machine_gsi);

        pirq_dpci(pirq)->masked = 0;
        pirq_dpci(pirq)->pending = 0;
        pirq_guest_eoi(dpci_pirq(pirq));
    }
    hvm_pci_intx_deassert(irq_map->dom, digl->device, digl->intx);
}
Quoted 2 lines

I can of course also do something similar for the identity mapping case.

Well, that's basically what I did outline, yes. We may need to do some archeology here to figure out whether once the more indirect mechanism was really needed, but the need disappeared without it being noticed. I don't think the original author(s) of the code would still be around to ask, but I didn't check (yet) who they are.

Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
xen/drivers/passthrough/io.c +17 -1
@@ -472,7 +510,27 @@ int pt_irq_create_bind(
                 pirq_dpci->flags = HVM_IRQ_DPCI_MAPPED |
                                    HVM_IRQ_DPCI_MACH_PCI |
                                    HVM_IRQ_DPCI_GUEST_PCI;
-                share = BIND_PIRQ__WILL_SHARE;
+                if ( !is_hardware_domain(d) )
+                    share = BIND_PIRQ__WILL_SHARE;
+                else
+                {
+                    unsigned int pin;
+                    struct hvm_vioapic *vioapic = gsi_vioapic(d, guest_gsi,
+                                                              &pin);
+
+                    if ( !vioapic )
+                    {
+                        ASSERT_UNREACHABLE();
+                        return -EINVAL;
+                    }
+                    pirq_dpci->flags |= HVM_IRQ_DPCI_IDENTITY_GSI;
+                    /*
+                     * Check if the corresponding vIO APIC pin is configured
+                     * level or edge trigger, level triggered interrupts will
Quoted 8 lines

xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 532

Quoted 3 lines
xen/drivers/passthrough/io.c +3 -0
+                     * be marked as shareable.
+                     */
+                    share = vioapic->redirtbl[pin].fields.trig_mode;

As pointed out during prior review (perhaps of another patch of yours) the trigger mode bit is meaningless for masked RTEs. At the very least an ASSERT() needs to be here for that reason, of course provided masked entries can never be seen here.

Quoted 2 lines

pt_irq_create_bind for GSIs will only be called when the hardware domain unmasks the RTE, so an ASSERT is the right choice IMHO.

Yes, I think I did see this in later code, so an ASSERT() it is then.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/io.c +0 -0
@@ -489,9 +547,15 @@ int pt_irq_create_bind(
                  * IRQ_GUEST is not set. As such we can reset 'dom' directly.
                  */
                 pirq_dpci->dom = NULL;
Quoted 8 lines

xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 550

Quoted 4 lines
xen/drivers/passthrough/io.c +1 -3
-                list_del(&girq->list);
-                list_del(&digl->list);
-                hvm_irq_dpci->link_cnt[link]--;
+                if ( !is_hardware_domain(d) )

To be honest I'd prefer if you checked digl and/or girq against NULL here, to avoid someone updating the condition above without updating this one in lock step.

Quoted 1 line

I've changed the condition to "girq && digl".

How about using || and then ASSERT()ing && inside the if() body?

Quoted 17 lines
Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/io.c +1 -0
@@ -638,11 +712,15 @@ int pt_irq_destroy_bind(
     if ( what && iommu_verbose )
     {
         unsigned int device = pt_irq_bind->u.pci.device;
+        char buf[24] = "";
 
Quoted 10 lines

xen/drivers/passthrough/io.c int pt_irq_destroy_bind( · line 720

Quoted 8 lines
xen/drivers/passthrough/io.c +4 -4
-        printk(XENLOG_G_INFO
-               "d%d %s unmap: m_irq=%u dev=%02x:%02x.%u intx=%u\n",
-               d->domain_id, what, machine_gsi, pt_irq_bind->u.pci.bus,
-               PCI_SLOT(device), PCI_FUNC(device), pt_irq_bind->u.pci.intx);
+        if ( !is_hardware_domain(d) )
+            snprintf(buf, ARRAY_SIZE(buf), " dev=%02x.%02x.%u intx=%u",
+                     pt_irq_bind->u.pci.bus, PCI_SLOT(device),
+                     PCI_FUNC(device), pt_irq_bind->u.pci.intx);

Now that this supports Dom0, you also need to log the segment.

Quoted 4 lines

I'm not sure I follow you here, for the Dom case all the fields in u.pci.* are unused, since Xen does an identity mapping of the GSI, but it doesn't know to which device it belongs. That's different for the MSI case, but then this fields are not used anyway.

Oh, right, sorry for the noise.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

PATCH v3 3/3 x86/vioapic: bind interrupts to PVH Dom0

In reply to Roger Pau Monne

Add 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 v2:
- s/vioapic_dom0_map_gsi/vioapic_hwdom_map_gsi/.
- Don't set hvm_domid in xen_domctl_bind_pt_irq_t (it's ignored).
- s/gdprintk/gprintk/.
- Change the logic of the error paths and remove the labels.

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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
xen/arch/x86/hvm/vioapic.c +60 -0
index abcc473c88..4093082c31 100644
@@ -158,6 +158,52 @@ static int vioapic_read(
     return X86EMUL_OKAY;
 }
 
+static int vioapic_hwdom_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,
+    };
+    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 == -EEXIST )
+        return 0;
+    if ( ret )
+    {
+        gprintk(XENLOG_WARNING, "vioapic: error registering GSI %u: %d\n",
+                 gsi, ret);
+        return ret;
+    }
+
+    ret = allocate_and_map_gsi_pirq(d, &pirq, &pirq);
+    if ( ret )
+    {
+        gprintk(XENLOG_WARNING, "vioapic: error mapping GSI %u: %d\n",
+                 gsi, ret);
+        return ret;
+    }
+
+    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;
+}
+
 static void vioapic_write_redirent(
     struct hvm_vioapic *vioapic, unsigned int idx,
     int top_word, uint32_t val)
@@ -188,6 +234,20 @@ static void vioapic_write_redirent(
         unmasked = unmasked && !ent.fields.mask;
     }
 
+    if ( is_hardware_domain(d) && unmasked )
+    {
+        int ret;
+
+        ret = vioapic_hwdom_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
#9 lore raw

Re: [PATCH v3 for-next 3/3] x86/vioapic: bind interrupts to PVH Dom0

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:

Changes since v2:
- s/vioapic_dom0_map_gsi/vioapic_hwdom_map_gsi/.
- Don't set hvm_domid in xen_domctl_bind_pt_irq_t (it's ignored).

The implication of the respective earlier comment was for there to first be a prereq patch added removing this dead field. Otherwise not setting the field is a latent bug.

xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 167

Quoted 13 lines
xen/arch/x86/hvm/vioapic.c +7 -0
@@ -158,6 +158,52 @@ static int vioapic_read(
     return X86EMUL_OKAY;
 }
 
+static int vioapic_hwdom_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,

Actually you still set the field, just that this is no implicit. Hence the latent bug reduces to just the hwdom != Dom0 case, but anyway.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw

Re: [PATCH v3 for-next 3/3] x86/vioapic: bind interrupts to PVH Dom0

Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:

Changes since v2:
- s/vioapic_dom0_map_gsi/vioapic_hwdom_map_gsi/.
- Don't set hvm_domid in xen_domctl_bind_pt_irq_t (it's ignored).

The implication of the respective earlier comment was for there to first be a prereq patch added removing this dead field. Otherwise not setting the field is a latent bug.

I've added a pre-patch to get rid of hvm_domid in the bind struct.

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/vioapic.c +0 -0
@@ -158,6 +158,52 @@ static int vioapic_read(
     return X86EMUL_OKAY;
 }
 
Quoted 10 lines

xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 167

Quoted 7 lines
xen/arch/x86/hvm/vioapic.c +7 -0
+static int vioapic_hwdom_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,

Actually you still set the field, just that this is no implicit. Hence the latent bug reduces to just the hwdom != Dom0 case, but anyway.

What do you mean by implicit? Is that because I'm passing d to the bind function?

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw

Re: [PATCH v3 for-next 3/3] x86/vioapic: bind interrupts to PVH Dom0

Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 31.05.17 at 16:48, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 17:15, <[email protected]> wrote:

Changes since v2:
- s/vioapic_dom0_map_gsi/vioapic_hwdom_map_gsi/.
- Don't set hvm_domid in xen_domctl_bind_pt_irq_t (it's ignored).

The implication of the respective earlier comment was for there to first be a prereq patch added removing this dead field. Otherwise not setting the field is a latent bug.

I've added a pre-patch to get rid of hvm_domid in the bind struct.

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/vioapic.c +0 -0
@@ -158,6 +158,52 @@ static int vioapic_read(
     return X86EMUL_OKAY;
 }
 
Quoted 10 lines

xen/arch/x86/hvm/vioapic.c static int vioapic_read( · line 167

Quoted 7 lines
xen/arch/x86/hvm/vioapic.c +7 -0
+static int vioapic_hwdom_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,

Actually you still set the field, just that this is no implicit. Hence the latent bug reduces to just the hwdom != Dom0 case, but anyway.

Quoted 2 lines

What do you mean by implicit? Is that because I'm passing d to the bind function?

For one I see that me having misspelled thing ("is now implicit") may have caused misunderstanding. But what I meant anyway was that by omitting the initializer you implicitly initialize the field to zero, which is correct if and only if Dom0 == hwdom. But the discussion is moot with the field gone.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel