[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH V2] xen/arm: bootfdt: Always sort memory banks


  • To: Oleksandr Tyshchenko <olekstysh@xxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 6 Jul 2021 08:02:11 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a4IPHvn9kjIt6F7L5Y8SBUlRlI4UF9iILmKnab6OO+4=; b=X82a410yCcq4/Sj5LSu9WArrkpGxNAbtgviRcTszfXCR5pXw4GrSoq+arNrwBiGnRx/GDW3nowlpO8KWXx9DWTTZPL6GZUZiwFrvRNPTPMvWxSA5ofIcEsQgIYhIkrLoI4+WxWVZPqSxQ22P6leT9mzdy1PyByAVGnNvhHbeIovm2zmioMrZkLgQNtazYDfzQXJGK4+atfml4wAzSiI+rvbDut4Zj/6uOlLPzJXPAylw5yo1cwRcx6cvgLacip5CXBVXvhiRAWgnL0tBGQLHx60IxyqwYujwj+z6FGjHQ7O6J9Eo+f0HznUpkUAbMSY2YtNGJBAbS0UwIAoajqjzOA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TmH8YevJYbLHKMmAeCQwRs+HaFD+DaUUAWqeoqTaU36fB32zPqjxEHYo2rxH2H+NXCYHahBkV7LTfJCTznx19eYqab7Jue3pfabK+T0rO0oU17qErU7CjhoWZSkIffPXRU+u5iEdLi07YIUQS5saf6bGED5sBuoItu9eVDzaLjgCFwhKN86FyKunWnUPfxL0IfU3MFyq6N0u0dqYaZQN/tNiiWELO3wNOsUsxf+7ip3hKKvnaP3YRktcyamnNIX5N27lO+wZhXpf39bg13BUIUWPSdg9aYIZlUTozcctVPlI9ZrzrlG15ONuP59/Oc57h4+l16lujwLbVwc3hyPygw==
  • Authentication-results-original: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com;
  • Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 06 Jul 2021 08:02:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHXccYljzQk/sGJZEe7fPnXVyiC4as1lduA
  • Thread-topic: [PATCH V2] xen/arm: bootfdt: Always sort memory banks

Hi Oleksandr,

On 5 Jul 2021, at 18:48, Oleksandr Tyshchenko <olekstysh@xxxxxxxxx> wrote:

From: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>

At the moment, Xen on Arm64 expects the memory banks to be ordered.
Unfortunately, there may be a case when updated by firmware
device tree contains unordered banks. This means Xen will panic
when setting xenheap mappings for the subsequent bank with start
address being less than xenheap_mfn_start (start address of
the first bank).

As there is no clear requirement regarding ordering in the device
tree, update code to be able to deal with by sorting memory
banks. There is only one heap region on Arm32, so the sorting
is fine to be done in the common code.

Suggested-by: Julien Grall <jgrall@xxxxxxxxxx>
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

Cheers
Bertrand


---
  V2:
  - add Stefano's R-b
  - clarify patch description
  - clarify comment in code
  - drop "if (bootinfo.mem.nr_banks > 1)" check
---
xen/arch/arm/bootfdt.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
index dcff512..476e32e 100644
--- a/xen/arch/arm/bootfdt.c
+++ b/xen/arch/arm/bootfdt.c
@@ -13,6 +13,7 @@
#include <xen/init.h>
#include <xen/device_tree.h>
#include <xen/libfdt/libfdt.h>
+#include <xen/sort.h>
#include <xsm/xsm.h>
#include <asm/setup.h>

@@ -395,6 +396,21 @@ static void __init early_print_info(void)
    printk("\n");
}

+/* This function assumes that memory regions are not overlapped */
+static int __init cmp_memory_node(const void *key, const void *elem)
+{
+    const struct membank *handler0 = key;
+    const struct membank *handler1 = elem;
+
+    if ( handler0->start < handler1->start )
+        return -1;
+
+    if ( handler0->start >= (handler1->start + handler1->size) )
+        return 1;
+
+    return 0;
+}
+
/**
 * boot_fdt_info - initialize bootinfo from a DTB
 * @fdt: flattened device tree binary
@@ -412,6 +428,15 @@ 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, 0, early_scan_node, NULL);
+
+    /*
+     * On Arm64 setup_xenheap_mappings() expects to be called with the lowest
+     * bank in memory first. There is no requirement that the DT will provide
+     * the banks sorted in ascending order. So sort them through.
+     */
+    sort(bootinfo.mem.bank, bootinfo.mem.nr_banks, sizeof(struct membank),
+         cmp_memory_node, NULL);
+
    early_print_info();

    return fdt_totalsize(fdt);
--
2.7.4




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.