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 9B647606A322 for ; Wed, 2 Dec 2026 13:37:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L9c1CYgJ Received: from list by lists.xenproject.org with outflank-mailman.1510566.1703271 (Exim 4.92) (envelope-from ) id 1xYkVk-0002NG-7R; Wed, 02 Dec 2026 13:36:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1510566.1703271; Wed, 02 Dec 2026 13:36: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 1xYkVk-0002N9-4K; Wed, 02 Dec 2026 13:36:40 +0000 Received: by outflank-mailman (input) for mailman id 1510566; Wed, 02 Dec 2026 13:36:38 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYkVi-0002Mn-Am for xen-devel@lists.xenproject.org; Wed, 02 Dec 2026 13:36:38 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYkVh-000Ga6-N9 for xen-devel@lists.xenproject.org; Wed, 02 Dec 2026 14:36:37 +0100 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b101ee0-e002-0a2a0a5209dd-0a2a4503e130-28 for ; Wed, 02 Dec 2026 14:36:37 +0100 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b101ee5-fae8-0a2a45030019-d155dd31b47a-3 for ; Wed, 02 Dec 2026 14:36:37 +0100 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-492f0a1b685so9440896f8f.0 for ; Wed, 02 Dec 2026 05:36:37 -0800 (PST) Received: from localhost (cm-93-156-217-168.telecable.es. [93.156.217.168]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110ba3sm64420199f8f.35.2026.12.02.05.36.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 05:36:36 -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:To:From:Subject:Cc: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=1796218597; x=1796823397; darn=lists.xenproject.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=rmN8F8yF2h+rV3BA/MjTDp4U8oTMVVzM7iIGdrSLm10=; b=L9c1CYgJeKpqhmDiGSqgFXLEGuLPkwY0TsuCC6VqNT6hOuGUDV/8PjfSc1cRsOn/wZ UA00kq/dQyHJlrHNaCQGn7j8NPd2m4y6eN9IvkBpi36YIEwWQoCfEcx9v6HHaMfBvz/1 PwrnrLEpHhq589UbOeQEDvc9kfKDs8EwTkFwE1H1ASq/0J4cgFHcpSaOrUHI296ijBB1 NdnP39Ke36288laOgf7QNH+5Jg0/HRbxl+wwdgbGLl68ic5VNXaMfNfqXeDLJ5dkr+gG jEyGZDP6JZot4bx8ZkcgFkIIjrdJ+AQSnle0RZtIU16PiznyaoZtJjObMkjl/jyonIhT 7U5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796218597; x=1796823397; h=in-reply-to:references:to:from:subject:cc: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=rmN8F8yF2h+rV3BA/MjTDp4U8oTMVVzM7iIGdrSLm10=; b=hSAACSvkNcSlD9X9oEWrYhdf2YuZDuGdEtrWW/2ECokuzyZ7WsjfNzvq3X7Y8de+sd YcydC8JaoBumVxpvRA0JZQlMj7JsVYOy7fAEwnxrMuUbp8ZoklC5tApmh/Of6Otz/CbT JDcDTgMgEvgvGkVIyvbFF9oK/xR2irumkwt8QnfJ/cm3SAdq8ukaoFx/RqUGlkbT6DoU 2yRo23CDVOTLRjeXEXtOwknQ5Q+e7iBg4uApafSCZA/0pg6k3nPROImQD9j1QgDRY3Yg xHK62aziT+nJVR2eTNqbtAjdR61cR6w3paXJJePefk+9y5D4KipXLLhgBDXClA9HDHW7 mGLg== X-Forwarded-Encrypted: i=1; AL+hErGBteNO8eBvcdjgpHikrZtmcb0bJsCxD+vgt94xGIWcrLzfg/mrfONwtOEOBWQMquPtjTbhVEU+dOQ=@lists.xenproject.org X-Gm-Message-State: APuU4Z/BBy97DgfFJ/z1iXuiT5eB7Dy9qQ6LVx3CFp+LAbnu4dCPqvuU 1ZsqdD0CF1o4eP19kzCX2bRnrv4iqvcuQpEMF6UFkR1Nf/DaivWgh/ww X-Gm-Gg: AZFdTZdYIS6mO45VZkNzbGNl1inMO4uWG/JG7GfUiSi/Xt/ItsT6KEznyiilOIla5AD If0lr2UTOzh6AlFTE+Rn65dGlPkzEeRHN58sDdTVz44zrg9x6jMY82xEmGpWm00WgAa2CHcswWd oU+GSNUDWoxY/pzKGIjaXIMN+TjkpcTYBTF9JBpwwTdZFJKmJ7QCn3GDY0U2nX1Btim6M3AwlPU MB+M2rv++L9SizmThZfBQh7Lp/O5rNVCOKeFodTrjiELRii+lasuK8YIxG3VMOl/686/3+DsGax YI4d+QxCfvdRWQd2BT01q82yspRTd4Z4RtvIykhaL55HmXGucGovsURkpGDpCht/seDvzTKQYZY 8EE/6vZe4SOavrNtfmoDKe5hJSFOi7hXrvWm9ITzmGZ/q/LXdZKKFsSQC1hgVGBQ8UCFIODEPWb w38rMcGt5SL7LYKbQOr0zF6Sf1YhqSHYiW+Xthfm9m65Or+hPclAaivINJ32OGIgU7iLkMeZy2X xuqSSKYi/jv0B0+6U5vPualzxYlF5hkTEQNHlCRZXUhI1eC5pSPhw0aQmkr1vJ+cV3ocMf3bQqA JbOy96Gfk0yQMMmMAwwL+DYZ8RsjZhDYK+qlRVfqfKMmBgW1WGTqjG1A18L+lCqGBfzfLV6PhNG PePvUh60= X-Received: by 2002:a5d:584f:0:b0:4b9:8ac3:f5fa with SMTP id ffacd0b85a97d-4b98ac3f6d5mr47418634f8f.48.1796218596900; Wed, 02 Dec 2026 05:36:36 -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 14:36:35 +0100 Message-Id: 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?= To: "Grall, Julien" , =?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> <20978813-bfb9-4645-b5a3-08ad10d5f12a@xen.org> In-Reply-To: <20978813-bfb9-4645-b5a3-08ad10d5f12a@xen.org> X-purgate-ID: tlsNG-33051d/1796218597-76AF94E9-C1ED7782/0/0 X-purgate-type: clean X-purgate-size: 4841 X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_GMAIL_RCVD,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 12:49 PM CET, Julien Grall wrote: > Hi, > > On 02/12/2026 11:08, Gabriel Quint=C3=A1ns Souto wrote: >> 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. >>>> >>>> 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 ">". >>>> >>>> Signed-off-by: Gabriel Quint=C3=A1ns Souto >>>> --- >>>> xen/arch/arm/mmu/p2m.c | 19 ++++++++++++++++++- >>>> 1 file changed, 18 insertions(+), 1 deletion(-) >>>> >>>> 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, N= ULL); >>>> + 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= the P2M >>>> + * pool. If none is left, remove the whole superpage = at once. >>>> + */ >>> >>> Wouldn't this re-introduce the long running operation you were trying t= o >>> prevent? >>> >>=20 >> 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. > > My concern is a guest could trigger the P2M pool exhaustion if the pool= =20 > was not properly sized. This would be a DoS and therefore a security=20 > issue. I don't think it is acceptable even if this is rare. > >>=20 >>> But I think it is not great to require memory when tearing down the >>> domain. I would prefer if we consider dropping support for 1GiB foreign >>> and always force mapping with 2MiB. >>> >>> Cheers, >>=20 >> 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. > > I agree that 1GiB mapping is better. However if I have to choose between > security and performance, I will always choose the former. > >>=20 >> That said, if you still prefer forcing 2MB, I'll do that in v2. > > Unless you can make 1GiB removal safe in all the cases, we should force= =20 > 2MiB mapping. > > Cheers, An alternative option would be to implement preemption for the level 1 put handler. This would allow having 1GB mappings without shattering them. I know dropping the support for these mappings isn't a big deal, but if it's possible I think it's good to keep it. Let me know what you think and I'll send v2. Best regards, Gabriel