* [PATCH] xen/grant-table: fix resource leak in gnttab_init()
@ 2026-11-17 8:43 Haoxiang Li
2026-11-19 23:18 ` Edgecombe, Rick P
0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2026-11-17 8:43 UTC (permalink / raw)
To: sstabellini, linux, jgross, boris.ostrovsky, tglx, mingo, bp,
dave.hansen, x86, hpa, oleksandr_tyshchenko, david.vrabel,
konrad.wilk
Cc: xen-devel, linux-arm-kernel, linux-kernel, Haoxiang Li
For x86 PV guests, arch_gnttab_init() allocates virtual address areas
and PTE pointer arrays for the shared and status frames. These
resources are not released if the subsequent gnttab_setup() call fails.
Add arch_gnttab_free() and call it on this failure path before the
existing cleanup. Provide an empty implementation for ARM, which
is also used by ARM64.
Fixes: 162e37171276 ("x86/xen: safely map and unmap grant frames when in atomic context")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
arch/arm/xen/grant-table.c | 4 ++++
arch/x86/xen/grant-table.c | 9 +++++++++
drivers/xen/grant-table.c | 5 ++++-
include/xen/grant_table.h | 1 +
4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/arch/arm/xen/grant-table.c b/arch/arm/xen/grant-table.c
index 91cf08ba1e95..69db80877bb5 100644
--- a/arch/arm/xen/grant-table.c
+++ b/arch/arm/xen/grant-table.c
@@ -56,3 +56,7 @@ int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status)
{
return 0;
}
+
+void arch_gnttab_free(void)
+{
+}
diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c
index 5f4060b5a40d..0a89e43d804d 100644
--- a/arch/x86/xen/grant-table.c
+++ b/arch/x86/xen/grant-table.c
@@ -149,6 +149,15 @@ int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status)
return -ENOMEM;
}
+void arch_gnttab_free(void)
+{
+ if (!xen_pv_domain())
+ return;
+
+ arch_gnttab_vfree(&gnttab_shared_vm_area);
+ arch_gnttab_vfree(&gnttab_status_vm_area);
+}
+
#ifdef CONFIG_XEN_PVH
#include <xen/events.h>
#include <xen/xen-ops.h>
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 957500dd309a..fc18fe4cf7a3 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -1696,7 +1696,7 @@ int gnttab_init(void)
if (gnttab_setup() < 0) {
ret = -ENODEV;
- goto ini_nomem;
+ goto free_gnttab;
}
gnttab_size = nr_grant_frames * gnttab_interface->grefs_per_grant_frame;
@@ -1707,6 +1707,9 @@ int gnttab_init(void)
printk("Grant table initialized\n");
return 0;
+ free_gnttab:
+ arch_gnttab_free();
+
ini_nomem:
for (i--; i >= 0; i--)
free_page((unsigned long)gnttab_list[i]);
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index a33a60a2ea72..a635cadb61f1 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -203,6 +203,7 @@ gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, phys_addr_t addr,
}
int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status);
+void arch_gnttab_free(void);
int arch_gnttab_map_shared(xen_pfn_t *frames, unsigned long nr_gframes,
unsigned long max_nr_gframes,
void **__shared);
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] xen/grant-table: fix resource leak in gnttab_init()
2026-11-17 8:43 [PATCH] xen/grant-table: fix resource leak in gnttab_init() Haoxiang Li
@ 2026-11-19 23:18 ` Edgecombe, Rick P
0 siblings, 0 replies; 2+ messages in thread
From: Edgecombe, Rick P @ 2026-11-19 23:18 UTC (permalink / raw)
To: jgross@suse.com, linux@armlinux.org.uk, bp@alien8.de,
haoxiang_li2024@163.com, sstabellini@kernel.org, Ostrovsky, Boris,
mingo@redhat.com, dave.hansen@linux.intel.com, tglx@kernel.org,
david.vrabel@citrix.com, hpa@zytor.com, x86@kernel.org,
oleksandr_tyshchenko@epam.com, konrad.wilk@oracle.com
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org
On Tue, 2026-11-17 at 16:43 +0800, Haoxiang Li wrote:
> For x86 PV guests, arch_gnttab_init() allocates virtual address areas
> and PTE pointer arrays for the shared and status frames. These
> resources are not released if the subsequent gnttab_setup() call fails.
>
> Add arch_gnttab_free() and call it on this failure path before the
> existing cleanup. Provide an empty implementation for ARM, which
> is also used by ARM64.
>
> Fixes: 162e37171276 ("x86/xen: safely map and unmap grant frames when in atomic context")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
If the PV guest hits this scenario can it survive? I don't know xen pv very
well. Does this means that the PV guest has no disk or network. If so, the user
is probably not concerned with a one time memory leak.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 23:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 8:43 [PATCH] xen/grant-table: fix resource leak in gnttab_init() Haoxiang Li
2026-11-19 23:18 ` Edgecombe, Rick P
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox