LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Russell King <linux@armlinux.org.uk>,
	Alexander Potapenko <glider@google.com>,
	Marco Elver <elver@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <kasan-dev@googlegroups.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH 4/4] mm: kfence: Only load kfence_test when kfence is enabled
Date: Wed, 25 Aug 2021 17:21:16 +0800	[thread overview]
Message-ID: <20210825092116.149975-5-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20210825092116.149975-1-wangkefeng.wang@huawei.com>

Provide kfence_is_enabled() helper, only load kfence_test module
when kfence is enabled.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/kfence.h  | 2 ++
 mm/kfence/core.c        | 8 ++++++++
 mm/kfence/kfence_test.c | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/include/linux/kfence.h b/include/linux/kfence.h
index 3fe6dd8a18c1..f08f24e8a726 100644
--- a/include/linux/kfence.h
+++ b/include/linux/kfence.h
@@ -22,6 +22,8 @@
 #define KFENCE_POOL_SIZE ((CONFIG_KFENCE_NUM_OBJECTS + 1) * 2 * PAGE_SIZE)
 extern char *__kfence_pool;
 
+bool kfence_is_enabled(void);
+
 #ifdef CONFIG_KFENCE_STATIC_KEYS
 #include <linux/static_key.h>
 DECLARE_STATIC_KEY_FALSE(kfence_allocation_key);
diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index 7a97db8bc8e7..f1aaa7ebdcad 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -51,6 +51,14 @@ static unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE
 #endif
 #define MODULE_PARAM_PREFIX "kfence."
 
+bool kfence_is_enabled(void)
+{
+	if (!kfence_sample_interval || !READ_ONCE(kfence_enabled))
+		return false;
+	return true;
+}
+EXPORT_SYMBOL_GPL(kfence_is_enabled);
+
 static int param_set_sample_interval(const char *val, const struct kernel_param *kp)
 {
 	unsigned long num;
diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
index eb6307c199ea..4087f9f1497e 100644
--- a/mm/kfence/kfence_test.c
+++ b/mm/kfence/kfence_test.c
@@ -847,6 +847,8 @@ static void unregister_tracepoints(struct tracepoint *tp, void *ignore)
  */
 static int __init kfence_test_init(void)
 {
+	if (!kfence_is_enabled())
+		return 0;
 	/*
 	 * Because we want to be able to build the test as a module, we need to
 	 * iterate through all known tracepoints, since the static registration
-- 
2.26.2


  parent reply	other threads:[~2021-08-25  9:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25  9:21 [PATCH 0/4] ARM: Support KFENCE feature Kefeng Wang
2021-08-25  9:21 ` [PATCH 1/4] ARM: mm: Provide set_memory_valid() Kefeng Wang
2021-08-25  9:21 ` [PATCH 2/4] ARM: mm: Provide is_write_fault() Kefeng Wang
2021-08-25  9:21 ` [PATCH 3/4] ARM: Support KFENCE for ARM Kefeng Wang
2021-08-25 13:18   ` ownia
2021-08-25 14:31     ` Kefeng Wang
2021-08-25  9:21 ` Kefeng Wang [this message]
2021-08-25  9:31   ` [PATCH 4/4] mm: kfence: Only load kfence_test when kfence is enabled Alexander Potapenko
2021-08-25  9:54     ` Marco Elver
2021-08-25  9:55     ` Kefeng Wang
2021-08-25  9:59       ` Marco Elver
2021-08-25 10:14 ` [PATCH 0/4] ARM: Support KFENCE feature Marco Elver
2021-08-25 10:57   ` Marco Elver
2021-08-25 14:15     ` Kefeng Wang
2021-08-25 14:28     ` Kefeng Wang

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=20210825092116.149975-5-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --subject='Re: [PATCH 4/4] mm: kfence: Only load kfence_test when kfence is enabled' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).