From: Zhenhua Huang <quic_zhenhuah@quicinc.com>
To: <catalin.marinas@arm.com>, <will@kernel.org>, <glider@google.com>,
<elver@google.com>, <akpm@linux-foundation.org>
Cc: Zhenhua Huang <quic_zhenhuah@quicinc.com>,
<linux-arm-kernel@lists.infradead.org>, <linux-mm@kvack.org>
Subject: [PATCH] mm: kfence: export kfence_enabled as global variables
Date: Tue, 7 Feb 2023 14:15:19 +0800 [thread overview]
Message-ID: <1675750519-1064-1-git-send-email-quic_zhenhuah@quicinc.com> (raw)
Export the variable to ease the judgement of whether kfence enabled
at runtime. It should be more precise than through kernel config
"CONFIG_KFENCE".
For example We can disable kfence at runtime using bootargs
"kfence.sample_interval=0" but CONFIG_KFENCE enabled.
It was false positive.
Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
---
arch/arm64/mm/pageattr.c | 3 ++-
include/linux/kfence.h | 2 ++
mm/kfence/core.c | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index 79dd201..208d780 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -7,6 +7,7 @@
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/vmalloc.h>
+#include <linux/kfence.h>
#include <asm/cacheflush.h>
#include <asm/set_memory.h>
@@ -27,7 +28,7 @@ bool can_set_direct_map(void)
* protect/unprotect single pages.
*/
return (rodata_enabled && rodata_full) || debug_pagealloc_enabled() ||
- IS_ENABLED(CONFIG_KFENCE);
+ kfence_enabled;
}
static int change_page_range(pte_t *ptep, unsigned long addr, void *data)
diff --git a/include/linux/kfence.h b/include/linux/kfence.h
index 726857a..9fac824 100644
--- a/include/linux/kfence.h
+++ b/include/linux/kfence.h
@@ -26,6 +26,7 @@ extern unsigned long kfence_sample_interval;
*/
#define KFENCE_POOL_SIZE ((CONFIG_KFENCE_NUM_OBJECTS + 1) * 2 * PAGE_SIZE)
extern char *__kfence_pool;
+extern bool kfence_enabled;
DECLARE_STATIC_KEY_FALSE(kfence_allocation_key);
extern atomic_t kfence_allocation_gate;
@@ -222,6 +223,7 @@ bool __kfence_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *sla
#else /* CONFIG_KFENCE */
+#define kfence_enabled 0
static inline bool is_kfence_address(const void *addr) { return false; }
static inline void kfence_alloc_pool(void) { }
static inline void kfence_init(void) { }
diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index 5349c37..e5bf93d 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -48,7 +48,7 @@
/* === Data ================================================================= */
-static bool kfence_enabled __read_mostly;
+bool kfence_enabled __read_mostly;
static bool disabled_by_warn __read_mostly;
unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL;
--
2.7.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2023-02-07 6:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 6:15 Zhenhua Huang [this message]
2023-02-07 7:19 ` [PATCH] mm: kfence: export kfence_enabled as global variables Marco Elver
2023-02-07 7:46 ` Zhenhua Huang
2023-02-07 10:28 ` Alexander Potapenko
2023-02-07 10:42 ` Zhenhua Huang
2023-02-07 10:48 ` Mark Rutland
2023-02-07 12:35 ` Zhenhua Huang
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=1675750519-1064-1-git-send-email-quic_zhenhuah@quicinc.com \
--to=quic_zhenhuah@quicinc.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).