Skip to contentSkip to conversation

x86/dpci: bind legacy PCI interrupts to PVHv2 Dom0

PATCH In review Roger Pau Monne 2 participants 8 messages Jun 23, 2017 – Jun 26, 2017

lore
Share & tools
lore
#0 lore raw

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

There are only tree remaining patches, the first one is an improvements/cleanup to the vioapic code, the second adds support for identity mapping GSIs for the hardware domain, and finally the last one snoops vIO APIC writes from the hardware domain in order to setup those identity mappings.

A branch with the changes can be found at:

git://xenbits.xen.org/people/royger/xen.git dom0_gsi_v6

Thanks, Roger.

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

#1 lore raw

PATCH v6 1/3 x86/vioapic: make gsi_vioapic private

And introduce vioapic_get_{mask/vector} in order to replace it's usage.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v5:
- New in this version.

---
 xen/arch/x86/hvm/vioapic.c        | 26 ++++++++++++++++++++++++--
 xen/arch/x86/hvm/vpt.c            | 20 ++++++++++----------
 xen/include/asm-x86/hvm/vioapic.h |  6 +++---
 3 files changed, 37 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/vioapic.c +24 -2
index abcc473c88..f2895cf57c 100644
@@ -61,8 +61,8 @@ static struct hvm_vioapic *addr_vioapic(const struct domain *d,
     return NULL;
 }
 
-struct hvm_vioapic *gsi_vioapic(const struct domain *d, unsigned int gsi,
-                                unsigned int *pin)
+static struct hvm_vioapic *gsi_vioapic(const struct domain *d,
+                                       unsigned int gsi, unsigned int *pin)
 {
     unsigned int i;
 
@@ -476,6 +476,28 @@ void vioapic_update_EOI(struct domain *d, u8 vector)
     spin_unlock(&d->arch.hvm_domain.irq_lock);
 }
 
+int vioapic_get_mask(struct domain *d, unsigned int gsi)
+{
+    unsigned int pin;
+    const struct hvm_vioapic *vioapic = gsi_vioapic(d, gsi, &pin);
+
+    if ( !vioapic )
+        return -EINVAL;
+
+    return vioapic->redirtbl[pin].fields.mask;
+}
+
+int vioapic_get_vector(struct domain *d, unsigned int gsi)
+{
+    unsigned int pin;
+    const struct hvm_vioapic *vioapic = gsi_vioapic(d, gsi, &pin);
+
+    if ( !vioapic )
+        return -EINVAL;
+
+    return vioapic->redirtbl[pin].fields.vector;
+}
+
 static int ioapic_save(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_vioapic *s;
xen/arch/x86/hvm/vpt.c +10 -10
index e3f203915b..3841140be7 100644
@@ -78,8 +78,8 @@ void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
 static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
 {
     struct vcpu *v = pt->vcpu;
-    struct hvm_vioapic *vioapic;
-    unsigned int gsi, isa_irq, pin;
+    unsigned int gsi, isa_irq;
+    int vector;
 
     if ( pt->source == PTSRC_lapic )
         return pt->irq;
@@ -92,8 +92,8 @@ static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
                 + (isa_irq & 7));
 
     ASSERT(src == hvm_intsrc_lapic);
-    vioapic = gsi_vioapic(v->domain, gsi, &pin);
-    if ( !vioapic )
+    vector = vioapic_get_vector(v->domain, gsi);
+    if ( vector < 0 )
     {
         dprintk(XENLOG_WARNING, "d%u: invalid GSI (%u) for platform timer\n",
                 v->domain->domain_id, gsi);
@@ -101,14 +101,14 @@ static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
         return -1;
     }
 
-    return vioapic->redirtbl[pin].fields.vector;
+    return vector;
 }
 
 static int pt_irq_masked(struct periodic_time *pt)
 {
     struct vcpu *v = pt->vcpu;
-    unsigned int gsi, isa_irq, pin;
-    struct hvm_vioapic *vioapic;
+    unsigned int gsi, isa_irq;
+    int mask;
     uint8_t pic_imr;
 
     if ( pt->source == PTSRC_lapic )
@@ -121,8 +121,8 @@ static int pt_irq_masked(struct periodic_time *pt)
     isa_irq = pt->irq;
     gsi = hvm_isa_irq_to_gsi(isa_irq);
     pic_imr = v->domain->arch.hvm_domain.vpic[isa_irq >> 3].imr;
-    vioapic = gsi_vioapic(v->domain, gsi, &pin);
-    if ( !vioapic )
+    mask = vioapic_get_mask(v->domain, gsi);
+    if ( mask < 0 )
     {
         dprintk(XENLOG_WARNING, "d%u: invalid GSI (%u) for platform timer\n",
                 v->domain->domain_id, gsi);
@@ -131,7 +131,7 @@ static int pt_irq_masked(struct periodic_time *pt)
     }
 
     return (((pic_imr & (1 << (isa_irq & 7))) || !vlapic_accept_pic_intr(v)) &&
-            vioapic->redirtbl[pin].fields.mask);
+            mask);
 }
 
 static void pt_lock(struct periodic_time *pt)
xen/include/asm-x86/hvm/vioapic.h +3 -3
index 2ceb60eaef..5028bdcc48 100644
@@ -61,13 +61,13 @@ struct hvm_vioapic {
 #define domain_vioapic(d, i) ((d)->arch.hvm_domain.vioapic[i])
 #define vioapic_domain(v) ((v)->domain)
 
-struct hvm_vioapic *gsi_vioapic(const struct domain *d, unsigned int gsi,
-                                unsigned int *pin);
-
 int vioapic_init(struct domain *d);
 void vioapic_deinit(struct domain *d);
 void vioapic_reset(struct domain *d);
 void vioapic_irq_positive_edge(struct domain *d, unsigned int irq);
 void vioapic_update_EOI(struct domain *d, u8 vector);
 
+int vioapic_get_mask(struct domain *d, unsigned int gsi);
+int vioapic_get_vector(struct domain *d, unsigned int gsi);
+
 #endif /* __ASM_X86_HVM_VIOAPIC_H__ */
Signature · 7 lines
2.11.0 (Apple Git-81)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v6 1/3
#2 lore raw

Re: [PATCH v6 1/3] x86/vioapic: make gsi_vioapic private

xen/include/asm-x86/hvm/vioapic.h struct hvm_vioapic { · line 71

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.06.17 at 11:59, <[email protected]> wrote:
xen/include/asm-x86/hvm/vioapic.h +2 -0
+int vioapic_get_mask(struct domain *d, unsigned int gsi);
+int vioapic_get_vector(struct domain *d, unsigned int gsi);

Both should have their first parameter const qualified. With that

Jan

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

#3 lore raw

PATCH v6 1/3 x86/vioapic: make gsi_vioapic private

And introduce vioapic_get_{mask/vector} in order to replace it's usage.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v6:
- Constify domain parameter.

Changes since v5:
- New in this version.

---
 xen/arch/x86/hvm/vioapic.c        | 26 ++++++++++++++++++++++++--
 xen/arch/x86/hvm/vpt.c            | 20 ++++++++++----------
 xen/include/asm-x86/hvm/vioapic.h |  6 +++---
 3 files changed, 37 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/vioapic.c +24 -2
index abcc473c88..12912f068d 100644
@@ -61,8 +61,8 @@ static struct hvm_vioapic *addr_vioapic(const struct domain *d,
     return NULL;
 }
 
-struct hvm_vioapic *gsi_vioapic(const struct domain *d, unsigned int gsi,
-                                unsigned int *pin)
+static struct hvm_vioapic *gsi_vioapic(const struct domain *d,
+                                       unsigned int gsi, unsigned int *pin)
 {
     unsigned int i;
 
@@ -476,6 +476,28 @@ void vioapic_update_EOI(struct domain *d, u8 vector)
     spin_unlock(&d->arch.hvm_domain.irq_lock);
 }
 
+int vioapic_get_mask(const struct domain *d, unsigned int gsi)
+{
+    unsigned int pin;
+    const struct hvm_vioapic *vioapic = gsi_vioapic(d, gsi, &pin);
+
+    if ( !vioapic )
+        return -EINVAL;
+
+    return vioapic->redirtbl[pin].fields.mask;
+}
+
+int vioapic_get_vector(const struct domain *d, unsigned int gsi)
+{
+    unsigned int pin;
+    const struct hvm_vioapic *vioapic = gsi_vioapic(d, gsi, &pin);
+
+    if ( !vioapic )
+        return -EINVAL;
+
+    return vioapic->redirtbl[pin].fields.vector;
+}
+
 static int ioapic_save(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_vioapic *s;
xen/arch/x86/hvm/vpt.c +10 -10
index e3f203915b..3841140be7 100644
@@ -78,8 +78,8 @@ void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
 static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
 {
     struct vcpu *v = pt->vcpu;
-    struct hvm_vioapic *vioapic;
-    unsigned int gsi, isa_irq, pin;
+    unsigned int gsi, isa_irq;
+    int vector;
 
     if ( pt->source == PTSRC_lapic )
         return pt->irq;
@@ -92,8 +92,8 @@ static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
                 + (isa_irq & 7));
 
     ASSERT(src == hvm_intsrc_lapic);
-    vioapic = gsi_vioapic(v->domain, gsi, &pin);
-    if ( !vioapic )
+    vector = vioapic_get_vector(v->domain, gsi);
+    if ( vector < 0 )
     {
         dprintk(XENLOG_WARNING, "d%u: invalid GSI (%u) for platform timer\n",
                 v->domain->domain_id, gsi);
@@ -101,14 +101,14 @@ static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
         return -1;
     }
 
-    return vioapic->redirtbl[pin].fields.vector;
+    return vector;
 }
 
 static int pt_irq_masked(struct periodic_time *pt)
 {
     struct vcpu *v = pt->vcpu;
-    unsigned int gsi, isa_irq, pin;
-    struct hvm_vioapic *vioapic;
+    unsigned int gsi, isa_irq;
+    int mask;
     uint8_t pic_imr;
 
     if ( pt->source == PTSRC_lapic )
@@ -121,8 +121,8 @@ static int pt_irq_masked(struct periodic_time *pt)
     isa_irq = pt->irq;
     gsi = hvm_isa_irq_to_gsi(isa_irq);
     pic_imr = v->domain->arch.hvm_domain.vpic[isa_irq >> 3].imr;
-    vioapic = gsi_vioapic(v->domain, gsi, &pin);
-    if ( !vioapic )
+    mask = vioapic_get_mask(v->domain, gsi);
+    if ( mask < 0 )
     {
         dprintk(XENLOG_WARNING, "d%u: invalid GSI (%u) for platform timer\n",
                 v->domain->domain_id, gsi);
@@ -131,7 +131,7 @@ static int pt_irq_masked(struct periodic_time *pt)
     }
 
     return (((pic_imr & (1 << (isa_irq & 7))) || !vlapic_accept_pic_intr(v)) &&
-            vioapic->redirtbl[pin].fields.mask);
+            mask);
 }
 
 static void pt_lock(struct periodic_time *pt)
xen/include/asm-x86/hvm/vioapic.h +3 -3
index 2ceb60eaef..07fcd229e0 100644
@@ -61,13 +61,13 @@ struct hvm_vioapic {
 #define domain_vioapic(d, i) ((d)->arch.hvm_domain.vioapic[i])
 #define vioapic_domain(v) ((v)->domain)
 
-struct hvm_vioapic *gsi_vioapic(const struct domain *d, unsigned int gsi,
-                                unsigned int *pin);
-
 int vioapic_init(struct domain *d);
 void vioapic_deinit(struct domain *d);
 void vioapic_reset(struct domain *d);
 void vioapic_irq_positive_edge(struct domain *d, unsigned int irq);
 void vioapic_update_EOI(struct domain *d, u8 vector);
 
+int vioapic_get_mask(const struct domain *d, unsigned int gsi);
+int vioapic_get_vector(const struct domain *d, unsigned int gsi);
+
 #endif /* __ASM_X86_HVM_VIOAPIC_H__ */
Signature · 7 lines
2.11.0 (Apple Git-81)


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

PATCH v6 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 v5:
- Introduce vioapic_get_trigger_mode and use it in order to fetch the trigger mode of the vIO APIC pin.

Changes since v4:
- Remove the local pirq vairable in pt_irq_time_out (it was used only once).
- Change the == NULL checks to ! instead.
- Fix comments' grammar errors.
- Check whether hvm_irq_dpci is NULL instead of checking if d is the hardware domain (and add ASSERTs when appropriate).
- Make vioapic const in pt_irq_create_bind.

Changes since v3:
- Rewrite the comment in hvm_gsi_assert.
- Unconditionally set gsi_assert_count to 0 in hvm_gsi_deassert.
- In the pirq timeout function do not defer the EOI for the identity mapped case.
- Assert that the vIO APIC entry is not masked before checking the trigger mode.
- In the failure path of pt_irq_create_bind check that girq and digl are not NULL instead of relying on whether the domain is Dom0.
- In pt_irq_destroy_bind move a condition to the outer if in order to avoid code indentation.

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            |  42 ++++++++
 xen/arch/x86/hvm/vioapic.c        |  11 ++
 xen/drivers/passthrough/io.c      | 216 +++++++++++++++++++++++++++++---------
 xen/include/asm-x86/hvm/vioapic.h |   1 +
 xen/include/xen/hvm/irq.h         |   6 ++
 5 files changed, 224 insertions(+), 52 deletions(-)
xen/arch/x86/hvm/irq.c +42 -0
index 86255847a6..e425df913c 100644
@@ -126,6 +126,48 @@ 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 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. As we don't use that bitmap
+     * for the hardware domain, 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);
+    hvm_irq->gsi_assert_count[gsi] = 0;
+    spin_unlock(&d->arch.hvm_domain.irq_lock);
+}
+
 void hvm_isa_irq_assert(
     struct domain *d, unsigned int isa_irq)
 {
xen/arch/x86/hvm/vioapic.c +11 -0
index f2895cf57c..7e06899738 100644
@@ -498,6 +498,17 @@ int vioapic_get_vector(struct domain *d, unsigned int gsi)
     return vioapic->redirtbl[pin].fields.vector;
 }
 
+int vioapic_get_trigger_mode(struct domain *d, unsigned int gsi)
+{
+    unsigned int pin;
+    const struct hvm_vioapic *vioapic = gsi_vioapic(d, gsi, &pin);
+
+    if ( !vioapic )
+        return -EINVAL;
+
+    return vioapic->redirtbl[pin].fields.trig_mode;
+}
+
 static int ioapic_save(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_vioapic *s;
xen/drivers/passthrough/io.c +164 -52

320 lines not on this page · raw message

xen/include/asm-x86/hvm/vioapic.h +1 -0
index 5028bdcc48..74b4ca4670 100644
@@ -69,5 +69,6 @@ void vioapic_update_EOI(struct domain *d, u8 vector);
 
 int vioapic_get_mask(struct domain *d, unsigned int gsi);
 int vioapic_get_vector(struct domain *d, unsigned int gsi);
+int vioapic_get_trigger_mode(struct domain *d, unsigned int gsi);
 
 #endif /* __ASM_X86_HVM_VIOAPIC_H__ */
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
Reviewed-by on v6 2/3
#5 lore raw

Re: [PATCH v6 2/3] x86/pt: enable binding of GSIs to a PVH Dom0

xen/include/asm-x86/hvm/vioapic.h void vioapic_update_EOI(struct domain *d, u8 vector); · line 72

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 23.06.17 at 11:59, <[email protected]> wrote:
xen/include/asm-x86/hvm/vioapic.h +1 -0
@@ -69,5 +69,6 @@ void vioapic_update_EOI(struct domain *d, u8 vector);
 
 int vioapic_get_mask(struct domain *d, unsigned int gsi);
 int vioapic_get_vector(struct domain *d, unsigned int gsi);
+int vioapic_get_trigger_mode(struct domain *d, unsigned int gsi);

const here too and then

Jan

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

#6 lore raw

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

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 v6:
- Constify domain parameter of vioapic_get_trigger_mode.

Changes since v5:
- Introduce vioapic_get_trigger_mode and use it in order to fetch the trigger mode of the vIO APIC pin.

Changes since v4:
- Remove the local pirq vairable in pt_irq_time_out (it was used only once).
- Change the == NULL checks to ! instead.
- Fix comments' grammar errors.
- Check whether hvm_irq_dpci is NULL instead of checking if d is the hardware domain (and add ASSERTs when appropriate).
- Make vioapic const in pt_irq_create_bind.

Changes since v3:
- Rewrite the comment in hvm_gsi_assert.
- Unconditionally set gsi_assert_count to 0 in hvm_gsi_deassert.
- In the pirq timeout function do not defer the EOI for the identity mapped case.
- Assert that the vIO APIC entry is not masked before checking the trigger mode.
- In the failure path of pt_irq_create_bind check that girq and digl are not NULL instead of relying on whether the domain is Dom0.
- In pt_irq_destroy_bind move a condition to the outer if in order to avoid code indentation.

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            |  42 ++++++++
 xen/arch/x86/hvm/vioapic.c        |  11 ++
 xen/drivers/passthrough/io.c      | 216 +++++++++++++++++++++++++++++---------
 xen/include/asm-x86/hvm/vioapic.h |   1 +
 xen/include/xen/hvm/irq.h         |   6 ++
 5 files changed, 224 insertions(+), 52 deletions(-)
xen/arch/x86/hvm/irq.c +42 -0
index 86255847a6..e425df913c 100644
@@ -126,6 +126,48 @@ 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 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. As we don't use that bitmap
+     * for the hardware domain, 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);
+    hvm_irq->gsi_assert_count[gsi] = 0;
+    spin_unlock(&d->arch.hvm_domain.irq_lock);
+}
+
 void hvm_isa_irq_assert(
     struct domain *d, unsigned int isa_irq)
 {
xen/arch/x86/hvm/vioapic.c +11 -0
index 12912f068d..2beba45047 100644
@@ -498,6 +498,17 @@ int vioapic_get_vector(const struct domain *d, unsigned int gsi)
     return vioapic->redirtbl[pin].fields.vector;
 }
 
+int vioapic_get_trigger_mode(const struct domain *d, unsigned int gsi)
+{
+    unsigned int pin;
+    const struct hvm_vioapic *vioapic = gsi_vioapic(d, gsi, &pin);
+
+    if ( !vioapic )
+        return -EINVAL;
+
+    return vioapic->redirtbl[pin].fields.trig_mode;
+}
+
 static int ioapic_save(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_vioapic *s;
xen/drivers/passthrough/io.c +164 -52

320 lines not on this page · raw message

xen/include/asm-x86/hvm/vioapic.h +1 -0
index 07fcd229e0..138d2c0b35 100644
@@ -69,5 +69,6 @@ void vioapic_update_EOI(struct domain *d, u8 vector);
 
 int vioapic_get_mask(const struct domain *d, unsigned int gsi);
 int vioapic_get_vector(const struct domain *d, unsigned int gsi);
+int vioapic_get_trigger_mode(const struct domain *d, unsigned int gsi);
 
 #endif /* __ASM_X86_HVM_VIOAPIC_H__ */
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
#7 lore raw

PATCH v6 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 v4:
- s/d/currd/.

Changes since v3:
- Setup the binding after writing the modified RTE fields back into the vIO APIC struct, or else pt_irq_create_bind will fetch the wrong trigger mode.

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 7e06899738..b0ca352d17 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 *currd = 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(currd));
+
+    /* 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(currd, 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(currd, &pt_irq_bind);
+    if ( ret )
+    {
+        gprintk(XENLOG_WARNING, "vioapic: error binding GSI %u: %d\n",
+                gsi, ret);
+        spin_lock(&currd->event_lock);
+        unmap_domain_pirq(currd, pirq);
+        spin_unlock(&currd->event_lock);
+    }
+    pcidevs_unlock();
+
+    return ret;
+}
+
 static void vioapic_write_redirent(
     struct hvm_vioapic *vioapic, unsigned int idx,
     int top_word, uint32_t val)
@@ -190,6 +236,20 @@ static void vioapic_write_redirent(
 
     *pent = ent;
 
+    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. */
+            pent->fields.mask = 1;
+            unmasked = 0;
+        }
+    }
+
     if ( gsi == 0 )
     {
         vlapic_adjust_i8259_target(d);
Signature · 7 lines
2.11.0 (Apple Git-81)


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