From nobody Mon Feb 9 16:54:02 2026 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632982954978724.6354655188995; Wed, 29 Sep 2021 23:22:34 -0700 (PDT) Received: from localhost ([::1]:41022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVpSj-0006Qg-Jd for importer@patchew.org; Thu, 30 Sep 2021 02:22:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVot7-0002Ny-UM; Thu, 30 Sep 2021 01:45:45 -0400 Received: from gandalf.ozlabs.org ([2404:9400:2:0:216:3eff:fee2:21ea]:53215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVot6-00044m-1O; Thu, 30 Sep 2021 01:45:45 -0400 Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4HKhyR3y5gz4xc6; Thu, 30 Sep 2021 15:44:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1632980671; bh=yAY+LD8MQArIJOi80Rk5/239hHY0FX96UQCZuSlFHxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yb4MiWax/qyb2Nk5l5p7VCxurLQGMDk6X7DRVeG5pV2Sd6NA+L3uhU1gWpnsWp+aZ IQTkkVTuCQZ/06Lkc1wD4m8/lrNR18qB2B/dEI/Elrhat4hXT3jE7GklaFMlK3AhCc L5Wo1d24mYARjfctw8m/g+NDTTDkpNVsCZQ0XPYg= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 37/44] spapr_numa.c: fixes in spapr_numa_FORM2_write_rtas_tables() Date: Thu, 30 Sep 2021 15:44:19 +1000 Message-Id: <20210930054426.357344-38-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210930054426.357344-1-david@gibson.dropbear.id.au> References: <20210930054426.357344-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2404:9400:2:0:216:3eff:fee2:21ea; envelope-from=dgibson@gandalf.ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: Daniel Henrique Barboza , mark.cave-ayland@ilande.co.uk, qemu-devel@nongnu.org, groug@kaod.org, hpoussin@reactos.org, clg@kaod.org, qemu-ppc@nongnu.org, philmd@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-ZM-MESSAGEID: 1632982955816100001 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza This patch has a handful of modifications for the recent added FORM2 support: - to not allocate more than the necessary size in 'distance_table'. At this moment the array is oversized due to allocating uint32_t for all elements, when most of them fits in an uint8_t. Fix it by changing the array to uint8_t and allocating the exact size; - use stl_be_p() to store the uint32_t at the start of 'distance_table'; - use sizeof(uint32_t) to skip the uint32_t length when populating the distances; - use the NUMA_DISTANCE_MIN macro from sysemu/numa.h to avoid hardcoding the local distance value. Signed-off-by: Daniel Henrique Barboza Message-Id: <20210922122852.130054-2-danielhb413@gmail.com> Reviewed-by: Greg Kurz Signed-off-by: David Gibson --- hw/ppc/spapr_numa.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 58d5dc7084..5822938448 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -502,9 +502,8 @@ static void spapr_numa_FORM2_write_rtas_tables(SpaprMac= hineState *spapr, int nb_numa_nodes =3D ms->numa_state->num_nodes; int distance_table_entries =3D nb_numa_nodes * nb_numa_nodes; g_autofree uint32_t *lookup_index_table =3D NULL; - g_autofree uint32_t *distance_table =3D NULL; + g_autofree uint8_t *distance_table =3D NULL; int src, dst, i, distance_table_size; - uint8_t *node_distances; =20 /* * ibm,numa-lookup-index-table: array with length and a @@ -531,11 +530,13 @@ static void spapr_numa_FORM2_write_rtas_tables(SpaprM= achineState *spapr, * array because NUMA ids can be sparse (node 0 is the first, * node 8 is the second ...). */ - distance_table =3D g_new0(uint32_t, distance_table_entries + 1); - distance_table[0] =3D cpu_to_be32(distance_table_entries); + distance_table_size =3D distance_table_entries * sizeof(uint8_t) + + sizeof(uint32_t); + distance_table =3D g_new0(uint8_t, distance_table_size); + stl_be_p(distance_table, distance_table_entries); =20 - node_distances =3D (uint8_t *)&distance_table[1]; - i =3D 0; + /* Skip the uint32_t array length at the start */ + i =3D sizeof(uint32_t); =20 for (src =3D 0; src < nb_numa_nodes; src++) { for (dst =3D 0; dst < nb_numa_nodes; dst++) { @@ -546,16 +547,14 @@ static void spapr_numa_FORM2_write_rtas_tables(SpaprM= achineState *spapr, * adding the numa_info to retrieve distance info from. */ if (src =3D=3D dst) { - node_distances[i++] =3D 10; + distance_table[i++] =3D NUMA_DISTANCE_MIN; continue; } =20 - node_distances[i++] =3D numa_info[src].distance[dst]; + distance_table[i++] =3D numa_info[src].distance[dst]; } } =20 - distance_table_size =3D distance_table_entries * sizeof(uint8_t) + - sizeof(uint32_t); _FDT(fdt_setprop(fdt, rtas, "ibm,numa-distance-table", distance_table, distance_table_size)); } --=20 2.31.1