Skip to contentSkip to conversation

qemu: make default_write_config use mask table

PATCH Superseded Michael S. Tsirkin 17 participants 319 messages Jun 5, 2009 – Jul 23, 2009 1 message not in the archive Page 1 of 2

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#1 lore raw

PATCH v3 1/13 qemu: make default_write_config use mask table

In reply to a message not in the archive

Change much of hw/pci to use symbolic constants and a table-driven
design: add a mask table with writable bits set and readonly bits unset. Detect change by comparing original and new registers.

This makes it easy to support capabilities where read-only/writeable bit layout differs between devices, depending on capabilities present.

As a result, writing a single byte in BAR registers now works as it should. Writing to upper limit registers in the bridge also works as it should. Code is also shorter.

---
 hw/pci.c |  145 ++++++++++++-------------------------------------------------
 hw/pci.h |   18 +++++++-
 2 files changed, 46 insertions(+), 117 deletions(-)
hw/pci.c +29 -116
index 0ab5b94..235191d 100644
@@ -239,6 +239,17 @@ int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
     return pci_parse_devaddr(devaddr, domp, busp, slotp);
 }
 
+static void pci_init_mask(PCIDevice *dev)
+{
+    int i;
+    dev->wmask[PCI_CACHE_LINE_SIZE] = 0xff;
+    dev->wmask[PCI_INTERRUPT_LINE] = 0xff;
+    dev->wmask[PCI_COMMAND] = PCI_COMMAND_IO | PCI_COMMAND_MEMORY
+                              | PCI_COMMAND_MASTER;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        dev->wmask[i] = 0xff;
+}
+
 /* -1 for devfn means auto assign */
 static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
                                          const char *name, int devfn,
@@ -261,6 +272,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
     memset(pci_dev->irq_state, 0, sizeof(pci_dev->irq_state));
     pci_set_default_subsystem_id(pci_dev);
+    pci_init_mask(pci_dev);
 
     if (!config_read)
         config_read = pci_default_read_config;
@@ -334,6 +346,7 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
 {
     PCIIORegion *r;
     uint32_t addr;
+    uint32_t wmask;
 
     if ((unsigned int)region_num >= PCI_NUM_REGIONS)
         return;
@@ -349,12 +362,17 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     r->size = size;
     r->type = type;
     r->map_func = map_func;
+
+    wmask = ~(size - 1);
     if (region_num == PCI_ROM_SLOT) {
         addr = 0x30;
+        /* ROM enable bit is writeable */
+        wmask |= 1;
     } else {
         addr = 0x10 + region_num * 4;
     }
     *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type);
+    *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
 static void pci_update_mappings(PCIDevice *d)
@@ -463,118 +481,21 @@ uint32_t pci_default_read_config(PCIDevice *d,
     return val;
 }
 
-void pci_default_write_config(PCIDevice *d,
-                              uint32_t address, uint32_t val, int len)
+void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
 {
-    int can_write, i;
-    uint32_t end, addr;
-
-    if (len == 4 && ((address >= 0x10 && address < 0x10 + 4 * 6) ||
-                     (address >= 0x30 && address < 0x34))) {
-        PCIIORegion *r;
-        int reg;
+    uint8_t orig[PCI_CONFIG_SPACE_SIZE];
+    int i;
 
-        if ( address >= 0x30 ) {
-            reg = PCI_ROM_SLOT;
-        }else{
-            reg = (address - 0x10) >> 2;
-        }
-        r = &d->io_regions[reg];
-        if (r->size == 0)
-            goto default_config;
-        /* compute the stored value */
-        if (reg == PCI_ROM_SLOT) {
-            /* keep ROM enable bit */
-            val &= (~(r->size - 1)) | 1;
-        } else {
-            val &= ~(r->size - 1);
-            val |= r->type;
-        }
-        *(uint32_t *)(d->config + address) = cpu_to_le32(val);
-        pci_update_mappings(d);
-        return;
-    }
- default_config:
     /* not efficient, but simple */
-    addr = address;
-    for(i = 0; i < len; i++) {
-        /* default read/write accesses */
-        switch(d->config[0x0e]) {
-        case 0x00:
-        case 0x80:
-            switch(addr) {
-            case 0x00:
-            case 0x01:
-            case 0x02:
-            case 0x03:
-            case 0x06:
-            case 0x07:
-            case 0x08:
-            case 0x09:
-            case 0x0a:
-            case 0x0b:
-            case 0x0e:
-            case 0x10 ... 0x27: /* base */
-            case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */
-            case 0x30 ... 0x33: /* rom */
-            case 0x3d:
-                can_write = 0;
-                break;
-            default:
-                can_write = 1;
-                break;
-            }
-            break;
-        default:
-        case 0x01:
-            switch(addr) {
-            case 0x00:
-            case 0x01:
-            case 0x02:
-            case 0x03:
-            case 0x06:
-            case 0x07:
-            case 0x08:
-            case 0x09:
-            case 0x0a:
-            case 0x0b:
-            case 0x0e:
-            case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */
-            case 0x38 ... 0x3b: /* rom */
-            case 0x3d:
-                can_write = 0;
-                break;
-            default:
-                can_write = 1;
-                break;
-            }
-            break;
-        }
-        if (can_write) {
-            /* Mask out writes to reserved bits in registers */
-            switch (addr) {
-	    case 0x05:
-                val &= ~PCI_COMMAND_RESERVED_MASK_HI;
-                break;
-            case 0x06:
-                val &= ~PCI_STATUS_RESERVED_MASK_LO;
-                break;
-            case 0x07:
-                val &= ~PCI_STATUS_RESERVED_MASK_HI;
-                break;
-            }
-            d->config[addr] = val;
-        }
-        if (++addr > 0xff)
-        	break;
-        val >>= 8;
+    memcpy(orig, d->config, PCI_CONFIG_SPACE_SIZE);
+    for(i = 0; i < l && addr < PCI_CONFIG_SPACE_SIZE; val >>= 8, ++i, ++addr) {
+        uint8_t wmask = d->wmask[addr];
+        d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask);
     }
-
-    end = address + len;
-    if (end > PCI_COMMAND && address < (PCI_COMMAND + 2)) {
-        /* if the command register is modified, we must modify the mappings */
+    if (memcmp(orig + PCI_BASE_ADDRESS_0, d->config + PCI_BASE_ADDRESS_0, 24)
+        || ((orig[PCI_COMMAND] ^ d->config[PCI_COMMAND])
+            & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
         pci_update_mappings(d);
-    }
 }
 
 void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
@@ -847,16 +768,8 @@ static void pci_bridge_write_config(PCIDevice *d,
 {
     PCIBridge *s = (PCIBridge *)d;
 
-    if (address == 0x19 || (address == 0x18 && len > 1)) {
-        if (address == 0x19)
-            s->bus->bus_num = val & 0xff;
-        else
-            s->bus->bus_num = (val >> 8) & 0xff;
-#if defined(DEBUG_PCI)
-        printf ("pci-bridge: %s: Assigned bus %d\n", d->name, s->bus->bus_num);
-#endif
-    }
     pci_default_write_config(d, address, val, len);
+    s->bus->bus_num = d->config[PCI_SECONDARY_BUS];
 }
 
 PCIBus *pci_find_bus(int bus_num)
hw/pci.h +17 -1
index 0405837..d0db402 100644
@@ -100,16 +100,24 @@ typedef struct PCIIORegion {
 #define PCI_COMMAND		0x04	/* 16 bits */
 #define  PCI_COMMAND_IO		0x1	/* Enable response in I/O space */
 #define  PCI_COMMAND_MEMORY	0x2	/* Enable response in Memory space */
+#define  PCI_COMMAND_MASTER	0x4	/* Enable bus master */
 #define PCI_STATUS              0x06    /* 16 bits */
 #define PCI_REVISION_ID         0x08    /* 8 bits  */
 #define PCI_CLASS_DEVICE        0x0a    /* Device class */
+#define PCI_CACHE_LINE_SIZE	0x0c	/* 8 bits */
+#define PCI_LATENCY_TIMER	0x0d	/* 8 bits */
 #define PCI_HEADER_TYPE         0x0e    /* 8 bits */
 #define  PCI_HEADER_TYPE_NORMAL		0
 #define  PCI_HEADER_TYPE_BRIDGE		1
 #define  PCI_HEADER_TYPE_CARDBUS	2
 #define  PCI_HEADER_TYPE_MULTI_FUNCTION 0x80
+#define PCI_BASE_ADDRESS_0	0x10	/* 32 bits */
+#define PCI_PRIMARY_BUS		0x18	/* Primary bus number */
+#define PCI_SECONDARY_BUS	0x19	/* Secondary bus number */
+#define PCI_SEC_STATUS		0x1e	/* Secondary status register, only bit 14 used */
 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c    /* 16 bits */
 #define PCI_SUBSYSTEM_ID        0x2e    /* 16 bits */
+#define PCI_CAPABILITY_LIST	0x34	/* Offset of first capability list entry */
 #define PCI_INTERRUPT_LINE	0x3c	/* 8 bits */
 #define PCI_INTERRUPT_PIN	0x3d	/* 8 bits */
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
@@ -139,10 +147,18 @@ typedef struct PCIIORegion {
 
 #define PCI_COMMAND_RESERVED_MASK_HI (PCI_COMMAND_RESERVED >> 8)
 
+/* Size of the standard PCI config header */
+#define PCI_CONFIG_HEADER_SIZE 0x40
+/* Size of the standard PCI config space */
+#define PCI_CONFIG_SPACE_SIZE 0x100
+
 struct PCIDevice {
     DeviceState qdev;
     /* PCI config space */
-    uint8_t config[256];
+    uint8_t config[PCI_CONFIG_SPACE_SIZE];
+
+    /* Used to implement R/W bytes */
+    uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
     /* the following fields are read only */
     PCIBus *bus;
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#3 lore raw

PATCH v3 2/13 qemu: capability bits in pci save/restore

In reply to a message not in the archive

Add support for capability bits in save/restore for pci. These will be used for MSI, where the capability might be present or not as requested by user, which does not map well into a single version number.

---
 hw/pci.c |   14 ++++++++++++--
 hw/pci.h |    4 ++++
 2 files changed, 16 insertions(+), 2 deletions(-)
hw/pci.c +12 -2
index 235191d..361d741 100644
@@ -127,12 +127,15 @@ int pci_bus_num(PCIBus *s)
 
 void pci_device_save(PCIDevice *s, QEMUFile *f)
 {
+    int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, 2); /* PCI device version */
+    qemu_put_be32(f, version); /* PCI device version */
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
 }
 
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -141,7 +144,7 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     int i;
 
     version_id = qemu_get_be32(f);
-    if (version_id > 2)
+    if (version_id > 3)
         return -EINVAL;
     qemu_get_buffer(f, s->config, 256);
     pci_update_mappings(s);
@@ -149,6 +152,13 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (version_id >= 2)
         for (i = 0; i < 4; i ++)
             s->irq_state[i] = qemu_get_be32(f);
+    if (version_id >= 3)
+        s->cap_present = qemu_get_be32(f);
+    else
+        s->cap_present = 0;
+
+    if (s->cap_present & ~s->cap_supported)
+        return -EINVAL;
 
     return 0;
 }
hw/pci.h +4 -0
index d0db402..6f0803f 100644
@@ -178,6 +178,10 @@ struct PCIDevice {
 
     /* Current IRQ levels.  Used internally by the generic PCI code.  */
     int irq_state[4];
+
+    /* Capability bits for save/load */
+    uint32_t cap_supported;
+    uint32_t cap_present;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#5 lore raw

PATCH v3 3/13 qemu: add routines to manage PCI capabilities

In reply to a message not in the archive

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +89 -9
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }
 
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }
 
@@ -870,3 +877,76 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static int pci_find_space(PCIDevice *pdev, uint8_t size)
+{
+    int offset = PCI_CONFIG_HEADER_SIZE;
+    int i;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        if (pdev->used[i])
+            offset = i + 1;
+        else if (i - offset + 1 == size)
+            return offset;
+    return 0;
+}
+
+static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
+                                        uint8_t *prev_p)
+{
+    uint8_t next, prev;
+
+    if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST))
+        return 0;
+
+    for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
+         prev = next + PCI_CAP_LIST_NEXT)
+        if (pdev->config[next + PCI_CAP_LIST_ID] == cap_id)
+            break;
+
+    *prev_p = prev;
+    return next;
+}
+
+/* Reserve space and add capability to the linked list in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t offset = pci_find_space(pdev, size);
+    uint8_t *config = pdev->config + offset;
+    if (!offset)
+        return -ENOSPC;
+    config[PCI_CAP_LIST_ID] = cap_id;
+    config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
+    pdev->config[PCI_CAPABILITY_LIST] = offset;
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
+    /* Make capability read-only by default */
+    memset(pdev->wmask + offset, 0, size);
+    return offset;
+}
+
+/* Unlink capability from the pci config space. */
+void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev);
+    if (!offset)
+        return;
+    pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];
+    /* Make capability writeable again */
+    memset(pdev->wmask + offset, 0xff, size);
+    memset(pdev->used + offset, 0, size);
+
+    if (!pdev->config[PCI_CAPABILITY_LIST])
+        pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
+}
+
+uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
+{
+    uint8_t prev;
+    return pci_find_capability_list(pdev, cap_id, &prev);
+}
hw/pci.h +17 -1
index 6f0803f..4838c59 100644
@@ -123,6 +123,10 @@ typedef struct PCIIORegion {
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
 #define PCI_MAX_LAT		0x3f	/* 8 bits */
 
+/* Capability lists */
+#define PCI_CAP_LIST_ID		0	/* Capability ID */
+#define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
+
 #define PCI_REVISION            0x08    /* obsolete, use PCI_REVISION_ID */
 #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
 #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
@@ -130,7 +134,7 @@ typedef struct PCIIORegion {
 /* Bits in the PCI Status Register (PCI 2.3 spec) */
 #define PCI_STATUS_RESERVED1	0x007
 #define PCI_STATUS_INT_STATUS	0x008
-#define PCI_STATUS_CAPABILITIES	0x010
+#define PCI_STATUS_CAP_LIST	0x010
 #define PCI_STATUS_66MHZ	0x020
 #define PCI_STATUS_RESERVED2	0x040
 #define PCI_STATUS_FAST_BACK	0x080
@@ -160,6 +164,9 @@ struct PCIDevice {
     /* Used to implement R/W bytes */
     uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
+    /* Used to allocate config space for capabilities. */
+    uint8_t used[PCI_CONFIG_SPACE_SIZE];
+
     /* the following fields are read only */
     PCIBus *bus;
     int devfn;
@@ -194,6 +201,15 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
+uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
+
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#280 lore raw

PATCH v3 4/13 qemu: helper routines for pci access.

In reply to a message not in the archive

Add inline routines for convenient access to pci devices with correct (little) endianness. Will be used by MSI-X support.

---
 hw/pci.h |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)
hw/pci.h +27 -3
index 4838c59..477aa64 100644
@@ -240,21 +240,45 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
                         pci_map_irq_fn map_irq, const char *name);
 
 static inline void
+pci_set_word(uint8_t *config, uint16_t val)
+{
+    cpu_to_le16wu((uint16_t *)config, val);
+}
+
+static inline uint16_t
+pci_get_word(uint8_t *config)
+{
+    return le16_to_cpupu((uint16_t *)config);
+}
+
+static inline void
+pci_set_long(uint8_t *config, uint32_t val)
+{
+    cpu_to_le32wu((uint32_t *)config, val);
+}
+
+static inline uint32_t
+pci_get_long(uint8_t *config)
+{
+    return le32_to_cpupu((uint32_t *)config);
+}
+
+static inline void
 pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val)
 {
-    cpu_to_le16wu((uint16_t *)&pci_config[PCI_VENDOR_ID], val);
+    pci_set_word(&pci_config[PCI_VENDOR_ID], val);
 }
 
 static inline void
 pci_config_set_device_id(uint8_t *pci_config, uint16_t val)
 {
-    cpu_to_le16wu((uint16_t *)&pci_config[PCI_DEVICE_ID], val);
+    pci_set_word(&pci_config[PCI_DEVICE_ID], val);
 }
 
 static inline void
 pci_config_set_class(uint8_t *pci_config, uint16_t val)
 {
-    cpu_to_le16wu((uint16_t *)&pci_config[PCI_CLASS_DEVICE], val);
+    pci_set_word(&pci_config[PCI_CLASS_DEVICE], val);
 }
 
 typedef void (*pci_qdev_initfn)(PCIDevice *dev);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#282 lore raw

PATCH v3 5/13 qemu: MSI-X support functions

In reply to a message not in the archive

Add functions implementing MSI-X support. First user will be virtio-pci. Note that platform must set a flag to declare MSI supported. For PC this will be set by APIC.

---
 Makefile.target |    2 +-
 hw/msix.c       |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/msix.h       |   35 +++++
 hw/pci.h        |   20 +++
 4 files changed, 479 insertions(+), 1 deletions(-)
 create mode 100644 hw/msix.c
 create mode 100644 hw/msix.h
Makefile.target +1 -1
index 664a1e3..87b2859 100644
@@ -486,7 +486,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o msix.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
hw/msix.c new file +423 -0

423 lines not on this page · raw message

hw/msix.h new file +35 -0
new file mode 100644
index 0000000..79e84a3
@@ -0,0 +1,35 @@
+#ifndef QEMU_MSIX_H
+#define QEMU_MSIX_H
+
+#include "qemu-common.h"
+
+int msix_init(PCIDevice *pdev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size);
+
+void msix_write_config(PCIDevice *pci_dev, uint32_t address,
+                       uint32_t val, int len);
+
+void msix_mmio_map(PCIDevice *pci_dev, int region_num,
+                   uint32_t addr, uint32_t size, int type);
+
+int msix_uninit(PCIDevice *d);
+
+void msix_save(PCIDevice *dev, QEMUFile *f);
+int msix_load(PCIDevice *dev, QEMUFile *f);
+
+int msix_enabled(PCIDevice *dev);
+int msix_present(PCIDevice *dev);
+
+uint32_t msix_bar_size(PCIDevice *dev);
+
+int msix_vector_use(PCIDevice *dev, unsigned vector);
+void msix_vector_unuse(PCIDevice *dev, unsigned vector);
+
+void msix_notify(PCIDevice *dev, unsigned vector);
+
+void msix_reset(PCIDevice *dev);
+
+extern int msix_disable;
+extern int msix_supported;
+
+#endif
hw/pci.h +20 -0
index 477aa64..98a34ee 100644
@@ -156,6 +156,11 @@ typedef struct PCIIORegion {
 /* Size of the standard PCI config space */
 #define PCI_CONFIG_SPACE_SIZE 0x100
 
+/* Bits in cap_supported/cap_present fields. */
+enum {
+    QEMU_PCI_CAP_MSIX = 0x1,
+};
+
 struct PCIDevice {
     DeviceState qdev;
     /* PCI config space */
@@ -189,6 +194,21 @@ struct PCIDevice {
     /* Capability bits for save/load */
     uint32_t cap_supported;
     uint32_t cap_present;
+
+    /* Offset of MSI-X capability in config space */
+    uint8_t msix_cap;
+
+    /* MSI-X entries */
+    int msix_entries_nr;
+
+    /* Space to store MSIX table */
+    uint8_t *msix_table_page;
+    /* MMIO index used to map MSIX table and pending bit entries. */
+    int msix_mmio_index;
+    /* Reference-count for entries actually in use by driver. */
+    unsigned *msix_entry_used;
+    /* Region including the MSI-X table */
+    uint32_t msix_bar_size;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#288 lore raw

PATCH v3 6/13 qemu: add flag to disable MSI-X by default

In reply to a message not in the archive

Add global flag to disable MSI-X by default. This is useful primarily to make images loadable by older qemu (without msix). Even when MSI-X is disabled by flag, you can still load images that have MSI-X enabled.

---
 hw/msix.c       |    3 +++
 qemu-options.hx |    2 ++
 vl.c            |    3 +++
 3 files changed, 8 insertions(+), 0 deletions(-)
hw/msix.c +3 -0
index 1b5aec8..ada81d8 100644
@@ -122,6 +122,9 @@ void msix_write_config(PCIDevice *dev, uint32_t addr,
                        uint32_t val, int len)
 {
     unsigned enable_pos = dev->msix_cap + MSIX_ENABLE_OFFSET;
+    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+        return;
+
     if (addr + len <= enable_pos || addr > enable_pos)
         return;
 
qemu-options.hx +2 -0
index 87af798..fd041a4 100644
@@ -1575,3 +1575,5 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting,
 DEF("old-param", 0, QEMU_OPTION_old_param,
     "-old-param      old param mode\n")
 #endif
+DEF("disable-msix", 0, QEMU_OPTION_disable_msix,
+    "-disable-msix disable msix support for PCI devices (enabled by default)\n")
vl.c +3 -0
index 2c1f0e0..2757d4f 100644
@@ -134,6 +134,7 @@ int main(int argc, char **argv)
 #include "hw/usb.h"
 #include "hw/pcmcia.h"
 #include "hw/pc.h"
+#include "hw/msix.h"
 #include "hw/audiodev.h"
 #include "hw/isa.h"
 #include "hw/baum.h"
@@ -5557,6 +5558,8 @@ int main(int argc, char **argv, char **envp)
                 xen_mode = XEN_ATTACH;
                 break;
 #endif
+            case QEMU_OPTION_disable_msix:
+                msix_disable = 1;
             }
         }
     }
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#290 lore raw

PATCH v3 7/13 qemu: minimal MSI/MSI-X implementation for PC

In reply to a message not in the archive

Implement MSI support in APIC. Note that MSI and MMIO APIC registers are at the same memory location, but actually not on the global bus: MSI is on PCI bus, APIC is connected directly to the CPU. We map them on the global bus at the same address which happens to work because MSI registers are reserved in APIC MMIO and vice versa.

---
 hw/apic.c |   43 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 39 insertions(+), 4 deletions(-)
hw/apic.c +39 -4
index 8c8b2de..ed03a36 100644
@@ -19,6 +19,8 @@
  */
 #include "hw.h"
 #include "pc.h"
+#include "pci.h"
+#include "msix.h"
 #include "qemu-timer.h"
 #include "host-utils.h"
 
@@ -63,6 +65,19 @@
 #define MAX_APICS 255
 #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 MSI_ADDR_BASE                   0xfee00000
+#define MSI_ADDR_SIZE                   0x100000
+
 typedef struct APICState {
     CPUState *cpu_env;
     uint32_t apicbase;
@@ -712,11 +727,31 @@ static uint32_t apic_mem_readl(void *opaque, target_phys_addr_t addr)
     return val;
 }
 
+static void apic_send_msi(target_phys_addr_t addr, uint32 data)
+{
+    uint8_t dest = (addr & MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT;
+    uint8_t vector = (data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT;
+    uint8_t dest_mode = (addr >> MSI_ADDR_DEST_MODE_SHIFT) & 0x1;
+    uint8_t trigger_mode = (data >> MSI_DATA_TRIGGER_SHIFT) & 0x1;
+    uint8_t delivery = (data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x7;
+    /* XXX: Ignore redirection hint. */
+    apic_deliver_irq(dest, dest_mode, delivery, vector, 0, trigger_mode);
+}
+
 static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     CPUState *env;
     APICState *s;
-    int index;
+    int index = (addr >> 4) & 0xff;
+    if (addr > 0xfff || !index) {
+        /* MSI and MMIO APIC are at the same memory location,
+         * but actually not on the global bus: MSI is on PCI bus
+         * APIC is connected directly to the CPU.
+         * Mapping them on the global bus happens to work because
+         * MSI registers are reserved in APIC MMIO and vice versa. */
+        apic_send_msi(addr, val);
+        return;
+    }
 
     env = cpu_single_env;
     if (!env)
@@ -727,7 +762,6 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     printf("APIC write: %08x = %08x\n", (uint32_t)addr, val);
 #endif
 
-    index = (addr >> 4) & 0xff;
     switch(index) {
     case 0x02:
         s->id = (val >> 24);
@@ -911,6 +945,7 @@ int apic_init(CPUState *env)
     s->cpu_env = env;
 
     apic_reset(s);
+    msix_supported = 1;
 
     /* XXX: mapping more APICs at the same memory location */
     if (apic_io_memory == 0) {
@@ -918,7 +953,8 @@ int apic_init(CPUState *env)
            on the global memory bus. */
         apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
                                                 apic_mem_write, NULL);
-        cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
+        /* XXX: what if the base changes? */
+        cpu_register_physical_memory(MSI_ADDR_BASE, MSI_ADDR_SIZE,
                                      apic_io_memory);
     }
     s->timer = qemu_new_timer(vm_clock, apic_timer, s);
@@ -929,4 +965,3 @@ int apic_init(CPUState *env)
     local_apics[s->id] = s;
     return 0;
 }
-
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#296 lore raw

PATCH v3 8/13 qemu: add support for resizing regions

In reply to a message not in the archive

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +36 -18
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+
 static void pci_update_mappings(PCIDevice *d)
 {
     PCIIORegion *r;
@@ -445,24 +480,7 @@ static void pci_update_mappings(PCIDevice *d)
             }
             /* now do the real mapping */
             if (new_addr != r->addr) {
-                if (r->addr != -1) {
-                    if (r->type & PCI_ADDRESS_SPACE_IO) {
-                        int class;
-                        /* NOTE: specific hack for IDE in PC case:
-                           only one byte must be mapped. */
-                        class = d->config[0x0a] | (d->config[0x0b] << 8);
-                        if (class == 0x0101 && r->size == 4) {
-                            isa_unassign_ioport(r->addr + 2, 1);
-                        } else {
-                            isa_unassign_ioport(r->addr, r->size);
-                        }
-                    } else {
-                        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
-                                                     r->size,
-                                                     IO_MEM_UNASSIGNED);
-                        qemu_unregister_coalesced_mmio(r->addr, r->size);
-                    }
-                }
+                pci_unmap_region(d, r);
                 r->addr = new_addr;
                 if (r->addr != -1) {
                     r->map_func(d, i, r->addr, r->size, r->type);
hw/pci.h +3 -0
index 98a34ee..8e74033 100644
@@ -221,6 +221,9 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size);
+
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#304 lore raw

PATCH v3 9/13 qemu: virtio support for many interrupt vectors

In reply to a message not in the archive

Extend virtio to support many interrupt vectors, and rearrange code in preparation for multi-vector support (mostly move reset out to bindings, because we will have to reset the vectors in transport-specific code). Actual bindings in pci, and use in net, to follow.
Load and save are not connected to bindings yet, so they are left stubbed out for now.

---
 hw/syborg_virtio.c |   13 ++++++++--
 hw/virtio-pci.c    |   24 +++++++++++++++----
 hw/virtio.c        |   63 ++++++++++++++++++++++++++++++++++++++-------------
 hw/virtio.h        |   10 ++++++-
 4 files changed, 84 insertions(+), 26 deletions(-)
hw/syborg_virtio.c +10 -3
index 37c219c..d8c978a 100644
@@ -134,7 +134,10 @@ static void syborg_virtio_writel(void *opaque, target_phys_addr_t offset,
         vdev->features = value;
         break;
     case SYBORG_VIRTIO_QUEUE_BASE:
-        virtio_queue_set_addr(vdev, vdev->queue_sel, value);
+        if (value == 0)
+            virtio_reset(vdev);
+        else
+            virtio_queue_set_addr(vdev, vdev->queue_sel, value);
         break;
     case SYBORG_VIRTIO_QUEUE_SEL:
         if (value < VIRTIO_PCI_QUEUE_MAX)
@@ -228,7 +231,7 @@ static CPUWriteMemoryFunc *syborg_virtio_writefn[] = {
      syborg_virtio_writel
 };
 
-static void syborg_virtio_update_irq(void *opaque)
+static void syborg_virtio_update_irq(void *opaque, uint16_t vector)
 {
     SyborgVirtIOProxy *proxy = opaque;
     int level;
@@ -239,7 +242,7 @@ static void syborg_virtio_update_irq(void *opaque)
 }
 
 static VirtIOBindings syborg_virtio_bindings = {
-    .update_irq = syborg_virtio_update_irq
+    .notify = syborg_virtio_update_irq
 };
 
 static void syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev)
@@ -248,6 +251,8 @@ static void syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev)
 
     proxy->vdev = vdev;
 
+    /* Don't support multiple vectors */
+    proxy->vdev->nvectors = 0;
     sysbus_init_irq(&proxy->busdev, &proxy->irq);
     iomemtype = cpu_register_io_memory(0, syborg_virtio_readfn,
                                        syborg_virtio_writefn, proxy);
@@ -255,6 +260,8 @@ static void syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev)
 
     proxy->id = ((uint32_t)0x1af4 << 16) | vdev->device_id;
 
+    qemu_register_reset(virtio_reset, 0, vdev);
+
     virtio_bind_device(vdev, &syborg_virtio_bindings, proxy);
 }
 
hw/virtio-pci.c +19 -5
index c072423..7dfdd80 100644
@@ -78,13 +78,19 @@ typedef struct {
 
 /* virtio device */
 
-static void virtio_pci_update_irq(void *opaque)
+static void virtio_pci_notify(void *opaque, uint16_t vector)
 {
     VirtIOPCIProxy *proxy = opaque;
 
     qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }
 
+static void virtio_pci_reset(void *opaque)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    virtio_reset(proxy->vdev);
+}
+
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
@@ -108,7 +114,10 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         break;
     case VIRTIO_PCI_QUEUE_PFN:
         pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
-        virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
+        if (pa == 0)
+            virtio_pci_reset(proxy);
+        else
+            virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
         break;
     case VIRTIO_PCI_QUEUE_SEL:
         if (val < VIRTIO_PCI_QUEUE_MAX)
@@ -120,7 +129,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     case VIRTIO_PCI_STATUS:
         vdev->status = val & 0xFF;
         if (vdev->status == 0)
-            virtio_reset(vdev);
+            virtio_pci_reset(proxy);
         break;
     }
 }
@@ -158,7 +167,7 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
         /* reading from the ISR also clears it. */
         ret = vdev->isr;
         vdev->isr = 0;
-        virtio_update_irq(vdev);
+        qemu_set_irq(proxy->pci_dev.irq[0], 0);
         break;
     default:
         break;
@@ -243,7 +252,7 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
-    .update_irq = virtio_pci_update_irq
+    .notify = virtio_pci_notify
 };
 
 static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
@@ -255,6 +264,9 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     proxy->vdev = vdev;
 
+    /* No support for multiple vectors yet. */
+    proxy->vdev->nvectors = 0;
+
     config = proxy->pci_dev.config;
     pci_config_set_vendor_id(config, vendor);
     pci_config_set_device_id(config, device);
@@ -279,6 +291,8 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
     pci_register_io_region(&proxy->pci_dev, 0, size, PCI_ADDRESS_SPACE_IO,
                            virtio_map);
 
+    qemu_register_reset(virtio_pci_reset, 0, proxy);
+
     virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
 }
 
hw/virtio.c +47 -16

166 lines not on this page · raw message

hw/virtio.h +8 -2
index 425727e..04a3c3d 100644
@@ -71,11 +71,13 @@ typedef struct VirtQueueElement
 } VirtQueueElement;
 
 typedef struct {
-    void (*update_irq)(void * opaque);
+    void (*notify)(void * opaque, uint16_t vector);
 } VirtIOBindings;
 
 #define VIRTIO_PCI_QUEUE_MAX 16
 
+#define VIRTIO_NO_VECTOR 0xffff
+
 struct VirtIODevice
 {
     const char *name;
@@ -85,6 +87,8 @@ struct VirtIODevice
     uint32_t features;
     size_t config_len;
     void *config;
+    uint16_t config_vector;
+    int nvectors;
     uint32_t (*get_features)(VirtIODevice *vdev);
     uint32_t (*bad_features)(VirtIODevice *vdev);
     void (*set_features)(VirtIODevice *vdev, uint32_t val);
@@ -114,7 +118,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
 
 void virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
-void virtio_load(VirtIODevice *vdev, QEMUFile *f);
+int virtio_load(VirtIODevice *vdev, QEMUFile *f);
 
 void virtio_cleanup(VirtIODevice *vdev);
 
@@ -140,6 +144,8 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr);
 target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n);
 int virtio_queue_get_num(VirtIODevice *vdev, int n);
 void virtio_queue_notify(VirtIODevice *vdev, int n);
+uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
+void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#306 lore raw

PATCH v3 10/13 qemu: MSI-X support in virtio PCI

In reply to a message not in the archive

This enables actual support for MSI-X in virtio PCI. First user will be virtio-net.

---
 hw/virtio-pci.c |  152 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 112 insertions(+), 40 deletions(-)
hw/virtio-pci.c +112 -40
index 7dfdd80..294f4c7 100644
@@ -18,6 +18,7 @@
 #include "virtio.h"
 #include "pci.h"
 //#include "sysemu.h"
+#include "msix.h"
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -47,7 +48,24 @@
  * a read-and-acknowledge. */
 #define VIRTIO_PCI_ISR                  19
 
-#define VIRTIO_PCI_CONFIG               20
+/* MSI-X registers: only enabled if MSI-X is enabled. */
+/* A 16-bit vector for configuration changes. */
+#define VIRTIO_MSI_CONFIG_VECTOR        20
+/* A 16-bit vector for selected queue notifications. */
+#define VIRTIO_MSI_QUEUE_VECTOR         22
+
+/* Config space size */
+#define VIRTIO_PCI_CONFIG_NOMSI         20
+#define VIRTIO_PCI_CONFIG_MSI           24
+#define VIRTIO_PCI_REGION_SIZE(dev)     (msix_present(dev) ? \
+                                         VIRTIO_PCI_CONFIG_MSI : \
+                                         VIRTIO_PCI_CONFIG_NOMSI)
+
+/* The remaining space is defined by each driver as the per-driver
+ * configuration space */
+#define VIRTIO_PCI_CONFIG(dev)          (msix_enabled(dev) ? \
+                                         VIRTIO_PCI_CONFIG_MSI : \
+                                         VIRTIO_PCI_CONFIG_NOMSI)
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
@@ -81,14 +99,17 @@ typedef struct {
 static void virtio_pci_notify(void *opaque, uint16_t vector)
 {
     VirtIOPCIProxy *proxy = opaque;
-
-    qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
+    if (msix_enabled(&proxy->pci_dev))
+        msix_notify(&proxy->pci_dev, vector);
+    else
+        qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }
 
 static void virtio_pci_reset(void *opaque)
 {
     VirtIOPCIProxy *proxy = opaque;
     virtio_reset(proxy->vdev);
+    msix_reset(&proxy->pci_dev);
 }
 
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
@@ -97,8 +118,6 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     VirtIODevice *vdev = proxy->vdev;
     target_phys_addr_t pa;
 
-    addr -= proxy->addr;
-
     switch (addr) {
     case VIRTIO_PCI_GUEST_FEATURES:
 	/* Guest does not negotiate properly?  We have to assume nothing. */
@@ -131,17 +150,33 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         if (vdev->status == 0)
             virtio_pci_reset(proxy);
         break;
+    case VIRTIO_MSI_CONFIG_VECTOR:
+        msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
+        /* Make it possible for guest to discover an error took place. */
+        if (msix_vector_use(&proxy->pci_dev, val) < 0)
+            val = VIRTIO_NO_VECTOR;
+        vdev->config_vector = val;
+        break;
+    case VIRTIO_MSI_QUEUE_VECTOR:
+        msix_vector_unuse(&proxy->pci_dev,
+                          virtio_queue_vector(vdev, vdev->queue_sel));
+        /* Make it possible for guest to discover an error took place. */
+        if (msix_vector_use(&proxy->pci_dev, val) < 0)
+            val = VIRTIO_NO_VECTOR;
+        virtio_queue_set_vector(vdev, vdev->queue_sel, val);
+        break;
+    default:
+        fprintf(stderr, "%s: unexpected address 0x%x value 0x%x\n",
+                __func__, addr, val);
+        break;
     }
 }
 
-static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
+static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
 {
-    VirtIOPCIProxy *proxy = opaque;
     VirtIODevice *vdev = proxy->vdev;
     uint32_t ret = 0xFFFFFFFF;
 
-    addr -= proxy->addr;
-
     switch (addr) {
     case VIRTIO_PCI_HOST_FEATURES:
         ret = vdev->get_features(vdev);
@@ -169,6 +204,12 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
         vdev->isr = 0;
         qemu_set_irq(proxy->pci_dev.irq[0], 0);
         break;
+    case VIRTIO_MSI_CONFIG_VECTOR:
+        ret = vdev->config_vector;
+        break;
+    case VIRTIO_MSI_QUEUE_VECTOR:
+        ret = virtio_queue_vector(vdev, vdev->queue_sel);
+        break;
     default:
         break;
     }
@@ -179,42 +220,72 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
 static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config)
+        return virtio_ioport_read(proxy, addr);
+    addr -= config;
     return virtio_config_readb(proxy->vdev, addr);
 }
 
 static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config)
+        return virtio_ioport_read(proxy, addr);
+    addr -= config;
     return virtio_config_readw(proxy->vdev, addr);
 }
 
 static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config)
+        return virtio_ioport_read(proxy, addr);
+    addr -= config;
     return virtio_config_readl(proxy->vdev, addr);
 }
 
 static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config) {
+        virtio_ioport_write(proxy, addr, val);
+        return;
+    }
+    addr -= config;
     virtio_config_writeb(proxy->vdev, addr, val);
 }
 
 static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config) {
+        virtio_ioport_write(proxy, addr, val);
+        return;
+    }
+    addr -= config;
     virtio_config_writew(proxy->vdev, addr, val);
 }
 
 static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config) {
+        virtio_ioport_write(proxy, addr, val);
+        return;
+    }
+    addr -= config;
     virtio_config_writel(proxy->vdev, addr, val);
 }
 
@@ -223,32 +294,26 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 {
     VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev);
     VirtIODevice *vdev = proxy->vdev;
-    int i;
+    unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
 
     proxy->addr = addr;
-    for (i = 0; i < 3; i++) {
-        register_ioport_write(addr, VIRTIO_PCI_CONFIG, 1 << i,
-                              virtio_ioport_write, proxy);
-        register_ioport_read(addr, VIRTIO_PCI_CONFIG, 1 << i,
-                             virtio_ioport_read, proxy);
-    }
 
-    if (vdev->config_len) {
-        register_ioport_write(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 1,
-                              virtio_pci_config_writeb, proxy);
-        register_ioport_write(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 2,
-                              virtio_pci_config_writew, proxy);
-        register_ioport_write(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 4,
-                              virtio_pci_config_writel, proxy);
-        register_ioport_read(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 1,
-                             virtio_pci_config_readb, proxy);
-        register_ioport_read(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 2,
-                             virtio_pci_config_readw, proxy);
-        register_ioport_read(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 4,
-                             virtio_pci_config_readl, proxy);
+    register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
+    register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
+    register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
+    register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
+    register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
+    register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
 
+    if (vdev->config_len)
         vdev->get_config(vdev, vdev->config);
-    }
+}
+
+static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
+                                uint32_t val, int len)
+{
+    pci_default_write_config(pci_dev, address, val, len);
+    msix_write_config(pci_dev, address, val, len);
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
@@ -264,9 +329,6 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     proxy->vdev = vdev;
 
-    /* No support for multiple vectors yet. */
-    proxy->vdev->nvectors = 0;
-
     config = proxy->pci_dev.config;
     pci_config_set_vendor_id(config, vendor);
     pci_config_set_device_id(config, device);
@@ -284,7 +346,17 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     config[0x3d] = 1;
 
-    size = 20 + vdev->config_len;
+    if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) {
+        pci_register_io_region(&proxy->pci_dev, 1,
+                               msix_bar_size(&proxy->pci_dev),
+                               PCI_ADDRESS_SPACE_MEM,
+                               msix_mmio_map);
+        proxy->pci_dev.config_write = virtio_write_config;
+        proxy->pci_dev.unregister = msix_uninit;
+    } else
+        vdev->nvectors = 0;
+
+    size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len;
     if (size & (size-1))
         size = 1 << qemu_fls(size);
 
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#308 lore raw

PATCH v3 11/13 qemu: request 3 vectors in virtio-net

In reply to a message not in the archive

Request up to 3 vectors in virtio-net. Actual bindings might supply less.

---
 hw/virtio-net.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/virtio-net.c +1 -0
index 60aa6da..6118fe3 100644
@@ -621,6 +621,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev)
     n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
 
     n->vlans = qemu_mallocz(MAX_VLAN >> 3);
+    n->vdev.nvectors = 3;
 
     register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#310 lore raw

PATCH v3 12/13 qemu: virtio save/load bindings

In reply to a message not in the archive

Implement bindings for virtio save/load. Use them in virtio pci.

---
 hw/virtio-pci.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/virtio.c     |   31 ++++++++++++++-----------------
 hw/virtio.h     |    4 ++++
 3 files changed, 66 insertions(+), 18 deletions(-)
hw/virtio-pci.c +48 -1
index 294f4c7..589fbb1 100644
@@ -105,6 +105,48 @@ static void virtio_pci_notify(void *opaque, uint16_t vector)
         qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }
 
+static void virtio_pci_save_config(void * opaque, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    pci_device_save(&proxy->pci_dev, f);
+    msix_save(&proxy->pci_dev, f);
+    if (msix_present(&proxy->pci_dev))
+        qemu_put_be16(f, proxy->vdev->config_vector);
+}
+
+static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    if (msix_present(&proxy->pci_dev))
+        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
+}
+
+static int virtio_pci_load_config(void * opaque, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    int ret;
+    ret = pci_device_load(&proxy->pci_dev, f);
+    if (ret)
+        return ret;
+    ret = msix_load(&proxy->pci_dev, f);
+    if (ret)
+        return ret;
+    if (msix_present(&proxy->pci_dev))
+        qemu_get_be16s(f, &proxy->vdev->config_vector);
+    return 0;
+}
+
+static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    uint16_t vector;
+    if (!msix_present(&proxy->pci_dev))
+        return 0;
+    qemu_get_be16s(f, &vector);
+    virtio_queue_set_vector(proxy->vdev, n, vector);
+    return 0;
+}
+
 static void virtio_pci_reset(void *opaque)
 {
     VirtIOPCIProxy *proxy = opaque;
@@ -317,7 +359,12 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
-    .notify = virtio_pci_notify
+    .notify = virtio_pci_notify,
+    .save_config = virtio_pci_save_config,
+    .load_config = virtio_pci_load_config,
+    .save_config = virtio_pci_save_config,
+    .save_queue = virtio_pci_save_queue,
+    .load_queue = virtio_pci_load_queue,
 };
 
 static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
hw/virtio.c +14 -17
index 63ffcff..b773dff 100644
@@ -568,9 +568,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
     int i;
 
-    /* FIXME: load/save binding.  */
-    //pci_device_save(&vdev->pci_dev, f);
-    //msix_save(&vdev->pci_dev, f);
+    if (vdev->binding->save_config)
+        vdev->binding->save_config(vdev->binding_opaque, f);
 
     qemu_put_8s(f, &vdev->status);
     qemu_put_8s(f, &vdev->isr);
@@ -596,19 +595,20 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
         qemu_put_be32(f, vdev->vq[i].vring.num);
         qemu_put_be64(f, vdev->vq[i].pa);
         qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
-        if (vdev->nvectors)
-            qemu_put_be16s(f, &vdev->vq[i].vector);
+        if (vdev->binding->save_queue)
+            vdev->binding->save_queue(vdev->binding_opaque, i, f);
     }
 }
 
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
-    int num, i;
+    int num, i, ret;
 
-    /* FIXME: load/save binding.  */
-    //pci_device_load(&vdev->pci_dev, f);
-    //r = msix_load(&vdev->pci_dev, f);
-    //pci_resize_io_region(&vdev->pci_dev, 1, msix_bar_size(&vdev->pci_dev));
+    if (vdev->binding->load_config) {
+        ret = vdev->binding->load_config(vdev->binding_opaque, f);
+        if (ret)
+            return ret;
+    }
 
     qemu_get_8s(f, &vdev->status);
     qemu_get_8s(f, &vdev->isr);
@@ -617,10 +617,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
     vdev->config_len = qemu_get_be32(f);
     qemu_get_buffer(f, vdev->config, vdev->config_len);
 
-    if (vdev->nvectors) {
-        qemu_get_be16s(f, &vdev->config_vector);
-        //msix_vector_use(&vdev->pci_dev, vdev->config_vector);
-    }
     num = qemu_get_be32(f);
 
     for (i = 0; i < num; i++) {
@@ -631,9 +627,10 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
         if (vdev->vq[i].pa) {
             virtqueue_init(&vdev->vq[i]);
         }
-        if (vdev->nvectors) {
-            qemu_get_be16s(f, &vdev->vq[i].vector);
-            //msix_vector_use(&vdev->pci_dev, vdev->config_vector);
+        if (vdev->binding->load_queue) {
+            ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);
+            if (ret)
+                return ret;
         }
     }
 
hw/virtio.h +4 -0
index 04a3c3d..ce05517 100644
@@ -72,6 +72,10 @@ typedef struct VirtQueueElement
 
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
+    void (*save_config)(void * opaque, QEMUFile *f);
+    void (*save_queue)(void * opaque, int n, QEMUFile *f);
+    int (*load_config)(void * opaque, QEMUFile *f);
+    int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;
 
 #define VIRTIO_PCI_QUEUE_MAX 16
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#318 lore raw

PATCH v3 13/13 qemu: add pci_get/set_byte

In reply to a message not in the archive

Add pci_get/set_byte to keep *_word and *_long access functions company. They are unused for now.

---
 hw/pci.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/pci.h +12 -0
index 8e74033..7cc9a8a 100644
@@ -263,6 +263,18 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
                         pci_map_irq_fn map_irq, const char *name);
 
 static inline void
+pci_set_byte(uint8_t *config, uint8_t val)
+{
+    *config = val;
+}
+
+static inline uint8_t
+pci_get_byte(uint8_t *config)
+{
+    return *config;
+}
+
+static inline void
 pci_set_word(uint8_t *config, uint16_t val)
 {
     cpu_to_le16wu((uint16_t *)config, val);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#2 lore raw

PATCH v3 1/13 qemu: make default_write_config use mask table

In reply to a message not in the archive

Change much of hw/pci to use symbolic constants and a table-driven
design: add a mask table with writable bits set and readonly bits unset. Detect change by comparing original and new registers.

This makes it easy to support capabilities where read-only/writeable bit layout differs between devices, depending on capabilities present.

As a result, writing a single byte in BAR registers now works as it should. Writing to upper limit registers in the bridge also works as it should. Code is also shorter.

---
 hw/pci.c |  145 ++++++++++++-------------------------------------------------
 hw/pci.h |   18 +++++++-
 2 files changed, 46 insertions(+), 117 deletions(-)
hw/pci.c +29 -116
index 0ab5b94..235191d 100644
@@ -239,6 +239,17 @@ int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
     return pci_parse_devaddr(devaddr, domp, busp, slotp);
 }
 
+static void pci_init_mask(PCIDevice *dev)
+{
+    int i;
+    dev->wmask[PCI_CACHE_LINE_SIZE] = 0xff;
+    dev->wmask[PCI_INTERRUPT_LINE] = 0xff;
+    dev->wmask[PCI_COMMAND] = PCI_COMMAND_IO | PCI_COMMAND_MEMORY
+                              | PCI_COMMAND_MASTER;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        dev->wmask[i] = 0xff;
+}
+
 /* -1 for devfn means auto assign */
 static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
                                          const char *name, int devfn,
@@ -261,6 +272,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
     memset(pci_dev->irq_state, 0, sizeof(pci_dev->irq_state));
     pci_set_default_subsystem_id(pci_dev);
+    pci_init_mask(pci_dev);
 
     if (!config_read)
         config_read = pci_default_read_config;
@@ -334,6 +346,7 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
 {
     PCIIORegion *r;
     uint32_t addr;
+    uint32_t wmask;
 
     if ((unsigned int)region_num >= PCI_NUM_REGIONS)
         return;
@@ -349,12 +362,17 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     r->size = size;
     r->type = type;
     r->map_func = map_func;
+
+    wmask = ~(size - 1);
     if (region_num == PCI_ROM_SLOT) {
         addr = 0x30;
+        /* ROM enable bit is writeable */
+        wmask |= 1;
     } else {
         addr = 0x10 + region_num * 4;
     }
     *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type);
+    *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
 static void pci_update_mappings(PCIDevice *d)
@@ -463,118 +481,21 @@ uint32_t pci_default_read_config(PCIDevice *d,
     return val;
 }
 
-void pci_default_write_config(PCIDevice *d,
-                              uint32_t address, uint32_t val, int len)
+void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
 {
-    int can_write, i;
-    uint32_t end, addr;
-
-    if (len == 4 && ((address >= 0x10 && address < 0x10 + 4 * 6) ||
-                     (address >= 0x30 && address < 0x34))) {
-        PCIIORegion *r;
-        int reg;
+    uint8_t orig[PCI_CONFIG_SPACE_SIZE];
+    int i;
 
-        if ( address >= 0x30 ) {
-            reg = PCI_ROM_SLOT;
-        }else{
-            reg = (address - 0x10) >> 2;
-        }
-        r = &d->io_regions[reg];
-        if (r->size == 0)
-            goto default_config;
-        /* compute the stored value */
-        if (reg == PCI_ROM_SLOT) {
-            /* keep ROM enable bit */
-            val &= (~(r->size - 1)) | 1;
-        } else {
-            val &= ~(r->size - 1);
-            val |= r->type;
-        }
-        *(uint32_t *)(d->config + address) = cpu_to_le32(val);
-        pci_update_mappings(d);
-        return;
-    }
- default_config:
     /* not efficient, but simple */
-    addr = address;
-    for(i = 0; i < len; i++) {
-        /* default read/write accesses */
-        switch(d->config[0x0e]) {
-        case 0x00:
-        case 0x80:
-            switch(addr) {
-            case 0x00:
-            case 0x01:
-            case 0x02:
-            case 0x03:
-            case 0x06:
-            case 0x07:
-            case 0x08:
-            case 0x09:
-            case 0x0a:
-            case 0x0b:
-            case 0x0e:
-            case 0x10 ... 0x27: /* base */
-            case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */
-            case 0x30 ... 0x33: /* rom */
-            case 0x3d:
-                can_write = 0;
-                break;
-            default:
-                can_write = 1;
-                break;
-            }
-            break;
-        default:
-        case 0x01:
-            switch(addr) {
-            case 0x00:
-            case 0x01:
-            case 0x02:
-            case 0x03:
-            case 0x06:
-            case 0x07:
-            case 0x08:
-            case 0x09:
-            case 0x0a:
-            case 0x0b:
-            case 0x0e:
-            case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */
-            case 0x38 ... 0x3b: /* rom */
-            case 0x3d:
-                can_write = 0;
-                break;
-            default:
-                can_write = 1;
-                break;
-            }
-            break;
-        }
-        if (can_write) {
-            /* Mask out writes to reserved bits in registers */
-            switch (addr) {
-	    case 0x05:
-                val &= ~PCI_COMMAND_RESERVED_MASK_HI;
-                break;
-            case 0x06:
-                val &= ~PCI_STATUS_RESERVED_MASK_LO;
-                break;
-            case 0x07:
-                val &= ~PCI_STATUS_RESERVED_MASK_HI;
-                break;
-            }
-            d->config[addr] = val;
-        }
-        if (++addr > 0xff)
-        	break;
-        val >>= 8;
+    memcpy(orig, d->config, PCI_CONFIG_SPACE_SIZE);
+    for(i = 0; i < l && addr < PCI_CONFIG_SPACE_SIZE; val >>= 8, ++i, ++addr) {
+        uint8_t wmask = d->wmask[addr];
+        d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask);
     }
-
-    end = address + len;
-    if (end > PCI_COMMAND && address < (PCI_COMMAND + 2)) {
-        /* if the command register is modified, we must modify the mappings */
+    if (memcmp(orig + PCI_BASE_ADDRESS_0, d->config + PCI_BASE_ADDRESS_0, 24)
+        || ((orig[PCI_COMMAND] ^ d->config[PCI_COMMAND])
+            & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
         pci_update_mappings(d);
-    }
 }
 
 void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
@@ -847,16 +768,8 @@ static void pci_bridge_write_config(PCIDevice *d,
 {
     PCIBridge *s = (PCIBridge *)d;
 
-    if (address == 0x19 || (address == 0x18 && len > 1)) {
-        if (address == 0x19)
-            s->bus->bus_num = val & 0xff;
-        else
-            s->bus->bus_num = (val >> 8) & 0xff;
-#if defined(DEBUG_PCI)
-        printf ("pci-bridge: %s: Assigned bus %d\n", d->name, s->bus->bus_num);
-#endif
-    }
     pci_default_write_config(d, address, val, len);
+    s->bus->bus_num = d->config[PCI_SECONDARY_BUS];
 }
 
 PCIBus *pci_find_bus(int bus_num)
hw/pci.h +17 -1
index 0405837..d0db402 100644
@@ -100,16 +100,24 @@ typedef struct PCIIORegion {
 #define PCI_COMMAND		0x04	/* 16 bits */
 #define  PCI_COMMAND_IO		0x1	/* Enable response in I/O space */
 #define  PCI_COMMAND_MEMORY	0x2	/* Enable response in Memory space */
+#define  PCI_COMMAND_MASTER	0x4	/* Enable bus master */
 #define PCI_STATUS              0x06    /* 16 bits */
 #define PCI_REVISION_ID         0x08    /* 8 bits  */
 #define PCI_CLASS_DEVICE        0x0a    /* Device class */
+#define PCI_CACHE_LINE_SIZE	0x0c	/* 8 bits */
+#define PCI_LATENCY_TIMER	0x0d	/* 8 bits */
 #define PCI_HEADER_TYPE         0x0e    /* 8 bits */
 #define  PCI_HEADER_TYPE_NORMAL		0
 #define  PCI_HEADER_TYPE_BRIDGE		1
 #define  PCI_HEADER_TYPE_CARDBUS	2
 #define  PCI_HEADER_TYPE_MULTI_FUNCTION 0x80
+#define PCI_BASE_ADDRESS_0	0x10	/* 32 bits */
+#define PCI_PRIMARY_BUS		0x18	/* Primary bus number */
+#define PCI_SECONDARY_BUS	0x19	/* Secondary bus number */
+#define PCI_SEC_STATUS		0x1e	/* Secondary status register, only bit 14 used */
 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c    /* 16 bits */
 #define PCI_SUBSYSTEM_ID        0x2e    /* 16 bits */
+#define PCI_CAPABILITY_LIST	0x34	/* Offset of first capability list entry */
 #define PCI_INTERRUPT_LINE	0x3c	/* 8 bits */
 #define PCI_INTERRUPT_PIN	0x3d	/* 8 bits */
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
@@ -139,10 +147,18 @@ typedef struct PCIIORegion {
 
 #define PCI_COMMAND_RESERVED_MASK_HI (PCI_COMMAND_RESERVED >> 8)
 
+/* Size of the standard PCI config header */
+#define PCI_CONFIG_HEADER_SIZE 0x40
+/* Size of the standard PCI config space */
+#define PCI_CONFIG_SPACE_SIZE 0x100
+
 struct PCIDevice {
     DeviceState qdev;
     /* PCI config space */
-    uint8_t config[256];
+    uint8_t config[PCI_CONFIG_SPACE_SIZE];
+
+    /* Used to implement R/W bytes */
+    uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
     /* the following fields are read only */
     PCIBus *bus;
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#4 lore raw

PATCH v3 2/13 qemu: capability bits in pci save/restore

In reply to a message not in the archive

Add support for capability bits in save/restore for pci. These will be used for MSI, where the capability might be present or not as requested by user, which does not map well into a single version number.

---
 hw/pci.c |   14 ++++++++++++--
 hw/pci.h |    4 ++++
 2 files changed, 16 insertions(+), 2 deletions(-)
hw/pci.c +12 -2
index 235191d..361d741 100644
@@ -127,12 +127,15 @@ int pci_bus_num(PCIBus *s)
 
 void pci_device_save(PCIDevice *s, QEMUFile *f)
 {
+    int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, 2); /* PCI device version */
+    qemu_put_be32(f, version); /* PCI device version */
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
 }
 
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -141,7 +144,7 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     int i;
 
     version_id = qemu_get_be32(f);
-    if (version_id > 2)
+    if (version_id > 3)
         return -EINVAL;
     qemu_get_buffer(f, s->config, 256);
     pci_update_mappings(s);
@@ -149,6 +152,13 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (version_id >= 2)
         for (i = 0; i < 4; i ++)
             s->irq_state[i] = qemu_get_be32(f);
+    if (version_id >= 3)
+        s->cap_present = qemu_get_be32(f);
+    else
+        s->cap_present = 0;
+
+    if (s->cap_present & ~s->cap_supported)
+        return -EINVAL;
 
     return 0;
 }
hw/pci.h +4 -0
index d0db402..6f0803f 100644
@@ -178,6 +178,10 @@ struct PCIDevice {
 
     /* Current IRQ levels.  Used internally by the generic PCI code.  */
     int irq_state[4];
+
+    /* Capability bits for save/load */
+    uint32_t cap_supported;
+    uint32_t cap_present;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#6 lore raw

PATCH v3 3/13 qemu: add routines to manage PCI capabilities

In reply to a message not in the archive

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +89 -9
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }
 
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }
 
@@ -870,3 +877,76 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static int pci_find_space(PCIDevice *pdev, uint8_t size)
+{
+    int offset = PCI_CONFIG_HEADER_SIZE;
+    int i;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        if (pdev->used[i])
+            offset = i + 1;
+        else if (i - offset + 1 == size)
+            return offset;
+    return 0;
+}
+
+static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
+                                        uint8_t *prev_p)
+{
+    uint8_t next, prev;
+
+    if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST))
+        return 0;
+
+    for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
+         prev = next + PCI_CAP_LIST_NEXT)
+        if (pdev->config[next + PCI_CAP_LIST_ID] == cap_id)
+            break;
+
+    *prev_p = prev;
+    return next;
+}
+
+/* Reserve space and add capability to the linked list in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t offset = pci_find_space(pdev, size);
+    uint8_t *config = pdev->config + offset;
+    if (!offset)
+        return -ENOSPC;
+    config[PCI_CAP_LIST_ID] = cap_id;
+    config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
+    pdev->config[PCI_CAPABILITY_LIST] = offset;
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
+    /* Make capability read-only by default */
+    memset(pdev->wmask + offset, 0, size);
+    return offset;
+}
+
+/* Unlink capability from the pci config space. */
+void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev);
+    if (!offset)
+        return;
+    pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];
+    /* Make capability writeable again */
+    memset(pdev->wmask + offset, 0xff, size);
+    memset(pdev->used + offset, 0, size);
+
+    if (!pdev->config[PCI_CAPABILITY_LIST])
+        pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
+}
+
+uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
+{
+    uint8_t prev;
+    return pci_find_capability_list(pdev, cap_id, &prev);
+}
hw/pci.h +17 -1
index 6f0803f..4838c59 100644
@@ -123,6 +123,10 @@ typedef struct PCIIORegion {
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
 #define PCI_MAX_LAT		0x3f	/* 8 bits */
 
+/* Capability lists */
+#define PCI_CAP_LIST_ID		0	/* Capability ID */
+#define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
+
 #define PCI_REVISION            0x08    /* obsolete, use PCI_REVISION_ID */
 #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
 #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
@@ -130,7 +134,7 @@ typedef struct PCIIORegion {
 /* Bits in the PCI Status Register (PCI 2.3 spec) */
 #define PCI_STATUS_RESERVED1	0x007
 #define PCI_STATUS_INT_STATUS	0x008
-#define PCI_STATUS_CAPABILITIES	0x010
+#define PCI_STATUS_CAP_LIST	0x010
 #define PCI_STATUS_66MHZ	0x020
 #define PCI_STATUS_RESERVED2	0x040
 #define PCI_STATUS_FAST_BACK	0x080
@@ -160,6 +164,9 @@ struct PCIDevice {
     /* Used to implement R/W bytes */
     uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
+    /* Used to allocate config space for capabilities. */
+    uint8_t used[PCI_CONFIG_SPACE_SIZE];
+
     /* the following fields are read only */
     PCIBus *bus;
     int devfn;
@@ -194,6 +201,15 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
+uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
+
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#281 lore raw

PATCH v3 4/13 qemu: helper routines for pci access.

In reply to a message not in the archive

Add inline routines for convenient access to pci devices with correct (little) endianness. Will be used by MSI-X support.

---
 hw/pci.h |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)
hw/pci.h +27 -3
index 4838c59..477aa64 100644
@@ -240,21 +240,45 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
                         pci_map_irq_fn map_irq, const char *name);
 
 static inline void
+pci_set_word(uint8_t *config, uint16_t val)
+{
+    cpu_to_le16wu((uint16_t *)config, val);
+}
+
+static inline uint16_t
+pci_get_word(uint8_t *config)
+{
+    return le16_to_cpupu((uint16_t *)config);
+}
+
+static inline void
+pci_set_long(uint8_t *config, uint32_t val)
+{
+    cpu_to_le32wu((uint32_t *)config, val);
+}
+
+static inline uint32_t
+pci_get_long(uint8_t *config)
+{
+    return le32_to_cpupu((uint32_t *)config);
+}
+
+static inline void
 pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val)
 {
-    cpu_to_le16wu((uint16_t *)&pci_config[PCI_VENDOR_ID], val);
+    pci_set_word(&pci_config[PCI_VENDOR_ID], val);
 }
 
 static inline void
 pci_config_set_device_id(uint8_t *pci_config, uint16_t val)
 {
-    cpu_to_le16wu((uint16_t *)&pci_config[PCI_DEVICE_ID], val);
+    pci_set_word(&pci_config[PCI_DEVICE_ID], val);
 }
 
 static inline void
 pci_config_set_class(uint8_t *pci_config, uint16_t val)
 {
-    cpu_to_le16wu((uint16_t *)&pci_config[PCI_CLASS_DEVICE], val);
+    pci_set_word(&pci_config[PCI_CLASS_DEVICE], val);
 }
 
 typedef void (*pci_qdev_initfn)(PCIDevice *dev);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#283 lore raw

PATCH v3 5/13 qemu: MSI-X support functions

In reply to a message not in the archive

Add functions implementing MSI-X support. First user will be virtio-pci. Note that platform must set a flag to declare MSI supported. For PC this will be set by APIC.

---
 Makefile.target |    2 +-
 hw/msix.c       |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/msix.h       |   35 +++++
 hw/pci.h        |   20 +++
 4 files changed, 479 insertions(+), 1 deletions(-)
 create mode 100644 hw/msix.c
 create mode 100644 hw/msix.h
Makefile.target +1 -1
index 664a1e3..87b2859 100644
@@ -486,7 +486,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o msix.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
hw/msix.c new file +423 -0

423 lines not on this page · raw message

hw/msix.h new file +35 -0
new file mode 100644
index 0000000..79e84a3
@@ -0,0 +1,35 @@
+#ifndef QEMU_MSIX_H
+#define QEMU_MSIX_H
+
+#include "qemu-common.h"
+
+int msix_init(PCIDevice *pdev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size);
+
+void msix_write_config(PCIDevice *pci_dev, uint32_t address,
+                       uint32_t val, int len);
+
+void msix_mmio_map(PCIDevice *pci_dev, int region_num,
+                   uint32_t addr, uint32_t size, int type);
+
+int msix_uninit(PCIDevice *d);
+
+void msix_save(PCIDevice *dev, QEMUFile *f);
+int msix_load(PCIDevice *dev, QEMUFile *f);
+
+int msix_enabled(PCIDevice *dev);
+int msix_present(PCIDevice *dev);
+
+uint32_t msix_bar_size(PCIDevice *dev);
+
+int msix_vector_use(PCIDevice *dev, unsigned vector);
+void msix_vector_unuse(PCIDevice *dev, unsigned vector);
+
+void msix_notify(PCIDevice *dev, unsigned vector);
+
+void msix_reset(PCIDevice *dev);
+
+extern int msix_disable;
+extern int msix_supported;
+
+#endif
hw/pci.h +20 -0
index 477aa64..98a34ee 100644
@@ -156,6 +156,11 @@ typedef struct PCIIORegion {
 /* Size of the standard PCI config space */
 #define PCI_CONFIG_SPACE_SIZE 0x100
 
+/* Bits in cap_supported/cap_present fields. */
+enum {
+    QEMU_PCI_CAP_MSIX = 0x1,
+};
+
 struct PCIDevice {
     DeviceState qdev;
     /* PCI config space */
@@ -189,6 +194,21 @@ struct PCIDevice {
     /* Capability bits for save/load */
     uint32_t cap_supported;
     uint32_t cap_present;
+
+    /* Offset of MSI-X capability in config space */
+    uint8_t msix_cap;
+
+    /* MSI-X entries */
+    int msix_entries_nr;
+
+    /* Space to store MSIX table */
+    uint8_t *msix_table_page;
+    /* MMIO index used to map MSIX table and pending bit entries. */
+    int msix_mmio_index;
+    /* Reference-count for entries actually in use by driver. */
+    unsigned *msix_entry_used;
+    /* Region including the MSI-X table */
+    uint32_t msix_bar_size;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#289 lore raw

PATCH v3 6/13 qemu: add flag to disable MSI-X by default

In reply to a message not in the archive

Add global flag to disable MSI-X by default. This is useful primarily to make images loadable by older qemu (without msix). Even when MSI-X is disabled by flag, you can still load images that have MSI-X enabled.

---
 hw/msix.c       |    3 +++
 qemu-options.hx |    2 ++
 vl.c            |    3 +++
 3 files changed, 8 insertions(+), 0 deletions(-)
hw/msix.c +3 -0
index 1b5aec8..ada81d8 100644
@@ -122,6 +122,9 @@ void msix_write_config(PCIDevice *dev, uint32_t addr,
                        uint32_t val, int len)
 {
     unsigned enable_pos = dev->msix_cap + MSIX_ENABLE_OFFSET;
+    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+        return;
+
     if (addr + len <= enable_pos || addr > enable_pos)
         return;
 
qemu-options.hx +2 -0
index 87af798..fd041a4 100644
@@ -1575,3 +1575,5 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting,
 DEF("old-param", 0, QEMU_OPTION_old_param,
     "-old-param      old param mode\n")
 #endif
+DEF("disable-msix", 0, QEMU_OPTION_disable_msix,
+    "-disable-msix disable msix support for PCI devices (enabled by default)\n")
vl.c +3 -0
index 2c1f0e0..2757d4f 100644
@@ -134,6 +134,7 @@ int main(int argc, char **argv)
 #include "hw/usb.h"
 #include "hw/pcmcia.h"
 #include "hw/pc.h"
+#include "hw/msix.h"
 #include "hw/audiodev.h"
 #include "hw/isa.h"
 #include "hw/baum.h"
@@ -5557,6 +5558,8 @@ int main(int argc, char **argv, char **envp)
                 xen_mode = XEN_ATTACH;
                 break;
 #endif
+            case QEMU_OPTION_disable_msix:
+                msix_disable = 1;
             }
         }
     }
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#291 lore raw

PATCH v3 7/13 qemu: minimal MSI/MSI-X implementation for PC

In reply to a message not in the archive

Implement MSI support in APIC. Note that MSI and MMIO APIC registers are at the same memory location, but actually not on the global bus: MSI is on PCI bus, APIC is connected directly to the CPU. We map them on the global bus at the same address which happens to work because MSI registers are reserved in APIC MMIO and vice versa.

---
 hw/apic.c |   43 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 39 insertions(+), 4 deletions(-)
hw/apic.c +39 -4
index 8c8b2de..ed03a36 100644
@@ -19,6 +19,8 @@
  */
 #include "hw.h"
 #include "pc.h"
+#include "pci.h"
+#include "msix.h"
 #include "qemu-timer.h"
 #include "host-utils.h"
 
@@ -63,6 +65,19 @@
 #define MAX_APICS 255
 #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 MSI_ADDR_BASE                   0xfee00000
+#define MSI_ADDR_SIZE                   0x100000
+
 typedef struct APICState {
     CPUState *cpu_env;
     uint32_t apicbase;
@@ -712,11 +727,31 @@ static uint32_t apic_mem_readl(void *opaque, target_phys_addr_t addr)
     return val;
 }
 
+static void apic_send_msi(target_phys_addr_t addr, uint32 data)
+{
+    uint8_t dest = (addr & MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT;
+    uint8_t vector = (data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT;
+    uint8_t dest_mode = (addr >> MSI_ADDR_DEST_MODE_SHIFT) & 0x1;
+    uint8_t trigger_mode = (data >> MSI_DATA_TRIGGER_SHIFT) & 0x1;
+    uint8_t delivery = (data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x7;
+    /* XXX: Ignore redirection hint. */
+    apic_deliver_irq(dest, dest_mode, delivery, vector, 0, trigger_mode);
+}
+
 static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     CPUState *env;
     APICState *s;
-    int index;
+    int index = (addr >> 4) & 0xff;
+    if (addr > 0xfff || !index) {
+        /* MSI and MMIO APIC are at the same memory location,
+         * but actually not on the global bus: MSI is on PCI bus
+         * APIC is connected directly to the CPU.
+         * Mapping them on the global bus happens to work because
+         * MSI registers are reserved in APIC MMIO and vice versa. */
+        apic_send_msi(addr, val);
+        return;
+    }
 
     env = cpu_single_env;
     if (!env)
@@ -727,7 +762,6 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     printf("APIC write: %08x = %08x\n", (uint32_t)addr, val);
 #endif
 
-    index = (addr >> 4) & 0xff;
     switch(index) {
     case 0x02:
         s->id = (val >> 24);
@@ -911,6 +945,7 @@ int apic_init(CPUState *env)
     s->cpu_env = env;
 
     apic_reset(s);
+    msix_supported = 1;
 
     /* XXX: mapping more APICs at the same memory location */
     if (apic_io_memory == 0) {
@@ -918,7 +953,8 @@ int apic_init(CPUState *env)
            on the global memory bus. */
         apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
                                                 apic_mem_write, NULL);
-        cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
+        /* XXX: what if the base changes? */
+        cpu_register_physical_memory(MSI_ADDR_BASE, MSI_ADDR_SIZE,
                                      apic_io_memory);
     }
     s->timer = qemu_new_timer(vm_clock, apic_timer, s);
@@ -929,4 +965,3 @@ int apic_init(CPUState *env)
     local_apics[s->id] = s;
     return 0;
 }
-
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#297 lore raw

PATCH v3 8/13 qemu: add support for resizing regions

In reply to a message not in the archive

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +36 -18
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+
 static void pci_update_mappings(PCIDevice *d)
 {
     PCIIORegion *r;
@@ -445,24 +480,7 @@ static void pci_update_mappings(PCIDevice *d)
             }
             /* now do the real mapping */
             if (new_addr != r->addr) {
-                if (r->addr != -1) {
-                    if (r->type & PCI_ADDRESS_SPACE_IO) {
-                        int class;
-                        /* NOTE: specific hack for IDE in PC case:
-                           only one byte must be mapped. */
-                        class = d->config[0x0a] | (d->config[0x0b] << 8);
-                        if (class == 0x0101 && r->size == 4) {
-                            isa_unassign_ioport(r->addr + 2, 1);
-                        } else {
-                            isa_unassign_ioport(r->addr, r->size);
-                        }
-                    } else {
-                        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
-                                                     r->size,
-                                                     IO_MEM_UNASSIGNED);
-                        qemu_unregister_coalesced_mmio(r->addr, r->size);
-                    }
-                }
+                pci_unmap_region(d, r);
                 r->addr = new_addr;
                 if (r->addr != -1) {
                     r->map_func(d, i, r->addr, r->size, r->type);
hw/pci.h +3 -0
index 98a34ee..8e74033 100644
@@ -221,6 +221,9 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size);
+
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#305 lore raw

PATCH v3 9/13 qemu: virtio support for many interrupt vectors

In reply to a message not in the archive

Extend virtio to support many interrupt vectors, and rearrange code in preparation for multi-vector support (mostly move reset out to bindings, because we will have to reset the vectors in transport-specific code). Actual bindings in pci, and use in net, to follow.
Load and save are not connected to bindings yet, so they are left stubbed out for now.

---
 hw/syborg_virtio.c |   13 ++++++++--
 hw/virtio-pci.c    |   24 +++++++++++++++----
 hw/virtio.c        |   63 ++++++++++++++++++++++++++++++++++++++-------------
 hw/virtio.h        |   10 ++++++-
 4 files changed, 84 insertions(+), 26 deletions(-)
hw/syborg_virtio.c +10 -3
index 37c219c..d8c978a 100644
@@ -134,7 +134,10 @@ static void syborg_virtio_writel(void *opaque, target_phys_addr_t offset,
         vdev->features = value;
         break;
     case SYBORG_VIRTIO_QUEUE_BASE:
-        virtio_queue_set_addr(vdev, vdev->queue_sel, value);
+        if (value == 0)
+            virtio_reset(vdev);
+        else
+            virtio_queue_set_addr(vdev, vdev->queue_sel, value);
         break;
     case SYBORG_VIRTIO_QUEUE_SEL:
         if (value < VIRTIO_PCI_QUEUE_MAX)
@@ -228,7 +231,7 @@ static CPUWriteMemoryFunc *syborg_virtio_writefn[] = {
      syborg_virtio_writel
 };
 
-static void syborg_virtio_update_irq(void *opaque)
+static void syborg_virtio_update_irq(void *opaque, uint16_t vector)
 {
     SyborgVirtIOProxy *proxy = opaque;
     int level;
@@ -239,7 +242,7 @@ static void syborg_virtio_update_irq(void *opaque)
 }
 
 static VirtIOBindings syborg_virtio_bindings = {
-    .update_irq = syborg_virtio_update_irq
+    .notify = syborg_virtio_update_irq
 };
 
 static void syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev)
@@ -248,6 +251,8 @@ static void syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev)
 
     proxy->vdev = vdev;
 
+    /* Don't support multiple vectors */
+    proxy->vdev->nvectors = 0;
     sysbus_init_irq(&proxy->busdev, &proxy->irq);
     iomemtype = cpu_register_io_memory(0, syborg_virtio_readfn,
                                        syborg_virtio_writefn, proxy);
@@ -255,6 +260,8 @@ static void syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev)
 
     proxy->id = ((uint32_t)0x1af4 << 16) | vdev->device_id;
 
+    qemu_register_reset(virtio_reset, 0, vdev);
+
     virtio_bind_device(vdev, &syborg_virtio_bindings, proxy);
 }
 
hw/virtio-pci.c +19 -5
index c072423..7dfdd80 100644
@@ -78,13 +78,19 @@ typedef struct {
 
 /* virtio device */
 
-static void virtio_pci_update_irq(void *opaque)
+static void virtio_pci_notify(void *opaque, uint16_t vector)
 {
     VirtIOPCIProxy *proxy = opaque;
 
     qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }
 
+static void virtio_pci_reset(void *opaque)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    virtio_reset(proxy->vdev);
+}
+
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
@@ -108,7 +114,10 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         break;
     case VIRTIO_PCI_QUEUE_PFN:
         pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
-        virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
+        if (pa == 0)
+            virtio_pci_reset(proxy);
+        else
+            virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
         break;
     case VIRTIO_PCI_QUEUE_SEL:
         if (val < VIRTIO_PCI_QUEUE_MAX)
@@ -120,7 +129,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     case VIRTIO_PCI_STATUS:
         vdev->status = val & 0xFF;
         if (vdev->status == 0)
-            virtio_reset(vdev);
+            virtio_pci_reset(proxy);
         break;
     }
 }
@@ -158,7 +167,7 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
         /* reading from the ISR also clears it. */
         ret = vdev->isr;
         vdev->isr = 0;
-        virtio_update_irq(vdev);
+        qemu_set_irq(proxy->pci_dev.irq[0], 0);
         break;
     default:
         break;
@@ -243,7 +252,7 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
-    .update_irq = virtio_pci_update_irq
+    .notify = virtio_pci_notify
 };
 
 static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
@@ -255,6 +264,9 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     proxy->vdev = vdev;
 
+    /* No support for multiple vectors yet. */
+    proxy->vdev->nvectors = 0;
+
     config = proxy->pci_dev.config;
     pci_config_set_vendor_id(config, vendor);
     pci_config_set_device_id(config, device);
@@ -279,6 +291,8 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
     pci_register_io_region(&proxy->pci_dev, 0, size, PCI_ADDRESS_SPACE_IO,
                            virtio_map);
 
+    qemu_register_reset(virtio_pci_reset, 0, proxy);
+
     virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
 }
 
hw/virtio.c +47 -16

166 lines not on this page · raw message

hw/virtio.h +8 -2
index 425727e..04a3c3d 100644
@@ -71,11 +71,13 @@ typedef struct VirtQueueElement
 } VirtQueueElement;
 
 typedef struct {
-    void (*update_irq)(void * opaque);
+    void (*notify)(void * opaque, uint16_t vector);
 } VirtIOBindings;
 
 #define VIRTIO_PCI_QUEUE_MAX 16
 
+#define VIRTIO_NO_VECTOR 0xffff
+
 struct VirtIODevice
 {
     const char *name;
@@ -85,6 +87,8 @@ struct VirtIODevice
     uint32_t features;
     size_t config_len;
     void *config;
+    uint16_t config_vector;
+    int nvectors;
     uint32_t (*get_features)(VirtIODevice *vdev);
     uint32_t (*bad_features)(VirtIODevice *vdev);
     void (*set_features)(VirtIODevice *vdev, uint32_t val);
@@ -114,7 +118,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
 
 void virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
-void virtio_load(VirtIODevice *vdev, QEMUFile *f);
+int virtio_load(VirtIODevice *vdev, QEMUFile *f);
 
 void virtio_cleanup(VirtIODevice *vdev);
 
@@ -140,6 +144,8 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr);
 target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n);
 int virtio_queue_get_num(VirtIODevice *vdev, int n);
 void virtio_queue_notify(VirtIODevice *vdev, int n);
+uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
+void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#307 lore raw

PATCH v3 10/13 qemu: MSI-X support in virtio PCI

In reply to a message not in the archive

This enables actual support for MSI-X in virtio PCI. First user will be virtio-net.

---
 hw/virtio-pci.c |  152 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 112 insertions(+), 40 deletions(-)
hw/virtio-pci.c +112 -40
index 7dfdd80..294f4c7 100644
@@ -18,6 +18,7 @@
 #include "virtio.h"
 #include "pci.h"
 //#include "sysemu.h"
+#include "msix.h"
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -47,7 +48,24 @@
  * a read-and-acknowledge. */
 #define VIRTIO_PCI_ISR                  19
 
-#define VIRTIO_PCI_CONFIG               20
+/* MSI-X registers: only enabled if MSI-X is enabled. */
+/* A 16-bit vector for configuration changes. */
+#define VIRTIO_MSI_CONFIG_VECTOR        20
+/* A 16-bit vector for selected queue notifications. */
+#define VIRTIO_MSI_QUEUE_VECTOR         22
+
+/* Config space size */
+#define VIRTIO_PCI_CONFIG_NOMSI         20
+#define VIRTIO_PCI_CONFIG_MSI           24
+#define VIRTIO_PCI_REGION_SIZE(dev)     (msix_present(dev) ? \
+                                         VIRTIO_PCI_CONFIG_MSI : \
+                                         VIRTIO_PCI_CONFIG_NOMSI)
+
+/* The remaining space is defined by each driver as the per-driver
+ * configuration space */
+#define VIRTIO_PCI_CONFIG(dev)          (msix_enabled(dev) ? \
+                                         VIRTIO_PCI_CONFIG_MSI : \
+                                         VIRTIO_PCI_CONFIG_NOMSI)
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
@@ -81,14 +99,17 @@ typedef struct {
 static void virtio_pci_notify(void *opaque, uint16_t vector)
 {
     VirtIOPCIProxy *proxy = opaque;
-
-    qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
+    if (msix_enabled(&proxy->pci_dev))
+        msix_notify(&proxy->pci_dev, vector);
+    else
+        qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }
 
 static void virtio_pci_reset(void *opaque)
 {
     VirtIOPCIProxy *proxy = opaque;
     virtio_reset(proxy->vdev);
+    msix_reset(&proxy->pci_dev);
 }
 
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
@@ -97,8 +118,6 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     VirtIODevice *vdev = proxy->vdev;
     target_phys_addr_t pa;
 
-    addr -= proxy->addr;
-
     switch (addr) {
     case VIRTIO_PCI_GUEST_FEATURES:
 	/* Guest does not negotiate properly?  We have to assume nothing. */
@@ -131,17 +150,33 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         if (vdev->status == 0)
             virtio_pci_reset(proxy);
         break;
+    case VIRTIO_MSI_CONFIG_VECTOR:
+        msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
+        /* Make it possible for guest to discover an error took place. */
+        if (msix_vector_use(&proxy->pci_dev, val) < 0)
+            val = VIRTIO_NO_VECTOR;
+        vdev->config_vector = val;
+        break;
+    case VIRTIO_MSI_QUEUE_VECTOR:
+        msix_vector_unuse(&proxy->pci_dev,
+                          virtio_queue_vector(vdev, vdev->queue_sel));
+        /* Make it possible for guest to discover an error took place. */
+        if (msix_vector_use(&proxy->pci_dev, val) < 0)
+            val = VIRTIO_NO_VECTOR;
+        virtio_queue_set_vector(vdev, vdev->queue_sel, val);
+        break;
+    default:
+        fprintf(stderr, "%s: unexpected address 0x%x value 0x%x\n",
+                __func__, addr, val);
+        break;
     }
 }
 
-static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
+static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
 {
-    VirtIOPCIProxy *proxy = opaque;
     VirtIODevice *vdev = proxy->vdev;
     uint32_t ret = 0xFFFFFFFF;
 
-    addr -= proxy->addr;
-
     switch (addr) {
     case VIRTIO_PCI_HOST_FEATURES:
         ret = vdev->get_features(vdev);
@@ -169,6 +204,12 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
         vdev->isr = 0;
         qemu_set_irq(proxy->pci_dev.irq[0], 0);
         break;
+    case VIRTIO_MSI_CONFIG_VECTOR:
+        ret = vdev->config_vector;
+        break;
+    case VIRTIO_MSI_QUEUE_VECTOR:
+        ret = virtio_queue_vector(vdev, vdev->queue_sel);
+        break;
     default:
         break;
     }
@@ -179,42 +220,72 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
 static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config)
+        return virtio_ioport_read(proxy, addr);
+    addr -= config;
     return virtio_config_readb(proxy->vdev, addr);
 }
 
 static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config)
+        return virtio_ioport_read(proxy, addr);
+    addr -= config;
     return virtio_config_readw(proxy->vdev, addr);
 }
 
 static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config)
+        return virtio_ioport_read(proxy, addr);
+    addr -= config;
     return virtio_config_readl(proxy->vdev, addr);
 }
 
 static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config) {
+        virtio_ioport_write(proxy, addr, val);
+        return;
+    }
+    addr -= config;
     virtio_config_writeb(proxy->vdev, addr, val);
 }
 
 static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config) {
+        virtio_ioport_write(proxy, addr, val);
+        return;
+    }
+    addr -= config;
     virtio_config_writew(proxy->vdev, addr, val);
 }
 
 static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
-    addr -= proxy->addr + VIRTIO_PCI_CONFIG;
+    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    addr -= proxy->addr;
+    if (addr < config) {
+        virtio_ioport_write(proxy, addr, val);
+        return;
+    }
+    addr -= config;
     virtio_config_writel(proxy->vdev, addr, val);
 }
 
@@ -223,32 +294,26 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 {
     VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev);
     VirtIODevice *vdev = proxy->vdev;
-    int i;
+    unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
 
     proxy->addr = addr;
-    for (i = 0; i < 3; i++) {
-        register_ioport_write(addr, VIRTIO_PCI_CONFIG, 1 << i,
-                              virtio_ioport_write, proxy);
-        register_ioport_read(addr, VIRTIO_PCI_CONFIG, 1 << i,
-                             virtio_ioport_read, proxy);
-    }
 
-    if (vdev->config_len) {
-        register_ioport_write(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 1,
-                              virtio_pci_config_writeb, proxy);
-        register_ioport_write(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 2,
-                              virtio_pci_config_writew, proxy);
-        register_ioport_write(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 4,
-                              virtio_pci_config_writel, proxy);
-        register_ioport_read(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 1,
-                             virtio_pci_config_readb, proxy);
-        register_ioport_read(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 2,
-                             virtio_pci_config_readw, proxy);
-        register_ioport_read(addr + VIRTIO_PCI_CONFIG, vdev->config_len, 4,
-                             virtio_pci_config_readl, proxy);
+    register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
+    register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
+    register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
+    register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
+    register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
+    register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
 
+    if (vdev->config_len)
         vdev->get_config(vdev, vdev->config);
-    }
+}
+
+static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
+                                uint32_t val, int len)
+{
+    pci_default_write_config(pci_dev, address, val, len);
+    msix_write_config(pci_dev, address, val, len);
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
@@ -264,9 +329,6 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     proxy->vdev = vdev;
 
-    /* No support for multiple vectors yet. */
-    proxy->vdev->nvectors = 0;
-
     config = proxy->pci_dev.config;
     pci_config_set_vendor_id(config, vendor);
     pci_config_set_device_id(config, device);
@@ -284,7 +346,17 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     config[0x3d] = 1;
 
-    size = 20 + vdev->config_len;
+    if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) {
+        pci_register_io_region(&proxy->pci_dev, 1,
+                               msix_bar_size(&proxy->pci_dev),
+                               PCI_ADDRESS_SPACE_MEM,
+                               msix_mmio_map);
+        proxy->pci_dev.config_write = virtio_write_config;
+        proxy->pci_dev.unregister = msix_uninit;
+    } else
+        vdev->nvectors = 0;
+
+    size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len;
     if (size & (size-1))
         size = 1 << qemu_fls(size);
 
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#309 lore raw

PATCH v3 11/13 qemu: request 3 vectors in virtio-net

In reply to a message not in the archive

Request up to 3 vectors in virtio-net. Actual bindings might supply less.

---
 hw/virtio-net.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/virtio-net.c +1 -0
index 60aa6da..6118fe3 100644
@@ -621,6 +621,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev)
     n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
 
     n->vlans = qemu_mallocz(MAX_VLAN >> 3);
+    n->vdev.nvectors = 3;
 
     register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#311 lore raw

PATCH v3 12/13 qemu: virtio save/load bindings

In reply to a message not in the archive

Implement bindings for virtio save/load. Use them in virtio pci.

---
 hw/virtio-pci.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/virtio.c     |   31 ++++++++++++++-----------------
 hw/virtio.h     |    4 ++++
 3 files changed, 66 insertions(+), 18 deletions(-)
hw/virtio-pci.c +48 -1
index 294f4c7..589fbb1 100644
@@ -105,6 +105,48 @@ static void virtio_pci_notify(void *opaque, uint16_t vector)
         qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }
 
+static void virtio_pci_save_config(void * opaque, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    pci_device_save(&proxy->pci_dev, f);
+    msix_save(&proxy->pci_dev, f);
+    if (msix_present(&proxy->pci_dev))
+        qemu_put_be16(f, proxy->vdev->config_vector);
+}
+
+static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    if (msix_present(&proxy->pci_dev))
+        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
+}
+
+static int virtio_pci_load_config(void * opaque, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    int ret;
+    ret = pci_device_load(&proxy->pci_dev, f);
+    if (ret)
+        return ret;
+    ret = msix_load(&proxy->pci_dev, f);
+    if (ret)
+        return ret;
+    if (msix_present(&proxy->pci_dev))
+        qemu_get_be16s(f, &proxy->vdev->config_vector);
+    return 0;
+}
+
+static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    uint16_t vector;
+    if (!msix_present(&proxy->pci_dev))
+        return 0;
+    qemu_get_be16s(f, &vector);
+    virtio_queue_set_vector(proxy->vdev, n, vector);
+    return 0;
+}
+
 static void virtio_pci_reset(void *opaque)
 {
     VirtIOPCIProxy *proxy = opaque;
@@ -317,7 +359,12 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
-    .notify = virtio_pci_notify
+    .notify = virtio_pci_notify,
+    .save_config = virtio_pci_save_config,
+    .load_config = virtio_pci_load_config,
+    .save_config = virtio_pci_save_config,
+    .save_queue = virtio_pci_save_queue,
+    .load_queue = virtio_pci_load_queue,
 };
 
 static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
hw/virtio.c +14 -17
index 63ffcff..b773dff 100644
@@ -568,9 +568,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
     int i;
 
-    /* FIXME: load/save binding.  */
-    //pci_device_save(&vdev->pci_dev, f);
-    //msix_save(&vdev->pci_dev, f);
+    if (vdev->binding->save_config)
+        vdev->binding->save_config(vdev->binding_opaque, f);
 
     qemu_put_8s(f, &vdev->status);
     qemu_put_8s(f, &vdev->isr);
@@ -596,19 +595,20 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
         qemu_put_be32(f, vdev->vq[i].vring.num);
         qemu_put_be64(f, vdev->vq[i].pa);
         qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
-        if (vdev->nvectors)
-            qemu_put_be16s(f, &vdev->vq[i].vector);
+        if (vdev->binding->save_queue)
+            vdev->binding->save_queue(vdev->binding_opaque, i, f);
     }
 }
 
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
-    int num, i;
+    int num, i, ret;
 
-    /* FIXME: load/save binding.  */
-    //pci_device_load(&vdev->pci_dev, f);
-    //r = msix_load(&vdev->pci_dev, f);
-    //pci_resize_io_region(&vdev->pci_dev, 1, msix_bar_size(&vdev->pci_dev));
+    if (vdev->binding->load_config) {
+        ret = vdev->binding->load_config(vdev->binding_opaque, f);
+        if (ret)
+            return ret;
+    }
 
     qemu_get_8s(f, &vdev->status);
     qemu_get_8s(f, &vdev->isr);
@@ -617,10 +617,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
     vdev->config_len = qemu_get_be32(f);
     qemu_get_buffer(f, vdev->config, vdev->config_len);
 
-    if (vdev->nvectors) {
-        qemu_get_be16s(f, &vdev->config_vector);
-        //msix_vector_use(&vdev->pci_dev, vdev->config_vector);
-    }
     num = qemu_get_be32(f);
 
     for (i = 0; i < num; i++) {
@@ -631,9 +627,10 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
         if (vdev->vq[i].pa) {
             virtqueue_init(&vdev->vq[i]);
         }
-        if (vdev->nvectors) {
-            qemu_get_be16s(f, &vdev->vq[i].vector);
-            //msix_vector_use(&vdev->pci_dev, vdev->config_vector);
+        if (vdev->binding->load_queue) {
+            ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);
+            if (ret)
+                return ret;
         }
     }
 
hw/virtio.h +4 -0
index 04a3c3d..ce05517 100644
@@ -72,6 +72,10 @@ typedef struct VirtQueueElement
 
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
+    void (*save_config)(void * opaque, QEMUFile *f);
+    void (*save_queue)(void * opaque, int n, QEMUFile *f);
+    int (*load_config)(void * opaque, QEMUFile *f);
+    int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;
 
 #define VIRTIO_PCI_QUEUE_MAX 16
Signature · 1 line
1.6.3.1.56.g79e1.dirty
author maintainer
#319 lore raw

PATCH v3 13/13 qemu: add pci_get/set_byte

In reply to a message not in the archive

Add pci_get/set_byte to keep *_word and *_long access functions company. They are unused for now.

---
 hw/pci.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
hw/pci.h +12 -0
index 8e74033..7cc9a8a 100644
@@ -263,6 +263,18 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
                         pci_map_irq_fn map_irq, const char *name);
 
 static inline void
+pci_set_byte(uint8_t *config, uint8_t val)
+{
+    *config = val;
+}
+
+static inline uint8_t
+pci_get_byte(uint8_t *config)
+{
+    return *config;
+}
+
+static inline void
 pci_set_word(uint8_t *config, uint16_t val)
 {
     cpu_to_le16wu((uint16_t *)config, val);
Signature · 1 line
1.6.3.1.56.g79e1.dirty
#7 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Michael S. Tsirkin
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 8 lines
hw/pci.c +4 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

Quoted 24 lines
hw/pci.c +19 -0
@@ -870,3 +877,76 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static int pci_find_space(PCIDevice *pdev, uint8_t size)
+{
+    int offset = PCI_CONFIG_HEADER_SIZE;
+    int i;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        if (pdev->used[i])
+            offset = i + 1;
+        else if (i - offset + 1 == size)
+            return offset;
+    return 0;
+}
+
+static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
+                                        uint8_t *prev_p)
+{
+    uint8_t next, prev;
+
+    if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST))

hw/pci.c PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) · line 908

Quoted 10 lines
hw/pci.c +10 -0
+        return 0;
+
+    for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
+         prev = next + PCI_CAP_LIST_NEXT)
+        if (pdev->config[next + PCI_CAP_LIST_ID] == cap_id)
+            break;
+
+    *prev_p = prev;
+    return next;
+}

I'd prefer to do:

	if (prev_p)
		*prev_p = prev;

so we don't have to always pass a prev_p pointer. You have yourself a user where you don't need it in this very patch.

Quoted 99 lines
hw/pci.c +44 -0
+
+/* Reserve space and add capability to the linked list in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t offset = pci_find_space(pdev, size);
+    uint8_t *config = pdev->config + offset;
+    if (!offset)
+        return -ENOSPC;
+    config[PCI_CAP_LIST_ID] = cap_id;
+    config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
+    pdev->config[PCI_CAPABILITY_LIST] = offset;
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
+    /* Make capability read-only by default */
+    memset(pdev->wmask + offset, 0, size);
+    return offset;
+}
+
+/* Unlink capability from the pci config space. */
+void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev);
+    if (!offset)
+        return;
+    pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];
+    /* Make capability writeable again */
+    memset(pdev->wmask + offset, 0xff, size);
+    memset(pdev->used + offset, 0, size);
+
+    if (!pdev->config[PCI_CAPABILITY_LIST])
+        pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
+}
+
+uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
+{
+    uint8_t prev;
+    return pci_find_capability_list(pdev, cap_id, &prev);
+}
hw/pci.h +17 -1
index 6f0803f..4838c59 100644
@@ -123,6 +123,10 @@ typedef struct PCIIORegion {
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
 #define PCI_MAX_LAT		0x3f	/* 8 bits */
 
+/* Capability lists */
+#define PCI_CAP_LIST_ID		0	/* Capability ID */
+#define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
+
 #define PCI_REVISION            0x08    /* obsolete, use PCI_REVISION_ID */
 #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
 #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
@@ -130,7 +134,7 @@ typedef struct PCIIORegion {
 /* Bits in the PCI Status Register (PCI 2.3 spec) */
 #define PCI_STATUS_RESERVED1	0x007
 #define PCI_STATUS_INT_STATUS	0x008
-#define PCI_STATUS_CAPABILITIES	0x010
+#define PCI_STATUS_CAP_LIST	0x010
 #define PCI_STATUS_66MHZ	0x020
 #define PCI_STATUS_RESERVED2	0x040
 #define PCI_STATUS_FAST_BACK	0x080
@@ -160,6 +164,9 @@ struct PCIDevice {
     /* Used to implement R/W bytes */
     uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
+    /* Used to allocate config space for capabilities. */
+    uint8_t used[PCI_CONFIG_SPACE_SIZE];
+
     /* the following fields are read only */
     PCIBus *bus;
     int devfn;
@@ -194,6 +201,15 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
+uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
+
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
#279 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Michael S. Tsirkin
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 8 lines
hw/pci.c +4 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

Quoted 24 lines
hw/pci.c +19 -0
@@ -870,3 +877,76 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static int pci_find_space(PCIDevice *pdev, uint8_t size)
+{
+    int offset = PCI_CONFIG_HEADER_SIZE;
+    int i;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        if (pdev->used[i])
+            offset = i + 1;
+        else if (i - offset + 1 == size)
+            return offset;
+    return 0;
+}
+
+static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
+                                        uint8_t *prev_p)
+{
+    uint8_t next, prev;
+
+    if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST))

hw/pci.c PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) · line 908

Quoted 10 lines
hw/pci.c +10 -0
+        return 0;
+
+    for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
+         prev = next + PCI_CAP_LIST_NEXT)
+        if (pdev->config[next + PCI_CAP_LIST_ID] == cap_id)
+            break;
+
+    *prev_p = prev;
+    return next;
+}

I'd prefer to do:

	if (prev_p)
		*prev_p = prev;

so we don't have to always pass a prev_p pointer. You have yourself a user where you don't need it in this very patch.

Quoted 99 lines
hw/pci.c +44 -0
+
+/* Reserve space and add capability to the linked list in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t offset = pci_find_space(pdev, size);
+    uint8_t *config = pdev->config + offset;
+    if (!offset)
+        return -ENOSPC;
+    config[PCI_CAP_LIST_ID] = cap_id;
+    config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
+    pdev->config[PCI_CAPABILITY_LIST] = offset;
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
+    /* Make capability read-only by default */
+    memset(pdev->wmask + offset, 0, size);
+    return offset;
+}
+
+/* Unlink capability from the pci config space. */
+void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev);
+    if (!offset)
+        return;
+    pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];
+    /* Make capability writeable again */
+    memset(pdev->wmask + offset, 0xff, size);
+    memset(pdev->used + offset, 0, size);
+
+    if (!pdev->config[PCI_CAPABILITY_LIST])
+        pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
+}
+
+uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
+{
+    uint8_t prev;
+    return pci_find_capability_list(pdev, cap_id, &prev);
+}
hw/pci.h +17 -1
index 6f0803f..4838c59 100644
@@ -123,6 +123,10 @@ typedef struct PCIIORegion {
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
 #define PCI_MAX_LAT		0x3f	/* 8 bits */
 
+/* Capability lists */
+#define PCI_CAP_LIST_ID		0	/* Capability ID */
+#define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
+
 #define PCI_REVISION            0x08    /* obsolete, use PCI_REVISION_ID */
 #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
 #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
@@ -130,7 +134,7 @@ typedef struct PCIIORegion {
 /* Bits in the PCI Status Register (PCI 2.3 spec) */
 #define PCI_STATUS_RESERVED1	0x007
 #define PCI_STATUS_INT_STATUS	0x008
-#define PCI_STATUS_CAPABILITIES	0x010
+#define PCI_STATUS_CAP_LIST	0x010
 #define PCI_STATUS_66MHZ	0x020
 #define PCI_STATUS_RESERVED2	0x040
 #define PCI_STATUS_FAST_BACK	0x080
@@ -160,6 +164,9 @@ struct PCIDevice {
     /* Used to implement R/W bytes */
     uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
+    /* Used to allocate config space for capabilities. */
+    uint8_t used[PCI_CONFIG_SPACE_SIZE];
+
     /* the following fields are read only */
     PCIBus *bus;
     int devfn;
@@ -194,6 +201,15 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
+uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
+
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
#284 lore raw

Re: [Qemu-devel] [PATCHv3 05/13] qemu: MSI-X support functions

In reply to Michael S. Tsirkin
Quoted 89 lines · Michael S. Tsirkin

Add functions implementing MSI-X support. First user will be virtio-pci. Note that platform must set a flag to declare MSI supported. For PC this will be set by APIC.

---
 Makefile.target |    2 +-
 hw/msix.c       |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/msix.h       |   35 +++++
 hw/pci.h        |   20 +++
 4 files changed, 479 insertions(+), 1 deletions(-)
 create mode 100644 hw/msix.c
 create mode 100644 hw/msix.h
Makefile.target +1 -1
index 664a1e3..87b2859 100644
@@ -486,7 +486,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o msix.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
hw/msix.c new file +56 -0
new file mode 100644
index 0000000..1b5aec8
@@ -0,0 +1,423 @@
+/*
+ * MSI-X device support
+ *
+ * This module includes support for MSI-X in pci devices.
+ *
+ * Author: Michael S. Tsirkin <[email protected]>
+ *
+ *  Copyright (c) 2009, Red Hat Inc, Michael S. Tsirkin ([email protected])
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "hw.h"
+#include "msix.h"
+#include "pci.h"
+
+/* Declaration from linux/pci_regs.h */
+#define  PCI_CAP_ID_MSIX 0x11 /* MSI-X */
+#define  PCI_MSIX_FLAGS 2     /* Table at lower 11 bits */
+#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
+#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
+#define  PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+
+/* MSI-X capability structure */
+#define MSIX_TABLE_OFFSET 4
+#define MSIX_PBA_OFFSET 8
+#define MSIX_CAP_LENGTH 12
+
+/* MSI enable bit is in byte 1 in FLAGS register */
+#define MSIX_ENABLE_OFFSET (PCI_MSIX_FLAGS + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
+
+/* MSI-X table format */
+#define MSIX_MSG_ADDR 0
+#define MSIX_MSG_UPPER_ADDR 4
+#define MSIX_MSG_DATA 8
+#define MSIX_VECTOR_CTRL 12
+#define MSIX_ENTRY_SIZE 16
+#define MSIX_VECTOR_MASK 0x1
+
+/* How much space does an MSIX table need. */
+/* The spec requires giving the table structure
+ * a 4K aligned region all by itself. Align it to
+ * target pages so that drivers can do passthrough
+ * on the rest of the region. */
+#define MSIX_PAGE_SIZE TARGET_PAGE_ALIGN(0x1000)
+/* Reserve second half of the page for pending bits */
+#define MSIX_PAGE_PENDING (MSIX_PAGE_SIZE / 2)
+#define MSIX_MAX_ENTRIES 32
+
+
+#ifdef MSIX_DEBUG
+#define DEBUG(fmt, ...)                                       \
+    do {                                                      \
+      fprintf(stderr, "%s: " fmt, __func__ , __VA_ARGS__);    \

hw/msix.c line 66

Quoted 10 lines
hw/msix.c new file +10 -0
+    } while (0)
+#else
+#define DEBUG(fmt, ...) do { } while(0)
+#endif
+
+/* Flag to globally disable MSI-X support */
+int msix_disable;
+
+/* Flag for interrupt controller to declare MSI-X support */
+int msix_supported;

maybe better to make it static, and provide msi_state() returning -1 for disabled, 0 for supported, etc...

Quoted 54 lines
hw/msix.c new file +53 -0
+
+/* Add MSI-X capability to the config space for the device. */
+/* Given a bar and its size, add MSI-X table on top of it
+ * and fill MSI-X capability in the config space.
+ * Original bar size must be a power of 2 or 0.
+ * New bar size is returned. */
+static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
+                           unsigned bar_nr, unsigned bar_size)
+{
+    int config_offset;
+    uint8_t *config;
+    uint32_t new_size;
+
+    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+        return -EINVAL;
+    if (bar_size > 0x80000000)
+        return -ENOSPC;
+
+    /* Add space for MSI-X structures */
+    if (!bar_size)
+        new_size = MSIX_PAGE_SIZE;
+    else if (bar_size < MSIX_PAGE_SIZE) {
+        bar_size = MSIX_PAGE_SIZE;
+        new_size = MSIX_PAGE_SIZE * 2;
+    } else
+        new_size = bar_size * 2;
+
+    pdev->msix_bar_size = new_size;
+    config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
+    if (config_offset < 0)
+        return config_offset;
+    config = pdev->config + config_offset;
+
+    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    /* Table on top of BAR */
+    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    /* Pending bits on top of that */
+    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+                 bar_nr);
+    pdev->msix_cap = config_offset;
+    /* Make flags bit writeable. */
+    pdev->wmask[config_offset + MSIX_ENABLE_OFFSET] |= MSIX_ENABLE_MASK;
+    return 0;
+}
+
 
+
+/* Initialize the MSI-X structures. Note: if MSI-X is supported, BAR size is
+ * modified, it should be retrieved with msix_bar_size. */
+int msix_init(struct PCIDevice *dev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size)
+{
+    int ret = -ENOMEM;
+    /* Nothing to do if MSI is not supported by interrupt controller */

hw/msix.c

Quoted 10 lines
hw/msix.c new file +10 -0
+    if (!msix_supported)
+        return -ENOTTY;
+
+    if (nentries > MSIX_MAX_ENTRIES)
+        return -EINVAL;
+
+    dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
+                                        sizeof *dev->msix_entry_used);
+    if (!dev->msix_entry_used)
+        goto err_used;

no need to check. oom_checker will kill qemu if it fails.

hw/msix.c line 247

Quoted 4 lines
hw/msix.c new file +4 -0
+
+    dev->msix_table_page = qemu_mallocz(MSIX_PAGE_SIZE);
+    if (!dev->msix_table_page)
+        goto err_page;

ditto.

#287 lore raw

Re: [Qemu-devel] [PATCHv3 05/13] qemu: MSI-X support functions

In reply to Michael S. Tsirkin
Quoted 89 lines · Michael S. Tsirkin

Add functions implementing MSI-X support. First user will be virtio-pci. Note that platform must set a flag to declare MSI supported. For PC this will be set by APIC.

---
 Makefile.target |    2 +-
 hw/msix.c       |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/msix.h       |   35 +++++
 hw/pci.h        |   20 +++
 4 files changed, 479 insertions(+), 1 deletions(-)
 create mode 100644 hw/msix.c
 create mode 100644 hw/msix.h
Makefile.target +1 -1
index 664a1e3..87b2859 100644
@@ -486,7 +486,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o msix.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
hw/msix.c new file +56 -0
new file mode 100644
index 0000000..1b5aec8
@@ -0,0 +1,423 @@
+/*
+ * MSI-X device support
+ *
+ * This module includes support for MSI-X in pci devices.
+ *
+ * Author: Michael S. Tsirkin <[email protected]>
+ *
+ *  Copyright (c) 2009, Red Hat Inc, Michael S. Tsirkin ([email protected])
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "hw.h"
+#include "msix.h"
+#include "pci.h"
+
+/* Declaration from linux/pci_regs.h */
+#define  PCI_CAP_ID_MSIX 0x11 /* MSI-X */
+#define  PCI_MSIX_FLAGS 2     /* Table at lower 11 bits */
+#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
+#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
+#define  PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+
+/* MSI-X capability structure */
+#define MSIX_TABLE_OFFSET 4
+#define MSIX_PBA_OFFSET 8
+#define MSIX_CAP_LENGTH 12
+
+/* MSI enable bit is in byte 1 in FLAGS register */
+#define MSIX_ENABLE_OFFSET (PCI_MSIX_FLAGS + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
+
+/* MSI-X table format */
+#define MSIX_MSG_ADDR 0
+#define MSIX_MSG_UPPER_ADDR 4
+#define MSIX_MSG_DATA 8
+#define MSIX_VECTOR_CTRL 12
+#define MSIX_ENTRY_SIZE 16
+#define MSIX_VECTOR_MASK 0x1
+
+/* How much space does an MSIX table need. */
+/* The spec requires giving the table structure
+ * a 4K aligned region all by itself. Align it to
+ * target pages so that drivers can do passthrough
+ * on the rest of the region. */
+#define MSIX_PAGE_SIZE TARGET_PAGE_ALIGN(0x1000)
+/* Reserve second half of the page for pending bits */
+#define MSIX_PAGE_PENDING (MSIX_PAGE_SIZE / 2)
+#define MSIX_MAX_ENTRIES 32
+
+
+#ifdef MSIX_DEBUG
+#define DEBUG(fmt, ...)                                       \
+    do {                                                      \
+      fprintf(stderr, "%s: " fmt, __func__ , __VA_ARGS__);    \

hw/msix.c line 66

Quoted 10 lines
hw/msix.c new file +10 -0
+    } while (0)
+#else
+#define DEBUG(fmt, ...) do { } while(0)
+#endif
+
+/* Flag to globally disable MSI-X support */
+int msix_disable;
+
+/* Flag for interrupt controller to declare MSI-X support */
+int msix_supported;

maybe better to make it static, and provide msi_state() returning -1 for disabled, 0 for supported, etc...

Quoted 54 lines
hw/msix.c new file +53 -0
+
+/* Add MSI-X capability to the config space for the device. */
+/* Given a bar and its size, add MSI-X table on top of it
+ * and fill MSI-X capability in the config space.
+ * Original bar size must be a power of 2 or 0.
+ * New bar size is returned. */
+static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
+                           unsigned bar_nr, unsigned bar_size)
+{
+    int config_offset;
+    uint8_t *config;
+    uint32_t new_size;
+
+    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+        return -EINVAL;
+    if (bar_size > 0x80000000)
+        return -ENOSPC;
+
+    /* Add space for MSI-X structures */
+    if (!bar_size)
+        new_size = MSIX_PAGE_SIZE;
+    else if (bar_size < MSIX_PAGE_SIZE) {
+        bar_size = MSIX_PAGE_SIZE;
+        new_size = MSIX_PAGE_SIZE * 2;
+    } else
+        new_size = bar_size * 2;
+
+    pdev->msix_bar_size = new_size;
+    config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
+    if (config_offset < 0)
+        return config_offset;
+    config = pdev->config + config_offset;
+
+    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    /* Table on top of BAR */
+    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    /* Pending bits on top of that */
+    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+                 bar_nr);
+    pdev->msix_cap = config_offset;
+    /* Make flags bit writeable. */
+    pdev->wmask[config_offset + MSIX_ENABLE_OFFSET] |= MSIX_ENABLE_MASK;
+    return 0;
+}
+
 
+
+/* Initialize the MSI-X structures. Note: if MSI-X is supported, BAR size is
+ * modified, it should be retrieved with msix_bar_size. */
+int msix_init(struct PCIDevice *dev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size)
+{
+    int ret = -ENOMEM;
+    /* Nothing to do if MSI is not supported by interrupt controller */

hw/msix.c

Quoted 10 lines
hw/msix.c new file +10 -0
+    if (!msix_supported)
+        return -ENOTTY;
+
+    if (nentries > MSIX_MAX_ENTRIES)
+        return -EINVAL;
+
+    dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
+                                        sizeof *dev->msix_entry_used);
+    if (!dev->msix_entry_used)
+        goto err_used;

no need to check. oom_checker will kill qemu if it fails.

hw/msix.c line 247

Quoted 4 lines
hw/msix.c new file +4 -0
+
+    dev->msix_table_page = qemu_mallocz(MSIX_PAGE_SIZE);
+    if (!dev->msix_table_page)
+        goto err_page;

ditto.

#292 lore raw

Re: [Qemu-devel] [PATCHv3 07/13] qemu: minimal MSI/MSI-X implementation for PC

In reply to Michael S. Tsirkin
Quoted 19 lines
     env = cpu_single_env;
     if (!env)
hw/apic.c +1 -1
@@ -727,7 +762,6 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     printf("APIC write: %08x = %08x\n", (uint32_t)addr, val);
 #endif
 
-    index = (addr >> 4) & 0xff;
     switch(index) {
     case 0x02:
         s->id = (val >> 24);
@@ -911,6 +945,7 @@ int apic_init(CPUState *env)
     s->cpu_env = env;
 
     apic_reset(s);
+    msix_supported = 1;
 
     /* XXX: mapping more APICs at the same memory location */
     if (apic_io_memory == 0) {

hw/apic.c int apic_init(CPUState *env) · line 958

Quoted 7 lines
hw/apic.c +2 -1
@@ -918,7 +953,8 @@ int apic_init(CPUState *env)
            on the global memory bus. */
         apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
                                                 apic_mem_write, NULL);
-        cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
+        /* XXX: what if the base changes? */
+        cpu_register_physical_memory(MSI_ADDR_BASE, MSI_ADDR_SIZE,
                                      apic_io_memory);

+1

I think you have a point here. Your patch is in no way worse than what we had, but we're currently not handling correctly the case of base address changing. Guess it is not common in normal apic usage for OSes...

#298 lore raw

Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions

In reply to Michael S. Tsirkin
Quoted 30 lines · Michael S. Tsirkin

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +12 -0
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 416

Quoted 10 lines
hw/pci.c +10 -0
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+

this is a good cleanup...

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 429

Quoted 13 lines
hw/pci.c +13 -0
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+

but the only user of this one seem to be commented out, and later removed. Why is this needed?

#295 lore raw

Re: [Qemu-devel] [PATCHv3 07/13] qemu: minimal MSI/MSI-X implementation for PC

In reply to Michael S. Tsirkin
Quoted 19 lines
     env = cpu_single_env;
     if (!env)
hw/apic.c +1 -1
@@ -727,7 +762,6 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     printf("APIC write: %08x = %08x\n", (uint32_t)addr, val);
 #endif
 
-    index = (addr >> 4) & 0xff;
     switch(index) {
     case 0x02:
         s->id = (val >> 24);
@@ -911,6 +945,7 @@ int apic_init(CPUState *env)
     s->cpu_env = env;
 
     apic_reset(s);
+    msix_supported = 1;
 
     /* XXX: mapping more APICs at the same memory location */
     if (apic_io_memory == 0) {

hw/apic.c int apic_init(CPUState *env) · line 958

Quoted 7 lines
hw/apic.c +2 -1
@@ -918,7 +953,8 @@ int apic_init(CPUState *env)
            on the global memory bus. */
         apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
                                                 apic_mem_write, NULL);
-        cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
+        /* XXX: what if the base changes? */
+        cpu_register_physical_memory(MSI_ADDR_BASE, MSI_ADDR_SIZE,
                                      apic_io_memory);

+1

I think you have a point here. Your patch is in no way worse than what we had, but we're currently not handling correctly the case of base address changing. Guess it is not common in normal apic usage for OSes...

#303 lore raw

Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions

In reply to Michael S. Tsirkin
Quoted 30 lines · Michael S. Tsirkin

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +12 -0
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 416

Quoted 10 lines
hw/pci.c +10 -0
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+

this is a good cleanup...

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 429

Quoted 13 lines
hw/pci.c +13 -0
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+

but the only user of this one seem to be commented out, and later removed. Why is this needed?

#312 lore raw

Re: [Qemu-devel] [PATCHv3 12/13] qemu: virtio save/load bindings

In reply to Michael S. Tsirkin

duplicated save config.

Quoted 5 lines
hw/virtio.h +0 -0
index 04a3c3d..ce05517 100644

hw/virtio.h typedef struct VirtQueueElement · line 80

Quoted 9 lines
hw/virtio.h +4 -0
@@ -72,6 +72,10 @@ typedef struct VirtQueueElement
 
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
+    void (*save_config)(void * opaque, QEMUFile *f);
+    void (*save_queue)(void * opaque, int n, QEMUFile *f);
+    int (*load_config)(void * opaque, QEMUFile *f);
+    int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;
 

So, what's the overall effect on a virtual machine that gets migrated, of a certain device not implementing one of those functions? Will it work? Will it break?

#317 lore raw

Re: [Qemu-devel] [PATCHv3 12/13] qemu: virtio save/load bindings

In reply to Michael S. Tsirkin

duplicated save config.

Quoted 5 lines
hw/virtio.h +0 -0
index 04a3c3d..ce05517 100644

hw/virtio.h typedef struct VirtQueueElement · line 80

Quoted 9 lines
hw/virtio.h +4 -0
@@ -72,6 +72,10 @@ typedef struct VirtQueueElement
 
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
+    void (*save_config)(void * opaque, QEMUFile *f);
+    void (*save_queue)(void * opaque, int n, QEMUFile *f);
+    int (*load_config)(void * opaque, QEMUFile *f);
+    int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;
 

So, what's the overall effect on a virtual machine that gets migrated, of a certain device not implementing one of those functions? Will it work? Will it break?

author maintainer
#8 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Glauber Costa
Quoted 52 lines · Glauber Costa
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 4 lines
hw/pci.c +0 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
Quoted 16 lines
Quoted 4 lines
hw/pci.c +4 -0
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

We lose the ability to let user control the capabilities exposed by the device.

And generally, I dislike arbitrary limitations. The PCI spec says the capability can be anywhere, implementing a linked list of caps is simple enough to not invent abritrary restrictions.

Quoted 35 lines
Quoted 24 lines
hw/pci.c +19 -0
@@ -870,3 +877,76 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static int pci_find_space(PCIDevice *pdev, uint8_t size)
+{
+    int offset = PCI_CONFIG_HEADER_SIZE;
+    int i;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        if (pdev->used[i])
+            offset = i + 1;
+        else if (i - offset + 1 == size)
+            return offset;
+    return 0;
+}
+
+static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
+                                        uint8_t *prev_p)
+{
+    uint8_t next, prev;
+
+    if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST))

hw/pci.c PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) · line 908

Quoted 10 lines
hw/pci.c +10 -0
+        return 0;
+
+    for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
+         prev = next + PCI_CAP_LIST_NEXT)
+        if (pdev->config[next + PCI_CAP_LIST_ID] == cap_id)
+            break;
+
+    *prev_p = prev;
+    return next;
+}

I'd prefer to do:

Quoted 4 lines
	if (prev_p)
		*prev_p = prev;

so we don't have to always pass a prev_p pointer. You have yourself a user where you don't need it in this very patch.

Good idea.

Quoted 99 lines
Quoted 99 lines
hw/pci.c +44 -0
+
+/* Reserve space and add capability to the linked list in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t offset = pci_find_space(pdev, size);
+    uint8_t *config = pdev->config + offset;
+    if (!offset)
+        return -ENOSPC;
+    config[PCI_CAP_LIST_ID] = cap_id;
+    config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
+    pdev->config[PCI_CAPABILITY_LIST] = offset;
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
+    /* Make capability read-only by default */
+    memset(pdev->wmask + offset, 0, size);
+    return offset;
+}
+
+/* Unlink capability from the pci config space. */
+void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev);
+    if (!offset)
+        return;
+    pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];
+    /* Make capability writeable again */
+    memset(pdev->wmask + offset, 0xff, size);
+    memset(pdev->used + offset, 0, size);
+
+    if (!pdev->config[PCI_CAPABILITY_LIST])
+        pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
+}
+
+uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
+{
+    uint8_t prev;
+    return pci_find_capability_list(pdev, cap_id, &prev);
+}
hw/pci.h +17 -1
index 6f0803f..4838c59 100644
@@ -123,6 +123,10 @@ typedef struct PCIIORegion {
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
 #define PCI_MAX_LAT		0x3f	/* 8 bits */
 
+/* Capability lists */
+#define PCI_CAP_LIST_ID		0	/* Capability ID */
+#define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
+
 #define PCI_REVISION            0x08    /* obsolete, use PCI_REVISION_ID */
 #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
 #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
@@ -130,7 +134,7 @@ typedef struct PCIIORegion {
 /* Bits in the PCI Status Register (PCI 2.3 spec) */
 #define PCI_STATUS_RESERVED1	0x007
 #define PCI_STATUS_INT_STATUS	0x008
-#define PCI_STATUS_CAPABILITIES	0x010
+#define PCI_STATUS_CAP_LIST	0x010
 #define PCI_STATUS_66MHZ	0x020
 #define PCI_STATUS_RESERVED2	0x040
 #define PCI_STATUS_FAST_BACK	0x080
@@ -160,6 +164,9 @@ struct PCIDevice {
     /* Used to implement R/W bytes */
     uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
+    /* Used to allocate config space for capabilities. */
+    uint8_t used[PCI_CONFIG_SPACE_SIZE];
+
     /* the following fields are read only */
     PCIBus *bus;
     int devfn;
@@ -194,6 +201,15 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
+uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
+
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
Signature · 1 line
MST
author maintainer
#9 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Glauber Costa
Quoted 52 lines · Glauber Costa
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 4 lines
hw/pci.c +0 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
Quoted 16 lines
Quoted 4 lines
hw/pci.c +4 -0
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

We lose the ability to let user control the capabilities exposed by the device.

And generally, I dislike arbitrary limitations. The PCI spec says the capability can be anywhere, implementing a linked list of caps is simple enough to not invent abritrary restrictions.

Quoted 35 lines
Quoted 24 lines
hw/pci.c +19 -0
@@ -870,3 +877,76 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 
     return (PCIDevice *)dev;
 }
+
+static int pci_find_space(PCIDevice *pdev, uint8_t size)
+{
+    int offset = PCI_CONFIG_HEADER_SIZE;
+    int i;
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        if (pdev->used[i])
+            offset = i + 1;
+        else if (i - offset + 1 == size)
+            return offset;
+    return 0;
+}
+
+static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
+                                        uint8_t *prev_p)
+{
+    uint8_t next, prev;
+
+    if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST))

hw/pci.c PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) · line 908

Quoted 10 lines
hw/pci.c +10 -0
+        return 0;
+
+    for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
+         prev = next + PCI_CAP_LIST_NEXT)
+        if (pdev->config[next + PCI_CAP_LIST_ID] == cap_id)
+            break;
+
+    *prev_p = prev;
+    return next;
+}

I'd prefer to do:

Quoted 4 lines
	if (prev_p)
		*prev_p = prev;

so we don't have to always pass a prev_p pointer. You have yourself a user where you don't need it in this very patch.

Good idea.

Quoted 99 lines
Quoted 99 lines
hw/pci.c +44 -0
+
+/* Reserve space and add capability to the linked list in pci config space */
+int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t offset = pci_find_space(pdev, size);
+    uint8_t *config = pdev->config + offset;
+    if (!offset)
+        return -ENOSPC;
+    config[PCI_CAP_LIST_ID] = cap_id;
+    config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
+    pdev->config[PCI_CAPABILITY_LIST] = offset;
+    pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
+    memset(pdev->used + offset, 0xFF, size);
+    /* Make capability read-only by default */
+    memset(pdev->wmask + offset, 0, size);
+    return offset;
+}
+
+/* Unlink capability from the pci config space. */
+void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
+{
+    uint8_t prev, offset = pci_find_capability_list(pdev, cap_id, &prev);
+    if (!offset)
+        return;
+    pdev->config[prev] = pdev->config[offset + PCI_CAP_LIST_NEXT];
+    /* Make capability writeable again */
+    memset(pdev->wmask + offset, 0xff, size);
+    memset(pdev->used + offset, 0, size);
+
+    if (!pdev->config[PCI_CAPABILITY_LIST])
+        pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST;
+}
+
+/* Reserve space for capability at a known offset (to call after load). */
+void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size)
+{
+    memset(pdev->used + offset, 0xff, size);
+}
+
+uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
+{
+    uint8_t prev;
+    return pci_find_capability_list(pdev, cap_id, &prev);
+}
hw/pci.h +17 -1
index 6f0803f..4838c59 100644
@@ -123,6 +123,10 @@ typedef struct PCIIORegion {
 #define PCI_MIN_GNT		0x3e	/* 8 bits */
 #define PCI_MAX_LAT		0x3f	/* 8 bits */
 
+/* Capability lists */
+#define PCI_CAP_LIST_ID		0	/* Capability ID */
+#define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
+
 #define PCI_REVISION            0x08    /* obsolete, use PCI_REVISION_ID */
 #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
 #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
@@ -130,7 +134,7 @@ typedef struct PCIIORegion {
 /* Bits in the PCI Status Register (PCI 2.3 spec) */
 #define PCI_STATUS_RESERVED1	0x007
 #define PCI_STATUS_INT_STATUS	0x008
-#define PCI_STATUS_CAPABILITIES	0x010
+#define PCI_STATUS_CAP_LIST	0x010
 #define PCI_STATUS_66MHZ	0x020
 #define PCI_STATUS_RESERVED2	0x040
 #define PCI_STATUS_FAST_BACK	0x080
@@ -160,6 +164,9 @@ struct PCIDevice {
     /* Used to implement R/W bytes */
     uint8_t wmask[PCI_CONFIG_SPACE_SIZE];
 
+    /* Used to allocate config space for capabilities. */
+    uint8_t used[PCI_CONFIG_SPACE_SIZE];
+
     /* the following fields are read only */
     PCIBus *bus;
     int devfn;
@@ -194,6 +201,15 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
+
+void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size);
+
+uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
+
+
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len);
 void pci_default_write_config(PCIDevice *d,
Signature · 1 line
1.6.3.1.56.g79e1.dirty
Signature · 1 line
MST
author maintainer
#285 lore raw

Re: [Qemu-devel] [PATCHv3 05/13] qemu: MSI-X support functions

In reply to Glauber Costa
Quoted 93 lines · Glauber Costa
Quoted 92 lines · Michael S. Tsirkin

Add functions implementing MSI-X support. First user will be virtio-pci. Note that platform must set a flag to declare MSI supported. For PC this will be set by APIC.

---
 Makefile.target |    2 +-
 hw/msix.c       |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/msix.h       |   35 +++++
 hw/pci.h        |   20 +++
 4 files changed, 479 insertions(+), 1 deletions(-)
 create mode 100644 hw/msix.c
 create mode 100644 hw/msix.h
Makefile.target +1 -1
index 664a1e3..87b2859 100644
@@ -486,7 +486,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o msix.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
hw/msix.c new file +59 -0
new file mode 100644
index 0000000..1b5aec8
@@ -0,0 +1,423 @@
+/*
+ * MSI-X device support
+ *
+ * This module includes support for MSI-X in pci devices.
+ *
+ * Author: Michael S. Tsirkin <[email protected]>
+ *
+ *  Copyright (c) 2009, Red Hat Inc, Michael S. Tsirkin ([email protected])
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "hw.h"
+#include "msix.h"
+#include "pci.h"
+
+/* Declaration from linux/pci_regs.h */
+#define  PCI_CAP_ID_MSIX 0x11 /* MSI-X */
+#define  PCI_MSIX_FLAGS 2     /* Table at lower 11 bits */
+#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
+#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
+#define  PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+
+/* MSI-X capability structure */
+#define MSIX_TABLE_OFFSET 4
+#define MSIX_PBA_OFFSET 8
+#define MSIX_CAP_LENGTH 12
+
+/* MSI enable bit is in byte 1 in FLAGS register */
+#define MSIX_ENABLE_OFFSET (PCI_MSIX_FLAGS + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
+
+/* MSI-X table format */
+#define MSIX_MSG_ADDR 0
+#define MSIX_MSG_UPPER_ADDR 4
+#define MSIX_MSG_DATA 8
+#define MSIX_VECTOR_CTRL 12
+#define MSIX_ENTRY_SIZE 16
+#define MSIX_VECTOR_MASK 0x1
+
+/* How much space does an MSIX table need. */
+/* The spec requires giving the table structure
+ * a 4K aligned region all by itself. Align it to
+ * target pages so that drivers can do passthrough
+ * on the rest of the region. */
+#define MSIX_PAGE_SIZE TARGET_PAGE_ALIGN(0x1000)
+/* Reserve second half of the page for pending bits */
+#define MSIX_PAGE_PENDING (MSIX_PAGE_SIZE / 2)
+#define MSIX_MAX_ENTRIES 32
+
+
+#ifdef MSIX_DEBUG
+#define DEBUG(fmt, ...)                                       \
+    do {                                                      \
+      fprintf(stderr, "%s: " fmt, __func__ , __VA_ARGS__);    \
+    } while (0)
+#else
+#define DEBUG(fmt, ...) do { } while(0)
Quoted 8 lines

hw/msix.c line 66

Quoted 7 lines
hw/msix.c new file +7 -0
+#endif
+
+/* Flag to globally disable MSI-X support */
+int msix_disable;
+
+/* Flag for interrupt controller to declare MSI-X support */
+int msix_supported;

maybe better to make it static,

It's not read-only either.

Quoted 2 lines

and provide msi_state() returning -1 for disabled, 0 for supported, etc...

Matter of taste, I prefer a set of binary flags rather than yet another enum:
msix_disable is controlled by user, msix_supported is a safety valve for non-PC platforms. It's easier to keep them separate IMO.

Quoted 66 lines
Quoted 54 lines
hw/msix.c new file +53 -0
+
+/* Add MSI-X capability to the config space for the device. */
+/* Given a bar and its size, add MSI-X table on top of it
+ * and fill MSI-X capability in the config space.
+ * Original bar size must be a power of 2 or 0.
+ * New bar size is returned. */
+static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
+                           unsigned bar_nr, unsigned bar_size)
+{
+    int config_offset;
+    uint8_t *config;
+    uint32_t new_size;
+
+    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+        return -EINVAL;
+    if (bar_size > 0x80000000)
+        return -ENOSPC;
+
+    /* Add space for MSI-X structures */
+    if (!bar_size)
+        new_size = MSIX_PAGE_SIZE;
+    else if (bar_size < MSIX_PAGE_SIZE) {
+        bar_size = MSIX_PAGE_SIZE;
+        new_size = MSIX_PAGE_SIZE * 2;
+    } else
+        new_size = bar_size * 2;
+
+    pdev->msix_bar_size = new_size;
+    config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
+    if (config_offset < 0)
+        return config_offset;
+    config = pdev->config + config_offset;
+
+    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    /* Table on top of BAR */
+    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    /* Pending bits on top of that */
+    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+                 bar_nr);
+    pdev->msix_cap = config_offset;
+    /* Make flags bit writeable. */
+    pdev->wmask[config_offset + MSIX_ENABLE_OFFSET] |= MSIX_ENABLE_MASK;
+    return 0;
+}
+
 
+
+/* Initialize the MSI-X structures. Note: if MSI-X is supported, BAR size is
+ * modified, it should be retrieved with msix_bar_size. */
+int msix_init(struct PCIDevice *dev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size)
+{
+    int ret = -ENOMEM;
+    /* Nothing to do if MSI is not supported by interrupt controller */

hw/msix.c

Quoted 10 lines
hw/msix.c new file +10 -0
+    if (!msix_supported)
+        return -ENOTTY;
+
+    if (nentries > MSIX_MAX_ENTRIES)
+        return -EINVAL;
+
+    dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
+                                        sizeof *dev->msix_entry_used);
+    if (!dev->msix_entry_used)
+        goto err_used;

no need to check. oom_checker will kill qemu if it fails.

Quoted 6 lines

hw/msix.c line 247

Quoted 4 lines
hw/msix.c new file +4 -0
+
+    dev->msix_table_page = qemu_mallocz(MSIX_PAGE_SIZE);
+    if (!dev->msix_table_page)
+        goto err_page;

ditto.

Good point.

Signature · 1 line
MST
author maintainer
#293 lore raw

Re: [Qemu-devel] [PATCHv3 07/13] qemu: minimal MSI/MSI-X implementation for PC

In reply to Glauber Costa
Quoted 28 lines · Glauber Costa
Quoted 19 lines
     env = cpu_single_env;
     if (!env)
hw/apic.c +1 -1
@@ -727,7 +762,6 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     printf("APIC write: %08x = %08x\n", (uint32_t)addr, val);
 #endif
 
-    index = (addr >> 4) & 0xff;
     switch(index) {
     case 0x02:
         s->id = (val >> 24);
@@ -911,6 +945,7 @@ int apic_init(CPUState *env)
     s->cpu_env = env;
 
     apic_reset(s);
+    msix_supported = 1;
 
     /* XXX: mapping more APICs at the same memory location */
     if (apic_io_memory == 0) {

hw/apic.c int apic_init(CPUState *env) · line 958

Quoted 7 lines
hw/apic.c +2 -1
@@ -918,7 +953,8 @@ int apic_init(CPUState *env)
            on the global memory bus. */
         apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
                                                 apic_mem_write, NULL);
-        cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
+        /* XXX: what if the base changes? */
+        cpu_register_physical_memory(MSI_ADDR_BASE, MSI_ADDR_SIZE,
                                      apic_io_memory);

+1

Quoted 2 lines

I think you have a point here. Your patch is in no way worse than what we had, but we're currently not handling correctly the case of base address changing.

Yep.

Quoted 1 line

Guess it is not common in normal apic usage for OSes...

Signature · 1 line
MST
author maintainer
#286 lore raw

Re: [Qemu-devel] [PATCHv3 05/13] qemu: MSI-X support functions

In reply to Glauber Costa
Quoted 93 lines · Glauber Costa
Quoted 92 lines · Michael S. Tsirkin

Add functions implementing MSI-X support. First user will be virtio-pci. Note that platform must set a flag to declare MSI supported. For PC this will be set by APIC.

---
 Makefile.target |    2 +-
 hw/msix.c       |  423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/msix.h       |   35 +++++
 hw/pci.h        |   20 +++
 4 files changed, 479 insertions(+), 1 deletions(-)
 create mode 100644 hw/msix.c
 create mode 100644 hw/msix.h
Makefile.target +1 -1
index 664a1e3..87b2859 100644
@@ -486,7 +486,7 @@ endif #CONFIG_BSD_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \
-     gdbstub.o gdbstub-xml.o
+     gdbstub.o gdbstub-xml.o msix.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
hw/msix.c new file +59 -0
new file mode 100644
index 0000000..1b5aec8
@@ -0,0 +1,423 @@
+/*
+ * MSI-X device support
+ *
+ * This module includes support for MSI-X in pci devices.
+ *
+ * Author: Michael S. Tsirkin <[email protected]>
+ *
+ *  Copyright (c) 2009, Red Hat Inc, Michael S. Tsirkin ([email protected])
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "hw.h"
+#include "msix.h"
+#include "pci.h"
+
+/* Declaration from linux/pci_regs.h */
+#define  PCI_CAP_ID_MSIX 0x11 /* MSI-X */
+#define  PCI_MSIX_FLAGS 2     /* Table at lower 11 bits */
+#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
+#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
+#define  PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+
+/* MSI-X capability structure */
+#define MSIX_TABLE_OFFSET 4
+#define MSIX_PBA_OFFSET 8
+#define MSIX_CAP_LENGTH 12
+
+/* MSI enable bit is in byte 1 in FLAGS register */
+#define MSIX_ENABLE_OFFSET (PCI_MSIX_FLAGS + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
+
+/* MSI-X table format */
+#define MSIX_MSG_ADDR 0
+#define MSIX_MSG_UPPER_ADDR 4
+#define MSIX_MSG_DATA 8
+#define MSIX_VECTOR_CTRL 12
+#define MSIX_ENTRY_SIZE 16
+#define MSIX_VECTOR_MASK 0x1
+
+/* How much space does an MSIX table need. */
+/* The spec requires giving the table structure
+ * a 4K aligned region all by itself. Align it to
+ * target pages so that drivers can do passthrough
+ * on the rest of the region. */
+#define MSIX_PAGE_SIZE TARGET_PAGE_ALIGN(0x1000)
+/* Reserve second half of the page for pending bits */
+#define MSIX_PAGE_PENDING (MSIX_PAGE_SIZE / 2)
+#define MSIX_MAX_ENTRIES 32
+
+
+#ifdef MSIX_DEBUG
+#define DEBUG(fmt, ...)                                       \
+    do {                                                      \
+      fprintf(stderr, "%s: " fmt, __func__ , __VA_ARGS__);    \
+    } while (0)
+#else
+#define DEBUG(fmt, ...) do { } while(0)
Quoted 8 lines

hw/msix.c line 66

Quoted 7 lines
hw/msix.c new file +7 -0
+#endif
+
+/* Flag to globally disable MSI-X support */
+int msix_disable;
+
+/* Flag for interrupt controller to declare MSI-X support */
+int msix_supported;

maybe better to make it static,

It's not read-only either.

Quoted 2 lines

and provide msi_state() returning -1 for disabled, 0 for supported, etc...

Matter of taste, I prefer a set of binary flags rather than yet another enum:
msix_disable is controlled by user, msix_supported is a safety valve for non-PC platforms. It's easier to keep them separate IMO.

Quoted 66 lines
Quoted 54 lines
hw/msix.c new file +53 -0
+
+/* Add MSI-X capability to the config space for the device. */
+/* Given a bar and its size, add MSI-X table on top of it
+ * and fill MSI-X capability in the config space.
+ * Original bar size must be a power of 2 or 0.
+ * New bar size is returned. */
+static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
+                           unsigned bar_nr, unsigned bar_size)
+{
+    int config_offset;
+    uint8_t *config;
+    uint32_t new_size;
+
+    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+        return -EINVAL;
+    if (bar_size > 0x80000000)
+        return -ENOSPC;
+
+    /* Add space for MSI-X structures */
+    if (!bar_size)
+        new_size = MSIX_PAGE_SIZE;
+    else if (bar_size < MSIX_PAGE_SIZE) {
+        bar_size = MSIX_PAGE_SIZE;
+        new_size = MSIX_PAGE_SIZE * 2;
+    } else
+        new_size = bar_size * 2;
+
+    pdev->msix_bar_size = new_size;
+    config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
+    if (config_offset < 0)
+        return config_offset;
+    config = pdev->config + config_offset;
+
+    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    /* Table on top of BAR */
+    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    /* Pending bits on top of that */
+    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+                 bar_nr);
+    pdev->msix_cap = config_offset;
+    /* Make flags bit writeable. */
+    pdev->wmask[config_offset + MSIX_ENABLE_OFFSET] |= MSIX_ENABLE_MASK;
+    return 0;
+}
+
 
+
+/* Initialize the MSI-X structures. Note: if MSI-X is supported, BAR size is
+ * modified, it should be retrieved with msix_bar_size. */
+int msix_init(struct PCIDevice *dev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size)
+{
+    int ret = -ENOMEM;
+    /* Nothing to do if MSI is not supported by interrupt controller */

hw/msix.c

Quoted 10 lines
hw/msix.c new file +10 -0
+    if (!msix_supported)
+        return -ENOTTY;
+
+    if (nentries > MSIX_MAX_ENTRIES)
+        return -EINVAL;
+
+    dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
+                                        sizeof *dev->msix_entry_used);
+    if (!dev->msix_entry_used)
+        goto err_used;

no need to check. oom_checker will kill qemu if it fails.

Quoted 6 lines

hw/msix.c line 247

Quoted 4 lines
hw/msix.c new file +4 -0
+
+    dev->msix_table_page = qemu_mallocz(MSIX_PAGE_SIZE);
+    if (!dev->msix_table_page)
+        goto err_page;

ditto.

Good point.

Signature · 1 line
MST
author maintainer
#294 lore raw

Re: [Qemu-devel] [PATCHv3 07/13] qemu: minimal MSI/MSI-X implementation for PC

In reply to Glauber Costa
Quoted 28 lines · Glauber Costa
Quoted 19 lines
     env = cpu_single_env;
     if (!env)
hw/apic.c +1 -1
@@ -727,7 +762,6 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     printf("APIC write: %08x = %08x\n", (uint32_t)addr, val);
 #endif
 
-    index = (addr >> 4) & 0xff;
     switch(index) {
     case 0x02:
         s->id = (val >> 24);
@@ -911,6 +945,7 @@ int apic_init(CPUState *env)
     s->cpu_env = env;
 
     apic_reset(s);
+    msix_supported = 1;
 
     /* XXX: mapping more APICs at the same memory location */
     if (apic_io_memory == 0) {

hw/apic.c int apic_init(CPUState *env) · line 958

Quoted 7 lines
hw/apic.c +2 -1
@@ -918,7 +953,8 @@ int apic_init(CPUState *env)
            on the global memory bus. */
         apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
                                                 apic_mem_write, NULL);
-        cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
+        /* XXX: what if the base changes? */
+        cpu_register_physical_memory(MSI_ADDR_BASE, MSI_ADDR_SIZE,
                                      apic_io_memory);

+1

Quoted 2 lines

I think you have a point here. Your patch is in no way worse than what we had, but we're currently not handling correctly the case of base address changing.

Yep.

Quoted 1 line

Guess it is not common in normal apic usage for OSes...

Signature · 1 line
MST
author maintainer
#299 lore raw

Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions

In reply to Glauber Costa
Quoted 43 lines · Glauber Costa
Quoted 30 lines · Michael S. Tsirkin

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +12 -0
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 416

Quoted 10 lines
hw/pci.c +10 -0
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+

this is a good cleanup...

Quoted 16 lines

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 429

Quoted 13 lines
hw/pci.c +13 -0
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+

but the only user of this one seem to be commented out, and later removed. Why is this needed?

Um, I think this needs to be called on load: virtio has a memmory region if and only if it has MSI-X.

Signature · 1 line
MST
author maintainer
#300 lore raw

Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions

In reply to Glauber Costa
Quoted 43 lines · Glauber Costa
Quoted 30 lines · Michael S. Tsirkin

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +12 -0
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 416

Quoted 10 lines
hw/pci.c +10 -0
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+

this is a good cleanup...

Quoted 16 lines

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 429

Quoted 13 lines
hw/pci.c +13 -0
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+

but the only user of this one seem to be commented out, and later removed. Why is this needed?

Um, I think this needs to be called on load: virtio has a memmory region if and only if it has MSI-X.

Signature · 1 line
MST
author maintainer
#313 lore raw

Re: [Qemu-devel] [PATCHv3 12/13] qemu: virtio save/load bindings

In reply to Glauber Costa
Quoted 8 lines · Glauber Costa

duplicated save config.

Quoted 6 lines
hw/virtio.h +0 -0
index 04a3c3d..ce05517 100644
@@ -72,6 +72,10 @@ typedef struct VirtQueueElement
 
Quoted 10 lines

hw/virtio.h typedef struct VirtQueueElement · line 80

Quoted 8 lines
hw/virtio.h +4 -0
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
+    void (*save_config)(void * opaque, QEMUFile *f);
+    void (*save_queue)(void * opaque, int n, QEMUFile *f);
+    int (*load_config)(void * opaque, QEMUFile *f);
+    int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;
 

So, what's the overall effect on a virtual machine that gets migrated, of a certain device not implementing one of those functions?

Those are implemented by a transport (e.g. virtio_pci) not the device.

Quoted 1 line

Will it work? Will it break?

It will work - assuming there's nothing transport-specific you need to save and load. If there is - this patch is not breaking anything that isn't already broken ...

Signature · 1 line
MST
author maintainer
#314 lore raw

Re: [Qemu-devel] [PATCHv3 12/13] qemu: virtio save/load bindings

In reply to Glauber Costa
Quoted 8 lines · Glauber Costa

duplicated save config.

Quoted 6 lines
hw/virtio.h +0 -0
index 04a3c3d..ce05517 100644
@@ -72,6 +72,10 @@ typedef struct VirtQueueElement
 
Quoted 10 lines

hw/virtio.h typedef struct VirtQueueElement · line 80

Quoted 8 lines
hw/virtio.h +4 -0
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
+    void (*save_config)(void * opaque, QEMUFile *f);
+    void (*save_queue)(void * opaque, int n, QEMUFile *f);
+    int (*load_config)(void * opaque, QEMUFile *f);
+    int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;
 

So, what's the overall effect on a virtual machine that gets migrated, of a certain device not implementing one of those functions?

Those are implemented by a transport (e.g. virtio_pci) not the device.

Quoted 1 line

Will it work? Will it break?

It will work - assuming there's nothing transport-specific you need to save and load. If there is - this patch is not breaking anything that isn't already broken ...

Signature · 1 line
MST
author maintainer
#301 lore raw

Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions

In reply to Glauber Costa
Quoted 43 lines · Glauber Costa
Quoted 30 lines · Michael S. Tsirkin

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +12 -0
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 416

Quoted 10 lines
hw/pci.c +10 -0
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+

this is a good cleanup...

Quoted 16 lines

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 429

Quoted 13 lines
hw/pci.c +13 -0
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+

but the only user of this one seem to be commented out, and later removed. Why is this needed?

This was the missing bit:

Set correct size for msi-x memory region when loading the device.

hw/virtio-pci.c +2 -0
index 589fbb1..f657364 100644
@@ -133,6 +133,8 @@ static int virtio_pci_load_config(void * opaque, QEMUFile *f)
         return ret;
     if (msix_present(&proxy->pci_dev))
         qemu_get_be16s(f, &proxy->vdev->config_vector);
+
+    pci_resize_io_region(&proxy->pci_dev, 1, msix_bar_size(&proxy->pci_dev));
     return 0;
 }
 
Signature · 1 line
MST
author maintainer
#302 lore raw

Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions

In reply to Glauber Costa
Quoted 43 lines · Glauber Costa
Quoted 30 lines · Michael S. Tsirkin

Make it possible to resize PCI regions. This will be used by virtio with MSI-X, where the region size depends on whether MSI-X is enabled, and can change across load/save.

---
 hw/pci.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 hw/pci.h |    3 +++
 2 files changed, 39 insertions(+), 18 deletions(-)
hw/pci.c +12 -0
index ed011b5..042a216 100644
@@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
     *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask);
 }
 
+static void pci_unmap_region(PCIDevice *d, PCIIORegion *r)
+{
+    if (r->addr == -1)
+        return;
+    if (r->type & PCI_ADDRESS_SPACE_IO) {
+        int class;
+        /* NOTE: specific hack for IDE in PC case:
+           only one byte must be mapped. */
+        class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+        if (class == 0x0101 && r->size == 4) {
+            isa_unassign_ioport(r->addr + 2, 1);
+        } else {

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 416

Quoted 10 lines
hw/pci.c +10 -0
+            isa_unassign_ioport(r->addr, r->size);
+        }
+    } else {
+        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                     r->size,
+                                     IO_MEM_UNASSIGNED);
+        qemu_unregister_coalesced_mmio(r->addr, r->size);
+    }
+}
+

this is a good cleanup...

Quoted 16 lines

hw/pci.c void pci_register_io_region(PCIDevice *pci_dev, int region_num, · line 429

Quoted 13 lines
hw/pci.c +13 -0
+void pci_resize_io_region(PCIDevice *pci_dev, int region_num,
+                          uint32_t size)
+{
+
+    PCIIORegion *r = &pci_dev->io_regions[region_num];
+    if (r->size == size)
+        return;
+    r->size = size;
+    pci_unmap_region(pci_dev, r);
+    r->addr = -1;
+    pci_update_mappings(pci_dev);
+}
+

but the only user of this one seem to be commented out, and later removed. Why is this needed?

This was the missing bit:

Set correct size for msi-x memory region when loading the device.

hw/virtio-pci.c +2 -0
index 589fbb1..f657364 100644
@@ -133,6 +133,8 @@ static int virtio_pci_load_config(void * opaque, QEMUFile *f)
         return ret;
     if (msix_present(&proxy->pci_dev))
         qemu_get_be16s(f, &proxy->vdev->config_vector);
+
+    pci_resize_io_region(&proxy->pci_dev, 1, msix_bar_size(&proxy->pci_dev));
     return 0;
 }
 
Signature · 1 line
MST
#10 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Michael S. Tsirkin
Quoted 70 lines · Michael S. Tsirkin
Quoted 52 lines · Glauber Costa
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 4 lines
hw/pci.c +0 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
Quoted 16 lines
Quoted 4 lines
hw/pci.c +4 -0
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

Quoted 6 lines

We lose the ability to let user control the capabilities exposed by the device.

And generally, I dislike arbitrary limitations. The PCI spec says the capability can be anywhere, implementing a linked list of caps is simple enough to not invent abritrary restrictions.

yes, but this is migration time, right?

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

#278 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Michael S. Tsirkin
Quoted 70 lines · Michael S. Tsirkin
Quoted 52 lines · Glauber Costa
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 4 lines
hw/pci.c +0 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
Quoted 16 lines
Quoted 4 lines
hw/pci.c +4 -0
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

Quoted 6 lines

We lose the ability to let user control the capabilities exposed by the device.

And generally, I dislike arbitrary limitations. The PCI spec says the capability can be anywhere, implementing a linked list of caps is simple enough to not invent abritrary restrictions.

yes, but this is migration time, right?

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

author maintainer
#11 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Glauber Costa
Quoted 71 lines · Glauber Costa
Quoted 70 lines · Michael S. Tsirkin
Quoted 68 lines · Glauber Costa
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 8 lines
hw/pci.c +4 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

Quoted 7 lines
Quoted 6 lines

We lose the ability to let user control the capabilities exposed by the device.

And generally, I dislike arbitrary limitations. The PCI spec says the capability can be anywhere, implementing a linked list of caps is simple enough to not invent abritrary restrictions.

yes, but this is migration time, right?

I think so, yes.

Quoted 5 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

Maybe this explanation should go into the comment above?

Signature · 1 line
MST
author maintainer
#12 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Glauber Costa
Quoted 71 lines · Glauber Costa
Quoted 70 lines · Michael S. Tsirkin
Quoted 68 lines · Glauber Costa
Quoted 17 lines · Michael S. Tsirkin

Add routines to manage PCI capability list. First user will be MSI-X.

---
 hw/pci.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 hw/pci.h |   18 +++++++++++-
 2 files changed, 106 insertions(+), 10 deletions(-)
hw/pci.c +0 -1
index 361d741..ed011b5 100644
@@ -130,12 +130,13 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)
     int version = s->cap_present ? 3 : 2;
     int i;
 
-    qemu_put_be32(f, version); /* PCI device version */

hw/pci.c void pci_device_save(PCIDevice *s, QEMUFile *f) · line 140

Quoted 10 lines
hw/pci.c +4 -2
+    /* PCI device version and capabilities */
+    qemu_put_be32(f, version);
+    if (version >= 3)
+        qemu_put_be32(f, s->cap_present);
     qemu_put_buffer(f, s->config, 256);
     for (i = 0; i < 4; i++)
         qemu_put_be32(f, s->irq_state[i]);
-    if (version >= 3)
-        qemu_put_be32(f, s->cap_present);
 }

What is it doing here?
You should just do it right in the first patch, instead of doing in one way there, and fixing here.

Quoted 5 lines
hw/pci.c +0 -0
 int pci_device_load(PCIDevice *s, QEMUFile *f)
@@ -146,12 +147,6 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     version_id = qemu_get_be32(f);
     if (version_id > 3)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 152

Quoted 10 lines
hw/pci.c +0 -6
         return -EINVAL;
-    qemu_get_buffer(f, s->config, 256);
-    pci_update_mappings(s);
-
-    if (version_id >= 2)
-        for (i = 0; i < 4; i ++)
-            s->irq_state[i] = qemu_get_be32(f);
     if (version_id >= 3)
         s->cap_present = qemu_get_be32(f);
     else

ditto.

Quoted 8 lines
hw/pci.c +4 -0
@@ -160,6 +155,18 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     if (s->cap_present & ~s->cap_supported)
         return -EINVAL;
 
+    qemu_get_buffer(f, s->config, 256);
+    pci_update_mappings(s);
+
+    if (version_id >= 2)

hw/pci.c int pci_device_load(PCIDevice *s, QEMUFile *f) · line 171

Quoted 10 lines
hw/pci.c +8 -0
+        for (i = 0; i < 4; i ++)
+            s->irq_state[i] = qemu_get_be32(f);
+    /* Clear wmask and used bits for capabilities.
+       Must be restored separately, since capabilities can
+       be placed anywhere in config space. */
+    memset(s->used, 0, PCI_CONFIG_SPACE_SIZE);
+    for (i = PCI_CONFIG_HEADER_SIZE; i < PCI_CONFIG_SPACE_SIZE; ++i)
+        s->wmask[i] = 0xff;
     return 0;
 }

Sorry, I don't exactly understand it. Although it can be anywhere, what do we actually lose by keeping it at the same place in config space?

Quoted 7 lines
Quoted 6 lines

We lose the ability to let user control the capabilities exposed by the device.

And generally, I dislike arbitrary limitations. The PCI spec says the capability can be anywhere, implementing a linked list of caps is simple enough to not invent abritrary restrictions.

yes, but this is migration time, right?

I think so, yes.

Quoted 5 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

Maybe this explanation should go into the comment above?

Signature · 1 line
MST
#13 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

We should not be loading state into a different device (or a similar device with a different set of capabilities).

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

Paul

#14 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Michael S. Tsirkin
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

We should not be loading state into a different device (or a similar device with a different set of capabilities).

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

Paul

author maintainer
#15 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

Quoted 13 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

We should not be loading state into a different device (or a similar device with a different set of capabilities).

Quoted 6 lines

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

Paul

Why shouldn't it? You don't load a snapshot while guest is running.

Signature · 1 line
MST
author maintainer
#16 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Paul Brook
Quoted 13 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

We should not be loading state into a different device (or a similar device with a different set of capabilities).

Quoted 6 lines

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

Paul

Why shouldn't it? You don't load a snapshot while guest is running.

Signature · 1 line
MST
#17 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Paul Brook
Quoted 10 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

Quoted 7 lines

We should not be loading state into a different device (or a similar device with a different set of capabilities).

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

If you can create a machine be restoring a snapshot which you can't create by normally starting QEMU, then you'll soon have guests which work fine from their snapshots, but which cannot be booted without a snapshot because there's no way to boot the right machine for the guest.

Ssomeone might even have guests like that for years without noticing, because they always save and restore guest state using snapshots, then one day they simply want to boot the guest from it's disk image and find there's no way to do it with any QEMU which runs on their host platform.

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

-- Jamie

#18 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Paul Brook
Quoted 10 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

Quoted 7 lines

We should not be loading state into a different device (or a similar device with a different set of capabilities).

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

If you can create a machine be restoring a snapshot which you can't create by normally starting QEMU, then you'll soon have guests which work fine from their snapshots, but which cannot be booted without a snapshot because there's no way to boot the right machine for the guest.

Ssomeone might even have guests like that for years without noticing, because they always save and restore guest state using snapshots, then one day they simply want to boot the guest from it's disk image and find there's no way to do it with any QEMU which runs on their host platform.

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

-- Jamie

author maintainer
#19 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

Quoted 19 lines · Jamie Lokier
Quoted 10 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

Quoted 7 lines

We should not be loading state into a different device (or a similar device with a different set of capabilities).

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

Quoted 4 lines

If you can create a machine be restoring a snapshot which you can't create by normally starting QEMU, then you'll soon have guests which work fine from their snapshots, but which cannot be booted without a snapshot because there's no way to boot the right machine for the guest.

Yes. This clearly isn't what I'm building here. You *can* create a guest without msi-x support by passing an appropriate flag.

Quoted 11 lines

Ssomeone might even have guests like that for years without noticing, because they always save and restore guest state using snapshots, then one day they simply want to boot the guest from it's disk image and find there's no way to do it with any QEMU which runs on their host platform.

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

-- Jamie

And then we'll have the same set of problems there.

Signature · 1 line
MST
author maintainer
#20 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Jamie Lokier
Quoted 19 lines · Jamie Lokier
Quoted 10 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines

caps can be anywhere, but we don't expect it to change during machine execution lifetime.

Or I am just confused by the name "pci_device_load" ?

Right. So I want to load an image and it has capability X at offset Y. wmask has to match. I don't want to assume that we never change Y for the device without breaking old images, so I clear wmask here and set it up again after looking up capabilities that I loaded.

Quoted 7 lines

We should not be loading state into a different device (or a similar device with a different set of capabilities).

If you want to provide backwards compatibility then you should do that by creating a device that is the same as the original. As I mentioned in my earlier mail, loading a snapshot should never do anything that can not be achieved through normal operation.

Quoted 4 lines

If you can create a machine be restoring a snapshot which you can't create by normally starting QEMU, then you'll soon have guests which work fine from their snapshots, but which cannot be booted without a snapshot because there's no way to boot the right machine for the guest.

Yes. This clearly isn't what I'm building here. You *can* create a guest without msi-x support by passing an appropriate flag.

Quoted 11 lines

Ssomeone might even have guests like that for years without noticing, because they always save and restore guest state using snapshots, then one day they simply want to boot the guest from it's disk image and find there's no way to do it with any QEMU which runs on their host platform.

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

-- Jamie

And then we'll have the same set of problems there.

Signature · 1 line
MST
#21 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

-- Jamie

#22 lore raw

Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

-- Jamie

#23 lore raw

Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 11 lines · Jamie Lokier
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 6 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

= Problem 2 - We can't predict the future =

If a VM manager supplies a configuration which is missing any given option, qemu cannot tell the difference between:

- This is a basic config, the VM manager wants whatever the default of the current qemu version

- This is a complete config dumped using an old version of qemu, the VM manager wants the old default

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

- Use defaults where compat hints are not available; e.g. if the VM manager specifies a device config, but no compat hints are supplied for it, then just use default values

- Make the config override compat hints; e.g. if there are compat hints specified for a device not included in the machine config, just ignore those hints

Cheers,
Mark.

#24 lore raw

Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Jamie Lokier
Quoted 11 lines · Jamie Lokier
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 6 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

= Problem 2 - We can't predict the future =

If a VM manager supplies a configuration which is missing any given option, qemu cannot tell the difference between:

- This is a basic config, the VM manager wants whatever the default of the current qemu version

- This is a complete config dumped using an old version of qemu, the VM manager wants the old default

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

- Use defaults where compat hints are not available; e.g. if the VM manager specifies a device config, but no compat hints are supplied for it, then just use default values

- Make the config override compat hints; e.g. if there are compat hints specified for a device not included in the machine config, just ignore those hints

Cheers,
Mark.

author maintainer
#25 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 6 lines · Mark McLoughlin

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

Why make it "like the savevm" format then?
If they are opaque anyway, compat hints could be part of savevm format.

Quoted 10 lines

- Use defaults where compat hints are not available; e.g. if the VM manager specifies a device config, but no compat hints are supplied for it, then just use default values

- Make the config override compat hints; e.g. if there are compat hints specified for a device not included in the machine config, just ignore those hints

Cheers,
Mark.

If compat hints are opaque and only editable by qemu, we can get into a situation where one can't create a specific setup with a new qemu.

Signature · 1 line
MST
author maintainer
#26 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 6 lines · Mark McLoughlin

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

Why make it "like the savevm" format then?
If they are opaque anyway, compat hints could be part of savevm format.

Quoted 10 lines

- Use defaults where compat hints are not available; e.g. if the VM manager specifies a device config, but no compat hints are supplied for it, then just use default values

- Make the config override compat hints; e.g. if there are compat hints specified for a device not included in the machine config, just ignore those hints

Cheers,
Mark.

If compat hints are opaque and only editable by qemu, we can get into a situation where one can't create a specific setup with a new qemu.

Signature · 1 line
MST
#27 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · Mark McLoughlin

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

Why make it "like the savevm" format then?
If they are opaque anyway, compat hints could be part of savevm format.

So a "savevm --only-compat-hints" command? It might make sense, since we would want the compat hints with savevm too.

Quoted 8 lines
Quoted 8 lines

- Use defaults where compat hints are not available; e.g. if the VM manager specifies a device config, but no compat hints are supplied for it, then just use default values

- Make the config override compat hints; e.g. if there are compat hints specified for a device not included in the machine config, just ignore those hints

Quoted 5 lines
Quoted 2 lines

Cheers,
Mark.

If compat hints are opaque and only editable by qemu, we can get into a situation where one can't create a specific setup with a new qemu.

An example?

Cheers,
Mark.

#28 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin
Quoted 6 lines · Mark McLoughlin

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

Why make it "like the savevm" format then?
If they are opaque anyway, compat hints could be part of savevm format.

So a "savevm --only-compat-hints" command? It might make sense, since we would want the compat hints with savevm too.

Quoted 8 lines
Quoted 8 lines

- Use defaults where compat hints are not available; e.g. if the VM manager specifies a device config, but no compat hints are supplied for it, then just use default values

- Make the config override compat hints; e.g. if there are compat hints specified for a device not included in the machine config, just ignore those hints

Quoted 5 lines
Quoted 2 lines

Cheers,
Mark.

If compat hints are opaque and only editable by qemu, we can get into a situation where one can't create a specific setup with a new qemu.

An example?

Cheers,
Mark.

#29 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 33 lines · Mark McLoughlin
Quoted 12 lines · Jamie Lokier
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 7 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

Quoted 8 lines

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

Regards,

Anthony Liguori

#30 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 33 lines · Mark McLoughlin
Quoted 12 lines · Jamie Lokier
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 7 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

Quoted 8 lines

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

Regards,

Anthony Liguori

#236 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 9 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

Regards,

Anthony Liguori

#277 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 9 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

Regards,

Anthony Liguori

#31 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 38 lines · Anthony Liguori
Quoted 37 lines · Mark McLoughlin
Quoted 12 lines · Jamie Lokier
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 7 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

Quoted 7 lines
Quoted 4 lines

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

Yes, complexity is the issue.

Quoted 2 lines

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

In libvirt's case, a lot of the complexity would come from needing to figure out what to change.

i.e. libvirt produces a qemu configuration (currently a command line) from a guest XML's configuration; with this idea, libvirt would probably compare the old XML config to the new XML config, and then apply those differences to the qemu configuration.

Cheers,
Mark.

#32 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 38 lines · Anthony Liguori
Quoted 37 lines · Mark McLoughlin
Quoted 12 lines · Jamie Lokier
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 7 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

Quoted 7 lines
Quoted 4 lines

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

Yes, complexity is the issue.

Quoted 2 lines

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

In libvirt's case, a lot of the complexity would come from needing to figure out what to change.

i.e. libvirt produces a qemu configuration (currently a command line) from a guest XML's configuration; with this idea, libvirt would probably compare the old XML config to the new XML config, and then apply those differences to the qemu configuration.

Cheers,
Mark.

#237 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

Quoted 8 lines
Quoted 3 lines

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Cheers,
Mark.

[1] - Adding such a per-device version number to the config file would solve problem (2)

#238 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

Quoted 8 lines
Quoted 3 lines

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Cheers,
Mark.

[1] - Adding such a per-device version number to the config file would solve problem (2)

#33 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 57 lines · Mark McLoughlin
Quoted 43 lines · Anthony Liguori
Quoted 41 lines · Mark McLoughlin
Quoted 15 lines · Jamie Lokier
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 8 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

Quoted 8 lines
Quoted 5 lines

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

Yes, complexity is the issue.

Quoted 7 lines
Quoted 3 lines

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

In libvirt's case, a lot of the complexity would come from needing to figure out what to change.

Right, libvirt wants to be able to easily say "add a scsi block device to this VM". The way I see this working is that there would be a default pc.dtc. We would still have a -drive file=foo.img,if=scsi option that would really just be a wrapper around first searching for an existing LSI controller, if one exists, attaching the lun, if not, create one, etc.

libvirt could continue to use this sort of interface. However, as it wants to do more advanced things, it may have to dive into the device tree itself.

On live migration, QEMU will save a copy of the device tree somewhere and libvirt needs to keep track of it. It can treat it as opaque. -M /path/to/foo.dtc -drive file=foo.img,if=scsi should continue working as expected IMHO.

Regards,

Anthony Liguori

#34 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 53 lines · Mark McLoughlin
Quoted 43 lines · Anthony Liguori
Quoted 41 lines · Mark McLoughlin
Quoted 15 lines · Jamie Lokier
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 8 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

Quoted 7 lines
Quoted 5 lines

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

Quoted 9 lines

Yes, complexity is the issue.

Quoted 2 lines

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

In libvirt's case, a lot of the complexity would come from needing to figure out what to change.

Right, libvirt wants to be able to easily say "add a scsi block device to this VM". The way I see this working is that there would be a default pc.dtc. We would still have a -drive file=foo.img,if=scsi option that would really just be a wrapper around first searching for an existing LSI controller, if one exists, attaching the lun, if not, create one, etc.

libvirt could continue to use this sort of interface. However, as it wants to do more advanced things, it may have to dive into the device tree itself.

On live migration, QEMU will save a copy of the device tree somewhere and libvirt needs to keep track of it. It can treat it as opaque. -M /path/to/foo.dtc -drive file=foo.img,if=scsi should continue working as expected IMHO.

Regards,

Anthony Liguori

#239 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 16 lines · Mark McLoughlin
Quoted 14 lines · Anthony Liguori
Quoted 10 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

Quoted 9 lines
Quoted 3 lines

In my mind, that's what compat hints is. I don't see another sane way to implement it.

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

I think the point is that you don't need version numbers if you have a proper device tree. NB the device tree contains no host configuration information.

Regards,

Anthony Liguori

Quoted 11 lines

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Cheers,
Mark.

[1] - Adding such a per-device version number to the config file would solve problem (2)

#240 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 16 lines · Mark McLoughlin
Quoted 14 lines · Anthony Liguori
Quoted 10 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

Quoted 8 lines
Quoted 2 lines

In my mind, that's what compat hints is. I don't see another sane way to implement it.

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

I think the point is that you don't need version numbers if you have a proper device tree. NB the device tree contains no host configuration information.

Regards,

Anthony Liguori

Quoted 11 lines

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Cheers,
Mark.

[1] - Adding such a per-device version number to the config file would solve problem (2)

#35 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 73 lines · Anthony Liguori
Quoted 57 lines · Mark McLoughlin
Quoted 43 lines · Anthony Liguori
Quoted 41 lines · Mark McLoughlin
Quoted 15 lines · Jamie Lokier
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 8 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

Quoted 8 lines
Quoted 5 lines

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

Yes, complexity is the issue.

Quoted 7 lines
Quoted 3 lines

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

In libvirt's case, a lot of the complexity would come from needing to figure out what to change.

Right, libvirt wants to be able to easily say "add a scsi block device to this VM". The way I see this working is that there would be a default pc.dtc. We would still have a -drive file=foo.img,if=scsi option that would really just be a wrapper around first searching for an existing LSI controller, if one exists, attaching the lun, if not, create one, etc.

Quoted 8 lines

libvirt could continue to use this sort of interface. However, as it wants to do more advanced things, it may have to dive into the device tree itself.

On live migration, QEMU will save a copy of the device tree somewhere and libvirt needs to keep track of it. It can treat it as opaque. -M /path/to/foo.dtc -drive file=foo.img,if=scsi should continue working as expected IMHO.

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

The basic problem would be that the command line config would have very limited ability to override the device tree config.

Cheers,
Mark.

#241 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 21 lines · Anthony Liguori
Quoted 20 lines · Mark McLoughlin
Quoted 17 lines · Anthony Liguori
Quoted 10 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

Quoted 8 lines
Quoted 5 lines

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Quoted 1 line

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

Cheers,
Mark.

#36 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 73 lines · Anthony Liguori
Quoted 57 lines · Mark McLoughlin
Quoted 43 lines · Anthony Liguori
Quoted 41 lines · Mark McLoughlin
Quoted 15 lines · Jamie Lokier
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines

I think the right long term answer to all this is a way to get QEMU to dump it's current machine configuration in glorious detail as a file which can be reloaded as a machine configuration.

And then we'll have the same set of problems there.

We will, and the solution will be the same: options to create devices as they were in older versions of QEMU. It only needs to cover device features which matter to guests, not every bug fix.

Quoted 8 lines

However with a machine configuration which is generated by QEMU, there's less worry about proliferation of obscure options, compared with the command line. You don't necessarily have to document every backward-compatibility option in any detail, you just have to make sure it's written and read properly, which is much the same thing as the snapshot code does.

This is a sensible plan, but I don't think we should mix these compat options in with the VM manager supplied configuration.

There are two problems with that approach.

= Problem 1 - VM manager needs to parse qemu config =

Your proposal implies:

- VM manager supplies a basic configuration to qemu

- It then immediately asks qemu for a dump of the machine configuration in all its glorious detail and retains that config

Quoted 8 lines
Quoted 5 lines

- If the VM manager wishes to add a new device it needs to parse the qemu config and add it, rather than just generate an entirely new config

What's the problem with parsing the device config and modifying it? Is it just complexity?

Yes, complexity is the issue.

Quoted 7 lines
Quoted 3 lines

If we provided a mechanism to simplify manipulating a device config, would that eliminate the concern here?

In libvirt's case, a lot of the complexity would come from needing to figure out what to change.

Right, libvirt wants to be able to easily say "add a scsi block device to this VM". The way I see this working is that there would be a default pc.dtc. We would still have a -drive file=foo.img,if=scsi option that would really just be a wrapper around first searching for an existing LSI controller, if one exists, attaching the lun, if not, create one, etc.

Quoted 8 lines

libvirt could continue to use this sort of interface. However, as it wants to do more advanced things, it may have to dive into the device tree itself.

On live migration, QEMU will save a copy of the device tree somewhere and libvirt needs to keep track of it. It can treat it as opaque. -M /path/to/foo.dtc -drive file=foo.img,if=scsi should continue working as expected IMHO.

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

The basic problem would be that the command line config would have very limited ability to override the device tree config.

Cheers,
Mark.

#242 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 21 lines · Anthony Liguori
Quoted 20 lines · Mark McLoughlin
Quoted 17 lines · Anthony Liguori
Quoted 10 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

Quoted 8 lines
Quoted 5 lines

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Quoted 1 line

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

Cheers,
Mark.

#37 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 13 lines · Mark McLoughlin

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

Quoted 8 lines

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

The basic problem would be that the command line config would have very limited ability to override the device tree config.

After libvirt has done -drive file=foo... it should dump the machine config and use that from then on.

To combined to a single thread...

Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Please define "attribute". I don't follow what you're asking.

Quoted 6 lines
Quoted 2 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

No, the IDE definition would contain some sort of symbolic node name. A separate mechanism (either command line or host config file) would then link a image file to the symbolic name.

libvirt should really never worry about the machine config file for normal things unless it needs to change what devices are exposed to a guest.

Regards,

Anthony Liguori

#38 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 13 lines · Mark McLoughlin

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

Quoted 8 lines

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

The basic problem would be that the command line config would have very limited ability to override the device tree config.

After libvirt has done -drive file=foo... it should dump the machine config and use that from then on.

To combined to a single thread...

Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Please define "attribute". I don't follow what you're asking.

Quoted 6 lines
Quoted 2 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

No, the IDE definition would contain some sort of symbolic node name. A separate mechanism (either command line or host config file) would then link a image file to the symbolic name.

libvirt should really never worry about the machine config file for normal things unless it needs to change what devices are exposed to a guest.

Regards,

Anthony Liguori

#39 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 19 lines · Anthony Liguori
Quoted 18 lines · Mark McLoughlin

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

Quoted 6 lines
Quoted 3 lines

The basic problem would be that the command line config would have very limited ability to override the device tree config.

After libvirt has done -drive file=foo... it should dump the machine config and use that from then on.

Right - libvirt then wouldn't be able to avoid the complexity of merging any future changes into the dumped machine config.

Quoted 8 lines

To combined to a single thread...

Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Please define "attribute". I don't follow what you're asking.

e.g. a per-device "enable MSI support" flag.

If qemu is supplied with a device tree that lacks that flag, does it enable or disable MSI?

Enable by default is bad - it could be a device tree dumped from an old version of qemu, so compat would be broken.

Disable by default is bad - it could be a simple device tree supplied by the user, and the latest features are wanted.

Maybe we want a per-device "this is a complete device description" flag and if anything is missing from a supposedly complete description, the old defaults would be used. A config dumped from qemu would have this flag set, a config generated by libvirt would not have the flag.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

No, the IDE definition would contain some sort of symbolic node name. A separate mechanism (either command line or host config file) would then link a image file to the symbolic name.

Okay.

Quoted 2 lines

libvirt should really never worry about the machine config file for normal things unless it needs to change what devices are exposed to a guest.

But changing devices *is* normal ... e.g. removing a block device.

Writing out a device tree is not a problem for libvirt (or any other management tools), it's the need to merge changes into an existing device tree is where the real complexity would lie.

Cheers,
Mark.

#40 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 19 lines · Anthony Liguori
Quoted 18 lines · Mark McLoughlin

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

Quoted 6 lines
Quoted 3 lines

The basic problem would be that the command line config would have very limited ability to override the device tree config.

After libvirt has done -drive file=foo... it should dump the machine config and use that from then on.

Right - libvirt then wouldn't be able to avoid the complexity of merging any future changes into the dumped machine config.

Quoted 8 lines

To combined to a single thread...

Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Please define "attribute". I don't follow what you're asking.

e.g. a per-device "enable MSI support" flag.

If qemu is supplied with a device tree that lacks that flag, does it enable or disable MSI?

Enable by default is bad - it could be a device tree dumped from an old version of qemu, so compat would be broken.

Disable by default is bad - it could be a simple device tree supplied by the user, and the latest features are wanted.

Maybe we want a per-device "this is a complete device description" flag and if anything is missing from a supposedly complete description, the old defaults would be used. A config dumped from qemu would have this flag set, a config generated by libvirt would not have the flag.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

No, the IDE definition would contain some sort of symbolic node name. A separate mechanism (either command line or host config file) would then link a image file to the symbolic name.

Okay.

Quoted 2 lines

libvirt should really never worry about the machine config file for normal things unless it needs to change what devices are exposed to a guest.

But changing devices *is* normal ... e.g. removing a block device.

Writing out a device tree is not a problem for libvirt (or any other management tools), it's the need to merge changes into an existing device tree is where the real complexity would lie.

Cheers,
Mark.

#41 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 47 lines · Mark McLoughlin
Quoted 19 lines · Anthony Liguori
Quoted 18 lines · Mark McLoughlin

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

Quoted 6 lines
Quoted 3 lines

The basic problem would be that the command line config would have very limited ability to override the device tree config.

After libvirt has done -drive file=foo... it should dump the machine config and use that from then on.

Right - libvirt then wouldn't be able to avoid the complexity of merging any future changes into the dumped machine config.

Quoted 8 lines

To combined to a single thread...

Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Please define "attribute". I don't follow what you're asking.

e.g. a per-device "enable MSI support" flag.

If qemu is supplied with a device tree that lacks that flag, does it enable or disable MSI?

Enable by default is bad - it could be a device tree dumped from an old version of qemu, so compat would be broken.

Quoted 7 lines

Disable by default is bad - it could be a simple device tree supplied by the user, and the latest features are wanted.

Maybe we want a per-device "this is a complete device description" flag and if anything is missing from a supposedly complete description, the old defaults would be used. A config dumped from qemu would have this flag set, a config generated by libvirt would not have the flag.

If the device has different behavior or different properties from guest perspective compared to the old device, it should get a new device type so that you could specify in the device tree either the old device or the new one. Flags won't help in the long term.

#44 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 47 lines · Mark McLoughlin
Quoted 19 lines · Anthony Liguori
Quoted 18 lines · Mark McLoughlin

So, when libvirt creates a guest for the first time, it makes a copy of the device tree and continues to use that even if qemu is upgraded. That's enough to ensure compat is retained for all built-in devices.

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ... or:

2) Don't use the command line, instead get a dump of the entire device tree (including the SCSI device) - if the device is to be removed or modified in future, libvirt would need to modify the device tree

Quoted 6 lines
Quoted 3 lines

The basic problem would be that the command line config would have very limited ability to override the device tree config.

After libvirt has done -drive file=foo... it should dump the machine config and use that from then on.

Right - libvirt then wouldn't be able to avoid the complexity of merging any future changes into the dumped machine config.

Quoted 8 lines

To combined to a single thread...

Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Please define "attribute". I don't follow what you're asking.

e.g. a per-device "enable MSI support" flag.

If qemu is supplied with a device tree that lacks that flag, does it enable or disable MSI?

Enable by default is bad - it could be a device tree dumped from an old version of qemu, so compat would be broken.

Quoted 7 lines

Disable by default is bad - it could be a simple device tree supplied by the user, and the latest features are wanted.

Maybe we want a per-device "this is a complete device description" flag and if anything is missing from a supposedly complete description, the old defaults would be used. A config dumped from qemu would have this flag set, a config generated by libvirt would not have the flag.

If the device has different behavior or different properties from guest perspective compared to the old device, it should get a new device type so that you could specify in the device tree either the old device or the new one. Flags won't help in the long term.

#42 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Blue Swirl
Quoted 4 lines · Blue Swirl

If the device has different behavior or different properties from guest perspective compared to the old device, it should get a new device type so that you could specify in the device tree either the old device or the new one.

Yes, that works - it's analogous to a device (type, version) pair.

Cheers,
Mark.

#43 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Blue Swirl
Quoted 4 lines · Blue Swirl

If the device has different behavior or different properties from guest perspective compared to the old device, it should get a new device type so that you could specify in the device tree either the old device or the new one.

Yes, that works - it's analogous to a device (type, version) pair.

Cheers,
Mark.

#234 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

What's the problem with parsing the device config and modifying it? Is it just complexity?

Two-way modification. Management wants to store the configuration in their database and tell the hypervisor what the machine looks like. If qemu also tells management what the machine looks like, we can easily get conflicts.

Signature · 1 line
error compiling committee.c: too many arguments to function
#235 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 2 lines · Anthony Liguori

What's the problem with parsing the device config and modifying it? Is it just complexity?

Two-way modification. Management wants to store the configuration in their database and tell the hypervisor what the machine looks like. If qemu also tells management what the machine looks like, we can easily get conflicts.

Signature · 1 line
error compiling committee.c: too many arguments to function
#243 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 9 lines · Mark McLoughlin
Quoted 3 lines

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

Quoted 7 lines
Quoted 3 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

Or in a different file. I agree splitting host and guest configuration is a must-have, this ensures portability of virtual machines across hosts and time.

Signature · 1 line
error compiling committee.c: too many arguments to function
#244 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 8 lines · Mark McLoughlin
Quoted 2 lines

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

Quoted 7 lines
Quoted 3 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

Or in a different file. I agree splitting host and guest configuration is a must-have, this ensures portability of virtual machines across hosts and time.

Signature · 1 line
error compiling committee.c: too many arguments to function
author maintainer
#267 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 17 lines · Mark McLoughlin
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

Quoted 8 lines
Quoted 3 lines

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

Quoted 8 lines

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Could you clarify this requirement please?

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

OTOH, if you reboot the guest, it's ok for addresses to change.

Quoted 10 lines

Cheers,
Mark.

[1] - Adding such a per-device version number to the config file would solve problem (2)

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#268 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 17 lines · Mark McLoughlin
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Mark McLoughlin

On Wed, 2009-06-10 at 20:27 +0100, Jamie Lokier wrote:

= Solution - Separate configuration from compat hints =

As I suggested before:

Quoted 8 lines
Quoted 3 lines

- Allow the VM manager to dump compat hints; this would be an opaque file format, more like the savevm format than a config file

How is compat hints different from a device tree?

In my mind, that's what compat hints is. I don't see another sane way to implement it.

Quoted 8 lines

A device tree with a different purpose than a config file.

In its simplest form it could be a device tree with a version number for each device[1].

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Could you clarify this requirement please?

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

OTOH, if you reboot the guest, it's ok for addresses to change.

Quoted 10 lines

Cheers,
Mark.

[1] - Adding such a per-device version number to the config file would solve problem (2)

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#269 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 5 lines · Michael S. Tsirkin

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

Why not?

Quoted 2 lines

OTOH, if you reboot the guest, it's ok for addresses to change.

No, it's not. Some guests depend on addressing for their configuration (for example older Linux guests will swap eth0/eth1 if you swap their slots).

Signature · 1 line
error compiling committee.c: too many arguments to function
#270 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

Why not?

Quoted 2 lines

OTOH, if you reboot the guest, it's ok for addresses to change.

No, it's not. Some guests depend on addressing for their configuration (for example older Linux guests will swap eth0/eth1 if you swap their slots).

Signature · 1 line
error compiling committee.c: too many arguments to function
author maintainer
#271 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 8 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

Why not?

E.g. configuration cycles address a specific bus/slot. You need cooperation from guest if you want to move a device.

Quoted 6 lines
Quoted 2 lines

OTOH, if you reboot the guest, it's ok for addresses to change.

No, it's not. Some guests depend on addressing for their configuration (for example older Linux guests will swap eth0/eth1 if you swap their slots).

Ah, I misunderstood what's meant by the address. I agree that it's useful to be able to control device's placement on the bus.

Signature · 1 line
MST
author maintainer
#47 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 8 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Signature · 1 line
MST
author maintainer
#272 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

Why not?

E.g. configuration cycles address a specific bus/slot. You need cooperation from guest if you want to move a device.

Quoted 6 lines
Quoted 2 lines

OTOH, if you reboot the guest, it's ok for addresses to change.

No, it's not. Some guests depend on addressing for their configuration (for example older Linux guests will swap eth0/eth1 if you swap their slots).

Ah, I misunderstood what's meant by the address. I agree that it's useful to be able to control device's placement on the bus.

Signature · 1 line
MST
author maintainer
#48 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 8 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Signature · 1 line
MST
#245 lore raw

Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 1 line · Avi Kivity

Mark McLoughlin wrote:

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

Or in a different file. I agree splitting host and guest configuration is a must-have, this ensures portability of virtual machines across hosts and time.

Splitting into two separate sections should suffice, they could live in the same file for convenience.

#246 lore raw

Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 1 line · Avi Kivity

Mark McLoughlin wrote:

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

NB the device tree contains no host configuration information.

So, it wouldn't e.g. include the path to the image file for a block device? That would always be specified on the command line?

Or in a different file. I agree splitting host and guest configuration is a must-have, this ensures portability of virtual machines across hosts and time.

Splitting into two separate sections should suffice, they could live in the same file for convenience.

#275 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Mark McLoughlin

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Could you clarify this requirement please?

Avi clarified, but I've written it up here too:

https://fedoraproject.org/wiki/Features/KVM_Stable_PCI_Addresses

Cheers,
Mark.

#276 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Mark McLoughlin

The other obvious piece to add to it would be PCI addresses, so that even if you remove a device, the addresses assigned to existing devices don't change.

Could you clarify this requirement please?

Avi clarified, but I've written it up here too:

https://fedoraproject.org/wiki/Features/KVM_Stable_PCI_Addresses

Cheers,
Mark.

#49 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

Quoted 8 lines
Quoted 4 lines

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

Again, details written up here:

https://fedoraproject.org/wiki/Features/KVM_Stable_PCI_Addresses

Cheers,
Mark.

#247 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Mark McLoughlin
Quoted 3 lines

I think the point is that you don't need version numbers if you have a proper device tree.

Quoted 7 lines
Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

Cheers,
Mark.

#50 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

Quoted 8 lines
Quoted 4 lines

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

Again, details written up here:

https://fedoraproject.org/wiki/Features/KVM_Stable_PCI_Addresses

Cheers,
Mark.

#51 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 9 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Quoted 3 lines

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

pci_addr was never meant to bring world peace, just stable PCI addresses. The other issues should be addressed separately.

Quoted 5 lines

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

If all devices (including vga, ide) are set up with pci_addr, then this is unneeded. You do need to export available slot numbers from qemu.

Signature · 1 line
error compiling committee.c: too many arguments to function
#52 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 9 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Quoted 3 lines

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

pci_addr was never meant to bring world peace, just stable PCI addresses. The other issues should be addressed separately.

Quoted 5 lines

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

If all devices (including vga, ide) are set up with pci_addr, then this is unneeded. You do need to export available slot numbers from qemu.

Signature · 1 line
error compiling committee.c: too many arguments to function
#273 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 5 lines

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

Quoted 7 lines
Quoted 2 lines

Why not?

E.g. configuration cycles address a specific bus/slot. You need cooperation from guest if you want to move a device.

By "remove several lines from the config" I understood the guest needs to be restarted. Of course if you don't restart the guest you need true hotplug.

Signature · 1 line
error compiling committee.c: too many arguments to function
#274 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 5 lines

If we want to remove a device from under a running guest, you need hotplug. So we can't just remove several lines from the config and hope that it'll work simply because the PCI address is stable.

Quoted 7 lines
Quoted 2 lines

Why not?

E.g. configuration cycles address a specific bus/slot. You need cooperation from guest if you want to move a device.

By "remove several lines from the config" I understood the guest needs to be restarted. Of course if you don't restart the guest you need true hotplug.

Signature · 1 line
error compiling committee.c: too many arguments to function
#208 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 12 lines · Michael S. Tsirkin
Quoted 9 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file), then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Signature · 1 line
error compiling committee.c: too many arguments to function
#209 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 12 lines · Michael S. Tsirkin
Quoted 9 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file), then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Signature · 1 line
error compiling committee.c: too many arguments to function
#248 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Mark McLoughlin
Quoted 3 lines

I think the point is that you don't need version numbers if you have a proper device tree.

Quoted 7 lines
Quoted 5 lines

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

Cheers,
Mark.

author maintainer
#210 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 22 lines · Avi Kivity
Quoted 12 lines · Michael S. Tsirkin
Quoted 9 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file), then turns on the power. Command line options are the parts lying around when we start.

Quoted 7 lines

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Maybe we need a generic 'bus options' flag.

author maintainer
#211 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 22 lines · Avi Kivity
Quoted 12 lines · Michael S. Tsirkin
Quoted 9 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to figure out what address to use, libvirt would need to query qemu for what address was originally allocated to device or it would do all the PCI address allocation itself ...

Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file), then turns on the power. Command line options are the parts lying around when we start.

Quoted 7 lines

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Maybe we need a generic 'bus options' flag.

author maintainer
#53 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 22 lines · Avi Kivity
Quoted 9 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Quoted 3 lines

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

pci_addr was never meant to bring world peace, just stable PCI addresses. The other issues should be addressed separately.

Quoted 8 lines
Quoted 5 lines

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

If all devices (including vga, ide) are set up with pci_addr, then this is unneeded.

Right. I think it could be an all or nothing at all approach.

Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

author maintainer
#54 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 22 lines · Avi Kivity
Quoted 9 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Quoted 3 lines

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

pci_addr was never meant to bring world peace, just stable PCI addresses. The other issues should be addressed separately.

Quoted 8 lines
Quoted 5 lines

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

If all devices (including vga, ide) are set up with pci_addr, then this is unneeded.

Right. I think it could be an all or nothing at all approach.

Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

#55 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

--
Gleb.

author maintainer
#57 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Gleb Natapov
Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

#56 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

--
Gleb.

author maintainer
#58 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

#59 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

--
Gleb.

#60 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

--
Gleb.

author maintainer
#61 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 5 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

Do you mean the KVM kernel module here? I don't know much about the BIOS. Can't qemu control the number of slots declared?

Signature · 1 line
MST
author maintainer
#62 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Gleb Natapov
Quoted 5 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

Do you mean the KVM kernel module here? I don't know much about the BIOS. Can't qemu control the number of slots declared?

Signature · 1 line
MST
#63 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Gleb Natapov
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

Do you mean the KVM kernel module here? I don't know much about the

No I don't mean KVM kernel module here.

Quoted 2 lines

BIOS. Can't qemu control the number of slots declared?

Qemu represents HW, BIOS drives this HW. They should be in sync on such important issues like pci slot configuration. Even if QEMU can control the number of slots declared (which it can't easily do), it will be able to do it only on startup (before BIOS runs). The way to have dynamic number of slots may be pci bridge emulation. Not sure what is needed from BIOS for that.

--
Gleb.

#64 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Gleb Natapov
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

Do you mean the KVM kernel module here? I don't know much about the

No I don't mean KVM kernel module here.

Quoted 2 lines

BIOS. Can't qemu control the number of slots declared?

Qemu represents HW, BIOS drives this HW. They should be in sync on such important issues like pci slot configuration. Even if QEMU can control the number of slots declared (which it can't easily do), it will be able to do it only on startup (before BIOS runs). The way to have dynamic number of slots may be pci bridge emulation. Not sure what is needed from BIOS for that.

--
Gleb.

#67 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

A slot needs to be configured in ACPI, and not be taken by onboard chips (piix takes slot 0, for example).

Signature · 1 line
error compiling committee.c: too many arguments to function
#68 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

A slot needs to be configured in ACPI, and not be taken by onboard chips (piix takes slot 0, for example).

Signature · 1 line
error compiling committee.c: too many arguments to function
#249 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 10 lines · Mark McLoughlin
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Quoted 7 lines
Quoted 2 lines

-baseline 0.10

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default. Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

Signature · 1 line
error compiling committee.c: too many arguments to function
#250 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 10 lines · Mark McLoughlin
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Quoted 7 lines
Quoted 2 lines

-baseline 0.10

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default. Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

Signature · 1 line
error compiling committee.c: too many arguments to function
author maintainer
#65 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Gleb Natapov
Quoted 15 lines · Gleb Natapov
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

Quoted 7 lines
Quoted 1 line

Do you mean the KVM kernel module here? I don't know much about the

No I don't mean KVM kernel module here.

Quoted 2 lines

BIOS. Can't qemu control the number of slots declared?

Qemu represents HW, BIOS drives this HW. They should be in sync on such important issues like pci slot configuration.

As a simple solution, let's stick to 32 slots per bus. That's the maximum that the PCI spec allows, anyway.

Quoted 3 lines

Even if QEMU can control the number of slots declared (which it can't easily do), it will be able to do it only on startup (before BIOS runs).

That's OK - this is when the machine description is read.

Quoted 3 lines

The way to have dynamic
number of slots may be pci bridge emulation. Not sure what is needed from BIOS for that.

Since bridge can be hot-plugged, probably nothing? But we don't necessarily need dynamic number of slots IMO.

Quoted 3 lines

--
Gleb.

Signature · 1 line
MST
#190 lore raw

Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Quoted 8 lines
Quoted 4 lines

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Correct.

Quoted 13 lines
Quoted 3 lines

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

pci_addr was never meant to bring world peace, just stable PCI addresses. The other issues should be addressed separately.

Quoted 5 lines

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

Quoted 3 lines

If all devices (including vga, ide) are set up with pci_addr, then this is unneeded. You do need to export available slot numbers from qemu.

Not really. QEMU gives just the host bridge a fixed slot[*]. All the other slots are available.

The real problem is devices that get implicitly added, like the SCSI controller. Those devices get their slots auto-assigned, which can interfere with slot numbers chosen by the user. We need a way to avoid that, as you suggested elsewhere in this thread.

[*] There's an exception or two for oddball targets.

author maintainer
#66 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Gleb Natapov
Quoted 15 lines · Gleb Natapov
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

Because it does not exist?

We can create a slot with any number, can't we?

What do you mean? If the mobo has 4 slots you can't create fifth. KVM describes 32 slots in the BIOS.

Quoted 7 lines
Quoted 1 line

Do you mean the KVM kernel module here? I don't know much about the

No I don't mean KVM kernel module here.

Quoted 2 lines

BIOS. Can't qemu control the number of slots declared?

Qemu represents HW, BIOS drives this HW. They should be in sync on such important issues like pci slot configuration.

As a simple solution, let's stick to 32 slots per bus. That's the maximum that the PCI spec allows, anyway.

Quoted 3 lines

Even if QEMU can control the number of slots declared (which it can't easily do), it will be able to do it only on startup (before BIOS runs).

That's OK - this is when the machine description is read.

Quoted 3 lines

The way to have dynamic
number of slots may be pci bridge emulation. Not sure what is needed from BIOS for that.

Since bridge can be hot-plugged, probably nothing? But we don't necessarily need dynamic number of slots IMO.

Quoted 3 lines

--
Gleb.

Signature · 1 line
MST
#191 lore raw

Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Quoted 8 lines
Quoted 4 lines

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Correct.

Quoted 13 lines
Quoted 3 lines

However, the first problem is that it isn't a solution to the guest ABI problem more generally.

pci_addr was never meant to bring world peace, just stable PCI addresses. The other issues should be addressed separately.

Quoted 5 lines

And the second problem is that for e.g. libvirt to use it, it would have to be possible to query qemu for what PCI slots were assigned to the devices - libvirt would need to be able to parse 'info pci' and match the devices listed with the devices specified on the command line.

Quoted 3 lines

If all devices (including vga, ide) are set up with pci_addr, then this is unneeded. You do need to export available slot numbers from qemu.

Not really. QEMU gives just the host bridge a fixed slot[*]. All the other slots are available.

The real problem is devices that get implicitly added, like the SCSI controller. Those devices get their slots auto-assigned, which can interfere with slot numbers chosen by the user. We need a way to avoid that, as you suggested elsewhere in this thread.

[*] There's an exception or two for oddball targets.

#192 lore raw

Re: Configuration vs. compat hints

(adding cc)

Quoted 3 lines · Markus Armbruster

Not really. QEMU gives just the host bridge a fixed slot[*]. All the other slots are available.

qemu needs to export these two bits of information: the first free slot and the number of slots.

More generally, which slots are open. We can assume 1:31, but that's unlovely.

Quoted 5 lines

The real problem is devices that get implicitly added, like the SCSI controller. Those devices get their slots auto-assigned, which can interfere with slot numbers chosen by the user. We need a way to avoid that, as you suggested elsewhere in this thread.

Paul/Anthony, can we have -vga pci_addr=, -usb-controller pci_addr=, and -drive pci_addr= (and later, -disk-controller)? Stalling while waiting for the ultimate config file is only generating pain and out-of-tree patches.

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

Signature · 1 line
error compiling committee.c: too many arguments to function
#193 lore raw

Re: Configuration vs. compat hints

In reply to Markus Armbruster

(adding cc)

Quoted 3 lines · Markus Armbruster

Not really. QEMU gives just the host bridge a fixed slot[*]. All the other slots are available.

qemu needs to export these two bits of information: the first free slot and the number of slots.

More generally, which slots are open. We can assume 1:31, but that's unlovely.

Quoted 5 lines

The real problem is devices that get implicitly added, like the SCSI controller. Those devices get their slots auto-assigned, which can interfere with slot numbers chosen by the user. We need a way to avoid that, as you suggested elsewhere in this thread.

Paul/Anthony, can we have -vga pci_addr=, -usb-controller pci_addr=, and -drive pci_addr= (and later, -disk-controller)? Stalling while waiting for the ultimate config file is only generating pain and out-of-tree patches.

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

Signature · 1 line
error compiling committee.c: too many arguments to function
author maintainer
#69 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

A slot needs to be configured in ACPI,

Can we configure all possible 32 slots?

Quoted 2 lines

and not be taken by onboard chips
(piix takes slot 0, for example).

piix is the root complex, isn't it? Are there other examples? If not, we could teach management about the root complex being special ...

Quoted 2 lines
Signature · 1 line
error compiling committee.c: too many arguments to function
author maintainer
#70 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

You do need to export available slot numbers from qemu.

Why would a slot be unavailable?

A slot needs to be configured in ACPI,

Can we configure all possible 32 slots?

Quoted 2 lines

and not be taken by onboard chips
(piix takes slot 0, for example).

piix is the root complex, isn't it? Are there other examples? If not, we could teach management about the root complex being special ...

Quoted 2 lines
Signature · 1 line
error compiling committee.c: too many arguments to function
#194 lore raw

Re: Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 3 lines · Avi Kivity

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

It is not just you.

#71 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

A slot needs to be configured in ACPI,

Can we configure all possible 32 slots?

That's what we do. But one is always taken. In the future, perhaps more.

Quoted 7 lines
Quoted 3 lines

and not be taken by onboard chips
(piix takes slot 0, for example).

piix is the root complex, isn't it? Are there other examples? If not, we could teach management about the root complex being special ...

We should just tell the user which slots are open.

Signature · 1 line
error compiling committee.c: too many arguments to function
#72 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

A slot needs to be configured in ACPI,

Can we configure all possible 32 slots?

That's what we do. But one is always taken. In the future, perhaps more.

Quoted 7 lines
Quoted 3 lines

and not be taken by onboard chips
(piix takes slot 0, for example).

piix is the root complex, isn't it? Are there other examples? If not, we could teach management about the root complex being special ...

We should just tell the user which slots are open.

Signature · 1 line
error compiling committee.c: too many arguments to function
#195 lore raw

Re: [Qemu-devel] Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 3 lines · Avi Kivity

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

It is not just you.

#202 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Quoted 8 lines
Quoted 4 lines

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Is there opposition? I don't ever recall seeing a patch...

I think it's a perfectly fine idea.

Regards,

Anthony Liguori

#203 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Quoted 6 lines
Quoted 4 lines

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Is there opposition? I don't ever recall seeing a patch...

I think it's a perfectly fine idea.

Regards,

Anthony Liguori

#196 lore raw

Re: [Qemu-devel] Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity

(adding cc)

Quoted 3 lines · Markus Armbruster

Not really. QEMU gives just the host bridge a fixed slot[*]. All the other slots are available.

Quoted 5 lines

qemu needs to export these two bits of information: the first free slot and the number of slots.

More generally, which slots are open. We can assume 1:31, but that's unlovely.

Point.

Quoted 10 lines
Quoted 5 lines

The real problem is devices that get implicitly added, like the SCSI controller. Those devices get their slots auto-assigned, which can interfere with slot numbers chosen by the user. We need a way to avoid that, as you suggested elsewhere in this thread.

Paul/Anthony, can we have -vga pci_addr=, -usb-controller pci_addr=, and -drive pci_addr= (and later, -disk-controller)? Stalling while waiting for the ultimate config file is only generating pain and out-of-tree patches.

Yup.

I got bit-rotten patches for pci_addr=, and I can unrot them if they're wanted.

Quoted 2 lines

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

Ha, .bash_history as config file...

author maintainer
#73 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 13 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

A slot needs to be configured in ACPI,

Can we configure all possible 32 slots?

That's what we do. But one is always taken. In the future, perhaps more.

Quoted 4 lines
Quoted 3 lines

and not be taken by onboard chips
(piix takes slot 0, for example).

Quoted 5 lines
Quoted 3 lines

piix is the root complex, isn't it? Are there other examples? If not, we could teach management about the root complex being special ...

We should just tell the user which slots are open.

This might be tricky if the config is passed in with the command line flags.

#197 lore raw

Re: [Qemu-devel] Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity

(adding cc)

Quoted 3 lines · Markus Armbruster

Not really. QEMU gives just the host bridge a fixed slot[*]. All the other slots are available.

Quoted 5 lines

qemu needs to export these two bits of information: the first free slot and the number of slots.

More generally, which slots are open. We can assume 1:31, but that's unlovely.

Point.

Quoted 10 lines
Quoted 5 lines

The real problem is devices that get implicitly added, like the SCSI controller. Those devices get their slots auto-assigned, which can interfere with slot numbers chosen by the user. We need a way to avoid that, as you suggested elsewhere in this thread.

Paul/Anthony, can we have -vga pci_addr=, -usb-controller pci_addr=, and -drive pci_addr= (and later, -disk-controller)? Stalling while waiting for the ultimate config file is only generating pain and out-of-tree patches.

Yup.

I got bit-rotten patches for pci_addr=, and I can unrot them if they're wanted.

Quoted 2 lines

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

Ha, .bash_history as config file...

author maintainer
#74 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 13 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

A slot needs to be configured in ACPI,

Can we configure all possible 32 slots?

That's what we do. But one is always taken. In the future, perhaps more.

Quoted 4 lines
Quoted 3 lines

and not be taken by onboard chips
(piix takes slot 0, for example).

Quoted 5 lines
Quoted 3 lines

piix is the root complex, isn't it? Are there other examples? If not, we could teach management about the root complex being special ...

We should just tell the user which slots are open.

This might be tricky if the config is passed in with the command line flags.

#212 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Michael S. Tsirkin
Quoted 11 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to
figure
out what address to use, libvirt would need to query qemu for
what
address was originally allocated to device or it would do all the PCI address allocation itself ...

Quoted 7 lines
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

Quoted 10 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Drivers don't have indexes and buses but we specify it on the -drive line. -drive is convenient syntax. It stops being convenient when you force it to be two options.

Regards,

Anthony Liguori

#213 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Michael S. Tsirkin
Quoted 11 lines · Mark McLoughlin

However, in order to retain compat for that SCSI device (e.g. ensuring the PCI address doesn't change as other devices are added an removed), we're back to the same problem ... either:

1) Use '-drive file=foo.img,if=scsi,pci_addr=foo'; in order to
figure
out what address to use, libvirt would need to query qemu for
what
address was originally allocated to device or it would do all the PCI address allocation itself ...

Quoted 6 lines
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

Quoted 9 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Drivers don't have indexes and buses but we specify it on the -drive line. -drive is convenient syntax. It stops being convenient when you force it to be two options.

Regards,

Anthony Liguori

#251 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 20 lines · Avi Kivity
Quoted 11 lines · Mark McLoughlin
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

I think the point is that you don't need version numbers if you have a
proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

Quoted 7 lines
Quoted 2 lines

-baseline 0.10

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

Quoted 6 lines

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default. Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

-M pc1
-M pc2

etc.

This is pretty easy to maintain with config files.

Regards,

Anthony Liguori

#252 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Mark McLoughlin
Quoted 12 lines
Quoted 10 lines
Quoted 4 lines

I think the point is that you don't need version numbers if you have a proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

Quoted 6 lines
Quoted 4 lines

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default. Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

-M pc1
-M pc2

etc.

This is pretty easy to maintain with config files.

Regards,

Anthony Liguori

#75 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin

We should just tell the user which slots are open.

This might be tricky if the config is passed in with the command line flags.

qemu -show-available-pci-slots

(the qemu equivalent to KVM_CHECK_EXTENSION)

Signature · 1 line
error compiling committee.c: too many arguments to function
#198 lore raw

Re: [Qemu-devel] Re: Configuration vs. compat hints

In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster
Quoted 5 lines · Avi Kivity

Paul/Anthony, can we have -vga pci_addr=, -usb-controller pci_addr=, and -drive pci_addr= (and later, -disk-controller)? Stalling while waiting for the ultimate config file is only generating pain and out-of-tree patches.

Quoted 5 lines

Yup.

I got bit-rotten patches for pci_addr=, and I can unrot them if they're wanted.

Yes, would be good to have patches on the list to discuss. In principle, I have no objection to this.

Regards,

Anthony Liguori

#199 lore raw

Re: [Qemu-devel] Re: Configuration vs. compat hints

In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster
Quoted 5 lines · Avi Kivity

Paul/Anthony, can we have -vga pci_addr=, -usb-controller pci_addr=, and -drive pci_addr= (and later, -disk-controller)? Stalling while waiting for the ultimate config file is only generating pain and out-of-tree patches.

Quoted 5 lines

Yup.

I got bit-rotten patches for pci_addr=, and I can unrot them if they're wanted.

Yes, would be good to have patches on the list to discuss. In principle, I have no objection to this.

Regards,

Anthony Liguori

#77 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin

We should just tell the user which slots are open.

This might be tricky if the config is passed in with the command line flags.

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's not a good idea to have management applications attempt to do PCI slot allocation. For instance, one day we may decide to make virtio devices multi-function.

Regards,

Anthony Liguori

#78 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin

We should just tell the user which slots are open.

This might be tricky if the config is passed in with the command line flags.

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's not a good idea to have management applications attempt to do PCI slot allocation. For instance, one day we may decide to make virtio devices multi-function.

Regards,

Anthony Liguori

#76 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin

We should just tell the user which slots are open.

This might be tricky if the config is passed in with the command line flags.

qemu -show-available-pci-slots

(the qemu equivalent to KVM_CHECK_EXTENSION)

Signature · 1 line
error compiling committee.c: too many arguments to function
#204 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 7 lines
Quoted 3 lines

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Is there opposition? I don't ever recall seeing a patch...

Izik Eidus posted a patch (using a different syntax) in November 2007.

Quoted 2 lines

I think it's a perfectly fine idea.

Good.

Signature · 1 line
error compiling committee.c: too many arguments to function
#205 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 5 lines
Quoted 3 lines

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Is there opposition? I don't ever recall seeing a patch...

Izik Eidus posted a patch (using a different syntax) in November 2007.

Quoted 2 lines

I think it's a perfectly fine idea.

Good.

Signature · 1 line
error compiling committee.c: too many arguments to function
#214 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 6 lines
Quoted 3 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

I'd be sad too, but not surprised.

Quoted 5 lines
Quoted 5 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

Quoted 8 lines
Quoted 5 lines

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Drivers don't have indexes and buses but we specify it on the -drive line.

Drives do have indexes. On old parallel scsi drives you set the index by clicking a button on the back of the drive to cycle through scsi addresses 0-7. An IDE drive's index is determined by the cable (master/slave). A SATA drive's index is determined by which header on the motherboard the drive connects to.

If by bus you mean the if= parameter, then drives certainly do have buses. Just try connecting the scsi drive from the previous paragraph to a USB port.

Quoted 2 lines

-drive is convenient syntax. It stops being convenient when you force it to be two options.

controller= defaults to some builtin thing which autoinstantiates when necessary, so the old -drive syntax works.

Signature · 1 line
error compiling committee.c: too many arguments to function
#206 lore raw

Re: Configuration vs. compat hints

In reply to Anthony Liguori
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

Quoted 5 lines
Quoted 3 lines

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Is there opposition? I don't ever recall seeing a patch...

http://www.archivum.info/[email protected]/2009-01/msg01458.html

Quoted 1 line

I think it's a perfectly fine idea.

Off to dust off my patch series.

#215 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 5 lines
Quoted 3 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

I'd be sad too, but not surprised.

Quoted 11 lines
Quoted 9 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Drivers don't have indexes and buses but we specify it on the -drive line.

Drives do have indexes. On old parallel scsi drives you set the index by clicking a button on the back of the drive to cycle through scsi addresses 0-7. An IDE drive's index is determined by the cable (master/slave). A SATA drive's index is determined by which header on the motherboard the drive connects to.

If by bus you mean the if= parameter, then drives certainly do have buses. Just try connecting the scsi drive from the previous paragraph to a USB port.

Quoted 2 lines

-drive is convenient syntax. It stops being convenient when you force it to be two options.

controller= defaults to some builtin thing which autoinstantiates when necessary, so the old -drive syntax works.

Signature · 1 line
error compiling committee.c: too many arguments to function
#207 lore raw

Re: Configuration vs. compat hints

In reply to Anthony Liguori
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Mark McLoughlin
Quoted 4 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yep, most people seem to agree that it makes sense to allow this, but some believe it should only be via a machine description file, not the command line.

Quoted 5 lines
Quoted 3 lines

I don't understand this opposition. It's clear a machine config file is a long way in our future. It's also clear lack of stable PCI addresses hurts us now.

Is there opposition? I don't ever recall seeing a patch...

http://www.archivum.info/[email protected]/2009-01/msg01458.html

Quoted 1 line

I think it's a perfectly fine idea.

Off to dust off my patch series.

#79 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Michael S. Tsirkin

We should just tell the user which slots are open.
This might be tricky if the config is passed in with the command line
flags.

Quoted 6 lines
Quoted 1 line

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's a roundabout way of doing things.

As an example, if you try to fit too many devices into the machine, you have to try to add all devices and watch for a qemu error. If you know in advance how many slots you have, you never enter into that situation (and you need to show the limit to the user anyway).

Quoted 4 lines

It's not a good idea to have management applications attempt to do PCI slot allocation. For instance, one day we may decide to make virtio devices multi-function.

Non-virtio, as well. But we can't make that the default, so the user will have to specify this anyway.

Given that you can't hotunplug individual functions, the user will have to specify exactly how functions are aggregated into devices. My recommendation would be for a GUI to allow the user to select a 'quad port virtio NIC' or 'dual port virtio scsi controller' rather than trying to do anything automatic.

Signature · 1 line
error compiling committee.c: too many arguments to function
#80 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 11 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Michael S. Tsirkin

We should just tell the user which slots are open.
This might be tricky if the config is passed in with the command line
flags.

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's a roundabout way of doing things.

As an example, if you try to fit too many devices into the machine, you have to try to add all devices and watch for a qemu error. If you know in advance how many slots you have, you never enter into that situation (and you need to show the limit to the user anyway).

Quoted 2 lines

It's not a good idea to have management applications attempt to do PCI slot allocation. For instance, one day we may decide to make virtio devices multi-function.

Non-virtio, as well. But we can't make that the default, so the user will have to specify this anyway.

Given that you can't hotunplug individual functions, the user will have to specify exactly how functions are aggregated into devices. My recommendation would be for a GUI to allow the user to select a 'quad port virtio NIC' or 'dual port virtio scsi controller' rather than trying to do anything automatic.

Signature · 1 line
error compiling committee.c: too many arguments to function
#253 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 18 lines · Anthony Liguori
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

That's a version number :-)

Quoted 8 lines
Quoted 1 line

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default. Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

How do you add a new attribute to the device tree and, when a supplied

Review

Quoted 2 lines
(quoted diff) +0 -2
-M pc1
-M pc2

Certainly preferable to -baseline.

Quoted 1 line

This is pretty easy to maintain with config files.

Let's not tie the two together.

Signature · 1 line
error compiling committee.c: too many arguments to function
#254 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 13 lines · Anthony Liguori
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default. Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

How do you add a new attribute to the device tree and, when a supplied

Review

Quoted 2 lines
(quoted diff) +0 -2
-M pc1
-M pc2

Certainly preferable to -baseline.

Quoted 1 line

This is pretty easy to maintain with config files.

Let's not tie the two together.

Signature · 1 line
error compiling committee.c: too many arguments to function
#232 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori

Hi,

Quoted 5 lines
Quoted 2 lines

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

It shouldn't last until 2017, but the process isn't that trivial. Some qemu code / control flow needs serious restruction until it is in a state that creating the devices from a fdt can actually work.

Quoted 3 lines

Drivers don't have indexes and buses but we specify it on the -drive line. -drive is convenient syntax. It stops being convenient when you force it to be two options.

One more issue: -drive also mixes host and guest configuration. These must be separated too.

cheers,
Gerd

#233 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori

Hi,

Quoted 5 lines
Quoted 2 lines

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

It shouldn't last until 2017, but the process isn't that trivial. Some qemu code / control flow needs serious restruction until it is in a state that creating the devices from a fdt can actually work.

Quoted 3 lines

Drivers don't have indexes and buses but we specify it on the -drive line. -drive is convenient syntax. It stops being convenient when you force it to be two options.

One more issue: -drive also mixes host and guest configuration. These must be separated too.

cheers,
Gerd

#216 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 25 lines · Avi Kivity
Quoted 10 lines · Anthony Liguori
Quoted 6 lines
Quoted 3 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

I'd be sad too, but not surprised.

Quoted 11 lines
Quoted 10 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Quoted 8 lines
Quoted 2 lines

Drivers don't have indexes and buses but we specify it on the -drive line.

Drives do have indexes. On old parallel scsi drives you set the index by clicking a button on the back of the drive to cycle through scsi addresses 0-7. An IDE drive's index is determined by the cable (master/slave). A SATA drive's index is determined by which header on the motherboard the drive connects to.

It's not at all that simple. SCSI has a hierarchical address mechanism
with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

For IDE, it's a combination of bus, slot, and master/slave. For virtio, it's just a PCI address. What we really need is something that is more opaque and controller specific. For instance, if we were going to do controllers...

-controller type=lsi1234,pci_addr=foobar,name=blah -controller-disk controller=blah,target=0,lun=1,name=sda

-controller type=ide,pci_addr=barfoo,name=ide -controller-disk controller=ide,slot=secondary,cable=slave,name=hdd

-drive file=foo.img,controller-disk=sda
-drive file=bar.img,controller-disk=hdd

And having "-hdd file=foo.img" be short-hand for "-drive file=%s,controller-disk=%s".

Quoted 5 lines

If by bus you mean the if= parameter, then drives certainly do have buses. Just try connecting the scsi drive from the previous paragraph to a USB port.

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Regards,

Anthony Liguori

#217 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 20 lines · Avi Kivity
Quoted 8 lines · Anthony Liguori
Quoted 5 lines
Quoted 3 lines

This last option makes sense to me: in a real world the user has control over where he places the device on the bus, so why not with qemu?

Yes, the user build the machine using the command line and monitor (or, in 2017, the machine configuration file),

Considering pbrook just posted a machine config for arm, I think it would be rather sad if pc wasn't converted to it by 2017...

I'd be sad too, but not surprised.

Quoted 8 lines
Quoted 8 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Drives to not have pci addresses.

Drivers don't have indexes and buses but we specify it on the -drive line.

Drives do have indexes. On old parallel scsi drives you set the index by clicking a button on the back of the drive to cycle through scsi addresses 0-7. An IDE drive's index is determined by the cable (master/slave). A SATA drive's index is determined by which header on the motherboard the drive connects to.

It's not at all that simple. SCSI has a hierarchical address mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

For IDE, it's a combination of bus, slot, and master/slave. For virtio, it's just a PCI address. What we really need is something that is more opaque and controller specific. For instance, if we were going to do controllers...

-controller type=lsi1234,pci_addr=foobar,name=blah -controller-disk controller=blah,target=0,lun=1,name=sda

-controller type=ide,pci_addr=barfoo,name=ide -controller-disk controller=ide,slot=secondary,cable=slave,name=hdd

-drive file=foo.img,controller-disk=sda
-drive file=bar.img,controller-disk=hdd

And having "-hdd file=foo.img" be short-hand for "-drive file=%s,controller-disk=%s".

Quoted 3 lines

If by bus you mean the if= parameter, then drives certainly do have buses. Just try connecting the scsi drive from the previous paragraph to a USB port.

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Regards,

Anthony Liguori

#81 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Michael S. Tsirkin

We should just tell the user which slots are open.
This might be tricky if the config is passed in with the command
line
flags.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's a roundabout way of doing things.

Having libvirt do PCI slot allocation scares me. It assumes we can return a whitelist of available slots, and then let libvirt just randomly assign things. There's knowledge though in slot assignment that's board-specific. For instance, depending on how many LNK lines you have, you may want to put things in slots in such a way to optimize interrupt balancing or something like that.

Some platforms have quirks about expecting a particular slot to have a particular device. It's still an optimal device but it has to be in that slot. You can't really express that via an available slot list.

Quoted 8 lines

Non-virtio, as well. But we can't make that the default, so the user will have to specify this anyway.

Given that you can't hotunplug individual functions, the user will have to specify exactly how functions are aggregated into devices. My recommendation would be for a GUI to allow the user to select a 'quad port virtio NIC' or 'dual port virtio scsi controller' rather than trying to do anything automatic.

Yeah, I haven't thought much about that.

Regards,

Anthony Liguori

#82 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Michael S. Tsirkin

We should just tell the user which slots are open.
This might be tricky if the config is passed in with the command
line
flags.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's a roundabout way of doing things.

Having libvirt do PCI slot allocation scares me. It assumes we can return a whitelist of available slots, and then let libvirt just randomly assign things. There's knowledge though in slot assignment that's board-specific. For instance, depending on how many LNK lines you have, you may want to put things in slots in such a way to optimize interrupt balancing or something like that.

Some platforms have quirks about expecting a particular slot to have a particular device. It's still an optimal device but it has to be in that slot. You can't really express that via an available slot list.

Quoted 3 lines

Non-virtio, as well. But we can't make that the default, so the user will have to specify this anyway.

Given that you can't hotunplug individual functions, the user will have to specify exactly how functions are aggregated into devices. My recommendation would be for a GUI to allow the user to select a 'quad port virtio NIC' or 'dual port virtio scsi controller' rather than trying to do anything automatic.

Yeah, I haven't thought much about that.

Regards,

Anthony Liguori

#255 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity

Certainly preferable to -baseline.

Quoted 1 line

This is pretty easy to maintain with config files.

Let's not tie the two together.

I mentioned it because it suggests a good transition. We at least have to think through how things map to the post-config file world regardless of whether that's a few months from now or a decade :-)

Regards,

Anthony Liguori

#256 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity

Certainly preferable to -baseline.

Quoted 1 line

This is pretty easy to maintain with config files.

Let's not tie the two together.

I mentioned it because it suggests a good transition. We at least have to think through how things map to the post-config file world regardless of whether that's a few months from now or a decade :-)

Regards,

Anthony Liguori

#218 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 22 lines · Anthony Liguori
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Drives to not have pci addresses.

Quoted 8 lines
Quoted 2 lines

Drivers don't have indexes and buses but we specify it on the -drive line.

Drives do have indexes. On old parallel scsi drives you set the index by clicking a button on the back of the drive to cycle through scsi addresses 0-7. An IDE drive's index is determined by the cable (master/slave). A SATA drive's index is determined by which header on the motherboard the drive connects to.

Quoted 6 lines

It's not at all that simple. SCSI has a hierarchical address
mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

Well, another level in the hierarchy, but I don't think it materially changes things.

Quoted 4 lines

For IDE, it's a combination of bus, slot, and master/slave. For virtio, it's just a PCI address. What we really need is something that is more opaque and controller specific.

virtio also has a bus (did you mean the pci bus for IDE?), master/slave is the index. virtio doesn't have index, but IMO that was a mistake and we should have designed it as a disk controller in the first place.

Quoted 11 lines

For instance, if we were going to do controllers...

(quoted diff) +0 -6
-controller type=lsi1234,pci_addr=foobar,name=blah
-controller-disk controller=blah,target=0,lun=1,name=sda
 
-controller type=ide,pci_addr=barfoo,name=ide
-controller-disk controller=ide,slot=secondary,cable=slave,name=hdd
 
-drive file=foo.img,controller-disk=sda
-drive file=bar.img,controller-disk=hdd
Quoted 2 lines

And having "-hdd file=foo.img" be short-hand for "-drive file=%s,controller-disk=%s".

Yeah.

Quoted 6 lines
Quoted 5 lines

If by bus you mean the if= parameter, then drives certainly do have buses. Just try connecting the scsi drive from the previous paragraph to a USB port.

Quoted 7 lines

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Isn't the drive table something totally internal? And how does bus= relate to it?

Confused.

Signature · 1 line
error compiling committee.c: too many arguments to function
#219 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 9 lines · Anthony Liguori
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

then turns on the power. Command line options are the parts lying around when we start.

btw, -drive needs to be separated:

-controller type=lsi1234,pci_addr=foobar,name=blah -drive file=foo.img,controller=blah,index=0 -drive file=bar.img,controller=blah,index=1

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Drives to not have pci addresses.

Drivers don't have indexes and buses but we specify it on the -drive line.

Drives do have indexes. On old parallel scsi drives you set the index by clicking a button on the back of the drive to cycle through scsi addresses 0-7. An IDE drive's index is determined by the cable (master/slave). A SATA drive's index is determined by which header on the motherboard the drive connects to.

It's not at all that simple. SCSI has a hierarchical address mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

Well, another level in the hierarchy, but I don't think it materially changes things.

Quoted 2 lines

For IDE, it's a combination of bus, slot, and master/slave. For virtio, it's just a PCI address. What we really need is something that is more opaque and controller specific.

virtio also has a bus (did you mean the pci bus for IDE?), master/slave is the index. virtio doesn't have index, but IMO that was a mistake and we should have designed it as a disk controller in the first place.

Quoted 11 lines

For instance, if we were going to do controllers...

(quoted diff) +0 -6
-controller type=lsi1234,pci_addr=foobar,name=blah
-controller-disk controller=blah,target=0,lun=1,name=sda
 
-controller type=ide,pci_addr=barfoo,name=ide
-controller-disk controller=ide,slot=secondary,cable=slave,name=hdd
 
-drive file=foo.img,controller-disk=sda
-drive file=bar.img,controller-disk=hdd
Quoted 1 line

And having "-hdd file=foo.img" be short-hand for "-drive file=%s,controller-disk=%s".

Yeah.

Quoted 5 lines
Quoted 3 lines

If by bus you mean the if= parameter, then drives certainly do have buses. Just try connecting the scsi drive from the previous paragraph to a USB port.

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Isn't the drive table something totally internal? And how does bus= relate to it?

Confused.

Signature · 1 line
error compiling committee.c: too many arguments to function
#83 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Avi Kivity
Quoted 13 lines · Anthony Liguori
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Michael S. Tsirkin

We should just tell the user which slots are open.
This might be tricky if the config is passed in with the command
line
flags.

qemu -show-available-pci-slots

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

Quoted 8 lines
Quoted 1 line

It's a roundabout way of doing things.

Having libvirt do PCI slot allocation scares me. It assumes we can return a whitelist of available slots, and then let libvirt just randomly assign things. There's knowledge though in slot assignment that's board-specific. For instance, depending on how many LNK lines you have, you may want to put things in slots in such a way to optimize interrupt balancing or something like that.

How would qemu know which slots to optimize for?

In practice, I don't see that as a real problem. We should (a) add an ioapic and four more pci links (b) recommend that slots be assigned in ascending order, and everything works.

I don't see your concern about libvirt allocating slots. If a human can plug a card into a slot, so can libvirt. Doing an interactive back-and-forth (equivalent to plugging a card while blindfolded, then looking to see which slot we hit) is certainly more difficult.

Quoted 3 lines

Some platforms have quirks about expecting a particular slot to have a particular device. It's still an optimal device but it has to be in that slot. You can't really express that via an available slot list.

I'll be surprised if we ever measure different dma speeds on different slots in the qemu virtual pci bus. If we do, we'll find a way to express them:

   $ qemu -print-pci
   slot 0:01: available 33MHz
   slot 0:02: available 33MHz
   slot 0:03: available 66MHz

I feel a little silly typing this.

Signature · 1 line
error compiling committee.c: too many arguments to function
#257 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 11 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity

Certainly preferable to -baseline.

Quoted 1 line

This is pretty easy to maintain with config files.

Let's not tie the two together.

I mentioned it because it suggests a good transition. We at least have to think through how things map to the post-config file world regardless of whether that's a few months from now or a decade :-)

Sure, it's good both from the transitional point of view and in its own right.

Signature · 1 line
error compiling committee.c: too many arguments to function
#220 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 10 lines · Avi Kivity
Quoted 6 lines · Anthony Liguori

It's not at all that simple. SCSI has a hierarchical address
mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

Well, another level in the hierarchy, but I don't think it materially changes things.

Depends on whether you expect to say index=0,lun=3 or index=3. If you mean the later, then it's quite conceivable that each target supports less than the maximum number of LUNs. This makes things pretty confusing to the user because they have to know that in the current implementation, index=0 is valid, index=1 isn't, but index=8 is.

Quoted 10 lines
Quoted 7 lines

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Isn't the drive table something totally internal? And how does bus= relate to it?

The reality of unit=X,bus=Y,if=Z is that they expand to:

drive_table_index=Y*max_devs[Z] + X

Whereas max_devs = {"ide":4, "scsi": 7, *:0}

How drive_table_index is interpreted is "if" specific. For if=scsi, each lsi device gets a base drive table index that starts at bus_index *
7. For virtio, the first empty spot in drive_table results in no more drives being created.

It's broken by design.

Regards,

Anthony Liguori

#221 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 4 lines · Avi Kivity
Quoted 1 line · Anthony Liguori

It's not at all that simple. SCSI has a hierarchical address mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

Well, another level in the hierarchy, but I don't think it materially changes things.

Depends on whether you expect to say index=0,lun=3 or index=3. If you mean the later, then it's quite conceivable that each target supports less than the maximum number of LUNs. This makes things pretty confusing to the user because they have to know that in the current implementation, index=0 is valid, index=1 isn't, but index=8 is.

Quoted 3 lines
Quoted 1 line

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Isn't the drive table something totally internal? And how does bus= relate to it?

The reality of unit=X,bus=Y,if=Z is that they expand to:

drive_table_index=Y*max_devs[Z] + X

Whereas max_devs = {"ide":4, "scsi": 7, *:0}

How drive_table_index is interpreted is "if" specific. For if=scsi, each lsi device gets a base drive table index that starts at bus_index * 7. For virtio, the first empty spot in drive_table results in no more drives being created.

It's broken by design.

Regards,

Anthony Liguori

#84 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Michael S. Tsirkin

We should just tell the user which slots are open.
This might be tricky if the config is passed in with the command
line
flags.

qemu -show-available-pci-slots

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Why does the user care?

Let QEMU allocate the PCI slot, then query it to see what slot it assigned and remember that.

It's a roundabout way of doing things.

Having libvirt do PCI slot allocation scares me. It assumes we can return a whitelist of available slots, and then let libvirt just randomly assign things. There's knowledge though in slot assignment that's board-specific. For instance, depending on how many LNK lines you have, you may want to put things in slots in such a way to optimize interrupt balancing or something like that.

How would qemu know which slots to optimize for?

In practice, I don't see that as a real problem. We should (a) add an ioapic and four more pci links (b) recommend that slots be assigned in ascending order, and everything works.

I don't see your concern about libvirt allocating slots. If a human can plug a card into a slot, so can libvirt. Doing an interactive back-and-forth (equivalent to plugging a card while blindfolded, then looking to see which slot we hit) is certainly more difficult.

Quoted 1 line

Some platforms have quirks about expecting a particular slot to have a particular device. It's still an optimal device but it has to be in that slot. You can't really express that via an available slot list.

I'll be surprised if we ever measure different dma speeds on different slots in the qemu virtual pci bus. If we do, we'll find a way to express them:

  $ qemu -print-pci
  slot 0:01: available 33MHz
  slot 0:02: available 33MHz
  slot 0:03: available 66MHz

I feel a little silly typing this.

Signature · 1 line
error compiling committee.c: too many arguments to function
#258 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity

Certainly preferable to -baseline.

Quoted 1 line

This is pretty easy to maintain with config files.

Let's not tie the two together.

I mentioned it because it suggests a good transition. We at least have to think through how things map to the post-config file world regardless of whether that's a few months from now or a decade :-)

Sure, it's good both from the transitional point of view and in its own right.

Signature · 1 line
error compiling committee.c: too many arguments to function
#85 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 4 lines · Avi Kivity

On 06/15/2009 04:23 PM, Anthony Liguori wrote:

How would qemu know which slots to optimize for?

Quoted 8 lines

In practice, I don't see that as a real problem. We should (a) add an ioapic and four more pci links (b) recommend that slots be assigned in ascending order, and everything works.

I don't see your concern about libvirt allocating slots. If a human can plug a card into a slot, so can libvirt. Doing an interactive back-and-forth (equivalent to plugging a card while blindfolded, then looking to see which slot we hit) is certainly more difficult.

Let's take a concrete example because I think you missed my point. For the r2d board, if you have 1 on-board NIC, it has to go in slot 2. Additional NICs can go in any slot, but the primary on-board NIC is expected to live in slot 2. It's possible to not have that on-board NIC.

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

Regards,

Anthony Liguori

#86 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Avi Kivity
Quoted 7 lines · Avi Kivity

On 06/15/2009 04:23 PM, Anthony Liguori wrote:

How would qemu know which slots to optimize for?

In practice, I don't see that as a real problem. We should (a) add an ioapic and four more pci links (b) recommend that slots be assigned in ascending order, and everything works.

I don't see your concern about libvirt allocating slots. If a human can plug a card into a slot, so can libvirt. Doing an interactive back-and-forth (equivalent to plugging a card while blindfolded, then looking to see which slot we hit) is certainly more difficult.

Let's take a concrete example because I think you missed my point. For the r2d board, if you have 1 on-board NIC, it has to go in slot 2. Additional NICs can go in any slot, but the primary on-board NIC is expected to live in slot 2. It's possible to not have that on-board NIC.

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

Regards,

Anthony Liguori

#222 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 9 lines · Anthony Liguori
Quoted 8 lines · Avi Kivity
Quoted 6 lines · Anthony Liguori

It's not at all that simple. SCSI has a hierarchical address
mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

Quoted 8 lines
Quoted 2 lines

Well, another level in the hierarchy, but I don't think it materially changes things.

Depends on whether you expect to say index=0,lun=3 or index=3. If you mean the later, then it's quite conceivable that each target supports less than the maximum number of LUNs. This makes things pretty confusing to the user because they have to know that in the current implementation, index=0 is valid, index=1 isn't, but index=8 is.

I'd object to any implicit addressing rules. If we have to say target=2,lun=7,street=8,city=9,state=99,zip=12345 instead of index=8345345235 so be it.

Quoted 15 lines
Quoted 10 lines
Quoted 7 lines

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Isn't the drive table something totally internal? And how does bus= relate to it?

The reality of unit=X,bus=Y,if=Z is that they expand to:

drive_table_index=Y*max_devs[Z] + X

Quoted 8 lines

Whereas max_devs = {"ide":4, "scsi": 7, *:0}

How drive_table_index is interpreted is "if" specific. For if=scsi, each lsi device gets a base drive table index that starts at bus_index
* 7. For virtio, the first empty spot in drive_table results in no more drives being created.

It's broken by design.

Agreed. Pity that it's exposed to the poor users.

Signature · 1 line
error compiling committee.c: too many arguments to function
#223 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 4 lines · Avi Kivity
Quoted 1 line · Anthony Liguori

It's not at all that simple. SCSI has a hierarchical address mechanism with 0-7 targets but then potentially multiple LUNs per target. Today, we always emulate a single LUN per target but if we ever wanted to support more than 7 disks on a SCSI controller, we would have to add multiple LUN support too. So the current linear unit= parameter is actually pretty broken for SCSI.

Well, another level in the hierarchy, but I don't think it materially changes things.

Depends on whether you expect to say index=0,lun=3 or index=3. If you mean the later, then it's quite conceivable that each target supports less than the maximum number of LUNs. This makes things pretty confusing to the user because they have to know that in the current implementation, index=0 is valid, index=1 isn't, but index=8 is.

I'd object to any implicit addressing rules. If we have to say target=2,lun=7,street=8,city=9,state=99,zip=12345 instead of index=8345345235 so be it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

No, I meant drive file=foo.img,bus=3. If that doesn't seem obvious what it should do to you that's because it isn't at all obvious :-) It ends up skipping a predefined number of locations in the drive table. This is pretty broken fundamentally because it assumes controllers always support a fixed number of devices. Nothing really respects bus_id though so in practice, I assume it's almost universally broken.

Isn't the drive table something totally internal? And how does bus= relate to it?

The reality of unit=X,bus=Y,if=Z is that they expand to:

Quoted 7 lines

drive_table_index=Y*max_devs[Z] + X

Whereas max_devs = {"ide":4, "scsi": 7, *:0}

How drive_table_index is interpreted is "if" specific. For if=scsi, each lsi device gets a base drive table index that starts at bus_index * 7. For virtio, the first empty spot in drive_table results in no more drives being created.

It's broken by design.

Agreed. Pity that it's exposed to the poor users.

Signature · 1 line
error compiling committee.c: too many arguments to function
#259 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Mark McLoughlin
Quoted 13 lines
Quoted 11 lines
Quoted 5 lines

I think the point is that you don't need version numbers if you have a
proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default.

No need to punish new guests in order to maintain compatibility for old guests.

Quoted 9 lines
Quoted 5 lines

Eventually the
default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

(quoted diff) +0 -2
-M pc1
-M pc2
Quoted 3 lines

etc.

This is pretty easy to maintain with config files.

I think this would be reasonable, but it is essentially just a version number which you objected to on the basis that it would make cherry-picking harder for distros.

One thing that would be nice with this '-M pc1' thing would be to retain '-M pc' as a symlink to the latest version. We'd also need a way to read the symlink too, so that you can query what the current latest version is and use that in future.

How would this machine type version relate to e.g. changing the default PCI class of virtio-blk? Would we bump the version number of all machine types can use virtio-blk?

A per-device version number is workable alternative, but only with a saveabi type file IMHO.

I've tried to summarise the options here:

https://fedoraproject.org/wiki/Features/KVM_Stable_Guest_ABI

Cheers,
Mark.

#260 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Mark McLoughlin
Quoted 13 lines
Quoted 11 lines
Quoted 5 lines

I think the point is that you don't need version numbers if you have a
proper device tree.

How do you add a new attribute to the device tree and, when a supplied device tree lacking said attribute, distinguish between a device tree from an old version of qemu (i.e. use the old default) and a partial device tree from the VM manager (i.e. use the new default) ?

-baseline 0.10

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

That's a version number :-)

(I was responding to Anthony's "you don't need a version number")

If you want to prevent incompatibilities, you need to make everything new (potentially including bugfixes) non-default.

No need to punish new guests in order to maintain compatibility for old guests.

Quoted 9 lines
Quoted 5 lines

Eventually the
default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

(quoted diff) +0 -2
-M pc1
-M pc2
Quoted 3 lines

etc.

This is pretty easy to maintain with config files.

I think this would be reasonable, but it is essentially just a version number which you objected to on the basis that it would make cherry-picking harder for distros.

One thing that would be nice with this '-M pc1' thing would be to retain '-M pc' as a symlink to the latest version. We'd also need a way to read the symlink too, so that you can query what the current latest version is and use that in future.

How would this machine type version relate to e.g. changing the default PCI class of virtio-blk? Would we bump the version number of all machine types can use virtio-blk?

A per-device version number is workable alternative, but only with a saveabi type file IMHO.

I've tried to summarise the options here:

https://fedoraproject.org/wiki/Features/KVM_Stable_Guest_ABI

Cheers,
Mark.

#87 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 14 lines · Anthony Liguori
Quoted 4 lines · Avi Kivity

On 06/15/2009 04:23 PM, Anthony Liguori wrote:

How would qemu know which slots to optimize for?

Quoted 8 lines

In practice, I don't see that as a real problem. We should (a) add an ioapic and four more pci links (b) recommend that slots be assigned in ascending order, and everything works.

I don't see your concern about libvirt allocating slots. If a human can plug a card into a slot, so can libvirt. Doing an interactive back-and-forth (equivalent to plugging a card while blindfolded, then looking to see which slot we hit) is certainly more difficult.

Quoted 5 lines

Let's take a concrete example because I think you missed my point. For the r2d board, if you have 1 on-board NIC, it has to go in slot
2. Additional NICs can go in any slot, but the primary on-board NIC is expected to live in slot 2. It's possible to not have that on-board NIC.

Libvirt does not support r2d. I hope it won't start to support it. We can have default values for these types of devices or something like pci_addr=auto.

Quoted 9 lines

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

The end user should have a mechanism to control device slot positioning. For example, if you have several pci devices, some
get high rate of interrupts and some not, if you want to optimize you guest you should isolate the high rate 'interesting' devices. This is something the user will need to do. I agree that the default behavior might be 'auto'

Also, while moving from one qemu version to another, you'll need to represent the older behavior. -qemu-0.10 is not good enough since there will be multiple versions in the future with multiple distributions setting their defaults.

Quoted 5 lines

Regards,

Anthony Liguori

#88 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 7 lines · Avi Kivity

On 06/15/2009 04:23 PM, Anthony Liguori wrote:

How would qemu know which slots to optimize for?

In practice, I don't see that as a real problem. We should (a) add an ioapic and four more pci links (b) recommend that slots be assigned in ascending order, and everything works.

I don't see your concern about libvirt allocating slots. If a human can plug a card into a slot, so can libvirt. Doing an interactive back-and-forth (equivalent to plugging a card while blindfolded, then looking to see which slot we hit) is certainly more difficult.

Let's take a concrete example because I think you missed my point. For the r2d board, if you have 1 on-board NIC, it has to go in slot 2. Additional NICs can go in any slot, but the primary on-board NIC is expected to live in slot 2. It's possible to not have that on-board NIC.

Libvirt does not support r2d. I hope it won't start to support it.
We can have default values for these types of devices or something like pci_addr=auto.

Quoted 5 lines

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

The end user should have a mechanism to control device slot positioning. For example, if you have several pci devices, some get high rate of interrupts and some not, if you want to optimize you guest you should isolate the high rate 'interesting' devices. This is something the user will need to do. I agree that the default behavior might be 'auto'

Also, while moving from one qemu version to another, you'll need to represent the older behavior. -qemu-0.10 is not good enough since there will be multiple versions in the future with multiple distributions setting their defaults.

Quoted 5 lines

Regards,

Anthony Liguori

#261 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 7 lines · Mark McLoughlin
Quoted 5 lines · Anthony Liguori
Quoted 2 lines

Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

(quoted diff) +0 -2
-M pc1
-M pc2
Quoted 9 lines
Quoted 4 lines

etc.

This is pretty easy to maintain with config files.

I think this would be reasonable, but it is essentially just a version number which you objected to on the basis that it would make cherry-picking harder for distros.

It doesn't have to be pc1, pc2. It could be pc-with-usb or pc-with-balloon. If a distro cherry picks in such a way that their pc is not a standard QEMU pc, they would add a new PC type that's specific to their distro.

Quoted 5 lines

One thing that would be nice with this '-M pc1' thing would be to retain '-M pc' as a symlink to the latest version. We'd also need a way to read the symlink too, so that you can query what the current latest version is and use that in future.

Another option is an explicit -M default which always uses the default machine for the architecture. Likewise, we would need a way to query what the default machine was for an architecture.

Quoted 4 lines

How would this machine type version relate to e.g. changing the default PCI class of virtio-blk? Would we bump the version number of all machine types can use virtio-blk?

You would introduce a new machine type. For instance, pc-virtio-class-other. The names don't have to look like that, I'm just doing that to make a point. This may mean that you end up with dozens of machine types but you preserve compatibility, which is a good thing.

Of course, the flip side is that you make preserving the machine config the duty of the user and we don't maintain compatible machine types. This won't work without a proper config file though so for now, we're stuck maintaining machine types.

Regards,

Anthony Liguori

#266 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Mark McLoughlin
Quoted 11 lines · Mark McLoughlin
Quoted 9 lines · Anthony Liguori
Quoted 6 lines

Eventually the
default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

(quoted diff) +0 -2
-M pc1
-M pc2
Quoted 9 lines
Quoted 4 lines

etc.

This is pretty easy to maintain with config files.

I think this would be reasonable, but it is essentially just a version number which you objected to on the basis that it would make cherry-picking harder for distros.

It doesn't have to be pc1, pc2. It could be pc-with-usb or pc-with-balloon. If a distro cherry picks in such a way that their pc is not a standard QEMU pc, they would add a new PC type that's specific to their distro.

Quoted 5 lines

One thing that would be nice with this '-M pc1' thing would be to retain '-M pc' as a symlink to the latest version. We'd also need a way to read the symlink too, so that you can query what the current latest version is and use that in future.

Another option is an explicit -M default which always uses the default machine for the architecture. Likewise, we would need a way to query what the default machine was for an architecture.

Quoted 4 lines

How would this machine type version relate to e.g. changing the default PCI class of virtio-blk? Would we bump the version number of all machine types can use virtio-blk?

You would introduce a new machine type. For instance, pc-virtio-class-other. The names don't have to look like that, I'm just doing that to make a point. This may mean that you end up with dozens of machine types but you preserve compatibility, which is a good thing.

Of course, the flip side is that you make preserving the machine config the duty of the user and we don't maintain compatible machine types. This won't work without a proper config file though so for now, we're stuck maintaining machine types.

Regards,

Anthony Liguori

#200 lore raw

Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 2 lines · Avi Kivity

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

as a user-only (well, i'm a developer, but don't meddle in kernel affairs since 0.99pl9); I also like that kvm is totally CLI-managed.

but migration-wise, i think it could be nicer if the 'origin' process could send the config to the 'target' one. IOW: the -incoming flag shouldn't need any other parameter, and the 'migrate' command should send the whole hardware description before the CPU state, and fail with a 'can't comply' message if the target complains.

of course, that's a simplification. for example, the 'target' process should be able to respect some parameters, mostly the 'external' descriptions, like storage pathnames, or '-net tap' ones.

Signature · 1 line
Javier
#201 lore raw

Re: Configuration vs. compat hints

In reply to Avi Kivity
Quoted 2 lines · Avi Kivity

(I'd be quite happy constructing the entire machine config on the command line, but I realize it's just me)

as a user-only (well, i'm a developer, but don't meddle in kernel affairs since 0.99pl9); I also like that kvm is totally CLI-managed.

but migration-wise, i think it could be nicer if the 'origin' process could send the config to the 'target' one. IOW: the -incoming flag shouldn't need any other parameter, and the 'migrate' command should send the whole hardware description before the CPU state, and fail with a 'can't comply' message if the target complains.

of course, that's a simplification. for example, the 'target' process should be able to respect some parameters, mostly the 'external' descriptions, like storage pathnames, or '-net tap' ones.

Signature · 1 line
Javier
#89 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Dor Laor
Quoted 1 line · Dor Laor

Libvirt does not support r2d. I hope it won't start to support it.

It supports mips, sparc, and ppc machines now. I don't see why it wouldn't support r2d. For ppcemb, I expect this same problem to occur. This sort of restriction is going to be common with embedded boards.

Quoted 2 lines

We can have default values for these types of devices or something like pci_addr=auto.

Why wouldn't libvirt always use pci_addr=auto? If the only argument for having libvirt do pci slot allocation is error messages, can't we find a nice way to allow libvirt to create friendly error messages when QEMU fails?

Quoted 9 lines
Quoted 8 lines

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

Quoted 6 lines

The end user should have a mechanism to control device slot positioning. For example, if you have several pci devices, some get high rate of interrupts and some not, if you want to optimize you guest you should isolate the high rate 'interesting' devices. This is something the user will need to do. I agree that the default behavior might be 'auto'

I'm not at all arguing against pci_addr. I'm arguing about how libvirt should use it with respect to the "genesis" use-case where libvirt has no specific reason to choose one PCI slot over another. In that case, I'm merely advocating that we want to let QEMU make the decision.

Regards,

Anthony Liguori

author maintainer
#262 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 36 lines · Anthony Liguori
Quoted 10 lines · Mark McLoughlin
Quoted 8 lines · Anthony Liguori
Quoted 5 lines

Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

(quoted diff) +0 -2
-M pc1
-M pc2
Quoted 9 lines
Quoted 4 lines

etc.

This is pretty easy to maintain with config files.

I think this would be reasonable, but it is essentially just a version number which you objected to on the basis that it would make cherry-picking harder for distros.

It doesn't have to be pc1, pc2. It could be pc-with-usb or pc-with-balloon. If a distro cherry picks in such a way that their pc is not a standard QEMU pc, they would add a new PC type that's specific to their distro.

Quoted 5 lines

One thing that would be nice with this '-M pc1' thing would be to retain '-M pc' as a symlink to the latest version. We'd also need a way to read the symlink too, so that you can query what the current latest version is and use that in future.

Another option is an explicit -M default which always uses the default machine for the architecture. Likewise, we would need a way to query what the default machine was for an architecture.

Quoted 8 lines
Quoted 4 lines

How would this machine type version relate to e.g. changing the default PCI class of virtio-blk? Would we bump the version number of all machine types can use virtio-blk?

You would introduce a new machine type. For instance, pc-virtio-class-other. The names don't have to look like that, I'm just doing that to make a point. This may mean that you end up with dozens of machine types but you preserve compatibility, which is a good thing.

And then pc-virtio-class-other-with-balloon-without-usb? Wouldn't it be more straightforward to have capability bits which can be switched on and off independently rather than trying to fit unrelated features into a machine type? IMO it only seems more work at first, and QA gets a bit nervious that they can't exhaustively test all options. But in the long run it simplifies things as you don't have to set policy and invent silly names.

Quoted 8 lines

Of course, the flip side is that you make preserving the machine config the duty of the user and we don't maintain compatible machine types. This won't work without a proper config file though so for now, we're stuck maintaining machine types.

Regards,

Anthony Liguori

author maintainer
#263 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 36 lines · Anthony Liguori
Quoted 10 lines · Mark McLoughlin
Quoted 8 lines · Anthony Liguori
Quoted 5 lines

Eventually the default configuration becomes increasingly unusable and you need a new baseline. You must still be able to fall back to the old baseline for older guests. I don't think games with configuration files can hide that.

(quoted diff) +0 -2
-M pc1
-M pc2
Quoted 9 lines
Quoted 4 lines

etc.

This is pretty easy to maintain with config files.

I think this would be reasonable, but it is essentially just a version number which you objected to on the basis that it would make cherry-picking harder for distros.

It doesn't have to be pc1, pc2. It could be pc-with-usb or pc-with-balloon. If a distro cherry picks in such a way that their pc is not a standard QEMU pc, they would add a new PC type that's specific to their distro.

Quoted 5 lines

One thing that would be nice with this '-M pc1' thing would be to retain '-M pc' as a symlink to the latest version. We'd also need a way to read the symlink too, so that you can query what the current latest version is and use that in future.

Another option is an explicit -M default which always uses the default machine for the architecture. Likewise, we would need a way to query what the default machine was for an architecture.

Quoted 8 lines
Quoted 4 lines

How would this machine type version relate to e.g. changing the default PCI class of virtio-blk? Would we bump the version number of all machine types can use virtio-blk?

You would introduce a new machine type. For instance, pc-virtio-class-other. The names don't have to look like that, I'm just doing that to make a point. This may mean that you end up with dozens of machine types but you preserve compatibility, which is a good thing.

And then pc-virtio-class-other-with-balloon-without-usb? Wouldn't it be more straightforward to have capability bits which can be switched on and off independently rather than trying to fit unrelated features into a machine type? IMO it only seems more work at first, and QA gets a bit nervious that they can't exhaustively test all options. But in the long run it simplifies things as you don't have to set policy and invent silly names.

Quoted 8 lines

Of course, the flip side is that you make preserving the machine config the duty of the user and we don't maintain compatible machine types. This won't work without a proper config file though so for now, we're stuck maintaining machine types.

Regards,

Anthony Liguori

author maintainer
#90 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 31 lines · Anthony Liguori
Quoted 1 line · Dor Laor

Libvirt does not support r2d. I hope it won't start to support it.

It supports mips, sparc, and ppc machines now. I don't see why it wouldn't support r2d. For ppcemb, I expect this same problem to occur. This sort of restriction is going to be common with embedded boards.

Quoted 2 lines

We can have default values for these types of devices or something like pci_addr=auto.

Why wouldn't libvirt always use pci_addr=auto? If the only argument for having libvirt do pci slot allocation is error messages, can't we find a nice way to allow libvirt to create friendly error messages when QEMU fails?

Quoted 9 lines
Quoted 8 lines

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

Quoted 6 lines

The end user should have a mechanism to control device slot positioning. For example, if you have several pci devices, some get high rate of interrupts and some not, if you want to optimize you guest you should isolate the high rate 'interesting' devices. This is something the user will need to do. I agree that the default behavior might be 'auto'

Quoted 4 lines

I'm not at all arguing against pci_addr. I'm arguing about how libvirt should use it with respect to the "genesis" use-case where libvirt has no specific reason to choose one PCI slot over another. In that case, I'm merely advocating that we want to let QEMU make the decision.

The allocation code could be moved out into a library, and libvirt could link with it (ducks).

Quoted 3 lines

Regards,

Anthony Liguori

author maintainer
#91 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

In reply to Anthony Liguori
Quoted 31 lines · Anthony Liguori
Quoted 1 line · Dor Laor

Libvirt does not support r2d. I hope it won't start to support it.

It supports mips, sparc, and ppc machines now. I don't see why it wouldn't support r2d. For ppcemb, I expect this same problem to occur. This sort of restriction is going to be common with embedded boards.

Quoted 2 lines

We can have default values for these types of devices or something like pci_addr=auto.

Why wouldn't libvirt always use pci_addr=auto? If the only argument for having libvirt do pci slot allocation is error messages, can't we find a nice way to allow libvirt to create friendly error messages when QEMU fails?

Quoted 9 lines
Quoted 8 lines

If you let QEMU allocate which PCI slot a device goes in, we can hide this detail from libvirt. If you have libvirt do PCI slot allocation by default, it has to know about this restriction in the r2d board unless you have a clever way to express this sort of information.

Once QEMU has allocated a device to a slot, libvirt can do a good job maintaining that relationship.

Quoted 6 lines

The end user should have a mechanism to control device slot positioning. For example, if you have several pci devices, some get high rate of interrupts and some not, if you want to optimize you guest you should isolate the high rate 'interesting' devices. This is something the user will need to do. I agree that the default behavior might be 'auto'

Quoted 4 lines

I'm not at all arguing against pci_addr. I'm arguing about how libvirt should use it with respect to the "genesis" use-case where libvirt has no specific reason to choose one PCI slot over another. In that case, I'm merely advocating that we want to let QEMU make the decision.

The allocation code could be moved out into a library, and libvirt could link with it (ducks).

Quoted 3 lines

Regards,

Anthony Liguori

#92 lore raw

Re: Configuration vs. compat hints [was Re: [Qemu-devel] [PATCHv3 03/13] qemu: add routines to manage PCI capabilities]

Quoted 9 lines · Michael S. Tsirkin
Quoted 5 lines

I'm not at all arguing against pci_addr. I'm arguing about how libvirt should use it with respect to the "genesis" use-case where libvirt has no specific reason to choose one PCI slot over another. In that case, I'm merely advocating that we want to let QEMU make the decision.

The allocation code could be moved out into a library, and libvirt could link with it (ducks).

Why does libvirt want to do allocation?

Regards,

Anthony Liguori