From patchwork Thu Aug 15 23:36:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096601 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 D6FCB112C for ; Thu, 15 Aug 2019 23:37:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C822B28671 for ; Thu, 15 Aug 2019 23:37:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9F3228987; Thu, 15 Aug 2019 23:37:39 +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 439DF28671 for ; Thu, 15 Aug 2019 23:37:39 +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 1hyPI8-0004Wo-L1; Thu, 15 Aug 2019 23:36:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hyPI7-0004Vy-Fi for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:23 +0000 X-Inumbo-ID: 7d63366a-bfb5-11e9-813a-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7d63366a-bfb5-11e9-813a-bc764e2007e4; Thu, 15 Aug 2019 23:36:22 +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 011BF206C2; Thu, 15 Aug 2019 23:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912182; bh=kdoEydHJ0lAk4rl0w+kwY2uJo4+7v9YoaAYrixw9Gq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mcTEsALRqmKKpF0hkKIw8+OkYF9f4B55o037GRD/lE1nyV/6Xy//SjYpyrSoyPKLT f/d+B8ME2HFIzabV7A7Kw6ab/SGmbgDbMn1eTIS0HjqtnwFld2j5kTSfV2UB6Ur8cK FuVvCvb/tZTSkxUfrdTvA+g85E2c/QnoJd4NksbQ= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:11 -0700 Message-Id: <20190815233618.31630-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 1/8] xen/arm: pass node to 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, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a new parameter to device_tree_for_each_node: node, the node to start the search from. Passing 0 triggers the old behavior. Set min_depth to depth of the current node + 1 to avoid scanning siblings of the initial node passed as an argument. Don't call func() on the parent node passed as an argument. Clarify the change in the comment on top of the function. Signed-off-by: Stefano Stabellini --- Changes in v6: - fix code style - don't call func() on the first node Changes in v5: - go back to v3 - code style improvement in acpi/boot.c - improve comments and commit message - increase min_depth to avoid parsing siblings - replace for with do/while loop and increase min_depth to avoid scanning siblings of the initial node - pass only node, calculate depth Changes in v3: - improve commit message - improve in-code comments - improve code style Changes in v2: - new --- xen/arch/arm/acpi/boot.c | 8 +++++--- xen/arch/arm/bootfdt.c | 34 ++++++++++++++++++++-------------- xen/include/xen/device_tree.h | 6 +++--- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c index 9b29769a10..bf9c78b02c 100644 --- a/xen/arch/arm/acpi/boot.c +++ b/xen/arch/arm/acpi/boot.c @@ -246,9 +246,11 @@ int __init acpi_boot_table_init(void) * - the device tree is not empty (it has more than just a /chosen node) * and ACPI has not been force enabled (acpi=force) */ - if ( param_acpi_off || ( !param_acpi_force - && device_tree_for_each_node(device_tree_flattened, - dt_scan_depth1_nodes, NULL))) + if ( param_acpi_off) + goto disable; + if ( !param_acpi_force && + device_tree_for_each_node(device_tree_flattened, 0, + dt_scan_depth1_nodes, NULL) ) goto disable; /* diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 891b4b66ff..f1614ef7fc 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -75,9 +75,10 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, } /** - * device_tree_for_each_node - iterate over all device tree nodes + * device_tree_for_each_node - iterate over all device tree sub-nodes * @fdt: flat device tree. - * @func: function to call for each node. + * @node: parent node to start the search from + * @func: function to call for each sub-node. * @data: data to pass to @func. * * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored. @@ -85,20 +86,18 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, * Returns 0 if all nodes were iterated over successfully. If @func * returns a value different from 0, that value is returned immediately. */ -int __init device_tree_for_each_node(const void *fdt, +int __init device_tree_for_each_node(const void *fdt, int node, device_tree_node_func func, void *data) { - int node; - int depth; + int depth = fdt_node_depth(fdt, node); + int min_depth = depth + 1; + int first_node = node; u32 address_cells[DEVICE_TREE_MAX_DEPTH]; u32 size_cells[DEVICE_TREE_MAX_DEPTH]; int ret; - for ( node = 0, depth = 0; - node >=0 && depth >= 0; - node = fdt_next_node(fdt, node, &depth) ) - { + do { const char *name = fdt_get_name(fdt, node, NULL); u32 as, ss; @@ -117,10 +116,17 @@ int __init device_tree_for_each_node(const void *fdt, size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells", ss); - ret = func(fdt, node, name, depth, as, ss, data); - if ( ret != 0 ) - return ret; - } + /* skip the first node */ + if ( node != first_node ) + { + ret = func(fdt, node, name, depth, as, ss, data); + if ( ret != 0 ) + return ret; + } + + node = fdt_next_node(fdt, node, &depth); + } while ( node >= 0 && depth >= min_depth ); + return 0; } @@ -357,7 +363,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, 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..9a7a8f2dab 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -158,9 +158,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 device_tree_for_each_node(const void *fdt, int node, + device_tree_node_func func, + void *data); /** * dt_unflatten_host_device_tree - Unflatten the host device tree From patchwork Thu Aug 15 23:36:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096611 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 3914813B1 for ; Thu, 15 Aug 2019 23:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AC0728671 for ; Thu, 15 Aug 2019 23:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E58F28987; Thu, 15 Aug 2019 23:38:02 +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 A5C6E28671 for ; Thu, 15 Aug 2019 23:38: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 1hyPI8-0004Wz-Te; Thu, 15 Aug 2019 23:36:24 +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 1hyPI8-0004WZ-5k for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:24 +0000 X-Inumbo-ID: 7dac2528-bfb5-11e9-8baa-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7dac2528-bfb5-11e9-8baa-12813bfff9fa; Thu, 15 Aug 2019 23:36:23 +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 73F3B2089E; Thu, 15 Aug 2019 23:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912182; bh=G3p5I60qpfIGdbFvY5MV5Azxe4+cOeULECZc45oO4YQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k4Xelb54yMw4wpC8qLnZ6+IK7PMyX7hzoeEvE07VJEYDklan1hDxgLqSFxcKqfz+a THE+WbdSYGbS+f5UeRzX3mtDBWadUqX03nFMvy4Qp5qgpLVcjvaV6KMpyYr5wQtiZh YbEpbvixyV2iqK07AEVastBmLiHcocQAzXmM/rHw= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:12 -0700 Message-Id: <20190815233618.31630-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 2/8] 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, Volodymyr_Babchuk@epam.com 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. Return error if there is no reg property or if nr_banks is reached. Let the caller deal with the error. Add a printk when device tree parsing fails. Signed-off-by: Stefano Stabellini --- Changes in v6: - fix out of space check - bring back printk when address_cells or size_cells are not properly set - return -EINVAL in that case (different from reg missing) - add printk when parsing fails - return -ENOENT when memory size is 0 Changes in v5: - return -ENOENT if address_cells or size_cells are not properly set Changes in v4: - return error if there is no reg propery, remove printk - return error if nr_banks is reached Changes in v3: - improve commit message - check return value of process_memory_node Changes in v2: - new --- xen/arch/arm/bootfdt.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index f1614ef7fc..9dc2c1352d 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -130,9 +130,10 @@ int __init device_tree_for_each_node(const void *fdt, int node, 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; @@ -145,15 +146,12 @@ static void __init process_memory_node(const void *fdt, int node, { printk("fdt: node `%s': invalid #address-cells or #size-cells", name); - return; + return -EINVAL; } prop = fdt_get_property(fdt, node, "reg", NULL); if ( !prop ) - { - printk("fdt: node `%s': missing `reg' property\n", name); - return; - } + return -ENOENT; cell = (const __be32 *)prop->data; banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); @@ -162,11 +160,15 @@ static void __init process_memory_node(const void *fdt, int node, { device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); if ( !size ) - continue; + return -ENOENT; bootinfo.mem.bank[bootinfo.mem.nr_banks].start = start; bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size; bootinfo.mem.nr_banks++; } + + if ( i < banks ) + return -ENOSPC; + return 0; } static void __init process_multiboot_node(const void *fdt, int node, @@ -298,15 +300,20 @@ 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; + if ( rc < 0 ) + printk("fdt: node `%s': parsing failed\n", name); + return rc; } static void __init early_print_info(void) From patchwork Thu Aug 15 23:36:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096605 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 B280F13B1 for ; Thu, 15 Aug 2019 23:37:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A456328671 for ; Thu, 15 Aug 2019 23:37:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98D0128987; Thu, 15 Aug 2019 23:37:41 +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 24EE028671 for ; Thu, 15 Aug 2019 23:37:41 +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 1hyPI9-0004XR-5v; Thu, 15 Aug 2019 23:36:25 +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 1hyPI8-0004Wd-7b for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:24 +0000 X-Inumbo-ID: 7deddf2c-bfb5-11e9-8baa-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7deddf2c-bfb5-11e9-8baa-12813bfff9fa; Thu, 15 Aug 2019 23:36:23 +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 E1BEF2133F; Thu, 15 Aug 2019 23:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912183; bh=VrkQfwclZMv2QSw41k+/p04NIYbK3QMdI8jQlpohiDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y2DFEsnY0CjOMbkC+3Gu0X3liT3Jf55khkSp47/5yjLO7y7bjm3gDhd0vIwhb29mr Doih+ORqGjQko/pq3eMEPrzm7m2bLgj6QWlmDdY4iIZYOjTBUAiw39NB8MUYpDFqY0 y2B4S3lJJy8VTnKx0EnBfccemq4NGe8aTDjyvxWo= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:13 -0700 Message-Id: <20190815233618.31630-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 3/8] 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 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 Acked-by: Julien Grall --- Changes in v6: - use dt_node_cmp - add acked-by 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 | 39 ++++++++++++++++++++++++++++++++----- xen/include/asm-arm/setup.h | 1 + 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 9dc2c1352d..f23ebaa188 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -141,6 +141,7 @@ 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 = data; if ( address_cells < 1 || size_cells < 1 ) { @@ -156,14 +157,14 @@ static int __init process_memory_node(const void *fdt, int node, 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 ) return -ENOENT; - 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++; } if ( i < banks ) @@ -171,6 +172,31 @@ static int __init process_memory_node(const void *fdt, int node, 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, + void *data) +{ + int rc = process_memory_node(fdt, node, name, depth, address_cells, + size_cells, data); + + if ( rc == -ENOSPC ) + panic("Max number of supported reserved-memory regions reached."); + else if ( rc != -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_cells) +{ + 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_cells) @@ -304,7 +330,10 @@ 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, &bootinfo.mem); + else if ( depth == 1 && !dt_node_cmp(name, "reserved-memory") ) + rc = process_reserved_memory(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 Thu Aug 15 23:36:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096613 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 83F85112C for ; Thu, 15 Aug 2019 23:38:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7537728671 for ; Thu, 15 Aug 2019 23:38:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69C7528987; Thu, 15 Aug 2019 23:38:03 +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 19E2428671 for ; Thu, 15 Aug 2019 23:38:03 +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 1hyPIA-0004Yd-FH; Thu, 15 Aug 2019 23:36:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hyPI8-0004Wn-L6 for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:24 +0000 X-Inumbo-ID: 7e2dfbfc-bfb5-11e9-a661-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7e2dfbfc-bfb5-11e9-a661-bc764e2007e4; Thu, 15 Aug 2019 23:36:24 +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 587EF2171F; Thu, 15 Aug 2019 23:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912183; bh=0uqIw7fi9ShLv/DkZ30VYPsmelaDyUQss+KOJVtuL50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HKiB2E6oJWOagzttb97ezGU1FithE4jz1g3eJiJoHQh+pY8FtFHczy1oeCKARSDBH puM23kbxYdN62Im//3oDksHSCWOKERAi6vLTIucWPZJpV4B+Inq7fdjUaDy8reVni+ M8mFWTkOFH4GWjR/0euWrVS5oneN7a+jxZYUKCC0= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:14 -0700 Message-Id: <20190815233618.31630-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 4/8] xen/arm: fix indentation in early_print_info 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP No functional changes. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- xen/arch/arm/bootfdt.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index f23ebaa188..a70a739bb0 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -354,15 +354,15 @@ static void __init early_print_info(void) for ( i = 0; i < mi->nr_banks; i++ ) printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n", - mi->bank[i].start, - mi->bank[i].start + mi->bank[i].size - 1); + mi->bank[i].start, + mi->bank[i].start + mi->bank[i].size - 1); printk("\n"); for ( i = 0 ; i < mods->nr_mods; i++ ) printk("MODULE[%d]: %"PRIpaddr" - %"PRIpaddr" %-12s\n", - i, - mods->module[i].start, - mods->module[i].start + mods->module[i].size, - boot_module_kind_as_string(mods->module[i].kind)); + i, + mods->module[i].start, + mods->module[i].start + mods->module[i].size, + boot_module_kind_as_string(mods->module[i].kind)); nr_rsvd = fdt_num_mem_rsv(device_tree_flattened); for ( i = 0; i < nr_rsvd; i++ ) @@ -372,8 +372,7 @@ static void __init early_print_info(void) continue; /* fdt_get_mem_rsv returns length */ e += s; - printk(" RESVD[%d]: %"PRIpaddr" - %"PRIpaddr"\n", - i, s, e); + printk(" RESVD[%d]: %"PRIpaddr" - %"PRIpaddr"\n", i, s, e); } printk("\n"); for ( i = 0 ; i < cmds->nr_mods; i++ ) From patchwork Thu Aug 15 23:36:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096607 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 8E52813B1 for ; Thu, 15 Aug 2019 23:37:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 816A828671 for ; Thu, 15 Aug 2019 23:37:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75BE128987; Thu, 15 Aug 2019 23:37:42 +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 0FEB428671 for ; Thu, 15 Aug 2019 23:37:42 +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 1hyPIA-0004Z3-PR; Thu, 15 Aug 2019 23:36:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hyPI9-0004XA-27 for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:25 +0000 X-Inumbo-ID: 7e6f1f7e-bfb5-11e9-b90c-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7e6f1f7e-bfb5-11e9-b90c-bc764e2007e4; Thu, 15 Aug 2019 23:36:24 +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 BE76E21721; Thu, 15 Aug 2019 23:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912184; bh=dY1+4C6ioFzT1qk7+UYhtydOtn73tdyVnlbfaPw3Sq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vV60XGEn6G9C6V20HcSz+yP15ka73BAb4oOUe9S6GXIiOAFAho5Z8FeatHehJJ0+v 5sEoBfcmjeN4YX6gLXd1odfS0YyL0n7FX9Kgy1Qfm+HFsF1VcuvYE/6U26HLa5zMmp l8WWoCaTiLqogDCOkPhyQrJlFIDhqSlKSyyFDQws= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:15 -0700 Message-Id: <20190815233618.31630-5-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 5/8] xen/arm: early_print_info print reserved_mem 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Improve early_print_info to also print the banks saved in bootinfo.reserved_mem. Print them right after RESVD, increasing the same index. Since we are at it, also switch the existing RESVD print to use unsigned int. Signed-off-by: Stefano Stabellini Reviewed-by: Volodymyr Babchuk Acked-by: Julien Grall --- Changes in v6: - add acked-by and reviewed-by - fix indentation Changes in v5: - switch to unsigned Changes in v4: - new patch --- xen/arch/arm/bootfdt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index a70a739bb0..a02c6a1065 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -348,9 +348,10 @@ static int __init early_scan_node(const void *fdt, static void __init early_print_info(void) { struct meminfo *mi = &bootinfo.mem; + struct meminfo *mem_resv = &bootinfo.reserved_mem; struct bootmodules *mods = &bootinfo.modules; struct bootcmdlines *cmds = &bootinfo.cmdlines; - int i, nr_rsvd; + unsigned int i, j, nr_rsvd; for ( i = 0; i < mi->nr_banks; i++ ) printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n", @@ -372,7 +373,13 @@ static void __init early_print_info(void) continue; /* fdt_get_mem_rsv returns length */ e += s; - printk(" RESVD[%d]: %"PRIpaddr" - %"PRIpaddr"\n", i, s, e); + printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i, s, e); + } + for ( j = 0; j < mem_resv->nr_banks; j++, i++ ) + { + printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i, + mem_resv->bank[j].start, + mem_resv->bank[j].start + mem_resv->bank[j].size - 1); } printk("\n"); for ( i = 0 ; i < cmds->nr_mods; i++ ) From patchwork Thu Aug 15 23:36:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096615 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 BA33C13B1 for ; Thu, 15 Aug 2019 23:38:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB65828671 for ; Thu, 15 Aug 2019 23:38:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FDA028988; Thu, 15 Aug 2019 23:38:06 +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 3BA1328671 for ; Thu, 15 Aug 2019 23:38: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 1hyPIB-0004ZW-51; Thu, 15 Aug 2019 23:36:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hyPI9-0004Xw-IP for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:25 +0000 X-Inumbo-ID: 7eaf1c78-bfb5-11e9-a661-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7eaf1c78-bfb5-11e9-a661-bc764e2007e4; Thu, 15 Aug 2019 23:36:25 +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 361F62173B; Thu, 15 Aug 2019 23:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912184; bh=0bgcGpcMk+jFDiW7wNFctOouGU3NAg189hzDhO+IHyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oC9mJ9Pywc3+SfOdMkieWBrAE+qcqspRhVzErvBVrHmJcKsy4JHSxqcTRe8jbXpM8 q/7s3Lfm71J8RYiFa5MFKT17WHA85x/KkLdhrwQfdhIPuMHuXh/01WExbsua+x9FSL jwoao8Nl7Vb+8XZLIYGeO95tqoIABrokg2uy81YU= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:16 -0700 Message-Id: <20190815233618.31630-6-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 6/8] 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, Volodymyr_Babchuk@epam.com 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 v4: - code style - add acked-by 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..bc4082296e 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 Thu Aug 15 23:36:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096603 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 6CB0756FF for ; Thu, 15 Aug 2019 23:37:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F77128671 for ; Thu, 15 Aug 2019 23:37:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 536AA28987; Thu, 15 Aug 2019 23:37: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 F3A1D28671 for ; Thu, 15 Aug 2019 23:37:39 +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 1hyPIB-0004aS-Mp; Thu, 15 Aug 2019 23:36:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hyPI9-0004YI-Vh for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:26 +0000 X-Inumbo-ID: 7efa37f8-bfb5-11e9-b90c-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7efa37f8-bfb5-11e9-b90c-bc764e2007e4; Thu, 15 Aug 2019 23:36:25 +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 9ECCB2173E; Thu, 15 Aug 2019 23:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912184; bh=AThwz4wThr4JPginnrcX3zZoiJJtt2Vt6Zaw7pTFK9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ClFHFJFAkBu9scenHqEGBm63w970w+Cpw1/Ui2T35T2NVxwNgqefVIoifBBvj0xF8 vAqr6Nmy/Q+WrIq5nGJJMR/nKaq5ixqQo5n7yAeuaxawrvqRH+hcCRWd4dGlqXJ7G7 oCiO8tin/HjzIsCl6HFkksKWi2qJEwrQJlee7iYo= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:17 -0700 Message-Id: <20190815233618.31630-7-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 7/8] 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, Volodymyr_Babchuk@epam.com 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 unprivileged guests, until reserved-memory regions are properly supported in Xen. For now, do not call iomem_permit_access on them, because giving iomem_permit_access to dom0 means that the toolstack will be able to assign the region to a domU. Signed-off-by: Stefano Stabellini --- Changes in v6: - compare against "/reserved-memory/" Changes in v5: - fix check condition - use strnicmp - return error - improve commit message Changes in v4: - compare the parent name with reserved-memory - use dt_node_cmp Changes in v3: - new patch --- xen/arch/arm/domain_build.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 4c8404155a..673ffa453f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1155,15 +1155,23 @@ 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 to domUs + * until reserved-memory support is complete. + */ + if ( strnicmp(dt_node_full_name(dev), "/reserved-memory/", + strlen("/reserved-memory/")) != 0 ) { - 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 Thu Aug 15 23:36:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11096617 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 E3CC156FF for ; Thu, 15 Aug 2019 23:38:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D61DF28671 for ; Thu, 15 Aug 2019 23:38:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA11528987; Thu, 15 Aug 2019 23:38:06 +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 652E528985 for ; Thu, 15 Aug 2019 23:38: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 1hyPIC-0004bA-2j; Thu, 15 Aug 2019 23:36:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hyPIA-0004Yc-GZ for xen-devel@lists.xenproject.org; Thu, 15 Aug 2019 23:36:26 +0000 X-Inumbo-ID: 7f362880-bfb5-11e9-aee9-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7f362880-bfb5-11e9-aee9-bc764e2007e4; Thu, 15 Aug 2019 23:36:26 +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 1E52E21743; Thu, 15 Aug 2019 23:36:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565912185; bh=v0p1+LsB4Pm+1HUBP8bU27P9WAkEWA9v3YfAR9ciU9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W7Wh54PaStUQ5Zlv8d6SBmzbz0U+gzo4D2jrcp3cXRcrlcUOGCa8buKEJLYLxM9N+ l6hm4eo10L8re8/QW/UARLwebvJYvcA8n7oYEU2pDrg+vDFYz07VHXIOsM0lH7HMx4 S85TxN5rJqRvvUjUZ1JuEd3Kqbp+1xrZT/JxgueE= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Thu, 15 Aug 2019 16:36:18 -0700 Message-Id: <20190815233618.31630-8-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v6 8/8] 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, Volodymyr_Babchuk@epam.com 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. Change make_memory_node to take a struct meminfo * instead of a kernel_info. Call it twice for dom0, once to create the first regular memory node, and the second time to create a second memory node with the ranges covering reserved-memory regions. Also, make a small code style fix in make_memory_node. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v5: - add acked-by Changes in v4: - pass struct meminfo * to make_memory_node - call make_memory_node twice for dom0, once for normal memory, once for reserved-memory regions --- xen/arch/arm/domain_build.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 673ffa453f..a654217820 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -639,11 +639,11 @@ static int __init fdt_property_interrupts(void *fdt, gic_interrupt_t *intr, static int __init make_memory_node(const struct domain *d, void *fdt, int addrcells, int sizecells, - const struct kernel_info *kinfo) + struct meminfo *mem) { int res, i; int reg_size = addrcells + sizecells; - int nr_cells = reg_size*kinfo->mem.nr_banks; + int nr_cells = reg_size * mem->nr_banks; __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */]; __be32 *cells; @@ -662,10 +662,10 @@ static int __init make_memory_node(const struct domain *d, return res; cells = ®[0]; - for ( i = 0 ; i < kinfo->mem.nr_banks; i++ ) + for ( i = 0 ; i < mem->nr_banks; i++ ) { - u64 start = kinfo->mem.bank[i].start; - u64 size = kinfo->mem.bank[i].size; + u64 start = mem->bank[i].start; + u64 size = mem->bank[i].size; dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n", i, start, start + size); @@ -1485,10 +1485,18 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, if ( res ) return res; - res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, kinfo); + res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo->mem); if ( res ) return res; + /* + * Create a second memory node to store the ranges covering + * reserved-memory regions. + */ + res = make_memory_node(d, kinfo->fdt, addrcells, sizecells, + &bootinfo.reserved_mem); + if ( res ) + return res; } res = fdt_end_node(kinfo->fdt); @@ -1744,7 +1752,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( ret ) goto err; - ret = make_memory_node(d, kinfo->fdt, addrcells, sizecells, kinfo); + ret = make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo->mem); if ( ret ) goto err;