Skip to contentSkip to conversation

Xen PCI Passthrough

PATCH Superseded Anthony PERARD 3 participants 19 messages Mar 28, 2012 – Mar 30, 2012 Kbuild

v10 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v10 cover Xen PCI Passthrough

Hi all,

This patch series introduces the PCI passthrough for Xen.

Please review patches number 1, 2, 3, 4 and 7.

First, we have XenHostPCIDevice that help to access one PCI device of the host.

Then, the PCI passthrough device himself. Cut in 3 parts (or file), there is one to take care of the initialisation of a passthrough device. The second one handle everything about the config address space, there are specifics functions for every config register. The third one is to handle MSI.

There is a patch series on xen-devel (applied to xen-unstable) that add the support of setting a PCI passthrough device through QMP from libxl (xen tool stack). It is just a call to device_add, with the driver parametter hostaddr="0000:07:00.1".

Change v9-v10:
host-pci-device:
- rename to xen-host-pci-device.
- suppress usage of scanf and use strtol instead.
- add irq field
- no more goto loop
xen_pt:
- take machine_irq value from XenHostPCIDevice instead of reading it from the pci config space
- rename xen_pci_device to xen_pt
- use xen_pt as prefix
# this should fix namespace issue

Change v8-v9:
- rename PCI_DEVICE_ID_INTEL_82599_VF to PCI_DEVICE_ID_INTEL_82599_SFP_VF to be consistant with Linux.
- remove the patch about checking bar overlaps, the function is now in xen_pci_passthrough.c and uses pci_for_each_device.
- Introduce an opaque argument to the function pci_for_each_device.
- Fix the usage of memory listener: declare a stub function for every callback in the MemoryListener.

Change v7-v8:
- rework of the memory mapping of BARs. We now use a memory_listener to update a xen memory_mapping when a memory_region is updated.
- address few comment from Michael in the pci_check_overlap function.
- fix the handling of the ROM slot.

Change v6-v7:
- few fix and rebased on master
- remove of the power management capability, keep the minimum like if it is always desactivated.
- new patch: port of patch from the qemu-xen fork.

Change v5-v6:
- msitraslate code have been removed.
- code for the power management capability is removed, but will be re-added for the next version of the patch series as a separate patch.

- new patch to remove a check in pci_parse_devaddr.
- use pci_default_config_write, so no more hack to handle the BAR mapping in QEMU.
- improve the code in general (a bit more comprehensible).
- update to QOM.

Change v4-v5:
- return -errno if there is an error in host_pci_get_*
- rename internal function get_value to get_hex_value (and return the same error value has get_resource)

Change v3-v4:
- host_pci_get_* can now return an error, and take an extra parameter, a pointer to store the wanted value.
- The memory_region for the PCI BAR are handled "manualy" because calling pci_default_write_config was not possible, because the XenPT handle the PCIIORegion it self. This make possible to do a device_remove.
- Introduction of PT_ERR and PT_WARN macro to print debug and error messages. Also, these macro as well as PT_LOG will always print the short BDF of the device in the guest point of view.
- PT_ERR is print by default (for all error messages).
- Some debug/error message have been improve and should be a bit more useful.
- hw_error have been removed from the code, and have been replaced by either a call to qemu_system_shudown_request() (that lead to a domain destroy) or a failed in the initialisation of the device.
- Now, every patchs should compile with no error.

Change v2-v3;
- in host-pci-device.c:
- Return more usefull error code in get_ressource().
- Use macro in host_pci_find_ext_cap_offset instead of raw number. But I still not sure if PCI_MAX_EXT_CAP is right, it's result is 480 like it was before, so it's maybe ok.
- All use of MSI stuff in two first pci passthrough patch have been removed and move to the last patch.

Change v1-v2:
- fix style issue (checkpatch.pl)
- set the original authors, add some missing copyright headers
- HostPCIDevice:
- introduce HostPCIIORegions (with base_addr, size, flags)
- save all flags from ./resource and store it in a separate field.
- fix endianess on write
- new host_pci_dev_put function
- use pci.c like interface host_pci_get/set_byte/word/long (instead of host_pci_read/write_)
- compile HostPCIDevice only on linux (as well as xen_pci_passthrough)
- introduce apic-msidef.h file.
- no more run_one_timer, if a pci device is in the middle of a power transition, just "return an error" in config read/write
- use a global var mapped_machine_irq (local to xen_pci_passthrough.c)
- add msitranslate and power-mgmt ad qdev property

Allen Kay (2):
Introduce Xen PCI Passthrough, qdevice (1/3) Introduce Xen PCI Passthrough, PCI config space helpers (2/3)

Anthony PERARD (5):
pci_ids: Add INTEL_82599_SFP_VF id.
configure: Introduce --enable-xen-pci-passthrough. Introduce XenHostPCIDevice to access a pci device on the host. pci.c: Add opaque argument to pci_for_each_device. Introduce apic-msidef.h

Jiang Yunhong (1):
Introduce Xen PCI Passthrough, MSI (3/3)

 Makefile.target          |    6 +
 configure                |   25 +
 hw/apic-msidef.h         |   30 +
 hw/apic.c                |   11 +-
 hw/pci.c                 |   11 +-
 hw/pci.h                 |    4 +-
 hw/pci_ids.h             |    1 +
 hw/xen-host-pci-device.c |  354 +++++++++
 hw/xen-host-pci-device.h |   78 ++
 hw/xen_common.h          |    3 +
 hw/xen_platform.c        |    8 +-
 hw/xen_pt.c              |  854 +++++++++++++++++++++
 hw/xen_pt.h              |  301 ++++++++
 hw/xen_pt_config_init.c  | 1868 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen_pt_msi.c          |  620 +++++++++++++++
 xen-all.c                |   12 +
 16 files changed, 4167 insertions(+), 19 deletions(-)
 create mode 100644 hw/apic-msidef.h
 create mode 100644 hw/xen-host-pci-device.c
 create mode 100644 hw/xen-host-pci-device.h
 create mode 100644 hw/xen_pt.c
 create mode 100644 hw/xen_pt.h
 create mode 100644 hw/xen_pt_config_init.c
 create mode 100644 hw/xen_pt_msi.c
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH v10 1/8 pci_ids: Add INTEL_82599_SFP_VF id.

---
 hw/pci_ids.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci_ids.h +1 -0
index e8235a7..649e6b3 100644
@@ -118,6 +118,7 @@
 #define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939
 #define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a
 #define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c
+#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed
 
 #define PCI_VENDOR_ID_XEN               0x5853
 #define PCI_DEVICE_ID_XEN_PLATFORM      0x0001
Signature · 1 line
Anthony PERARD
#4 lore raw

PATCH v10 2/8 configure: Introduce --enable-xen-pci-passthrough.

In reply to Anthony PERARD
---
 configure |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
configure +25 -0
index 14ef738..cb7bc75 100755
@@ -136,6 +136,7 @@ vnc_png=""
 vnc_thread="no"
 xen=""
 xen_ctrl_version=""
+xen_pci_passthrough=""
 linux_aio=""
 cap_ng=""
 attr=""
@@ -682,6 +683,10 @@ for opt do
   ;;
   --enable-xen) xen="yes"
   ;;
+  --disable-xen-pci-passthrough) xen_pci_passthrough="no"
+  ;;
+  --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -1034,6 +1039,8 @@ echo "                           (affects only QEMU, not qemu-img)"
 echo "  --enable-mixemu          enable mixer emulation"
 echo "  --disable-xen            disable xen backend driver support"
 echo "  --enable-xen             enable xen backend driver support"
+echo "  --disable-xen-pci-passthrough"
+echo "  --enable-xen-pci-passthrough"
 echo "  --disable-brlapi         disable BrlAPI"
 echo "  --enable-brlapi          enable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
@@ -1478,6 +1485,21 @@ EOF
   fi
 fi
 
+if test "$xen_pci_passthrough" != "no"; then
+  if test "$xen" = "yes" && test "$linux" = "yes"; then
+    xen_pci_passthrough=yes
+  else
+    if test "$xen_pci_passthrough" = "yes"; then
+      echo "ERROR"
+      echo "ERROR: User requested feature Xen PCI Passthrough"
+      echo "ERROR: but this feature require /sys from Linux"
+      echo "ERROR"
+      exit 1;
+    fi
+    xen_pci_passthrough=no
+  fi
+fi
+
 ##########################################
 # pkg-config probe
 
@@ -3635,6 +3657,9 @@ case "$target_arch2" in
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
       target_phys_bits=64
       echo "CONFIG_XEN=y" >> $config_target_mak
+      if test "$xen_pci_passthrough" = yes; then
+        echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak"
+      fi
     else
       echo "CONFIG_NO_XEN=y" >> $config_target_mak
     fi
Signature · 1 line
Anthony PERARD
#8 lore raw

PATCH v10 3/8 Introduce XenHostPCIDevice to access a pci device on the host.

In reply to Anthony PERARD
---
 Makefile.target          |    3 +
 hw/xen-host-pci-device.c |  354 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-host-pci-device.h |   78 ++++++++++
 3 files changed, 435 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen-host-pci-device.c
 create mode 100644 hw/xen-host-pci-device.h
Makefile.target +3 -0
index 44b2e83..70386a7 100644
@@ -235,6 +235,9 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o
 
 obj-i386-$(CONFIG_XEN) += xen_platform.o
 
+# Xen PCI Passthrough
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
+
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
 ifeq ($(CONFIG_KVM), y)
hw/xen-host-pci-device.c new file +354 -0

354 lines not on this page · raw message

hw/xen-host-pci-device.h new file +78 -0

78 lines not on this page · raw message

Signature · 1 line
Anthony PERARD
#12 lore raw

PATCH v10 4/8 pci.c: Add opaque argument to pci_for_each_device.

In reply to Anthony PERARD
---
 hw/pci.c          |   11 +++++++----
 hw/pci.h          |    4 +++-
 hw/xen_platform.c |    8 ++++----
 3 files changed, 14 insertions(+), 9 deletions(-)
hw/pci.c +7 -4
index 77001fa..49f1bf0 100644
@@ -1123,7 +1123,9 @@ static const pci_class_desc pci_class_descriptions[] =
 };
 
 static void pci_for_each_device_under_bus(PCIBus *bus,
-                                          void (*fn)(PCIBus *b, PCIDevice *d))
+                                          void (*fn)(PCIBus *b, PCIDevice *d,
+                                                     void *opaque),
+                                          void *opaque)
 {
     PCIDevice *d;
     int devfn;
@@ -1131,18 +1133,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,
     for(devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) {
         d = bus->devices[devfn];
         if (d) {
-            fn(bus, d);
+            fn(bus, d, opaque);
         }
     }
 }
 
 void pci_for_each_device(PCIBus *bus, int bus_num,
-                         void (*fn)(PCIBus *b, PCIDevice *d))
+                         void (*fn)(PCIBus *b, PCIDevice *d, void *opaque),
+                         void *opaque)
 {
     bus = pci_find_bus(bus, bus_num);
 
     if (bus) {
-        pci_for_each_device_under_bus(bus, fn);
+        pci_for_each_device_under_bus(bus, fn, opaque);
     }
 }
 
hw/pci.h +3 -1
index 4f19fdb..2827fd1 100644
@@ -296,7 +296,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
 PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
                                const char *default_devaddr);
 int pci_bus_num(PCIBus *s);
-void pci_for_each_device(PCIBus *bus, int bus_num, void (*fn)(PCIBus *bus, PCIDevice *d));
+void pci_for_each_device(PCIBus *bus, int bus_num,
+                         void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
+                         void *opaque);
 PCIBus *pci_find_root_bus(int domain);
 int pci_find_domain(const PCIBus *bus);
 PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
hw/xen_platform.c +4 -4
index 5a7c4cc..88ff5e8 100644
@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)
 #define UNPLUG_ALL_NICS 2
 #define UNPLUG_AUX_IDE_DISKS 4
 
-static void unplug_nic(PCIBus *b, PCIDevice *d)
+static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
 {
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_NETWORK_ETHERNET) {
@@ -93,10 +93,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)
 
 static void pci_unplug_nics(PCIBus *bus)
 {
-    pci_for_each_device(bus, 0, unplug_nic);
+    pci_for_each_device(bus, 0, unplug_nic, NULL);
 }
 
-static void unplug_disks(PCIBus *b, PCIDevice *d)
+static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
 {
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_STORAGE_IDE) {
@@ -106,7 +106,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)
 
 static void pci_unplug_disks(PCIBus *bus)
 {
-    pci_for_each_device(bus, 0, unplug_disks);
+    pci_for_each_device(bus, 0, unplug_disks, NULL);
 }
 
 static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
Signature · 1 line
Anthony PERARD
#15 lore raw

PATCH v10 5/8 Introduce Xen PCI Passthrough, qdevice (1/3)

In reply to Anthony PERARD

From: Allen Kay <[email protected]>

A more complete history can be found here:
git://xenbits.xensource.com/qemu-xen-unstable.git

---
 Makefile.target         |    2 +
 hw/xen_common.h         |    3 +
 hw/xen_pt.c             |  815 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen_pt.h             |  248 ++++++++++++++
 hw/xen_pt_config_init.c |   11 +
 xen-all.c               |   12 +
 6 files changed, 1091 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_pt.c
 create mode 100644 hw/xen_pt.h
 create mode 100644 hw/xen_pt_config_init.c
Makefile.target +2 -0
index 70386a7..fb9f63b 100644
@@ -237,6 +237,8 @@ obj-i386-$(CONFIG_XEN) += xen_platform.o
 
 # Xen PCI Passthrough
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_config_init.o
 
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
hw/xen_common.h +3 -0
index 0409ac7..48916fd 100644
@@ -135,4 +135,7 @@ static inline int xc_fd(xc_interface *xen_xc)
 
 void destroy_hvm_domain(void);
 
+/* shutdown/destroy current domain because of an error */
+void xen_shutdown_fatal_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
 #endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_pt.c new file +815 -0

815 lines not on this page · raw message

hw/xen_pt.h new file +248 -0

248 lines not on this page · raw message

hw/xen_pt_config_init.c new file +11 -0
new file mode 100644
index 0000000..64d22e8
@@ -0,0 +1,11 @@
+#include "xen_pt.h"
+
+XenPTRegGroup *xen_pt_find_reg_grp(XenPCIPassthroughState *s, uint32_t address)
+{
+    return NULL;
+}
+
+XenPTReg *xen_pt_find_reg(XenPTRegGroup *reg_grp, uint32_t address)
+{
+    return NULL;
+}
xen-all.c +12 -0
index 3e6de41..e9daf8e 100644
@@ -1145,3 +1145,15 @@ void xen_register_framebuffer(MemoryRegion *mr)
 {
     framebuffer = mr;
 }
+
+void xen_shutdown_fatal_error(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    fprintf(stderr, "Will destroy the domain.\n");
+    /* destroy the domain */
+    qemu_system_shutdown_request();
+}
Signature · 1 line
Anthony PERARD
#16 lore raw

PATCH v10 6/8 Introduce Xen PCI Passthrough, PCI config space helpers (2/3)

In reply to Anthony PERARD

From: Allen Kay <[email protected]>

A more complete history can be found here:
git://xenbits.xensource.com/qemu-xen-unstable.git

---
 hw/xen_pt.c             |   10 +
 hw/xen_pt.h             |    2 +
 hw/xen_pt_config_init.c | 1386 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1398 insertions(+), 0 deletions(-)
hw/xen_pt.c +10 -0
index dc762bb..760679c 100644
@@ -676,6 +676,13 @@ static int xen_pt_initfn(PCIDevice *d)
     /* Handle real device's MMIO/PIO BARs */
     xen_pt_register_regions(s);
 
+    /* reinitialize each config register to be emulated */
+    if (xen_pt_config_init(s)) {
+        XEN_PT_ERR(d, "PCI Config space initialisation failed.\n");
+        xen_host_pci_device_put(&s->real_device);
+        return -1;
+    }
+
     /* Bind interrupt */
     if (!s->dev.config[PCI_INTERRUPT_PIN]) {
         XEN_PT_LOG(d, "no pin interrupt\n");
@@ -774,6 +781,9 @@ static int xen_pt_unregister_device(PCIDevice *d)
         }
     }
 
+    /* delete all emulated config registers */
+    xen_pt_config_delete(s);
+
     xen_pt_unregister_regions(s);
     memory_listener_unregister(&s->memory_listener);
 
hw/xen_pt.h +2 -0
index b7c080c..3766f07 100644
@@ -62,6 +62,8 @@ typedef int (*xen_pt_conf_byte_read)
 #define XEN_PT_BAR_ALLF 0xFFFFFFFF
 #define XEN_PT_BAR_UNMAPPED (-1)
 
+#define PCI_CAP_MAX 48
+
 
 typedef enum {
     XEN_PT_GRP_TYPE_HARDWIRED = 0,  /* 0 Hardwired reg group */
hw/xen_pt_config_init.c +1386 -0

1,397 lines not on this page · raw message

Signature · 1 line
Anthony PERARD
#17 lore raw

PATCH v10 7/8 Introduce apic-msidef.h

In reply to Anthony PERARD

This patch move the msi definition from apic.c to apic-msidef.h. So it can be used also by other .c files.

---
 hw/apic-msidef.h |   30 ++++++++++++++++++++++++++++++
 hw/apic.c        |   11 +----------
 2 files changed, 31 insertions(+), 10 deletions(-)
 create mode 100644 hw/apic-msidef.h
hw/apic-msidef.h new file +30 -0
new file mode 100644
index 0000000..6e2eb71
@@ -0,0 +1,30 @@
+#ifndef HW_APIC_MSIDEF_H
+#define HW_APIC_MSIDEF_H
+
+/*
+ * Intel APIC constants: from include/asm/msidef.h
+ */
+
+/*
+ * Shifts for MSI data
+ */
+
+#define MSI_DATA_VECTOR_SHIFT           0
+#define  MSI_DATA_VECTOR_MASK           0x000000ff
+
+#define MSI_DATA_DELIVERY_MODE_SHIFT    8
+#define MSI_DATA_LEVEL_SHIFT            14
+#define MSI_DATA_TRIGGER_SHIFT          15
+
+/*
+ * Shift/mask fields for msi address
+ */
+
+#define MSI_ADDR_DEST_MODE_SHIFT        2
+
+#define MSI_ADDR_REDIRECTION_SHIFT      3
+
+#define MSI_ADDR_DEST_ID_SHIFT          12
+#define  MSI_ADDR_DEST_ID_MASK          0x00ffff0
+
+#endif /* HW_APIC_MSIDEF_H */
hw/apic.c +1 -10
index 4eeaf88..a8da2f1 100644
@@ -22,19 +22,10 @@
 #include "host-utils.h"
 #include "trace.h"
 #include "pc.h"
+#include "apic-msidef.h"
 
 #define MAX_APIC_WORDS 8
 
-/* Intel APIC constants: from include/asm/msidef.h */
-#define MSI_DATA_VECTOR_SHIFT		0
-#define MSI_DATA_VECTOR_MASK		0x000000ff
-#define MSI_DATA_DELIVERY_MODE_SHIFT	8
-#define MSI_DATA_TRIGGER_SHIFT		15
-#define MSI_DATA_LEVEL_SHIFT		14
-#define MSI_ADDR_DEST_MODE_SHIFT	2
-#define MSI_ADDR_DEST_ID_SHIFT		12
-#define	MSI_ADDR_DEST_ID_MASK		0x00ffff0
-
 #define SYNC_FROM_VAPIC                 0x1
 #define SYNC_TO_VAPIC                   0x2
 #define SYNC_ISR_IRR_TO_VAPIC           0x4
Signature · 1 line
Anthony PERARD
#18 lore raw

PATCH v10 8/8 Introduce Xen PCI Passthrough, MSI (3/3)

In reply to Anthony PERARD

From: Jiang Yunhong <[email protected]>

A more complete history can be found here:
git://xenbits.xensource.com/qemu-xen-unstable.git

---
 Makefile.target         |    1 +
 hw/xen_pt.c             |   31 +++-
 hw/xen_pt.h             |   51 ++++
 hw/xen_pt_config_init.c |  471 +++++++++++++++++++++++++++++++++++
 hw/xen_pt_msi.c         |  620 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1173 insertions(+), 1 deletions(-)
 create mode 100644 hw/xen_pt_msi.c
Makefile.target +1 -0
index fb9f63b..7f3c80f 100644
@@ -239,6 +239,7 @@ obj-i386-$(CONFIG_XEN) += xen_platform.o
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_config_init.o
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_msi.o
 
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
hw/xen_pt.c +30 -1
index 760679c..0c3a961 100644
@@ -36,6 +36,20 @@
  *
  *     Write '1'
  *       - Set real bit to '1'.
+ *
+ * MSI interrupt:
+ *   Initialize MSI register(xen_pt_msi_setup, xen_pt_msi_update)
+ *     Bind MSI(xc_domain_update_msi_irq)
+ *       <fail>
+ *         - Unmap MSI.
+ *         - Set dev->msi->pirq to '-1'.
+ *
+ * MSI-X interrupt:
+ *   Initialize MSI-X register(xen_pt_msix_update_one)
+ *     Bind MSI-X(xc_domain_update_msi_irq)
+ *       <fail>
+ *         - Unmap MSI-X.
+ *         - Set entry->pirq to '-1'.
  */
 
 #include <sys/ioctl.h>
@@ -534,7 +548,15 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
     };
 
     bar = xen_pt_bar_from_region(s, mr);
-    if (bar == -1) {
+    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
+        return;
+    }
+
+    if (s->msix && &s->msix->mmio == mr) {
+        if (adding) {
+            s->msix->mmio_base_addr = sec->offset_within_address_space;
+            rc = xen_pt_msix_update_remap(s, s->msix->bar_index);
+        }
         return;
     }
 
@@ -767,6 +789,13 @@ static int xen_pt_unregister_device(PCIDevice *d)
         }
     }
 
+    if (s->msi) {
+        xen_pt_msi_disable(s);
+    }
+    if (s->msix) {
+        xen_pt_msix_disable(s);
+    }
+
     if (machine_irq) {
         xen_pt_mapped_machine_irq[machine_irq]--;
 
hw/xen_pt.h +51 -0

67 lines not on this page · raw message

hw/xen_pt_config_init.c +471 -0

501 lines not on this page · raw message

hw/xen_pt_msi.c new file +620 -0

620 lines not on this page · raw message

Signature · 1 line
Anthony PERARD
#9 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 3/8] Introduce XenHostPCIDevice to access a pci device on the host.

In reply to Anthony PERARD

hw/xen-host-pci-device.c line 26

Quoted 6 lines
hw/xen-host-pci-device.c new file +6 -0
+static int xen_host_pci_sysfs_path(const XenHostPCIDevice *d,
+                                   const char *name, char *buf, ssize_t size)
+{
+    int rc;
+
+    rc = snprintf(buf, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/%s",

The format is actually " %04x:%02x:%02x.%d"

hw/xen-host-pci-device.c line 31

Quoted 5 lines
hw/xen-host-pci-device.c new file +5 -0
+                  d->domain, d->bus, d->dev, d->func, name);
+
+    if (rc >= size || rc < 0) {
+        /* The ouput is truncated or an other error is encountered */
+        return -1;

-ENODEV

hw/xen-host-pci-device.c line 40

Quoted 9 lines
hw/xen-host-pci-device.c new file +9 -0
+    }
+    return 0;
+}
+
+static int xen_host_pci_get_resource(XenHostPCIDevice *d)
+{
+    int i, rc, fd;
+    char path[PATH_MAX];
+    char buf[512];

You should have a #define for the 512.

hw/xen-host-pci-device.c line 45

Quoted 5 lines
hw/xen-host-pci-device.c new file +5 -0
+    unsigned long long start, end, flags, size;
+    char *endptr, *s;
+
+    if (xen_host_pci_sysfs_path(d, "resource", path, sizeof (path))) {
+        return -1;

-ENODEV

hw/xen-host-pci-device.c line 56

Quoted 11 lines
hw/xen-host-pci-device.c new file +11 -0
+    }
+    fd = open(path, O_RDONLY);
+    if (fd == -1) {
+        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
+        return -errno;
+    }
+
+    do {
+        rc = read(fd, &buf, sizeof (buf));
+        if (rc < 0 && errno != EINTR) {
+            rc = -errno;

So you are using the errnor types, so you should use them throughout this function.

Quoted 32 lines
hw/xen-host-pci-device.c new file +32 -0
+            goto out;
+        }
+    } while (rc < 0);
+    buf[rc] = 0;
+    rc = 0;
+
+    s = buf;
+    for (i = 0; i < PCI_NUM_REGIONS; i++) {
+        start = strtoll(s, &endptr, 16);
+        if (*endptr != ' ' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+        end = strtoll(s, &endptr, 16);
+        if (*endptr != ' ' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+        flags = strtoll(s, &endptr, 16);
+        if (*endptr != '\n' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+
+        if (start) {
+            size = end - start + 1;
+        } else {
+            size = 0;
+        }
+
+        if (i < PCI_ROM_SLOT) {
+            d->io_regions[i].base_addr = start;

hw/xen-host-pci-device.c line 98

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+            d->io_regions[i].size = size;
+            d->io_regions[i].flags = flags;
+        } else {
+            d->rom.base_addr = start;
+            d->rom.size = size;
+            d->rom.flags = flags;
+        }
+    }
+    if (i != PCI_NUM_REGIONS) {
+        rc = -1;

-ENODEV

hw/xen-host-pci-device.c line 110

Quoted 12 lines
hw/xen-host-pci-device.c new file +12 -0
+    }
+
+out:
+    close(fd);
+    return rc;
+}
+
+static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name,
+                                  unsigned int *pvalue, int base)
+{
+    char path[PATH_MAX];
+    char buf[42];

You should use a #define

hw/xen-host-pci-device.c line 116

Quoted 6 lines
hw/xen-host-pci-device.c new file +6 -0
+    int fd, rc;
+    unsigned long value;
+    char *endptr;
+
+    if (xen_host_pci_sysfs_path(d, name, path, sizeof (path))) {
+        return -1;

-ENODEV

hw/xen-host-pci-device.c line 124

Quoted 8 lines
hw/xen-host-pci-device.c new file +8 -0
+    }
+    fd = open(path, O_RDONLY);
+    if (fd == -1) {
+        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
+        return -errno;
+    }
+    do {
+        rc = read(fd, &buf, sizeof (buf) - 1);

Here you have sizeof(buf) - 1, but in the function xen_host_pci_get_resource(..) you didn't do that. Any particular reason?

hw/xen-host-pci-device.c line 133

Quoted 9 lines
hw/xen-host-pci-device.c new file +9 -0
+        if (rc < 0 && errno != EINTR) {
+            rc = -errno;
+            goto out;
+        }
+    } while (rc < 0);
+    buf[rc] = 0;
+    value = strtol(buf, &endptr, base);
+    if (endptr == buf || *endptr != '\n') {
+        rc = -1;

??? -Exx something I think

Quoted 32 lines
hw/xen-host-pci-device.c new file +32 -0
+    } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) {
+        rc = -errno;
+    } else {
+        rc = 0;
+        *pvalue = value;
+    }
+out:
+    close(fd);
+    return rc;
+}
+
+static inline int xen_host_pci_get_hex_value(XenHostPCIDevice *d,
+                                             const char *name,
+                                             unsigned int *pvalue)
+{
+    return xen_host_pci_get_value(d, name, pvalue, 16);
+}
+
+static inline int xen_host_pci_get_dec_value(XenHostPCIDevice *d,
+                                             const char *name,
+                                             unsigned int *pvalue)
+{
+    return xen_host_pci_get_value(d, name, pvalue, 10);
+}
+
+static bool xen_host_pci_dev_is_virtfn(XenHostPCIDevice *d)
+{
+    char path[PATH_MAX];
+    struct stat buf;
+
+    if (xen_host_pci_sysfs_path(d, "physfn", path, sizeof (path))) {
+        return false;

hw/xen-host-pci-device.c line 175

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+    }
+    return !stat(path, &buf);
+}
+
+static int xen_host_pci_config_open(XenHostPCIDevice *d)
+{
+    char path[PATH_MAX];
+
+    if (xen_host_pci_sysfs_path(d, "config", path, sizeof (path))) {
+        return -1;

-ENODEV

Quoted 114 lines
hw/xen-host-pci-device.c new file +114 -0
+    }
+    d->config_fd = open(path, O_RDWR);
+    if (d->config_fd < 0) {
+        return -errno;
+    }
+    return 0;
+}
+
+static int xen_host_pci_config_read(XenHostPCIDevice *d,
+                                    int pos, void *buf, int len)
+{
+    int rc;
+
+    do {
+        rc = pread(d->config_fd, buf, len, pos);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    if (rc != len) {
+        return -errno;
+    }
+    return 0;
+}
+
+static int xen_host_pci_config_write(XenHostPCIDevice *d,
+                                     int pos, const void *buf, int len)
+{
+    int rc;
+
+    do {
+        rc = pwrite(d->config_fd, buf, len, pos);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    if (rc != len) {
+        return -errno;
+    }
+    return 0;
+}
+
+int xen_host_pci_get_byte(XenHostPCIDevice *d, int pos, uint8_t *p)
+{
+    uint8_t buf;
+    int rc = xen_host_pci_config_read(d, pos, &buf, 1);
+    if (!rc) {
+        *p = buf;
+    }
+    return rc;
+}
+
+int xen_host_pci_get_word(XenHostPCIDevice *d, int pos, uint16_t *p)
+{
+    uint16_t buf;
+    int rc = xen_host_pci_config_read(d, pos, &buf, 2);
+    if (!rc) {
+        *p = le16_to_cpu(buf);
+    }
+    return rc;
+}
+
+int xen_host_pci_get_long(XenHostPCIDevice *d, int pos, uint32_t *p)
+{
+    uint32_t buf;
+    int rc = xen_host_pci_config_read(d, pos, &buf, 4);
+    if (!rc) {
+        *p = le32_to_cpu(buf);
+    }
+    return rc;
+}
+
+int xen_host_pci_get_block(XenHostPCIDevice *d, int pos, uint8_t *buf, int len)
+{
+    return xen_host_pci_config_read(d, pos, buf, len);
+}
+
+int xen_host_pci_set_byte(XenHostPCIDevice *d, int pos, uint8_t data)
+{
+    return xen_host_pci_config_write(d, pos, &data, 1);
+}
+
+int xen_host_pci_set_word(XenHostPCIDevice *d, int pos, uint16_t data)
+{
+    data = cpu_to_le16(data);
+    return xen_host_pci_config_write(d, pos, &data, 2);
+}
+
+int xen_host_pci_set_long(XenHostPCIDevice *d, int pos, uint32_t data)
+{
+    data = cpu_to_le32(data);
+    return xen_host_pci_config_write(d, pos, &data, 4);
+}
+
+int xen_host_pci_set_block(XenHostPCIDevice *d, int pos, uint8_t *buf, int len)
+{
+    return xen_host_pci_config_write(d, pos, buf, len);
+}
+
+int xen_host_pci_find_ext_cap_offset(XenHostPCIDevice *d, uint32_t cap)
+{
+    uint32_t header = 0;
+    int max_cap = XEN_HOST_PCI_MAX_EXT_CAP;
+    int pos = PCI_CONFIG_SPACE_SIZE;
+
+    do {
+        if (xen_host_pci_get_long(d, pos, &header)) {
+            break;
+        }
+        /*
+         * If we have no capabilities, this is indicated by cap ID,
+         * cap version and next pointer all being 0.
+         */
+        if (header == 0) {
+            break;
+        }
+
+        if (PCI_EXT_CAP_ID(header) == cap) {
+            return pos;
+        }

hw/xen-host-pci-device.c line 299

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+
+        pos = PCI_EXT_CAP_NEXT(header);
+        if (pos < PCI_CONFIG_SPACE_SIZE) {
+            break;
+        }
+
+        max_cap--;
+    } while (max_cap > 0);
+
+    return 0;

If we fail in this function (which can happen [https://bugzilla.redhat.com/show_bug.cgi?id=767742])
shouldn't this function return something else besides 0?

Besides those comments, the patch looks good to me.

Reviewed-by me. on v10 2/8
#5 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 2/8] configure: Introduce --enable-xen-pci-passthrough.

In reply to Anthony PERARD
Quoted 2 lines · Anthony PERARD
Reviewed-by me.
Quoted 76 lines
---
 configure |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
configure +25 -0
index 14ef738..cb7bc75 100755
@@ -136,6 +136,7 @@ vnc_png=""
 vnc_thread="no"
 xen=""
 xen_ctrl_version=""
+xen_pci_passthrough=""
 linux_aio=""
 cap_ng=""
 attr=""
@@ -682,6 +683,10 @@ for opt do
   ;;
   --enable-xen) xen="yes"
   ;;
+  --disable-xen-pci-passthrough) xen_pci_passthrough="no"
+  ;;
+  --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -1034,6 +1039,8 @@ echo "                           (affects only QEMU, not qemu-img)"
 echo "  --enable-mixemu          enable mixer emulation"
 echo "  --disable-xen            disable xen backend driver support"
 echo "  --enable-xen             enable xen backend driver support"
+echo "  --disable-xen-pci-passthrough"
+echo "  --enable-xen-pci-passthrough"
 echo "  --disable-brlapi         disable BrlAPI"
 echo "  --enable-brlapi          enable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
@@ -1478,6 +1485,21 @@ EOF
   fi
 fi
 
+if test "$xen_pci_passthrough" != "no"; then
+  if test "$xen" = "yes" && test "$linux" = "yes"; then
+    xen_pci_passthrough=yes
+  else
+    if test "$xen_pci_passthrough" = "yes"; then
+      echo "ERROR"
+      echo "ERROR: User requested feature Xen PCI Passthrough"
+      echo "ERROR: but this feature require /sys from Linux"
+      echo "ERROR"
+      exit 1;
+    fi
+    xen_pci_passthrough=no
+  fi
+fi
+
 ##########################################
 # pkg-config probe
 
@@ -3635,6 +3657,9 @@ case "$target_arch2" in
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
       target_phys_bits=64
       echo "CONFIG_XEN=y" >> $config_target_mak
+      if test "$xen_pci_passthrough" = yes; then
+        echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak"
+      fi
     else
       echo "CONFIG_NO_XEN=y" >> $config_target_mak
     fi
Signature · 7 lines
Anthony PERARD


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

Re: [Qemu-devel] [Xen-devel] [PATCH V10 1/8] pci_ids: Add INTEL_82599_SFP_VF id.

In reply to Anthony PERARD

On Wed, Mar 28, 2012 at 12:41:40PM +0100, Anthony PERARD wrote:

You really should say why this is added.. It is so odd just to have 'add this' without any justification. Can you at least say:

"We are using this in our quirk lookup provided by patch
titled: XXXYYY" ?

Quoted 26 lines
---
 hw/pci_ids.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci_ids.h +1 -0
index e8235a7..649e6b3 100644
@@ -118,6 +118,7 @@
 #define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939
 #define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a
 #define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c
+#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed
 
 #define PCI_VENDOR_ID_XEN               0x5853
 #define PCI_DEVICE_ID_XEN_PLATFORM      0x0001
Signature · 7 lines
Anthony PERARD


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

Re: [Qemu-devel] [Xen-devel] [PATCH V10 4/8] pci.c: Add opaque argument to pci_for_each_device.

In reply to Anthony PERARD

On Wed, Mar 28, 2012 at 12:41:43PM +0100, Anthony PERARD wrote:

What is purpose of it? Can you give more details please?

Quoted 104 lines
---
 hw/pci.c          |   11 +++++++----
 hw/pci.h          |    4 +++-
 hw/xen_platform.c |    8 ++++----
 3 files changed, 14 insertions(+), 9 deletions(-)
hw/pci.c +7 -4
index 77001fa..49f1bf0 100644
@@ -1123,7 +1123,9 @@ static const pci_class_desc pci_class_descriptions[] =
 };
 
 static void pci_for_each_device_under_bus(PCIBus *bus,
-                                          void (*fn)(PCIBus *b, PCIDevice *d))
+                                          void (*fn)(PCIBus *b, PCIDevice *d,
+                                                     void *opaque),
+                                          void *opaque)
 {
     PCIDevice *d;
     int devfn;
@@ -1131,18 +1133,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,
     for(devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) {
         d = bus->devices[devfn];
         if (d) {
-            fn(bus, d);
+            fn(bus, d, opaque);
         }
     }
 }
 
 void pci_for_each_device(PCIBus *bus, int bus_num,
-                         void (*fn)(PCIBus *b, PCIDevice *d))
+                         void (*fn)(PCIBus *b, PCIDevice *d, void *opaque),
+                         void *opaque)
 {
     bus = pci_find_bus(bus, bus_num);
 
     if (bus) {
-        pci_for_each_device_under_bus(bus, fn);
+        pci_for_each_device_under_bus(bus, fn, opaque);
     }
 }
 
hw/pci.h +3 -1
index 4f19fdb..2827fd1 100644
@@ -296,7 +296,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
 PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
                                const char *default_devaddr);
 int pci_bus_num(PCIBus *s);
-void pci_for_each_device(PCIBus *bus, int bus_num, void (*fn)(PCIBus *bus, PCIDevice *d));
+void pci_for_each_device(PCIBus *bus, int bus_num,
+                         void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
+                         void *opaque);
 PCIBus *pci_find_root_bus(int domain);
 int pci_find_domain(const PCIBus *bus);
 PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
hw/xen_platform.c +4 -4
index 5a7c4cc..88ff5e8 100644
@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)
 #define UNPLUG_ALL_NICS 2
 #define UNPLUG_AUX_IDE_DISKS 4
 
-static void unplug_nic(PCIBus *b, PCIDevice *d)
+static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
 {
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_NETWORK_ETHERNET) {
@@ -93,10 +93,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)
 
 static void pci_unplug_nics(PCIBus *bus)
 {
-    pci_for_each_device(bus, 0, unplug_nic);
+    pci_for_each_device(bus, 0, unplug_nic, NULL);
 }
 
-static void unplug_disks(PCIBus *b, PCIDevice *d)
+static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
 {
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_STORAGE_IDE) {
@@ -106,7 +106,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)
 
 static void pci_unplug_disks(PCIBus *bus)
 {
-    pci_for_each_device(bus, 0, unplug_disks);
+    pci_for_each_device(bus, 0, unplug_disks, NULL);
 }
 
 static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
Signature · 7 lines
Anthony PERARD


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

Re: [Qemu-devel] [Xen-devel] [PATCH V10 2/8] configure: Introduce --enable-xen-pci-passthrough.

In reply to Konrad Rzeszutek Wilk
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Anthony PERARD
Reviewed-by me.

FYI, the scripts that I use to manage patches will collect Reviewed-by's and put them in the commit message so there's a proper review history in git.

But 'Reviewed-by: me.' will lose it's context and your review will be forever lost to git history :-)

So please use the proper tags.

Regards,

Anthony Liguori

Quoted 78 lines
Quoted 77 lines
---
  configure |   25 +++++++++++++++++++++++++
  1 files changed, 25 insertions(+), 0 deletions(-)
configure +25 -1
index 14ef738..cb7bc75 100755
@@ -136,6 +136,7 @@ vnc_png=""
  vnc_thread="no"
  xen=""
  xen_ctrl_version=""
+xen_pci_passthrough=""
  linux_aio=""
  cap_ng=""
  attr=""
@@ -682,6 +683,10 @@ for opt do
    ;;
    --enable-xen) xen="yes"
    ;;
+  --disable-xen-pci-passthrough) xen_pci_passthrough="no"
+  ;;
+  --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
+  ;;
    --disable-brlapi) brlapi="no"
    ;;
    --enable-brlapi) brlapi="yes"
@@ -1034,6 +1039,8 @@ echo "                           (affects only QEMU, not qemu-img)"
  echo "  --enable-mixemu          enable mixer emulation"
  echo "  --disable-xen            disable xen backend driver support"
  echo "  --enable-xen             enable xen backend driver support"
+echo "  --disable-xen-pci-passthrough"
+echo "  --enable-xen-pci-passthrough"
  echo "  --disable-brlapi         disable BrlAPI"
  echo "  --enable-brlapi          enable BrlAPI"
  echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
@@ -1478,6 +1485,21 @@ EOF
    fi
  fi
 
+if test "$xen_pci_passthrough" != "no"; then
+  if test "$xen" = "yes"&&  test "$linux" = "yes"; then
+    xen_pci_passthrough=yes
+  else
+    if test "$xen_pci_passthrough" = "yes"; then
+      echo "ERROR"
+      echo "ERROR: User requested feature Xen PCI Passthrough"
+      echo "ERROR: but this feature require /sys from Linux"
+      echo "ERROR"
+      exit 1;
+    fi
+    xen_pci_passthrough=no
+  fi
+fi
+
  ##########################################
  # pkg-config probe
 
@@ -3635,6 +3657,9 @@ case "$target_arch2" in
      if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
        target_phys_bits=64
        echo "CONFIG_XEN=y">>  $config_target_mak
+      if test "$xen_pci_passthrough" = yes; then
+        echo "CONFIG_XEN_PCI_PASSTHROUGH=y">>  "$config_target_mak"
+      fi
      else
        echo "CONFIG_NO_XEN=y">>  $config_target_mak
      fi
--

Anthony PERARD

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

#7 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 2/8] configure: Introduce --enable-xen-pci-passthrough.

Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Anthony PERARD
Quoted 8 lines
Quoted 1 line
Reviewed-by me.

FYI, the scripts that I use to manage patches will collect Reviewed-by's and put them in the commit message so there's a proper review history in git.

But 'Reviewed-by: me.' will lose it's context and your review will be forever lost to git history :-)

I figured that Anthony would repost the patch set and stick my proper name in it...

Quoted 85 lines

So please use the proper tags.

Regards,

Anthony Liguori

Quoted 78 lines
Quoted 77 lines
---
 configure |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
configure +25 -1
index 14ef738..cb7bc75 100755
@@ -136,6 +136,7 @@ vnc_png=""
 vnc_thread="no"
 xen=""
 xen_ctrl_version=""
+xen_pci_passthrough=""
 linux_aio=""
 cap_ng=""
 attr=""
@@ -682,6 +683,10 @@ for opt do
   ;;
   --enable-xen) xen="yes"
   ;;
+  --disable-xen-pci-passthrough) xen_pci_passthrough="no"
+  ;;
+  --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -1034,6 +1039,8 @@ echo "                           (affects only QEMU, not qemu-img)"
 echo "  --enable-mixemu          enable mixer emulation"
 echo "  --disable-xen            disable xen backend driver support"
 echo "  --enable-xen             enable xen backend driver support"
+echo "  --disable-xen-pci-passthrough"
+echo "  --enable-xen-pci-passthrough"
 echo "  --disable-brlapi         disable BrlAPI"
 echo "  --enable-brlapi          enable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
@@ -1478,6 +1485,21 @@ EOF
   fi
 fi
 
+if test "$xen_pci_passthrough" != "no"; then
+  if test "$xen" = "yes"&&  test "$linux" = "yes"; then
+    xen_pci_passthrough=yes
+  else
+    if test "$xen_pci_passthrough" = "yes"; then
+      echo "ERROR"
+      echo "ERROR: User requested feature Xen PCI Passthrough"
+      echo "ERROR: but this feature require /sys from Linux"
+      echo "ERROR"
+      exit 1;
+    fi
+    xen_pci_passthrough=no
+  fi
+fi
+
 ##########################################
 # pkg-config probe
 
@@ -3635,6 +3657,9 @@ case "$target_arch2" in
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
       target_phys_bits=64
       echo "CONFIG_XEN=y">>  $config_target_mak
+      if test "$xen_pci_passthrough" = yes; then
+        echo "CONFIG_XEN_PCI_PASSTHROUGH=y">>  "$config_target_mak"
+      fi
     else
       echo "CONFIG_NO_XEN=y">>  $config_target_mak
     fi
--

Anthony PERARD

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

#10 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 3/8] Introduce XenHostPCIDevice to access a pci device on the host.

In reply to Konrad Rzeszutek Wilk
Quoted 29 lines · Konrad Rzeszutek Wilk

hw/xen-host-pci-device.c line 26

Quoted 6 lines
hw/xen-host-pci-device.c new file +6 -0
+static int xen_host_pci_sysfs_path(const XenHostPCIDevice *d,
+                                   const char *name, char *buf, ssize_t size)
+{
+    int rc;
+
+    rc = snprintf(buf, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/%s",

The format is actually " %04x:%02x:%02x.%d"

Quoted 5 lines

+                  d->domain, d->bus, d->dev, d->func, name); +
+    if (rc >= size || rc < 0) {
+        /* The ouput is truncated or an other error is encountered */
+        return -1;

-ENODEV

hw/xen-host-pci-device.c line 40

Quoted 9 lines

+    }
+    return 0;

hw/xen-host-pci-device.c new file +7 -0
+}
+
+static int xen_host_pci_get_resource(XenHostPCIDevice *d)
+{
+    int i, rc, fd;
+    char path[PATH_MAX];
+    char buf[512];

You should have a #define for the 512.

Quoted 7 lines
Quoted 5 lines

+    unsigned long long start, end, flags, size;
+    char *endptr, *s;
+
+    if (xen_host_pci_sysfs_path(d, "resource", path, sizeof (path))) {
+        return -1;

-ENODEV

I still does not understand why return ENODEV (No such device) when an error occure. Is it the better way to say that a device does not behave like it should, or that a "module" using a device encounter any kind of error that prevent it to use the device ?

Quoted 94 lines
Quoted 11 lines

+    }
+    fd = open(path, O_RDONLY);
+    if (fd == -1) {
+        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
+        return -errno;
+    }
+
+    do {
+        rc = read(fd, &buf, sizeof (buf));
+        if (rc < 0 && errno != EINTR) {
+            rc = -errno;

So you are using the errnor types, so you should use them throughout this function.

Quoted 32 lines

+            goto out;
+        }
+    } while (rc < 0);
+    buf[rc] = 0;
+    rc = 0;

hw/xen-host-pci-device.c new file +27 -0
+
+    s = buf;
+    for (i = 0; i < PCI_NUM_REGIONS; i++) {
+        start = strtoll(s, &endptr, 16);
+        if (*endptr != ' ' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+        end = strtoll(s, &endptr, 16);
+        if (*endptr != ' ' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+        flags = strtoll(s, &endptr, 16);
+        if (*endptr != '\n' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+
+        if (start) {
+            size = end - start + 1;
+        } else {
+            size = 0;
+        }
+
+        if (i < PCI_ROM_SLOT) {
+            d->io_regions[i].base_addr = start;

hw/xen-host-pci-device.c line 98

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+            d->io_regions[i].size = size;
+            d->io_regions[i].flags = flags;
+        } else {
+            d->rom.base_addr = start;
+            d->rom.size = size;
+            d->rom.flags = flags;
+        }
+    }
+    if (i != PCI_NUM_REGIONS) {
+        rc = -1;

-ENODEV

hw/xen-host-pci-device.c line 110

Quoted 12 lines

+    }

hw/xen-host-pci-device.c new file +11 -0
+
+out:
+    close(fd);
+    return rc;
+}
+
+static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name,
+                                  unsigned int *pvalue, int base)
+{
+    char path[PATH_MAX];
+    char buf[42];

You should use a #define

Quoted 6 lines

+    int fd, rc;
+    unsigned long value;
+    char *endptr;
+
+    if (xen_host_pci_sysfs_path(d, name, path, sizeof (path))) {
+        return -1;

-ENODEV

Quoted 8 lines

+    }
+    fd = open(path, O_RDONLY);
+    if (fd == -1) {
+        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
+        return -errno;
+    }
+    do {
+        rc = read(fd, &buf, sizeof (buf) - 1);

Quoted 2 lines

Here you have sizeof(buf) - 1, but in the function xen_host_pci_get_resource(..) you didn't do that. Any particular reason?

Nop, it's just a mistake.

Quoted 64 lines
Quoted 9 lines

+        if (rc < 0 && errno != EINTR) {
+            rc = -errno;
+            goto out;
+        }
+    } while (rc < 0);
+    buf[rc] = 0;
+    value = strtol(buf, &endptr, base);
+    if (endptr == buf || *endptr != '\n') {
+        rc = -1;

??? -Exx something I think

Quoted 32 lines

+    } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) {
+        rc = -errno;
+    } else {
+        rc = 0;
+        *pvalue = value;
+    }

hw/xen-host-pci-device.c new file +26 -0
+out:
+    close(fd);
+    return rc;
+}
+
+static inline int xen_host_pci_get_hex_value(XenHostPCIDevice *d,
+                                             const char *name,
+                                             unsigned int *pvalue)
+{
+    return xen_host_pci_get_value(d, name, pvalue, 16);
+}
+
+static inline int xen_host_pci_get_dec_value(XenHostPCIDevice *d,
+                                             const char *name,
+                                             unsigned int *pvalue)
+{
+    return xen_host_pci_get_value(d, name, pvalue, 10);
+}
+
+static bool xen_host_pci_dev_is_virtfn(XenHostPCIDevice *d)
+{
+    char path[PATH_MAX];
+    struct stat buf;
+
+    if (xen_host_pci_sysfs_path(d, "physfn", path, sizeof (path))) {
+        return false;

hw/xen-host-pci-device.c line 175

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+    }
+    return !stat(path, &buf);
+}
+
+static int xen_host_pci_config_open(XenHostPCIDevice *d)
+{
+    char path[PATH_MAX];
+
+    if (xen_host_pci_sysfs_path(d, "config", path, sizeof (path))) {
+        return -1;

-ENODEV

Quoted 7 lines

+    }
+    d->config_fd = open(path, O_RDWR);
+    if (d->config_fd < 0) {
+        return -errno;
+    }
+    return 0;
+}

[...]

Quoted 26 lines
Quoted 26 lines
hw/xen-host-pci-device.c new file +26 -0
+int xen_host_pci_find_ext_cap_offset(XenHostPCIDevice *d, uint32_t cap)
+{
+    uint32_t header = 0;
+    int max_cap = XEN_HOST_PCI_MAX_EXT_CAP;
+    int pos = PCI_CONFIG_SPACE_SIZE;
+
+    do {
+        if (xen_host_pci_get_long(d, pos, &header)) {
+            break;
+        }
+        /*
+         * If we have no capabilities, this is indicated by cap ID,
+         * cap version and next pointer all being 0.
+         */
+        if (header == 0) {
+            break;
+        }
+
+        if (PCI_EXT_CAP_ID(header) == cap) {
+            return pos;
+        }
+
+        pos = PCI_EXT_CAP_NEXT(header);
+        if (pos < PCI_CONFIG_SPACE_SIZE) {
+            break;
+        }
Quoted 8 lines

hw/xen-host-pci-device.c line 299

Quoted 5 lines
hw/xen-host-pci-device.c new file +5 -0
+
+        max_cap--;
+    } while (max_cap > 0);
+
+    return 0;

If we fail in this function (which can happen [https://bugzilla.redhat.com/show_bug.cgi?id=767742])
shouldn't this function return something else besides 0?

-1 should be good enough, as it's not an offset.

Quoted 1 line

Besides those comments, the patch looks good to me.

Thanks,

Signature · 1 line
Anthony PERARD
#3 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 1/8] pci_ids: Add INTEL_82599_SFP_VF id.

In reply to Konrad Rzeszutek Wilk
Quoted 5 lines · Konrad Rzeszutek Wilk

You really should say why this is added.. It is so odd just to have 'add this' without any justification. Can you at least say:

"We are using this in our quirk lookup provided by patch
titled: XXXYYY" ?

I will add this.

Thanks,

Signature · 1 line
Anthony PERARD
#14 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 4/8] pci.c: Add opaque argument to pci_for_each_device.

In reply to Konrad Rzeszutek Wilk
Quoted 1 line · Konrad Rzeszutek Wilk

What is purpose of it? Can you give more details please?

The purpose is to have a more generic pci_for_each_device by passing a extra argument to the fonction called one every device.

I'll add that to the patch comment.

Signature · 1 line
Anthony PERARD
#11 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH V10 3/8] Introduce XenHostPCIDevice to access a pci device on the host.

In reply to Anthony PERARD
Quoted 37 lines · Anthony PERARD
Quoted 35 lines · Konrad Rzeszutek Wilk

hw/xen-host-pci-device.c line 26

Quoted 6 lines
hw/xen-host-pci-device.c new file +6 -0
+static int xen_host_pci_sysfs_path(const XenHostPCIDevice *d,
+                                   const char *name, char *buf, ssize_t size)
+{
+    int rc;
+
+    rc = snprintf(buf, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/%s",

The format is actually " %04x:%02x:%02x.%d"

Quoted 5 lines

+                  d->domain, d->bus, d->dev, d->func, name); +
+    if (rc >= size || rc < 0) {
+        /* The ouput is truncated or an other error is encountered */
+        return -1;

-ENODEV

hw/xen-host-pci-device.c line 40

Quoted 9 lines

+    }
+    return 0;

hw/xen-host-pci-device.c new file +7 -0
+}
+
+static int xen_host_pci_get_resource(XenHostPCIDevice *d)
+{
+    int i, rc, fd;
+    char path[PATH_MAX];
+    char buf[512];

You should have a #define for the 512.

Quoted 5 lines

+    unsigned long long start, end, flags, size;
+    char *endptr, *s;
+
+    if (xen_host_pci_sysfs_path(d, "resource", path, sizeof (path))) {
+        return -1;

Quoted 6 lines
Quoted 1 line

-ENODEV

I still does not understand why return ENODEV (No such device) when an error occure. Is it the better way to say that a device does not behave like it should, or that a "module" using a device encounter any kind of error that prevent it to use the device ?

That is fine too - there is probably a -Exxx that is exactly for that. Perhaps ENOSPC?

Quoted 211 lines
Quoted 96 lines
Quoted 13 lines

+    }
+    fd = open(path, O_RDONLY);
+    if (fd == -1) {
+        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
+        return -errno;
+    }
+
+    do {
+        rc = read(fd, &buf, sizeof (buf));
+        if (rc < 0 && errno != EINTR) {
+            rc = -errno;

So you are using the errnor types, so you should use them throughout this function.

Quoted 32 lines

+            goto out;
+        }
+    } while (rc < 0);
+    buf[rc] = 0;
+    rc = 0;

hw/xen-host-pci-device.c new file +27 -0
+
+    s = buf;
+    for (i = 0; i < PCI_NUM_REGIONS; i++) {
+        start = strtoll(s, &endptr, 16);
+        if (*endptr != ' ' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+        end = strtoll(s, &endptr, 16);
+        if (*endptr != ' ' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+        flags = strtoll(s, &endptr, 16);
+        if (*endptr != '\n' || s == endptr) {
+            break;
+        }
+        s = endptr + 1;
+
+        if (start) {
+            size = end - start + 1;
+        } else {
+            size = 0;
+        }
+
+        if (i < PCI_ROM_SLOT) {
+            d->io_regions[i].base_addr = start;

hw/xen-host-pci-device.c line 98

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+            d->io_regions[i].size = size;
+            d->io_regions[i].flags = flags;
+        } else {
+            d->rom.base_addr = start;
+            d->rom.size = size;
+            d->rom.flags = flags;
+        }
+    }
+    if (i != PCI_NUM_REGIONS) {
+        rc = -1;

-ENODEV

hw/xen-host-pci-device.c line 110

Quoted 12 lines

+    }

hw/xen-host-pci-device.c new file +11 -0
+
+out:
+    close(fd);
+    return rc;
+}
+
+static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name,
+                                  unsigned int *pvalue, int base)
+{
+    char path[PATH_MAX];
+    char buf[42];

You should use a #define

Quoted 6 lines

+    int fd, rc;
+    unsigned long value;
+    char *endptr;
+
+    if (xen_host_pci_sysfs_path(d, name, path, sizeof (path))) {
+        return -1;

-ENODEV

Quoted 8 lines

+    }
+    fd = open(path, O_RDONLY);
+    if (fd == -1) {
+        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));
+        return -errno;
+    }
+    do {
+        rc = read(fd, &buf, sizeof (buf) - 1);

Quoted 2 lines

Here you have sizeof(buf) - 1, but in the function xen_host_pci_get_resource(..) you didn't do that. Any particular reason?

Nop, it's just a mistake.

Quoted 64 lines
Quoted 9 lines

+        if (rc < 0 && errno != EINTR) {
+            rc = -errno;
+            goto out;
+        }
+    } while (rc < 0);
+    buf[rc] = 0;
+    value = strtol(buf, &endptr, base);
+    if (endptr == buf || *endptr != '\n') {
+        rc = -1;

??? -Exx something I think

Quoted 32 lines

+    } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) {
+        rc = -errno;
+    } else {
+        rc = 0;
+        *pvalue = value;
+    }

hw/xen-host-pci-device.c new file +26 -0
+out:
+    close(fd);
+    return rc;
+}
+
+static inline int xen_host_pci_get_hex_value(XenHostPCIDevice *d,
+                                             const char *name,
+                                             unsigned int *pvalue)
+{
+    return xen_host_pci_get_value(d, name, pvalue, 16);
+}
+
+static inline int xen_host_pci_get_dec_value(XenHostPCIDevice *d,
+                                             const char *name,
+                                             unsigned int *pvalue)
+{
+    return xen_host_pci_get_value(d, name, pvalue, 10);
+}
+
+static bool xen_host_pci_dev_is_virtfn(XenHostPCIDevice *d)
+{
+    char path[PATH_MAX];
+    struct stat buf;
+
+    if (xen_host_pci_sysfs_path(d, "physfn", path, sizeof (path))) {
+        return false;

hw/xen-host-pci-device.c line 175

Quoted 10 lines
hw/xen-host-pci-device.c new file +10 -0
+    }
+    return !stat(path, &buf);
+}
+
+static int xen_host_pci_config_open(XenHostPCIDevice *d)
+{
+    char path[PATH_MAX];
+
+    if (xen_host_pci_sysfs_path(d, "config", path, sizeof (path))) {
+        return -1;

-ENODEV

Quoted 7 lines

+    }
+    d->config_fd = open(path, O_RDWR);
+    if (d->config_fd < 0) {
+        return -errno;
+    }
+    return 0;
+}

[...]

Quoted 26 lines
Quoted 26 lines
hw/xen-host-pci-device.c new file +26 -0
+int xen_host_pci_find_ext_cap_offset(XenHostPCIDevice *d, uint32_t cap)
+{
+    uint32_t header = 0;
+    int max_cap = XEN_HOST_PCI_MAX_EXT_CAP;
+    int pos = PCI_CONFIG_SPACE_SIZE;
+
+    do {
+        if (xen_host_pci_get_long(d, pos, &header)) {
+            break;
+        }
+        /*
+         * If we have no capabilities, this is indicated by cap ID,
+         * cap version and next pointer all being 0.
+         */
+        if (header == 0) {
+            break;
+        }
+
+        if (PCI_EXT_CAP_ID(header) == cap) {
+            return pos;
+        }
+
+        pos = PCI_EXT_CAP_NEXT(header);
+        if (pos < PCI_CONFIG_SPACE_SIZE) {
+            break;
+        }
Quoted 8 lines

hw/xen-host-pci-device.c line 299

Quoted 5 lines
hw/xen-host-pci-device.c new file +5 -0
+
+        max_cap--;
+    } while (max_cap > 0);
+
+    return 0;

If we fail in this function (which can happen [https://bugzilla.redhat.com/show_bug.cgi?id=767742])
shouldn't this function return something else besides 0?

-1 should be good enough, as it's not an offset.

Quoted 1 line

Besides those comments, the patch looks good to me.

Thanks,

Signature · 1 line
Anthony PERARD