Skip to contentSkip to conversation

mm/kfence: print disabling or re-enabling message

PATCH Superseded Jackie Liu 2 participants 3 messages May 17, 2022 – May 18, 2022

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/1 mm/kfence: print disabling or re-enabling message

From: Jackie Liu <[email protected]>

By printing information, we can friendly prompt the status change information of kfence by dmesg.

---
 mm/kfence/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/kfence/core.c +5 -1
index 11a954763be9..beb552089b67 100644
@@ -67,8 +67,11 @@ static int param_set_sample_interval(const char *val, const struct kernel_param
 	if (ret < 0)
 		return ret;
 
-	if (!num) /* Using 0 to indicate KFENCE is disabled. */
+	if (!num) {
+		/* Using 0 to indicate KFENCE is disabled. */
 		WRITE_ONCE(kfence_enabled, false);
+		pr_info("KFENCE is disabled.\n");
+	}
 
 	*((unsigned long *)kp->arg) = num;
 
@@ -874,6 +877,7 @@ static int kfence_enable_late(void)
 
 	WRITE_ONCE(kfence_enabled, true);
 	queue_delayed_work(system_unbound_wq, &kfence_timer, 0);
+	pr_info("KFENCE is re-enabled.\n");
 	return 0;
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 6 lines · Jackie Liu

From: Jackie Liu <[email protected]>

By printing information, we can friendly prompt the status change information of kfence by dmesg.

Personally, I've never found this useful. If I want to get the current accurate state of KFENCE enablement, I just look at /sys/kernel/debug/kfence/stats.

Nevertheless, some comments below.

Quoted 9 lines
---
 mm/kfence/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/kfence/core.c +0 -0
index 11a954763be9..beb552089b67 100644

mm/kfence/core.c static int param_set_sample_interval(const char *val, const struct kernel_param · line 73

Quoted 8 lines
mm/kfence/core.c +3 -1
@@ -67,8 +67,11 @@ static int param_set_sample_interval(const char *val, const struct kernel_param
 	if (ret < 0)
 		return ret;
 
-	if (!num) /* Using 0 to indicate KFENCE is disabled. */
+	if (!num) {
+		/* Using 0 to indicate KFENCE is disabled. */
 		WRITE_ONCE(kfence_enabled, false);
+		pr_info("KFENCE is disabled.\n");

This will also print on boot if kfence.sample_interval=0 is passed. This is ugly.

We also have a pr_fmt, and writing "KFENCE" again is ugly, too. And adding '.' at the end of these short log lines is not something done much in the kernel, and also ugly.

So what you want is this fixup:

mm/kfence/core.c +4 -3
index beb552089b67..de5bcf2609fe 100644
@@ -67,10 +67,11 @@ static int param_set_sample_interval(const char *val, const struct kernel_param
 	if (ret < 0)
 		return ret;
 
+	/* Using 0 to indicate KFENCE is disabled. */
 	if (!num) {
-		/* Using 0 to indicate KFENCE is disabled. */
+		if (READ_ONCE(kfence_enabled))
+			pr_info("disabled\n");
 		WRITE_ONCE(kfence_enabled, false);
-		pr_info("KFENCE is disabled.\n");
 	}
 
 	*((unsigned long *)kp->arg) = num;
@@ -877,7 +878,7 @@ static int kfence_enable_late(void)
 
 	WRITE_ONCE(kfence_enabled, true);
 	queue_delayed_work(system_unbound_wq, &kfence_timer, 0);
-	pr_info("KFENCE is re-enabled.\n");
+	pr_info("re-enabled\n");
 	return 0;
 }
 
author
#2 lore raw

Hi Marco, Thanks for your reply.

May 17, 2022 11:42 AM, "Marco Elver" <[email protected]> 写到:

Quoted 12 lines · Jackie Liu
Quoted 7 lines

From: Jackie Liu <[email protected]>

By printing information, we can friendly prompt the status change information of kfence by dmesg.

Personally, I've never found this useful. If I want to get the current accurate state of KFENCE enablement, I just look at /sys/kernel/debug/kfence/stats.

Yes, I can get the status through this file, but there is no other place to indicate that the status has changed. By logging in kmsg, it can not only reflect the status change through dmesg, but also be recorded by programs such as syslog.

This is very useful for me.

Quoted 49 lines

Nevertheless, some comments below.

Quoted 9 lines

---
mm/kfence/core.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
mm/kfence/core.c +0 -0
index 11a954763be9..beb552089b67 100644

mm/kfence/core.c static int param_set_sample_interval(const char *val, const struct kernel_param · line 73

Quoted 8 lines
mm/kfence/core.c +3 -1
@@ -67,8 +67,11 @@ static int param_set_sample_interval(const char *val, const struct kernel_param
 if (ret < 0)
 return ret;
 
- if (!num) /* Using 0 to indicate KFENCE is disabled. */
+ if (!num) {
+ /* Using 0 to indicate KFENCE is disabled. */
 WRITE_ONCE(kfence_enabled, false);
+ pr_info("KFENCE is disabled.\n");

This will also print on boot if kfence.sample_interval=0 is passed. This is ugly.

We also have a pr_fmt, and writing "KFENCE" again is ugly, too. And adding '.' at the end of these short log lines is not something done much in the kernel, and also ugly.

So what you want is this fixup:

mm/kfence/core.c +3 -2
index beb552089b67..de5bcf2609fe 100644
@@ -67,10 +67,11 @@ static int param_set_sample_interval(const char *val, const struct kernel_param
 if (ret < 0)
 return ret;
 
+ /* Using 0 to indicate KFENCE is disabled. */
 if (!num) {
- /* Using 0 to indicate KFENCE is disabled. */
+ if (READ_ONCE(kfence_enabled))
+ pr_info("disabled\n");
 WRITE_ONCE(kfence_enabled, false);
- pr_info("KFENCE is disabled.\n");
 }
 
 *((unsigned long *)kp->arg) = num;

mm/kfence/core.c static int kfence_enable_late(void) · line 883

Quoted 7 lines
mm/kfence/core.c +1 -1
@@ -877,7 +878,7 @@ static int kfence_enable_late(void)
 
 WRITE_ONCE(kfence_enabled, true);
 queue_delayed_work(system_unbound_wq, &kfence_timer, 0);
- pr_info("KFENCE is re-enabled.\n");
+ pr_info("re-enabled\n");
 return 0;
 }

Thanks for you fixup.

--
Jackie Liu