From nobody Tue Nov 11 13:36:58 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=1561161408; cv=none; d=zoho.com; s=zohoarc; b=c3MNe6kh0alBy/mq3JPmclu3UKRWfD87+PZpOnk+lR2ATcoeSP/XcuZPrSGPjMdibJV4ALED/XXuLUajPvMvrgSnGIiSPUbsDw0ZOBdFfYyqGR5sN0K1jd7inV1UYA2tdcbLZye08Xk0DsvPXBSg1xMOHDh+2SnvowHfzeCLepI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561161408; 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=qsIFOTrc/O7lhjvAUgOv64UtIWoKhknjRLrEr6pfq4A=; b=JvMlUJcppG0qQuv71brwKJDxON5xWSjNnWJGbtAFFAawnE6imObW5sowNAB0GH7IySowuFm7WonJ4A1nveCoT3dQd3gG+8B1GrfLZCTyutl07lUjuZRjqGf1sH55OsEIDOS/nU7dZNbVgloozoVDJ9n5Kc3a0NGSEeGImwMfqak= 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 1561161408491994.5018664525384; Fri, 21 Jun 2019 16:56:48 -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 1heTO9-0004W4-Gz; Fri, 21 Jun 2019 23:56:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heTO8-0004V5-A9 for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 23:56:12 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 24f0bd46-9480-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 23:56:11 +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 627E6208CA; Fri, 21 Jun 2019 23:56:10 +0000 (UTC) X-Inumbo-ID: 24f0bd46-9480-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561161370; bh=ooUl19J+IJwZ1PqFUpcffEM0Og0dNRoOvPVOxh2NX3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KYB9qNK6rDDwk6nE4MZoNevD99KLnTJytUfgd9JPYy5DK6Nz5jeBgbXBszCwrlF+A 1Y1DP9E7OItZjNzm0ynWBfjQ8EZVIqMOEaJLj533LcZPGW+se4G26WVsCidM5tCwz0 Usjf1J15+A6nwgjz7udwCtYDafiSM+alpLGyEbRQ= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 21 Jun 2019 16:56:05 -0700 Message-Id: <20190621235608.2153-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 3/6] 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 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 --- It is cleaner to avoid sharing the whole function process_memory_node between the normal memory case and the reserved-memory case. I'll do it in the next version once I understand the best way do to it. --- 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 | 38 +++++++++++++++++++++++++++++++------ xen/include/asm-arm/setup.h | 1 + 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 611724433b..b24ab10cb9 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -135,6 +135,8 @@ 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; + bool reserved =3D (bool)data; =20 if ( address_cells < 1 || size_cells < 1 ) { @@ -143,29 +145,49 @@ static int __init process_memory_node(const void *fdt= , int node, return 0; } =20 + if ( reserved ) + mem =3D &bootinfo.reserved_mem; + else + mem =3D &bootinfo.mem; + prop =3D fdt_get_property(fdt, node, "reg", NULL); if ( !prop ) { - printk("fdt: node `%s': missing `reg' property\n", name); + if ( !reserved ) + printk("fdt: node `%s': missing `reg' property\n", name); return 0; } =20 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++; } + /* + * We reached the max number of supported reserved-memory regions. + * Stop and refuse to continue. We don't want to risk Xen allocating + * those regions as normal memory to a VM. + */ + BUG_ON(reserved && mem->nr_banks =3D=3D NR_MEM_BANKS); =20 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) +{ + device_tree_for_each_node(fdt, node, depth, process_memory_node, (void= *)true); + return 0; +} + static void __init process_multiboot_node(const void *fdt, int node, const char *name, u32 address_cells, u32 size_cell= s) @@ -299,7 +321,11 @@ 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, (void*)false); + else if ( depth =3D=3D 1 && !strcmp(name, "reserved-memory") && + strlen(name) =3D=3D strlen("reserved-memory") ) + rc =3D process_reserved_memory_node(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