From nobody Thu Mar 28 22:46:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575006660; cv=none; d=zohomail.com; s=zohoarc; b=V+uuvB/H2ypE6dAIqkKNU7XVa3tyycPJWzsh0aqFU1YZ0dh8flyeM6eSsXi6Ly3rAZOwaxwt/8nejenirrVOdOyXXE9nRMUI/lL9iRCh4Sx02shUGFkmH12hWJeD2dqBCadQvvZ7ZotPmOrpS0PrmE/ox14PZpg3AWRfzcY4e3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575006660; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sL82UNWSsU/46+eqRhvAOQpeRpnkGib7cNpV5dOuifo=; b=Pro9lNaQ88jsnLlokBFu1a4PDnaU0UYGir/MD/zZMm5yM34AWO03eqPCS5nPNiSLx+XV0dVlltJB0bXhVDZaJEgJXSfS2pKU96sr3wKD8Kc9lnOLvFvT+qTEiQD/27xVZj/TxhNAOr8BmyCXeqASWjzistn5UNwJi4VfsVF+sxo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575006660949608.0842687842041; Thu, 28 Nov 2019 21:51:00 -0800 (PST) Received: from localhost ([::1]:55076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaZBB-0001hs-F6 for importer@patchew.org; Fri, 29 Nov 2019 00:50:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55653) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaYuy-0002gu-Bs for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaYut-0002nc-5x for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:10 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:33515) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaYus-0002Lv-6k; Fri, 29 Nov 2019 00:34:07 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PNTz5B8Fz9sPj; Fri, 29 Nov 2019 16:33:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1575005639; bh=gkJR1uYIZjQwGcO4AthiZKM0GvBR19MZhgvCP1GHfdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bA1yiETXRs4JRRX34AuLOJO25rpIvMjje9cFkaS2VjnFIjPKlLaVT9h2tksS5V20W S0j8JPvEmMjKtd9eEF3zsz7IcVVAFd3gSUX2uD9+ARW/qjNb828iKeeKyW95BFJPSP LgL0OXL2Dd7DWmVhX2chWFkWkHzI8oHzzZnJNrtU= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 1/4] spapr: Don't trigger a CAS reboot for XICS/XIVE mode changeover Date: Fri, 29 Nov 2019 16:33:53 +1100 Message-Id: <20191129053356.232413-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129053356.232413-1-david@gibson.dropbear.id.au> References: <20191129053356.232413-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 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, David Gibson , qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" PAPR allows the interrupt controller used on a POWER9 machine (XICS or XIVE) to be selected by the guest operating system, by using the ibm,client-architecture-support (CAS) feature negotiation call. Currently, if the guest selects an interrupt controller different from the one selected at initial boot, this causes the system to be reset with the new model and the boot starts again. This means we run through the SLOF boot process twice, as well as any other bootloader (e.g. grub) in use before the OS calls CAS. This can be confusing and/or inconvenient for users. Thanks to two fairly recent changes, we no longer need this reboot. 1) we now completely regenerate the device tree when CAS is called (meaning we don't need special case updates for all the device tree changes caused by the interrupt controller mode change), 2) we now have explicit code paths to activate and deactivate the different interrupt controllers, rather than just implicitly calling those at machine reset time. We can therefore eliminate the reboot for changing irq mode, simply by putting a called to spapr_irq_update_active_intc() before we call spapr_h_cas_compose_response() (which gives the updated device tree to the guest firmware and OS). Signed-off-by: David Gibson Reviewed-by: Cedric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr_hcall.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 140f05c1c6..05a7ca275b 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1767,21 +1767,10 @@ static target_ulong h_client_architecture_support(P= owerPCCPU *cpu, } spapr->cas_pre_isa3_guest =3D !spapr_ovec_test(ov1_guest, OV1_PPC_3_00= ); spapr_ovec_cleanup(ov1_guest); - if (!spapr->cas_reboot) { - /* If spapr_machine_reset() did not set up a HPT but one is necess= ary - * (because the guest isn't going to use radix) then set it up her= e. */ - if ((spapr->patb_entry & PATE1_GR) && !guest_radix) { - /* legacy hash or new hash: */ - spapr_setup_hpt_and_vrma(spapr); - } - spapr->cas_reboot =3D - (spapr_h_cas_compose_response(spapr, args[1], args[2], - ov5_updates) !=3D 0); - } =20 /* - * Ensure the guest asks for an interrupt mode we support; otherwise - * terminate the boot. + * Ensure the guest asks for an interrupt mode we support; + * otherwise terminate the boot. */ if (guest_xive) { if (!spapr->irq->xive) { @@ -1797,14 +1786,18 @@ static target_ulong h_client_architecture_support(P= owerPCCPU *cpu, } } =20 - /* - * Generate a machine reset when we have an update of the - * interrupt mode. Only required when the machine supports both - * modes. - */ + spapr_irq_update_active_intc(spapr); + if (!spapr->cas_reboot) { - spapr->cas_reboot =3D spapr_ovec_test(ov5_updates, OV5_XIVE_EXPLOI= T) - && spapr->irq->xics && spapr->irq->xive; + /* If spapr_machine_reset() did not set up a HPT but one is necess= ary + * (because the guest isn't going to use radix) then set it up her= e. */ + if ((spapr->patb_entry & PATE1_GR) && !guest_radix) { + /* legacy hash or new hash: */ + spapr_setup_hpt_and_vrma(spapr); + } + spapr->cas_reboot =3D + (spapr_h_cas_compose_response(spapr, args[1], args[2], + ov5_updates) !=3D 0); } =20 spapr_ovec_cleanup(ov5_updates); --=20 2.23.0 From nobody Thu Mar 28 22:46:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575006043; cv=none; d=zohomail.com; s=zohoarc; b=PPayG19f71XH109BqxBlLJgZSGTAmS8e1lrNrKgrRi7gd4co2FM1HDWRDQTlBWsfHG5wr5iXWdUsJb6m4rddPua5NI30/l1b+5z/8b+n0w6rO4UAzIzI3sbt7Fxm6HUtIwsWEwf860Yky/XLBjosrtbBOcqg7mAvZ9XM4pYZbPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575006043; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8+obQ9vv8gaEap76eCbThOBFcQPdRw1eITXlJ5KgZCM=; b=haOAiPVDUzJWTOkQv5m/hT9o9BG82CtWpRzexg2i7Q3Y2xQ7JP9IyfgbVZhpk8mXsmIAFfaOQn3fy1tbUGYvmhKMD+ej3z8jm+a/2Rz2JoZQJZrGg9Jhp5u7sVYHljuD5CVJtH6dEe6j6nI+Z41nWdxk1y8XDJWs/Zt6GuhYK68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575006043116776.2385167798515; Thu, 28 Nov 2019 21:40:43 -0800 (PST) Received: from localhost ([::1]:55042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaZ1E-0005OH-O6 for importer@patchew.org; Fri, 29 Nov 2019 00:40:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55624) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaYuw-0002gj-0W for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaYut-0002ou-Eh for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:09 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:52047) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaYur-0002M8-5U; Fri, 29 Nov 2019 00:34:07 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PNTz6JDlz9sR2; Fri, 29 Nov 2019 16:33:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1575005639; bh=cenYxuwXEyURgovfy5vrBzyXXCpM0tGcpKxNSH0Fqxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FiT9oC31/HOeacIXfVMW4+tCI46DYubpuENLGUMvG23cqROaEBLhXMtZh+cwg3RBA qQXkaE3rPMBlJZzQoS4Qanu+qusXklombD2dPko0KteLGEoq7zACsN+uY57nRQShPb aoTyrnRCEAzX6JCQgwT9FEWdOkwEvDQEc5x5/6Eg= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 2/4] spapr: Improve handling of fdt buffer size Date: Fri, 29 Nov 2019 16:33:54 +1100 Message-Id: <20191129053356.232413-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129053356.232413-1-david@gibson.dropbear.id.au> References: <20191129053356.232413-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 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, David Gibson , qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Previously, spapr_build_fdt() constructed the device tree in a fixed buffer of size FDT_MAX_SIZE. This is a bit inflexible, but more importantly it's awkward for the case where we use it during CAS. In that case the guest firmware supplies a buffer and we have to awkwardly check that what we generated fits into it afterwards, after doing a lot of size checks during spapr_build_fdt(). Simplify this by having spapr_build_fdt() take a 'space' parameter. For the CAS case, we pass in the buffer size provided by SLOF, for the machine init case, we continue to pass FDT_MAX_SIZE. Signed-off-by: David Gibson Reviewed-by: Cedric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d9c9a2bcee..d34e317f48 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -917,7 +917,8 @@ static bool spapr_hotplugged_dev_before_cas(void) return false; } =20 -static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset); +static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, + size_t space); =20 int spapr_h_cas_compose_response(SpaprMachineState *spapr, target_ulong addr, target_ulong size, @@ -930,24 +931,17 @@ int spapr_h_cas_compose_response(SpaprMachineState *s= papr, return 1; } =20 - if (size < sizeof(hdr) || size > FW_MAX_SIZE) { - error_report("SLOF provided an unexpected CAS buffer size " - TARGET_FMT_lu " (min: %zu, max: %u)", - size, sizeof(hdr), FW_MAX_SIZE); + if (size < sizeof(hdr)) { + error_report("SLOF provided insufficient CAS buffer " + TARGET_FMT_lu " (min: %zu)", size, sizeof(hdr)); exit(EXIT_FAILURE); } =20 size -=3D sizeof(hdr); =20 - fdt =3D spapr_build_fdt(spapr, false); + fdt =3D spapr_build_fdt(spapr, false, size); _FDT((fdt_pack(fdt))); =20 - if (fdt_totalsize(fdt) + sizeof(hdr) > size) { - g_free(fdt); - trace_spapr_cas_failed(size); - return -1; - } - cpu_physical_memory_write(addr, &hdr, sizeof(hdr)); cpu_physical_memory_write(addr + sizeof(hdr), fdt, fdt_totalsize(fdt)); trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr)); @@ -1197,7 +1191,8 @@ static void spapr_dt_hypervisor(SpaprMachineState *sp= apr, void *fdt) } } =20 -static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset) +static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, + size_t space) { MachineState *machine =3D MACHINE(spapr); MachineClass *mc =3D MACHINE_GET_CLASS(machine); @@ -1207,8 +1202,8 @@ static void *spapr_build_fdt(SpaprMachineState *spapr= , bool reset) SpaprPhbState *phb; char *buf; =20 - fdt =3D g_malloc0(FDT_MAX_SIZE); - _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE))); + fdt =3D g_malloc0(space); + _FDT((fdt_create_empty_tree(fdt, space))); =20 /* Root node */ _FDT(fdt_setprop_string(fdt, 0, "device_type", "chrp")); @@ -1723,19 +1718,13 @@ static void spapr_machine_reset(MachineState *machi= ne) */ fdt_addr =3D MIN(spapr->rma_size, RTAS_MAX_ADDR) - FDT_MAX_SIZE; =20 - fdt =3D spapr_build_fdt(spapr, true); + fdt =3D spapr_build_fdt(spapr, true, FDT_MAX_SIZE); =20 rc =3D fdt_pack(fdt); =20 /* Should only fail if we've built a corrupted tree */ assert(rc =3D=3D 0); =20 - if (fdt_totalsize(fdt) > FDT_MAX_SIZE) { - error_report("FDT too big ! 0x%x bytes (max is 0x%x)", - fdt_totalsize(fdt), FDT_MAX_SIZE); - exit(1); - } - /* Load the fdt */ qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt)); --=20 2.23.0 From nobody Thu Mar 28 22:46:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575006328; cv=none; d=zohomail.com; s=zohoarc; b=k6r+EA8iZEo5s+BaCtxORNm5kXZ1esgWPwgB3Dv/sFD4oaLe4KZttICC7rjXr1Fj1BDM6UPfqXODf1GjdyTgdhwqlPtdMKyxZ2x6kImfJKKG2x5/UochGb5BfZhriFcSdmFFOdqwzjg3A+aglED4za1VV6yL9tQkRnLNsHK+dTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575006328; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GhzESCk9kTAI2g9KA8bW0jQLYSZDIEdDTS4sfcIgF6o=; b=YKo8f/Pdgc8e1qULwih92kuw0rXx1NNwnw+JB3bIo9x+pmNH6Ei1044ySH/UItv03SNdS3EBK0bR7qM5onkbwFkPH15/v5ugD14RBUKlxo+g4MST52+m+onxEuNQYFjHoO2/u/nI721zyyXoTATWHovsX0KdWXKLscAAtgcTYm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575006328438408.64528694340515; Thu, 28 Nov 2019 21:45:28 -0800 (PST) Received: from localhost ([::1]:55046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaZ5q-0007UJ-Hz for importer@patchew.org; Fri, 29 Nov 2019 00:45:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55640) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaYv0-0002gl-6g for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaYut-0002op-EZ for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:09 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:51261) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaYut-0002LS-26; Fri, 29 Nov 2019 00:34:07 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PNV00NwYz9sR7; Fri, 29 Nov 2019 16:33:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1575005640; bh=YmyEz8vrvnk7O0yuNW6ah+1YhIkQcxGbaHdD5Ns3gEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyKsL0BJ7xZenPOkRanhi1hfCI3Nmx46sdEKUJa7vmzGyKRkLH5lMk7iRVmvg4d8U frHlqRzzTBzrvO3olHfD0nqNOSV6Qu66az+BwQF3Yz4wDosRaHi7LXBp2CatbzYUzl +5aq0VIEsSI8kHUGNvgSJnOT3ymDLdIdY9q2ZYKY= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 3/4] spapr: Fold h_cas_compose_response() into h_client_architecture_support() Date: Fri, 29 Nov 2019 16:33:55 +1100 Message-Id: <20191129053356.232413-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129053356.232413-1-david@gibson.dropbear.id.au> References: <20191129053356.232413-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 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, David Gibson , qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" spapr_h_cas_compose_response() handles the last piece of the PAPR feature negotiation process invoked via the ibm,client-architecture-support OF call. Its only caller is h_client_architecture_support() which handles most of the rest of that process. I believe it was place in a separate file originally to handle some fiddly dependencies between functions, but mostly it's just confusing to have the CAS process split into two pieces like this. Now that compose response is simplified (by just generating the whole device tree anew), it's cleaner to just fold it into h_client_architecture_support(). Signed-off-by: David Gibson Reviewed-by: Cedric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 61 +----------------------------------------- hw/ppc/spapr_hcall.c | 55 ++++++++++++++++++++++++++++++++++--- include/hw/ppc/spapr.h | 4 +-- 3 files changed, 54 insertions(+), 66 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d34e317f48..5187f5b0a5 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -76,7 +76,6 @@ #include "hw/nmi.h" #include "hw/intc/intc.h" =20 -#include "qemu/cutils.h" #include "hw/ppc/spapr_cpu_core.h" #include "hw/mem/memory-device.h" #include "hw/ppc/spapr_tpm_proxy.h" @@ -897,63 +896,6 @@ out: return ret; } =20 -static bool spapr_hotplugged_dev_before_cas(void) -{ - Object *drc_container, *obj; - ObjectProperty *prop; - ObjectPropertyIterator iter; - - drc_container =3D container_get(object_get_root(), "/dr-connector"); - object_property_iter_init(&iter, drc_container); - while ((prop =3D object_property_iter_next(&iter))) { - if (!strstart(prop->type, "link<", NULL)) { - continue; - } - obj =3D object_property_get_link(drc_container, prop->name, NULL); - if (spapr_drc_needed(obj)) { - return true; - } - } - return false; -} - -static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, - size_t space); - -int spapr_h_cas_compose_response(SpaprMachineState *spapr, - target_ulong addr, target_ulong size, - SpaprOptionVector *ov5_updates) -{ - void *fdt; - SpaprDeviceTreeUpdateHeader hdr =3D { .version_id =3D 1 }; - - if (spapr_hotplugged_dev_before_cas()) { - return 1; - } - - if (size < sizeof(hdr)) { - error_report("SLOF provided insufficient CAS buffer " - TARGET_FMT_lu " (min: %zu)", size, sizeof(hdr)); - exit(EXIT_FAILURE); - } - - size -=3D sizeof(hdr); - - fdt =3D spapr_build_fdt(spapr, false, size); - _FDT((fdt_pack(fdt))); - - cpu_physical_memory_write(addr, &hdr, sizeof(hdr)); - cpu_physical_memory_write(addr + sizeof(hdr), fdt, fdt_totalsize(fdt)); - trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr)); - - g_free(spapr->fdt_blob); - spapr->fdt_size =3D fdt_totalsize(fdt); - spapr->fdt_initial_size =3D spapr->fdt_size; - spapr->fdt_blob =3D fdt; - - return 0; -} - static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) { MachineState *ms =3D MACHINE(spapr); @@ -1191,8 +1133,7 @@ static void spapr_dt_hypervisor(SpaprMachineState *sp= apr, void *fdt) } } =20 -static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, - size_t space) +void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space) { MachineState *machine =3D MACHINE(spapr); MachineClass *mc =3D MACHINE_GET_CLASS(machine); diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 05a7ca275b..0f19be794c 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "sysemu/hw_accel.h" #include "sysemu/runstate.h" @@ -15,6 +16,7 @@ #include "cpu-models.h" #include "trace.h" #include "kvm_ppc.h" +#include "hw/ppc/fdt.h" #include "hw/ppc/spapr_ovec.h" #include "mmu-book3s-v3.h" #include "hw/mem/memory-device.h" @@ -1638,6 +1640,26 @@ static uint32_t cas_check_pvr(SpaprMachineState *spa= pr, PowerPCCPU *cpu, return best_compat; } =20 +static bool spapr_hotplugged_dev_before_cas(void) +{ + Object *drc_container, *obj; + ObjectProperty *prop; + ObjectPropertyIterator iter; + + drc_container =3D container_get(object_get_root(), "/dr-connector"); + object_property_iter_init(&iter, drc_container); + while ((prop =3D object_property_iter_next(&iter))) { + if (!strstart(prop->type, "link<", NULL)) { + continue; + } + obj =3D object_property_get_link(drc_container, prop->name, NULL); + if (spapr_drc_needed(obj)) { + return true; + } + } + return false; +} + static target_ulong h_client_architecture_support(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, @@ -1645,6 +1667,8 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, { /* Working address in data buffer */ target_ulong addr =3D ppc64_phys_to_real(args[0]); + target_ulong fdt_buf =3D args[1]; + target_ulong fdt_bufsize =3D args[2]; target_ulong ov_table; uint32_t cas_pvr; SpaprOptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; @@ -1788,16 +1812,41 @@ static target_ulong h_client_architecture_support(P= owerPCCPU *cpu, =20 spapr_irq_update_active_intc(spapr); =20 + if (spapr_hotplugged_dev_before_cas()) { + spapr->cas_reboot =3D true; + } + if (!spapr->cas_reboot) { + void *fdt; + SpaprDeviceTreeUpdateHeader hdr =3D { .version_id =3D 1 }; + /* If spapr_machine_reset() did not set up a HPT but one is necess= ary * (because the guest isn't going to use radix) then set it up her= e. */ if ((spapr->patb_entry & PATE1_GR) && !guest_radix) { /* legacy hash or new hash: */ spapr_setup_hpt_and_vrma(spapr); } - spapr->cas_reboot =3D - (spapr_h_cas_compose_response(spapr, args[1], args[2], - ov5_updates) !=3D 0); + + if (fdt_bufsize < sizeof(hdr)) { + error_report("SLOF provided insufficient CAS buffer " + TARGET_FMT_lu " (min: %zu)", fdt_bufsize, sizeof(= hdr)); + exit(EXIT_FAILURE); + } + + fdt_bufsize -=3D sizeof(hdr); + + fdt =3D spapr_build_fdt(spapr, false, fdt_bufsize); + _FDT((fdt_pack(fdt))); + + cpu_physical_memory_write(fdt_buf, &hdr, sizeof(hdr)); + cpu_physical_memory_write(fdt_buf + sizeof(hdr), fdt, + fdt_totalsize(fdt)); + trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr)); + + g_free(spapr->fdt_blob); + spapr->fdt_size =3D fdt_totalsize(fdt); + spapr->fdt_initial_size =3D spapr->fdt_size; + spapr->fdt_blob =3D fdt; } =20 spapr_ovec_cleanup(ov5_updates); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index d5ab5ea7b2..61f005c6f6 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -766,11 +766,9 @@ struct SpaprEventLogEntry { QTAILQ_ENTRY(SpaprEventLogEntry) next; }; =20 +void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space); void spapr_events_init(SpaprMachineState *sm); void spapr_dt_events(SpaprMachineState *sm, void *fdt); -int spapr_h_cas_compose_response(SpaprMachineState *sm, - target_ulong addr, target_ulong size, - SpaprOptionVector *ov5_updates); void close_htab_fd(SpaprMachineState *spapr); void spapr_setup_hpt_and_vrma(SpaprMachineState *spapr); void spapr_free_hpt(SpaprMachineState *spapr); --=20 2.23.0 From nobody Thu Mar 28 22:46:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575006010; cv=none; d=zohomail.com; s=zohoarc; b=PRYp+dKkce5H/xHD9gYM1vuyUqpoxinuihqImYZwy6VT+7BsI4RswymBx8ZNrN5VufRUS2C7OyhfT2AGQGbxu7EN/4f7X2A+M/emOpWwhbx2ZG8wmupd+V13rr8KPFKQoKCdlxiEPaStY67d4LfwC+JnxD4WXcUCaztJmlksVSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575006010; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YhjCuAMEdGlyFw45vVT5DIkfWKLKIJ5lAvHD1cnvs5s=; b=Yawi1tojAi9T6cJrPvd9k0XpTsWnZ1HGEGR/Me+HSElarC485odg4xs/zkadwLe8m/NmdN6khfWLL+zFLsBwYEg+duSnQEBIJ3oOqO29p3y9Ib0mJzkv9gY7hr/hUR1CFnDlUPo8Kncd4EEJeQt1OKdM+28N1u9wFumq7MvYB4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157500600959615.154304622845757; Thu, 28 Nov 2019 21:40:09 -0800 (PST) Received: from localhost ([::1]:55038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaZ0g-0005HP-JA for importer@patchew.org; Fri, 29 Nov 2019 00:40:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55695) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaYuy-0002h1-CH for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaYuu-0002uz-Sk for qemu-devel@nongnu.org; Fri, 29 Nov 2019 00:34:11 -0500 Received: from ozlabs.org ([203.11.71.1]:47053) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaYuu-0002Mn-GQ; Fri, 29 Nov 2019 00:34:08 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PNV00zrLz9sR8; Fri, 29 Nov 2019 16:33:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1575005640; bh=eSymelUFtceSa3fIrS+iMSr+NirExn0qwY6U9PuT39U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mif7cP/8eQ0/WPbEJIW4malfvYPzeMSlReIlzlrMvzpuV5y4Bs6CUGXckGJAHt3sc T4+ePium7VXm5es1txjsWH8fed3Xf/ldWU1dkkR4OiigSAxFEwKENHMo2D3vr0HnuW q2HVdmP2CyFL3igPSDm6MjlT2jsVBlCKSRXWjymg= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 4/4] spapr: Simplify ovec diff Date: Fri, 29 Nov 2019 16:33:56 +1100 Message-Id: <20191129053356.232413-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129053356.232413-1-david@gibson.dropbear.id.au> References: <20191129053356.232413-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, David Gibson , qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" spapr_ovec_diff(ov, old, new) has somewhat complex semantics. ov is set to those bits which are in new but not old, and it returns as a boolean whether or not there are any bits in old but not new. It turns out that both callers only care about the second, not the first. This is basically equivalent to a bitmap subset operation, which is easier to understand and implement. So replace spapr_ovec_diff() with spapr_ovec_subset(). Cc: Mike Roth Signed-off-by: David Gibson Reviewed-by: Cedric Le Goater --- hw/ppc/spapr.c | 14 +++----------- hw/ppc/spapr_hcall.c | 8 ++------ hw/ppc/spapr_ovec.c | 30 ++++++++++-------------------- include/hw/ppc/spapr_ovec.h | 4 +--- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5187f5b0a5..32e1cc1d3f 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1840,8 +1840,6 @@ static bool spapr_ov5_cas_needed(void *opaque) { SpaprMachineState *spapr =3D opaque; SpaprOptionVector *ov5_mask =3D spapr_ovec_new(); - SpaprOptionVector *ov5_legacy =3D spapr_ovec_new(); - SpaprOptionVector *ov5_removed =3D spapr_ovec_new(); bool cas_needed; =20 /* Prior to the introduction of SpaprOptionVector, we had two option @@ -1873,17 +1871,11 @@ static bool spapr_ov5_cas_needed(void *opaque) spapr_ovec_set(ov5_mask, OV5_DRCONF_MEMORY); spapr_ovec_set(ov5_mask, OV5_DRMEM_V2); =20 - /* spapr_ovec_diff returns true if bits were removed. we avoid using - * the mask itself since in the future it's possible "legacy" bits may= be - * removed via machine options, which could generate a false positive - * that breaks migration. - */ - spapr_ovec_intersect(ov5_legacy, spapr->ov5, ov5_mask); - cas_needed =3D spapr_ovec_diff(ov5_removed, spapr->ov5, ov5_legacy); + /* We need extra information if we have any bits outside the mask + * defined above */ + cas_needed =3D !spapr_ovec_subset(spapr->ov5, ov5_mask); =20 spapr_ovec_cleanup(ov5_mask); - spapr_ovec_cleanup(ov5_legacy); - spapr_ovec_cleanup(ov5_removed); =20 return cas_needed; } diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 0f19be794c..f1799b1b70 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1671,7 +1671,7 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, target_ulong fdt_bufsize =3D args[2]; target_ulong ov_table; uint32_t cas_pvr; - SpaprOptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; + SpaprOptionVector *ov1_guest, *ov5_guest, *ov5_cas_old; bool guest_radix; Error *local_err =3D NULL; bool raw_mode_supported =3D false; @@ -1770,9 +1770,7 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, /* capabilities that have been added since CAS-generated guest reset. * if capabilities have since been removed, generate another reset */ - ov5_updates =3D spapr_ovec_new(); - spapr->cas_reboot =3D spapr_ovec_diff(ov5_updates, - ov5_cas_old, spapr->ov5_cas); + spapr->cas_reboot =3D !spapr_ovec_subset(ov5_cas_old, spapr->ov5_cas); spapr_ovec_cleanup(ov5_cas_old); /* Now that processing is finished, set the radix/hash bit for the * guest if it requested a valid mode; otherwise terminate the boot. */ @@ -1849,8 +1847,6 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, spapr->fdt_blob =3D fdt; } =20 - spapr_ovec_cleanup(ov5_updates); - if (spapr->cas_reboot) { qemu_system_reset_request(SHUTDOWN_CAUSE_SUBSYSTEM_RESET); } diff --git a/hw/ppc/spapr_ovec.c b/hw/ppc/spapr_ovec.c index 811fadf143..0ff6d1aeae 100644 --- a/hw/ppc/spapr_ovec.c +++ b/hw/ppc/spapr_ovec.c @@ -76,31 +76,21 @@ void spapr_ovec_intersect(SpaprOptionVector *ov, bitmap_and(ov->bitmap, ov1->bitmap, ov2->bitmap, OV_MAXBITS); } =20 -/* returns true if options bits were removed, false otherwise */ -bool spapr_ovec_diff(SpaprOptionVector *ov, - SpaprOptionVector *ov_old, - SpaprOptionVector *ov_new) +/* returns true if ov1 has a subset of bits in ov2 */ +bool spapr_ovec_subset(SpaprOptionVector *ov1, SpaprOptionVector *ov2) { - unsigned long *change_mask =3D bitmap_new(OV_MAXBITS); - unsigned long *removed_bits =3D bitmap_new(OV_MAXBITS); - bool bits_were_removed =3D false; + unsigned long *tmp =3D bitmap_new(OV_MAXBITS); + bool result; =20 - g_assert(ov); - g_assert(ov_old); - g_assert(ov_new); - - bitmap_xor(change_mask, ov_old->bitmap, ov_new->bitmap, OV_MAXBITS); - bitmap_and(ov->bitmap, ov_new->bitmap, change_mask, OV_MAXBITS); - bitmap_and(removed_bits, ov_old->bitmap, change_mask, OV_MAXBITS); + g_assert(ov1); + g_assert(ov2); =20 - if (!bitmap_empty(removed_bits, OV_MAXBITS)) { - bits_were_removed =3D true; - } + bitmap_andnot(tmp, ov1->bitmap, ov2->bitmap, OV_MAXBITS); + result =3D bitmap_empty(tmp, OV_MAXBITS); =20 - g_free(change_mask); - g_free(removed_bits); + g_free(tmp); =20 - return bits_were_removed; + return result; } =20 void spapr_ovec_cleanup(SpaprOptionVector *ov) diff --git a/include/hw/ppc/spapr_ovec.h b/include/hw/ppc/spapr_ovec.h index 7891e9caac..2bed517a2b 100644 --- a/include/hw/ppc/spapr_ovec.h +++ b/include/hw/ppc/spapr_ovec.h @@ -66,9 +66,7 @@ SpaprOptionVector *spapr_ovec_clone(SpaprOptionVector *ov= _orig); void spapr_ovec_intersect(SpaprOptionVector *ov, SpaprOptionVector *ov1, SpaprOptionVector *ov2); -bool spapr_ovec_diff(SpaprOptionVector *ov, - SpaprOptionVector *ov_old, - SpaprOptionVector *ov_new); +bool spapr_ovec_subset(SpaprOptionVector *ov1, SpaprOptionVector *ov2); void spapr_ovec_cleanup(SpaprOptionVector *ov); void spapr_ovec_set(SpaprOptionVector *ov, long bitnr); void spapr_ovec_clear(SpaprOptionVector *ov, long bitnr); --=20 2.23.0