From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E9D1606A31A for ; Wed, 2 Dec 2026 11:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zNLjUMg7 Received: from list by lists.xenproject.org with outflank-mailman.1509891.1702501 (Exim 4.92) (envelope-from ) id 1xYiCL-0003CB-Cm; Wed, 02 Dec 2026 11:08:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1509891.1702501; Wed, 02 Dec 2026 11:08:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYiCL-0003C3-9G; Wed, 02 Dec 2026 11:08:29 +0000 Received: by outflank-mailman (input) for mailman id 1509891; Wed, 02 Dec 2026 11:08:27 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYiCJ-0003Bx-OC for xen-devel@lists.xenproject.org; Wed, 02 Dec 2026 11:08:27 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYiCI-0005Qh-BV for xen-devel@lists.xenproject.org; Wed, 02 Dec 2026 12:08:26 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b0ffc28-bab6-0a2a0a5309dd-0a2a45089024-16 for ; Wed, 02 Dec 2026 12:08:26 +0100 Received: from [209.85.221.42] (helo=mail-wr1-f42.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b0ffc2a-f659-0a2a45080019-d155dd2aa4c9-3 for ; Wed, 02 Dec 2026 12:08:26 +0100 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-4c3f0acc1easo2529556f8f.0 for ; Wed, 02 Dec 2026 03:08:26 -0800 (PST) Received: from localhost (cm-93-156-217-168.telecable.es. [93.156.217.168]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab9cf005f2sm64272316f8f.45.2026.12.02.03.08.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 03:08:25 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="In-Reply-To:References:From:Subject:Cc:To:Message-Id:Date:Content-Type:Content-Transfer-Encoding:Mime-Version" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796209706; x=1796814506; darn=lists.xenproject.org; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=HETB4UZQrNUGf7nGhb5GuUqUZ8HybgE7qcF6GCwhhfU=; b=zNLjUMg7eJc8qvOyN3mRPZhfFdxzx1WlAWeu6Jto5F9/ctTDAOiKPyCkvoqnBXxVnc QeG4ZSES6hLmFaU4PK2FSJkIO06eP2rIUEchqzY6uoykL4tu4KcRmjdWB9ifRRaKBEJl qkebBoSZhDvFmvuChKSIlCp9YApR/MyXee8gVBy02S0DGth98Kz1/TN2DEmASrC+k7qW xSbwmsJISew+SwehLOnkwAJ6fuvfqFVgIUasTEcaggSxP8wdwmFc+KCD4M96JAkkBCLY JYrivE53+ordT49XMLBjuGodxHKh5hN79gAOaYkvEo707rRHjOywevO7QwB8ueODlE5I Z2Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796209706; x=1796814506; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HETB4UZQrNUGf7nGhb5GuUqUZ8HybgE7qcF6GCwhhfU=; b=GzeU42t4HfqWBlvympW0MbpxKZf32cdtguxGI9osjZboGgW9wBpxpo01KnIZaABP4u 3oxEy0o5D65uOqdgTnsnTxPI1uWwd9O8UFMDsTW+pTe5adGl8lCKj2MFs4efNuAsvEhI w/buxRPabNybpoFTcLTw/THJV65vSrUwqd95U5n6fk9O+nVSUNEOa7Q7q+5THV1AsDyp vIfCgqzWvvkT2iUqH8ZHmxalxtmxO9cX8tg25GDsIqtMurmZBiUcG1NNi5MI5BR/Bbfc OcU9taTV0KFGhLCazJj4NyfohdmfpgiiItHZ74Ep6UKyOtVSuliTPeiyieSPBFFd1VbM /75w== X-Forwarded-Encrypted: i=1; AL+hErEL0JG3UEBmiFI/t7U2NxIxD3rUSk7fL/lt/yFUsOX0E/Wc7UEvAwlFznKFN3rMYfLmYdLqCSPUaE4=@lists.xenproject.org X-Gm-Message-State: APuU4Z+tDTNLyFCJr4Vj9mwBmild7TXBgJ+mLEFNP3jbVZkf8X52RuJu knOMFTNKdHwou/rmsov/DbDnTvBwdTUB51DbzThfiV7ZJEd3h/jd9iFe X-Gm-Gg: AZFdTZejflkF79ZlRI+6XC2KZWi2CjIvCyqGwu5SvUwYW8gyLUKOB0EvjR5bt0InwpU 2JVki1cbV/XgjE8ovrsSrGyQzy314iOKyoNp91VxWRAVITJjJeBPr7ISr/6vEHMT4Y600y7JpyY bJNK48fG+AkR7vpbm1mgpNlllpIY2ix1FYHZ+TynuuLaZnSAWPXQeh5NMytbgILkMHEfFdqZla+ DCDuh8WETMapi5busqhlRpZ9nGfy1austc3O8D9o9EhHWyTfulV5PIHH4Oy8vHN3xTQe3vb6w5m i12IdI81n/HcAx9aVsyC6iw5ns+vQKJ9SrhnpO7rsUpByTiFenDaw9ghFEgGnm/+3dGNtzQ1QAm cT6p1fVEopZEJsTpLqDU4lYN+vnwqM2sEARYng0G5MwLQwat7ncboTKzfN5+/2Fhb73ehSgyta2 vGGzNpT+8RbI74AZlk6pwRfTwcfrwikye6rZcmJZEl7VLg39vy5M0uN4J87RGJGdezLtwaAYell n03VKmns/5igwNgMaJQ9a024bkWVO+WRL8mWPYJPqQkYCwLUX7euXxPdif8MYUQnEuPW3fyiR3P 06otXioU1gh2JC9a3h/QRf5b9fPCZ/tHX6TY7QkpK7ylfuXKCCPna2lCo3Rd2g== X-Received: by 2002:a05:6000:4518:b0:4cd:bb56:3cad with SMTP id ffacd0b85a97d-4cdbb563f82mr827984f8f.11.1796209705564; Wed, 02 Dec 2026 03:08:25 -0800 (PST) X-Archived-By: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Dec 2026 12:08:24 +0100 Message-Id: To: "Grall, Julien" , =?utf-8?q?Gabriel_Quint=C3=A1ns_Souto?= , Cc: "Luca Fancellu" , "Stefano Stabellini" , "Bertrand Marquis" , "Michal Orzel" , "Volodymyr Babchuk" Subject: Re: [PATCH 2/3] xen/arm: p2m: split level 1 foreign superpages for preemption From: =?utf-8?q?Gabriel_Quint=C3=A1ns_Souto?= X-Mailer: aerc 0.21.0 References: <20261130164324.47726-1-gabi.qs.mail@gmail.com> <20261130164324.47726-3-gabi.qs.mail@gmail.com> <4f2643a0-4f1e-430e-8a95-384d540eec84@xen.org> In-Reply-To: <4f2643a0-4f1e-430e-8a95-384d540eec84@xen.org> X-purgate-ID: tlsNG-c1860d/1796209706-D437587B-EBE4F6D4/0/0 X-purgate-type: clean X-purgate-size: 3724 X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed Dec 2, 2026 at 11:06 AM CET, Julien Grall wrote: > Hi Gabriel, > > Thank you for the series. > > On 30/11/2026 16:43, Gabriel Quint=C3=A1ns Souto wrote: >> Static shared memory can create 1GB foreign mappings, as >> p2m_set_entry() picks the mapping size based only on alignment. >> p2m_put_page() doesn't have a put for level 1, so the references of >> such a mapping are never dropped, the pages are never freed and >> destroying the owner never completes. >>=20 >> Putting the references of a 1GB block at once would take too long >> without being able to preempt, since relinquish_p2m_mapping() can only >> be preempted between entries. By changing the order to 2MB, >> __p2m_set_entry() can split the superpage and therefore put 2MB >> blocks, allowing the preemption check in relinquish_p2m_mapping() to >> work properly. For that, the check also needs ">=3D" instead of ">". >>=20 >> Signed-off-by: Gabriel Quint=C3=A1ns Souto >> --- >> xen/arch/arm/mmu/p2m.c | 19 ++++++++++++++++++- >> 1 file changed, 18 insertions(+), 1 deletion(-) >>=20 >> diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c >> index bc6d196..e7a27db 100644 >> --- a/xen/arch/arm/mmu/p2m.c >> +++ b/xen/arch/arm/mmu/p2m.c >> @@ -1595,6 +1595,13 @@ int relinquish_p2m_mapping(struct domain *d) >> start =3D gfn_next_boundary(start, order) ) >> { >> mfn_t mfn =3D p2m_get_entry(p2m, start, &t, NULL, &order, NULL= ); >> + bool split =3D false; >> + >> + if ( p2m_is_foreign(t) && order =3D=3D XEN_PT_LEVEL_ORDER(1) ) >> + { >> + order =3D XEN_PT_LEVEL_ORDER(2); >> + split =3D true; >> + } >> =20 >> count++; >> /* >> @@ -1602,7 +1609,7 @@ int relinquish_p2m_mapping(struct domain *d) >> * foreign mapping. >> */ >> if ( (!(count % 512) || >> - (p2m_is_foreign(t) && (order > XEN_PT_LEVEL_ORDER(2)))) &= & >> + (p2m_is_foreign(t) && (order >=3D XEN_PT_LEVEL_ORDER(2)))= ) && >> hypercall_preempt_check() ) >> { >> rc =3D -ERESTART; >> @@ -1621,6 +1628,16 @@ int relinquish_p2m_mapping(struct domain *d) >> */ >> rc =3D __p2m_set_entry(p2m, start, order, INVALID_MFN, >> p2m_invalid, p2m_access_rwx); >> + if ( unlikely(rc =3D=3D -ENOMEM && split) ) >> + { >> + /* >> + * Shattering the foreign superpage needs a page from t= he P2M >> + * pool. If none is left, remove the whole superpage at= once. >> + */ > > Wouldn't this re-introduce the long running operation you were trying to= =20 > prevent? > With the whole series applied, relinquish_p2m_mapping() shatters the 1GB mapping into 2MB mappings, and then calls __p2m_set_entry() on each of them with preemption. It only falls back to the level 1 put handler if the P2M pool is exhausted, which should be rare. > But I think it is not great to require memory when tearing down the=20 > domain. I would prefer if we consider dropping support for 1GiB foreign= =20 > and always force mapping with 2MiB. > > Cheers, IMO it's better to keep 1GB foreign mappings, since forcing 2MB changes how any 1GB aligned static shm region is mapped and loses the benefit of 1GB blocks. The memory needed at teardown is one page from the P2M pool per 1GB foreign mapping, and if it isn't available the fallback still puts the pages. That said, if you still prefer forcing 2MB, I'll do that in v2. Best regards, Gabriel