linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>,
	"kasan-dev@googlegroups.com" <kasan-dev@googlegroups.com>
Subject: [PATCH 2/4] mm/kasan: Move kasan_pXX_table() and kasan_early_shadow_page_entry()
Date: Wed, 2 Feb 2022 08:44:58 +0000	[thread overview]
Message-ID: <3fe9bf0867b2ffc7cd43fe7040ee18d245641ec1.1643791473.git.christophe.leroy@csgroup.eu> (raw)
In-Reply-To: <a480ac6f31eece520564afd0230c277c78169aa5.1643791473.git.christophe.leroy@csgroup.eu>

In order to reuse them outside of mm/kasan/init.c, move the
following helpers outside of init.c:

	kasan_p4d_table()
	kasan_pud_table()
	kasan_pmd_table()
	kasan_pte_table()
	kasan_early_shadow_page_entry()

And make them available when KASAN is not selected.

Inclusion of kasan.h in mm.h needs to be moved down a bit
in order to get lm_alias() definition.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 include/linux/kasan.h | 57 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/mm.h    |  3 ++-
 mm/kasan/init.c       | 37 ----------------------------
 3 files changed, 59 insertions(+), 38 deletions(-)

diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index c29778b25d8a..1629797198ec 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -28,6 +28,7 @@ struct kunit_kasan_expectation {
 #ifdef CONFIG_KASAN_SOFTWARE
 
 #include <linux/pgtable.h>
+#include <linux/mm.h>
 
 /* Software KASAN implementations use shadow memory. */
 
@@ -81,6 +82,62 @@ static inline void kasan_disable_current(void) {}
 
 #endif /* CONFIG_KASAN_SOFTWARE */
 
+#if defined(CONFIG_KASAN_SOFTWARE) && CONFIG_PGTABLE_LEVELS > 4
+static inline bool kasan_p4d_table(pgd_t pgd)
+{
+	return pgd_page(pgd) == virt_to_page(lm_alias(kasan_early_shadow_p4d));
+}
+#else
+static inline bool kasan_p4d_table(pgd_t pgd)
+{
+	return false;
+}
+#endif
+#if defined(CONFIG_KASAN_SOFTWARE) && CONFIG_PGTABLE_LEVELS > 3
+static inline bool kasan_pud_table(p4d_t p4d)
+{
+	return p4d_page(p4d) == virt_to_page(lm_alias(kasan_early_shadow_pud));
+}
+#else
+static inline bool kasan_pud_table(p4d_t p4d)
+{
+	return false;
+}
+#endif
+#if defined(CONFIG_KASAN_SOFTWARE) && CONFIG_PGTABLE_LEVELS > 2
+static inline bool kasan_pmd_table(pud_t pud)
+{
+	return pud_page(pud) == virt_to_page(lm_alias(kasan_early_shadow_pmd));
+}
+#else
+static inline bool kasan_pmd_table(pud_t pud)
+{
+	return false;
+}
+#endif
+
+#ifdef CONFIG_KASAN_SOFTWARE
+static inline bool kasan_pte_table(pmd_t pmd)
+{
+	return pmd_page(pmd) == virt_to_page(lm_alias(kasan_early_shadow_pte));
+}
+
+static inline bool kasan_early_shadow_page_entry(pte_t pte)
+{
+	return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page));
+}
+#else
+static inline bool kasan_pte_table(pmd_t pmd)
+{
+	return false;
+}
+
+static inline bool kasan_early_shadow_page_entry(pte_t pte)
+{
+	return false;
+}
+#endif
+
 #ifdef CONFIG_KASAN_HW_TAGS
 
 DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index e1a84b1e6787..b06ee84b3717 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -31,7 +31,6 @@
 #include <linux/sizes.h>
 #include <linux/sched.h>
 #include <linux/pgtable.h>
-#include <linux/kasan.h>
 
 struct mempolicy;
 struct anon_vma;
@@ -121,6 +120,8 @@ extern int mmap_rnd_compat_bits __read_mostly;
 #define lm_alias(x)	__va(__pa_symbol(x))
 #endif
 
+#include <linux/kasan.h>
+
 /*
  * To prevent common memory management code establishing
  * a zero page mapping on a read fault.
diff --git a/mm/kasan/init.c b/mm/kasan/init.c
index cc64ed6858c6..e863071a49ef 100644
--- a/mm/kasan/init.c
+++ b/mm/kasan/init.c
@@ -30,53 +30,16 @@ unsigned char kasan_early_shadow_page[PAGE_SIZE] __page_aligned_bss;
 
 #if CONFIG_PGTABLE_LEVELS > 4
 p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D] __page_aligned_bss;
-static inline bool kasan_p4d_table(pgd_t pgd)
-{
-	return pgd_page(pgd) == virt_to_page(lm_alias(kasan_early_shadow_p4d));
-}
-#else
-static inline bool kasan_p4d_table(pgd_t pgd)
-{
-	return false;
-}
 #endif
 #if CONFIG_PGTABLE_LEVELS > 3
 pud_t kasan_early_shadow_pud[MAX_PTRS_PER_PUD] __page_aligned_bss;
-static inline bool kasan_pud_table(p4d_t p4d)
-{
-	return p4d_page(p4d) == virt_to_page(lm_alias(kasan_early_shadow_pud));
-}
-#else
-static inline bool kasan_pud_table(p4d_t p4d)
-{
-	return false;
-}
 #endif
 #if CONFIG_PGTABLE_LEVELS > 2
 pmd_t kasan_early_shadow_pmd[MAX_PTRS_PER_PMD] __page_aligned_bss;
-static inline bool kasan_pmd_table(pud_t pud)
-{
-	return pud_page(pud) == virt_to_page(lm_alias(kasan_early_shadow_pmd));
-}
-#else
-static inline bool kasan_pmd_table(pud_t pud)
-{
-	return false;
-}
 #endif
 pte_t kasan_early_shadow_pte[MAX_PTRS_PER_PTE + PTE_HWTABLE_PTRS]
 	__page_aligned_bss;
 
-static inline bool kasan_pte_table(pmd_t pmd)
-{
-	return pmd_page(pmd) == virt_to_page(lm_alias(kasan_early_shadow_pte));
-}
-
-static inline bool kasan_early_shadow_page_entry(pte_t pte)
-{
-	return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page));
-}
-
 static __init void *early_alloc(size_t size, int node)
 {
 	void *ptr = memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),
-- 
2.33.1


  reply	other threads:[~2022-02-02  8:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02  8:44 [PATCH 1/4] mm/kasan: Add CONFIG_KASAN_SOFTWARE Christophe Leroy
2022-02-02  8:44 ` Christophe Leroy [this message]
2022-02-02 12:48   ` [PATCH 2/4] mm/kasan: Move kasan_pXX_table() and kasan_early_shadow_page_entry() kernel test robot
2022-02-02 12:49   ` kernel test robot
2022-02-02  8:45 ` [PATCH 3/4] powerpc/ptdump: Use kasan_pXX_table() Christophe Leroy
2022-02-02  8:45 ` [PATCH 4/4] [RFC] risc/kasan: " Christophe Leroy
2022-02-02 13:50 ` [PATCH 1/4] mm/kasan: Add CONFIG_KASAN_SOFTWARE kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3fe9bf0867b2ffc7cd43fe7040ee18d245641ec1.1643791473.git.christophe.leroy@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryabinin.a.a@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox