From nobody Fri May 17 01:10:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1712894169; cv=none; d=zohomail.com; s=zohoarc; b=PlXCf+8hKgf0WCypiUvYTFvDeXIQi1hViolCb/QDx7m+xXa6vAYTy7jNapkGVRomAU7x86VBYPo9d3bGdx7hXI6limsz/fEEnlyzCCkAe/tifJqBUrWvJuJMVWZTNVYlLnqOoyL76uJrAqXN5qhqoqj3D9ZxpgihuGLoyTuzTLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712894169; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h6QhePaFuDvespR2wWM7QXtyi8l5kFrGXTzysLGgKXk=; b=PnmF1FZiMeANYyZ1fkTHPG+RuIBjdCCckCOJw/aNF1nuML83QM9s16QSfZvGUCW+ULErVxyh9CzWZtPpsqghq6/qLqVX006ZXx6tD1bO7+Zs/wH9CkkuqslFRTtHVXk1Mqk/JDkpH6FsBQ6YqVYL+pMfGzVbnQzOcfTPcE4KCF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712894169480323.47489774291444; Thu, 11 Apr 2024 20:56:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.704315.1100643 (Exim 4.92) (envelope-from ) id 1rv80n-0003ch-N6; Fri, 12 Apr 2024 03:55:37 +0000 Received: by outflank-mailman (output) from mailman id 704315.1100643; Fri, 12 Apr 2024 03:55:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80n-0003cZ-KN; Fri, 12 Apr 2024 03:55:37 +0000 Received: by outflank-mailman (input) for mailman id 704315; Fri, 12 Apr 2024 03:55:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80m-0003cM-3I for xen-devel@lists.xenproject.org; Fri, 12 Apr 2024 03:55:36 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 83b9b8eb-f880-11ee-b908-491648fe20b8; Fri, 12 Apr 2024 05:55:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 05FD68285611; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hVfuiZoSChIF; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id C3BC48286D98; Thu, 11 Apr 2024 22:55:32 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id AXGpxrF1BjZr; Thu, 11 Apr 2024 22:55:32 -0500 (CDT) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 653B7828560C; Thu, 11 Apr 2024 22:55:32 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 83b9b8eb-f880-11ee-b908-491648fe20b8 DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com C3BC48286D98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1712894132; bh=h6QhePaFuDvespR2wWM7QXtyi8l5kFrGXTzysLGgKXk=; h=From:To:Date:Message-Id:MIME-Version; b=pUXKyaB2ltLSDrvQ9QIx0ybpheNbIifDDTbK4RgI8yh10Wio1Fmh6HEShhYWRRlH7 uiIF7PT4S/jbeFkiGwooQ/rF5KXKeLuXyrkjuTUTNqMMOL+tx8LU+4JCudUWUK+I3F HqyJsb+pkl3KN4ZZ0uAYS0BXVWD2o4J0mw1nX4Do= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Shawn Anastasio , Jan Beulich Subject: [PATCH v4 1/6] xen/ppc: Introduce stub asm/static-shmem.h Date: Thu, 11 Apr 2024 22:55:18 -0500 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1712894169780100003 Content-Type: text/plain; charset="utf-8" Required for bootfdt.c to build. Signed-off-by: Shawn Anastasio --- Changes in v4: none xen/arch/ppc/include/asm/static-shmem.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 xen/arch/ppc/include/asm/static-shmem.h diff --git a/xen/arch/ppc/include/asm/static-shmem.h b/xen/arch/ppc/include= /asm/static-shmem.h new file mode 100644 index 0000000000..84370d6e6c --- /dev/null +++ b/xen/arch/ppc/include/asm/static-shmem.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_PPC_STATIC_SHMEM_H__ +#define __ASM_PPC_STATIC_SHMEM_H__ + +static inline int process_shm_node(const void *fdt, int node, + uint32_t address_cells, uint32_t size_c= ells) +{ + return -EINVAL; +} + +#endif /* __ASM_PPC_STATIC_SHMEM_H__ */ -- 2.30.2 From nobody Fri May 17 01:10:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1712894169; cv=none; d=zohomail.com; s=zohoarc; b=GHeduzTRXPZ4C1oUVpDWrhCJlGsiPGNKNSgslmk+Q5oabd/QCbAg4Nqks0ZkJYAumwU1CKt0B4uFtuGpB1EVQkTai9qsl8tv2gLN05f6PtkgDL5nS/VVppN47YatbrWQ5Y7WTj9FeMt6qPXz7fFbFupv7kdHh56hoMbn8WjdlgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712894169; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4lBNQmQi/xabDS46AhsL1+meGbFpGjZ3/8DO7ocjTe0=; b=S0PutuPM5uzYes1xd0GjKphRXD1kLPzXKRFdMbgZRhBuzdlnED9fNo8RJ/MZaK8KdEuWQRfFlhb4J8WYPi2dVgRYD6dt1EIMP9Exy6GAolC/9cMQ2TCVJkQs3Egiz0qBmS7JyAkLPo20w45QQxmShnr91aCKD8hbfQXaLIwydTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712894169649662.8128807224779; Thu, 11 Apr 2024 20:56:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.704321.1100702 (Exim 4.92) (envelope-from ) id 1rv80s-00051N-KZ; Fri, 12 Apr 2024 03:55:42 +0000 Received: by outflank-mailman (output) from mailman id 704321.1100702; Fri, 12 Apr 2024 03:55:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80s-00050d-Gc; Fri, 12 Apr 2024 03:55:42 +0000 Received: by outflank-mailman (input) for mailman id 704321; Fri, 12 Apr 2024 03:55:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80q-0003cg-LO for xen-devel@lists.xenproject.org; Fri, 12 Apr 2024 03:55:40 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 853d1402-f880-11ee-94a3-07e782e9044d; Fri, 12 Apr 2024 05:55:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id C010C8285556; Thu, 11 Apr 2024 22:55:36 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id y8mAwMzhx4Ny; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 678F08287000; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id zlnvwZV6BNhZ; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id B768C8285611; Thu, 11 Apr 2024 22:55:32 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 853d1402-f880-11ee-94a3-07e782e9044d DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com 678F08287000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1712894133; bh=4lBNQmQi/xabDS46AhsL1+meGbFpGjZ3/8DO7ocjTe0=; h=From:To:Date:Message-Id:MIME-Version; b=BMlU5jrYqIT50/E5wx53uFouwhTATDoYN+1nH8HfhzrPUrKurj6xcSuWSbj7ZxXNN xTyYav4Keu/TBWPXExMnAT2CvZMF2oUMtOTdgWrJTAnSCYBngCKd9jHb7488zmMDV4 xHsGv8YuQRBF6BPecyhXkPYxFoF1cA262bn3ujhQ= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Shawn Anastasio , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , "Daniel P. Smith" Subject: [PATCH v4 2/6] xen/device-tree: Move Arm's setup.c bootinfo functions to common Date: Thu, 11 Apr 2024 22:55:19 -0500 Message-Id: <451705505ff7f80ec66c78cc2830196fa6e4090c.1712893887.git.sanastasio@raptorengineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1712894169844100007 Content-Type: text/plain; charset="utf-8" Arm's setup.c contains a collection of functions for parsing memory map and other boot information from a device tree. Since these routines are generally useful on any architecture that supports device tree booting, move them into xen/common/device-tree. Suggested-by: Julien Grall Signed-off-by: Shawn Anastasio --- Changes in v4: - create new xen/include/bootinfo.h rather than relying on arch's asm/setup.h to provide required definitions for bootinfo.c - build bootinfo.c as .init.o - clean up and sort bootinfo.c's #includes - use CONFIG_SEPARATE_XENHEAP rather than CONFIG_ARM_32 to guard xenheap-specific behavior of populate_boot_allocator - (MAINTAINERS) include all of common/device-tree rather than just bootinfo.c MAINTAINERS | 1 + xen/arch/arm/include/asm/setup.h | 109 +------- xen/arch/arm/setup.c | 419 ---------------------------- xen/common/Makefile | 1 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/bootinfo.c | 446 ++++++++++++++++++++++++++++++ xen/include/xen/bootfdt.h | 116 ++++++++ 7 files changed, 566 insertions(+), 527 deletions(-) create mode 100644 xen/common/device-tree/Makefile create mode 100644 xen/common/device-tree/bootinfo.c create mode 100644 xen/include/xen/bootfdt.h diff --git a/MAINTAINERS b/MAINTAINERS index d1850c134d..13adb794b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -295,6 +295,7 @@ M: Stefano Stabellini M: Julien Grall S: Supported F: xen/common/libfdt/ +F: xen/common/device-tree/ F: xen/common/device_tree.c F: xen/common/dt-overlay.c F: xen/include/xen/libfdt/ diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index d15a88d2e0..bf16afe31c 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -4,108 +4,7 @@ #include #include #include - -#define MIN_FDT_ALIGN 8 -#define MAX_FDT_SIZE SZ_2M - -#define NR_MEM_BANKS 256 - -#define MAX_MODULES 32 /* Current maximum useful modules */ - -typedef enum { - BOOTMOD_XEN, - BOOTMOD_FDT, - BOOTMOD_KERNEL, - BOOTMOD_RAMDISK, - BOOTMOD_XSM, - BOOTMOD_GUEST_DTB, - BOOTMOD_UNKNOWN -} bootmodule_kind; - -enum membank_type { - /* - * The MEMBANK_DEFAULT type refers to either reserved memory for the - * device/firmware (when the bank is in 'reserved_mem') or any RAM (wh= en - * the bank is in 'mem'). - */ - MEMBANK_DEFAULT, - /* - * The MEMBANK_STATIC_DOMAIN type is used to indicate whether the memo= ry - * bank is bound to a static Xen domain. It is only valid when the bank - * is in reserved_mem. - */ - MEMBANK_STATIC_DOMAIN, - /* - * The MEMBANK_STATIC_HEAP type is used to indicate whether the memory - * bank is reserved as static heap. It is only valid when the bank is - * in reserved_mem. - */ - MEMBANK_STATIC_HEAP, -}; - -/* Indicates the maximum number of characters(\0 included) for shm_id */ -#define MAX_SHM_ID_LENGTH 16 - -struct membank { - paddr_t start; - paddr_t size; - enum membank_type type; -#ifdef CONFIG_STATIC_SHM - char shm_id[MAX_SHM_ID_LENGTH]; - unsigned int nr_shm_borrowers; -#endif -}; - -struct meminfo { - unsigned int nr_banks; - struct membank bank[NR_MEM_BANKS]; -}; - -/* - * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. - * The purpose of the domU flag is to avoid getting confused in - * kernel_probe, where we try to guess which is the dom0 kernel and - * initrd to be compatible with all versions of the multiboot spec. - */ -#define BOOTMOD_MAX_CMDLINE 1024 -struct bootmodule { - bootmodule_kind kind; - bool domU; - paddr_t start; - paddr_t size; -}; - -/* DT_MAX_NAME is the node name max length according the DT spec */ -#define DT_MAX_NAME 41 -struct bootcmdline { - bootmodule_kind kind; - bool domU; - paddr_t start; - char dt_name[DT_MAX_NAME]; - char cmdline[BOOTMOD_MAX_CMDLINE]; -}; - -struct bootmodules { - int nr_mods; - struct bootmodule module[MAX_MODULES]; -}; - -struct bootcmdlines { - unsigned int nr_mods; - struct bootcmdline cmdline[MAX_MODULES]; -}; - -struct bootinfo { - struct meminfo mem; - /* The reserved regions are only used when booting using Device-Tree */ - struct meminfo reserved_mem; - struct bootmodules modules; - struct bootcmdlines cmdlines; -#ifdef CONFIG_ACPI - struct meminfo acpi; -#endif - bool static_heap; -}; +#include struct map_range_data { @@ -118,8 +17,6 @@ struct map_range_data struct rangeset *irq_ranges; }; -extern struct bootinfo bootinfo; - extern domid_t max_init_domid; void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); @@ -142,9 +39,6 @@ void fw_unreserved_regions(paddr_t s, paddr_t e, void (*cb)(paddr_t ps, paddr_t pe), unsigned int first); -size_t boot_fdt_info(const void *fdt, paddr_t paddr); -const char *boot_fdt_cmdline(const void *fdt); - bool check_reserved_regions_overlap(paddr_t region_start, paddr_t region_s= ize); struct bootmodule *add_boot_module(bootmodule_kind kind, @@ -159,7 +53,6 @@ struct bootcmdline * boot_cmdline_find_by_name(const cha= r *name); const char *boot_module_kind_as_string(bootmodule_kind kind); void init_pdx(void); -void populate_boot_allocator(void); void setup_mm(void); extern uint32_t hyp_traps_vector[]; diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index b9a7f61f73..61203db8af 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -48,8 +48,6 @@ #include #include -struct bootinfo __initdata bootinfo; - /* * Sanitized version of cpuinfo containing only features available on all * cores (only on arm64 as there is no sanitization support on arm32). @@ -203,309 +201,6 @@ static void __init processor_id(void) processor_setup(); } -static void __init dt_unreserved_regions(paddr_t s, paddr_t e, - void (*cb)(paddr_t ps, paddr_t pe= ), - unsigned int first) -{ - unsigned int i, nr; - int rc; - - rc =3D fdt_num_mem_rsv(device_tree_flattened); - if ( rc < 0 ) - panic("Unable to retrieve the number of reserved regions (rc=3D%d)= \n", - rc); - - nr =3D rc; - - for ( i =3D first; i < nr ; i++ ) - { - paddr_t r_s, r_e; - - if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &r_s, &r_e ) = < 0 ) - /* If we can't read it, pretend it doesn't exist... */ - continue; - - r_e +=3D r_s; /* fdt_get_mem_rsv_paddr returns length */ - - 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; - } - } - - /* - * 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 =3D bootinfo.reserved_mem.bank[i - nr].start; - paddr_t r_e =3D 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); -} - -/* - * TODO: '*_end' could be 0 if the bank/region is at the end of the physic= al - * address space. This is for now not handled as it requires more rework. - */ -static bool __init meminfo_overlap_check(struct meminfo *meminfo, - paddr_t region_start, - paddr_t region_size) -{ - paddr_t bank_start =3D INVALID_PADDR, bank_end =3D 0; - paddr_t region_end =3D region_start + region_size; - unsigned int i, bank_num =3D meminfo->nr_banks; - - for ( i =3D 0; i < bank_num; i++ ) - { - bank_start =3D meminfo->bank[i].start; - bank_end =3D bank_start + meminfo->bank[i].size; - - if ( region_end <=3D bank_start || region_start >=3D bank_end ) - continue; - else - { - printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with = bank[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n", - region_start, region_end, i, bank_start, bank_end); - return true; - } - } - - return false; -} - -/* - * TODO: '*_end' could be 0 if the module/region is at the end of the phys= ical - * address space. This is for now not handled as it requires more rework. - */ -static bool __init bootmodules_overlap_check(struct bootmodules *bootmodul= es, - paddr_t region_start, - paddr_t region_size) -{ - paddr_t mod_start =3D INVALID_PADDR, mod_end =3D 0; - paddr_t region_end =3D region_start + region_size; - unsigned int i, mod_num =3D bootmodules->nr_mods; - - for ( i =3D 0; i < mod_num; i++ ) - { - mod_start =3D bootmodules->module[i].start; - mod_end =3D mod_start + bootmodules->module[i].size; - - if ( region_end <=3D mod_start || region_start >=3D mod_end ) - continue; - else - { - printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with = mod[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n", - region_start, region_end, i, mod_start, mod_end); - return true; - } - } - - return false; -} - -void __init fw_unreserved_regions(paddr_t s, paddr_t e, - void (*cb)(paddr_t ps, paddr_t pe), - unsigned int first) -{ - if ( acpi_disabled ) - dt_unreserved_regions(s, e, cb, first); - else - cb(s, e); -} - -/* - * Given an input physical address range, check if this range is overlappi= ng - * with the existing reserved memory regions defined in bootinfo. - * Return true if the input physical address range is overlapping with any - * existing reserved memory regions, otherwise false. - */ -bool __init check_reserved_regions_overlap(paddr_t region_start, - paddr_t region_size) -{ - /* Check if input region is overlapping with bootinfo.reserved_mem ban= ks */ - if ( meminfo_overlap_check(&bootinfo.reserved_mem, - region_start, region_size) ) - return true; - - /* Check if input region is overlapping with bootmodules */ - if ( bootmodules_overlap_check(&bootinfo.modules, - region_start, region_size) ) - return true; - -#ifdef CONFIG_ACPI - /* Check if input region is overlapping with ACPI EfiACPIReclaimMemory= */ - if ( meminfo_overlap_check(&bootinfo.acpi, region_start, region_size) ) - return true; -#endif - - return false; -} - -struct bootmodule __init *add_boot_module(bootmodule_kind kind, - paddr_t start, paddr_t size, - bool domU) -{ - struct bootmodules *mods =3D &bootinfo.modules; - struct bootmodule *mod; - unsigned int i; - - if ( mods->nr_mods =3D=3D MAX_MODULES ) - { - printk("Ignoring %s boot module at %"PRIpaddr"-%"PRIpaddr" (too ma= ny)\n", - boot_module_kind_as_string(kind), start, start + size); - return NULL; - } - - if ( check_reserved_regions_overlap(start, size) ) - return NULL; - - for ( i =3D 0 ; i < mods->nr_mods ; i++ ) - { - mod =3D &mods->module[i]; - if ( mod->kind =3D=3D kind && mod->start =3D=3D start ) - { - if ( !domU ) - mod->domU =3D false; - return mod; - } - } - - mod =3D &mods->module[mods->nr_mods++]; - mod->kind =3D kind; - mod->start =3D start; - mod->size =3D size; - mod->domU =3D domU; - - return mod; -} - -/* - * boot_module_find_by_kind can only be used to return Xen modules (e.g - * XSM, DTB) or Dom0 modules. This is not suitable for looking up guest - * modules. - */ -struct bootmodule * __init boot_module_find_by_kind(bootmodule_kind kind) -{ - struct bootmodules *mods =3D &bootinfo.modules; - struct bootmodule *mod; - int i; - for (i =3D 0 ; i < mods->nr_mods ; i++ ) - { - mod =3D &mods->module[i]; - if ( mod->kind =3D=3D kind && !mod->domU ) - return mod; - } - return NULL; -} - -void __init add_boot_cmdline(const char *name, const char *cmdline, - bootmodule_kind kind, paddr_t start, bool dom= U) -{ - struct bootcmdlines *cmds =3D &bootinfo.cmdlines; - struct bootcmdline *cmd; - - if ( cmds->nr_mods =3D=3D MAX_MODULES ) - { - printk("Ignoring %s cmdline (too many)\n", name); - return; - } - - cmd =3D &cmds->cmdline[cmds->nr_mods++]; - cmd->kind =3D kind; - cmd->domU =3D domU; - cmd->start =3D start; - - ASSERT(strlen(name) <=3D DT_MAX_NAME); - safe_strcpy(cmd->dt_name, name); - - if ( strlen(cmdline) > BOOTMOD_MAX_CMDLINE ) - panic("module %s command line too long\n", name); - safe_strcpy(cmd->cmdline, cmdline); -} - -/* - * boot_cmdline_find_by_kind can only be used to return Xen modules (e.g - * XSM, DTB) or Dom0 modules. This is not suitable for looking up guest - * modules. - */ -struct bootcmdline * __init boot_cmdline_find_by_kind(bootmodule_kind kind) -{ - struct bootcmdlines *cmds =3D &bootinfo.cmdlines; - struct bootcmdline *cmd; - int i; - - for ( i =3D 0 ; i < cmds->nr_mods ; i++ ) - { - cmd =3D &cmds->cmdline[i]; - if ( cmd->kind =3D=3D kind && !cmd->domU ) - return cmd; - } - return NULL; -} - -struct bootcmdline * __init boot_cmdline_find_by_name(const char *name) -{ - struct bootcmdlines *mods =3D &bootinfo.cmdlines; - struct bootcmdline *mod; - unsigned int i; - - for (i =3D 0 ; i < mods->nr_mods ; i++ ) - { - mod =3D &mods->cmdline[i]; - if ( strcmp(mod->dt_name, name) =3D=3D 0 ) - return mod; - } - return NULL; -} - -struct bootmodule * __init boot_module_find_by_addr_and_kind(bootmodule_ki= nd kind, - paddr_t start) -{ - struct bootmodules *mods =3D &bootinfo.modules; - struct bootmodule *mod; - unsigned int i; - - for (i =3D 0 ; i < mods->nr_mods ; i++ ) - { - mod =3D &mods->module[i]; - if ( mod->kind =3D=3D kind && mod->start =3D=3D start ) - return mod; - } - return NULL; -} - -const char * __init boot_module_kind_as_string(bootmodule_kind kind) -{ - switch ( kind ) - { - case BOOTMOD_XEN: return "Xen"; - case BOOTMOD_FDT: return "Device Tree"; - case BOOTMOD_KERNEL: return "Kernel"; - case BOOTMOD_RAMDISK: return "Ramdisk"; - case BOOTMOD_XSM: return "XSM"; - case BOOTMOD_GUEST_DTB: return "DTB"; - case BOOTMOD_UNKNOWN: return "Unknown"; - default: BUG(); - } -} - void __init discard_initial_modules(void) { struct bootmodules *mi =3D &bootinfo.modules; @@ -544,40 +239,6 @@ static void * __init relocate_fdt(paddr_t dtb_paddr, s= ize_t dtb_size) return fdt; } -/* - * Return the end of the non-module region starting at s. In other - * words return s the start of the next modules after s. - * - * On input *end is the end of the region which should be considered - * and it is updated to reflect the end of the module, clipped to the - * end of the region if it would run over. - */ -static paddr_t __init next_module(paddr_t s, paddr_t *end) -{ - struct bootmodules *mi =3D &bootinfo.modules; - paddr_t lowest =3D ~(paddr_t)0; - int i; - - for ( i =3D 0; i < mi->nr_mods; i++ ) - { - paddr_t mod_s =3D mi->module[i].start; - paddr_t mod_e =3D mod_s + mi->module[i].size; - - if ( !mi->module[i].size ) - continue; - - if ( mod_s < s ) - continue; - if ( mod_s > lowest ) - continue; - if ( mod_s > *end ) - continue; - lowest =3D mod_s; - *end =3D min(*end, mod_e); - } - return lowest; -} - void __init init_pdx(void) { paddr_t bank_start, bank_size, bank_end; @@ -622,86 +283,6 @@ void __init init_pdx(void) } } -/* - * Populate the boot allocator. - * If a static heap was not provided by the admin, all the RAM but the - * following regions will be added: - * - Modules (e.g., Xen, Kernel) - * - Reserved regions - * - Xenheap (arm32 only) - * If a static heap was provided by the admin, populate the boot - * allocator with the corresponding regions only, but with Xenheap excluded - * on arm32. - */ -void __init populate_boot_allocator(void) -{ - unsigned int i; - const struct meminfo *banks =3D &bootinfo.mem; - paddr_t s, e; - - if ( bootinfo.static_heap ) - { - for ( i =3D 0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) - { - if ( bootinfo.reserved_mem.bank[i].type !=3D MEMBANK_STATIC_HE= AP ) - continue; - - s =3D bootinfo.reserved_mem.bank[i].start; - e =3D s + bootinfo.reserved_mem.bank[i].size; -#ifdef CONFIG_ARM_32 - /* Avoid the xenheap, note that the xenheap cannot across a ba= nk */ - if ( s <=3D mfn_to_maddr(directmap_mfn_start) && - e >=3D mfn_to_maddr(directmap_mfn_end) ) - { - init_boot_pages(s, mfn_to_maddr(directmap_mfn_start)); - init_boot_pages(mfn_to_maddr(directmap_mfn_end), e); - } - else -#endif - init_boot_pages(s, e); - } - - return; - } - - for ( i =3D 0; i < banks->nr_banks; i++ ) - { - const struct membank *bank =3D &banks->bank[i]; - paddr_t bank_end =3D bank->start + bank->size; - - s =3D bank->start; - while ( s < bank_end ) - { - paddr_t n =3D bank_end; - - e =3D next_module(s, &n); - - if ( e =3D=3D ~(paddr_t)0 ) - e =3D n =3D bank_end; - - /* - * Module in a RAM bank other than the one which we are - * not dealing with here. - */ - if ( e > bank_end ) - e =3D bank_end; - -#ifdef CONFIG_ARM_32 - /* Avoid the xenheap */ - if ( s < mfn_to_maddr(directmap_mfn_end) && - mfn_to_maddr(directmap_mfn_start) < e ) - { - e =3D mfn_to_maddr(directmap_mfn_start); - n =3D mfn_to_maddr(directmap_mfn_end); - } -#endif - - fw_unreserved_regions(s, e, init_boot_pages, 0); - s =3D n; - } - } -} - size_t __read_mostly dcache_line_bytes; /* C entry point for boot CPU */ diff --git a/xen/common/Makefile b/xen/common/Makefile index e5eee19a85..3a39dd35f2 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_UBSAN) +=3D ubsan/ obj-$(CONFIG_NEEDS_LIBELF) +=3D libelf/ obj-$(CONFIG_HAS_DEVICE_TREE) +=3D libfdt/ +obj-$(CONFIG_HAS_DEVICE_TREE) +=3D device-tree/ CONF_FILE :=3D $(if $(patsubst /%,,$(KCONFIG_CONFIG)),$(objtree)/)$(KCONFI= G_CONFIG) $(obj)/config.gz: $(CONF_FILE) diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makef= ile new file mode 100644 index 0000000000..947bad979c --- /dev/null +++ b/xen/common/device-tree/Makefile @@ -0,0 +1 @@ +obj-y +=3D bootinfo.init.o diff --git a/xen/common/device-tree/bootinfo.c b/xen/common/device-tree/boo= tinfo.c new file mode 100644 index 0000000000..914f876d29 --- /dev/null +++ b/xen/common/device-tree/bootinfo.c @@ -0,0 +1,446 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Derived from $xen/arch/arm/setup.c. + * + * Early device tree parsing and bookkeeping routines. + * + * Tim Deegan + * Copyright (c) 2011 Citrix Systems. + * Copyright (c) 2024 Raptor Engineering LLC + */ + +#include +#include +#include +#include +#include +#include +#include + +struct bootinfo __initdata bootinfo; + +const char * __init boot_module_kind_as_string(bootmodule_kind kind) +{ + switch ( kind ) + { + case BOOTMOD_XEN: return "Xen"; + case BOOTMOD_FDT: return "Device Tree"; + case BOOTMOD_KERNEL: return "Kernel"; + case BOOTMOD_RAMDISK: return "Ramdisk"; + case BOOTMOD_XSM: return "XSM"; + case BOOTMOD_GUEST_DTB: return "DTB"; + case BOOTMOD_UNKNOWN: return "Unknown"; + default: BUG(); + } +} + +static void __init dt_unreserved_regions(paddr_t s, paddr_t e, + void (*cb)(paddr_t ps, paddr_t pe= ), + unsigned int first) +{ + unsigned int i, nr; + int rc; + + rc =3D fdt_num_mem_rsv(device_tree_flattened); + if ( rc < 0 ) + panic("Unable to retrieve the number of reserved regions (rc=3D%d)= \n", + rc); + + nr =3D rc; + + for ( i =3D first; i < nr ; i++ ) + { + paddr_t r_s, r_e; + + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &r_s, &r_e ) = < 0 ) + /* If we can't read it, pretend it doesn't exist... */ + continue; + + r_e +=3D r_s; /* fdt_get_mem_rsv_paddr returns length */ + + 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; + } + } + + /* + * 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 =3D bootinfo.reserved_mem.bank[i - nr].start; + paddr_t r_e =3D 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); +} + +/* + * TODO: '*_end' could be 0 if the bank/region is at the end of the physic= al + * address space. This is for now not handled as it requires more rework. + */ +static bool __init meminfo_overlap_check(struct meminfo *meminfo, + paddr_t region_start, + paddr_t region_size) +{ + paddr_t bank_start =3D INVALID_PADDR, bank_end =3D 0; + paddr_t region_end =3D region_start + region_size; + unsigned int i, bank_num =3D meminfo->nr_banks; + + for ( i =3D 0; i < bank_num; i++ ) + { + bank_start =3D meminfo->bank[i].start; + bank_end =3D bank_start + meminfo->bank[i].size; + + if ( region_end <=3D bank_start || region_start >=3D bank_end ) + continue; + else + { + printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with = bank[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n", + region_start, region_end, i, bank_start, bank_end); + return true; + } + } + + return false; +} + +/* + * TODO: '*_end' could be 0 if the module/region is at the end of the phys= ical + * address space. This is for now not handled as it requires more rework. + */ +static bool __init bootmodules_overlap_check(struct bootmodules *bootmodul= es, + paddr_t region_start, + paddr_t region_size) +{ + paddr_t mod_start =3D INVALID_PADDR, mod_end =3D 0; + paddr_t region_end =3D region_start + region_size; + unsigned int i, mod_num =3D bootmodules->nr_mods; + + for ( i =3D 0; i < mod_num; i++ ) + { + mod_start =3D bootmodules->module[i].start; + mod_end =3D mod_start + bootmodules->module[i].size; + + if ( region_end <=3D mod_start || region_start >=3D mod_end ) + continue; + else + { + printk("Region: [%#"PRIpaddr", %#"PRIpaddr") overlapping with = mod[%u]: [%#"PRIpaddr", %#"PRIpaddr")\n", + region_start, region_end, i, mod_start, mod_end); + return true; + } + } + + return false; +} + +void __init fw_unreserved_regions(paddr_t s, paddr_t e, + void (*cb)(paddr_t ps, paddr_t pe), + unsigned int first) +{ + if ( acpi_disabled ) + dt_unreserved_regions(s, e, cb, first); + else + cb(s, e); +} + +/* + * Given an input physical address range, check if this range is overlappi= ng + * with the existing reserved memory regions defined in bootinfo. + * Return true if the input physical address range is overlapping with any + * existing reserved memory regions, otherwise false. + */ +bool __init check_reserved_regions_overlap(paddr_t region_start, + paddr_t region_size) +{ + /* Check if input region is overlapping with bootinfo.reserved_mem ban= ks */ + if ( meminfo_overlap_check(&bootinfo.reserved_mem, + region_start, region_size) ) + return true; + + /* Check if input region is overlapping with bootmodules */ + if ( bootmodules_overlap_check(&bootinfo.modules, + region_start, region_size) ) + return true; + +#ifdef CONFIG_ACPI + /* Check if input region is overlapping with ACPI EfiACPIReclaimMemory= */ + if ( meminfo_overlap_check(&bootinfo.acpi, region_start, region_size) ) + return true; +#endif + + return false; +} + +struct bootmodule __init *add_boot_module(bootmodule_kind kind, + paddr_t start, paddr_t size, + bool domU) +{ + struct bootmodules *mods =3D &bootinfo.modules; + struct bootmodule *mod; + unsigned int i; + + if ( mods->nr_mods =3D=3D MAX_MODULES ) + { + printk("Ignoring %s boot module at %"PRIpaddr"-%"PRIpaddr" (too ma= ny)\n", + boot_module_kind_as_string(kind), start, start + size); + return NULL; + } + + if ( check_reserved_regions_overlap(start, size) ) + return NULL; + + for ( i =3D 0 ; i < mods->nr_mods ; i++ ) + { + mod =3D &mods->module[i]; + if ( mod->kind =3D=3D kind && mod->start =3D=3D start ) + { + if ( !domU ) + mod->domU =3D false; + return mod; + } + } + + mod =3D &mods->module[mods->nr_mods++]; + mod->kind =3D kind; + mod->start =3D start; + mod->size =3D size; + mod->domU =3D domU; + + return mod; +} + +/* + * boot_module_find_by_kind can only be used to return Xen modules (e.g + * XSM, DTB) or Dom0 modules. This is not suitable for looking up guest + * modules. + */ +struct bootmodule * __init boot_module_find_by_kind(bootmodule_kind kind) +{ + struct bootmodules *mods =3D &bootinfo.modules; + struct bootmodule *mod; + int i; + for (i =3D 0 ; i < mods->nr_mods ; i++ ) + { + mod =3D &mods->module[i]; + if ( mod->kind =3D=3D kind && !mod->domU ) + return mod; + } + return NULL; +} + +void __init add_boot_cmdline(const char *name, const char *cmdline, + bootmodule_kind kind, paddr_t start, bool dom= U) +{ + struct bootcmdlines *cmds =3D &bootinfo.cmdlines; + struct bootcmdline *cmd; + + if ( cmds->nr_mods =3D=3D MAX_MODULES ) + { + printk("Ignoring %s cmdline (too many)\n", name); + return; + } + + cmd =3D &cmds->cmdline[cmds->nr_mods++]; + cmd->kind =3D kind; + cmd->domU =3D domU; + cmd->start =3D start; + + ASSERT(strlen(name) <=3D DT_MAX_NAME); + safe_strcpy(cmd->dt_name, name); + + if ( strlen(cmdline) > BOOTMOD_MAX_CMDLINE ) + panic("module %s command line too long\n", name); + safe_strcpy(cmd->cmdline, cmdline); +} + +/* + * boot_cmdline_find_by_kind can only be used to return Xen modules (e.g + * XSM, DTB) or Dom0 modules. This is not suitable for looking up guest + * modules. + */ +struct bootcmdline * __init boot_cmdline_find_by_kind(bootmodule_kind kind) +{ + struct bootcmdlines *cmds =3D &bootinfo.cmdlines; + struct bootcmdline *cmd; + int i; + + for ( i =3D 0 ; i < cmds->nr_mods ; i++ ) + { + cmd =3D &cmds->cmdline[i]; + if ( cmd->kind =3D=3D kind && !cmd->domU ) + return cmd; + } + return NULL; +} + +struct bootcmdline * __init boot_cmdline_find_by_name(const char *name) +{ + struct bootcmdlines *mods =3D &bootinfo.cmdlines; + struct bootcmdline *mod; + unsigned int i; + + for (i =3D 0 ; i < mods->nr_mods ; i++ ) + { + mod =3D &mods->cmdline[i]; + if ( strcmp(mod->dt_name, name) =3D=3D 0 ) + return mod; + } + return NULL; +} + +struct bootmodule * __init boot_module_find_by_addr_and_kind(bootmodule_ki= nd kind, + paddr_t start) +{ + struct bootmodules *mods =3D &bootinfo.modules; + struct bootmodule *mod; + unsigned int i; + + for (i =3D 0 ; i < mods->nr_mods ; i++ ) + { + mod =3D &mods->module[i]; + if ( mod->kind =3D=3D kind && mod->start =3D=3D start ) + return mod; + } + return NULL; +} + +/* + * Return the end of the non-module region starting at s. In other + * words return s the start of the next modules after s. + * + * On input *end is the end of the region which should be considered + * and it is updated to reflect the end of the module, clipped to the + * end of the region if it would run over. + */ +static paddr_t __init next_module(paddr_t s, paddr_t *end) +{ + struct bootmodules *mi =3D &bootinfo.modules; + paddr_t lowest =3D ~(paddr_t)0; + int i; + + for ( i =3D 0; i < mi->nr_mods; i++ ) + { + paddr_t mod_s =3D mi->module[i].start; + paddr_t mod_e =3D mod_s + mi->module[i].size; + + if ( !mi->module[i].size ) + continue; + + if ( mod_s < s ) + continue; + if ( mod_s > lowest ) + continue; + if ( mod_s > *end ) + continue; + lowest =3D mod_s; + *end =3D min(*end, mod_e); + } + return lowest; +} + +/* + * Populate the boot allocator. + * If a static heap was not provided by the admin, all the RAM but the + * following regions will be added: + * - Modules (e.g., Xen, Kernel) + * - Reserved regions + * - Xenheap (CONFIG_SEPARATE_XENHEAP only) + * If a static heap was provided by the admin, populate the boot + * allocator with the corresponding regions only, but with Xenheap excluded + * on arm32. + */ +void __init populate_boot_allocator(void) +{ + unsigned int i; + const struct meminfo *banks =3D &bootinfo.mem; + paddr_t s, e; + + if ( bootinfo.static_heap ) + { + for ( i =3D 0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { + if ( bootinfo.reserved_mem.bank[i].type !=3D MEMBANK_STATIC_HE= AP ) + continue; + + s =3D bootinfo.reserved_mem.bank[i].start; + e =3D s + bootinfo.reserved_mem.bank[i].size; +#ifdef CONFIG_SEPARATE_XENHEAP + /* Avoid the xenheap, note that the xenheap cannot across a ba= nk */ + if ( s <=3D mfn_to_maddr(directmap_mfn_start) && + e >=3D mfn_to_maddr(directmap_mfn_end) ) + { + init_boot_pages(s, mfn_to_maddr(directmap_mfn_start)); + init_boot_pages(mfn_to_maddr(directmap_mfn_end), e); + } + else +#endif + init_boot_pages(s, e); + } + + return; + } + + for ( i =3D 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank =3D &banks->bank[i]; + paddr_t bank_end =3D bank->start + bank->size; + + s =3D bank->start; + while ( s < bank_end ) + { + paddr_t n =3D bank_end; + + e =3D next_module(s, &n); + + if ( e =3D=3D ~(paddr_t)0 ) + e =3D n =3D bank_end; + + /* + * Module in a RAM bank other than the one which we are + * not dealing with here. + */ + if ( e > bank_end ) + e =3D bank_end; + +#ifdef CONFIG_SEPARATE_XENHEAP + /* Avoid the xenheap */ + if ( s < mfn_to_maddr(directmap_mfn_end) && + mfn_to_maddr(directmap_mfn_start) < e ) + { + e =3D mfn_to_maddr(directmap_mfn_start); + n =3D mfn_to_maddr(directmap_mfn_end); + } +#endif + + fw_unreserved_regions(s, e, init_boot_pages, 0); + s =3D n; + } + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h new file mode 100644 index 0000000000..b0487bdbbd --- /dev/null +++ b/xen/include/xen/bootfdt.h @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __XEN_BOOTFDT_H__ +#define __XEN_BOOTFDT_H__ + +#include + +#define MIN_FDT_ALIGN 8 +#define MAX_FDT_SIZE SZ_2M + +#define NR_MEM_BANKS 256 + +#define MAX_MODULES 32 /* Current maximum useful modules */ + +typedef enum { + BOOTMOD_XEN, + BOOTMOD_FDT, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_XSM, + BOOTMOD_GUEST_DTB, + BOOTMOD_UNKNOWN +} bootmodule_kind; + +enum membank_type { + /* + * The MEMBANK_DEFAULT type refers to either reserved memory for the + * device/firmware (when the bank is in 'reserved_mem') or any RAM (wh= en + * the bank is in 'mem'). + */ + MEMBANK_DEFAULT, + /* + * The MEMBANK_STATIC_DOMAIN type is used to indicate whether the memo= ry + * bank is bound to a static Xen domain. It is only valid when the bank + * is in reserved_mem. + */ + MEMBANK_STATIC_DOMAIN, + /* + * The MEMBANK_STATIC_HEAP type is used to indicate whether the memory + * bank is reserved as static heap. It is only valid when the bank is + * in reserved_mem. + */ + MEMBANK_STATIC_HEAP, +}; + +/* Indicates the maximum number of characters(\0 included) for shm_id */ +#define MAX_SHM_ID_LENGTH 16 + +struct membank { + paddr_t start; + paddr_t size; + enum membank_type type; +#ifdef CONFIG_STATIC_SHM + char shm_id[MAX_SHM_ID_LENGTH]; + unsigned int nr_shm_borrowers; +#endif +}; + +struct meminfo { + unsigned int nr_banks; + struct membank bank[NR_MEM_BANKS]; +}; + +/* + * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. + * The purpose of the domU flag is to avoid getting confused in + * kernel_probe, where we try to guess which is the dom0 kernel and + * initrd to be compatible with all versions of the multiboot spec. + */ +#define BOOTMOD_MAX_CMDLINE 1024 +struct bootmodule { + bootmodule_kind kind; + bool domU; + paddr_t start; + paddr_t size; +}; + +/* DT_MAX_NAME is the node name max length according the DT spec */ +#define DT_MAX_NAME 41 +struct bootcmdline { + bootmodule_kind kind; + bool domU; + paddr_t start; + char dt_name[DT_MAX_NAME]; + char cmdline[BOOTMOD_MAX_CMDLINE]; +}; + +struct bootmodules { + int nr_mods; + struct bootmodule module[MAX_MODULES]; +}; + +struct bootcmdlines { + unsigned int nr_mods; + struct bootcmdline cmdline[MAX_MODULES]; +}; + +struct bootinfo { + struct meminfo mem; + struct meminfo reserved_mem; + struct bootmodules modules; + struct bootcmdlines cmdlines; +#ifdef CONFIG_ACPI + struct meminfo acpi; +#endif + bool static_heap; +}; + +extern struct bootinfo bootinfo; + +void populate_boot_allocator(void); + +size_t boot_fdt_info(const void *fdt, paddr_t paddr); + +const char *boot_fdt_cmdline(const void *fdt); + +#endif /* __XEN_BOOTFDT_H__ */ -- 2.30.2 From nobody Fri May 17 01:10:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1712894161; cv=none; d=zohomail.com; s=zohoarc; b=HW/UJXtypITW8HuJCtJrEFyua5pqBMEyWm+gR05yrOj0Ul/2BOn07N+tekmQad2g37K410AQAjXnluiPDo0IgqZwP9mc4dHPHwZS4URcRzdlbY4Qxl8G2wsFLVYbWW9+72nbwxR4EC2kF67NtLaZsNPDC/6spMpoy6w5LwHnMq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712894161; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9DEDygZK7p/Loek4mAbH1z9o5S1b+BWpvMpymX80HZI=; b=OZ88TGFGfvVMtNz0I0bU/FYWMSnDIGPrUIoWdPivPHIF7WRah7BQvsKpgmtxmfSnvaYbpJp1Od1JTFLVwULT+hkW3rke39WewPawxNJsikcrCnYsK4LREqTydKaAj/ZZvQG38dUmkGKQWwN0ceRtrvmYSL8E0OEt5LCSepvCqCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712894161459359.06925839018766; Thu, 11 Apr 2024 20:56:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.704318.1100674 (Exim 4.92) (envelope-from ) id 1rv80q-0004Jh-DU; Fri, 12 Apr 2024 03:55:40 +0000 Received: by outflank-mailman (output) from mailman id 704318.1100674; Fri, 12 Apr 2024 03:55:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80q-0004Ja-Ai; Fri, 12 Apr 2024 03:55:40 +0000 Received: by outflank-mailman (input) for mailman id 704318; Fri, 12 Apr 2024 03:55:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80o-0003cg-UK for xen-devel@lists.xenproject.org; Fri, 12 Apr 2024 03:55:38 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 84118175-f880-11ee-94a3-07e782e9044d; Fri, 12 Apr 2024 05:55:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id A642C8286D98; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id NAsXlbbp8DZW; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id C36DD8285556; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id m3PLhvj5tDYh; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 49A0D8287026; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 84118175-f880-11ee-94a3-07e782e9044d DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com C36DD8285556 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1712894133; bh=9DEDygZK7p/Loek4mAbH1z9o5S1b+BWpvMpymX80HZI=; h=From:To:Date:Message-Id:MIME-Version; b=DjBkXOKKwz+n7R8dZy6Zpmhaf4thjnQZXGOcyA+pbucZ3VX+UVnk0Np0gmGS3A5IT hc4+2Uh661wzpPIJxigqaRj0QyRnqwoozDgeGSCiCpXg6A4q2EkqU2EekQKj9My7Wo ijDvKcU7TM5KkCB5DyDLyaw/4iglz+LLTffgTyzk= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Shawn Anastasio , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich Subject: [PATCH v4 3/6] xen/common: Move Arm's bootfdt.c to common Date: Thu, 11 Apr 2024 22:55:20 -0500 Message-Id: <6df5d50608898f0a7ff48d96176d1c7d15424812.1712893887.git.sanastasio@raptorengineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1712894162003100001 Content-Type: text/plain; charset="utf-8" Move Arm's bootfdt.c to xen/common so that it can be used by other device tree architectures like PPC and RISCV. Suggested-by: Julien Grall Signed-off-by: Shawn Anastasio Acked-by: Julien Grall --- Changes in v4: - move function prototypes to patch 2's xen/include/bootfdt.h - clean up #includes xen/arch/arm/Makefile | 1 - xen/arch/arm/include/asm/setup.h | 13 ------------- xen/common/device-tree/Makefile | 1 + xen/{arch/arm =3D> common/device-tree}/bootfdt.c | 11 +++++------ xen/include/xen/bootfdt.h | 14 ++++++++++++++ 5 files changed, 20 insertions(+), 20 deletions(-) rename xen/{arch/arm =3D> common/device-tree}/bootfdt.c (99%) diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 7b1350e2ef..9e1548378c 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -10,7 +10,6 @@ obj-$(CONFIG_TEE) +=3D tee/ obj-$(CONFIG_HAS_VPCI) +=3D vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) +=3D alternative.o -obj-y +=3D bootfdt.init.o obj-y +=3D cpuerrata.o obj-y +=3D cpufeature.o obj-y +=3D decode.o diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index bf16afe31c..f955b7653a 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -39,19 +39,6 @@ void fw_unreserved_regions(paddr_t s, paddr_t e, void (*cb)(paddr_t ps, paddr_t pe), unsigned int first); -bool check_reserved_regions_overlap(paddr_t region_start, paddr_t region_s= ize); - -struct bootmodule *add_boot_module(bootmodule_kind kind, - paddr_t start, paddr_t size, bool domU); -struct bootmodule *boot_module_find_by_kind(bootmodule_kind kind); -struct bootmodule * boot_module_find_by_addr_and_kind(bootmodule_kind kind, - paddr_t start= ); -void add_boot_cmdline(const char *name, const char *cmdline, - bootmodule_kind kind, paddr_t start, bool domU); -struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind); -struct bootcmdline * boot_cmdline_find_by_name(const char *name); -const char *boot_module_kind_as_string(bootmodule_kind kind); - void init_pdx(void); void setup_mm(void); diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makef= ile index 947bad979c..ff2de71c96 100644 --- a/xen/common/device-tree/Makefile +++ b/xen/common/device-tree/Makefile @@ -1 +1,2 @@ +obj-y +=3D bootfdt.init.o obj-y +=3D bootinfo.init.o diff --git a/xen/arch/arm/bootfdt.c b/xen/common/device-tree/bootfdt.c similarity index 99% rename from xen/arch/arm/bootfdt.c rename to xen/common/device-tree/bootfdt.c index 35dbdf3384..f01a5b5d76 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -4,13 +4,12 @@ * * Copyright (C) 2012-2014 Citrix Systems, Inc. */ -#include -#include -#include -#include -#include + +#include #include -#include +#include +#include +#include #include #include #include diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index b0487bdbbd..577618da16 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -107,6 +107,20 @@ struct bootinfo { extern struct bootinfo bootinfo; +bool check_reserved_regions_overlap(paddr_t region_start, + paddr_t region_size); + +struct bootmodule *add_boot_module(bootmodule_kind kind, + paddr_t start, paddr_t size, bool domU); +struct bootmodule *boot_module_find_by_kind(bootmodule_kind kind); +struct bootmodule * boot_module_find_by_addr_and_kind(bootmodule_kind kind, + paddr_t start= ); +void add_boot_cmdline(const char *name, const char *cmdline, + bootmodule_kind kind, paddr_t start, bool domU); +struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind); +struct bootcmdline * boot_cmdline_find_by_name(const char *name); +const char *boot_module_kind_as_string(bootmodule_kind kind); + void populate_boot_allocator(void); size_t boot_fdt_info(const void *fdt, paddr_t paddr); -- 2.30.2 From nobody Fri May 17 01:10:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1712894166; cv=none; d=zohomail.com; s=zohoarc; b=iyFVjutQ7DA8CYjsWELVxVXhZBA66wI6A7W6+YDGpRDEOrfED1woMYprooUV01XSq+NTYsx1pUehPmmJB9Rl2HVkLrxmayg3Wua3mEYxfeCw6y2cp5zPRIww4bfPTbpIvDFCZOCm9AVoXl5SP0XV5xlIHy6LckJsmQ/kehswRdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712894166; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eg1UVmj1RCeFzD5J2HKUl3hljqZ0KApTIh1L8o/IKLs=; b=IwLRSywA1R1AzHFs0sq1CCzA1PCiDAd8/gps/HMGt1aGU67KGQokEx34RWWQl2nE3+zCv8pqIwtZ9yiKV+I3uwFpK4rWymtVjWyryYa6dJexqIRJQQQAvPaaM/EZqUjFQAl3y+hs+meDruz3TJnnwQFqpseZYkZiA9GxA1NuYEQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712894166114416.73874063249866; Thu, 11 Apr 2024 20:56:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.704319.1100679 (Exim 4.92) (envelope-from ) id 1rv80q-0004NO-OS; Fri, 12 Apr 2024 03:55:40 +0000 Received: by outflank-mailman (output) from mailman id 704319.1100679; Fri, 12 Apr 2024 03:55:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80q-0004ME-In; Fri, 12 Apr 2024 03:55:40 +0000 Received: by outflank-mailman (input) for mailman id 704319; Fri, 12 Apr 2024 03:55:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80p-0003cg-4w for xen-devel@lists.xenproject.org; Fri, 12 Apr 2024 03:55:39 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 84322b76-f880-11ee-94a3-07e782e9044d; Fri, 12 Apr 2024 05:55:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id F0A6D828703A; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id SYBZZGVPgQS8; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 3C9488287026; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wNLJwx4J2Rdd; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id C98908285A02; Thu, 11 Apr 2024 22:55:33 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 84322b76-f880-11ee-94a3-07e782e9044d DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com 3C9488287026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1712894134; bh=eg1UVmj1RCeFzD5J2HKUl3hljqZ0KApTIh1L8o/IKLs=; h=From:To:Date:Message-Id:MIME-Version; b=Vjot6yvEsM8vakaSq49ltR7MBPmmnNkRLFqDeRxVGKgjgxv47slVKl3JxqPc0Wfa8 LIW7XCRVSzA/pfcskXtOhbecYxB6PK217oZihc2AcB0yuDoFXblvo4lvYNZoskKmdu wK5RPp86hxlDqvvfzWdvId4RopPqXNXmhUwDUJ5U= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Shawn Anastasio , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v4 4/6] xen/ppc: Enable bootfdt and boot allocator Date: Thu, 11 Apr 2024 22:55:21 -0500 Message-Id: <46e6d4ddd74b9ecc4937d1086efe06eb39c499dd.1712893887.git.sanastasio@raptorengineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1712894167817100001 Content-Type: text/plain; charset="utf-8" Enable usage of bootfdt for populating the boot info struct from the firmware-provided device tree. Also enable the Xen boot page allocator. Additionally, modify bootfdt.c's boot_fdt_info() to tolerate the scenario in which the FDT overlaps a reserved memory region, as is the case on PPC when booted directly from skiboot. Since this means that Xen can now boot without a BOOTMOD_FDT present in bootinfo, clarify this fact in a comment above BOOTMOD_FDT's definition. Signed-off-by: Shawn Anastasio Acked-by: Julien Grall --- Changes in v4: - drop unnecessary libfdt.h include in setup.c - make boot_fdt and xen_bootmodule const - more clearly document that BOOTMOD_FDT is now optional - add explicit (void) cast to BOOTMOD_FDT creation xen/arch/ppc/setup.c | 22 +++++++++++++++++++++- xen/common/device-tree/bootfdt.c | 11 +++++++++-- xen/include/xen/bootfdt.h | 7 +++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/xen/arch/ppc/setup.c b/xen/arch/ppc/setup.c index 101bdd8bb6..47e997969f 100644 --- a/xen/arch/ppc/setup.c +++ b/xen/arch/ppc/setup.c @@ -1,12 +1,15 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include #include +#include +#include #include #include #include #include #include #include +#include /* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); @@ -24,6 +27,9 @@ void __init noreturn start_xen(unsigned long r3, unsigned= long r4, unsigned long r5, unsigned long r6, unsigned long r7) { + const void *boot_fdt; + const struct bootmodule *xen_bootmodule; + if ( r5 ) { /* Unsupported OpenFirmware boot protocol */ @@ -32,11 +38,25 @@ void __init noreturn start_xen(unsigned long r3, unsign= ed long r4, else { /* kexec boot protocol */ - boot_opal_init((void *)r3); + boot_fdt =3D (void *)r3; + boot_opal_init(boot_fdt); } setup_exceptions(); + device_tree_flattened =3D boot_fdt; + boot_fdt_info(boot_fdt, r3); + + /* + * Xen relocates itself at the ppc64 entrypoint, so we need to manuall= y mark + * the kernel module. + */ + xen_bootmodule =3D add_boot_module(BOOTMOD_XEN, __pa(_start), + PAGE_ALIGN(__pa(_end)), false); + BUG_ON(!xen_bootmodule); + + populate_boot_allocator(); + setup_initial_pagetables(); early_printk("Hello, ppc64le!\n"); diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/boot= fdt.c index f01a5b5d76..76d0f72ef9 100644 --- a/xen/common/device-tree/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -542,12 +542,19 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t = paddr) if ( ret < 0 ) panic("No valid device tree\n"); - add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false); - ret =3D device_tree_for_each_node(fdt, 0, early_scan_node, NULL); if ( ret ) panic("Early FDT parsing failed (%d)\n", ret); + /* + * Add module for the FDT itself after the device tree has been parsed= . This + * is required on ppc64le where the device tree passed to Xen may have= been + * allocated by skiboot, in which case it will exist within a reserved + * region and this call will fail. This is fine, however, since either= way + * the allocator will know not to step on the device tree. + */ + (void)add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false); + /* * On Arm64 setup_directmap_mappings() expects to be called with the l= owest * bank in memory first. There is no requirement that the DT will prov= ide diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index 577618da16..ea3ad96bb9 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -13,7 +13,14 @@ typedef enum { BOOTMOD_XEN, + + /* + * The BOOTMOD_FDT type will only be present when the firmware-provide= d FDT + * blob exists outside of a reserved memory region which is platform- + * dependent and may not be relied upon. + */ BOOTMOD_FDT, + BOOTMOD_KERNEL, BOOTMOD_RAMDISK, BOOTMOD_XSM, -- 2.30.2 From nobody Fri May 17 01:10:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1712894168; cv=none; d=zohomail.com; s=zohoarc; b=IKaFtnHGk5KZ47f14LgHlpThN1aCzP9+eHKi5mnJGprQiEnPucNEvjsV3rvJ8x1Aq2c3ZmM79l6hzpc+nCYNIRqH/FnjuggABuXelWVlAxqJ2RIUa9AqHbC5Bfrt9ZgiBNWmasHYwDbwn4ZBwd55cmL62kWQIvrlHccQvI8BcMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712894168; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=heOOpt0GaBxaUSv5fvn3lv+UIGdQ/ulfvZ6FNZzyZOw=; b=cyAdudrGgi3JJmgjwR2+FamVtS5d/rmz/CAeoxJKjxU695LNpV1MWiGeRc4nnBE4HP4qlNVvjOHPaDhzMIp40A+h2Harb3+Ci09nfEWxGOzYwIWAiclnrmchQh8xadfyo5K8Fz+lupT5DCs1cfPRL3KvYEbtGOIRQXXXanD7xAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712894168161263.7393693478381; Thu, 11 Apr 2024 20:56:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.704320.1100685 (Exim 4.92) (envelope-from ) id 1rv80r-0004Ta-44; Fri, 12 Apr 2024 03:55:41 +0000 Received: by outflank-mailman (output) from mailman id 704320.1100685; Fri, 12 Apr 2024 03:55:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80q-0004St-Uq; Fri, 12 Apr 2024 03:55:40 +0000 Received: by outflank-mailman (input) for mailman id 704320; Fri, 12 Apr 2024 03:55:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80p-0003cg-LD for xen-devel@lists.xenproject.org; Fri, 12 Apr 2024 03:55:39 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8442fd6d-f880-11ee-94a3-07e782e9044d; Fri, 12 Apr 2024 05:55:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 1F26E8285A02; Thu, 11 Apr 2024 22:55:35 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id OSBGkdgH4Iiv; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 7C92A82859ED; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id f9g-kxk51Npp; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 373308286D98; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8442fd6d-f880-11ee-94a3-07e782e9044d DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com 7C92A82859ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1712894134; bh=heOOpt0GaBxaUSv5fvn3lv+UIGdQ/ulfvZ6FNZzyZOw=; h=From:To:Date:Message-Id:MIME-Version; b=HGYyEtM9BK0j8a4C1oPdhhLQv2GV1dZUoKnAPbrAO1cIn/QembCE7TzIc939HlhSq yC5uAhgcTH/PJtXqAQW8JowkxKVl1bl9L8uezSnXcMR6i/IgkZP4N2N2pp5twpurvO amR93xntax8pE5CDTnt9WhNeI69w3bS+KYUddqT4= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Shawn Anastasio , Jan Beulich Subject: [PATCH v4 5/6] xen/ppc: mm-radix: Replace debug printing code with printk Date: Thu, 11 Apr 2024 22:55:22 -0500 Message-Id: <5b55af3e1e12b17f2f2e7f71df1834a4814d0a25.1712893887.git.sanastasio@raptorengineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1712894169791100004 Content-Type: text/plain; charset="utf-8" Now that we have common code building, there's no need to keep the old itoa64+debug print function in mm-radix.c Signed-off-by: Shawn Anastasio Reviewed-by: Jan Beulich --- Changes in v4: none xen/arch/ppc/mm-radix.c | 58 +++++++++-------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/xen/arch/ppc/mm-radix.c b/xen/arch/ppc/mm-radix.c index daa411a6fa..ab5a10695c 100644 --- a/xen/arch/ppc/mm-radix.c +++ b/xen/arch/ppc/mm-radix.c @@ -15,6 +15,12 @@ void enable_mmu(void); +#ifdef CONFIG_DEBUG +#define radix_dprintk(msg, ...) printk(XENLOG_DEBUG msg, ## __VA_ARGS__) +#else +#define radix_dprintk(...) +#endif + #define INITIAL_LVL1_PD_COUNT 1 #define INITIAL_LVL2_LVL3_PD_COUNT 2 #define INITIAL_LVL4_PT_COUNT 256 @@ -80,45 +86,6 @@ static __init struct lvl4_pt *lvl4_pt_pool_alloc(void) return &initial_lvl4_pt_pool[initial_lvl4_pt_pool_used++]; } -#ifndef NDEBUG -/* TODO: Remove once we get common/ building */ -static char *__init itoa64_hex(uint64_t val, char *out_buf, size_t buf_len) -{ - uint64_t cur; - size_t i =3D buf_len - 1; - - /* Null terminate buffer */ - out_buf[i] =3D '\0'; - - /* Add digits in reverse */ - cur =3D val; - while ( cur && i > 0 ) - { - out_buf[--i] =3D "0123456789ABCDEF"[cur % 16]; - cur /=3D 16; - } - - /* Pad to 16 digits */ - while ( i > 0 ) - out_buf[--i] =3D '0'; - - return out_buf + i; -} -#endif - -static void __init radix_dprint(uint64_t addr, const char *msg) -{ -#ifndef NDEBUG - char buf[sizeof("DEADBEEFCAFEBABA")]; - char *addr_s =3D itoa64_hex(addr, buf, sizeof(buf)); - - early_printk("(0x"); - early_printk(addr_s); - early_printk(") "); - early_printk(msg); -#endif -} - static void __init setup_initial_mapping(struct lvl1_pd *lvl1, vaddr_t map_start, vaddr_t map_end, @@ -186,27 +153,26 @@ static void __init setup_initial_mapping(struct lvl1_= pd *lvl1, unsigned long paddr =3D (page_addr - map_start) + phys_base; unsigned long flags; - radix_dprint(paddr, "being mapped to "); - radix_dprint(page_addr, "!\n"); + radix_dprintk("%016lx being mapped to %016lx\n", paddr, page_a= ddr); if ( is_kernel_text(page_addr) || is_kernel_inittext(page_addr= ) ) { - radix_dprint(page_addr, "being marked as TEXT (RX)\n"); + radix_dprintk("%016lx being marked as TEXT (RX)\n", page_a= ddr); flags =3D PTE_XEN_RX; } else if ( is_kernel_rodata(page_addr) ) { - radix_dprint(page_addr, "being marked as RODATA (RO)\n"); + radix_dprintk("%016lx being marked as RODATA (RO)\n", page= _addr); flags =3D PTE_XEN_RO; } else { - radix_dprint(page_addr, "being marked as DEFAULT (RW)\n"); + radix_dprintk("%016lx being marked as DEFAULT (RW)\n", pag= e_addr); flags =3D PTE_XEN_RW; } *pte =3D paddr_to_pte(paddr, flags); - radix_dprint(paddr_to_pte(paddr, flags).pte, - "is result of PTE map!\n"); + radix_dprintk("%016lx is the result of PTE map\n", + paddr_to_pte(paddr, flags).pte); } else { -- 2.30.2 From nobody Fri May 17 01:10:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1712894162; cv=none; d=zohomail.com; s=zohoarc; b=W/Q49PQD8SjVigi3e5gMgkutwOlwRJkbIaIn57MQek30p9QFZjPl2rOVGwfMR1C7ebVfy89k/jL+02+ws3BJwQlYs2X1CJWuY2KgnbtWOMjKrqttVNlKnYOAXBkw+HZHM1U79NAL9OnfoKj+kHVaFARNNEhpFb3ObOeY3dOWwrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712894162; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+oNr6YI+my9C14uC+qtbQ1w6T4lZvStTVUqWonPVFJk=; b=T5fcL9b23PTeQnuwB3gHyX3BAPD8nQaa29V5vnt4Jr6zMSfrHvjjyqJGR9Cp2oFRC5YAHlZZrvZMJXyI1mBKfPhOFVR6TALe98jMAzPo4UD8aJZTHOkU99zbVJFNhadiTw7gOiuh8Id0FobFva5SEmDUL02R3sffMai/lDxWP+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712894162750564.6214931616425; Thu, 11 Apr 2024 20:56:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.704317.1100664 (Exim 4.92) (envelope-from ) id 1rv80p-00045B-5T; Fri, 12 Apr 2024 03:55:39 +0000 Received: by outflank-mailman (output) from mailman id 704317.1100664; Fri, 12 Apr 2024 03:55:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80p-000453-2f; Fri, 12 Apr 2024 03:55:39 +0000 Received: by outflank-mailman (input) for mailman id 704317; Fri, 12 Apr 2024 03:55:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rv80o-0003cM-6e for xen-devel@lists.xenproject.org; Fri, 12 Apr 2024 03:55:38 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 84d4d64b-f880-11ee-b908-491648fe20b8; Fri, 12 Apr 2024 05:55:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 1B2E28285611; Thu, 11 Apr 2024 22:55:36 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id CS4f9qiucV-D; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id D65ED8285556; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Geqn_ei1Dc-Z; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 7F2528287038; Thu, 11 Apr 2024 22:55:34 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 84d4d64b-f880-11ee-b908-491648fe20b8 DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com D65ED8285556 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1712894134; bh=+oNr6YI+my9C14uC+qtbQ1w6T4lZvStTVUqWonPVFJk=; h=From:To:Date:Message-Id:MIME-Version; b=vKUSuEnRWVFTbxsQ0z5Na6B824wIEO/b80JUU2xv6Ps+5fr4qadwCbZXkwoxY9kSz dQnw47wXWGvZfnnZyQ0YSLDOp3dfjo+BGejzQPrSB18lRhRbKYexfBWpUAXy2vicva BKV4eUBNY6TKIs1d0wESuxO3V//wqgDFPfmqSA8M= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Shawn Anastasio , Jan Beulich Subject: [PATCH v4 6/6] xen/ppc: mm-radix: Allocate all paging structures at runtime Date: Thu, 11 Apr 2024 22:55:23 -0500 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1712894163817100005 Content-Type: text/plain; charset="utf-8" In the initial mm-radix implementation, the in-memory partition and process tables required to configure the MMU, as well as the page tables themselves were all allocated statically since the boot allocator was not yet available. Now that it is, allocate these structures at runtime and bump the size of the Process Table to its maximum supported value (on POWER9). Signed-off-by: Shawn Anastasio --- Changes in v4: - use mfn_add in initial_page_alloc() - zero pages returned by initial_page_alloc() xen/arch/ppc/mm-radix.c | 231 +++++++++++++++++++++------------------- 1 file changed, 123 insertions(+), 108 deletions(-) diff --git a/xen/arch/ppc/mm-radix.c b/xen/arch/ppc/mm-radix.c index ab5a10695c..8f4bfa87c0 100644 --- a/xen/arch/ppc/mm-radix.c +++ b/xen/arch/ppc/mm-radix.c @@ -21,69 +21,105 @@ void enable_mmu(void); #define radix_dprintk(...) #endif -#define INITIAL_LVL1_PD_COUNT 1 -#define INITIAL_LVL2_LVL3_PD_COUNT 2 -#define INITIAL_LVL4_PT_COUNT 256 - -static size_t __initdata initial_lvl1_pd_pool_used; -static struct lvl1_pd initial_lvl1_pd_pool[INITIAL_LVL1_PD_COUNT]; - -static size_t __initdata initial_lvl2_lvl3_pd_pool_used; -static struct lvl2_pd initial_lvl2_lvl3_pd_pool[INITIAL_LVL2_LVL3_PD_COUNT= ]; - -static size_t __initdata initial_lvl4_pt_pool_used; -static struct lvl4_pt initial_lvl4_pt_pool[INITIAL_LVL4_PT_COUNT]; - -/* Only reserve minimum Partition and Process tables */ #define PATB_SIZE_LOG2 16 /* Only supported partition table size on POWER9= */ #define PATB_SIZE (1UL << PATB_SIZE_LOG2) -#define PRTB_SIZE_LOG2 12 +#define PRTB_SIZE_LOG2 24 /* Maximum process table size on POWER9 */ #define PRTB_SIZE (1UL << PRTB_SIZE_LOG2) -static struct patb_entry - __aligned(PATB_SIZE) initial_patb[PATB_SIZE / sizeof(struct patb_entry= )]; +static struct patb_entry *initial_patb; +static struct prtb_entry *initial_prtb; -static struct prtb_entry - __aligned(PRTB_SIZE) initial_prtb[PRTB_SIZE / sizeof(struct prtb_entry= )]; +static mfn_t __initdata min_alloc_mfn =3D {-1}; +static mfn_t __initdata max_alloc_mfn =3D {0}; -static __init struct lvl1_pd *lvl1_pd_pool_alloc(void) +/* + * A thin wrapper for alloc_boot_pages that keeps track of the maximum and + * minimum mfns that have been allocated. This information is used by + * setup_initial_mapping to include the allocated pages in the initial + * page mapping. + * + * Additionally, allocated pages are zeroed before return. + */ +static mfn_t __init initial_page_alloc(unsigned long nr_pfns, + unsigned long pfn_align) { - if ( initial_lvl1_pd_pool_used >=3D INITIAL_LVL1_PD_COUNT ) - { - early_printk("Ran out of space for LVL1 PD!\n"); - die(); - } + mfn_t mfn_first, mfn_last; - return &initial_lvl1_pd_pool[initial_lvl1_pd_pool_used++]; -} + mfn_first =3D alloc_boot_pages(nr_pfns, pfn_align); + mfn_last =3D mfn_add(mfn_first, nr_pfns - 1); -static __init struct lvl2_pd *lvl2_pd_pool_alloc(void) -{ - if ( initial_lvl2_lvl3_pd_pool_used >=3D INITIAL_LVL2_LVL3_PD_COUNT ) - { - early_printk("Ran out of space for LVL2/3 PD!\n"); - die(); - } + min_alloc_mfn =3D _mfn(min(mfn_x(min_alloc_mfn), mfn_x(mfn_first))); + max_alloc_mfn =3D _mfn(max(mfn_x(max_alloc_mfn), mfn_x(mfn_last))); - return &initial_lvl2_lvl3_pd_pool[initial_lvl2_lvl3_pd_pool_used++]; + memset(__va(mfn_to_maddr(mfn_first)), 0, nr_pfns << PAGE_SHIFT); + + return mfn_first; } -static __init struct lvl3_pd *lvl3_pd_pool_alloc(void) +static __init void *initial_pd_pt_alloc(void) { - BUILD_BUG_ON(sizeof(struct lvl3_pd) !=3D sizeof(struct lvl2_pd)); + BUILD_BUG_ON(sizeof(struct lvl1_pd) > PAGE_SIZE); + BUILD_BUG_ON(sizeof(struct lvl2_pd) > PAGE_SIZE); + BUILD_BUG_ON(sizeof(struct lvl3_pd) > PAGE_SIZE); + BUILD_BUG_ON(sizeof(struct lvl4_pt) > PAGE_SIZE); - return (struct lvl3_pd *) lvl2_pd_pool_alloc(); + return __va(mfn_to_maddr(initial_page_alloc(1, 1))); } -static __init struct lvl4_pt *lvl4_pt_pool_alloc(void) +static void map_page_initial(struct lvl1_pd *lvl1, vaddr_t virt, paddr_t p= hys, + unsigned long flags) { - if ( initial_lvl4_pt_pool_used >=3D INITIAL_LVL4_PT_COUNT ) + struct lvl2_pd *lvl2; + struct lvl3_pd *lvl3; + struct lvl4_pt *lvl4; + pde_t *pde; + pte_t *pte; + + /* Allocate LVL 2 PD if necessary */ + pde =3D pt_entry(lvl1, virt); + if ( !pde_is_valid(*pde) ) { - early_printk("Ran out of space for LVL4 PT!\n"); - die(); + lvl2 =3D initial_pd_pt_alloc(); + *pde =3D paddr_to_pde(__pa(lvl2), PDE_VALID, + XEN_PT_ENTRIES_LOG2_LVL_2); + } + else + lvl2 =3D __va(pde_to_paddr(*pde)); + + /* Allocate LVL 3 PD if necessary */ + pde =3D pt_entry(lvl2, virt); + if ( !pde_is_valid(*pde) ) + { + lvl3 =3D initial_pd_pt_alloc(); + *pde =3D paddr_to_pde(__pa(lvl3), PDE_VALID, + XEN_PT_ENTRIES_LOG2_LVL_3); + } + else + lvl3 =3D __va(pde_to_paddr(*pde)); + + /* Allocate LVL 4 PT if necessary */ + pde =3D pt_entry(lvl3, virt); + if ( !pde_is_valid(*pde) ) + { + lvl4 =3D initial_pd_pt_alloc(); + *pde =3D paddr_to_pde(__pa(lvl4), PDE_VALID, + XEN_PT_ENTRIES_LOG2_LVL_4); } + else + lvl4 =3D __va(pde_to_paddr(*pde)); - return &initial_lvl4_pt_pool[initial_lvl4_pt_pool_used++]; + /* Finally, create PTE in LVL 4 PT */ + pte =3D pt_entry(lvl4, virt); + if ( !pte_is_valid(*pte) ) + { + radix_dprintk("%016lx being mapped to %016lx\n", phys, virt); + *pte =3D paddr_to_pte(phys, flags); + } + else + { + early_printk("BUG: Tried to create PTE for already-mapped page!"); + die(); + } } static void __init setup_initial_mapping(struct lvl1_pd *lvl1, @@ -92,6 +128,7 @@ static void __init setup_initial_mapping(struct lvl1_pd = *lvl1, paddr_t phys_base) { uint64_t page_addr; + mfn_t previous_max_alloc_mfn; if ( map_start & ~PAGE_MASK ) { @@ -105,81 +142,47 @@ static void __init setup_initial_mapping(struct lvl1_= pd *lvl1, die(); } + /* Identity map Xen itself */ for ( page_addr =3D map_start; page_addr < map_end; page_addr +=3D PAG= E_SIZE ) { - struct lvl2_pd *lvl2; - struct lvl3_pd *lvl3; - struct lvl4_pt *lvl4; - pde_t *pde; - pte_t *pte; - - /* Allocate LVL 2 PD if necessary */ - pde =3D pt_entry(lvl1, page_addr); - if ( !pde_is_valid(*pde) ) - { - lvl2 =3D lvl2_pd_pool_alloc(); - *pde =3D paddr_to_pde(__pa(lvl2), PDE_VALID, - XEN_PT_ENTRIES_LOG2_LVL_2); - } - else - lvl2 =3D __va(pde_to_paddr(*pde)); + unsigned long flags; - /* Allocate LVL 3 PD if necessary */ - pde =3D pt_entry(lvl2, page_addr); - if ( !pde_is_valid(*pde) ) + if ( is_kernel_text(page_addr) || is_kernel_inittext(page_addr) ) { - lvl3 =3D lvl3_pd_pool_alloc(); - *pde =3D paddr_to_pde(__pa(lvl3), PDE_VALID, - XEN_PT_ENTRIES_LOG2_LVL_3); + radix_dprintk("%016lx being marked as TEXT (RX)\n", page_addr); + flags =3D PTE_XEN_RX; } - else - lvl3 =3D __va(pde_to_paddr(*pde)); - - /* Allocate LVL 4 PT if necessary */ - pde =3D pt_entry(lvl3, page_addr); - if ( !pde_is_valid(*pde) ) + else if ( is_kernel_rodata(page_addr) ) { - lvl4 =3D lvl4_pt_pool_alloc(); - *pde =3D paddr_to_pde(__pa(lvl4), PDE_VALID, - XEN_PT_ENTRIES_LOG2_LVL_4); + radix_dprintk("%016lx being marked as RODATA (RO)\n", page_add= r); + flags =3D PTE_XEN_RO; } else - lvl4 =3D __va(pde_to_paddr(*pde)); - - /* Finally, create PTE in LVL 4 PT */ - pte =3D pt_entry(lvl4, page_addr); - if ( !pte_is_valid(*pte) ) { - unsigned long paddr =3D (page_addr - map_start) + phys_base; - unsigned long flags; - - radix_dprintk("%016lx being mapped to %016lx\n", paddr, page_a= ddr); - if ( is_kernel_text(page_addr) || is_kernel_inittext(page_addr= ) ) - { - radix_dprintk("%016lx being marked as TEXT (RX)\n", page_a= ddr); - flags =3D PTE_XEN_RX; - } - else if ( is_kernel_rodata(page_addr) ) - { - radix_dprintk("%016lx being marked as RODATA (RO)\n", page= _addr); - flags =3D PTE_XEN_RO; - } - else - { - radix_dprintk("%016lx being marked as DEFAULT (RW)\n", pag= e_addr); - flags =3D PTE_XEN_RW; - } - - *pte =3D paddr_to_pte(paddr, flags); - radix_dprintk("%016lx is the result of PTE map\n", - paddr_to_pte(paddr, flags).pte); - } - else - { - early_printk("BUG: Tried to create PTE for already-mapped page= !"); - die(); + radix_dprintk("%016lx being marked as DEFAULT (RW)\n", page_ad= dr); + flags =3D PTE_XEN_RW; } + + map_page_initial(lvl1, page_addr, (page_addr - map_start) + phys_b= ase, flags); + } + + previous_max_alloc_mfn =3D max_alloc_mfn; + + /* + * Identity map all pages we've allocated for paging structures. This = act + * itself will allocate more pages, so continue until we've mapped from + * `max_alloc_mfn` down to `min_alloc_mfn`. This assumes that the heap= grows + * downwards, which matches the behavior of alloc_boot_pages. + */ + for ( page_addr =3D (vaddr_t)__va(mfn_to_maddr(max_alloc_mfn)); + mfn_to_maddr(min_alloc_mfn) <=3D __pa(page_addr); + page_addr -=3D PAGE_SIZE) + { + map_page_initial(lvl1, page_addr, __pa(page_addr), PTE_XEN_RW); } + + if ( mfn_x(previous_max_alloc_mfn) !=3D mfn_x(max_alloc_mfn) ) + panic("Early page heap unexpectedly grew upwards\n"); } static void __init setup_partition_table(struct lvl1_pd *root) @@ -208,9 +211,21 @@ static void __init setup_process_table(struct lvl1_pd = *root) void __init setup_initial_pagetables(void) { - struct lvl1_pd *root =3D lvl1_pd_pool_alloc(); + struct lvl1_pd *root; unsigned long lpcr; + mfn_t patb_mfn, prtb_mfn; + + /* Allocate mfns for in-memory tables using the boot allocator */ + prtb_mfn =3D initial_page_alloc(PRTB_SIZE / PAGE_SIZE, + 1 << (PRTB_SIZE_LOG2 - PAGE_SHIFT)); + patb_mfn =3D initial_page_alloc(PATB_SIZE / PAGE_SIZE, + 1 << (PATB_SIZE_LOG2 - PAGE_SHIFT)); + + initial_patb =3D __va(mfn_to_maddr(patb_mfn)); + initial_prtb =3D __va(mfn_to_maddr(prtb_mfn)); + /* Allocate and create page tables */ + root =3D initial_pd_pt_alloc(); setup_initial_mapping(root, (vaddr_t)_start, (vaddr_t)_end, __pa(_star= t)); /* Enable Radix mode in LPCR */ -- 2.30.2