@@ -1265,12 +1265,32 @@ static bool version_before_3(void *opaque, int version_id)
return version_id < 3;
}
+static bool spapr_pending_events_needed(void *opaque)
+{
+ sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
+ return !QTAILQ_EMPTY(&spapr->pending_events);
+}
+
static bool spapr_ccs_list_needed(void *opaque)
{
sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
return !QTAILQ_EMPTY(&spapr->ccs_list);
}
+static const VMStateDescription vmstate_spapr_event_entry = {
+ .name = "spapreventlogentry",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_INT32(log_type, sPAPREventLogEntry),
+ VMSTATE_BOOL(exception, sPAPREventLogEntry),
+ VMSTATE_UINT32(data_size, sPAPREventLogEntry),
+ VMSTATE_VARRAY_UINT32_ALLOC(data, sPAPREventLogEntry, data_size,
+ 0, vmstate_info_uint8, uint8_t),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
static const VMStateDescription vmstate_spapr_ccs = {
.name = "spaprconfigureconnectorstate",
.version_id = 1,
@@ -1283,11 +1303,28 @@ static const VMStateDescription vmstate_spapr_ccs = {
},
};
+static const QTAILQMetaData spapr_events_metadata =
+ VMSTATE_QTAILQ_METADATA(pending_events, sPAPRMachineState,
+ sPAPREventLogEntry, next,
+ vmstate_spapr_event_entry);
+
static const QTAILQMetaData spapr_ccs_metadata =
VMSTATE_QTAILQ_METADATA( ccs_list, sPAPRMachineState,
sPAPRConfigureConnectorState, next,
vmstate_spapr_ccs);
+static const VMStateDescription vmstate_spapr_pending_events = {
+ .name = "spaprpendingevents",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .needed = spapr_pending_events_needed,
+ .fields = (VMStateField[]) {
+ VMSTATE_QTAILQ_V(pending_events, sPAPRMachineState, 1,
+ spapr_events_metadata),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
static const VMStateDescription vmstate_spapr_ccs_list = {
.name = "spaprccslist",
.version_id = 1,
@@ -1315,6 +1352,7 @@ static const VMStateDescription vmstate_spapr = {
VMSTATE_END_OF_LIST()
},
.subsections = (const VMStateDescription*[]) {
+ &vmstate_spapr_pending_events,
&vmstate_spapr_ccs_list,
NULL
}
@@ -239,7 +239,8 @@ void spapr_events_fdt_skel(void *fdt, uint32_t check_exception_irq)
_FDT((fdt_end_node(fdt)));
}
-static void rtas_event_log_queue(int log_type, void *data, bool exception)
+static void rtas_event_log_queue(int log_type, void *data, bool exception,
+ int data_size)
{
sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
sPAPREventLogEntry *entry = g_new(sPAPREventLogEntry, 1);
@@ -248,6 +249,7 @@ static void rtas_event_log_queue(int log_type, void *data, bool exception)
entry->log_type = log_type;
entry->exception = exception;
entry->data = data;
+ entry->data_size = data_size;
QTAILQ_INSERT_TAIL(&spapr->pending_events, entry, next);
}
@@ -350,6 +352,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
struct rtas_event_log_v6_mainb *mainb;
struct rtas_event_log_v6_epow *epow;
struct epow_log_full *new_epow;
+ uint32_t data_size;
new_epow = g_malloc0(sizeof(*new_epow));
hdr = &new_epow->hdr;
@@ -358,13 +361,13 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
mainb = &new_epow->mainb;
epow = &new_epow->epow;
+ data_size = sizeof(*new_epow);
hdr->summary = cpu_to_be32(RTAS_LOG_VERSION_6
| RTAS_LOG_SEVERITY_EVENT
| RTAS_LOG_DISPOSITION_NOT_RECOVERED
| RTAS_LOG_OPTIONAL_PART_PRESENT
| RTAS_LOG_TYPE_EPOW);
- hdr->extended_length = cpu_to_be32(sizeof(*new_epow)
- - sizeof(new_epow->hdr));
+ hdr->extended_length = cpu_to_be32(data_size - sizeof(new_epow->hdr));
spapr_init_v6hdr(v6hdr);
spapr_init_maina(maina, 3 /* Main-A, Main-B and EPOW */);
@@ -384,7 +387,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
epow->event_modifier = RTAS_LOG_V6_EPOW_MODIFIER_NORMAL;
epow->extended_modifier = RTAS_LOG_V6_EPOW_XMODIFIER_PARTITION_SPECIFIC;
- rtas_event_log_queue(RTAS_LOG_TYPE_EPOW, new_epow, true);
+ rtas_event_log_queue(RTAS_LOG_TYPE_EPOW, new_epow, true, data_size);
qemu_irq_pulse(xics_get_qirq(spapr->icp, spapr->check_exception_irq));
}
@@ -407,6 +410,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
struct rtas_event_log_v6_maina *maina;
struct rtas_event_log_v6_mainb *mainb;
struct rtas_event_log_v6_hp *hp;
+ uint32_t data_size;
new_hp = g_malloc0(sizeof(struct hp_log_full));
hdr = &new_hp->hdr;
@@ -415,14 +419,14 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
mainb = &new_hp->mainb;
hp = &new_hp->hp;
+ data_size = sizeof(*new_hp);
hdr->summary = cpu_to_be32(RTAS_LOG_VERSION_6
| RTAS_LOG_SEVERITY_EVENT
| RTAS_LOG_DISPOSITION_NOT_RECOVERED
| RTAS_LOG_OPTIONAL_PART_PRESENT
| RTAS_LOG_INITIATOR_HOTPLUG
| RTAS_LOG_TYPE_HOTPLUG);
- hdr->extended_length = cpu_to_be32(sizeof(*new_hp)
- - sizeof(new_hp->hdr));
+ hdr->extended_length = cpu_to_be32(data_size - sizeof(new_hp->hdr));
spapr_init_v6hdr(v6hdr);
spapr_init_maina(maina, 3 /* Main-A, Main-B, HP */);
@@ -463,7 +467,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
hp->drc.index = cpu_to_be32(drc);
}
- rtas_event_log_queue(RTAS_LOG_TYPE_HOTPLUG, new_hp, true);
+ rtas_event_log_queue(RTAS_LOG_TYPE_HOTPLUG, new_hp, true, data_size);
qemu_irq_pulse(xics_get_qirq(spapr->icp, spapr->check_exception_irq));
}
@@ -530,7 +534,7 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMachineState *spapr,
goto out_no_events;
}
- hdr = event->data;
+ hdr = (struct rtas_error_log *)event->data;
event_len = be32_to_cpu(hdr->extended_length) + sizeof(*hdr);
if (event_len < len) {
@@ -580,7 +584,7 @@ static void event_scan(PowerPCCPU *cpu, sPAPRMachineState *spapr,
goto out_no_events;
}
- hdr = event->data;
+ hdr = (struct rtas_error_log *)event->data;
event_len = be32_to_cpu(hdr->extended_length) + sizeof(*hdr);
if (event_len < len) {
@@ -552,7 +552,8 @@ sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn);
struct sPAPREventLogEntry {
int log_type;
bool exception;
- void *data;
+ uint32_t data_size;
+ uint8_t *data;
QTAILQ_ENTRY(sPAPREventLogEntry) next;
};
In racing situations between hotplug events and migration operation, a rtas hotplug event could have not yet be delivered to the source guest when migration is started. In this case the pending_events of spapr state need be transmitted to the target so that the hotplug event can be finished on the target. All the different fields of the events are encoded as defined by PAPR. We can migrate them as uint8_t binary stream without any concerns about data padding or endianess. pending_events is put in a subsection in the spapr state VMSD to make sure migration across different versions is not broken. Signed-off-by: Jianjun Duan <duanj@linux.vnet.ibm.com> --- hw/ppc/spapr.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 22 +++++++++++++--------- include/hw/ppc/spapr.h | 3 ++- 3 files changed, 53 insertions(+), 10 deletions(-)