From nobody Fri May 3 19:48:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1636499926; cv=none; d=zohomail.com; s=zohoarc; b=PMnKFyBgNk7uJuaHbkskwI9olAUOoTB2tTQvUTo6D/ljnNz4pbV3dtOlZfq0F+poC/SvvlLpyhXyuT+UsT1KCAeoSzVpLsZaTUTKyB67OfDcPu82qUTGlcHx+Kx/Z+MhIVP8lL81zC6ERGtbAJBA2b1e7USyFED3IUMbc0V2OMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636499926; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=j9krEFKTL7KFUypWXYGFuJHU4G8JpZ/uGyFNDMTmDcU=; b=aZyn+2jlpRW8gamUz5t/YMGTX9mpbvg9n/kyTU84Ey7KNEvrUPyOpPUJQVyBLKL+6hKlZtljKEOEUffM/B91Kh2g8yRTrxpPcVyCbFc1FLf1Nzt8Wcb96SqlGSL4NPqSMnnqBUNYclpvg8oFjpWEzzADqu460atNps1ilh0ujMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1636499926930457.55660268546694; Tue, 9 Nov 2021 15:18:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.224147.387256 (Exim 4.92) (envelope-from ) id 1mkaNq-0005p7-CY; Tue, 09 Nov 2021 23:18:30 +0000 Received: by outflank-mailman (output) from mailman id 224147.387256; Tue, 09 Nov 2021 23:18:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mkaNq-0005p0-9N; Tue, 09 Nov 2021 23:18:30 +0000 Received: by outflank-mailman (input) for mailman id 224147; Tue, 09 Nov 2021 23:18:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mkaNp-0005ou-GM for xen-devel@lists.xenproject.org; Tue, 09 Nov 2021 23:18:29 +0000 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5771ed6f-41b3-11ec-a9d2-d9f7a1cc8784; Wed, 10 Nov 2021 00:18:28 +0100 (CET) Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C18561184; Tue, 9 Nov 2021 23:18:25 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5771ed6f-41b3-11ec-a9d2-d9f7a1cc8784 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636499906; bh=OxUWFDEDkNrUSwgkt3sGH9Y+1YXvIqRgEzBbuJTC630=; h=From:To:Cc:Subject:Date:From; b=BkdFJsKeRpOIZfAQLgtlIRysg25a87ntJfH7e8sEq1R8MFI2QYdlFtd6U/ZetY7LH SE3M7OcH25KIzC0Jg94GVLLbks9qixJiSoLuS/4AbNHQYACaBGWeCU9dEiaQtJs5J6 /xlE894b+CxH6yJn5fowiXDA1yR10od3yG/SRTY4oG4sBta3KWnDaD7JX2OMTzCNhf a1dZdJwrJYh6ma8sGuw+C3YM8J0pNWeT02bVsM5K58Dh4Fw86M60Ts/gRKeYcQ/KcR rTv3FS/ZxvhzStz83vo7RreNijmUMV7KJ1UMMPpJYHhNu0eZXlu6LsfCn90RJri4/d tD3+9PGZbw50w== From: Stefano Stabellini To: julien@xen.org Cc: sstabellini@kernel.org, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Wei.Chen@arm.com, iwj@xenproject.org, Volodymyr_Babchuk@epam.com, xen-devel@lists.xenproject.org, Stefano Stabellini Subject: [PATCH v2] xen/arm: don't assign domU static-mem to dom0 as reserved-memory Date: Tue, 9 Nov 2021 15:18:17 -0800 Message-Id: <20211109231817.587168-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1636499928158100001 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini DomUs static-mem ranges are added to the reserved_mem array for accounting, but they shouldn't be assigned to dom0 as the other regular reserved-memory ranges in device tree. In make_memory_nodes, fix the error by skipping banks with xen_domain set to true in the reserved-memory array. Also make sure to use the first valid (!xen_domain) start address for the memory node name. Fixes: 41c031ff437b ("xen/arm: introduce domain on Static Allocation") Signed-off-by: Stefano Stabellini Release-Acked-by: Ian Jackson --- Changes in v2: - improve commit message - improve in-code comment - update nr_cells appropriately --- xen/arch/arm/domain_build.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 9e92b640cd..c81a2bdfef 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -862,21 +862,25 @@ static int __init make_memory_node(const struct domai= n *d, { int res, i; int reg_size =3D addrcells + sizecells; - int nr_cells =3D reg_size * mem->nr_banks; + int nr_cells =3D 0; /* Placeholder for memory@ + a 64-bit number + \0 */ char buf[24]; __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */]; __be32 *cells; =20 - BUG_ON(nr_cells >=3D ARRAY_SIZE(reg)); if ( mem->nr_banks =3D=3D 0 ) return -ENOENT; =20 - dt_dprintk("Create memory node (reg size %d, nr cells %d)\n", - reg_size, nr_cells); + /* find first memory range not bound to a Xen domain */ + for ( i =3D 0; i < mem->nr_banks && mem->bank[i].xen_domain; i++ ) + ; + if ( i =3D=3D mem->nr_banks ) + return 0; + + dt_dprintk("Create memory node\n"); =20 /* ePAPR 3.4 */ - snprintf(buf, sizeof(buf), "memory@%"PRIx64, mem->bank[0].start); + snprintf(buf, sizeof(buf), "memory@%"PRIx64, mem->bank[i].start); res =3D fdt_begin_node(fdt, buf); if ( res ) return res; @@ -886,17 +890,24 @@ static int __init make_memory_node(const struct domai= n *d, return res; =20 cells =3D ®[0]; - for ( i =3D 0 ; i < mem->nr_banks; i++ ) + for ( ; i < mem->nr_banks; i++ ) { u64 start =3D mem->bank[i].start; u64 size =3D mem->bank[i].size; =20 + if ( mem->bank[i].xen_domain ) + continue; + dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n", i, start, start + size); =20 + nr_cells +=3D reg_size; dt_child_set_range(&cells, addrcells, sizecells, start, size); } =20 + dt_dprintk("(reg size %d, nr cells %d)\n", reg_size, nr_cells); + BUG_ON(nr_cells >=3D ARRAY_SIZE(reg)); + res =3D fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg)); if ( res ) return res; --=20 2.25.1