Skip to contentSkip to conversation

xen/pt: Fix a xen passthrough failure

PATCH Superseded Zhao Yan 3 participants 6 messages Dec 3, 2018 – Dec 4, 2018

lore
Share & tools
lore

Zhao Yan

author
#0 lore raw

PATCH v2 1/1 xen/pt: Fix a xen passthrough failure

For some pci device, even its PCI_INTERRUPT_PIN is not 0, it actually doesn't support INTx mode, so its machine irq read from host sysfs is 0. In that case, report PCI_INTERRUPT_PIN as 0 to guest and let passthrough continue.

v2: fix some coding style issue

Cc Roger Pau Monné <[email protected]>
Cc Jan Beulich <[email protected]>
---
 hw/xen/xen_pt.c             | 5 +++++
 hw/xen/xen_pt_config_init.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
hw/xen/xen_pt.c +5 -0
index f1f3a3727c..d601c9979c 100644
@@ -847,6 +847,11 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
     }
 
     machine_irq = s->real_device.irq;
+    if (machine_irq == 0) {
+        XEN_PT_LOG(d, "machine irq is 0\n");
+        goto out;
+    }
+
     rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq);
     if (rc < 0) {
         error_setg_errno(errp, errno, "Mapping machine irq %u to"
hw/xen/xen_pt_config_init.c +7 -1
index 47f9010c75..1007b6c977 100644
@@ -300,7 +300,13 @@ static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s,
                                   XenPTRegInfo *reg, uint32_t real_offset,
                                   uint32_t *data)
 {
-    *data = xen_pt_pci_read_intx(s);
+    if (s->real_device.irq)
+        *data = xen_pt_pci_read_intx(s);
+    else {
+        XEN_PT_LOG(&s->dev,
+            "machine irq is 0, init guest PCI_INTERRUPT_PIN to 0\n");
+        *data = 0;
+    }
     return 0;
 }
 
Signature · 1 line
2.17.1
#1 lore raw

Hello,

Thanks for the patch.

The subject should be more descriptive, "Fix a xen passthrough failure" is too generic. How about: "allow passthrough of devices with bogus interrupt pin" or something similar.

Quoted 6 lines · Zhao Yan

For some pci device, even its PCI_INTERRUPT_PIN is not 0, it actually doesn't support INTx mode, so its machine irq read from host sysfs is 0. In that case, report PCI_INTERRUPT_PIN as 0 to guest and let passthrough continue.

v2: fix some coding style issue

The changelog between versions should be below the '---'.

Quoted 14 lines
Cc Roger Pau Monné <[email protected]>
Cc Jan Beulich <[email protected]>
---
 hw/xen/xen_pt.c             | 5 +++++
 hw/xen/xen_pt_config_init.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
hw/xen/xen_pt.c +0 -0
index f1f3a3727c..d601c9979c 100644

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 851

Quoted 5 lines
hw/xen/xen_pt.c +2 -0
@@ -847,6 +847,11 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
     }
 
     machine_irq = s->real_device.irq;
+    if (machine_irq == 0) {
+        XEN_PT_LOG(d, "machine irq is 0\n");

I would maybe consider disabling INTX assertion here on the command register.

Quoted 11 lines
hw/xen/xen_pt.c +3 -0
+        goto out;
+    }
+
     rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq);
     if (rc < 0) {
         error_setg_errno(errp, errno, "Mapping machine irq %u to"
hw/xen/xen_pt_config_init.c +0 -0
index 47f9010c75..1007b6c977 100644

hw/xen/xen_pt_config_init.c static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s, · line 308

Quoted 10 lines
hw/xen/xen_pt_config_init.c +6 -1
@@ -300,7 +300,13 @@ static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s,
                                   XenPTRegInfo *reg, uint32_t real_offset,
                                   uint32_t *data)
 {
-    *data = xen_pt_pci_read_intx(s);
+    if (s->real_device.irq)
+        *data = xen_pt_pci_read_intx(s);
+    else {
+        XEN_PT_LOG(&s->dev,
+            "machine irq is 0, init guest PCI_INTERRUPT_PIN to 0\n");
+        *data = 0;

The default value for the register is already zero, so you could drop the else branch AFAICT.

Thanks, Roger.

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

author
#2 lore raw
Quoted 7 lines · Roger Pau Monné

Hello,

Thanks for the patch.

The subject should be more descriptive, "Fix a xen passthrough failure" is too generic. How about: "allow passthrough of devices with bogus interrupt pin" or something similar.

right, thanks for your suggestion. I'll change the subject to this one.

Quoted 11 lines · Zhao Yan
Quoted 6 lines

For some pci device, even its PCI_INTERRUPT_PIN is not 0, it actually doesn't support INTx mode, so its machine irq read from host sysfs is 0. In that case, report PCI_INTERRUPT_PIN as 0 to guest and let passthrough continue.

v2: fix some coding style issue

The changelog between versions should be below the '---'.

got it. thanks :)

Quoted 16 lines
Quoted 16 lines
Cc Roger Pau Monné <[email protected]>
Cc Jan Beulich <[email protected]>
---
 hw/xen/xen_pt.c             | 5 +++++
 hw/xen/xen_pt_config_init.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
hw/xen/xen_pt.c +0 -0
index f1f3a3727c..d601c9979c 100644
@@ -847,6 +847,11 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
     }
 
Quoted 7 lines

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 851

Quoted 3 lines
hw/xen/xen_pt.c +2 -0
     machine_irq = s->real_device.irq;
+    if (machine_irq == 0) {
+        XEN_PT_LOG(d, "machine irq is 0\n");

I would maybe consider disabling INTX assertion here on the command register.

ok, I'll add that.
Actually I was vacillating on whether to add the disabling of INTx assertion, as I thought PCI_INTERRUPT_PIN was already reported 0. But adding the disabling is better.

Quoted 16 lines
Quoted 16 lines
hw/xen/xen_pt.c +3 -0
+        goto out;
+    }
+
     rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq);
     if (rc < 0) {
         error_setg_errno(errp, errno, "Mapping machine irq %u to"
hw/xen/xen_pt_config_init.c +1 -1
index 47f9010c75..1007b6c977 100644
@@ -300,7 +300,13 @@ static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s,
                                   XenPTRegInfo *reg, uint32_t real_offset,
                                   uint32_t *data)
 {
-    *data = xen_pt_pci_read_intx(s);
+    if (s->real_device.irq)
Quoted 8 lines

hw/xen/xen_pt_config_init.c static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s, · line 308

Quoted 5 lines
hw/xen/xen_pt_config_init.c +5 -0
+        *data = xen_pt_pci_read_intx(s);
+    else {
+        XEN_PT_LOG(&s->dev,
+            "machine irq is 0, init guest PCI_INTERRUPT_PIN to 0\n");
+        *data = 0;

The default value for the register is already zero, so you could drop the else branch AFAICT.

ok, I'll drop the else branch. thanks for your review :)

Quoted 1 line

Thanks, Roger.

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

author
#3 lore raw
In reply to Roger Pau Monné
Quoted 7 lines · Roger Pau Monné

Hello,

Thanks for the patch.

The subject should be more descriptive, "Fix a xen passthrough failure" is too generic. How about: "allow passthrough of devices with bogus interrupt pin" or something similar.

right, thanks for your suggestion. I'll change the subject to this one.

Quoted 11 lines · Zhao Yan
Quoted 6 lines

For some pci device, even its PCI_INTERRUPT_PIN is not 0, it actually doesn't support INTx mode, so its machine irq read from host sysfs is 0. In that case, report PCI_INTERRUPT_PIN as 0 to guest and let passthrough continue.

v2: fix some coding style issue

The changelog between versions should be below the '---'.

got it. thanks :)

Quoted 16 lines
Quoted 16 lines
Cc Roger Pau Monné <[email protected]>
Cc Jan Beulich <[email protected]>
---
 hw/xen/xen_pt.c             | 5 +++++
 hw/xen/xen_pt_config_init.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
hw/xen/xen_pt.c +0 -0
index f1f3a3727c..d601c9979c 100644
@@ -847,6 +847,11 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
     }
 
Quoted 7 lines

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 851

Quoted 3 lines
hw/xen/xen_pt.c +2 -0
     machine_irq = s->real_device.irq;
+    if (machine_irq == 0) {
+        XEN_PT_LOG(d, "machine irq is 0\n");

I would maybe consider disabling INTX assertion here on the command register.

ok, I'll add that.
Actually I was vacillating on whether to add the disabling of INTx assertion, as I thought PCI_INTERRUPT_PIN was already reported 0. But adding the disabling is better.

Quoted 16 lines
Quoted 16 lines
hw/xen/xen_pt.c +3 -0
+        goto out;
+    }
+
     rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq);
     if (rc < 0) {
         error_setg_errno(errp, errno, "Mapping machine irq %u to"
hw/xen/xen_pt_config_init.c +1 -1
index 47f9010c75..1007b6c977 100644
@@ -300,7 +300,13 @@ static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s,
                                   XenPTRegInfo *reg, uint32_t real_offset,
                                   uint32_t *data)
 {
-    *data = xen_pt_pci_read_intx(s);
+    if (s->real_device.irq)
Quoted 8 lines

hw/xen/xen_pt_config_init.c static int xen_pt_irqpin_reg_init(XenPCIPassthroughState *s, · line 308

Quoted 5 lines
hw/xen/xen_pt_config_init.c +5 -0
+        *data = xen_pt_pci_read_intx(s);
+    else {
+        XEN_PT_LOG(&s->dev,
+            "machine irq is 0, init guest PCI_INTERRUPT_PIN to 0\n");
+        *data = 0;

The default value for the register is already zero, so you could drop the else branch AFAICT.

ok, I'll drop the else branch. thanks for your review :)

Quoted 1 line

Thanks, Roger.

#4 lore raw
In reply to Zhao Yan
Quoted 4 lines · Zhao Yan

For some pci device, even its PCI_INTERRUPT_PIN is not 0, it actually doesn't support INTx mode, so its machine irq read from host sysfs is 0. In that case, report PCI_INTERRUPT_PIN as 0 to guest and let passthrough continue.

What causes this problem?  It it a non-PCI compliant device?  Is it a device which has legacy lines prohibited?

~Andrew

author
#5 lore raw

hi Andrew,

It's a pci device that does not support legacy intx mode, but it accidently reports PCI_INTERRUPT_PIN as 1, which should be 0 instead.
So, in dom0, the machine irq is 0, which will cause later xc_physdev_map_pirq() fail and passthrough failure.

Therefore, we treat this case as PCI_INTERRUPT_PIN is 0 and report to guest the right value (0) of PCI_INTERRUPT_PIN.
Then in guest, it's able to use msi mode and function normally.

Quoted 10 lines · Andrew Cooper
Quoted 4 lines · Zhao Yan

For some pci device, even its PCI_INTERRUPT_PIN is not 0, it actually doesn't support INTx mode, so its machine irq read from host sysfs is 0. In that case, report PCI_INTERRUPT_PIN as 0 to guest and let passthrough continue.

What causes this problem?  It it a non-PCI compliant device?  Is it a device which has legacy lines prohibited?

~Andrew

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