From nobody Tue Nov 11 10:10:18 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1565678873; cv=none; d=zoho.com; s=zohoarc; b=dZu3INdZJ0g966k2jTUamLezXVaCTE6R7erbS4EVCRKJqpQXYrjgF3nQ3+JHgMCLoC9sXpdYUv37MR/R4kYsEre35VmB9UTy1n9r01faylsLYVy8ptpOCrsW6pw962wllimdZOP2o8jn+A3fsx+s+3R41UtfNCszEYXZbv2pbiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565678873; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=UW/4vmQk4pHIF55J4prx3rTGQLXuAGTIBFj0YVo/x04=; b=H6LsfCGu/0Sr616HbcabzIcpG5UTtyfe5R/OA/I0YLrwKb+SwAxoaf9PMNsM+tAgM1DOUkaSO5smM5LMwATcyTFFHDfn6lzAwPcUGyuJdvVm4DcYmTVsxeFJ0D+wt1ynA7V+56dgWLNjc9amb91OzmwtrxjE5weaoJ+vncIjRzk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 156567887366092.95366137576991; Mon, 12 Aug 2019 23:47:53 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQaY-0000Av-6P; Tue, 13 Aug 2019 06:47:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQaX-0000Am-L0 for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:47:21 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8d23aee8-bd50-11e9-8c9b-d7f7162dcfcd; Mon, 12 Aug 2019 22:28:47 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.xilinx.com (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E881820820; Mon, 12 Aug 2019 22:28:46 +0000 (UTC) X-Inumbo-ID: 8d23aee8-bd50-11e9-8c9b-d7f7162dcfcd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565648927; bh=1csM4IPo06ByYY4SlciFz8edTx3fDto1QEZU0aSOS1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TzpvlUAxJejiUTnOt2PJX2aoZnknnik7zTW9EcNV79o8X9ktB/dYdgx8HuHCh/nJe ByZtwjoX6MF1dkz+aQo8ue0iAH55QECLl2tfg7oG7seRnk0d6yHDVGk0npbW6dWiAV SO6QHU+WDhSvaaYzJpIXGvUAXhkZLfz8T+8V6rFM= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 15:28:40 -0700 Message-Id: <20190812222844.9636-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v5 3/7] xen/arm: keep track of reserved-memory regions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) As we parse the device tree in Xen, keep track of the reserved-memory regions as they need special treatment (follow-up patches will make use of the stored information.) Reuse process_memory_node to add reserved-memory regions to the bootinfo.reserved_mem array. Refuse to continue once we reach the max number of reserved memory regions to avoid accidentally mapping any portions of them into a VM. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v5: - remove unneeded cast - remove unneeded strlen check - don't pass address_cells, size_cells, depth to device_tree_for_each_node Changes in v4: - depth + 1 in process_reserved_memory_node - pass address_cells and size_cells to device_tree_for_each_node - pass struct meminfo * instead of a boolean to process_memory_node - improve in-code comment - use a separate process_reserved_memory_node (separate from process_memory_node) function wrapper to have different error handling Changes in v3: - match only /reserved-memory - put the warning back in place for reg not present on a normal memory region - refuse to continue once we reach the max number of reserved memory regions Changes in v2: - call process_memory_node from process_reserved_memory_node to avoid duplication --- xen/arch/arm/bootfdt.c | 41 +++++++++++++++++++++++++++++++------ xen/include/asm-arm/setup.h | 1 + 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 590b14304c..0b0e22a3d0 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -136,6 +136,7 @@ static int __init process_memory_node(const void *fdt, = int node, const __be32 *cell; paddr_t start, size; u32 reg_cells =3D address_cells + size_cells; + struct meminfo *mem =3D data; =20 if ( address_cells < 1 || size_cells < 1 ) return -ENOENT; @@ -147,21 +148,46 @@ static int __init process_memory_node(const void *fdt= , int node, cell =3D (const __be32 *)prop->data; banks =3D fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); =20 - for ( i =3D 0; i < banks && bootinfo.mem.nr_banks < NR_MEM_BANKS; i++ ) + for ( i =3D 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ ) { device_tree_get_reg(&cell, address_cells, size_cells, &start, &siz= e); if ( !size ) continue; - bootinfo.mem.bank[bootinfo.mem.nr_banks].start =3D start; - bootinfo.mem.bank[bootinfo.mem.nr_banks].size =3D size; - bootinfo.mem.nr_banks++; + mem->bank[mem->nr_banks].start =3D start; + mem->bank[mem->nr_banks].size =3D size; + mem->nr_banks++; } =20 - if ( bootinfo.mem.nr_banks =3D=3D NR_MEM_BANKS ) + if ( mem->nr_banks =3D=3D NR_MEM_BANKS ) return -ENOSPC; return 0; } =20 +static int __init process_reserved_memory_node(const void *fdt, int node, + const char *name, int depth, + u32 address_cells, + u32 size_cells, + void *data) +{ + int rc =3D process_memory_node(fdt, node, name, depth, address_cells, + size_cells, data); + + if ( rc =3D=3D -ENOSPC ) + panic("Max number of supported reserved-memory regions reached."); + else if ( rc !=3D -ENOENT ) + return rc; + return 0; +} + +static int __init process_reserved_memory(const void *fdt, int node, + const char *name, int depth, + u32 address_cells, u32 size_cell= s) +{ + return device_tree_for_each_node(fdt, node, + process_reserved_memory_node, + &bootinfo.reserved_mem); +} + static void __init process_multiboot_node(const void *fdt, int node, const char *name, u32 address_cells, u32 size_cell= s) @@ -295,7 +321,10 @@ static int __init early_scan_node(const void *fdt, =20 if ( device_tree_node_matches(fdt, node, "memory") ) rc =3D process_memory_node(fdt, node, name, depth, - address_cells, size_cells, NULL); + address_cells, size_cells, &bootinfo.mem); + else if ( depth =3D=3D 1 && !strcmp(name, "reserved-memory") ) + rc =3D process_reserved_memory(fdt, node, name, depth, + address_cells, size_cells); else if ( depth <=3D 3 && (device_tree_node_compatible(fdt, node, "xen= ,multiboot-module" ) || device_tree_node_compatible(fdt, node, "multiboot,module" ))) process_multiboot_node(fdt, node, name, address_cells, size_cells); diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index 8bf3d5910a..efcba545c2 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -66,6 +66,7 @@ struct bootcmdlines { =20 struct bootinfo { struct meminfo mem; + struct meminfo reserved_mem; struct bootmodules modules; struct bootcmdlines cmdlines; #ifdef CONFIG_ACPI --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel