From nobody Mon Feb 9 09:16:36 2026 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 header.i=@amazon.com; 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=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1705433204; cv=none; d=zohomail.com; s=zohoarc; b=lxX2t974jmep86q+n8W+v8d8LG2A90ZFwG4TF2hUQ8ZqXsOlJH2UcdihcM3r6Uad0u90GOeOPxELmDuA1tGrAWtHs5r3tQrYPjRNDJwY7Rx6qC5RnAMhw9ynQb8wOyTHr3XpAcwUKkA1lmXmcAL6HyYmAaEp5G2RmahZYIvy33s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433204; h=Content-Type: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=3bfMq1Uef4k7zIlKxhavHHhyVuwSclhXcQaPCDrDa7g=; b=F2dcC6f7sPLJ3xVKjDCoIfUF0QIX9kFQlg5u6y3nCFDsc+ISJogO7cHbTtxS/TzHsBZdvjbpUrMOZNGc5+8QotS7JVxQFRk1ssAqLY5CZW3+ljuY+PHCGLvdFnWVMSJXtlYpH5YjsZukc35lMCGomsJ+mtMX+beyzYEej1QCQ84= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; 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 1705433204170321.26977205838193; Tue, 16 Jan 2024 11:26:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668079.1039972 (Exim 4.92) (envelope-from ) id 1rPp4u-0003Fa-8f; Tue, 16 Jan 2024 19:26:28 +0000 Received: by outflank-mailman (output) from mailman id 668079.1039972; Tue, 16 Jan 2024 19:26:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp4u-0003F8-4m; Tue, 16 Jan 2024 19:26:28 +0000 Received: by outflank-mailman (input) for mailman id 668079; Tue, 16 Jan 2024 19:26:26 +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 1rPp4s-0002iI-Kv for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:26 +0000 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2306d3fa-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:24 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-6e7a78d7.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:23 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1e-m6i4x-6e7a78d7.us-east-1.amazon.com (Postfix) with ESMTPS id DA21380750; Tue, 16 Jan 2024 19:26:19 +0000 (UTC) Received: from EX19MTAUEB001.ant.amazon.com [10.0.44.209:34232] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.41.129:2525] with esmtp (Farcaster) id e3eca962-163c-4e87-9189-8e1da0e3c898; Tue, 16 Jan 2024 19:26:19 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEB001.ant.amazon.com (10.252.135.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:18 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:18 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:17 +0000 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 Sender: "Xen-devel" X-Inumbo-ID: 2306d3fa-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433184; x=1736969184; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3bfMq1Uef4k7zIlKxhavHHhyVuwSclhXcQaPCDrDa7g=; b=U2mekgigfQlp97fKeRfKjC/qPWGbEmz4IGoFfdKDtubzcHxaSflsjfG6 5K9mtCaBhSLR2/z2mDnHYJviq35/vO6zXD/dG+xk5D1gVQ541cin8ZtXq C7JPbYCs2Goos6ShROhNsfC3ru6OGglQ9UGhV25OUGAySGg5sPfE/BDZU Q=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="627983547" X-Farcaster-Flow-ID: e3eca962-163c-4e87-9189-8e1da0e3c898 From: Elias El Yandouzi To: CC: , , , Wei Liu , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , David Woodhouse , Hongyan Xia , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 02/27] x86/setup: Move vm_init() before acpi calls Date: Tue, 16 Jan 2024 19:25:46 +0000 Message-ID: <20240116192611.41112-3-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433205780100001 Content-Type: text/plain; charset="utf-8" From: Wei Liu After the direct map removal, pages from the boot allocator are not going to be mapped in the direct map. Although we have map_domain_page, they are ephemeral and are less helpful for mappings that are more than a page, so we want a mechanism to globally map a range of pages, which is what vmap is for. Therefore, we bring vm_init into early boot stage. To allow vmap to be initialised and used in early boot, we need to modify vmap to receive pages from the boot allocator during early boot stage. Signed-off-by: Wei Liu Signed-off-by: David Woodhouse Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Acked-by: Stefano Stabellini Reviewed-by: Jan Beulich ---- Changes in v2: - The return of map_pages_to_xen() is now checked in a separate patch - Clarify the commit message - Group the new boolean with the others diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 59dd9bb25a..7e28f62d09 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -748,6 +748,8 @@ void asmlinkage __init start_xen(unsigned long boot_phy= s_offset, =20 setup_mm(); =20 + vm_init(); + /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); =20 @@ -759,8 +761,6 @@ void asmlinkage __init start_xen(unsigned long boot_phy= s_offset, */ system_state =3D SYS_STATE_boot; =20 - vm_init(); - if ( acpi_disabled ) { printk("Booting using Device Tree\n"); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 897b7e9208..4d0c90b7a0 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -989,6 +989,7 @@ void asmlinkage __init noreturn __start_xen(unsigned lo= ng mbi_p) int i, j, e820_warn =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done =3D false, relocated =3D false; + bool vm_init_done =3D false; int ret; struct ns16550_defaults ns16550 =3D { .data_bits =3D 8, @@ -1531,12 +1532,23 @@ void asmlinkage __init noreturn __start_xen(unsigne= d long mbi_p) continue; =20 if ( !acpi_boot_table_init_done && - s >=3D (1ULL << 32) && - !acpi_boot_table_init() ) + s >=3D (1ULL << 32) ) { - acpi_boot_table_init_done =3D true; - srat_parse_regions(s); - setup_max_pdx(raw_max_page); + /* + * We only initialise vmap and acpi after going through the bo= ttom + * 4GiB, so that we have enough pages in the boot allocator. + */ + if ( !vm_init_done ) + { + vm_init(); + vm_init_done =3D true; + } + if ( !acpi_boot_table_init() ) + { + acpi_boot_table_init_done =3D true; + srat_parse_regions(s); + setup_max_pdx(raw_max_page); + } } =20 if ( pfn_to_pdx((e - 1) >> PAGE_SHIFT) >=3D max_pdx ) @@ -1722,6 +1734,9 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) =20 init_frametable(); =20 + if ( !vm_init_done ) + vm_init(); + if ( !acpi_boot_table_init_done ) acpi_boot_table_init(); =20 @@ -1761,12 +1776,6 @@ void asmlinkage __init noreturn __start_xen(unsigned= long mbi_p) end_boot_allocator(); =20 system_state =3D SYS_STATE_boot; - /* - * No calls involving ACPI code should go between the setting of - * SYS_STATE_boot and vm_init() (or else acpi_os_{,un}map_memory() - * will break). - */ - vm_init(); =20 bsp_stack =3D cpu_alloc_stack(0); if ( !bsp_stack ) diff --git a/xen/common/vmap.c b/xen/common/vmap.c index 830f64c5ef..fc5c70da4d 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -34,10 +34,19 @@ void __init vm_init_type(enum vmap_region type, void *s= tart, void *end) =20 for ( i =3D 0, va =3D (unsigned long)vm_bitmap(type); i < nr; ++i, va = +=3D PAGE_SIZE ) { - struct page_info *pg =3D alloc_domheap_page(NULL, 0); + mfn_t mfn; int rc; =20 - rc =3D map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR); + if ( system_state =3D=3D SYS_STATE_early_boot ) + mfn =3D alloc_boot_pages(1, 1); + else + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + BUG_ON(!pg); + mfn =3D page_to_mfn(pg); + } + rc =3D map_pages_to_xen(va, mfn, 1, PAGE_HYPERVISOR); BUG_ON(rc); =20 clear_page((void *)va); @@ -65,7 +74,7 @@ static void *vm_alloc(unsigned int nr, unsigned int align, spin_lock(&vm_lock); for ( ; ; ) { - struct page_info *pg; + mfn_t mfn; =20 ASSERT(vm_low[t] =3D=3D vm_top[t] || !test_bit(vm_low[t], vm_bitma= p(t))); for ( start =3D vm_low[t]; start < vm_top[t]; ) @@ -100,9 +109,16 @@ static void *vm_alloc(unsigned int nr, unsigned int al= ign, if ( vm_top[t] >=3D vm_end[t] ) return NULL; =20 - pg =3D alloc_domheap_page(NULL, 0); - if ( !pg ) - return NULL; + if ( system_state =3D=3D SYS_STATE_early_boot ) + mfn =3D alloc_boot_pages(1, 1); + else + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + if ( !pg ) + return NULL; + mfn =3D page_to_mfn(pg); + } =20 spin_lock(&vm_lock); =20 @@ -110,7 +126,7 @@ static void *vm_alloc(unsigned int nr, unsigned int ali= gn, { unsigned long va =3D (unsigned long)vm_bitmap(t) + vm_top[t] /= 8; =20 - if ( !map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR= ) ) + if ( !map_pages_to_xen(va, mfn, 1, PAGE_HYPERVISOR) ) { clear_page((void *)va); vm_top[t] +=3D PAGE_SIZE * 8; @@ -120,7 +136,10 @@ static void *vm_alloc(unsigned int nr, unsigned int al= ign, } } =20 - free_domheap_page(pg); + if ( system_state =3D=3D SYS_STATE_early_boot ) + init_boot_pages(mfn_to_maddr(mfn), mfn_to_maddr(mfn) + PAGE_SI= ZE); + else + free_domheap_page(mfn_to_page(mfn)); =20 if ( start >=3D vm_top[t] ) { --=20 2.40.1