From patchwork Fri Jun 21 23:56:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11010849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CC936C5 for ; Fri, 21 Jun 2019 23:57:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3AB82870D for ; Fri, 21 Jun 2019 23:57:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E833028BAF; Fri, 21 Jun 2019 23:57:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8626F2870D for ; Fri, 21 Jun 2019 23:57:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heTO9-0004WO-RY; 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-0004V6-BZ for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 23:56:12 +0000 X-Inumbo-ID: 247e2e7d-9480-11e9-8980-bc764e045a96 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 247e2e7d-9480-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 23:56:10 +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 A0A29206B6; Fri, 21 Jun 2019 23:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561161369; bh=kGs74uz4c0uoAwjFV0wL1k7xd0I+FLY1Eo1BEY4gNTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GBCDsBxKEkNiT35VCiO1UcIFmC5D/bs0khSuI57hwieLKlooqgNajjpN6kdFIxiEK 1cKIaOluFkQpjeT6s6qQqJueHLmPTwXaQUPLuSqqIWXcLCkY9pcDMgyaLv2bbB1eB7 StfMEk7Z3IxpQ8y/25DQfFlKy3zzc5yQTJuPvKYs= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 21 Jun 2019 16:56:03 -0700 Message-Id: <20190621235608.2153-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 1/6] xen/arm: extend device_tree_for_each_node 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add two new parameters to device_tree_for_each_node: node and depth. Node is the parent node to start the search from and depth is the min depth of the search (the depth of the parent node). Passing 0, 0 triggers the old behavior. We need this change because in follow-up patches we want to be able to use reuse device_tree_for_each_node to call a function for each children nodes of a provided node. Signed-off-by: Stefano Stabellini --- Changes in v3: - improve commit message - improve in-code comments - improve code style Changes in v2: - new --- xen/arch/arm/acpi/boot.c | 2 +- xen/arch/arm/bootfdt.c | 12 ++++++------ xen/include/xen/device_tree.h | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c index 9b29769a10..cfc85c2b61 100644 --- a/xen/arch/arm/acpi/boot.c +++ b/xen/arch/arm/acpi/boot.c @@ -248,7 +248,7 @@ int __init acpi_boot_table_init(void) */ if ( param_acpi_off || ( !param_acpi_force && device_tree_for_each_node(device_tree_flattened, - dt_scan_depth1_nodes, NULL))) + 0, 0, dt_scan_depth1_nodes, NULL))) goto disable; /* diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 891b4b66ff..2f9cb8878d 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -77,6 +77,8 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, /** * device_tree_for_each_node - iterate over all device tree nodes * @fdt: flat device tree. + * @node: parent node to start the search from + * @depth: depth of the parent node * @func: function to call for each node. * @data: data to pass to @func. * @@ -86,17 +88,15 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, * returns a value different from 0, that value is returned immediately. */ int __init device_tree_for_each_node(const void *fdt, + int node, int depth, device_tree_node_func func, void *data) { - int node; - int depth; u32 address_cells[DEVICE_TREE_MAX_DEPTH]; u32 size_cells[DEVICE_TREE_MAX_DEPTH]; - int ret; + int ret, min_depth = depth; - for ( node = 0, depth = 0; - node >=0 && depth >= 0; + for ( ; node >= 0 && depth >= min_depth; node = fdt_next_node(fdt, node, &depth) ) { const char *name = fdt_get_name(fdt, node, NULL); @@ -357,7 +357,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false); - device_tree_for_each_node((void *)fdt, early_scan_node, NULL); + device_tree_for_each_node((void *)fdt, 0, 0, early_scan_node, NULL); early_print_info(); return fdt_totalsize(fdt); diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 83156297e2..e1ec6cb88d 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -159,8 +159,9 @@ typedef int (*device_tree_node_func)(const void *fdt, extern const void *device_tree_flattened; int device_tree_for_each_node(const void *fdt, - device_tree_node_func func, - void *data); + int node, int depth, + device_tree_node_func func, + void *data); /** * dt_unflatten_host_device_tree - Unflatten the host device tree From patchwork Fri Jun 21 23:56:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11010843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C42F186E for ; Fri, 21 Jun 2019 23:57:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5942870D for ; Fri, 21 Jun 2019 23:57:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82BC628BAF; Fri, 21 Jun 2019 23:57:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B5BCA28BAD for ; Fri, 21 Jun 2019 23:57:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heTO8-0004V7-6p; Fri, 21 Jun 2019 23:56:12 +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 1heTO7-0004Ux-8K for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 23:56:11 +0000 X-Inumbo-ID: 24b97cbe-9480-11e9-b046-cb2c7ff3e318 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 24b97cbe-9480-11e9-b046-cb2c7ff3e318; Fri, 21 Jun 2019 23:56:10 +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 098D1208C3; Fri, 21 Jun 2019 23:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561161370; bh=sLXpdeS0tb/a6NC7NCOzf0ZkhpfS0D3SVKzk+8JxSUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H0SbDpzIjwqfn5Jhi4GLMSLhZS7G1IVuqlga66IVkVj7eQ5XtmjusCxZPiObi5O4l xM8ffLwVTkTuF4+YP1cdz1+SpfpNlsyGnZnS8/kwg04Q0+OIyCnKnYIm/b5AVhZU8+ fSrNiozfytPddVdFiw6XbWPhEskRL8OAUHv92dRs= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 21 Jun 2019 16:56:04 -0700 Message-Id: <20190621235608.2153-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 2/6] xen/arm: make process_memory_node a device_tree_node_func 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change the signature of process_memory_node to match device_tree_node_func. Thanks to this change, the next patch will be able to use device_tree_for_each_node to call process_memory_node on all the children of a provided node. Signed-off-by: Stefano Stabellini --- Changes in v3: - improve commit message - check return value of process_memory_node Changes in v2: - new --- xen/arch/arm/bootfdt.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 2f9cb8878d..611724433b 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -124,9 +124,10 @@ int __init device_tree_for_each_node(const void *fdt, return 0; } -static void __init process_memory_node(const void *fdt, int node, - const char *name, - u32 address_cells, u32 size_cells) +static int __init process_memory_node(const void *fdt, int node, + const char *name, int depth, + u32 address_cells, u32 size_cells, + void *data) { const struct fdt_property *prop; int i; @@ -139,14 +140,14 @@ static void __init process_memory_node(const void *fdt, int node, { printk("fdt: node `%s': invalid #address-cells or #size-cells", name); - return; + return 0; } prop = fdt_get_property(fdt, node, "reg", NULL); if ( !prop ) { printk("fdt: node `%s': missing `reg' property\n", name); - return; + return 0; } cell = (const __be32 *)prop->data; @@ -161,6 +162,8 @@ static void __init process_memory_node(const void *fdt, int node, bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size; bootinfo.mem.nr_banks++; } + + return 0; } static void __init process_multiboot_node(const void *fdt, int node, @@ -292,15 +295,18 @@ static int __init early_scan_node(const void *fdt, u32 address_cells, u32 size_cells, void *data) { + int rc = 0; + if ( device_tree_node_matches(fdt, node, "memory") ) - process_memory_node(fdt, node, name, address_cells, size_cells); + rc = process_memory_node(fdt, node, name, depth, + address_cells, size_cells, NULL); else if ( depth <= 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); else if ( depth == 1 && device_tree_node_matches(fdt, node, "chosen") ) process_chosen_node(fdt, node, name, address_cells, size_cells); - return 0; + return rc; } static void __init early_print_info(void) From patchwork Fri Jun 21 23:56:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11010819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DABA46C5 for ; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB75E2870D for ; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFBEC28BAD; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4FE702870D for ; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) 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 X-Inumbo-ID: 24f0bd46-9480-11e9-8980-bc764e045a96 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) 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = address_cells + size_cells; + struct meminfo *mem; + bool reserved = (bool)data; if ( address_cells < 1 || size_cells < 1 ) { @@ -143,29 +145,49 @@ static int __init process_memory_node(const void *fdt, int node, return 0; } + if ( reserved ) + mem = &bootinfo.reserved_mem; + else + mem = &bootinfo.mem; + prop = 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; } cell = (const __be32 *)prop->data; banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); - for ( i = 0; i < banks && bootinfo.mem.nr_banks < NR_MEM_BANKS; i++ ) + for ( i = 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ ) { device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); if ( !size ) continue; - bootinfo.mem.bank[bootinfo.mem.nr_banks].start = start; - bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size; - bootinfo.mem.nr_banks++; + mem->bank[mem->nr_banks].start = start; + mem->bank[mem->nr_banks].size = 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 == NR_MEM_BANKS); return 0; } +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_cells) @@ -299,7 +321,11 @@ static int __init early_scan_node(const void *fdt, if ( device_tree_node_matches(fdt, node, "memory") ) rc = process_memory_node(fdt, node, name, depth, - address_cells, size_cells, NULL); + address_cells, size_cells, (void*)false); + else if ( depth == 1 && !strcmp(name, "reserved-memory") && + strlen(name) == strlen("reserved-memory") ) + rc = process_reserved_memory_node(fdt, node, name, depth, + address_cells, size_cells); else if ( depth <= 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 { struct bootinfo { struct meminfo mem; + struct meminfo reserved_mem; struct bootmodules modules; struct bootcmdlines cmdlines; #ifdef CONFIG_ACPI From patchwork Fri Jun 21 23:56:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11010853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD5C076 for ; Fri, 21 Jun 2019 23:57:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE91A2870D for ; Fri, 21 Jun 2019 23:57:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2E8D28BAD; Fri, 21 Jun 2019 23:57:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 41AA62870D for ; Fri, 21 Jun 2019 23:57:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heTOA-0004XO-JM; Fri, 21 Jun 2019 23:56:14 +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 1heTO8-0004VI-Ff for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 23:56:12 +0000 X-Inumbo-ID: 252ef43a-9480-11e9-8a87-cb80762533cf Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 252ef43a-9480-11e9-8a87-cb80762533cf; 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 C19A821530; Fri, 21 Jun 2019 23:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561161371; bh=xd6isYPxj9hWpPMW0MEOb61upETwKMmHwAnuRy4ymKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXtwr+/C11Vjc0WAUnRweNCdcdrIhZqw5gzocJaWuTT9pjpsV30sVs2YTJ6eOM/Df zw5oKLWyW34Bwgyx660MY4fNlRXTapbJLa0spqszqrQJoGcwusZ1mAprGAyYaPm7E+ Yfbc672L8KrksFVn3fvKmcv3rEz9Qd6vW3bUAf1w= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 21 Jun 2019 16:56:06 -0700 Message-Id: <20190621235608.2153-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 4/6] xen/arm: handle reserved-memory in consider_modules and dt_unreserved_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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP reserved-memory regions overlap with memory nodes. The overlapping memory is reserved-memory and should be handled accordingly: consider_modules and dt_unreserved_regions should skip these regions the same way they are already skipping mem-reserve regions. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v3: - coding style - in-code comments Changes in v2: - fix commit message: full overlap - remove check_reserved_memory - extend consider_modules and dt_unreserved_regions --- xen/arch/arm/setup.c | 53 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 215746a5c3..d9cfb1aa2f 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -206,6 +206,28 @@ void __init dt_unreserved_regions(paddr_t s, paddr_t e, } } + /* + * i is the current bootmodule we are evaluating across all possible + * kinds. + * + * When retrieving the corresponding reserved-memory addresses + * below, we need to index the bootinfo.reserved_mem bank starting + * from 0, and only counting the reserved-memory modules. Hence, + * we need to use i - nr. + */ + for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + { + paddr_t r_s = bootinfo.reserved_mem.bank[i - nr].start; + paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + dt_unreserved_regions(r_e, e, cb, i+1); + dt_unreserved_regions(s, r_s, cb, i+1); + return; + } + } + cb(s, e); } @@ -392,7 +414,7 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, { const struct bootmodules *mi = &bootinfo.modules; int i; - int nr_rsvd; + int nr; s = (s+align-1) & ~(align-1); e = e & ~(align-1); @@ -418,9 +440,9 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, /* Now check any fdt reserved areas. */ - nr_rsvd = fdt_num_mem_rsv(device_tree_flattened); + nr = fdt_num_mem_rsv(device_tree_flattened); - for ( ; i < mi->nr_mods + nr_rsvd; i++ ) + for ( ; i < mi->nr_mods + nr; i++ ) { paddr_t mod_s, mod_e; @@ -442,6 +464,31 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, return consider_modules(s, mod_s, size, align, i+1); } } + + /* + * i is the current bootmodule we are evaluating, across all + * possible kinds of bootmodules. + * + * When retrieving the corresponding reserved-memory addresses, we + * need to index the bootinfo.reserved_mem bank starting from 0, and + * only counting the reserved-memory modules. Hence, we need to use + * i - nr. + */ + nr += mi->nr_mods; + for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + { + paddr_t r_s = bootinfo.reserved_mem.bank[i - nr].start; + paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + r_e = consider_modules(r_e, e, size, align, i + 1); + if ( r_e ) + return r_e; + + return consider_modules(s, r_s, size, align, i + 1); + } + } return e; } #endif From patchwork Fri Jun 21 23:56:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11010821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 281336C5 for ; Fri, 21 Jun 2019 23:57:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B20E28BAD for ; Fri, 21 Jun 2019 23:57:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FB0528BB1; Fri, 21 Jun 2019 23:57:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B723728BAD for ; Fri, 21 Jun 2019 23:57:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heTOA-0004Ws-7d; Fri, 21 Jun 2019 23:56:14 +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 1heTO8-0004VH-FM for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 23:56:12 +0000 X-Inumbo-ID: 2569bcfa-9480-11e9-8576-6743c81f8809 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2569bcfa-9480-11e9-8576-6743c81f8809; 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 2B2E221537; Fri, 21 Jun 2019 23:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561161371; bh=qHZHF64P4pb5q8gwpI51OTVazm0uZwlPIOGvXFN2SI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfr+Z8RLU60vnjR6yNcGru8bI1x3EfZzAI8J64jYjRQ4RqOnQJaGAQ9m8lAPJVBjU fO4XC02r8mIonKy5VxA/Bef8GKLvoUv9jUDxLE3DcbD4BgRrYjcyvb6tRu8eV15I/X EnaA0zviB8kGsFohf2KvqxX/XjokN4pujtb3oBuk= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 21 Jun 2019 16:56:07 -0700 Message-Id: <20190621235608.2153-5-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 5/6] xen/arm: don't iomem_permit_access for 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Don't allow reserved-memory regions to be remapped into any guests, until reserved-memory regions are properly supported in Xen. For now, do not call iomem_permit_access for them. Signed-off-by: Stefano Stabellini --- Changes in v4: - new patch --- xen/arch/arm/domain_build.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d9836779d1..76dd4bf6f9 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1158,15 +1158,22 @@ static int __init map_range_to_domain(const struct dt_device_node *dev, bool need_mapping = !dt_device_for_passthrough(dev); int res; - res = iomem_permit_access(d, paddr_to_pfn(addr), - paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); - if ( res ) + /* + * Don't give iomem permissions for reserved-memory ranges until + * reserved-memory support is complete. + */ + if ( strcmp(dt_node_name(dev), "reserved-memory") ) { - printk(XENLOG_ERR "Unable to permit to dom%d access to" - " 0x%"PRIx64" - 0x%"PRIx64"\n", - d->domain_id, - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); - return res; + res = iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); + return res; + } } if ( need_mapping ) From patchwork Fri Jun 21 23:56:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11010817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21E7476 for ; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 135752870D for ; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06EF828BAD; Fri, 21 Jun 2019 23:57:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9E2032870D for ; Fri, 21 Jun 2019 23:57:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heTOA-0004Xu-Ul; Fri, 21 Jun 2019 23:56:14 +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 1heTO8-0004Vh-Lx for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 23:56:12 +0000 X-Inumbo-ID: 25a31d42-9480-11e9-85fb-0f3bc153b142 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 25a31d42-9480-11e9-85fb-0f3bc153b142; Fri, 21 Jun 2019 23:56:12 +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 889D1215EA; Fri, 21 Jun 2019 23:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561161371; bh=OsGLz72IL7w4kLE/mYGoRyRf+rKLUXKwExD8YZIlHy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wsczEblBUtdSGub7SY+SlIIxXX3HSx+EUJI4j7onjhTqkBp20j7xdu2yhmxyyFOWp mkRUzUKrPgkDC8eVP/gzqwissaFe128uuHzwELB+QobsDaxHlWoCii1xyY7jw3+3Yp YspDlTwmo1/zlP3OlFexshTdWSB6pbxdQpL8H0dA= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 21 Jun 2019 16:56:08 -0700 Message-Id: <20190621235608.2153-6-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 6/6] xen/arm: add reserved-memory regions to the dom0 memory node 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reserved memory regions are automatically remapped to dom0. Their device tree nodes are also added to dom0 device tree. However, the dom0 memory node is not currently extended to cover the reserved memory regions ranges as required by the spec. This commit fixes it. Signed-off-by: Stefano Stabellini --- xen/arch/arm/domain_build.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 76dd4bf6f9..5047eb4c28 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -643,7 +643,8 @@ static int __init make_memory_node(const struct domain *d, { int res, i; int reg_size = addrcells + sizecells; - int nr_cells = reg_size*kinfo->mem.nr_banks; + int nr_cells = reg_size * (kinfo->mem.nr_banks + (is_hardware_domain(d) ? + bootinfo.reserved_mem.nr_banks : 0)); __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */]; __be32 *cells; @@ -673,6 +674,20 @@ static int __init make_memory_node(const struct domain *d, dt_child_set_range(&cells, addrcells, sizecells, start, size); } + if ( is_hardware_domain(d) ) + { + for ( i = 0; i < bootinfo.reserved_mem.nr_banks; i++ ) + { + u64 start = bootinfo.reserved_mem.bank[i].start; + u64 size = bootinfo.reserved_mem.bank[i].size; + + dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n", + i, start, start + size); + + dt_child_set_range(&cells, addrcells, sizecells, start, size); + } + } + res = fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg)); if ( res ) return res;