Skip to contentSkip to conversation

lib/vsprintf: Make no_hash_pointers take effect early

PATCH Superseded Kaitao Cheng 2 participants 2 messages Jun 12 – Jun 16

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib/vsprintf: Make no_hash_pointers take effect early

From: Kaitao Cheng <[email protected]>

The no_hash_pointers boot parameter is now handled as an alias for hash_pointers=never. However, hash_pointers=never only records the selected mode during early parameter parsing, and no_hash_pointers is not updated until hash_pointers_finalize() runs later from SLUB init.

This leaves a window during very early boot where %p output is still hashed even though the user explicitly requested unhashed pointers with no_hash_pointers or hash_pointers=never.

Set no_hash_pointers as soon as the "never" mode is parsed. The later hash_pointers_finalize() call still keeps the final policy decision in one place, but explicit requests to disable pointer hashing now take effect for early boot users too.

In Documentation/admin-guide/kernel-parameters.txt, the descriptions of both no_hash_pointers and hash_pointers= are already marked as [KNL,EARLY], which match the current semantics.

---
Changes in v2 (Andy Shevchenko):
- Add a description of the kernel documentation to the commit log.

Link to v1:
https://lore.kernel.org/all/[email protected]/

---
 lib/vsprintf.c | 1 +
 1 file changed, 1 insertion(+)
lib/vsprintf.c +1 -0
index 4221e95701f9..9d35c84f6c49 100644
@@ -2361,6 +2361,7 @@ static int __init hash_pointers_mode_parse(char *str)
 	} else if (strcmp(str, "never") == 0) {
 		pr_info("Hash pointers mode set to never.\n");
 		hash_pointers_mode = HASH_PTR_NEVER;
+		no_hash_pointers = true;
 	} else if (strcmp(str, "always") == 0) {
 		pr_info("Hash pointers mode set to always.\n");
 		hash_pointers_mode = HASH_PTR_ALWAYS;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 23 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

The no_hash_pointers boot parameter is now handled as an alias for hash_pointers=never. However, hash_pointers=never only records the selected mode during early parameter parsing, and no_hash_pointers is not updated until hash_pointers_finalize() runs later from SLUB init.

This leaves a window during very early boot where %p output is still hashed even though the user explicitly requested unhashed pointers with no_hash_pointers or hash_pointers=never.

Set no_hash_pointers as soon as the "never" mode is parsed. The later hash_pointers_finalize() call still keeps the final policy decision in one place, but explicit requests to disable pointer hashing now take effect for early boot users too.

In Documentation/admin-guide/kernel-parameters.txt, the descriptions of both no_hash_pointers and hash_pointers= are already marked as [KNL,EARLY], which match the current semantics.

lib/vsprintf.c static int __init hash_pointers_mode_parse(char *str) · line 2367

Quoted 7 lines
lib/vsprintf.c +1 -0
@@ -2361,6 +2361,7 @@ static int __init hash_pointers_mode_parse(char *str)
 	} else if (strcmp(str, "never") == 0) {
 		pr_info("Hash pointers mode set to never.\n");
 		hash_pointers_mode = HASH_PTR_NEVER;
+		no_hash_pointers = true;
 	} else if (strcmp(str, "always") == 0) {
 		pr_info("Hash pointers mode set to always.\n");
 		hash_pointers_mode = HASH_PTR_ALWAYS;

Sashiko AI has a good point that we should reset no_hash_pointers to false by default. It would handle the situation when the parameter is passed more times on the command line. Aka, the last parameter wins. See
https://sashiko.dev/#/patchset/20260612030642.14239-1-kaitao.cheng%40linux.dev

It is not a big deal. But let's do it right when touching this.

Otherwise, the patch makes sense and looks good to me.

Best Regards,
Petr