From: Greg Kurz <groug@kaod.org>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
clg@kaod.org, mdroth@linux.vnet.ibm.com
Subject: Re: [for-5.0 2/4] spapr: Improve handling of fdt buffer size
Date: Mon, 2 Dec 2019 08:52:27 +0100 [thread overview]
Message-ID: <20191202085227.0077fc5a@bahia.w3ibm.bluemix.net> (raw)
In-Reply-To: <20191129053356.232413-3-david@gibson.dropbear.id.au>
On Fri, 29 Nov 2019 16:33:54 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:
> 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 <david@gibson.dropbear.id.au>
> ---
Reviewed-by: Greg Kurz <groug@kaod.org>
> 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;
> }
>
> -static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset);
> +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,
> @@ -930,24 +931,17 @@ int spapr_h_cas_compose_response(SpaprMachineState *spapr,
> return 1;
> }
>
> - 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);
> }
>
> size -= sizeof(hdr);
>
> - fdt = spapr_build_fdt(spapr, false);
> + fdt = spapr_build_fdt(spapr, false, size);
> _FDT((fdt_pack(fdt)));
>
> - 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 *spapr, void *fdt)
> }
> }
>
> -static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset)
> +static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset,
> + size_t space)
> {
> MachineState *machine = MACHINE(spapr);
> MachineClass *mc = MACHINE_GET_CLASS(machine);
> @@ -1207,8 +1202,8 @@ static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset)
> SpaprPhbState *phb;
> char *buf;
>
> - fdt = g_malloc0(FDT_MAX_SIZE);
> - _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE)));
> + fdt = g_malloc0(space);
> + _FDT((fdt_create_empty_tree(fdt, space)));
>
> /* Root node */
> _FDT(fdt_setprop_string(fdt, 0, "device_type", "chrp"));
> @@ -1723,19 +1718,13 @@ static void spapr_machine_reset(MachineState *machine)
> */
> fdt_addr = MIN(spapr->rma_size, RTAS_MAX_ADDR) - FDT_MAX_SIZE;
>
> - fdt = spapr_build_fdt(spapr, true);
> + fdt = spapr_build_fdt(spapr, true, FDT_MAX_SIZE);
>
> rc = fdt_pack(fdt);
>
> /* Should only fail if we've built a corrupted tree */
> assert(rc == 0);
>
> - 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));
next prev parent reply other threads:[~2019-12-02 7:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-29 5:33 [for-5.0 0/4] spapr: Improvements to CAS feature negotiation David Gibson
2019-11-29 5:33 ` [for-5.0 1/4] spapr: Don't trigger a CAS reboot for XICS/XIVE mode changeover David Gibson
2019-12-02 7:03 ` Cédric Le Goater
2019-12-02 7:50 ` Greg Kurz
2019-12-02 7:59 ` David Gibson
2019-11-29 5:33 ` [for-5.0 2/4] spapr: Improve handling of fdt buffer size David Gibson
2019-12-02 7:04 ` Cédric Le Goater
2019-12-02 7:52 ` Greg Kurz [this message]
2019-11-29 5:33 ` [for-5.0 3/4] spapr: Fold h_cas_compose_response() into h_client_architecture_support() David Gibson
2019-12-02 7:04 ` Cédric Le Goater
2019-12-02 8:23 ` Greg Kurz
2019-12-02 8:40 ` David Gibson
2019-11-29 5:33 ` [for-5.0 4/4] spapr: Simplify ovec diff David Gibson
2019-12-02 7:04 ` Cédric Le Goater
2019-12-02 7:05 ` [for-5.0 0/4] spapr: Improvements to CAS feature negotiation Cédric Le Goater
2019-12-03 5:00 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191202085227.0077fc5a@bahia.w3ibm.bluemix.net \
--to=groug@kaod.org \
--cc=clg@kaod.org \
--cc=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).