kmm_map.c: Add way to test if addr is within kmap area or not

is_kmap_vaddr is added and used to test that a given (v)addr is actually
inside the kernel map area. This gives a speed optimization for kmm_unmap,
as it is no longer necessary to take the mm_map_lock to check if such a
mapping exists; obviously if the address is not within the kmap area, it
won't be in the list either.
This commit is contained in:
Ville Juven 2023-10-03 13:33:41 +03:00 committed by Petro Karashchenko
parent d199264dca
commit 5dd0474269

View File

@ -192,6 +192,26 @@ static FAR void *map_single_user_page(uintptr_t vaddr)
return (FAR void *)vaddr;
}
/****************************************************************************
* Name: is_kmap_vaddr
*
* Description:
* Return true if the virtual address, vaddr, lies in the kmap address
* space.
*
* Input Parameters:
* vaddr - The kernel virtual address where the mapping begins.
*
* Returned Value:
* True if vaddr is in the kmap address space; false otherwise.
*
****************************************************************************/
static bool is_kmap_vaddr(uintptr_t vaddr)
{
return (vaddr >= CONFIG_ARCH_KMAP_VBASE && vaddr < ARCH_KMAP_VEND);
}
/****************************************************************************
* Name: kmm_map_lock
*
@ -301,6 +321,15 @@ void kmm_unmap(FAR void *kaddr)
unsigned int npages;
int ret;
/* Speed optimization: check that addr is within kmap area */
if (!is_kmap_vaddr((uintptr_t)kaddr))
{
/* Nope: get out */
return;
}
/* Lock the mapping list when we fiddle around with it */
ret = kmm_map_lock();