xen/vmap: Introduce vmap_size() and use it

vunmap() and vfree() currently duplicate the (small) logic to find the
size of an vmap area. In a follow-up patch, we will want to introduce
another one (this time externally).

So introduce a new helper vmap_size() that will return the number of
pages in the area starting at the given address. Take the opportunity
to replace the open-coded version.

Note that vfree() was storing the type of the area in a local variable.
But this seems to have never been used (even when it was introduced).

Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Elias El Yandouzi <eliasely@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Julien Grall authored and Jan Beulich committed 2024-02-06 11:54:17 +01:00
1 parent 2213b5a293
commit ef0873946c
2 files changed
+13 -9

No files matched your search

+10 -9
View File
@@ -245,14 +245,21 @@ void *vmap(const mfn_t *mfn, unsigned int nr)
return __vmap(mfn, 1, nr, 1, PAGE_HYPERVISOR, VMAP_DEFAULT);
}
void vunmap(const void *va)
unsigned int vmap_size(const void *va)
{
unsigned long addr = (unsigned long)va;
unsigned int pages = vm_size(va, VMAP_DEFAULT);
if ( !pages )
pages = vm_size(va, VMAP_XEN);
return pages;
}
void vunmap(const void *va)
{
unsigned long addr = (unsigned long)va;
unsigned pages = vmap_size(va);
#ifndef _PAGE_NONE
destroy_xen_mappings(addr, addr + PAGE_SIZE * pages);
#else /* Avoid tearing down intermediate page tables. */
@@ -328,17 +335,11 @@ void vfree(void *va)
unsigned int i, pages;
struct page_info *pg;
PAGE_LIST_HEAD(pg_list);
enum vmap_region type = VMAP_DEFAULT;
if ( !va )
return;
pages = vm_size(va, type);
if ( !pages )
{
type = VMAP_XEN;
pages = vm_size(va, type);
}
pages = vmap_size(va);
ASSERT(pages);
for ( i = 0; i < pages; i++ )
+3
View File
@@ -25,6 +25,9 @@ void vfree(void *va);
void __iomem *ioremap(paddr_t pa, size_t len);
/* Return the number of pages in the mapping starting at address 'va' */
unsigned int vmap_size(const void *va);
static inline void iounmap(void __iomem *va)
{
unsigned long addr = (unsigned long)(void __force *)va;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.