All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gabriel Quintáns Souto" <gabi.qs.mail@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: "Luca Fancellu" <luca.fancellu@arm.com>,
	"Gabriel Quintáns Souto" <gabi.qs.mail@gmail.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Julien Grall" <julien@xen.org>,
	"Bertrand Marquis" <bertrand.marquis@arm.com>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>
Subject: [PATCH 0/3] xen/arm: p2m: free 1GB static shared memory on domain destroy
Date: Mon, 30 Nov 2026 17:43:21 +0100	[thread overview]
Message-ID: <20261130164324.47726-1-gabi.qs.mail@gmail.com> (raw)

Static shared memory can map a 1GB region into the borrower with a
single level 1 foreign entry, but level 1 puts were not implemented in
p2m_put_page(). When the borrower is destroyed, the extra reference it
holds on every page of the region is left behind, so the pages are never
freed and destroying the owner afterwards never completes.

Patch 2 is the main fix: relinquish_p2m_mapping() now splits the 1GB
mapping into 2MB blocks, so the puts go through the level 2 path and
can be preempted. Patch 3 adds level 1 puts for the case where the
split can't be done. Patch 1 fixes a separate issue in the split error
path, where references were put on the copied entries while the
superpage was still mapped, and the other two depend on it.

To reproduce it, I used a dom0less setup on QEMU virt (cortex-a72,
GICv3, -m 4G) with CONFIG_STATIC_SHM, where domU1 owns a 1GB region
allocated from the heap and domU2 borrows it, both at a 1GB aligned IPA:

    domU1 {
        ...
        shm-1g {
            compatible = "xen,domain-shared-memory-v1";
            role = "owner";
            xen,shm-id = "shm-1g";
            xen,shared-mem = <0x00 0x80000000 0x00 0x40000000>;
        };
    };

    domU2 {
        ...
        shm-1g {
            compatible = "xen,domain-shared-memory-v1";
            role = "borrower";
            xen,shm-id = "shm-1g";
            xen,shared-mem = <0x00 0x80000000 0x00 0x40000000>;
        };
    };

The 'q' debug key reports "1G mappings: 1" for both domains. Then, from
dom0, I destroyed domU2 followed by domU1:

  - Without the series, free_memory only went from 1982 to 2497 MB, and
    xl destroy of domU1 never returned. 'q' showed it stuck with
    dying=1 and nr_pages=262144.
  - With the series, both destroys completed and free_memory went from
    1982 to 3525 MB.

The -ENOMEM fallback was tested through a forced failure of
p2m_alloc_page() during relinquish.

An alternative would be to limit the foreign mappings of static shared
memory to 2MB, which avoids the issue without touching the level 1
path. I went with the split instead, since the TODO in p2m_put_page()
suggests level 1 superpages were meant to be supported.

Gabriel Quintáns Souto (3):
  xen/arm: p2m: add __p2m_free_entry() with a put argument
  xen/arm: p2m: split level 1 foreign superpages for preemption
  xen/arm: p2m: support level 1 puts if the superpage cannot be split

 xen/arch/arm/mmu/p2m.c | 68 +++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 20 deletions(-)

-- 
2.56.0



             reply	other threads:[~2026-11-30 16:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:43 Gabriel Quintáns Souto [this message]
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-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=20261130164324.47726-1-gabi.qs.mail@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.