Skip to contentSkip to conversation

Decouple Xen-HVM from PIIX

PATCH Applied Bernhard Beschow 5 participants 10 messages Jun 26, 2022 – Jun 28, 2022

lore
Share & tools
lore
#0 lore raw

cover Decouple Xen-HVM from PIIX

hw/i386/xen/xen-hvm.c contains logic which is PIIX-specific. This makes xen-hvm.c depend on PIIX which can be avoided if PIIX logic was isolated in PIIX itself.

Bernhard Beschow (2):
hw/i386/xen/xen-hvm: Allow for stubbing xen_set_pci_link_route() hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and
remove it

 hw/i386/xen/xen-hvm.c       | 17 ++---------------
 hw/isa/piix3.c              | 15 ++++++++++++++-
 include/hw/xen/xen.h        |  2 +-
 include/hw/xen/xen_common.h |  6 ------
 stubs/xen-hw-stub.c         |  3 ++-
 5 files changed, 19 insertions(+), 24 deletions(-)
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/2 hw/i386/xen/xen-hvm: Allow for stubbing xen_set_pci_link_route()

The only user of xen_set_pci_link_route() is xen_piix_pci_write_config_client() which implements PIIX-specific logic in the xen namespace. This makes xen-hvm depend on PIIX which could be avoided if xen_piix_pci_write_config_client() was implemented in PIIX. In order to do this, xen_set_pci_link_route() needs to be stubbable which this patch addresses.

---
 hw/i386/xen/xen-hvm.c       | 7 ++++++-
 include/hw/xen/xen.h        | 1 +
 include/hw/xen/xen_common.h | 6 ------
 stubs/xen-hw-stub.c         | 5 +++++
 4 files changed, 12 insertions(+), 7 deletions(-)
hw/i386/xen/xen-hvm.c +6 -1
index 0731f70410..204fda7949 100644
@@ -161,11 +161,16 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
         }
         v &= 0xf;
         if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
-            xen_set_pci_link_route(xen_domid, address + i - PIIX_PIRQCA, v);
+            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
         }
     }
 }
 
+int xen_set_pci_link_route(uint8_t link, uint8_t irq)
+{
+    return xendevicemodel_set_pci_link_route(xen_dmod, xen_domid, link, irq);
+}
+
 int xen_is_pirq_msi(uint32_t msi_data)
 {
     /* If vector is 0, the msi is remapped into a pirq, passed as
include/hw/xen/xen.h +1 -0
index 0f9962b1c1..13bffaef53 100644
@@ -21,6 +21,7 @@ extern enum xen_mode xen_mode;
 extern bool xen_domid_restrict;
 
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
+int xen_set_pci_link_route(uint8_t link, uint8_t irq);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
include/hw/xen/xen_common.h +0 -6
index 179741ff79..77ce17d8a4 100644
@@ -316,12 +316,6 @@ static inline int xen_set_pci_intx_level(domid_t domid, uint16_t segment,
                                              device, intx, level);
 }
 
-static inline int xen_set_pci_link_route(domid_t domid, uint8_t link,
-                                         uint8_t irq)
-{
-    return xendevicemodel_set_pci_link_route(xen_dmod, domid, link, irq);
-}
-
 static inline int xen_inject_msi(domid_t domid, uint64_t msi_addr,
                                  uint32_t msi_data)
 {
stubs/xen-hw-stub.c +5 -0
index 15f3921a76..743967623f 100644
@@ -23,6 +23,11 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
 {
 }
 
+int xen_set_pci_link_route(uint8_t link, uint8_t irq)
+{
+    return -1;
+}
+
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data)
 {
 }
Signature · 1 line
2.36.1
Reviewed-by Paul Durrant on v1 1/2
#2 lore raw

Re: [PATCH 1/2] hw/i386/xen/xen-hvm: Allow for stubbing xen_set_pci_link_route()

Quoted 8 lines · Bernhard Beschow

The only user of xen_set_pci_link_route() is xen_piix_pci_write_config_client() which implements PIIX-specific logic in the xen namespace. This makes xen-hvm depend on PIIX which could be avoided if xen_piix_pci_write_config_client() was implemented in PIIX. In order to do this, xen_set_pci_link_route() needs to be stubbable which this patch addresses.

#3 lore raw

Re: [PATCH 1/2] hw/i386/xen/xen-hvm: Allow for stubbing xen_set_pci_link_route()

In reply to Bernhard Beschow

Le 26/06/2022 à 11:46, Bernhard Beschow a écrit :

Quoted 72 lines

The only user of xen_set_pci_link_route() is xen_piix_pci_write_config_client() which implements PIIX-specific logic in the xen namespace. This makes xen-hvm depend on PIIX which could be avoided if xen_piix_pci_write_config_client() was implemented in PIIX. In order to do this, xen_set_pci_link_route() needs to be stubbable which this patch addresses.

---
  hw/i386/xen/xen-hvm.c       | 7 ++++++-
  include/hw/xen/xen.h        | 1 +
  include/hw/xen/xen_common.h | 6 ------
  stubs/xen-hw-stub.c         | 5 +++++
  4 files changed, 12 insertions(+), 7 deletions(-)
hw/i386/xen/xen-hvm.c +6 -1
index 0731f70410..204fda7949 100644
@@ -161,11 +161,16 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
          }
          v &= 0xf;
          if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
-            xen_set_pci_link_route(xen_domid, address + i - PIIX_PIRQCA, v);
+            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
          }
      }
  }
 
+int xen_set_pci_link_route(uint8_t link, uint8_t irq)
+{
+    return xendevicemodel_set_pci_link_route(xen_dmod, xen_domid, link, irq);
+}
+
  int xen_is_pirq_msi(uint32_t msi_data)
  {
      /* If vector is 0, the msi is remapped into a pirq, passed as
include/hw/xen/xen.h +1 -0
index 0f9962b1c1..13bffaef53 100644
@@ -21,6 +21,7 @@ extern enum xen_mode xen_mode;
  extern bool xen_domid_restrict;
 
  int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
+int xen_set_pci_link_route(uint8_t link, uint8_t irq);
  void xen_piix3_set_irq(void *opaque, int irq_num, int level);
  void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
  void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
include/hw/xen/xen_common.h +0 -6
index 179741ff79..77ce17d8a4 100644
@@ -316,12 +316,6 @@ static inline int xen_set_pci_intx_level(domid_t domid, uint16_t segment,
                                               device, intx, level);
  }
 
-static inline int xen_set_pci_link_route(domid_t domid, uint8_t link,
-                                         uint8_t irq)
-{
-    return xendevicemodel_set_pci_link_route(xen_dmod, domid, link, irq);
-}
-
  static inline int xen_inject_msi(domid_t domid, uint64_t msi_addr,
                                   uint32_t msi_data)
  {
stubs/xen-hw-stub.c +0 -0
index 15f3921a76..743967623f 100644
@@ -23,6 +23,11 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
  {

stubs/xen-hw-stub.c void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) · line 33

Quoted 10 lines
stubs/xen-hw-stub.c +5 -0
  }
 
+int xen_set_pci_link_route(uint8_t link, uint8_t irq)
+{
+    return -1;
+}
+
  void xen_hvm_inject_msi(uint64_t addr, uint32_t data)
  {
  }

Applied to my trivial-patches branch.

Thanks,
Laurent

#4 lore raw

PATCH 2/2 hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and remove it

In reply to Bernhard Beschow

xen_piix_pci_write_config_client() is implemented in the xen sub tree and uses PIIX constants internally, thus creating a direct dependency on PIIX. Now that xen_set_pci_link_route() is stubbable, the logic of xen_piix_pci_write_config_client() can be moved to PIIX which resolves the dependency.

---
 hw/i386/xen/xen-hvm.c | 18 ------------------
 hw/isa/piix3.c        | 15 ++++++++++++++-
 include/hw/xen/xen.h  |  1 -
 stubs/xen-hw-stub.c   |  4 ----
 4 files changed, 14 insertions(+), 24 deletions(-)
hw/i386/xen/xen-hvm.c +0 -18
index 204fda7949..e4293d6d66 100644
@@ -15,7 +15,6 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
 #include "hw/i386/pc.h"
-#include "hw/southbridge/piix.h"
 #include "hw/irq.h"
 #include "hw/hw.h"
 #include "hw/i386/apic-msidef.h"
@@ -149,23 +148,6 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
                            irq_num & 3, level);
 }
 
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
-{
-    int i;
-
-    /* Scan for updates to PCI link routes (0x60-0x63). */
-    for (i = 0; i < len; i++) {
-        uint8_t v = (val >> (8 * i)) & 0xff;
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
-        if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
-            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
-        }
-    }
-}
-
 int xen_set_pci_link_route(uint8_t link, uint8_t irq)
 {
     return xendevicemodel_set_pci_link_route(xen_dmod, xen_domid, link, irq);
hw/isa/piix3.c +14 -1
index 6388558f92..48f9ab1096 100644
@@ -138,7 +138,20 @@ static void piix3_write_config(PCIDevice *dev,
 static void piix3_write_config_xen(PCIDevice *dev,
                                    uint32_t address, uint32_t val, int len)
 {
-    xen_piix_pci_write_config_client(address, val, len);
+    int i;
+
+    /* Scan for updates to PCI link routes (0x60-0x63). */
+    for (i = 0; i < len; i++) {
+        uint8_t v = (val >> (8 * i)) & 0xff;
+        if (v & 0x80) {
+            v = 0;
+        }
+        v &= 0xf;
+        if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
+            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
+        }
+    }
+
     piix3_write_config(dev, address, val, len);
 }
 
include/hw/xen/xen.h +0 -1
index 13bffaef53..afdf9c436a 100644
@@ -23,7 +23,6 @@ extern bool xen_domid_restrict;
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 int xen_set_pci_link_route(uint8_t link, uint8_t irq);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
 int xen_is_pirq_msi(uint32_t msi_data);
 
stubs/xen-hw-stub.c +0 -4
index 743967623f..34a22f2ad7 100644
@@ -19,10 +19,6 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
 {
 }
 
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
-{
-}
-
 int xen_set_pci_link_route(uint8_t link, uint8_t irq)
 {
     return -1;
Signature · 1 line
2.36.1
Acked-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and remove it

Quoted 7 lines · Bernhard Beschow

xen_piix_pci_write_config_client() is implemented in the xen sub tree and uses PIIX constants internally, thus creating a direct dependency on PIIX. Now that xen_set_pci_link_route() is stubbable, the logic of xen_piix_pci_write_config_client() can be moved to PIIX which resolves the dependency.

Fine by me

Quoted 98 lines
---
 hw/i386/xen/xen-hvm.c | 18 ------------------
 hw/isa/piix3.c        | 15 ++++++++++++++-
 include/hw/xen/xen.h  |  1 -
 stubs/xen-hw-stub.c   |  4 ----
 4 files changed, 14 insertions(+), 24 deletions(-)
hw/i386/xen/xen-hvm.c +0 -18
index 204fda7949..e4293d6d66 100644
@@ -15,7 +15,6 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
 #include "hw/i386/pc.h"
-#include "hw/southbridge/piix.h"
 #include "hw/irq.h"
 #include "hw/hw.h"
 #include "hw/i386/apic-msidef.h"
@@ -149,23 +148,6 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
                            irq_num & 3, level);
 }
 
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
-{
-    int i;
-
-    /* Scan for updates to PCI link routes (0x60-0x63). */
-    for (i = 0; i < len; i++) {
-        uint8_t v = (val >> (8 * i)) & 0xff;
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
-        if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
-            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
-        }
-    }
-}
-
 int xen_set_pci_link_route(uint8_t link, uint8_t irq)
 {
     return xendevicemodel_set_pci_link_route(xen_dmod, xen_domid, link, irq);
hw/isa/piix3.c +14 -1
index 6388558f92..48f9ab1096 100644
@@ -138,7 +138,20 @@ static void piix3_write_config(PCIDevice *dev,
 static void piix3_write_config_xen(PCIDevice *dev,
                                    uint32_t address, uint32_t val, int len)
 {
-    xen_piix_pci_write_config_client(address, val, len);
+    int i;
+
+    /* Scan for updates to PCI link routes (0x60-0x63). */
+    for (i = 0; i < len; i++) {
+        uint8_t v = (val >> (8 * i)) & 0xff;
+        if (v & 0x80) {
+            v = 0;
+        }
+        v &= 0xf;
+        if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
+            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
+        }
+    }
+
     piix3_write_config(dev, address, val, len);
 }
 
include/hw/xen/xen.h +0 -1
index 13bffaef53..afdf9c436a 100644
@@ -23,7 +23,6 @@ extern bool xen_domid_restrict;
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 int xen_set_pci_link_route(uint8_t link, uint8_t irq);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
 int xen_is_pirq_msi(uint32_t msi_data);
 
stubs/xen-hw-stub.c +0 -4
index 743967623f..34a22f2ad7 100644
@@ -19,10 +19,6 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
 {
 }
 
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
-{
-}
-
 int xen_set_pci_link_route(uint8_t link, uint8_t irq)
 {
     return -1;
Signature · 1 line
2.36.1
Reviewed-by Paul Durrant on v1 2/2
#6 lore raw

Re: [PATCH 2/2] hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and remove it

In reply to Bernhard Beschow
Quoted 7 lines · Bernhard Beschow

xen_piix_pci_write_config_client() is implemented in the xen sub tree and uses PIIX constants internally, thus creating a direct dependency on PIIX. Now that xen_set_pci_link_route() is stubbable, the logic of xen_piix_pci_write_config_client() can be moved to PIIX which resolves the dependency.

#7 lore raw

Re: [PATCH 2/2] hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and remove it

In reply to Bernhard Beschow

Le 26/06/2022 à 11:46, Bernhard Beschow a écrit :

Quoted 93 lines

xen_piix_pci_write_config_client() is implemented in the xen sub tree and uses PIIX constants internally, thus creating a direct dependency on PIIX. Now that xen_set_pci_link_route() is stubbable, the logic of xen_piix_pci_write_config_client() can be moved to PIIX which resolves the dependency.

---
  hw/i386/xen/xen-hvm.c | 18 ------------------
  hw/isa/piix3.c        | 15 ++++++++++++++-
  include/hw/xen/xen.h  |  1 -
  stubs/xen-hw-stub.c   |  4 ----
  4 files changed, 14 insertions(+), 24 deletions(-)
hw/i386/xen/xen-hvm.c +0 -18
index 204fda7949..e4293d6d66 100644
@@ -15,7 +15,6 @@
  #include "hw/pci/pci.h"
  #include "hw/pci/pci_host.h"
  #include "hw/i386/pc.h"
-#include "hw/southbridge/piix.h"
  #include "hw/irq.h"
  #include "hw/hw.h"
  #include "hw/i386/apic-msidef.h"
@@ -149,23 +148,6 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
                             irq_num & 3, level);
  }
 
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
-{
-    int i;
-
-    /* Scan for updates to PCI link routes (0x60-0x63). */
-    for (i = 0; i < len; i++) {
-        uint8_t v = (val >> (8 * i)) & 0xff;
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
-        if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
-            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
-        }
-    }
-}
-
  int xen_set_pci_link_route(uint8_t link, uint8_t irq)
  {
      return xendevicemodel_set_pci_link_route(xen_dmod, xen_domid, link, irq);
hw/isa/piix3.c +14 -1
index 6388558f92..48f9ab1096 100644
@@ -138,7 +138,20 @@ static void piix3_write_config(PCIDevice *dev,
  static void piix3_write_config_xen(PCIDevice *dev,
                                     uint32_t address, uint32_t val, int len)
  {
-    xen_piix_pci_write_config_client(address, val, len);
+    int i;
+
+    /* Scan for updates to PCI link routes (0x60-0x63). */
+    for (i = 0; i < len; i++) {
+        uint8_t v = (val >> (8 * i)) & 0xff;
+        if (v & 0x80) {
+            v = 0;
+        }
+        v &= 0xf;
+        if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
+            xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
+        }
+    }
+
      piix3_write_config(dev, address, val, len);
  }
 
include/hw/xen/xen.h +0 -1
index 13bffaef53..afdf9c436a 100644
@@ -23,7 +23,6 @@ extern bool xen_domid_restrict;
  int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
  int xen_set_pci_link_route(uint8_t link, uint8_t irq);
  void xen_piix3_set_irq(void *opaque, int irq_num, int level);
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
  void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
  int xen_is_pirq_msi(uint32_t msi_data);
 
stubs/xen-hw-stub.c +0 -0
index 743967623f..34a22f2ad7 100644

stubs/xen-hw-stub.c void xen_piix3_set_irq(void *opaque, int irq_num, int level) · line 24

Quoted 10 lines
stubs/xen-hw-stub.c +0 -4
@@ -19,10 +19,6 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
  {
  }
 
-void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
-{
-}
-
  int xen_set_pci_link_route(uint8_t link, uint8_t irq)
  {
      return -1;

Applied to my trivial-patches branch.

Thanks,
Laurent

author
#8 lore raw
In reply to Bernhard Beschow

Am 26. Juni 2022 09:46:54 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 22 lines

hw/i386/xen/xen-hvm.c contains logic which is PIIX-specific. This makes xen-hvm.c depend on PIIX which can be avoided if PIIX logic was isolated in PIIX itself.

Bernhard Beschow (2):

hw/i386/xen/xen-hvm: Allow for stubbing xen_set_pci_link_route()

hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and

remove it

hw/i386/xen/xen-hvm.c | 17 ++---------------

hw/isa/piix3.c | 15 ++++++++++++++-

include/hw/xen/xen.h | 2 +-

include/hw/xen/xen_common.h | 6 ------

Quoted 11 lines

stubs/xen-hw-stub.c | 3 ++-

5 files changed, 19 insertions(+), 24 deletions(-)

-- >
2.36.1

Hi Laurent,

would you like to queue this as well? Both patches have been reviewed at least once, piix twice. Or would you rather keep the review period open for longer?

Best regards,
Bernhard

#9 lore raw
Quoted 35 lines · On Tue, 28 Jun 2022, B wrote:

Am 26. Juni 2022 09:46:54 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 22 lines

hw/i386/xen/xen-hvm.c contains logic which is PIIX-specific. This makes xen-hvm.c depend on PIIX which can be avoided if PIIX logic was isolated in PIIX itself.

Bernhard Beschow (2):

hw/i386/xen/xen-hvm: Allow for stubbing xen_set_pci_link_route()

hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and

remove it

hw/i386/xen/xen-hvm.c | 17 ++---------------

hw/isa/piix3.c | 15 ++++++++++++++-

include/hw/xen/xen.h | 2 +-

include/hw/xen/xen_common.h | 6 ------

Quoted 11 lines

stubs/xen-hw-stub.c | 3 ++-

5 files changed, 19 insertions(+), 24 deletions(-)

-- >
2.36.1

Quoted 3 lines

Hi Laurent,

would you like to queue this as well? Both patches have been reviewed at least once, piix twice. Or would you rather keep the review period open for longer?

Paul reviewed them both -- I don't think we need further reviews. Laurent could just take them.