This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch releases/12.3
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8e5ab446cd1d49ac44f403f6dbcdcc916a5fe2c9
Author: Ville Juven <ville.ju...@unikie.com>
AuthorDate: Tue Oct 3 13:33:41 2023 +0300

    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.
---
 mm/kmap/kmm_map.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/mm/kmap/kmm_map.c b/mm/kmap/kmm_map.c
index 4358ae57a6..1deb0f25ce 100644
--- a/mm/kmap/kmm_map.c
+++ b/mm/kmap/kmm_map.c
@@ -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();

Reply via email to