From nobody Mon Apr 29 02:44:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499796689652504.327420214266; Tue, 11 Jul 2017 11:11:29 -0700 (PDT) Received: from localhost ([::1]:48162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUzd9-0002lH-8F for importer@patchew.org; Tue, 11 Jul 2017 14:11:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUza1-0008Pc-5Y for qemu-devel@nongnu.org; Tue, 11 Jul 2017 14:08:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUzZx-00036R-UU for qemu-devel@nongnu.org; Tue, 11 Jul 2017 14:08:13 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:35030 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUzZx-00035o-Nv for qemu-devel@nongnu.org; Tue, 11 Jul 2017 14:08:09 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6BI3cSi123679 for ; Tue, 11 Jul 2017 14:08:09 -0400 Received: from e24smtp04.br.ibm.com (e24smtp04.br.ibm.com [32.104.18.25]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bn0muykv3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 11 Jul 2017 14:08:08 -0400 Received: from localhost by e24smtp04.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 11 Jul 2017 15:08:06 -0300 Received: from d24relay04.br.ibm.com (9.18.232.146) by e24smtp04.br.ibm.com (10.172.0.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 11 Jul 2017 15:08:04 -0300 Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay04.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6BI849h3146190; Tue, 11 Jul 2017 15:08:04 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v6BI86bF025299; Tue, 11 Jul 2017 15:08:06 -0300 Received: from arthas.br.ibm.com (arthas.br.ibm.com [9.18.235.135]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v6BI86os025269; Tue, 11 Jul 2017 15:08:06 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 15:07:55 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170711180755.21017-1-danielhb@linux.vnet.ibm.com> References: <20170711180755.21017-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17071118-0028-0000-0000-000001CA2D78 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071118-0029-0000-0000-000014CC61F1 Message-Id: <20170711180755.21017-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-11_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707110290 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v15] migration: spapr: migrate pending_events of spapr state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. To achieve the minimal VMSD possible to migrate the pending_events list, this patch makes the changes in spapr_events.c: - 'log_type' of sPAPREventLogEntry struct deleted. This information can be derived by inspecting the rtas_error_log summary field. A new function called 'spapr_event_log_entry_type' was added to retrieve the type of a given sPAPREventLogEntry. - sPAPREventLogEntry, epow_log_full and hp_log_full were redesigned. The only data we're going to migrate in the VMSD is the event log data itself, which can be divided in two parts: a rtas_error_log header and an extended event log field. The rtas_error_log header contains information about the size of the extended log field, which can be used inside VMSD as the size parameter of the VBUFFER_ALOC field that will store it. To allow this use, the header.extended_length field must be exposed inline to the VMSD instead of embedded into a 'data' field that holds everything. With this in mind, the following changes were done: * a new 'header' field was added to sPAPREventLogEntry. This field hold= s a a struct rtas_error_log inline. * the declaration of the 'rtas_error_log' struct was moved to spapr.h to be visible to the VMSD macros. * 'data' field of sPAPREventLogEntry was renamed to 'extended_log' and now holds only the contents of the extended event log. * 'struct rtas_error_log hdr' were taken away from both epow_log_full and hp_log_full. This information is now available at the header field of sPAPREventLogEntry. * epow_log_full and hp_log_full were renamed to epow_extended_log and hp_extended_log respectively. This rename makes it clearer to understand the new purpose of both structures: hold the information of an extended event log field. * spapr_powerdown_req and spapr_hotplug_req_event now creates a sPAPREventLogEntry structure that contains the full rtas log entry. * rtas_event_log_queue and rtas_event_log_dequeue now receives a sPAPREventLogEntry pointer as a parameter instead of a void pointer. - the endianess of the sPAPREventLogEntry header is now native instead of be32. We can use the fields in native endianess internally and write them in be32 in the guest physical memory inside 'check_exception'. This allows the VMSD inside spapr.c to read the correct size of the entended_log field. - inside spapr.c, pending_events is put in a subsection in the spapr state VMSD to make sure migration across different versions is not broken. A small change in rtas_event_log_queue and rtas_event_log_dequeue were also made: instead of calling qdev_get_machine(), both functions now receive a pointer to the sPAPRMachineState. This pointer is already available in the callers of these functions and we don't need to waste resources calling qdev() again. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 32 +++++++++++++++ hw/ppc/spapr_events.c | 103 +++++++++++++++++++++++++++------------------= ---- include/hw/ppc/spapr.h | 9 ++++- 3 files changed, 96 insertions(+), 48 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f4e011c..b3664e3 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1517,6 +1517,37 @@ static bool version_before_3(void *opaque, int versi= on_id) return version_id < 3; } =20 +static bool spapr_pending_events_needed(void *opaque) +{ + sPAPRMachineState *spapr =3D (sPAPRMachineState *)opaque; + return !QTAILQ_EMPTY(&spapr->pending_events); +} + +static const VMStateDescription vmstate_spapr_event_entry =3D { + .name =3D "spapr_event_log_entry", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(header.summary, sPAPREventLogEntry), + VMSTATE_UINT32(header.extended_length, sPAPREventLogEntry), + VMSTATE_VBUFFER_ALLOC_UINT32(extended_log, sPAPREventLogEntry, 0, + NULL, header.extended_length), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_spapr_pending_events =3D { + .name =3D "spapr_pending_events", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D spapr_pending_events_needed, + .fields =3D (VMStateField[]) { + VMSTATE_QTAILQ_V(pending_events, sPAPRMachineState, 1, + vmstate_spapr_event_entry, sPAPREventLogEntry, ne= xt), + VMSTATE_END_OF_LIST() + }, +}; + static bool spapr_ov5_cas_needed(void *opaque) { sPAPRMachineState *spapr =3D opaque; @@ -1615,6 +1646,7 @@ static const VMStateDescription vmstate_spapr =3D { .subsections =3D (const VMStateDescription*[]) { &vmstate_spapr_ov5_cas, &vmstate_spapr_patb_entry, + &vmstate_spapr_pending_events, NULL } }; diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 587a3da..41e50d8 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -42,8 +42,7 @@ #include "hw/ppc/spapr_ovec.h" #include =20 -struct rtas_error_log { - uint32_t summary; +/* Macros related to rtas_error_log struct defined in spapr.h */ #define RTAS_LOG_VERSION_MASK 0xff000000 #define RTAS_LOG_VERSION_6 0x06000000 #define RTAS_LOG_SEVERITY_MASK 0x00e00000 @@ -85,8 +84,6 @@ struct rtas_error_log { #define RTAS_LOG_TYPE_ECC_CORR 0x0000000a #define RTAS_LOG_TYPE_EPOW 0x00000040 #define RTAS_LOG_TYPE_HOTPLUG 0x000000e5 - uint32_t extended_length; -} QEMU_PACKED; =20 struct rtas_event_log_v6 { uint8_t b0; @@ -166,8 +163,7 @@ struct rtas_event_log_v6_epow { uint64_t reason_code; } QEMU_PACKED; =20 -struct epow_log_full { - struct rtas_error_log hdr; +struct epow_extended_log { struct rtas_event_log_v6 v6hdr; struct rtas_event_log_v6_maina maina; struct rtas_event_log_v6_mainb mainb; @@ -205,8 +201,7 @@ struct rtas_event_log_v6_hp { union drc_identifier drc_id; } QEMU_PACKED; =20 -struct hp_log_full { - struct rtas_error_log hdr; +struct hp_extended_log { struct rtas_event_log_v6 v6hdr; struct rtas_event_log_v6_maina maina; struct rtas_event_log_v6_mainb mainb; @@ -341,25 +336,26 @@ static int rtas_event_log_to_irq(sPAPRMachineState *s= papr, int log_type) return source->irq; } =20 -static void rtas_event_log_queue(int log_type, void *data) +static uint32_t spapr_event_log_entry_type(sPAPREventLogEntry *entry) { - sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); - sPAPREventLogEntry *entry =3D g_new(sPAPREventLogEntry, 1); + return entry->header.summary & RTAS_LOG_TYPE_MASK; +} =20 - g_assert(data); - entry->log_type =3D log_type; - entry->data =3D data; +static void rtas_event_log_queue(sPAPRMachineState *spapr, + sPAPREventLogEntry *entry) +{ QTAILQ_INSERT_TAIL(&spapr->pending_events, entry, next); } =20 -static sPAPREventLogEntry *rtas_event_log_dequeue(uint32_t event_mask) +static sPAPREventLogEntry *rtas_event_log_dequeue(sPAPRMachineState *spapr, + uint32_t event_mask) { - sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); sPAPREventLogEntry *entry =3D NULL; =20 QTAILQ_FOREACH(entry, &spapr->pending_events, next) { const sPAPREventSource *source =3D - rtas_event_log_to_source(spapr, entry->log_type); + rtas_event_log_to_source(spapr, + spapr_event_log_entry_type(entry)); =20 if (source->mask & event_mask) { break; @@ -380,7 +376,8 @@ static bool rtas_event_log_contains(uint32_t event_mask) =20 QTAILQ_FOREACH(entry, &spapr->pending_events, next) { const sPAPREventSource *source =3D - rtas_event_log_to_source(spapr, entry->log_type); + rtas_event_log_to_source(spapr, + spapr_event_log_entry_type(entry)); =20 if (source->mask & event_mask) { return true; @@ -428,27 +425,32 @@ static void spapr_init_maina(struct rtas_event_log_v6= _maina *maina, static void spapr_powerdown_req(Notifier *n, void *opaque) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); + sPAPREventLogEntry *entry; struct rtas_error_log *hdr; struct rtas_event_log_v6 *v6hdr; struct rtas_event_log_v6_maina *maina; struct rtas_event_log_v6_mainb *mainb; struct rtas_event_log_v6_epow *epow; - struct epow_log_full *new_epow; + struct epow_extended_log *new_epow; =20 + entry =3D g_new(sPAPREventLogEntry, 1); new_epow =3D g_malloc0(sizeof(*new_epow)); - hdr =3D &new_epow->hdr; + g_assert(entry); + g_assert(new_epow); + entry->extended_log =3D new_epow; + + hdr =3D &entry->header; v6hdr =3D &new_epow->v6hdr; maina =3D &new_epow->maina; mainb =3D &new_epow->mainb; epow =3D &new_epow->epow; =20 - hdr->summary =3D 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 =3D cpu_to_be32(sizeof(*new_epow) - - sizeof(new_epow->hdr)); + hdr->summary =3D 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 =3D sizeof(*new_epow); =20 spapr_init_v6hdr(v6hdr); spapr_init_maina(maina, 3 /* Main-A, Main-B and EPOW */); @@ -468,7 +470,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaq= ue) epow->event_modifier =3D RTAS_LOG_V6_EPOW_MODIFIER_NORMAL; epow->extended_modifier =3D RTAS_LOG_V6_EPOW_XMODIFIER_PARTITION_SPECI= FIC; =20 - rtas_event_log_queue(RTAS_LOG_TYPE_EPOW, new_epow); + rtas_event_log_queue(spapr, entry); =20 qemu_irq_pulse(xics_get_qirq(XICS_FABRIC(spapr), rtas_event_log_to_irq(spapr, @@ -480,28 +482,33 @@ static void spapr_hotplug_req_event(uint8_t hp_id, ui= nt8_t hp_action, union drc_identifier *drc_id) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); - struct hp_log_full *new_hp; + sPAPREventLogEntry *entry; + struct hp_extended_log *new_hp; struct rtas_error_log *hdr; struct rtas_event_log_v6 *v6hdr; struct rtas_event_log_v6_maina *maina; struct rtas_event_log_v6_mainb *mainb; struct rtas_event_log_v6_hp *hp; =20 - new_hp =3D g_malloc0(sizeof(struct hp_log_full)); - hdr =3D &new_hp->hdr; + entry =3D g_new(sPAPREventLogEntry, 1); + new_hp =3D g_malloc0(sizeof(struct hp_extended_log)); + g_assert(entry); + g_assert(new_hp); + entry->extended_log =3D new_hp; + + hdr =3D &entry->header; v6hdr =3D &new_hp->v6hdr; maina =3D &new_hp->maina; mainb =3D &new_hp->mainb; hp =3D &new_hp->hp; =20 - hdr->summary =3D 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 =3D cpu_to_be32(sizeof(*new_hp) - - sizeof(new_hp->hdr)); + hdr->summary =3D 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 =3D sizeof(*new_hp); =20 spapr_init_v6hdr(v6hdr); spapr_init_maina(maina, 3 /* Main-A, Main-B, HP */); @@ -551,7 +558,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint= 8_t hp_action, cpu_to_be32(drc_id->count_indexed.index); } =20 - rtas_event_log_queue(RTAS_LOG_TYPE_HOTPLUG, new_hp); + rtas_event_log_queue(spapr, entry); =20 qemu_irq_pulse(xics_get_qirq(XICS_FABRIC(spapr), rtas_event_log_to_irq(spapr, @@ -625,10 +632,10 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMac= hineState *spapr, target_ulong args, uint32_t nret, target_ulong rets) { + CPUState *cs =3D CPU(cpu); uint32_t mask, buf, len, event_len; uint64_t xinfo; sPAPREventLogEntry *event; - struct rtas_error_log *hdr; int i; =20 if ((nargs < 6) || (nargs > 7) || nret !=3D 1) { @@ -644,21 +651,25 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMac= hineState *spapr, xinfo |=3D (uint64_t)rtas_ld(args, 6) << 32; } =20 - event =3D rtas_event_log_dequeue(mask); + event =3D rtas_event_log_dequeue(spapr, mask); if (!event) { goto out_no_events; } =20 - hdr =3D event->data; - event_len =3D be32_to_cpu(hdr->extended_length) + sizeof(*hdr); + event_len =3D event->header.extended_length + sizeof(event->header); =20 if (event_len < len) { len =3D event_len; } =20 - cpu_physical_memory_write(buf, event->data, len); + stl_be_phys(cs->as, buf, event->header.summary); + stl_be_phys(cs->as, buf + sizeof(event->header.summary), + event->header.extended_length); + cpu_physical_memory_write(buf + sizeof(event->header), + event->extended_log, + event->header.extended_length); rtas_st(rets, 0, RTAS_OUT_SUCCESS); - g_free(event->data); + g_free(event->extended_log); g_free(event); =20 /* according to PAPR+, the IRQ must be left asserted, or re-asserted, = if diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index a184ffa..48a2cad 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -601,9 +601,14 @@ struct sPAPRTCETable { =20 sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn); =20 +struct rtas_error_log { + uint32_t summary; + uint32_t extended_length; +} QEMU_PACKED; + struct sPAPREventLogEntry { - int log_type; - void *data; + struct rtas_error_log header; + void *extended_log; QTAILQ_ENTRY(sPAPREventLogEntry) next; }; =20 --=20 2.9.4