From nobody Tue Feb 10 09:02:03 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1671193094; cv=none; d=zohomail.com; s=zohoarc; b=A9TiFYV3q/lqUBByrb62199ovAnoFcCqi1digW9Ck0xz27AvzZcfXikk8E87wv6mvDDPTeyhs5wIC6mLpOawtKyjlTXcEyVte/+7FCXbBfNt5mHjnSI1ss4C51FEpas0G7WsrAM1kv0DBo5QmqC+9AX9ZYqggJEE3wjgSd3jGns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671193094; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Fh/+Yu2IVhcS+oFNJd/xfdw1K28l8x0te4dRw3BaaIo=; b=CHY/pLXBgKOpUJ7XgP+/Sjz/8lZfev68Blw+bKqyWrpObUoP1BYdfXdAeCP+6Wy36FgYcYpsh5IBxD1EypWYxUVcSKv7g58U56ngOwgYGYx9M4CRKss6iG4bkxIrIpGxzFaZB5o3+ocdEnkhQrbRODufPEhDko6Mi4Cz0iG4pLk= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1671193094270389.3047429114647; Fri, 16 Dec 2022 04:18:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.464574.723081 (Exim 4.92) (envelope-from ) id 1p69es-0000ot-BN; Fri, 16 Dec 2022 12:17:46 +0000 Received: by outflank-mailman (output) from mailman id 464574.723081; Fri, 16 Dec 2022 12:17:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p69er-0000jM-DP; Fri, 16 Dec 2022 12:17:45 +0000 Received: by outflank-mailman (input) for mailman id 464574; Fri, 16 Dec 2022 12:17:38 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p69ek-0007M6-5n for xen-devel@lists.xenproject.org; Fri, 16 Dec 2022 12:17:38 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p69ek-00035J-3O; Fri, 16 Dec 2022 12:17:38 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p69DK-0004sN-J4; Fri, 16 Dec 2022 11:49:18 +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 Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Fh/+Yu2IVhcS+oFNJd/xfdw1K28l8x0te4dRw3BaaIo=; b=NXmxWhqOxfDRQJ/rW5WuU3OJ5s vMl2K4A1hRxKwHrWg3G08Rp4Qg4ldVys3xXHuuAxC6LgWtm76+LLv248VGkTcSG3zdqk2n6zZzcNF +boDbASPWG/EK7ni00T4BnJUbLmgMquxER9VoZRGv/lP/F5XzH3s1wXypmXAKinjwa2s=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall Subject: [PATCH 16/22] x86/setup: leave early boot slightly earlier Date: Fri, 16 Dec 2022 11:48:47 +0000 Message-Id: <20221216114853.8227-17-julien@xen.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221216114853.8227-1-julien@xen.org> References: <20221216114853.8227-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1671193094864100012 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia When we do not have a direct map, memory for metadata of heap nodes in init_node_heap() is allocated from xenheap, which needs to be mapped and unmapped on demand. However, we cannot just take memory from the boot allocator to create the PTEs while we are passing memory to the heap allocator. To solve this race, we leave early boot slightly sooner so that Xen PTE pages are allocated from the heap instead of the boot allocator. We can do this because the metadata for the 1st node is statically allocated, and by the time we need memory to create mappings for the 2nd node, we already have enough memory in the heap allocator in the 1st node. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall --- xen/arch/x86/setup.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 2cb051c6e4e7..ec5a7448a225 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1648,6 +1648,22 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 numa_initmem_init(0, raw_max_page); =20 + /* + * When we do not have a direct map, memory for metadata of heap nodes= in + * init_node_heap() is allocated from xenheap, which needs to be mappe= d and + * unmapped on demand. However, we cannot just take memory from the bo= ot + * allocator to create the PTEs while we are passing memory to the heap + * allocator during end_boot_allocator(). + * + * To solve this race, we need to leave early boot before + * end_boot_allocator() so that Xen PTE pages are allocated from the h= eap + * instead of the boot allocator. We can do this because the metadata = for + * the 1st node is statically allocated, and by the time we need memor= y to + * create mappings for the 2nd node, we already have enough memory in = the + * heap allocator in the 1st node. + */ + system_state =3D SYS_STATE_boot; + if ( max_page - 1 > virt_to_mfn(HYPERVISOR_VIRT_END - 1) ) { unsigned long limit =3D virt_to_mfn(HYPERVISOR_VIRT_END - 1); @@ -1677,8 +1693,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) else end_boot_allocator(); =20 - system_state =3D SYS_STATE_boot; - bsp_stack =3D cpu_alloc_stack(0); if ( !bsp_stack ) panic("No memory for BSP stack\n"); --=20 2.38.1