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 1/3] xen/arm: p2m: add __p2m_free_entry() with a put argument
Date: Mon, 30 Nov 2026 17:43:22 +0100 [thread overview]
Message-ID: <20261130164324.47726-2-gabi.qs.mail@gmail.com> (raw)
In-Reply-To: <20261130164324.47726-1-gabi.qs.mail@gmail.com>
If an error occurs while shattering a superpage, we only need
to free the sub-tree allocated for the split. The superpage is still
in place, so p2m_put_page() will be called when it is removed, and
calling it before would drop the references twice, which can free
pages that are still mapped.
Fixes: 3e2121ce479b ("xen/p2m: put reference for level 2 superpage")
Signed-off-by: Gabriel Quintáns Souto <gabi.qs.mail@gmail.com>
---
xen/arch/arm/mmu/p2m.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c
index 53d2893..bc6d196 100644
--- a/xen/arch/arm/mmu/p2m.c
+++ b/xen/arch/arm/mmu/p2m.c
@@ -810,9 +810,13 @@ static void p2m_put_page(const lpae_t pte, unsigned int level)
return p2m_put_l3_page(mfn, pte.p2m.type);
}
-/* Free lpae sub-tree behind an entry */
-static void p2m_free_entry(struct p2m_domain *p2m,
- lpae_t entry, unsigned int level)
+/*
+ * Free lpae sub-tree behind an entry. If put is false, the references
+ * on the leaf entries are kept, e.g. because they are copies of a
+ * superpage that is still in place.
+ */
+static void __p2m_free_entry(struct p2m_domain *p2m, lpae_t entry,
+ unsigned int level, bool put)
{
unsigned int i;
lpae_t *table;
@@ -839,14 +843,15 @@ static void p2m_free_entry(struct p2m_domain *p2m,
p2m->stats.mappings[level]--;
- p2m_put_page(entry, level);
+ if ( put )
+ p2m_put_page(entry, level);
return;
}
table = map_domain_page(lpae_get_mfn(entry));
for ( i = 0; i < XEN_PT_LPAE_ENTRIES; i++ )
- p2m_free_entry(p2m, *(table + i), level + 1);
+ __p2m_free_entry(p2m, *(table + i), level + 1, put);
unmap_domain_page(table);
@@ -867,6 +872,12 @@ static void p2m_free_entry(struct p2m_domain *p2m,
p2m_free_page(p2m->domain, pg);
}
+static void p2m_free_entry(struct p2m_domain *p2m,
+ lpae_t entry, unsigned int level)
+{
+ __p2m_free_entry(p2m, entry, level, true);
+}
+
static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry,
unsigned int level, unsigned int target,
const unsigned int *offsets)
@@ -1025,7 +1036,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
p2m->stats.mappings[level]++;
/* Free the allocated sub-tree */
- p2m_free_entry(p2m, split_pte, level);
+ __p2m_free_entry(p2m, split_pte, level, false);
rc = -ENOMEM;
goto out;
--
2.56.0
next prev parent reply other threads:[~2026-11-30 16:46 UTC|newest]
Thread overview: 6+ 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 ` Gabriel Quintáns Souto [this message]
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-2-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.