All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gabriel Quintáns Souto" <gabi.qs.mail@gmail.com>
To: "Grall, Julien" <julien@xen.org>,
	"Gabriel Quintáns Souto" <gabi.qs.mail@gmail.com>,
	xen-devel@lists.xenproject.org
Cc: "Luca Fancellu" <luca.fancellu@arm.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Bertrand Marquis" <bertrand.marquis@arm.com>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH 2/3] xen/arm: p2m: split level 1 foreign superpages for preemption
Date: Wed, 02 Dec 2026 14:36:35 +0100	[thread overview]
Message-ID: <DNAACN775467.12QK0VHKIIE9A@gmail.com> (raw)
In-Reply-To: <20978813-bfb9-4645-b5a3-08ad10d5f12a@xen.org>

On Wed Dec 2, 2026 at 12:49 PM CET, Julien Grall wrote:
> Hi,
>
> On 02/12/2026 11:08, Gabriel Quintáns 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áns 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 ">=" instead of ">".
>>>>
>>>> Signed-off-by: Gabriel Quintáns Souto <gabi.qs.mail@gmail.com>
>>>> ---
>>>>    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 = gfn_next_boundary(start, order) )
>>>>        {
>>>>            mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL);
>>>> +        bool split = false;
>>>> +
>>>> +        if ( p2m_is_foreign(t) && order == XEN_PT_LEVEL_ORDER(1) )
>>>> +        {
>>>> +            order = XEN_PT_LEVEL_ORDER(2);
>>>> +            split = true;
>>>> +        }
>>>>    
>>>>            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 >= XEN_PT_LEVEL_ORDER(2)))) &&
>>>>                 hypercall_preempt_check() )
>>>>            {
>>>>                rc = -ERESTART;
>>>> @@ -1621,6 +1628,16 @@ int relinquish_p2m_mapping(struct domain *d)
>>>>                 */
>>>>                rc = __p2m_set_entry(p2m, start, order, INVALID_MFN,
>>>>                                     p2m_invalid, p2m_access_rwx);
>>>> +            if ( unlikely(rc == -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 to
>>> 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.
>
> My concern is a guest could trigger the P2M pool exhaustion if the pool 
> was not properly sized. This would be a DoS and therefore a security 
> issue. I don't think it is acceptable even if this is rare.
>
>> 
>>> 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,
>> 
>> 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.
>
>> 
>> 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 
> 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


  reply	other threads:[~2026-12-02 13:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:43 [PATCH 0/3] xen/arm: p2m: free 1GB static shared memory on domain destroy Gabriel Quintáns Souto
2026-11-30 16:43 ` [PATCH 1/3] xen/arm: p2m: add __p2m_free_entry() with a put argument Gabriel Quintáns Souto
2026-11-30 16:43 ` [PATCH 2/3] xen/arm: p2m: split level 1 foreign superpages for preemption Gabriel Quintáns Souto
2026-12-02 10:06   ` Grall, Julien
2026-12-02 11:08     ` Gabriel Quintáns Souto
2026-12-02 11:49       ` Grall, Julien
2026-12-02 13:36         ` Gabriel Quintáns Souto [this message]
2026-11-30 16:43 ` [PATCH 3/3] xen/arm: p2m: support level 1 puts if the superpage cannot be split Gabriel Quintáns Souto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DNAACN775467.12QK0VHKIIE9A@gmail.com \
    --to=gabi.qs.mail@gmail.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=luca.fancellu@arm.com \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.