diff mbox series

[1/3] kasan: move kasan_shadow_to_mem() to shared header

Message ID 20211202112731.3346975-2-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64: kasan: log potential KASAN shadow aliases | expand

Commit Message

Mark Rutland Dec. 2, 2021, 11:27 a.m. UTC
Some arch code would like to convert a shadow address to a corresponding
memory address, e.g. for better reporting when a fault is taken on a
shadow access.

We already provide architectures with kasan_mem_to_shadow() and all the
underlying constants, so we may as well allow them to use
kasan_shadow_to_mem() rather than having to open-code this.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
---
 include/linux/kasan.h | 6 ++++++
 mm/kasan/kasan.h      | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index d8783b682669..9059533e19c3 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -56,6 +56,12 @@  static inline void *kasan_mem_to_shadow(const void *addr)
 		+ KASAN_SHADOW_OFFSET;
 }
 
+static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
+{
+	return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
+		<< KASAN_SHADOW_SCALE_SHIFT);
+}
+
 int kasan_add_zero_shadow(void *start, unsigned long size);
 void kasan_remove_zero_shadow(void *start, unsigned long size);
 
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index aebd8df86a1f..9ec09154ceb1 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -213,12 +213,6 @@  struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache,
 
 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
 
-static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
-{
-	return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
-		<< KASAN_SHADOW_SCALE_SHIFT);
-}
-
 static inline bool addr_has_metadata(const void *addr)
 {
 	return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START));