Skip to contentSkip to conversation

vpci/msi: fix updating already bound MSI interrupts

PATCH Superseded Roger Pau Monne 3 participants 13 messages May 8, 2018 – May 14, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vpci/msi: fix updating already bound MSI interrupts

Hello,

There's a bug in current vpci code for MSI emulation when updating an already bound interrupt. The code will disable and enable the interrupt in order to update the binding, which calls unmap_domain_pirq that disables the global MSI enable flag in the control register.

In order to fix this incorrect behavior introduce a new update helper that should be used to update the bindings of an already enabled group of MSI interrupts.

Thanks, Roger.

Roger Pau Monne (2):
vpci/msi: split code to bind pirq
vpci/msi: fix update of bound MSI interrupts

 xen/arch/x86/hvm/vmsi.c | 96 +++++++++++++++++++++++++++++------------
 xen/drivers/vpci/msi.c  |  3 +-
 xen/include/xen/vpci.h  |  2 +
 3 files changed, 71 insertions(+), 30 deletions(-)
Signature · 7 lines
2.17.0


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

PATCH 1/2 vpci/msi: split code to bind pirq

And put it in a separate update function. This is required in order to improve binding of MSI PIRQs when using vPCI.

No functional change.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/hvm/vmsi.c | 73 +++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 28 deletions(-)
xen/arch/x86/hvm/vmsi.c +45 -28
index 900d4f67d4..6e19851439 100644
@@ -663,6 +663,42 @@ void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev,
     vpci_mask_pirq(pdev->domain, msi->arch.pirq + entry, mask);
 }
 
+static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
+                           uint64_t address, unsigned int vectors,
+                           unsigned int pirq, uint32_t mask)
+{
+    unsigned int i;
+
+    ASSERT(pcidevs_locked());
+
+    for ( i = 0; i < vectors; i++ )
+    {
+        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
+        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
+        struct xen_domctl_bind_pt_irq bind = {
+            .machine_irq = pirq + i,
+            .irq_type = PT_IRQ_TYPE_MSI,
+            .u.msi.gvec = (vector & ~vector_mask) |
+                          ((vector + i) & vector_mask),
+            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
+        };
+        int rc = pt_irq_create_bind(pdev->domain, &bind);
+
+        if ( rc )
+        {
+            gdprintk(XENLOG_ERR,
+                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
+                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                     PCI_FUNC(pdev->devfn), pirq + i, rc);
+            while ( bind.machine_irq-- )
+                pt_irq_destroy_bind(pdev->domain, &bind);
+            return rc;
+        }
+    }
+
+    return 0;
+}
+
 static int vpci_msi_enable(const struct pci_dev *pdev, uint32_t data,
                            uint64_t address, unsigned int nr,
                            paddr_t table_base, uint32_t mask)
@@ -674,7 +710,7 @@ static int vpci_msi_enable(const struct pci_dev *pdev, uint32_t data,
         .table_base = table_base,
         .entry_nr = nr,
     };
-    unsigned int i, vectors = table_base ? 1 : nr;
+    unsigned vectors = table_base ? 1 : nr;
     int rc, pirq = INVALID_PIRQ;
 
     /* Get a PIRQ. */
@@ -690,36 +726,17 @@ static int vpci_msi_enable(const struct pci_dev *pdev, uint32_t data,
         return rc;
     }
 
-    for ( i = 0; i < vectors; i++ )
+    pcidevs_lock();
+    rc = vpci_msi_update(pdev, data, address, vectors, pirq, mask);
+    if ( rc )
     {
-        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
-        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
-        struct xen_domctl_bind_pt_irq bind = {
-            .machine_irq = pirq + i,
-            .irq_type = PT_IRQ_TYPE_MSI,
-            .u.msi.gvec = (vector & ~vector_mask) |
-                          ((vector + i) & vector_mask),
-            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
-        };
-
-        pcidevs_lock();
-        rc = pt_irq_create_bind(pdev->domain, &bind);
-        if ( rc )
-        {
-            gdprintk(XENLOG_ERR,
-                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
-                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
-                     PCI_FUNC(pdev->devfn), pirq + i, rc);
-            while ( bind.machine_irq-- )
-                pt_irq_destroy_bind(pdev->domain, &bind);
-            spin_lock(&pdev->domain->event_lock);
-            unmap_domain_pirq(pdev->domain, pirq);
-            spin_unlock(&pdev->domain->event_lock);
-            pcidevs_unlock();
-            return rc;
-        }
+        spin_lock(&pdev->domain->event_lock);
+        unmap_domain_pirq(pdev->domain, pirq);
+        spin_unlock(&pdev->domain->event_lock);
         pcidevs_unlock();
+        return rc;
     }
+    pcidevs_unlock();
 
     return pirq;
 }
Signature · 7 lines
2.17.0


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

Re: [PATCH 1/2] vpci/msi: split code to bind pirq

Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +19 -0
@@ -663,6 +663,42 @@ void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev,
     vpci_mask_pirq(pdev->domain, msi->arch.pirq + entry, mask);
 }
 
+static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
+                           uint64_t address, unsigned int vectors,
+                           unsigned int pirq, uint32_t mask)
+{
+    unsigned int i;
+
+    ASSERT(pcidevs_locked());
+
+    for ( i = 0; i < vectors; i++ )
+    {
+        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
+        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
+        struct xen_domctl_bind_pt_irq bind = {
+            .machine_irq = pirq + i,
+            .irq_type = PT_IRQ_TYPE_MSI,
+            .u.msi.gvec = (vector & ~vector_mask) |
+                          ((vector + i) & vector_mask),
+            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
+        };

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev, · line 694

Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +10 -0
+        int rc = pt_irq_create_bind(pdev->domain, &bind);
+
+        if ( rc )
+        {
+            gdprintk(XENLOG_ERR,
+                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
+                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                     PCI_FUNC(pdev->devfn), pirq + i, rc);
+            while ( bind.machine_irq-- )
+                pt_irq_destroy_bind(pdev->domain, &bind);

I realize this is just code movement, but is this while() correct? I think it can only be correct if pirq (which bind.machine_irq gets initialized from) was always zero, yet that doesn't look to be the case.

If you agree, I'd prefer fixed code to be moved (read: wants a prereq patch), or for the fix to be applied while moving the code (suitably reasoned about in the description).

Jan

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

#3 lore raw

Re: [PATCH 1/2] vpci/msi: split code to bind pirq

Quoted 41 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +19 -0
@@ -663,6 +663,42 @@ void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev,
     vpci_mask_pirq(pdev->domain, msi->arch.pirq + entry, mask);
 }
 
+static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
+                           uint64_t address, unsigned int vectors,
+                           unsigned int pirq, uint32_t mask)
+{
+    unsigned int i;
+
+    ASSERT(pcidevs_locked());
+
+    for ( i = 0; i < vectors; i++ )
+    {
+        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
+        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
+        struct xen_domctl_bind_pt_irq bind = {
+            .machine_irq = pirq + i,
+            .irq_type = PT_IRQ_TYPE_MSI,
+            .u.msi.gvec = (vector & ~vector_mask) |
+                          ((vector + i) & vector_mask),
+            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
+        };

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev, · line 694

Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +10 -0
+        int rc = pt_irq_create_bind(pdev->domain, &bind);
+
+        if ( rc )
+        {
+            gdprintk(XENLOG_ERR,
+                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
+                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                     PCI_FUNC(pdev->devfn), pirq + i, rc);
+            while ( bind.machine_irq-- )
+                pt_irq_destroy_bind(pdev->domain, &bind);

I realize this is just code movement, but is this while() correct? I think it can only be correct if pirq (which bind.machine_irq gets initialized from) was always zero, yet that doesn't look to be the case.

Quoted 3 lines

If you agree, I'd prefer fixed code to be moved (read: wants a prereq patch), or for the fix to be applied while moving the code (suitably reasoned about in the description).

Right, this should be:

while ( bind.machine_irq-- >= pirq )

    pt_irq_destroy_bind(pdev->domain, &bind);

Will fix before moving the code.

Thanks, Roger.

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

#4 lore raw

Re: [PATCH 1/2] vpci/msi: split code to bind pirq

Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 16:15, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +0 -0
@@ -663,6 +663,42 @@ void vpci_msi_arch_mask(struct vpci_msi *msi, const 

struct pci_dev *pdev,

Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/vmsi.c +23 -0
     vpci_mask_pirq(pdev->domain, msi->arch.pirq + entry, mask);
 }
 
+static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
+                           uint64_t address, unsigned int vectors,
+                           unsigned int pirq, uint32_t mask)
+{
+    unsigned int i;
+
+    ASSERT(pcidevs_locked());
+
+    for ( i = 0; i < vectors; i++ )
+    {
+        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
+        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
+        struct xen_domctl_bind_pt_irq bind = {
+            .machine_irq = pirq + i,
+            .irq_type = PT_IRQ_TYPE_MSI,
+            .u.msi.gvec = (vector & ~vector_mask) |
+                          ((vector + i) & vector_mask),
+            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
+        };
+        int rc = pt_irq_create_bind(pdev->domain, &bind);
+
+        if ( rc )
+        {
Quoted 8 lines

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev, · line 694

Quoted 6 lines
xen/arch/x86/hvm/vmsi.c +6 -0
+            gdprintk(XENLOG_ERR,
+                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
+                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                     PCI_FUNC(pdev->devfn), pirq + i, rc);
+            while ( bind.machine_irq-- )
+                pt_irq_destroy_bind(pdev->domain, &bind);

I realize this is just code movement, but is this while() correct? I think

it

Quoted 3 lines

can only be correct if pirq (which bind.machine_irq gets initialized from) was always zero, yet that doesn't look to be the case.

Quoted 8 lines
Quoted 3 lines

If you agree, I'd prefer fixed code to be moved (read: wants a prereq patch), or for the fix to be applied while moving the code (suitably reasoned about in the description).

Right, this should be:

while ( bind.machine_irq-- >= pirq )

    pt_irq_destroy_bind(pdev->domain, &bind);

">" you presumably mean, due to the post-decrement?

Jan

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

#5 lore raw

Re: [PATCH 1/2] vpci/msi: split code to bind pirq

Quoted 49 lines · Jan Beulich
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 16:15, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +0 -0
@@ -663,6 +663,42 @@ void vpci_msi_arch_mask(struct vpci_msi *msi, const 

struct pci_dev *pdev,

Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/vmsi.c +23 -0
     vpci_mask_pirq(pdev->domain, msi->arch.pirq + entry, mask);
 }
 
+static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
+                           uint64_t address, unsigned int vectors,
+                           unsigned int pirq, uint32_t mask)
+{
+    unsigned int i;
+
+    ASSERT(pcidevs_locked());
+
+    for ( i = 0; i < vectors; i++ )
+    {
+        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
+        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
+        struct xen_domctl_bind_pt_irq bind = {
+            .machine_irq = pirq + i,
+            .irq_type = PT_IRQ_TYPE_MSI,
+            .u.msi.gvec = (vector & ~vector_mask) |
+                          ((vector + i) & vector_mask),
+            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
+        };
+        int rc = pt_irq_create_bind(pdev->domain, &bind);
+
+        if ( rc )
+        {
Quoted 8 lines

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev, · line 694

Quoted 6 lines
xen/arch/x86/hvm/vmsi.c +6 -0
+            gdprintk(XENLOG_ERR,
+                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
+                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                     PCI_FUNC(pdev->devfn), pirq + i, rc);
+            while ( bind.machine_irq-- )
+                pt_irq_destroy_bind(pdev->domain, &bind);

I realize this is just code movement, but is this while() correct? I think

it

Quoted 6 lines

can only be correct if pirq (which bind.machine_irq gets initialized from) was always zero, yet that doesn't look to be the case.

If you agree, I'd prefer fixed code to be moved (read: wants a prereq patch), or for the fix to be applied while moving the code (suitably reasoned about in the description).

Quoted 6 lines
Quoted 4 lines

Right, this should be:

while ( bind.machine_irq-- >= pirq )

    pt_irq_destroy_bind(pdev->domain, &bind);

">" you presumably mean, due to the post-decrement?

Ended up doing --bind.machine_irq >= pirq, because it seemed clearer IMO.

Roger.

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

#6 lore raw

Re: [PATCH 1/2] vpci/msi: split code to bind pirq

Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 17:00, <[email protected]> wrote:
Quoted 51 lines · Jan Beulich
Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 16:15, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +0 -0
@@ -663,6 +663,42 @@ void vpci_msi_arch_mask(struct vpci_msi *msi, const 

struct pci_dev *pdev,

Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/vmsi.c +23 -0
     vpci_mask_pirq(pdev->domain, msi->arch.pirq + entry, mask);
 }
 
+static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
+                           uint64_t address, unsigned int vectors,
+                           unsigned int pirq, uint32_t mask)
+{
+    unsigned int i;
+
+    ASSERT(pcidevs_locked());
+
+    for ( i = 0; i < vectors; i++ )
+    {
+        uint8_t vector = MASK_EXTR(data, MSI_DATA_VECTOR_MASK);
+        uint8_t vector_mask = 0xff >> (8 - fls(vectors) + 1);
+        struct xen_domctl_bind_pt_irq bind = {
+            .machine_irq = pirq + i,
+            .irq_type = PT_IRQ_TYPE_MSI,
+            .u.msi.gvec = (vector & ~vector_mask) |
+                          ((vector + i) & vector_mask),
+            .u.msi.gflags = msi_gflags(data, address, (mask >> i) & 1),
+        };
+        int rc = pt_irq_create_bind(pdev->domain, &bind);
+
+        if ( rc )
+        {
Quoted 8 lines

xen/arch/x86/hvm/vmsi.c void vpci_msi_arch_mask(struct vpci_msi *msi, const struct pci_dev *pdev, · line 694

Quoted 6 lines
xen/arch/x86/hvm/vmsi.c +6 -0
+            gdprintk(XENLOG_ERR,
+                     "%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
+                     pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                     PCI_FUNC(pdev->devfn), pirq + i, rc);
+            while ( bind.machine_irq-- )
+                pt_irq_destroy_bind(pdev->domain, &bind);

I realize this is just code movement, but is this while() correct? I think

it

Quoted 6 lines

can only be correct if pirq (which bind.machine_irq gets initialized from) was always zero, yet that doesn't look to be the case.

If you agree, I'd prefer fixed code to be moved (read: wants a prereq patch), or for the fix to be applied while moving the code (suitably reasoned about in the description).

Right, this should be:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

while ( bind.machine_irq-- >= pirq )

    pt_irq_destroy_bind(pdev->domain, &bind);

">" you presumably mean, due to the post-decrement?

Ended up doing --bind.machine_irq >= pirq, because it seemed clearer IMO.

Please don't: Even if in practice pirq can't be zero (I think), your variant would degenerate into an infinite loop in that case.

Jan

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

#7 lore raw

PATCH 2/2 vpci/msi: fix update of bound MSI interrupts

In reply to Roger Pau Monne

Current update process of already bound MSI interrupts is wrong because unmap_domain_pirq calls pci_disable_msi, which disables MSI interrupts on the device. On the other hand map_domain_pirq doesn't enable MSI, so the current update process of already enabled MSI entries is wrong because MSI control bit will be disabled by unmap_domain_pirq and not re-enabled by map_domain_pirq.

In order to fix this avoid unmapping the PIRQs and just update the binding of the PIRQ. A new arch helper to do that is introduced.

Note that MSI-X is not affected because unmap_domain_pirq only disables the MSI enable control bit for the MSI case, for MSI-X the bit is left untouched by unmap_domain_pirq.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/hvm/vmsi.c | 23 +++++++++++++++++++++++
 xen/drivers/vpci/msi.c  |  3 +--
 xen/include/xen/vpci.h  |  2 ++
 3 files changed, 26 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmsi.c +23 -0
index 6e19851439..8f9f84a6f3 100644
@@ -699,6 +699,29 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
     return 0;
 }
 
+int vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev)
+{
+    int rc;
+
+    ASSERT(msi->arch.pirq != INVALID_PIRQ);
+
+    pcidevs_lock();
+    rc = vpci_msi_update(pdev, msi->data, msi->address, msi->vectors,
+                         msi->arch.pirq, msi->mask);
+    if ( rc )
+    {
+        spin_lock(&pdev->domain->event_lock);
+        unmap_domain_pirq(pdev->domain, msi->arch.pirq);
+        spin_unlock(&pdev->domain->event_lock);
+        pcidevs_unlock();
+        msi->arch.pirq = INVALID_PIRQ;
+        return rc;
+    }
+    pcidevs_unlock();
+
+    return 0;
+}
+
 static int vpci_msi_enable(const struct pci_dev *pdev, uint32_t data,
                            uint64_t address, unsigned int nr,
                            paddr_t table_base, uint32_t mask)
xen/drivers/vpci/msi.c +1 -2
index ad26c38a92..8f15ad7bf2 100644
@@ -87,8 +87,7 @@ static void update_msi(const struct pci_dev *pdev, struct vpci_msi *msi)
     if ( !msi->enabled )
         return;
 
-    vpci_msi_arch_disable(msi, pdev);
-    if ( vpci_msi_arch_enable(msi, pdev, msi->vectors) )
+    if ( vpci_msi_arch_update(msi, pdev) )
         msi->enabled = false;
 }
 
xen/include/xen/vpci.h +2 -0
index 72d2225a97..af2b8580ee 100644
@@ -159,6 +159,8 @@ int __must_check vpci_msi_arch_enable(struct vpci_msi *msi,
                                       const struct pci_dev *pdev,
                                       unsigned int vectors);
 void vpci_msi_arch_disable(struct vpci_msi *msi, const struct pci_dev *pdev);
+int __must_check vpci_msi_arch_update(struct vpci_msi *msi,
+                                      const struct pci_dev *pdev);
 void vpci_msi_arch_init(struct vpci_msi *msi);
 void vpci_msi_arch_print(const struct vpci_msi *msi);
 
Signature · 7 lines
2.17.0


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

Re: [PATCH 2/2] vpci/msi: fix update of bound MSI interrupts

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +3 -0
@@ -699,6 +699,29 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
     return 0;
 }
 
+int vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev)
+{
+    int rc;

xen/arch/x86/hvm/vmsi.c static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data, · line 714

Quoted 10 lines
xen/arch/x86/hvm/vmsi.c +10 -0
+
+    ASSERT(msi->arch.pirq != INVALID_PIRQ);
+
+    pcidevs_lock();
+    rc = vpci_msi_update(pdev, msi->data, msi->address, msi->vectors,
+                         msi->arch.pirq, msi->mask);
+    if ( rc )
+    {
+        spin_lock(&pdev->domain->event_lock);
+        unmap_domain_pirq(pdev->domain, msi->arch.pirq);

This looks quite undesirable - a failed update should leave the interrupt in its prior state rather than unbinding it. Is that overly difficult to achieve? At the very least for single-vector-MSI it looks to me as if nothing needed doing here at all to have just this net effect. If so, that special case is probably worthwhile to have, together with a comment on why the same isn't feasible / desirable for the multi vector case.

Jan

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

#9 lore raw

Re: [PATCH 2/2] vpci/msi: fix update of bound MSI interrupts

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +0 -0
@@ -699,6 +699,29 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
     return 0;
 }
 
Quoted 16 lines

xen/arch/x86/hvm/vmsi.c static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data, · line 714

Quoted 13 lines
xen/arch/x86/hvm/vmsi.c +13 -0
+int vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev)
+{
+    int rc;
+
+    ASSERT(msi->arch.pirq != INVALID_PIRQ);
+
+    pcidevs_lock();
+    rc = vpci_msi_update(pdev, msi->data, msi->address, msi->vectors,
+                         msi->arch.pirq, msi->mask);
+    if ( rc )
+    {
+        spin_lock(&pdev->domain->event_lock);
+        unmap_domain_pirq(pdev->domain, msi->arch.pirq);

This looks quite undesirable - a failed update should leave the interrupt in its prior state rather than unbinding it. Is that overly difficult to achieve?

Oh, TBH I would expect that writing an invalid data or address fields will disable MSI instead of keep using the old values. I'm not sure I see the reason to keep using the old values, certainly that could make something else go very wonky inside of the guest itself.

Thanks, Roger.

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

#10 lore raw

Re: [PATCH 2/2] vpci/msi: fix update of bound MSI interrupts

Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 16:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.05.18 at 11:25, <[email protected]> wrote:
xen/arch/x86/hvm/vmsi.c +0 -0
@@ -699,6 +699,29 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,
     return 0;
 }
 
Quoted 16 lines

xen/arch/x86/hvm/vmsi.c static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data, · line 714

Quoted 13 lines
xen/arch/x86/hvm/vmsi.c +13 -0
+int vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev)
+{
+    int rc;
+
+    ASSERT(msi->arch.pirq != INVALID_PIRQ);
+
+    pcidevs_lock();
+    rc = vpci_msi_update(pdev, msi->data, msi->address, msi->vectors,
+                         msi->arch.pirq, msi->mask);
+    if ( rc )
+    {
+        spin_lock(&pdev->domain->event_lock);
+        unmap_domain_pirq(pdev->domain, msi->arch.pirq);

This looks quite undesirable - a failed update should leave the interrupt in its prior state rather than unbinding it. Is that overly difficult to achieve?

Quoted 4 lines

Oh, TBH I would expect that writing an invalid data or address fields will disable MSI instead of keep using the old values. I'm not sure I see the reason to keep using the old values, certainly that could make something else go very wonky inside of the guest itself.

Yeah, true, neither is proper behavior comparing to a simple config space write (which can't really fail). Crashing the guest may be a more appropriate action here then. But with what you say I'd also be fine if you kept it as is.

Jan

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

#11 lore raw
In reply to Roger Pau Monne
Quoted 13 lines · Roger Pau Monne

Hello,

There's a bug in current vpci code for MSI emulation when updating an already bound interrupt. The code will disable and enable the interrupt in order to update the binding, which calls unmap_domain_pirq that disables the global MSI enable flag in the control register.

In order to fix this incorrect behavior introduce a new update helper that should be used to update the bindings of an already enabled group of MSI interrupts.

Thanks, Roger.

Quoted 9 lines

Roger Pau Monne (2):
vpci/msi: split code to bind pirq
vpci/msi: fix update of bound MSI interrupts

 xen/arch/x86/hvm/vmsi.c | 96 +++++++++++++++++++++++++++++------------
 xen/drivers/vpci/msi.c  |  3 +-
 xen/include/xen/vpci.h  |  2 +
 3 files changed, 71 insertions(+), 30 deletions(-)

I guess this is 4.11 material?

Juergen

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

#12 lore raw
Quoted 18 lines · Juergen Gross
Quoted 17 lines · Roger Pau Monne

Hello,

There's a bug in current vpci code for MSI emulation when updating an already bound interrupt. The code will disable and enable the interrupt in order to update the binding, which calls unmap_domain_pirq that disables the global MSI enable flag in the control register.

In order to fix this incorrect behavior introduce a new update helper that should be used to update the bindings of an already enabled group of MSI interrupts.

Thanks, Roger.

Roger Pau Monne (2):
vpci/msi: split code to bind pirq
vpci/msi: fix update of bound MSI interrupts

Quoted 7 lines
Quoted 5 lines
 xen/arch/x86/hvm/vmsi.c | 96 +++++++++++++++++++++++++++++------------
 xen/drivers/vpci/msi.c  |  3 +-
 xen/include/xen/vpci.h  |  2 +
 3 files changed, 71 insertions(+), 30 deletions(-)

I guess this is 4.11 material?

Hm, I think so given PVH Dom0 is experimental. OTOH this changes are to code used exclusively by PVH Dom0, so there's no chance of breaking anything else. Let's see what the maintainers think and I can Cc you later if required.

Thanks, Roger.

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