From nobody Mon Feb 9 19:09:37 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=1651003619; cv=none; d=zohomail.com; s=zohoarc; b=EF4kJGuls0nvZV8Bzk726bp0aIWyvHXIzwleuygZ1L7yb7gtmBQTQF5iho1kOS++wgihSCYlKP8MrY7QbMsK3Y3l18llB+4kOf1PkHIIcEGNjQ8tDCJzcjg6+lBPl3d1XJjmeuGFZJ1gjioS1BbyKi/CIiokXogMTjbAYUNWw58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651003619; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=cXpV0bZL990t71BRKzeJL0a98IyOZGTem4wwEkwMQyU=; b=BQC8syc4JUQZ/JYguUgMTsq1Ap3QmSGL6Gul1LQTpBpJlZxUM9fMtled4b+nv3WBPgUFK36kTYEgnOyaJOeOP7nd7AmEfpIXwkU4s4YLzqHM1ah/dt+PEweiGgVD9h80V5QR9j+XSF9o5gs5N4XfOI4WltJp8CSZyT2vyxRTU0g= 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 1651003619099548.8979579639539; Tue, 26 Apr 2022 13:06:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.314148.532095 (Exim 4.92) (envelope-from ) id 1njRSG-0003eZ-7j; Tue, 26 Apr 2022 20:06:36 +0000 Received: by outflank-mailman (output) from mailman id 314148.532095; Tue, 26 Apr 2022 20:06:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njRSG-0003eS-4Z; Tue, 26 Apr 2022 20:06:36 +0000 Received: by outflank-mailman (input) for mailman id 314148; Tue, 26 Apr 2022 20:06:34 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njRSE-0003eK-Ho for xen-devel@lists.xenproject.org; Tue, 26 Apr 2022 20:06:34 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njRSE-0004SG-6T; Tue, 26 Apr 2022 20:06:34 +0000 Received: from 54-240-197-224.amazon.com ([54.240.197.224] 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 1njRSD-0008Ly-U1; Tue, 26 Apr 2022 20:06:34 +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:Message-Id:Date: Subject:Cc:To:From; bh=cXpV0bZL990t71BRKzeJL0a98IyOZGTem4wwEkwMQyU=; b=Zc96Rk RpPopW2ikP6HSuiiipn5dNz0twcJDARU0CqVcjHNof3SLC48dhoGsh4SQhzajyKzzbYwJgZ9Rku0C o4ag5v+r2bZlMzof6NmhAxTIooJ2679btH3Bl+GVQF+D0GhOu29VDj1Zk5R1DyaTa8BUddjC6ieIN l1J/XVfVJ64=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , David Vrabel Subject: [PATCH] xen/arm: alternative: Don't call vmap() within stop_machine_run() Date: Tue, 26 Apr 2022 21:06:29 +0100 Message-Id: <20220426200629.58921-1-julien@xen.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1651003620244100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall Commit 88a037e2cfe1 "page_alloc: assert IRQs are enabled in heap alloc/free" extended the checks in the buddy allocator to catch any use of the helpers from context with interrupts disabled. Unfortunately, the rule is not followed in the alternative code and this will result to crash at boot with debug enabled: (XEN) Xen call trace: (XEN) [<0022a510>] alloc_xenheap_pages+0x120/0x150 (PC) (XEN) [<00000000>] 00000000 (LR) (XEN) [<002736ac>] arch/arm/mm.c#xen_pt_update+0x144/0x6e4 (XEN) [<002740d4>] map_pages_to_xen+0x10/0x20 (XEN) [<00236864>] __vmap+0x400/0x4a4 (XEN) [<0026aee8>] arch/arm/alternative.c#__apply_alternatives_multi_sto= p+0x144/0x1ec (XEN) [<0022fe40>] stop_machine_run+0x23c/0x300 (XEN) [<002c40c4>] apply_alternatives_all+0x34/0x5c (XEN) [<002ce3e8>] start_xen+0xcb8/0x1024 (XEN) [<00200068>] arch/arm/arm32/head.o#primary_switched+0xc/0x1c The interrupts will be disabled by the state machine in stop_machine_run(), hence why the ASSERT is hit. For now the patch extending the checks has been reverted, but it would be good to re-introduce it (allocation with interrupts disabled is not desirable). So move the re-mapping of Xen to the caller of stop_machine_run(). Signed-off-by: Julien Grall Cc: David Vrabel Reviewed-by: Stefano Stabellini --- I managed to successfully boot Xen with this patch and dropping the revert. --- xen/arch/arm/alternative.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index 237c4e564209..f03cd943c636 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -170,7 +170,7 @@ static int __apply_alternatives(const struct alt_region= *region, * We might be patching the stop_machine state machine, so implement a * really simple polling protocol here. */ -static int __apply_alternatives_multi_stop(void *unused) +static int __apply_alternatives_multi_stop(void *xenmap) { static int patched =3D 0; =20 @@ -185,22 +185,9 @@ static int __apply_alternatives_multi_stop(void *unuse= d) { int ret; struct alt_region region; - mfn_t xen_mfn =3D virt_to_mfn(_start); - paddr_t xen_size =3D _end - _start; - unsigned int xen_order =3D get_order_from_bytes(xen_size); - void *xenmap; =20 BUG_ON(patched); =20 - /* - * The text and inittext section are read-only. So re-map Xen to - * be able to patch the code. - */ - xenmap =3D __vmap(&xen_mfn, 1U << xen_order, 1, 1, PAGE_HYPERVISOR, - VMAP_DEFAULT); - /* Re-mapping Xen is not expected to fail during boot. */ - BUG_ON(!xenmap); - region.begin =3D __alt_instructions; region.end =3D __alt_instructions_end; =20 @@ -208,8 +195,6 @@ static int __apply_alternatives_multi_stop(void *unused) /* The patching is not expected to fail during boot. */ BUG_ON(ret !=3D 0); =20 - vunmap(xenmap); - /* Barriers provided by the cache flushing */ write_atomic(&patched, 1); } @@ -224,14 +209,29 @@ static int __apply_alternatives_multi_stop(void *unus= ed) void __init apply_alternatives_all(void) { int ret; + mfn_t xen_mfn =3D virt_to_mfn(_start); + paddr_t xen_size =3D _end - _start; + unsigned int xen_order =3D get_order_from_bytes(xen_size); + void *xenmap; =20 ASSERT(system_state !=3D SYS_STATE_active); =20 + /* + * The text and inittext section are read-only. So re-map Xen to + * be able to patch the code. + */ + xenmap =3D __vmap(&xen_mfn, 1U << xen_order, 1, 1, PAGE_HYPERVISOR, + VMAP_DEFAULT); + /* Re-mapping Xen is not expected to fail during boot. */ + BUG_ON(!xenmap); + /* better not try code patching on a live SMP system */ - ret =3D stop_machine_run(__apply_alternatives_multi_stop, NULL, NR_CPU= S); + ret =3D stop_machine_run(__apply_alternatives_multi_stop, xenmap, NR_C= PUS); =20 /* stop_machine_run should never fail at this stage of the boot */ BUG_ON(ret); + + vunmap(xenmap); } =20 int apply_alternatives(const struct alt_instr *start, const struct alt_ins= tr *end) --=20 2.32.0