From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819718111967.9600021836854; Fri, 30 Jun 2017 03:48:38 -0700 (PDT) Received: from localhost ([::1]:43643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtTY-0001Gh-DS for importer@patchew.org; Fri, 30 Jun 2017 06:48:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRh-0008Rt-2W for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRg-0007s0-0r for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:41 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:49107) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRf-0007qb-JD; Fri, 30 Jun 2017 06:46:39 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9m4QVbz9sNc; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819596; bh=GubPaFE8CDhwE7qba+KrBzdcWhKJFDXaLiLuUvkB+Pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mNbWYp0vFOlFTMzCo1ifbbHkFNbpoFUN4SW9NGARHtkO8tSxsY9SBafRXbn5RFOuW /okH8UQpoHOBCiYbVVPl/NSuzHbv6pIqGDKskZjSlXCovVH/mOJ89MNmzxDultyEyz GAJLB19mGmAGGkaTzAaYDYZvvwiQakVQnUKVUS5s= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:12 +1000 Message-Id: <20170630104632.27942-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 01/21] hw/ppc/prep: Remove superfluous call to soundhw_init() 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Thomas Huth When using the 40p machine, soundhw_init() is currently called twice, one time from vl.c and one time from ibm_40p_init(). The call in ibm_40p_init() was likely just a copy-and-paste from a old version of the prep machine - but there the call to audio_init() (which was the previous name of this function) has been removed many years ago already, with commit b3e6d591b05538056d665572f3e3bbfb3cbb70e7 ("audio: enable PCI audio cards for all PCI-enabled targets"), so we certainly also do not need the soundhw_init() in the 40p function anymore nowadays. Signed-off-by: Thomas Huth Reviewed-by: Sahid Ferdjaoui Reviewed-by: Eduardo Habkost Reviewed-by: Herv=C3=A9 Poussineau Signed-off-by: David Gibson --- hw/ppc/prep.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index d16646c..36d3dcd 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -36,7 +36,6 @@ #include "hw/pci/pci_host.h" #include "hw/ppc/ppc.h" #include "hw/boards.h" -#include "hw/audio/soundhw.h" #include "qemu/error-report.h" #include "qemu/log.h" #include "hw/ide.h" @@ -782,9 +781,6 @@ static void ibm_40p_init(MachineState *machine) qbus_walk_children(BUS(isa_bus), prep_set_cmos_checksum, NULL, NULL, N= ULL, &cmos_checksum); =20 - /* initialize audio subsystem */ - soundhw_init(); - /* add some more devices */ if (defaults_enabled()) { isa_create_simple(isa_bus, "i8042"); --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819717851275.6247094387413; Fri, 30 Jun 2017 03:48:37 -0700 (PDT) Received: from localhost ([::1]:43642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtTW-0001FU-7E for importer@patchew.org; Fri, 30 Jun 2017 06:48:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRh-0008Ru-2k for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRg-0007sK-2P for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:41 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:48171) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRf-0007qX-Kj; Fri, 30 Jun 2017 06:46:39 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9m2Br4z9s87; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819596; bh=kVCrb2llVKUAVIcNDAAuMlRmeuN5LulRxlx9RU+4+Gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nmkq93HBAkT+hlf7Up7/nV55UVKWT1RqIldbg2wrpseB3h2c/tjXVZsO7aeUA5suv l/Gw+CT487jx0lStzDa42JTEM2EU9kRz0FICJMfMGKrqFbVkOiAk7wNSs2lmLOKGKn v5OcCx/JxdVlNZVFlOnmhtJweOQ2Chs2O9CNkGA0= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:13 +1000 Message-Id: <20170630104632.27942-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 02/21] qapi: add explicit null to string input and output visitors 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, Greg Kurz , qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Greg Kurz This may be used for deprecated object properties that are kept for backwards compatibility. Signed-off-by: Greg Kurz Reviewed-by: Markus Armbruster Tested-by: Andrea Bolognani Signed-off-by: David Gibson --- qapi/string-input-visitor.c | 11 +++++++++++ qapi/string-output-visitor.c | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index c089491..63ae115 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -326,6 +326,16 @@ static void parse_type_number(Visitor *v, const char *= name, double *obj, *obj =3D val; } =20 +static void parse_type_null(Visitor *v, const char *name, Error **errp) +{ + StringInputVisitor *siv =3D to_siv(v); + + if (!siv->string || siv->string[0]) { + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "null"); + } +} + static void string_input_free(Visitor *v) { StringInputVisitor *siv =3D to_siv(v); @@ -349,6 +359,7 @@ Visitor *string_input_visitor_new(const char *str) v->visitor.type_bool =3D parse_type_bool; v->visitor.type_str =3D parse_type_str; v->visitor.type_number =3D parse_type_number; + v->visitor.type_null =3D parse_type_null; v->visitor.start_list =3D start_list; v->visitor.next_list =3D next_list; v->visitor.check_list =3D check_list; diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 53c2175..af649e1 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -256,6 +256,19 @@ static void print_type_number(Visitor *v, const char *= name, double *obj, string_output_set(sov, g_strdup_printf("%f", *obj)); } =20 +static void print_type_null(Visitor *v, const char *name, Error **errp) +{ + StringOutputVisitor *sov =3D to_sov(v); + char *out; + + if (sov->human) { + out =3D g_strdup(""); + } else { + out =3D g_strdup(""); + } + string_output_set(sov, out); +} + static void start_list(Visitor *v, const char *name, GenericList **list, size_t size, Error **errp) @@ -341,6 +354,7 @@ Visitor *string_output_visitor_new(bool human, char **r= esult) v->visitor.type_bool =3D print_type_bool; v->visitor.type_str =3D print_type_str; v->visitor.type_number =3D print_type_number; + v->visitor.type_null =3D print_type_null; v->visitor.start_list =3D start_list; v->visitor.next_list =3D next_list; v->visitor.end_list =3D end_list; --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820372079214.0258880571139; Fri, 30 Jun 2017 03:59:32 -0700 (PDT) Received: from localhost ([::1]:43696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQte6-0003Fp-41 for importer@patchew.org; Fri, 30 Jun 2017 06:59:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRj-0008S8-5y for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRg-0007sC-1M for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:43 -0400 Received: from ozlabs.org ([103.22.144.67]:52427) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRf-0007qY-8M; Fri, 30 Jun 2017 06:46:39 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9m3Kw6z9sNZ; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819596; bh=CMl6mOjOtzZxlTqlzC4mXp4x1b+T0Yep3R4s+tY8sA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZRGnxP2lihhWCzRF4qbPCdbQBhmqPyT0UZccGcJaaYSJ5YkwV0thzFa0aFPVPf2s zr6ot7N2ZO8lTUywXQyHNbAX4u2AXc+I5JhqED8r5pQ1CJIjqOx765B/omJ28g2IDg Gt/KvuXhfQMIOLE7ZcUO6sFnb/zBLW4mn/XHnqb8= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:14 +1000 Message-Id: <20170630104632.27942-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 03/21] pseries: Move CPU compatibility property to machine 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Server class POWER CPUs have a "compat" property, which is used to set the backwards compatibility mode for the processor. However, this only makes sense for machine types which don't give the guest access to hypervisor privilege - otherwise the compatibility level is under the guest's control. To reflect this, this removes the CPU 'compat' property and instead creates a 'max-cpu-compat' property on the pseries machine. Strictly speaking this breaks compatibility, but AFAIK the 'compat' option was never (directly) used with -device or device_add. The option was used with -cpu. So, to maintain compatibility, this patch adds a hack to the cpu option parsing to strip out any compat options supplied with -cpu and set them on the machine property instead of the now deprecated cpu property. Signed-off-by: David Gibson Tested-by: Suraj Jitindar Singh Reviewed-by: Greg Kurz Tested-by: Greg Kurz Tested-by: Andrea Bolognani --- hw/ppc/spapr.c | 6 ++- hw/ppc/spapr_cpu_core.c | 55 +++++++++++++++++++++++- hw/ppc/spapr_hcall.c | 8 ++-- include/hw/ppc/spapr.h | 12 ++++-- target/ppc/compat.c | 102 ++++++++++++++++++++++++++++++++++++++++= ++++ target/ppc/cpu.h | 5 ++- target/ppc/translate_init.c | 86 +++++++++++-------------------------- 7 files changed, 201 insertions(+), 73 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ea44358..67d4c13 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2131,7 +2131,7 @@ static void ppc_spapr_init(MachineState *machine) machine->cpu_model =3D kvm_enabled() ? "host" : smc->tcg_default_c= pu; } =20 - ppc_cpu_parse_features(machine->cpu_model); + spapr_cpu_parse_features(spapr); =20 spapr_init_cpus(spapr); =20 @@ -2503,6 +2503,10 @@ static void spapr_machine_initfn(Object *obj) " place of standard EPOW events when p= ossible" " (required for memory hot-unplug supp= ort)", NULL); + + ppc_compat_add_property(obj, "max-cpu-compat", &spapr->max_compat_pvr, + "Maximum permitted CPU compatibility mode", + &error_fatal); } =20 static void spapr_machine_finalizefn(Object *obj) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 9fb896b..97472fd 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -20,6 +20,57 @@ #include "sysemu/numa.h" #include "qemu/error-report.h" =20 +void spapr_cpu_parse_features(sPAPRMachineState *spapr) +{ + /* + * Backwards compatibility hack: + * + * CPUs had a "compat=3D" property which didn't make sense for + * anything except pseries. It was replaced by "max-cpu-compat" + * machine option. This supports old command lines like + * -cpu POWER8,compat=3Dpower7 + * By stripping the compat option and applying it to the machine + * before passing it on to the cpu level parser. + */ + gchar **inpieces; + int i, j; + gchar *compat_str =3D NULL; + + inpieces =3D g_strsplit(MACHINE(spapr)->cpu_model, ",", 0); + + /* inpieces[0] is the actual model string */ + i =3D 1; + j =3D 1; + while (inpieces[i]) { + if (g_str_has_prefix(inpieces[i], "compat=3D")) { + /* in case of multiple compat=3D options */ + g_free(compat_str); + compat_str =3D inpieces[i]; + } else { + j++; + } + + i++; + /* Excise compat options from list */ + inpieces[j] =3D inpieces[i]; + } + + if (compat_str) { + char *val =3D compat_str + strlen("compat=3D"); + gchar *newprops =3D g_strjoinv(",", inpieces); + + object_property_set_str(OBJECT(spapr), val, "max-cpu-compat", + &error_fatal); + + ppc_cpu_parse_features(newprops); + g_free(newprops); + } else { + ppc_cpu_parse_features(MACHINE(spapr)->cpu_model); + } + + g_strfreev(inpieces); +} + static void spapr_cpu_reset(void *opaque) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); @@ -67,10 +118,10 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, P= owerPCCPU *cpu, /* Enable PAPR mode in TCG or KVM */ cpu_ppc_set_papr(cpu, PPC_VIRTUAL_HYPERVISOR(spapr)); =20 - if (cpu->max_compat) { + if (spapr->max_compat_pvr) { Error *local_err =3D NULL; =20 - ppc_set_compat(cpu, cpu->max_compat, &local_err); + ppc_set_compat(cpu, spapr->max_compat_pvr, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index aa1ffea..8624ce8 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1045,11 +1045,11 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *= cpu, } } =20 -static uint32_t cas_check_pvr(PowerPCCPU *cpu, target_ulong *addr, - Error **errp) +static uint32_t cas_check_pvr(sPAPRMachineState *spapr, PowerPCCPU *cpu, + target_ulong *addr, Error **errp) { bool explicit_match =3D false; /* Matched the CPU's real PVR */ - uint32_t max_compat =3D cpu->max_compat; + uint32_t max_compat =3D spapr->max_compat_pvr; uint32_t best_compat =3D 0; int i; =20 @@ -1105,7 +1105,7 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, bool guest_radix; Error *local_err =3D NULL; =20 - cas_pvr =3D cas_check_pvr(cpu, &addr, &local_err); + cas_pvr =3D cas_check_pvr(spapr, cpu, &addr, &local_err); if (local_err) { error_report_err(local_err); return H_HARDWARE; diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index f973b02..2ddb052 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -86,16 +86,19 @@ struct sPAPRMachineState { uint64_t rtc_offset; /* Now used only during incoming migration */ struct PPCTimebase tb; bool has_graphics; - sPAPROptionVector *ov5; /* QEMU-supported option vectors */ - sPAPROptionVector *ov5_cas; /* negotiated (via CAS) option vectors= */ - bool cas_reboot; - bool cas_legacy_guest_workaround; =20 Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events; bool use_hotplug_event_source; sPAPREventSource *event_sources; =20 + /* ibm,client-architecture-support option negotiation */ + bool cas_reboot; + bool cas_legacy_guest_workaround; + sPAPROptionVector *ov5; /* QEMU-supported option vectors */ + sPAPROptionVector *ov5_cas; /* negotiated (via CAS) option vectors= */ + uint32_t max_compat_pvr; + /* Migration state */ int htab_save_index; bool htab_first_pass; @@ -635,6 +638,7 @@ void spapr_hotplug_req_add_by_count_indexed(sPAPRDRConn= ectorType drc_type, uint32_t count, uint32_t index= ); void spapr_hotplug_req_remove_by_count_indexed(sPAPRDRConnectorType drc_ty= pe, uint32_t count, uint32_t in= dex); +void spapr_cpu_parse_features(sPAPRMachineState *spapr); void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset, sPAPRMachineState *spapr); =20 diff --git a/target/ppc/compat.c b/target/ppc/compat.c index e8ec1e1..f1b67fa 100644 --- a/target/ppc/compat.c +++ b/target/ppc/compat.c @@ -24,9 +24,11 @@ #include "sysemu/cpus.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "cpu-models.h" =20 typedef struct { + const char *name; uint32_t pvr; uint64_t pcr; uint64_t pcr_level; @@ -38,6 +40,7 @@ static const CompatInfo compat_table[] =3D { * Ordered from oldest to newest - the code relies on this */ { /* POWER6, ISA2.05 */ + .name =3D "power6", .pvr =3D CPU_POWERPC_LOGICAL_2_05, .pcr =3D PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 | PCR_COMPAT_2_05 | PCR_TM_DIS | PCR_VSX_DIS, @@ -45,24 +48,28 @@ static const CompatInfo compat_table[] =3D { .max_threads =3D 2, }, { /* POWER7, ISA2.06 */ + .name =3D "power7", .pvr =3D CPU_POWERPC_LOGICAL_2_06, .pcr =3D PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 | PCR= _TM_DIS, .pcr_level =3D PCR_COMPAT_2_06, .max_threads =3D 4, }, { + .name =3D "power7+", .pvr =3D CPU_POWERPC_LOGICAL_2_06_PLUS, .pcr =3D PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 | PCR= _TM_DIS, .pcr_level =3D PCR_COMPAT_2_06, .max_threads =3D 4, }, { /* POWER8, ISA2.07 */ + .name =3D "power8", .pvr =3D CPU_POWERPC_LOGICAL_2_07, .pcr =3D PCR_COMPAT_3_00 | PCR_COMPAT_2_07, .pcr_level =3D PCR_COMPAT_2_07, .max_threads =3D 8, }, { /* POWER9, ISA3.00 */ + .name =3D "power9", .pvr =3D CPU_POWERPC_LOGICAL_3_00, .pcr =3D PCR_COMPAT_3_00, .pcr_level =3D PCR_COMPAT_3_00, @@ -189,3 +196,98 @@ int ppc_compat_max_threads(PowerPCCPU *cpu) =20 return n_threads; } + +static void ppc_compat_prop_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + uint32_t compat_pvr =3D *((uint32_t *)opaque); + const char *value; + + if (!compat_pvr) { + value =3D ""; + } else { + const CompatInfo *compat =3D compat_by_pvr(compat_pvr); + + g_assert(compat); + + value =3D compat->name; + } + + visit_type_str(v, name, (char **)&value, errp); +} + +static void ppc_compat_prop_set(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Error *local_err =3D NULL; + char *value; + uint32_t compat_pvr; + + visit_type_str(v, name, &value, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (strcmp(value, "") =3D=3D 0) { + compat_pvr =3D 0; + } else { + int i; + const CompatInfo *compat =3D NULL; + + for (i =3D 0; i < ARRAY_SIZE(compat_table); i++) { + if (strcmp(value, compat_table[i].name) =3D=3D 0) { + compat =3D &compat_table[i]; + break; + + } + } + + if (!compat) { + error_setg(errp, "Invalid compatibility mode \"%s\"", value); + goto out; + } + compat_pvr =3D compat->pvr; + } + + *((uint32_t *)opaque) =3D compat_pvr; + +out: + g_free(value); +} + +void ppc_compat_add_property(Object *obj, const char *name, + uint32_t *compat_pvr, const char *basedesc, + Error **errp) +{ + Error *local_err =3D NULL; + gchar *namesv[ARRAY_SIZE(compat_table) + 1]; + gchar *names, *desc; + int i; + + object_property_add(obj, name, "string", + ppc_compat_prop_get, ppc_compat_prop_set, NULL, + compat_pvr, &local_err); + if (local_err) { + goto out; + } + + for (i =3D 0; i < ARRAY_SIZE(compat_table); i++) { + /* + * Have to discard const here, because g_strjoinv() takes + * (gchar **), not (const gchar **) :( + */ + namesv[i] =3D (gchar *)compat_table[i].name; + } + namesv[ARRAY_SIZE(compat_table)] =3D NULL; + + names =3D g_strjoinv(", ", namesv); + desc =3D g_strdup_printf("%s. Valid values are %s.", basedesc, names); + object_property_set_description(obj, name, desc, &local_err); + + g_free(names); + g_free(desc); + +out: + error_propagate(errp, local_err); +} diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index d10808d..09393e6 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1189,7 +1189,6 @@ typedef struct PPCVirtualHypervisorClass PPCVirtualHy= pervisorClass; * PowerPCCPU: * @env: #CPUPPCState * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too - * @max_compat: Maximal supported logical PVR from the command line * @compat_pvr: Current logical PVR, zero if in "raw" mode * * A PowerPC CPU. @@ -1201,7 +1200,6 @@ struct PowerPCCPU { =20 CPUPPCState env; int cpu_dt_id; - uint32_t max_compat; uint32_t compat_pvr; PPCVirtualHypervisor *vhyp; Object *intc; @@ -1375,6 +1373,9 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_= pvr, Error **errp); void ppc_set_compat_all(uint32_t compat_pvr, Error **errp); #endif int ppc_compat_max_threads(PowerPCCPU *cpu); +void ppc_compat_add_property(Object *obj, const char *name, + uint32_t *compat_pvr, const char *basedesc, + Error **errp); #endif /* defined(TARGET_PPC64) */ =20 #include "exec/cpu-all.h" diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index 56a0ab2..e837cd2 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -33,6 +33,7 @@ #include "hw/qdev-properties.h" #include "hw/ppc/ppc.h" #include "mmu-book3s-v3.h" +#include "sysemu/qtest.h" =20 //#define PPC_DUMP_CPU //#define PPC_DEBUG_SPR @@ -8413,73 +8414,38 @@ POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data) pcc->l1_icache_size =3D 0x10000; } =20 -static void powerpc_get_compat(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - char *value =3D (char *)""; - Property *prop =3D opaque; - uint32_t *max_compat =3D qdev_get_prop_ptr(DEVICE(obj), prop); - - switch (*max_compat) { - case CPU_POWERPC_LOGICAL_2_05: - value =3D (char *)"power6"; - break; - case CPU_POWERPC_LOGICAL_2_06: - value =3D (char *)"power7"; - break; - case CPU_POWERPC_LOGICAL_2_07: - value =3D (char *)"power8"; - break; - case 0: - break; - default: - error_report("Internal error: compat is set to %x", *max_compat); - abort(); - break; - } - - visit_type_str(v, name, &value, errp); -} - -static void powerpc_set_compat(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) +/* + * The CPU used to have a "compat" property which set the + * compatibility mode PVR. However, this was conceptually broken - it + * only makes sense on the pseries machine type (otherwise the guest + * owns the PCR and can control the compatibility mode itself). It's + * been replaced with the 'max-cpu-compat' property on the pseries + * machine type. For backwards compatibility, pseries specially + * parses the -cpu parameter and converts old compat=3D parameters into + * the appropriate machine parameters. This stub implementation of + * the parameter catches any uses on explicitly created CPUs. + */ +static void getset_compat_deprecated(Object *obj, Visitor *v, const char *= name, + void *opaque, Error **errp) { - Error *error =3D NULL; - char *value =3D NULL; - Property *prop =3D opaque; - uint32_t *max_compat =3D qdev_get_prop_ptr(DEVICE(obj), prop); - - visit_type_str(v, name, &value, &error); - if (error) { - error_propagate(errp, error); - return; - } - - if (strcmp(value, "power6") =3D=3D 0) { - *max_compat =3D CPU_POWERPC_LOGICAL_2_05; - } else if (strcmp(value, "power7") =3D=3D 0) { - *max_compat =3D CPU_POWERPC_LOGICAL_2_06; - } else if (strcmp(value, "power8") =3D=3D 0) { - *max_compat =3D CPU_POWERPC_LOGICAL_2_07; - } else { - error_setg(errp, "Invalid compatibility mode \"%s\"", value); + if (!qtest_enabled()) { + error_report("CPU 'compat' property is deprecated and has no effec= t; " + "use max-cpu-compat machine property instead"); } - - g_free(value); + visit_type_null(v, name, NULL); } =20 -static PropertyInfo powerpc_compat_propinfo =3D { +static PropertyInfo ppc_compat_deprecated_propinfo =3D { .name =3D "str", - .description =3D "compatibility mode, power6/power7/power8", - .get =3D powerpc_get_compat, - .set =3D powerpc_set_compat, + .description =3D "compatibility mode (deprecated)", + .get =3D getset_compat_deprecated, + .set =3D getset_compat_deprecated, }; - -#define DEFINE_PROP_POWERPC_COMPAT(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, powerpc_compat_propinfo, uint32_t) - static Property powerpc_servercpu_properties[] =3D { - DEFINE_PROP_POWERPC_COMPAT("compat", PowerPCCPU, max_compat), + { + .name =3D "compat", + .info =3D &ppc_compat_deprecated_propinfo, + }, DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820081391926.5864404973197; Fri, 30 Jun 2017 03:54:41 -0700 (PDT) Received: from localhost ([::1]:43670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtZP-0007Ar-V0 for importer@patchew.org; Fri, 30 Jun 2017 06:54:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRl-0008Td-Al for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007vV-Df for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:45 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:52165) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRj-0007sj-0E; Fri, 30 Jun 2017 06:46:43 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9m6X7mz9sPN; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819596; bh=T0d0JECuXMwvQC08D5IMtoyvwpzfqxxyuJ6DF85G4Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hHqNI1vD7zj+4NY6HcrPIPglKU34oFLrzO0rVzq1BZ+RoDajdTH8XDv1/upMAIaq9 qCFPTc6GKYx2NQu+WzOitq1//X5O/6cHbbo1Vm3PNoyDAzaw//s77kBYM8w4SleEBH SSAjbAog01r/roKz3oRJtl1BfD1MhyzFa28jDNks= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:15 +1000 Message-Id: <20170630104632.27942-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 04/21] pseries: Reset CPU compatibility mode 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, the CPU compatibility mode is set when the cpu is initialized, then again when the guest negotiates features. This means if a guest negotiates a compatibility mode, then reboots, that compatibility mode will be retained across the reset. Usually that will get overridden when features are negotiated on the next boot, but it's still not really correct. This patch moves the initial set up of the compatibility mode from cpu init to reset time. The mode *is* retained if the reboot was caused by the feature negotiation (it might be important in that case, though it's unlikely). Signed-off-by: David Gibson Reviewed-by: Alexey Kardashevskiy Reviewed-by: Michael Roth Tested-by: Andrea Bolognani --- hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_cpu_core.c | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 67d4c13..81007b9 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1346,6 +1346,8 @@ static void ppc_spapr_reset(void) if (!spapr->cas_reboot) { spapr_ovec_cleanup(spapr->ov5_cas); spapr->ov5_cas =3D spapr_ovec_new(); + + ppc_set_compat_all(spapr->max_compat_pvr, &error_fatal); } =20 fdt =3D spapr_build_fdt(spapr, rtas_addr, spapr->rtas_size); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 97472fd..d6719d5 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -118,16 +118,6 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, P= owerPCCPU *cpu, /* Enable PAPR mode in TCG or KVM */ cpu_ppc_set_papr(cpu, PPC_VIRTUAL_HYPERVISOR(spapr)); =20 - if (spapr->max_compat_pvr) { - Error *local_err =3D NULL; - - ppc_set_compat(cpu, spapr->max_compat_pvr, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - } - qemu_register_reset(spapr_cpu_reset, cpu); spapr_cpu_reset(cpu); } --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820214534821.5153387631951; Fri, 30 Jun 2017 03:56:54 -0700 (PDT) Received: from localhost ([::1]:43681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtbY-0000U9-PT for importer@patchew.org; Fri, 30 Jun 2017 06:56:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRj-0008S6-4v for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRg-0007s6-1G for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:43 -0400 Received: from ozlabs.org ([103.22.144.67]:36635) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRf-0007qj-8K; Fri, 30 Jun 2017 06:46:39 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9m53Tyz9s9Y; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819596; bh=mj4ArQsRgIp4y9fQhqcjznWIo9IEtdULINx4t7Emb5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JQYbXjedFdf37Vl8aBUlt9G3TToXYgbspqNyZMl3nVLDWc82xZqnojby0OaX3axeL 2G3JQ7cXeR81rfTnSoRM1c69W8bDGke+/IhX6UPTK+Z4RWBv6i4wK2tEdaKb4UuhRh oOICUZEEd3kTJYx7JAnLZ49w1GoRb1xEZz9REpsg= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:16 +1000 Message-Id: <20170630104632.27942-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 05/21] ppc: Rework CPU compatibility testing across migration 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, Greg Kurz , qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Migrating between different CPU versions is a bit complicated for ppc. A long time ago, we ensured identical CPU versions at either end by checking the PVR had the same value. However, this breaks under KVM HV, because we always have to use the host's PVR - it's not virtualized. That would mean we couldn't migrate between hosts with different PVRs, even if the CPUs are close enough to compatible in practice (sometimes identical cores with different surrounding logic have different PVRs, so this happens in practice quite often). So, we removed the PVR check, but instead checked that several flags indicating supported instructions matched. This turns out to be a bad idea, because those instruction masks are not architected information, but essentially a TCG implementation detail. So changes to qemu internal CPU modelling can break migration - this happened between qemu-2.6 and qemu-2.7. That was addressed by 146c11f1 "target-ppc: Allow eventual removal of old migration mistakes". Now, verification of CPU compatibility across a migration basically doesn't happen. We simply ignore the PVR of the incoming migration, and hope the cpu on the destination is close enough to work. Now that we've cleaned up handling of processor compatibility modes for pseries machine type, we can do better. For new machine types (pseries-2.10+) We allow migration if: * The source and destination PVRs are for the same type of CPU, as determined by CPU class's pvr_match function OR * When the source was in a compatibility mode, and the destination CPU supports the same compatibility mode For older machine types we retain the existing behaviour - current CAS code will usually set a compat mode which would break backwards migration if we made them use the new behaviour. [Fixed from an earlier version by Greg Kurz]. Signed-off-by: David Gibson Signed-off-by: Greg Kurz Reviewed-by: Suraj Jitindar Singh Tested-by: Andrea Bolognani --- hw/ppc/spapr.c | 7 ++++- target/ppc/cpu.h | 1 + target/ppc/machine.c | 69 +++++++++++++++++++++++++++++++++++++++++= ++-- target/ppc/translate_init.c | 2 ++ 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 81007b9..52f4e72 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3362,7 +3362,12 @@ DEFINE_SPAPR_MACHINE(2_10, "2.10", true); * pseries-2.9 */ #define SPAPR_COMPAT_2_9 \ - HW_COMPAT_2_9 + HW_COMPAT_2_9 \ + { \ + .driver =3D TYPE_POWERPC_CPU, \ + .property =3D "pre-2.10-migration", \ + .value =3D "on", \ + }, \ =20 static void spapr_machine_2_9_instance_options(MachineState *machine) { diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 09393e6..6ee2a26 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1211,6 +1211,7 @@ struct PowerPCCPU { uint64_t mig_insns_flags; uint64_t mig_insns_flags2; uint32_t mig_nb_BATs; + bool pre_2_10_migration; }; =20 static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env) diff --git a/target/ppc/machine.c b/target/ppc/machine.c index 445f489..f578156 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -8,6 +8,7 @@ #include "helper_regs.h" #include "mmu-hash64.h" #include "migration/cpu.h" +#include "qapi/error.h" =20 static int cpu_load_old(QEMUFile *f, void *opaque, int version_id) { @@ -195,6 +196,27 @@ static void cpu_pre_save(void *opaque) } } =20 +/* + * Determine if a given PVR is a "close enough" match to the CPU + * object. For TCG and KVM PR it would probably be sufficient to + * require an exact PVR match. However for KVM HV the user is + * restricted to a PVR exactly matching the host CPU. The correct way + * to handle this is to put the guest into an architected + * compatibility mode. However, to allow a more forgiving transition + * and migration from before this was widely done, we allow migration + * between sufficiently similar PVRs, as determined by the CPU class's + * pvr_match() hook. + */ +static bool pvr_match(PowerPCCPU *cpu, uint32_t pvr) +{ + PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + + if (pvr =3D=3D pcc->pvr) { + return true; + } + return pcc->pvr_match(pcc, pvr); +} + static int cpu_post_load(void *opaque, int version_id) { PowerPCCPU *cpu =3D opaque; @@ -203,10 +225,31 @@ static int cpu_post_load(void *opaque, int version_id) target_ulong msr; =20 /* - * We always ignore the source PVR. The user or management - * software has to take care of running QEMU in a compatible mode. + * If we're operating in compat mode, we should be ok as long as + * the destination supports the same compatiblity mode. + * + * Otherwise, however, we require that the destination has exactly + * the same CPU model as the source. */ - env->spr[SPR_PVR] =3D env->spr_cb[SPR_PVR].default_value; + +#if defined(TARGET_PPC64) + if (cpu->compat_pvr) { + Error *local_err =3D NULL; + + ppc_set_compat(cpu, cpu->compat_pvr, &local_err); + if (local_err) { + error_report_err(local_err); + error_free(local_err); + return -1; + } + } else +#endif + { + if (!pvr_match(cpu, env->spr[SPR_PVR])) { + return -1; + } + } + env->lr =3D env->spr[SPR_LR]; env->ctr =3D env->spr[SPR_CTR]; cpu_write_xer(env, env->spr[SPR_XER]); @@ -560,6 +603,25 @@ static const VMStateDescription vmstate_tlbmas =3D { } }; =20 +static bool compat_needed(void *opaque) +{ + PowerPCCPU *cpu =3D opaque; + + assert(!(cpu->compat_pvr && !cpu->vhyp)); + return !cpu->pre_2_10_migration && cpu->compat_pvr !=3D 0; +} + +static const VMStateDescription vmstate_compat =3D { + .name =3D "cpu/compat", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D compat_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(compat_pvr, PowerPCCPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_ppc_cpu =3D { .name =3D "cpu", .version_id =3D 5, @@ -613,6 +675,7 @@ const VMStateDescription vmstate_ppc_cpu =3D { &vmstate_tlb6xx, &vmstate_tlbemb, &vmstate_tlbmas, + &vmstate_compat, NULL } }; diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index e837cd2..ee84044 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -10606,6 +10606,8 @@ static gchar *ppc_gdb_arch_name(CPUState *cs) =20 static Property ppc_cpu_properties[] =3D { DEFINE_PROP_BOOL("pre-2.8-migration", PowerPCCPU, pre_2_8_migration, f= alse), + DEFINE_PROP_BOOL("pre-2.10-migration", PowerPCCPU, pre_2_10_migration, + false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820054397717.221712579294; Fri, 30 Jun 2017 03:54:14 -0700 (PDT) Received: from localhost ([::1]:43668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtYy-0006Ta-Mp for importer@patchew.org; Fri, 30 Jun 2017 06:54:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRj-0008SK-UN for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRi-0007u8-RB for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:43 -0400 Received: from ozlabs.org ([103.22.144.67]:42809) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sW-Fk; Fri, 30 Jun 2017 06:46:42 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n0lBlz9sNd; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=gSoio5/asrfTcNsuUPYj2Uk15pMcS+BjxI7ghZNMXRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W9ros3lCskOj9S6b5anbHkulCFg1U64W9KZ3kzCBmgpW6XLOVA+h2EUmyrNqhu9Mg pvMiOfyPHispAHE8iDhwDW5h34LGi2rTtIzbCqJuelLKIK5JZoASaf5D7OTU7QnxBe X5jtAkgXG+sO5hLG8gYEHeLnTSrlCMPBQEMU+ixE= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:17 +1000 Message-Id: <20170630104632.27942-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 06/21] spapr: Add a "no HPT" encoding to HTAB migration stream 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Bharata B Rao , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Bharata B Rao Add a "no HPT" encoding (using value -1) to the HTAB migration stream (in the place of HPT size) when the guest doesn't allocate HPT. This will help the target side to match target HPT with the source HPT and thus enable successful migration. Suggested-by: David Gibson Signed-off-by: Bharata B Rao Signed-off-by: David Gibson --- hw/ppc/spapr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 52f4e72..f3e0b9b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1560,13 +1560,19 @@ static int htab_save_setup(QEMUFile *f, void *opaqu= e) sPAPRMachineState *spapr =3D opaque; =20 /* "Iteration" header */ - qemu_put_be32(f, spapr->htab_shift); + if (!spapr->htab_shift) { + qemu_put_be32(f, -1); + } else { + qemu_put_be32(f, spapr->htab_shift); + } =20 if (spapr->htab) { spapr->htab_save_index =3D 0; spapr->htab_first_pass =3D true; } else { - assert(kvm_enabled()); + if (spapr->htab_shift) { + assert(kvm_enabled()); + } } =20 =20 @@ -1712,7 +1718,12 @@ static int htab_save_iterate(QEMUFile *f, void *opaq= ue) int rc =3D 0; =20 /* Iteration header */ - qemu_put_be32(f, 0); + if (!spapr->htab_shift) { + qemu_put_be32(f, -1); + return 0; + } else { + qemu_put_be32(f, 0); + } =20 if (!spapr->htab) { assert(kvm_enabled()); @@ -1746,7 +1757,12 @@ static int htab_save_complete(QEMUFile *f, void *opa= que) int fd; =20 /* Iteration header */ - qemu_put_be32(f, 0); + if (!spapr->htab_shift) { + qemu_put_be32(f, -1); + return 0; + } else { + qemu_put_be32(f, 0); + } =20 if (!spapr->htab) { int rc; @@ -1790,6 +1806,11 @@ static int htab_load(QEMUFile *f, void *opaque, int = version_id) =20 section_hdr =3D qemu_get_be32(f); =20 + if (section_hdr =3D=3D -1) { + spapr_free_hpt(spapr); + return 0; + } + if (section_hdr) { Error *local_err =3D NULL; =20 --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819894368971.2640297282884; Fri, 30 Jun 2017 03:51:34 -0700 (PDT) Received: from localhost ([::1]:43660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtWO-00048n-N5 for importer@patchew.org; Fri, 30 Jun 2017 06:51:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRl-0008TT-34 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007vG-DC for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:45 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:48493) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sn-Tp; Fri, 30 Jun 2017 06:46:43 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n20ZYz9sxR; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=NLcyXkh0qawvmk6JuGlH6lR+kAG1ms7GUaQwhN1nmXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mtWZmR7wLAFgHXitI7vxWHK8fXhzF830p1A0SJiJvUEN+wJWoJPOJBoFf1p+awpXz +lcvIqtB3NndhmvzwKsntmdvffn8/2IEQ1n3RF1dYhsjFpnLc9mUJ+26fwwdvvbeUg j9mKLzBuKuo9jd0l6OeFQxIuovZHRzxBoiZJecF4= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:18 +1000 Message-Id: <20170630104632.27942-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 07/21] spapr: Fix migration of Radix guests 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Bharata B Rao , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Bharata B Rao Fix migration of radix guests by ensuring that we issue KVM_PPC_CONFIGURE_V3_MMU for radix case post migration. Reported-by: Nageswara R Sastry Signed-off-by: Bharata B Rao Reviewed-by: Suraj Jitindar Singh Signed-off-by: David Gibson --- hw/ppc/spapr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f3e0b9b..6c276af 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1445,6 +1445,18 @@ static int spapr_post_load(void *opaque, int version= _id) err =3D spapr_rtc_import_offset(&spapr->rtc, spapr->rtc_offset); } =20 + if (spapr->patb_entry) { + PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); + bool radix =3D !!(spapr->patb_entry & PATBE1_GR); + bool gtse =3D !!(cpu->env.spr[SPR_LPCR] & LPCR_GTSE); + + err =3D kvmppc_configure_v3_mmu(cpu, radix, gtse, spapr->patb_entr= y); + if (err) { + error_report("Process table config unsupported by the host"); + return -EINVAL; + } + } + return err; } =20 --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820091034751.7680930820486; Fri, 30 Jun 2017 03:54:51 -0700 (PDT) Received: from localhost ([::1]:43671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtZY-0007Fz-Ek for importer@patchew.org; Fri, 30 Jun 2017 06:54:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRk-0008T8-RS for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007un-94 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:44 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:55773) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sk-R2; Fri, 30 Jun 2017 06:46:43 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n4Cf7z9t0j; Fri, 30 Jun 2017 20:46:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=u3/MMFja2oDxwlb5iPunR3yS775q+O4QssX9tebK0NA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tm/5oQAvwEQhMy7X7Rxj3eF+9EOxjM2jaaKKd5PwyMiw9inIxnQhCGUnR44IHHyzj /i/Q77Q2Ghv86J8c2+Ls753UCbTeLOmxlRKu+0EoxwglADpdvxOJfR9q8qO/fqmYYP nAulM/CVIj7qiS3L6SVmgHd0+I4RQYPhyqj44q2U= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:19 +1000 Message-Id: <20170630104632.27942-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 08/21] target/ppc/excp_helper: Take BQL before calling cpu_interrupt() 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Since the introduction of MTTCG, using the msgsnd instruction abort()s if being called without holding the BQL. So let's protect that part of the code now with qemu_mutex_lock_iothread(). Buglink: https://bugs.launchpad.net/qemu/+bug/1694998 Signed-off-by: Thomas Huth Reviewed-by: Alex Benn=C3=A9e Signed-off-by: David Gibson --- target/ppc/excp_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 9cb2123..3a9f086 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -17,6 +17,7 @@ * License along with this library; if not, see . */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "exec/helper-proto.h" #include "exec/exec-all.h" @@ -1132,6 +1133,7 @@ void helper_msgsnd(target_ulong rb) return; } =20 + qemu_mutex_lock_iothread(); CPU_FOREACH(cs) { PowerPCCPU *cpu =3D POWERPC_CPU(cs); CPUPPCState *cenv =3D &cpu->env; @@ -1141,5 +1143,6 @@ void helper_msgsnd(target_ulong rb) cpu_interrupt(cs, CPU_INTERRUPT_HARD); } } + qemu_mutex_unlock_iothread(); } #endif --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819926319185.85774635027633; Fri, 30 Jun 2017 03:52:06 -0700 (PDT) Received: from localhost ([::1]:43662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtWv-0004Yh-09 for importer@patchew.org; Fri, 30 Jun 2017 06:52:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRk-0008Ss-HV for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007vP-DD for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:44 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:47985) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sh-U0; Fri, 30 Jun 2017 06:46:43 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n1LNXz9sRS; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=OWOHN7k8NF9moXE8B5QoGW7aaiCbp++HXND70JS0s8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TO2bXRDff0scp84Vy/0R3cAdyg9GOKdoWXWr/KDJM77yIg9cvgmyBke9SlDuqfKMn Y2QmiXlJRx48NvhmhP/MaXVYwBc8gsdUTuLNZdTllqX7RFmMSrqv0Z6akQsjfVuDu8 9kUsO398wpfw3eYSGznESRfqh1nAOF0mIQ5qb3OI= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:20 +1000 Message-Id: <20170630104632.27942-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 09/21] target/ppc: Fix return value in tcg radix mmu fault handler 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Suraj Jitindar Singh , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Suraj Jitindar Singh The mmu fault handler should return 0 if it was able to successfully handle the fault and a positive value otherwise. Currently the tcg radix mmu fault handler will return 1 after successfully handling a fault in virtual mode. This is incorrect so fix it so that it returns 0 in this case. The handler already correctly returns 0 when a fault was handled in real mode and 1 if an interrupt was generated. Fixes: d5fee0bbe68d ("target/ppc: Implement ISA V3.00 radix page fault hand= ler") Signed-off-by: Suraj Jitindar Singh Signed-off-by: David Gibson --- target/ppc/mmu-radix64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index de18c0b..69fde65 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -255,5 +255,5 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr= eaddr, int rwx, =20 tlb_set_page(cs, eaddr & TARGET_PAGE_MASK, raddr & TARGET_PAGE_MASK, prot, mmu_idx, 1UL << page_size); - return 1; + return 0; } --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819722816341.7381739351051; Fri, 30 Jun 2017 03:48:42 -0700 (PDT) Received: from localhost ([::1]:43645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtTd-0001Lo-7K for importer@patchew.org; Fri, 30 Jun 2017 06:48:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRk-0008T3-QW for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007vf-Gm for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:44 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:45939) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRj-0007sq-3T; Fri, 30 Jun 2017 06:46:43 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n3Qvtz9t1G; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=FENjylsMuXKYqXgurQ+s552T/ja1twx8+/XxUpB3GdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZPRrmCPwemZ8hECNVQd5luyNKjbYlcAjebFqFnJNGJYbBuYgpf2gQZ7wi2rqQdXa CcJFbWfyTNTOD5mRukE4uhcjI9R4ipqfojRnsw7npLYxd8WS3mM8VjFL6ejKmCbyTy vcC8gssucSUD/pmv7E2uUAA8YTKHLd0xBVRusXF4= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:21 +1000 Message-Id: <20170630104632.27942-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 10/21] xics: directly register ICPState objects to vmstate 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, Greg Kurz , qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Greg Kurz The ICPState objects are currently registered to vmstate as qdev objects. Their instance ids are hence computed automatically in the migration code, and thus depends on the order the CPU cores were plugged. If the destination had its CPU cores plugged in a different order than the source, then ICPState objects will have different instance_ids and load the wrong state. Since CPU objects have a reliable cpu_index which is already used as instance_id in vmstate, let's use it for ICPState as well. Please note that this doesn't break migration. Older machine types used to allocate and realize all ICPState objects at machine init time, for the who= le lifetime of the machine. The qdev instance ids are thus 0,1,2... nr_servers and happen to map to the vCPU indexes. Signed-off-by: Greg Kurz Reviewed-by: Laurent Vivier Signed-off-by: David Gibson --- hw/intc/xics.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/intc/xics.c b/hw/intc/xics.c index d4194d6..a84ba51 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -344,10 +344,14 @@ static void icp_realize(DeviceState *dev, Error **err= p) } =20 qemu_register_reset(icp_reset, dev); + vmstate_register(NULL, icp->cs->cpu_index, &vmstate_icp_server, icp); } =20 static void icp_unrealize(DeviceState *dev, Error **errp) { + ICPState *icp =3D ICP(dev); + + vmstate_unregister(NULL, &vmstate_icp_server, icp); qemu_unregister_reset(icp_reset, dev); } =20 @@ -355,7 +359,6 @@ static void icp_class_init(ObjectClass *klass, void *da= ta) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 - dc->vmsd =3D &vmstate_icp_server; dc->realize =3D icp_realize; dc->unrealize =3D icp_unrealize; } --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820242319152.18130911731816; Fri, 30 Jun 2017 03:57:22 -0700 (PDT) Received: from localhost ([::1]:43683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtbz-0000sS-Pi for importer@patchew.org; Fri, 30 Jun 2017 06:57:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRl-0008Tq-G2 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007ub-51 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:45 -0400 Received: from ozlabs.org ([103.22.144.67]:34319) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sY-Ha; Fri, 30 Jun 2017 06:46:43 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n2bVDz9sRb; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=xIprN1obLM0uycnEn2/LTTpUjME+eDFsSXD6wpvPdC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cb2xRciO5A3LE19WCRMKx67AFd8yUsycuAMQBvp3ohGEgYQDiQbHq4EIwugCki+DL 4QWFurJy98nbwYEuiPPSd6MSH9bSi9bYyqF/8hhFArQo2fWtI74X7qTINoTfy8sBpn phl4pmR53OCWUNblO8VudK/OtDF3f6p4A93HZcIc= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:22 +1000 Message-Id: <20170630104632.27942-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 11/21] spapr: fix migration of ICPState objects from/to older QEMU 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, Greg Kurz , qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Greg Kurz Commit 5bc8d26de20c ("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICPState objects from the machine to CPU cores. This is an improvement since we no longer allocate ICPState objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions. This patch allows spapr to register dummy "icp/server" entries to vmstate. These entries use a dedicated VMStateDescription that can swallow and discard state of an incoming migration stream, and that don't send anything on outgoing migration. As for real ICPState objects, the instance_id is the cpu_index of the corresponding vCPU, which happens to be equal to the generated instance_id of older machine types. The machine can unregister/register these entries when CPUs are dynamically plugged/unplugged. This is only available for pseries-2.9 and older machines, thanks to a compat property. Signed-off-by: Greg Kurz Signed-off-by: David Gibson --- hw/ppc/spapr.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++= ++-- include/hw/ppc/spapr.h | 1 + 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 6c276af..ef944f7 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -127,9 +127,49 @@ error: return NULL; } =20 +static bool pre_2_10_vmstate_dummy_icp_needed(void *opaque) +{ + /* Dummy entries correspond to unused ICPState objects in older QEMUs, + * and newer QEMUs don't even have them. In both cases, we don't want + * to send anything on the wire. + */ + return false; +} + +static const VMStateDescription pre_2_10_vmstate_dummy_icp =3D { + .name =3D "icp/server", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D pre_2_10_vmstate_dummy_icp_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UNUSED(4), /* uint32_t xirr */ + VMSTATE_UNUSED(1), /* uint8_t pending_priority */ + VMSTATE_UNUSED(1), /* uint8_t mfrr */ + VMSTATE_END_OF_LIST() + }, +}; + +static void pre_2_10_vmstate_register_dummy_icp(int i) +{ + vmstate_register(NULL, i, &pre_2_10_vmstate_dummy_icp, + (void *)(uintptr_t) i); +} + +static void pre_2_10_vmstate_unregister_dummy_icp(int i) +{ + vmstate_unregister(NULL, &pre_2_10_vmstate_dummy_icp, + (void *)(uintptr_t) i); +} + +static inline int xics_max_server_number(void) +{ + return DIV_ROUND_UP(max_cpus * kvmppc_smt_threads(), smp_threads); +} + static void xics_system_init(MachineState *machine, int nr_irqs, Error **e= rrp) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(machine); + sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(machine); =20 if (kvm_enabled()) { if (machine_kernel_irqchip_allowed(machine) && @@ -151,6 +191,17 @@ static void xics_system_init(MachineState *machine, in= t nr_irqs, Error **errp) return; } } + + if (smc->pre_2_10_has_unused_icps) { + int i; + + for (i =3D 0; i < xics_max_server_number(); i++) { + /* Dummy entries get deregistered when real ICPState objects + * are registered during CPU core hotplug. + */ + pre_2_10_vmstate_register_dummy_icp(i); + } + } } =20 static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu, @@ -979,7 +1030,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr, void *fdt; sPAPRPHBState *phb; char *buf; - int smt =3D kvmppc_smt_threads(); =20 fdt =3D g_malloc0(FDT_MAX_SIZE); _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE))); @@ -1019,7 +1069,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr, _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2)); =20 /* /interrupt controller */ - spapr_dt_xics(DIV_ROUND_UP(max_cpus * smt, smp_threads), fdt, PHANDLE_= XICP); + spapr_dt_xics(xics_max_server_number(), fdt, PHANDLE_XICP); =20 ret =3D spapr_populate_memory(spapr, fdt); if (ret < 0) { @@ -2845,9 +2895,24 @@ static void spapr_core_unplug(HotplugHandler *hotplu= g_dev, DeviceState *dev, Error **errp) { MachineState *ms =3D MACHINE(qdev_get_machine()); + sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); CPUCore *cc =3D CPU_CORE(dev); CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, cc->core_id, NULL); =20 + if (smc->pre_2_10_has_unused_icps) { + sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); + sPAPRCPUCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(OBJECT(cc)); + const char *typename =3D object_class_get_name(scc->cpu_class); + size_t size =3D object_type_get_instance_size(typename); + int i; + + for (i =3D 0; i < cc->nr_threads; i++) { + CPUState *cs =3D CPU(sc->threads + i * size); + + pre_2_10_vmstate_register_dummy_icp(cs->cpu_index); + } + } + assert(core_slot); core_slot->cpu =3D NULL; object_unparent(OBJECT(dev)); @@ -2899,6 +2964,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, { sPAPRMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); MachineClass *mc =3D MACHINE_GET_CLASS(spapr); + sPAPRMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); sPAPRCPUCore *core =3D SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc =3D CPU_CORE(dev); CPUState *cs =3D CPU(core->threads); @@ -2955,6 +3021,21 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, } } core_slot->cpu =3D OBJECT(dev); + + if (smc->pre_2_10_has_unused_icps) { + sPAPRCPUCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(OBJECT(cc)); + const char *typename =3D object_class_get_name(scc->cpu_class); + size_t size =3D object_type_get_instance_size(typename); + int i; + + for (i =3D 0; i < cc->nr_threads; i++) { + sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(dev); + void *obj =3D sc->threads + i * size; + + cs =3D CPU(obj); + pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); + } + } } =20 static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *= dev, @@ -3409,9 +3490,12 @@ static void spapr_machine_2_9_instance_options(Machi= neState *machine) =20 static void spapr_machine_2_9_class_options(MachineClass *mc) { + sPAPRMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); + spapr_machine_2_10_class_options(mc); SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_9); mc->numa_auto_assign_ram =3D numa_legacy_auto_assign_ram; + smc->pre_2_10_has_unused_icps =3D true; } =20 DEFINE_SPAPR_MACHINE(2_9, "2.9", false); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 2ddb052..a66bbac 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -53,6 +53,7 @@ struct sPAPRMachineClass { bool dr_lmb_enabled; /* enable dynamic-reconfig/hotplug of LMBs = */ bool use_ohci_by_default; /* use USB-OHCI instead of XHCI */ const char *tcg_default_cpu; /* which (TCG) CPU to simulate by default= */ + bool pre_2_10_has_unused_icps; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,=20 hwaddr *mmio32, hwaddr *mmio64, --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820715338605.5565295292149; Fri, 30 Jun 2017 04:05:15 -0700 (PDT) Received: from localhost ([::1]:43735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtja-0007tK-SY for importer@patchew.org; Fri, 30 Jun 2017 07:05:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRp-00006H-16 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRm-0007zY-T8 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:49 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:48965) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRm-0007wS-D5; Fri, 30 Jun 2017 06:46:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9p2dtjz9t2K; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819598; bh=MMcYBhnkOhZTNa+qb8yileQCReyTnA2F9XQdppFFMp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KdJOEHKNcU1e+p6LoTWdANxod5gVqXkban9DSvV8UHu75K+fDpr1zTsMMARDDZEgI /BohV0u8y828u5rPP8ty3cOKcw3kB0AhZlmSGahUZOzQtJ7kWZhFho+J4lNM4Cq1Zn 2zZJmj/+V5/4lZcdCNHBBJL7AZJgzpqMEh7cxmI4= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:23 +1000 Message-Id: <20170630104632.27942-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 12/21] target/ppc: Proper cleanup when ppc_cpu_realizefn fails 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Bharata B Rao , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Bharata B Rao If ppc_cpu_realizefn() fails after cpu_exec_realizefn() has been called, we will have to undo whatever cpu_exec_realizefn() did by explicitly calling cpu_exec_unrealizeffn() which is currently missing. Failure to do this proper cleanup will result in CPU which was never fully realized to linger on the cpus list causing SIGSEGV later (for eg when running "info cpus"). Signed-off-by: Bharata B Rao Reviewed-by: Greg Kurz Signed-off-by: David Gibson --- target/ppc/translate_init.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index ee84044..783bf98 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -9825,14 +9825,14 @@ static void ppc_cpu_realizefn(DeviceState *dev, Err= or **errp) error_append_hint(errp, "Adjust the number of cpus to %d " "or try to raise the number of threads per core\= n", cpu->cpu_dt_id * smp_threads / max_smt); - return; + goto unrealize; } #endif =20 if (tcg_enabled()) { if (ppc_fixup_cpu(cpu) !=3D 0) { error_setg(errp, "Unable to emulate selected CPU with TCG"); - return; + goto unrealize; } } =20 @@ -9841,14 +9841,14 @@ static void ppc_cpu_realizefn(DeviceState *dev, Err= or **errp) error_setg(errp, "CPU does not possess a BookE or 4xx MMU. " "Please use qemu-system-ppc or qemu-system-ppc64 instea= d " "or choose another CPU model."); - return; + goto unrealize; } #endif =20 create_ppc_opcodes(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); - return; + goto unrealize; } init_ppc_proc(cpu); =20 @@ -10033,6 +10033,10 @@ static void ppc_cpu_realizefn(DeviceState *dev, Er= ror **errp) fflush(stdout); } #endif + return; + +unrealize: + cpu_exec_unrealizefn(cs); } =20 static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820550318417.8577874044719; Fri, 30 Jun 2017 04:02:30 -0700 (PDT) Received: from localhost ([::1]:43720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtgx-0005gg-UV for importer@patchew.org; Fri, 30 Jun 2017 07:02:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRn-00004x-Ob for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRm-0007yO-55 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:47 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:54429) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRl-0007vm-Mf; Fri, 30 Jun 2017 06:46:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n6Hwkz9t1t; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=D1jsONpdYHcQz6X1ASCiMdvAop2lphz1JLqgbMQV9n8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Js7YuNeZaFUF7bt3M9bTp7EcpUCJHZbQ6Gs0hBiQrnbg/y5xNIP9hnS3mS5Euage/ wGoF2l9zksycTys2tHON/KzAdSxaekXYhrvQTH0uvf5Mka00Y+W4Hl7g+BhMRbPDjW BXk+s0cQjXzDyfJDQ/h3YRxoSKaYyUr27PprB9XU= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:24 +1000 Message-Id: <20170630104632.27942-14-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 13/21] spapr: prevent QEMU crash when CPU realization fails 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Bharata B Rao , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Bharata B Rao ICPState objects were being allocated before CPU thread realization. However commit 9ed656631d73 (xics: setup cpu at realize time) reversed it by allocating ICPState objects after CPU thread is realized. But it didn't take care to fix the error path because of which we observe a SIGSEGV when CPU thread realization fails during cold/hotplug. Fix this by ensuring that we do object_unparent() of ICPState object only in case when is was created earlier. Signed-off-by: Bharata B Rao Reviewed-by: Greg Kurz Signed-off-by: David Gibson --- hw/ppc/spapr_cpu_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index d6719d5..ea278ce 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -178,7 +178,7 @@ static void spapr_cpu_core_realize_child(Object *child,= Error **errp) sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); CPUState *cs =3D CPU(child); PowerPCCPU *cpu =3D POWERPC_CPU(cs); - Object *obj =3D NULL; + Object *obj; =20 object_property_set_bool(child, true, "realized", &local_err); if (local_err) { @@ -198,13 +198,14 @@ static void spapr_cpu_core_realize_child(Object *chil= d, Error **errp) object_property_add_const_link(obj, ICP_PROP_CPU, child, &error_abort); object_property_set_bool(obj, true, "realized", &local_err); if (local_err) { - goto error; + goto free_icp; } =20 return; =20 -error: +free_icp: object_unparent(obj); +error: error_propagate(errp, local_err); } =20 --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820249541707.7321701259033; Fri, 30 Jun 2017 03:57:29 -0700 (PDT) Received: from localhost ([::1]:43684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtc8-0000yX-6j for importer@patchew.org; Fri, 30 Jun 2017 06:57:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRn-0008Vp-0G for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRl-0007xv-UI for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:54831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRl-0007vL-GP; Fri, 30 Jun 2017 06:46:45 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n5j8cz9t2M; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=C+LWZTt49C65UUn3eNk4pY+YqJWaRf4IC+qvDQBJGCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hY2LFTl3ACNfI/EP99/2EiIAEkfr56p4dXW8ulJw80QKpAUAqkuiYTfjsusbmKpSl eDkQtSUD0qv1wu170Q7UbPs8mXxyCPMRaEZrcPCyPWDRdl2fFkvIY2flaGJaNcQrp1 PenHFEG8MJoN1eJmfB4xQ1C8/wYRa0cQOOwETr14= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:25 +1000 Message-Id: <20170630104632.27942-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 14/21] hw/ppc/spapr.c: consecutive 'spapr->patb_entry = 0' statements 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Daniel Henrique Barboza , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza In ppc_spapr_reset(), if the guest is using HPT, the code was executing: } else { spapr->patb_entry =3D 0; spapr_setup_hpt_and_vrma(spapr); } And, at the end of spapr_setup_hpt_and_vrma: /* We're setting up a hash table, so that means we're not radix */ spapr->patb_entry =3D 0; Resulting in spapr->patb_entry being assigned to 0 twice in a row. Given that 'spapr_setup_hpt_and_vrma' is also called inside 'spapr_check_setup_free_hpt' of spapr_hcall.c, this trivial patch removes the 'patb_entry =3D 0' assignment from the 'else' clause inside ppc_spapr_r= eset to avoid this behavior. Signed-off-by: Daniel Henrique Barboza Signed-off-by: David Gibson --- hw/ppc/spapr.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ef944f7..3c12af0 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1376,7 +1376,6 @@ static void ppc_spapr_reset(void) * Set the GR bit in PATB so that we know there is no HPT. */ spapr->patb_entry =3D PATBE1_GR; } else { - spapr->patb_entry =3D 0; spapr_setup_hpt_and_vrma(spapr); } =20 --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 149882024141511.59473125439456; Fri, 30 Jun 2017 03:57:21 -0700 (PDT) Received: from localhost ([::1]:43682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtbz-0000qy-Rd for importer@patchew.org; Fri, 30 Jun 2017 06:57:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRp-00006L-2a for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRl-0007y5-VY for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:49 -0400 Received: from ozlabs.org ([103.22.144.67]:42035) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRl-0007vr-Ap; Fri, 30 Jun 2017 06:46:45 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n6myFz9t1n; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=Y0q5IK7XbJ/odjtfhU/leEdCYh0GO18gX8b+YRQhE9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aG0ICatrnjlVW7VfW/bP0+keQlxAtY2gA9lgnweXuLFGRF43B2dOcxxY1bzxwPhsd 8J4aMsq5PzS7tTeQjbqoCuOZShKKPzytX5ab/XK43bRbEwvJTa9V3vG7uOH7L3U8xh 2d7vWeu8rsdA3DQHw4xz13hUvjQnaO/2KkL5KDnY= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:26 +1000 Message-Id: <20170630104632.27942-16-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 15/21] target-ppc: Enable open-pic timers to count and generate interrupts 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, Aaron Larson , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Aaron Larson Previously QEMU open-pic implemented the 4 open-pic timers including all timer registers, but the timers did not "count" or generate any interrupts. The patch makes the timers both count and generate interrupts. The timer clock frequency is fixed at 25MHZ. -- Responding to V2 patch comments. - Simplify clock frequency logic and commentary. - Remove camelCase variables. - Timer objects now created at init rather than lazily. Signed-off-by: Aaron Larson Signed-off-by: David Gibson --- hw/intc/openpic.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 111 insertions(+), 6 deletions(-) diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c index 5595bb2..9dd285b 100644 --- a/hw/intc/openpic.c +++ b/hw/intc/openpic.c @@ -45,6 +45,7 @@ #include "qemu/bitops.h" #include "qapi/qmp/qerror.h" #include "qemu/log.h" +#include "qemu/timer.h" =20 //#define DEBUG_OPENPIC =20 @@ -54,8 +55,10 @@ static const int debug_openpic =3D 1; static const int debug_openpic =3D 0; #endif =20 +static int get_current_cpu(void); #define DPRINTF(fmt, ...) do { \ if (debug_openpic) { \ + printf("Core%d: ", get_current_cpu()); \ printf(fmt , ## __VA_ARGS__); \ } \ } while (0) @@ -246,9 +249,31 @@ typedef struct IRQSource { #define IDR_EP 0x80000000 /* external pin */ #define IDR_CI 0x40000000 /* critical interrupt */ =20 +/* Convert between openpic clock ticks and nanosecs. In the hardware the = clock + frequency is driven by board inputs to the PIC which the PIC would then + divide by 4 or 8. For now hard code to 25MZ. +*/ +#define OPENPIC_TIMER_FREQ_MHZ 25 +#define OPENPIC_TIMER_NS_PER_TICK (1000 / OPENPIC_TIMER_FREQ_MHZ) +static inline uint64_t ns_to_ticks(uint64_t ns) +{ + return ns / OPENPIC_TIMER_NS_PER_TICK; +} +static inline uint64_t ticks_to_ns(uint64_t ticks) +{ + return ticks * OPENPIC_TIMER_NS_PER_TICK; +} + typedef struct OpenPICTimer { uint32_t tccr; /* Global timer current count register */ uint32_t tbcr; /* Global timer base count register */ + int n_IRQ; + bool qemu_timer_active; /* Is the qemu_timer is runni= ng? */ + struct QEMUTimer *qemu_timer; + struct OpenPICState *opp; /* Device timer is part of. */ + /* The QEMU_CLOCK_VIRTUAL time (in ns) corresponding to the last + current_count written or read, only defined if qemu_timer_active. */ + uint64_t origin_time; } OpenPICTimer; =20 typedef struct OpenPICMSI { @@ -795,6 +820,65 @@ static uint64_t openpic_gbl_read(void *opaque, hwaddr = addr, unsigned len) return retval; } =20 +static void openpic_tmr_set_tmr(OpenPICTimer *tmr, uint32_t val, bool enab= led); + +static void qemu_timer_cb(void *opaque) +{ + OpenPICTimer *tmr =3D opaque; + OpenPICState *opp =3D tmr->opp; + uint32_t n_IRQ =3D tmr->n_IRQ; + uint32_t val =3D tmr->tbcr & ~TBCR_CI; + uint32_t tog =3D ((tmr->tccr & TCCR_TOG) ^ TCCR_TOG); /* invert toggl= e. */ + + DPRINTF("%s n_IRQ=3D%d\n", __func__, n_IRQ); + /* Reload current count from base count and setup timer. */ + tmr->tccr =3D val | tog; + openpic_tmr_set_tmr(tmr, val, /*enabled=3D*/true); + /* Raise the interrupt. */ + opp->src[n_IRQ].destmask =3D read_IRQreg_idr(opp, n_IRQ); + openpic_set_irq(opp, n_IRQ, 1); + openpic_set_irq(opp, n_IRQ, 0); +} + +/* If enabled is true, arranges for an interrupt to be raised val clocks i= nto + the future, if enabled is false cancels the timer. */ +static void openpic_tmr_set_tmr(OpenPICTimer *tmr, uint32_t val, bool enab= led) +{ + uint64_t ns =3D ticks_to_ns(val & ~TCCR_TOG); + /* A count of zero causes a timer to be set to expire immediately. Th= is + effectively stops the simulation since the timer is constantly expi= ring + which prevents guest code execution, so we don't honor that + configuration. On real hardware, this situation would generate an + interrupt on every clock cycle if the interrupt was unmasked. */ + if ((ns =3D=3D 0) || !enabled) { + tmr->qemu_timer_active =3D false; + tmr->tccr =3D tmr->tccr & TCCR_TOG; + timer_del(tmr->qemu_timer); /* set timer to never expire. */ + } else { + tmr->qemu_timer_active =3D true; + uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + tmr->origin_time =3D now; + timer_mod(tmr->qemu_timer, now + ns); /* set timer expiration.= */ + } +} + +/* Returns the currrent tccr value, i.e., timer value (in clocks) with + appropriate TOG. */ +static uint64_t openpic_tmr_get_timer(OpenPICTimer *tmr) +{ + uint64_t retval; + if (!tmr->qemu_timer_active) { + retval =3D tmr->tccr; + } else { + uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + uint64_t used =3D now - tmr->origin_time; /* nsecs */ + uint32_t used_ticks =3D (uint32_t)ns_to_ticks(used); + uint32_t count =3D (tmr->tccr & ~TCCR_TOG) - used_ticks; + retval =3D (uint32_t)((tmr->tccr & TCCR_TOG) | (count & ~TCCR_TOG)= ); + } + return retval; +} + static void openpic_tmr_write(void *opaque, hwaddr addr, uint64_t val, unsigned len) { @@ -819,10 +903,15 @@ static void openpic_tmr_write(void *opaque, hwaddr ad= dr, uint64_t val, case 0x00: /* TCCR */ break; case 0x10: /* TBCR */ - if ((opp->timers[idx].tccr & TCCR_TOG) !=3D 0 && - (val & TBCR_CI) =3D=3D 0 && - (opp->timers[idx].tbcr & TBCR_CI) !=3D 0) { - opp->timers[idx].tccr &=3D ~TCCR_TOG; + /* Did the enable status change? */ + if ((opp->timers[idx].tbcr & TBCR_CI) !=3D (val & TBCR_CI)) { + /* Did "Count Inhibit" transition from 1 to 0? */ + if ((val & TBCR_CI) =3D=3D 0) { + opp->timers[idx].tccr =3D val & ~TCCR_TOG; + } + openpic_tmr_set_tmr(&opp->timers[idx], + (val & ~TBCR_CI), + /*enabled=3D*/((val & TBCR_CI) =3D=3D 0)); } opp->timers[idx].tbcr =3D val; break; @@ -854,7 +943,7 @@ static uint64_t openpic_tmr_read(void *opaque, hwaddr a= ddr, unsigned len) idx =3D (addr >> 6) & 0x3; switch (addr & 0x30) { case 0x00: /* TCCR */ - retval =3D opp->timers[idx].tccr; + retval =3D openpic_tmr_get_timer(&opp->timers[idx]); break; case 0x10: /* TBCR */ retval =3D opp->timers[idx].tbcr; @@ -1136,7 +1225,10 @@ static uint32_t openpic_iack(OpenPICState *opp, IRQD= est *dst, int cpu) IRQ_resetbit(&dst->raised, irq); } =20 - if ((irq >=3D opp->irq_ipi0) && (irq < (opp->irq_ipi0 + OPENPIC_MAX_I= PI))) { + /* Timers and IPIs support multicast. */ + if (((irq >=3D opp->irq_ipi0) && (irq < (opp->irq_ipi0 + OPENPIC_MAX_I= PI))) || + ((irq >=3D opp->irq_tim0) && (irq < (opp->irq_tim0 + OPENPIC_MAX_T= MR)))) { + DPRINTF("irq is IPI or TMR\n"); src->destmask &=3D ~(1 << cpu); if (src->destmask && !src->level) { /* trigger on CPUs that didn't know about it yet */ @@ -1341,6 +1433,10 @@ static void openpic_reset(DeviceState *d) for (i =3D 0; i < OPENPIC_MAX_TMR; i++) { opp->timers[i].tccr =3D 0; opp->timers[i].tbcr =3D TBCR_CI; + if (opp->timers[i].qemu_timer_active) { + timer_del(opp->timers[i].qemu_timer); /* Inhibit timer */ + opp->timers[i].qemu_timer_active =3D false; + } } /* Go out of RESET state */ opp->gcr =3D 0; @@ -1391,6 +1487,15 @@ static void fsl_common_init(OpenPICState *opp) opp->src[i].type =3D IRQ_TYPE_FSLSPECIAL; opp->src[i].level =3D false; } + + for (i =3D 0; i < OPENPIC_MAX_TMR; i++) { + opp->timers[i].n_IRQ =3D opp->irq_tim0 + i; + opp->timers[i].qemu_timer_active =3D false; + opp->timers[i].qemu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + &qemu_timer_cb, + &opp->timers[i]); + opp->timers[i].opp =3D opp; + } } =20 static void map_list(OpenPICState *opp, const MemReg *list, int *count) --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820395707781.930622354775; Fri, 30 Jun 2017 03:59:55 -0700 (PDT) Received: from localhost ([::1]:43699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQteU-0003ZA-4N for importer@patchew.org; Fri, 30 Jun 2017 06:59:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRn-00005D-Vn for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRm-0007yn-GS for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:48 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:46523) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRm-0007wB-3R; Fri, 30 Jun 2017 06:46:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9p0s0vz9t2L; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819598; bh=Xs9A2ckya6tYjMc4b48A9+Nm2E+OacbYTChvA8E0DKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f+4+3HuA/WoZgG/hIe6mhX+34kZqfdzX6LC40lif7qF3oU2SvvcNiI4ze42MYpEWS rWeO5ZebzH9utpBRuVG9RpQpnnWWwMNLbZt/k3G/UYQa9TMsyY1tM1t+Mm6suIDuDE tX2dT7Ean5Fv/Ytxvdi+1zk6eqGS2T3AO5z2wQGU= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:27 +1000 Message-Id: <20170630104632.27942-17-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 16/21] spapr: Start hotplugged PCI devices in ISOLATED 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" PCI DRCs, and only PCI DRCs, are immediately moved to UNISOLATED isolation state once the device is attached. This has been there from the initial implementation, and it's not clear why. The state diagram in PAPR 13.4 suggests PCI devices should start in ISOLATED state until the guest moves them into UNISOLATED, and the code in the guest-side drmgr tool seems to work that way too. Signed-off-by: David Gibson Reviewed-by: Michael Roth Reviewed-by: Greg Kurz --- hw/ppc/spapr_drc.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 5cb75bb..91fc08d 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -304,16 +304,6 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, } g_assert(fdt || coldplug); =20 - /* NOTE: setting initial isolation state to UNISOLATED means we can't - * detach unless guest has a userspace/kernel that moves this state - * back to ISOLATED in response to an unplug event, or this is done - * manually by the admin prior. if we force things while the guest - * may be accessing the device, we can easily crash the guest, so we - * we defer completion of removal in such cases to the reset() hook. - */ - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; - } drc->dr_indicator =3D SPAPR_DR_INDICATOR_ACTIVE; =20 drc->dev =3D d; --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820909294108.96182949143667; Fri, 30 Jun 2017 04:08:29 -0700 (PDT) Received: from localhost ([::1]:43753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtmi-0002dO-G6 for importer@patchew.org; Fri, 30 Jun 2017 07:08:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRq-00007d-5K for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRm-0007zP-Op for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:50 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:39279) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRl-0007w8-W8; Fri, 30 Jun 2017 06:46:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9p1KpMz9t2H; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819598; bh=y0QKxP474qSPDlzWpScqMOILZeg5Zm/82jyfh07Qasg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hqpSBylMAGB23wnZ7EPZPDQp91nYgV/JXG8HBUDqybGpwHDt21k30QC/xQGOKp0Zi uzfDDH6SGdjNEJgJ4sErfPBRIXpZyOSvYtuNQrGL4N5zP1ebb9P9pfzQWGUEz0V5gC qQBb4uMTwUYXkP3gY3BVV4eulgSytLo3MYeT5Xv0= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:28 +1000 Message-Id: <20170630104632.27942-18-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 17/21] spapr: Eliminate DRC 'signalled' state variable 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The 'signalled' field in the DRC appears to be entirely a torturous workaround for the fact that PCI devices were started in UNISOLATED state for unclear reasons. 1) 'signalled' is already meaningless for logical (so far, all non PCI) DRCs. It's always set to true (at least at any point it might be tested), and can't be assigned any real meaning due to the way signalling works for logical DRCs. 2) For PCI DRCs, the only time signalled would be false is when non-zero functions of a multifunction device are hotplugged, followed by function zero (the other way around is explicitly not permitted). In that case the secondary function DRCs are attached, but the notification isn't sent to the guest until function 0 is plugged. 3) signalled being false is used to allow a DRC detach to switch mode back to ISOLATED state, which allows a secondary function to be hotplugged then unplugged with function 0 never inserted. Without this a secondary function starting in UNISOLATED state couldn't be detached again without function 0 being inserted, all the functions configured by the guest, then sent back to ISOLATED state. 4) But now that PCI DRCs start in ISOLATED state, there's nothing to be done. If the guest doesn't get the notification, it won't switch the device to UNISOLATED state, so nothing prevents it from being unplugged. If the guest does move it to UNISOLATED state without the signal (due to a manual drmgr call, for instance) then it really isn't safe to unplug it. So, this patch removes the signalled variable and all code related to it. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 45 +-----------------------------------------= --- hw/ppc/spapr_events.c | 10 ---------- include/hw/ppc/spapr_drc.h | 2 -- 3 files changed, 1 insertion(+), 56 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 91fc08d..21f5bf1 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -172,12 +172,6 @@ static const char *spapr_drc_name(sPAPRDRConnector *dr= c) return g_strdup_printf("%s%d", drck->drc_name_prefix, drc->id); } =20 -/* has the guest been notified of device attachment? */ -static void set_signalled(sPAPRDRConnector *drc) -{ - drc->signalled =3D true; -} - /* * dr-entity-sense sensor value * returned via get-sensor-state RTAS calls @@ -310,17 +304,6 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, drc->fdt =3D fdt; drc->fdt_start_offset =3D fdt_start_offset; drc->configured =3D coldplug; - /* 'logical' DR resources such as memory/cpus are in some cases treated - * as a pool of resources from which the guest is free to choose from - * based on only a count. for resources that can be assigned in this - * fashion, we must assume the resource is signalled immediately - * since a single hotplug request might make an arbitrary number of - * such attached resources available to the guest, as opposed to - * 'physical' DR resources such as PCI where each device/resource is - * signalled individually. - */ - drc->signalled =3D (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_P= CI) - ? true : coldplug; =20 if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { drc->awaiting_allocation =3D true; @@ -336,26 +319,6 @@ void spapr_drc_detach(sPAPRDRConnector *drc, DeviceSta= te *d, Error **errp) { trace_spapr_drc_detach(spapr_drc_index(drc)); =20 - /* if we've signalled device presence to the guest, or if the guest - * has gone ahead and configured the device (via manually-executed - * device add via drmgr in guest, namely), we need to wait - * for the guest to quiesce the device before completing detach. - * Otherwise, we can assume the guest hasn't seen it and complete the - * detach immediately. Note that there is a small race window - * just before, or during, configuration, which is this context - * refers mainly to fetching the device tree via RTAS. - * During this window the device access will be arbitrated by - * associated DRC, which will simply fail the RTAS calls as invalid. - * This is recoverable within guest and current implementations of - * drmgr should be able to cope. - */ - if (!drc->signalled && !drc->configured) { - /* if the guest hasn't seen the device we can't rely on it to - * set it back to an isolated state via RTAS, so do it here manual= ly - */ - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; - } - if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); drc->awaiting_release =3D true; @@ -441,10 +404,6 @@ static void reset(DeviceState *d) drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_UNUS= ABLE); } } - - if (drck->dr_entity_sense(drc) =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { - drck->set_signalled(drc); - } } =20 static bool spapr_drc_needed(void *opaque) @@ -469,7 +428,7 @@ static bool spapr_drc_needed(void *opaque) case SPAPR_DR_CONNECTOR_TYPE_LMB: rc =3D !((drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_UNI= SOLATED) && (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_USA= BLE) && - drc->configured && drc->signalled && !drc->awaiting_release= ); + drc->configured && !drc->awaiting_release); break; case SPAPR_DR_CONNECTOR_TYPE_PHB: case SPAPR_DR_CONNECTOR_TYPE_VIO: @@ -491,7 +450,6 @@ static const VMStateDescription vmstate_spapr_drc =3D { VMSTATE_BOOL(configured, sPAPRDRConnector), VMSTATE_BOOL(awaiting_release, sPAPRDRConnector), VMSTATE_BOOL(awaiting_allocation, sPAPRDRConnector), - VMSTATE_BOOL(signalled, sPAPRDRConnector), VMSTATE_END_OF_LIST() } }; @@ -589,7 +547,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) drck->set_isolation_state =3D set_isolation_state; drck->set_allocation_state =3D set_allocation_state; drck->release_pending =3D release_pending; - drck->set_signalled =3D set_signalled; /* * Reason: it crashes FIXME find and document the real reason */ diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 171aedc..587a3da 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -475,13 +475,6 @@ static void spapr_powerdown_req(Notifier *n, void *opa= que) RTAS_LOG_TYPE_EPOW)= )); } =20 -static void spapr_hotplug_set_signalled(uint32_t drc_index) -{ - sPAPRDRConnector *drc =3D spapr_drc_by_index(drc_index); - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->set_signalled(drc); -} - static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action, sPAPRDRConnectorType drc_type, union drc_identifier *drc_id) @@ -528,9 +521,6 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint= 8_t hp_action, switch (drc_type) { case SPAPR_DR_CONNECTOR_TYPE_PCI: hp->hotplug_type =3D RTAS_LOG_V6_HP_TYPE_PCI; - if (hp->hotplug_action =3D=3D RTAS_LOG_V6_HP_ACTION_ADD) { - spapr_hotplug_set_signalled(drc_id->index); - } break; case SPAPR_DR_CONNECTOR_TYPE_LMB: hp->hotplug_type =3D RTAS_LOG_V6_HP_TYPE_MEMORY; diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index bc9f988..388e2a6 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -199,7 +199,6 @@ typedef struct sPAPRDRConnector { sPAPRConfigureConnectorState *ccs; =20 bool awaiting_release; - bool signalled; bool awaiting_allocation; =20 /* device pointer, via link property */ @@ -225,7 +224,6 @@ typedef struct sPAPRDRConnectorClass { =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); - void (*set_signalled)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; =20 uint32_t spapr_drc_index(sPAPRDRConnector *drc); --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819916288206.1751362990277; Fri, 30 Jun 2017 03:51:56 -0700 (PDT) Received: from localhost ([::1]:43661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtWj-0004Pb-Tg for importer@patchew.org; Fri, 30 Jun 2017 06:51:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRn-000053-Qz for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRm-0007yC-0y for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:47 -0400 Received: from ozlabs.org ([103.22.144.67]:45941) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRl-0007wA-LU; Fri, 30 Jun 2017 06:46:45 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9p1pb4z9t2J; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819598; bh=a3quTNUuQxREf0U2/aiH3ORiSsgcTcnOhwzBo/r6zQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=edFUSN5IQB1qOxTuKmY0UJ5nZ27V2FWdxuaZjRdVbzgTbZ4x1D08F2FK7dXCWBAjB J4H1SZPvAbgMBPiFc2mNdm2H1lekmf0B6K46D9W9zISQR3SBKIMFZKvEZSYXsHoFub 6HmRDyzNxHIj00yYWaP9bd8uLxQu384CyjCYRMAU= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:29 +1000 Message-Id: <20170630104632.27942-19-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 18/21] spapr: Split DRC release from DRC detach 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" spapr_drc_detach() is called when qemu generic code requests a device be unplugged. It makes a number of tests, which could well delay further action until later, before actually detach the device from the DRC. This splits out the part which actually removes the device from the DRC into spapr_drc_release(). This will be useful for further cleanups. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 21f5bf1..8a2b8f5 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -315,29 +315,8 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, NULL, 0, NULL); } =20 -void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) +static void spapr_drc_release(sPAPRDRConnector *drc) { - trace_spapr_drc_detach(spapr_drc_index(drc)); - - if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); - drc->awaiting_release =3D true; - return; - } - - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && - drc->allocation_state !=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { - trace_spapr_drc_awaiting_unusable(spapr_drc_index(drc)); - drc->awaiting_release =3D true; - return; - } - - if (drc->awaiting_allocation) { - drc->awaiting_release =3D true; - trace_spapr_drc_awaiting_allocation(spapr_drc_index(drc)); - return; - } - drc->dr_indicator =3D SPAPR_DR_INDICATOR_INACTIVE; =20 /* Calling release callbacks based on spapr_drc_type(drc). */ @@ -365,6 +344,32 @@ void spapr_drc_detach(sPAPRDRConnector *drc, DeviceSta= te *d, Error **errp) drc->dev =3D NULL; } =20 +void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) +{ + trace_spapr_drc_detach(spapr_drc_index(drc)); + + if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { + trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); + drc->awaiting_release =3D true; + return; + } + + if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && + drc->allocation_state !=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { + trace_spapr_drc_awaiting_unusable(spapr_drc_index(drc)); + drc->awaiting_release =3D true; + return; + } + + if (drc->awaiting_allocation) { + drc->awaiting_release =3D true; + trace_spapr_drc_awaiting_allocation(spapr_drc_index(drc)); + return; + } + + spapr_drc_release(drc); +} + static bool release_pending(sPAPRDRConnector *drc) { return drc->awaiting_release; --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820078304711.2371550659595; Fri, 30 Jun 2017 03:54:38 -0700 (PDT) Received: from localhost ([::1]:43669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtZN-000788-1D for importer@patchew.org; Fri, 30 Jun 2017 06:54:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRp-00006m-CR for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRm-0007z6-Mz for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:49 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:43223) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRm-0007w2-6K; Fri, 30 Jun 2017 06:46:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9p0K91z9t24; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819598; bh=G8mEko8WYp/9aCfexTpJypG6u+/YtUANCvhGOpnxYN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LSgdolGoTwCRvvKrSQ5ONLaqtJ5CdOMSedJm03HxPbTemNO/V8MeqnP0kAAX7mp5T XmQZCpOyQrbjPpa6HMbHzNHeGqaVr10oaVPLHvtRUnZuZJAVU6QrJoQWC+kpnCf4VE LKAnGINnVVlbaGpUOh+CpNRFZyKdjYGJsAMjqlr8= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:30 +1000 Message-Id: <20170630104632.27942-20-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 19/21] spapr: Make DRC reset force DRC into known 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The reset handler for DRCs attempts several state transitions which are subject to various checks and restrictions. But at reset time we know there is no guest, so we can ignore most of the usual sequencing rules and just set the DRC back to a known state. In fact, it's safer to do so. The existing code also has several redundant checks for drc->awaiting_release inside a block which has already tested that. This patch removes those and sets the DRC to a fixed initial state based only on whether a device is currently plugged or not. With DRCs correctly reset to a state based on device presence, we don't need to force state transitions as cold plugged devices are processed. This allows us to remove all the callers of the set_*_state() methods from outside spapr_drc.c. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr.c | 15 --------------- hw/ppc/spapr_drc.c | 35 ++++++++++++++++------------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 3c12af0..0ee9fac 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2636,12 +2636,6 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_= t addr_start, uint64_t size, =20 spapr_drc_attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, errp= ); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; - if (!dev->hotplugged) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(d= rc); - /* guests expect coldplugged LMBs to be pre-allocated */ - drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USAB= LE); - drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOL= ATED); - } } /* send hotplug notification to the * guest only in case of hotplugged memory @@ -3009,15 +3003,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, * of hotplugged CPUs. */ spapr_hotplug_req_add_by_index(drc); - } else { - /* - * Set the right DRC states for cold plugged CPU. - */ - if (drc) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(d= rc); - drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USAB= LE); - drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOL= ATED); - } } core_slot->cpu =3D OBJECT(dev); =20 diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 8a2b8f5..9a2511f 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -378,7 +378,6 @@ static bool release_pending(sPAPRDRConnector *drc) static void reset(DeviceState *d) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(d); - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 trace_spapr_drc_reset(spapr_drc_index(drc)); =20 @@ -386,27 +385,25 @@ static void reset(DeviceState *d) drc->ccs =3D NULL; =20 /* immediately upon reset we can safely assume DRCs whose devices - * are pending removal can be safely removed, and that they will - * subsequently be left in an ISOLATED state. move the DRC to this - * state in these cases (which will in turn complete any pending - * device removals) + * are pending removal can be safely removed. */ if (drc->awaiting_release) { - drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_ISOLATED); - /* generally this should also finalize the removal, but if the dev= ice - * hasn't yet been configured we normally defer removal under the - * assumption that this transition is taking place as part of devi= ce - * configuration. so check if we're still waiting after this, and - * force removal if we are - */ - if (drc->awaiting_release) { - spapr_drc_detach(drc, DEVICE(drc->dev), NULL); - } + spapr_drc_release(drc); + } + + drc->awaiting_allocation =3D false; =20 - /* non-PCI devices may be awaiting a transition to UNUSABLE */ - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && - drc->awaiting_release) { - drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_UNUS= ABLE); + if (drc->dev) { + /* A device present at reset is coldplugged */ + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; + if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; + } + } else { + /* Otherwise device is absent, but might be hotplugged */ + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; + if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; } } } --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498819726743880.5395162860736; Fri, 30 Jun 2017 03:48:46 -0700 (PDT) Received: from localhost ([::1]:43646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtTe-0001Mt-Ei for importer@patchew.org; Fri, 30 Jun 2017 06:48:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRk-0008T1-Pz for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007uN-05 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:44 -0400 Received: from ozlabs.org ([103.22.144.67]:34287) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sa-KA; Fri, 30 Jun 2017 06:46:42 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n4wtBz9sRg; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=p9BP9m7oiQx7AZbzn3H15TWvCVXnvk019uise7zLVKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLdUpW3E6kMPqOYAlRxOrQaQ4UPMvFTWtvvJEunmt9b1DzE5Am6w5YXV1DFtMHNJq M04YuYjLC5rPWcLg8wJwLMOs720JmCSo64WyPwZhrd+90egEuPKoFRWxOfhwNxmJY/ nsFX6M0rtaQbJWV6aE5ZPtJ68RIsnQkFXHDvpO0s= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:31 +1000 Message-Id: <20170630104632.27942-21-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 20/21] spapr: Clean up DRC set_allocation_state path 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The allocation-state indicator should only actually be implemented for "logical" DRCs, not physical ones. Factor a check for this, and also for valid indicator state values into rtas_set_allocation_state(). Because they don't exist for physical DRCs, there's no reason that we'd ever want more than one method implementation, so it can just be a plain function. In addition, the setting to USABLE and setting to UNUSABLE paths in set_allocation_state() don't actually have much in common. So, split the method separate functions for each parameter value (drc_set_usable() and drc_set_unusable()). Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 73 ++++++++++++++++++++++++++++--------------= ---- include/hw/ppc/spapr_drc.h | 2 -- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 9a2511f..dbcd670 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -114,33 +114,42 @@ static uint32_t set_isolation_state(sPAPRDRConnector = *drc, return RTAS_OUT_SUCCESS; } =20 -static uint32_t set_allocation_state(sPAPRDRConnector *drc, - sPAPRDRAllocationState state) +static uint32_t drc_set_usable(sPAPRDRConnector *drc) { - trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); - - if (state =3D=3D SPAPR_DR_ALLOCATION_STATE_USABLE) { - /* if there's no resource/device associated with the DRC, there's - * no way for us to put it in an allocation state consistent with - * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should - * result in an RTAS return code of -3 / "no such indicator" + /* if there's no resource/device associated with the DRC, there's + * no way for us to put it in an allocation state consistent with + * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should + * result in an RTAS return code of -3 / "no such indicator" + */ + if (!drc->dev) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + if (drc->awaiting_release && drc->awaiting_allocation) { + /* kernel is acknowledging a previous hotplug event + * while we are already removing it. + * it's safe to ignore awaiting_allocation here since we know the + * situation is predicated on the guest either already having done + * so (boot-time hotplug), or never being able to acquire in the + * first place (hotplug followed by immediate unplug). */ - if (!drc->dev) { - return RTAS_OUT_NO_SUCH_INDICATOR; - } + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->allocation_state =3D state; - if (drc->awaiting_release && - drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { - uint32_t drc_index =3D spapr_drc_index(drc); - trace_spapr_drc_set_allocation_state_finalizing(drc_index); - spapr_drc_detach(drc, DEVICE(drc->dev), NULL); - } else if (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_= USABLE) { - drc->awaiting_allocation =3D false; - } + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; + drc->awaiting_allocation =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_set_unusable(sPAPRDRConnector *drc) +{ + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + trace_spapr_drc_set_allocation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } + return RTAS_OUT_SUCCESS; } =20 @@ -547,7 +556,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->realize =3D realize; dk->unrealize =3D unrealize; drck->set_isolation_state =3D set_isolation_state; - drck->set_allocation_state =3D set_allocation_state; drck->release_pending =3D release_pending; /* * Reason: it crashes FIXME find and document the real reason @@ -817,14 +825,23 @@ static uint32_t rtas_set_isolation_state(uint32_t idx= , uint32_t state) static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) { sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); - sPAPRDRConnectorClass *drck; =20 - if (!drc) { - return RTAS_OUT_PARAM_ERROR; + if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_LOGICAL))= { + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return drck->set_allocation_state(drc, state); + trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); + + switch (state) { + case SPAPR_DR_ALLOCATION_STATE_USABLE: + return drc_set_usable(drc); + + case SPAPR_DR_ALLOCATION_STATE_UNUSABLE: + return drc_set_unusable(drc); + + default: + return RTAS_OUT_PARAM_ERROR; + } } =20 static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 388e2a6..1674b66 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -219,8 +219,6 @@ typedef struct sPAPRDRConnectorClass { /* accessors for guest-visible (generally via RTAS) DR state */ uint32_t (*set_isolation_state)(sPAPRDRConnector *drc, sPAPRDRIsolationState state); - uint32_t (*set_allocation_state)(sPAPRDRConnector *drc, - sPAPRDRAllocationState state); =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); --=20 2.9.4 From nobody Wed May 8 13:27:32 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.zoho.com; dkim=fail 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 1498820464739230.14143739118333; Fri, 30 Jun 2017 04:01:04 -0700 (PDT) Received: from localhost ([::1]:43708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtfb-0004a5-1K for importer@patchew.org; Fri, 30 Jun 2017 07:01:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRs-0000Aq-Hi for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRp-00082q-6k for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:52 -0400 Received: from ozlabs.org ([103.22.144.67]:39909) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRo-0007yz-EG; Fri, 30 Jun 2017 06:46:48 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9p36g8z9t1m; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819598; bh=7dgpehqqBDekcoguNBHvPcdM/eomHAtfmvbggLMc4pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CsHDbhh/vynxl4x5d3RNXTg6XHpUlzqTJAtARKrik5maq4Mqk9LQCCJFitSOUhJda tFn+9vOu5b/B3eTotiHYDs69SglnNIcRD+rGASlUFrSG0GBmwEqvNPashYssPG2Laf dBIVijAslQHDh+IksfoU0Ow++uXrZIJQ+abP2Kls= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:32 +1000 Message-Id: <20170630104632.27942-22-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 21/21] spapr: Clean up DRC set_isolation_state() path 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There are substantial differences in the various paths through set_isolation_state(), both for setting to ISOLATED versus UNISOLATED state and for logical versus physical DRCs. So, split the set_isolation_state() method into isolate() and unisolate() methods, and give it different implementations for the two DRC types. Factor some minimal common checks, including for valid indicator values (which we weren't previously checking) into rtas_set_isolation_state(). Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 145 ++++++++++++++++++++++++++++++++---------= ---- include/hw/ppc/spapr_drc.h | 6 +- 2 files changed, 105 insertions(+), 46 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index dbcd670..bd40b84 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -46,30 +46,64 @@ uint32_t spapr_drc_index(sPAPRDRConnector *drc) | (drc->id & DRC_INDEX_ID_MASK); } =20 -static uint32_t set_isolation_state(sPAPRDRConnector *drc, - sPAPRDRIsolationState state) +static uint32_t drc_isolate_physical(sPAPRDRConnector *drc) { - trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); - /* if the guest is configuring a device attached to this DRC, we * should reset the configuration state at this point since it may * no longer be reliable (guest released device and needs to start * over, or unplug occurred so the FDT is no longer valid) */ - if (state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - g_free(drc->ccs); - drc->ccs =3D NULL; - } + g_free(drc->ccs); + drc->ccs =3D NULL; =20 - if (state =3D=3D SPAPR_DR_ISOLATION_STATE_UNISOLATED) { - /* cannot unisolate a non-existent resource, and, or resources - * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, 13.5.3.= 5) - */ - if (!drc->dev || - drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { - return RTAS_OUT_NO_SUCH_INDICATOR; + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; + + /* if we're awaiting release, but still in an unconfigured state, + * it's likely the guest is still in the process of configuring + * the device and is transitioning the devices to an ISOLATED + * state as a part of that process. so we only complete the + * removal when this transition happens for a device in a + * configured state, as suggested by the state diagram from PAPR+ + * 2.7, 13.4 + */ + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + if (drc->configured) { + trace_spapr_drc_set_isolation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); + } else { + trace_spapr_drc_set_isolation_state_deferring(drc_index); } } + drc->configured =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_unisolate_physical(sPAPRDRConnector *drc) +{ + /* cannot unisolate a non-existent resource, and, or resources + * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, + * 13.5.3.5) + */ + if (!drc->dev) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_isolate_logical(sPAPRDRConnector *drc) +{ + /* if the guest is configuring a device attached to this DRC, we + * should reset the configuration state at this point since it may + * no longer be reliable (guest released device and needs to start + * over, or unplug occurred so the FDT is no longer valid) + */ + g_free(drc->ccs); + drc->ccs =3D NULL; =20 /* * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't @@ -81,35 +115,47 @@ static uint32_t set_isolation_state(sPAPRDRConnector *= drc, * If the LMB being removed doesn't belong to a DIMM device that is * actually being unplugged, fail the isolation request here. */ - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_LMB) { - if ((state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) && - !drc->awaiting_release) { - return RTAS_OUT_HW_ERROR; - } + if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_LMB + && !drc->awaiting_release) { + return RTAS_OUT_HW_ERROR; } =20 - drc->isolation_state =3D state; + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; =20 - if (drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - /* if we're awaiting release, but still in an unconfigured state, - * it's likely the guest is still in the process of configuring - * the device and is transitioning the devices to an ISOLATED - * state as a part of that process. so we only complete the - * removal when this transition happens for a device in a - * configured state, as suggested by the state diagram from - * PAPR+ 2.7, 13.4 - */ - if (drc->awaiting_release) { - uint32_t drc_index =3D spapr_drc_index(drc); - if (drc->configured) { - trace_spapr_drc_set_isolation_state_finalizing(drc_index); - spapr_drc_detach(drc, DEVICE(drc->dev), NULL); - } else { - trace_spapr_drc_set_isolation_state_deferring(drc_index); - } + /* if we're awaiting release, but still in an unconfigured state, + * it's likely the guest is still in the process of configuring + * the device and is transitioning the devices to an ISOLATED + * state as a part of that process. so we only complete the + * removal when this transition happens for a device in a + * configured state, as suggested by the state diagram from PAPR+ + * 2.7, 13.4 + */ + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + if (drc->configured) { + trace_spapr_drc_set_isolation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); + } else { + trace_spapr_drc_set_isolation_state_deferring(drc_index); } - drc->configured =3D false; } + drc->configured =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_unisolate_logical(sPAPRDRConnector *drc) +{ + /* cannot unisolate a non-existent resource, and, or resources + * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, + * 13.5.3.5) + */ + if (!drc->dev || + drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; =20 return RTAS_OUT_SUCCESS; } @@ -555,7 +601,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->reset =3D reset; dk->realize =3D realize; dk->unrealize =3D unrealize; - drck->set_isolation_state =3D set_isolation_state; drck->release_pending =3D release_pending; /* * Reason: it crashes FIXME find and document the real reason @@ -568,6 +613,8 @@ static void spapr_drc_physical_class_init(ObjectClass *= k, void *data) sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 drck->dr_entity_sense =3D physical_entity_sense; + drck->isolate =3D drc_isolate_physical; + drck->unisolate =3D drc_unisolate_physical; } =20 static void spapr_drc_logical_class_init(ObjectClass *k, void *data) @@ -575,6 +622,8 @@ static void spapr_drc_logical_class_init(ObjectClass *k= , void *data) sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 drck->dr_entity_sense =3D logical_entity_sense; + drck->isolate =3D drc_isolate_logical; + drck->unisolate =3D drc_unisolate_logical; } =20 static void spapr_drc_cpu_class_init(ObjectClass *k, void *data) @@ -815,11 +864,23 @@ static uint32_t rtas_set_isolation_state(uint32_t idx= , uint32_t state) sPAPRDRConnectorClass *drck; =20 if (!drc) { - return RTAS_OUT_PARAM_ERROR; + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 + trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return drck->set_isolation_state(drc, state); + + switch (state) { + case SPAPR_DR_ISOLATION_STATE_ISOLATED: + return drck->isolate(drc); + + case SPAPR_DR_ISOLATION_STATE_UNISOLATED: + return drck->unisolate(drc); + + default: + return RTAS_OUT_PARAM_ERROR; + } } =20 static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 1674b66..d9cacb3 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -215,10 +215,8 @@ typedef struct sPAPRDRConnectorClass { const char *drc_name_prefix; /* used other places in device tree */ =20 sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc); - - /* accessors for guest-visible (generally via RTAS) DR state */ - uint32_t (*set_isolation_state)(sPAPRDRConnector *drc, - sPAPRDRIsolationState state); + uint32_t (*isolate)(sPAPRDRConnector *drc); + uint32_t (*unisolate)(sPAPRDRConnector *drc); =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); --=20 2.9.4