Skip to contentSkip to conversation

vmstate: Add preallocation for migrating arrays (VMS_ALLOC flag)

PATCH Applied Alexey Kardashevskiy 3 participants 9 messages Jun 3, 2014 – Jun 25, 2014 6 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 7 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

Quoted 8 lines

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Quoted 79 lines
---
 include/migration/vmstate.h | 11 +++++++++++
 vmstate.c                   | 13 ++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
include/migration/vmstate.h +11 -0
index 7e45048..e794694 100644
@@ -101,6 +101,7 @@ enum VMStateFlags {
     VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
     VMS_MUST_EXIST       = 0x1000, /* Field must exist in input */
+    VMS_ALLOC            = 0x2000, /* Alloc a buffer on the destination */
 };
 
 typedef struct {
@@ -429,6 +430,16 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = offsetof(_state, _field),                          \
 }
 
+#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .vmsd       = &(_vmsd),                                          \
+    .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
+    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
+}
+
 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
     .name         = (stringify(_field)),                             \
     .version_id   = (_version),                                      \
vmstate.c +10 -3
index b5882fa..fb95e39 100644
@@ -43,11 +43,18 @@ static int vmstate_size(void *opaque, VMStateField *field)
     return size;
 }
 
-static void *vmstate_base_addr(void *opaque, VMStateField *field)
+static void *vmstate_base_addr(void *opaque, VMStateField *field, bool alloc)
 {
     void *base_addr = opaque + field->offset;
 
     if (field->flags & VMS_POINTER) {
+        if (alloc && (field->flags & VMS_ALLOC)) {
+            int n_elems = vmstate_n_elems(opaque, field);
+            if (n_elems) {
+                *((void **)base_addr + field->start) = g_malloc_n(n_elems,
+                                                                  field->size);
+            }
+        }
         base_addr = *(void **)base_addr + field->start;
     }
 
@@ -81,7 +88,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
              field->field_exists(opaque, version_id)) ||
             (!field->field_exists &&
              field->version_id <= version_id)) {
-            void *base_addr = vmstate_base_addr(opaque, field);
+            void *base_addr = vmstate_base_addr(opaque, field, true);
             int i, n_elems = vmstate_n_elems(opaque, field);
             int size = vmstate_size(opaque, field);
 
@@ -131,7 +138,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
     while (field->name) {
         if (!field->field_exists ||
             field->field_exists(opaque, vmsd->version_id)) {
-            void *base_addr = vmstate_base_addr(opaque, field);
+            void *base_addr = vmstate_base_addr(opaque, field, false);
             int i, n_elems = vmstate_n_elems(opaque, field);
             int size = vmstate_size(opaque, field);
 
Signature · 1 line
Alexey
#3 lore raw
Quoted 12 lines · Alexey Kardashevskiy
Quoted 11 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

Quoted 8 lines
Quoted 4 lines

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Hi, anyone? :)

Quoted 83 lines
Quoted 81 lines
---
 include/migration/vmstate.h | 11 +++++++++++
 vmstate.c                   | 13 ++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
include/migration/vmstate.h +11 -0
index 7e45048..e794694 100644
@@ -101,6 +101,7 @@ enum VMStateFlags {
     VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
     VMS_MUST_EXIST       = 0x1000, /* Field must exist in input */
+    VMS_ALLOC            = 0x2000, /* Alloc a buffer on the destination */
 };
 
 typedef struct {
@@ -429,6 +430,16 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = offsetof(_state, _field),                          \
 }
 
+#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .vmsd       = &(_vmsd),                                          \
+    .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
+    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
+}
+
 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
     .name         = (stringify(_field)),                             \
     .version_id   = (_version),                                      \
vmstate.c +10 -3
index b5882fa..fb95e39 100644
@@ -43,11 +43,18 @@ static int vmstate_size(void *opaque, VMStateField *field)
     return size;
 }
 
-static void *vmstate_base_addr(void *opaque, VMStateField *field)
+static void *vmstate_base_addr(void *opaque, VMStateField *field, bool alloc)
 {
     void *base_addr = opaque + field->offset;
 
     if (field->flags & VMS_POINTER) {
+        if (alloc && (field->flags & VMS_ALLOC)) {
+            int n_elems = vmstate_n_elems(opaque, field);
+            if (n_elems) {
+                *((void **)base_addr + field->start) = g_malloc_n(n_elems,
+                                                                  field->size);
+            }
+        }
         base_addr = *(void **)base_addr + field->start;
     }
 
@@ -81,7 +88,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
              field->field_exists(opaque, version_id)) ||
             (!field->field_exists &&
              field->version_id <= version_id)) {
-            void *base_addr = vmstate_base_addr(opaque, field);
+            void *base_addr = vmstate_base_addr(opaque, field, true);
             int i, n_elems = vmstate_n_elems(opaque, field);
             int size = vmstate_size(opaque, field);
 
@@ -131,7 +138,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
     while (field->name) {
         if (!field->field_exists ||
             field->field_exists(opaque, vmsd->version_id)) {
-            void *base_addr = vmstate_base_addr(opaque, field);
+            void *base_addr = vmstate_base_addr(opaque, field, false);
             int i, n_elems = vmstate_n_elems(opaque, field);
             int size = vmstate_size(opaque, field);
 
Signature · 1 line
Alexey
#4 lore raw
Quoted 20 lines · Alexey Kardashevskiy
Quoted 19 lines · Alexey Kardashevskiy
Quoted 15 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Quoted 4 lines
Quoted 1 line

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Hi, anyone? :)

Ping?

Quoted 88 lines
Quoted 86 lines
Quoted 84 lines
---
 include/migration/vmstate.h | 11 +++++++++++
 vmstate.c                   | 13 ++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
include/migration/vmstate.h +11 -0
index 7e45048..e794694 100644
@@ -101,6 +101,7 @@ enum VMStateFlags {
     VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
     VMS_MUST_EXIST       = 0x1000, /* Field must exist in input */
+    VMS_ALLOC            = 0x2000, /* Alloc a buffer on the destination */
 };
 
 typedef struct {
@@ -429,6 +430,16 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = offsetof(_state, _field),                          \
 }
 
+#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .vmsd       = &(_vmsd),                                          \
+    .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
+    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
+}
+
 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
     .name         = (stringify(_field)),                             \
     .version_id   = (_version),                                      \
vmstate.c +10 -3
index b5882fa..fb95e39 100644
@@ -43,11 +43,18 @@ static int vmstate_size(void *opaque, VMStateField *field)
     return size;
 }
 
-static void *vmstate_base_addr(void *opaque, VMStateField *field)
+static void *vmstate_base_addr(void *opaque, VMStateField *field, bool alloc)
 {
     void *base_addr = opaque + field->offset;
 
     if (field->flags & VMS_POINTER) {
+        if (alloc && (field->flags & VMS_ALLOC)) {
+            int n_elems = vmstate_n_elems(opaque, field);
+            if (n_elems) {
+                *((void **)base_addr + field->start) = g_malloc_n(n_elems,
+                                                                  field->size);
+            }
+        }
         base_addr = *(void **)base_addr + field->start;
     }
 
@@ -81,7 +88,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
              field->field_exists(opaque, version_id)) ||
             (!field->field_exists &&
              field->version_id <= version_id)) {
-            void *base_addr = vmstate_base_addr(opaque, field);
+            void *base_addr = vmstate_base_addr(opaque, field, true);
             int i, n_elems = vmstate_n_elems(opaque, field);
             int size = vmstate_size(opaque, field);
 
@@ -131,7 +138,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
     while (field->name) {
         if (!field->field_exists ||
             field->field_exists(opaque, vmsd->version_id)) {
-            void *base_addr = vmstate_base_addr(opaque, field);
+            void *base_addr = vmstate_base_addr(opaque, field, false);
             int i, n_elems = vmstate_n_elems(opaque, field);
             int size = vmstate_size(opaque, field);
 
Signature · 1 line
Alexey
#5 lore raw
Quoted 20 lines · Alexey Kardashevskiy
Quoted 19 lines · Alexey Kardashevskiy
Quoted 18 lines · Alexey Kardashevskiy
Quoted 15 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Hi, anyone? :)

Ping?

Alex

#6 lore raw
Quoted 23 lines · Alexander Graf
Quoted 22 lines · Alexey Kardashevskiy
Quoted 21 lines · Alexey Kardashevskiy
Quoted 20 lines · Alexey Kardashevskiy
Quoted 17 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all
require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to
VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Hi, anyone? :)

Ping?

This is cool and thanks :) But we still need to attract attention of others...

Signature · 1 line
Alexey
Reviewed-by
#7 lore raw
In reply to Alexander Graf
Quoted 21 lines · Alexander Graf
Quoted 20 lines · Alexey Kardashevskiy
Quoted 19 lines · Alexey Kardashevskiy
Quoted 18 lines · Alexey Kardashevskiy
Quoted 15 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Hi, anyone? :)

Ping?

BTW, should I include it, or will it got include through this series?

I am ok with both.

Later, Juan.

#8 lore raw
Quoted 21 lines · Juan Quintela
Quoted 20 lines · Alexander Graf
Quoted 19 lines · Alexey Kardashevskiy
Quoted 18 lines · Alexey Kardashevskiy
Quoted 17 lines · Alexey Kardashevskiy
Quoted 15 lines · Alexey Kardashevskiy

There are few helpers already to support array migration. However they all require the destination side to preallocate arrays before migration which is not always possible due to unknown array size as it might be some sort of dynamic state. One of the examples is an array of MSIX-enabled devices in SPAPR PHB - this array may vary from 0 to 65536 entries and its size depends on guest's ability to enable MSIX or do PCI hotplug.

This adds new VMSTATE_VARRAY_STRUCT_ALLOC macro which is pretty similar to VMSTATE_STRUCT_VARRAY_POINTER_INT32 but it can alloc memory for migratign array on the destination side.

This defines VMS_ALLOC flag for a field.

This changes vmstate_base_addr() to do the allocation when receiving migration.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Juan, Peter? No hurry, just pinging in order not to forget :) Thanks!

Hi, anyone? :)

Ping?

BTW, should I include it, or will it got include through this series?

Thanks a lot for the review :). I'll pick it up - the next patch depends on it and we're getting very close to hard freeze.

Alex

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: [Qemu-devel] [PATCH v3 9/9] spapr_pci: Use XICS interrupt allocator and do not cache interrupts in PHB

Quoted 241 lines · Alexander Graf
Quoted 145 lines · Alexey Kardashevskiy
Quoted 135 lines · Alexander Graf
Quoted 134 lines · Alexey Kardashevskiy

Currently SPAPR PHB keeps track of all allocated MSI (here and below MSI stands for both MSI and MSIX) interrupt because
XICS used to be unable to reuse interrupts. This is a problem for dynamic MSI reconfiguration which happens when guest reloads a driver or performs PCI hotplug. Another problem is that the existing implementation can enable MSI on 32 devices maximum (SPAPR_MSIX_MAX_DEVS=32) and there is no good reason for that.

This makes use of new XICS ability to reuse interrupts.

This reorganizes MSI information storage in sPAPRPHBState. Instead of static array of 32 descriptors (one per a PCI function), this patch adds a GHashTable when @config_addr is a key and (first_irq, num) pair is a value. GHashTable can dynamically grow and shrink so the initial limit of 32 devices is gone.

This changes migration stream as @msi_table was a static array while new @msi_devs is a dynamic hash table. This adds temporary array which is used for migration, it is populated in "spapr_pci"::pre_save() callback and expanded into the hash table in post_load() callback. Since the destination side does not know the number of MSI-enabled devices in advance and cannot pre-allocate the temporary array to receive migration state, this makes use of new VMSTATE_STRUCT_VARRAY_ALLOC macro which allocates the array automatically.

This resets the MSI configuration space when interrupts are released by the ibm,change-msi RTAS call.

This fixed traces to be more informative.

This changes vmstate_spapr_pci_msi name from "...lsi" to "...msi" which was incorrect by accident. As the internal representation changed, thus bumps migration version number.

---
Changes:
v3:
* used GHashTable
* implemented temporary MSI state array for migration

---
   hw/ppc/spapr_pci.c          | 195
+++++++++++++++++++++++++-------------------
   include/hw/pci-host/spapr.h |  21 +++--
   trace-events                |   5 +-
   3 files changed, 129 insertions(+), 92 deletions(-)
hw/ppc/spapr_pci.c +0 -1
index a2f9677..48c9aad 100644
@@ -220,36 +220,12 @@ static void rtas_write_pci_config(PowerPCCPU *cpu,
 sPAPREnvironment *spapr,
   }
     /*
- * Find an entry with config_addr or returns the empty one if not

found AND
- * alloc_new is set.
- * At the moment the msi_table entries are never released so there is
- * no point to look till the end of the list if we need to find the free entry.
- */

hw/ppc/spapr_pci.c +7 -22
-static int spapr_msicfg_find(sPAPRPHBState *phb, uint32_t config_addr,
-                             bool alloc_new)
-{
-    int i;
-
-    for (i = 0; i < SPAPR_MSIX_MAX_DEVS; ++i) {
-        if (!phb->msi_table[i].nvec) {
-            break;
-        }
-        if (phb->msi_table[i].config_addr == config_addr) {
-            return i;
-        }
-    }
-    if ((i < SPAPR_MSIX_MAX_DEVS) && alloc_new) {
-        trace_spapr_pci_msi("Allocating new MSI config", i, config_addr);
-        return i;
-    }
-
-    return -1;
-}
-
-/*
    * Set MSI/MSIX message data.
    * This is required for msi_notify()/msix_notify() which
    * will write at the addresses via spapr_msi_write().
+ *
+ * If hwaddr == 0, all entries will have .data == first_irq i.e.
+ * table will be reset.
    */
   static void spapr_msi_setmsg(PCIDevice *pdev, hwaddr addr, bool msix,
                                unsigned first_irq, unsigned req_num)
@@ -263,9 +239,12 @@ static void spapr_msi_setmsg(PCIDevice *pdev, hwaddr
 addr, bool msix,
           return;
       }
   -    for (i = 0; i < req_num; ++i, ++msg.data) {
+    for (i = 0; i < req_num; ++i) {
           msix_set_message(pdev, i, msg);
           trace_spapr_pci_msi_setup(pdev->name, i, msg.address);
+        if (addr) {
+            ++msg.data;
+        }
       }
   }
   @@ -280,9 +259,12 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu,

sPAPREnvironment *spapr,

       unsigned int req_num = rtas_ld(args, 4); /* 0 == remove all */
       unsigned int seq_num = rtas_ld(args, 5);
       unsigned int ret_intr_type;
hw/ppc/spapr_pci.c +7 -4
-    int ndev, irq, max_irqs = 0;
+    unsigned int irq, max_irqs = 0, num = 0;
       sPAPRPHBState *phb = NULL;
       PCIDevice *pdev = NULL;
+    bool msix = false;
+    spapr_pci_msi *msi;
+    int *config_addr_key;
         switch (func) {
       case RTAS_CHANGE_MSI_FN:
@@ -310,13 +292,18 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu,
 sPAPREnvironment *spapr,
         /* Releasing MSIs */
       if (!req_num) {
-        ndev = spapr_msicfg_find(phb, config_addr, false);
-        if (ndev < 0) {
-            trace_spapr_pci_msi("MSI has not been enabled", -1,
 config_addr);
+        msi = (spapr_pci_msi *) g_hash_table_lookup(phb->msi,
 &config_addr);
+        if (!msi) {
+            trace_spapr_pci_msi("Releasing wrong config", config_addr);
               rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
               return;
Quoted 8 lines

hw/ppc/spapr_pci.c static void rtas_ibm_change_msi(PowerPCCPU *cpu, · line 306

Quoted 6 lines
hw/ppc/spapr_pci.c +4 -1
           }
-        trace_spapr_pci_msi("Released MSIs", ndev, config_addr);
+
+        xics_free(spapr->icp, msi->first_irq, msi->num);
+        spapr_msi_setmsg(pdev, 0, msix, 0, num);
+        g_hash_table_remove(phb->msi, &config_addr);

Are you sure this doesn't have to be the exact same element? That pointer is to the stack, not to the element.

Quoted 6 lines

I was not sure so I tested and it deletes element even if the key for g_hash_table_remove() is on stack. I looked at glibc and it should just work as it is now while I am providing a key_equal_func() callback to the map:
http://sourcecodebrowser.com/glib2.0/2.12.4/ghash_8c.html#acff7e5fffc2572456a379d3d62d3e6ed

True, works for me.

Quoted 85 lines
Quoted 85 lines
Quoted 77 lines
hw/ppc/spapr_pci.c +2 -0
+
+        trace_spapr_pci_msi("Released MSIs", config_addr);
           rtas_st(rets, 0, RTAS_OUT_SUCCESS);
           rtas_st(rets, 1, 0);
           return;
hw/ppc/spapr_pci.c +0 -0
@@ -324,15 +311,6 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu,
 sPAPREnvironment *spapr,
         /* Enabling MSI */
   -    /* Find a device number in the map to add or reuse the existing

one */

hw/ppc/spapr_pci.c +5 -10
-    ndev = spapr_msicfg_find(phb, config_addr, true);
-    if (ndev >= SPAPR_MSIX_MAX_DEVS || ndev < 0) {
-        error_report("No free entry for a new MSI device");
-        rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
-        return;
-    }
-    trace_spapr_pci_msi("Configuring MSI", ndev, config_addr);
-
       /* Check if the device supports as many IRQs as requested */
       if (ret_intr_type == RTAS_TYPE_MSI) {
           max_irqs = msi_nr_vectors_allocated(pdev);
@@ -340,48 +318,47 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu,
 sPAPREnvironment *spapr,
           max_irqs = pdev->msix_entries_nr;
       }
       if (!max_irqs) {
-        error_report("Requested interrupt type %d is not enabled for
 device#%d",
-                     ret_intr_type, ndev);
+        error_report("Requested interrupt type %d is not enabled for
 device %x",
+                     ret_intr_type, config_addr);
           rtas_st(rets, 0, -1); /* Hardware error */
           return;
       }
       /* Correct the number if the guest asked for too many */
       if (req_num > max_irqs) {
+        trace_spapr_pci_msi_retry(config_addr, req_num, max_irqs);
           req_num = max_irqs;
+        irq = 0; /* to avoid misleading trace */
+        goto out;
       }
   -    /* Check if there is an old config and MSI number has not

changed */
- if (phb->msi_table[ndev].nvec && (req_num !=
phb->msi_table[ndev].nvec)) {

hw/ppc/spapr_pci.c +5 -15
-        /* Unexpected behaviour */
-        error_report("Cannot reuse MSI config for device#%d", ndev);
+    /* Allocate MSIs */
+    irq = xics_alloc_block(spapr->icp, 0, req_num, false,
+                           ret_intr_type == RTAS_TYPE_MSI);
+    if (!irq) {
+        error_report("Cannot allocate MSIs for device %x", config_addr);
           rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
           return;
       }
   -    /* There is no cached config, allocate MSIs */
-    if (!phb->msi_table[ndev].nvec) {
-        irq = xics_alloc_block(spapr->icp, 0, req_num, false,
-                               ret_intr_type == RTAS_TYPE_MSI);
-        if (irq < 0) {
-            error_report("Cannot allocate MSIs for device#%d", ndev);
-            rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
-            return;
-        }
-        phb->msi_table[ndev].irq = irq;
-        phb->msi_table[ndev].nvec = req_num;
-        phb->msi_table[ndev].config_addr = config_addr;
-    }
-
       /* Setup MSI/MSIX vectors in the device (via cfgspace or MSIX

BAR) */

       spapr_msi_setmsg(pdev, spapr->msi_win_addr, ret_intr_type ==

RTAS_TYPE_MSIX,

hw/ppc/spapr_pci.c

Quoted 7 lines
hw/ppc/spapr_pci.c +5 -1
-                     phb->msi_table[ndev].irq, req_num);
+                     irq, req_num);
   +    /* Add MSI device to cache */
+    msi = g_new(spapr_pci_msi, 1);
+    msi->first_irq = irq;
+    msi->num = req_num;
+    config_addr_key = g_new(int, 1);

gint?

Quoted 7 lines
Quoted 4 lines

Same thing but yeah, better to stay solid.

Is that it or you will have more comments after more careful review? :) Thanks!

I think the patch set is ok as is, but I want to have Juan's / Peter's ack on the vmstate patch.

Since Juan is ignoring this, can you please pull 1..7 of this and leave 8-9 for later as they not exactly about XICS anyway? Thanks!

Quoted 4 lines

Alex

Signature · 1 line
Alexey
#14 lore raw

Re: [Qemu-devel] [PATCH v3 0/9] Move interrupts from spapr to xics

In reply to a message not in the archive
Quoted 19 lines · Alexey Kardashevskiy

This moves interrupts allocation business from SPAPR to XICS and makes use of it.

Changes:
v3:
* replaces static array of descriptors in SPAPR PHB with GHashTable
* implements migration of hash table via temporary array

v2:
* s/server/source/
* fixed typos, code style, added an assert
* added patch for spapr_pci for better IRQ reuse for MSI/MSIX

There is just one source at the moment. We might create one per PHB and one per VIO device or VIO bus but I do not see any immediate profit from it.

Quoted 6 lines

Juan, Peter, you are cc-ed because 8/9 introduces new VMSTATE_STRUCT_VARRAY_ALLOC and 9/9 makes use of it and checkpatch.pl thinks you might be right people to get opinion about this from.

Please comment. Thanks!

Thanks, applied to ppc-next.

Alex