Skip to contentSkip to conversation

treewide: Make definitions of struct kernel_param_ops const

PATCH Applied Joe Perches 5 participants 12 messages Oct 4, 2020 – Oct 19, 2020

Subsystems (9)
Memory management x86 KVM PowerPC +5 more subsystems
lore
Share & tools
lore
#0 lore raw

cover treewide: Make definitions of struct kernel_param_ops const

Using const is good as it reduces data size.

Joe Perches (4):
KVM: PPC: Book3S HV: Make struct kernel_param_ops definition const kvm x86/mmu: Make struct kernel_param_ops definitions const rcu/tree: Make struct kernel_param_ops definitions const mm/zswap: Make struct kernel_param_ops definitions const

 arch/powerpc/kvm/book3s_hv.c | 2 +-
 arch/x86/kvm/mmu/mmu.c       | 4 ++--
 kernel/rcu/tree.c            | 4 ++--
 mm/zswap.c                   | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
2.26.0
#1 lore raw

PATCH 1/4 KVM: PPC: Book3S HV: Make struct kernel_param_ops definition const

This should be const, so make it so.

---
 arch/powerpc/kvm/book3s_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +1 -1
index 4ba06a2a306c..2b215852cdc9 100644
@@ -111,7 +111,7 @@ module_param(one_vm_per_core, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(one_vm_per_core, "Only run vCPUs from the same VM on a core (requires indep_threads_mode=N)");
 
 #ifdef CONFIG_KVM_XICS
-static struct kernel_param_ops module_param_ops = {
+static const struct kernel_param_ops module_param_ops = {
 	.set = param_set_int,
 	.get = param_get_int,
 };
Signature · 1 line
2.26.0
#3 lore raw

PATCH 2/4 kvm x86/mmu: Make struct kernel_param_ops definitions const

In reply to Joe Perches

These should be const, so make it so.

---
 arch/x86/kvm/mmu/mmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +2 -2
index 71aa3da2a0b7..6500dd681750 100644
@@ -64,12 +64,12 @@ static uint __read_mostly nx_huge_pages_recovery_ratio = 60;
 static int set_nx_huge_pages(const char *val, const struct kernel_param *kp);
 static int set_nx_huge_pages_recovery_ratio(const char *val, const struct kernel_param *kp);
 
-static struct kernel_param_ops nx_huge_pages_ops = {
+static const struct kernel_param_ops nx_huge_pages_ops = {
 	.set = set_nx_huge_pages,
 	.get = param_get_bool,
 };
 
-static struct kernel_param_ops nx_huge_pages_recovery_ratio_ops = {
+static const struct kernel_param_ops nx_huge_pages_recovery_ratio_ops = {
 	.set = set_nx_huge_pages_recovery_ratio,
 	.get = param_get_uint,
 };
Signature · 1 line
2.26.0
#6 lore raw

PATCH 3/4 rcu/tree: Make struct kernel_param_ops definitions const

In reply to Joe Perches

These should be const, so make it so.

---
 kernel/rcu/tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +2 -2
index f78ee759af9c..c4732bb80818 100644
@@ -552,12 +552,12 @@ static int param_set_next_fqs_jiffies(const char *val, const struct kernel_param
 	return ret;
 }
 
-static struct kernel_param_ops first_fqs_jiffies_ops = {
+static const struct kernel_param_ops first_fqs_jiffies_ops = {
 	.set = param_set_first_fqs_jiffies,
 	.get = param_get_ulong,
 };
 
-static struct kernel_param_ops next_fqs_jiffies_ops = {
+static const struct kernel_param_ops next_fqs_jiffies_ops = {
 	.set = param_set_next_fqs_jiffies,
 	.get = param_get_ulong,
 };
Signature · 1 line
2.26.0
#8 lore raw

PATCH 4/4 mm/zswap: Make struct kernel_param_ops definitions const

In reply to Joe Perches

These should be const, so make it so.

---
 mm/zswap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/zswap.c +3 -3
index fbb782924ccc..1eced701b3bd 100644
@@ -81,7 +81,7 @@ static bool zswap_pool_reached_full;
 static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON);
 static int zswap_enabled_param_set(const char *,
 				   const struct kernel_param *);
-static struct kernel_param_ops zswap_enabled_param_ops = {
+static const struct kernel_param_ops zswap_enabled_param_ops = {
 	.set =		zswap_enabled_param_set,
 	.get =		param_get_bool,
 };
@@ -91,7 +91,7 @@ module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644);
 static char *zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
 static int zswap_compressor_param_set(const char *,
 				      const struct kernel_param *);
-static struct kernel_param_ops zswap_compressor_param_ops = {
+static const struct kernel_param_ops zswap_compressor_param_ops = {
 	.set =		zswap_compressor_param_set,
 	.get =		param_get_charp,
 	.free =		param_free_charp,
@@ -102,7 +102,7 @@ module_param_cb(compressor, &zswap_compressor_param_ops,
 /* Compressed storage zpool to use */
 static char *zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
 static int zswap_zpool_param_set(const char *, const struct kernel_param *);
-static struct kernel_param_ops zswap_zpool_param_ops = {
+static const struct kernel_param_ops zswap_zpool_param_ops = {
 	.set =		zswap_zpool_param_set,
 	.get =		param_get_charp,
 	.free =		param_free_charp,
Signature · 1 line
2.26.0
#9 lore raw

Where is the declaration of buffer used in kernel_param_ops .get functions?

In reply to Joe Perches

These patches came up because I was looking for the location of the declaration of the buffer used in kernel/params.c struct kernel_param_ops .get functions.

I didn't find it.

I want to see if it's appropriate to convert the sprintf family of functions used in these .get functions to sysfs_emit.

Patches submitted here:
https://lore.kernel.org/lkml/5d606519698ce4c8f1203a2b35797d8254c6050a.1600285923.git.joe@perches.com/T/

Anyone know if it's appropriate to change the sprintf-like uses in these functions to sysfs_emit and/or sysfs_emit_at?

#10 lore raw

Re: Where is the declaration of buffer used in kernel_param_ops .get functions?

Quoted 11 lines · Joe Perches

These patches came up because I was looking for the location of the declaration of the buffer used in kernel/params.c struct kernel_param_ops .get functions.

I didn't find it.

I want to see if it's appropriate to convert the sprintf family of functions used in these .get functions to sysfs_emit.

Quoted 6 lines

Patches submitted here:
https://lore.kernel.org/lkml/5d606519698ce4c8f1203a2b35797d8254c6050a.1600285923.git.joe@perches.com/T/

Anyone know if it's appropriate to change the sprintf-like uses in these functions to sysfs_emit and/or sysfs_emit_at?

There's a lot of preprocessor magic to wade through.

I'm pretty sure this comes through include/linux/moduleparam.h and kernel/module.c.

#11 lore raw

Re: Where is the declaration of buffer used in kernel_param_ops .get functions?

Quoted 15 lines · Matthew Wilcox
Quoted 14 lines · Joe Perches

These patches came up because I was looking for the location of the declaration of the buffer used in kernel/params.c struct kernel_param_ops .get functions.

I didn't find it.

I want to see if it's appropriate to convert the sprintf family of functions used in these .get functions to sysfs_emit.

Patches submitted here:
https://lore.kernel.org/lkml/5d606519698ce4c8f1203a2b35797d8254c6050a.1600285923.git.joe@perches.com/T/

Quoted 8 lines
Quoted 3 lines

Anyone know if it's appropriate to change the sprintf-like uses in these functions to sysfs_emit and/or sysfs_emit_at?

There's a lot of preprocessor magic to wade through.

I'm pretty sure this comes through include/linux/moduleparam.h and kernel/module.c.

Dunno, looked there, still can't find it.

btw:

The __module_param_call macro looks very dodgy as it uses both __used and __attribute__((unused)) and likely one of them should be removed (unused?)

It looks like the comes from varying definitions of __attribute_used__ eventually converted to __used for old gcc versions 2, 3, and 4.

1da177e4c3f4:include/linux/compiler-gcc2.h:#define __attribute_used__   __attribute__((__unused__))
1da177e4c3f4:include/linux/compiler-gcc3.h:# define __attribute_used__  __attribute__((__used__))
1da177e4c3f4:include/linux/compiler-gcc3.h:# define __attribute_used__  __attribute__((__unused__))
1da177e4c3f4:include/linux/compiler-gcc4.h:#define __attribute_used__   __attribute__((__used__))

Maybe:

---
 include/linux/moduleparam.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/moduleparam.h +4 -4
index 47879fc7f75e..fc820b27fb00 100644
@@ -288,10 +288,10 @@ struct kparam_array
 	/* Default value instead of permissions? */			\
 	static const char __param_str_##name[] = prefix #name;		\
 	static struct kernel_param __moduleparam_const __param_##name	\
-	__used								\
-    __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
-	= { __param_str_##name, THIS_MODULE, ops,			\
-	    VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
+	__used __section("__param") __aligned(sizeof(void *)) = {	\
+		__param_str_##name, THIS_MODULE, ops,			\
+		VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg }	\
+	}
 
 /* Obsolete - use module_param_cb() */
 #define module_param_call(name, _set, _get, arg, perm)			\
maintainer
#7 lore raw

Re: [PATCH 3/4] rcu/tree: Make struct kernel_param_ops definitions const

In reply to Joe Perches
Quoted 3 lines · Joe Perches

These should be const, so make it so.

Queued for testing and review, thank you!

Thanx, Paul

Quoted 26 lines
---
 kernel/rcu/tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +2 -2
index f78ee759af9c..c4732bb80818 100644
@@ -552,12 +552,12 @@ static int param_set_next_fqs_jiffies(const char *val, const struct kernel_param
 	return ret;
 }
 
-static struct kernel_param_ops first_fqs_jiffies_ops = {
+static const struct kernel_param_ops first_fqs_jiffies_ops = {
 	.set = param_set_first_fqs_jiffies,
 	.get = param_get_ulong,
 };
 
-static struct kernel_param_ops next_fqs_jiffies_ops = {
+static const struct kernel_param_ops next_fqs_jiffies_ops = {
 	.set = param_set_next_fqs_jiffies,
 	.get = param_get_ulong,
 };
Signature · 1 line
2.26.0
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] kvm x86/mmu: Make struct kernel_param_ops definitions const

In reply to Joe Perches
Quoted 4 lines · Joe Perches

These should be const, so make it so.

Quoted 26 lines
---
 arch/x86/kvm/mmu/mmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +2 -3
index 71aa3da2a0b7..6500dd681750 100644
@@ -64,12 +64,12 @@ static uint __read_mostly nx_huge_pages_recovery_ratio = 60;
 static int set_nx_huge_pages(const char *val, const struct kernel_param *kp);
 static int set_nx_huge_pages_recovery_ratio(const char *val, const struct kernel_param *kp);
 
-static struct kernel_param_ops nx_huge_pages_ops = {
+static const struct kernel_param_ops nx_huge_pages_ops = {
        .set = set_nx_huge_pages,
        .get = param_get_bool,
 };
 
-static struct kernel_param_ops nx_huge_pages_recovery_ratio_ops = {
+static const struct kernel_param_ops nx_huge_pages_recovery_ratio_ops = {
        .set = set_nx_huge_pages_recovery_ratio,
        .get = param_get_uint,
 };
--

2.26.0

maintainer Applied
#2 lore raw

Re: [PATCH 1/4] KVM: PPC: Book3S HV: Make struct kernel_param_ops definition const

In reply to Joe Perches
Quoted 13 lines · Joe Perches

This should be const, so make it so.

---
 arch/powerpc/kvm/book3s_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +0 -0
index 4ba06a2a306c..2b215852cdc9 100644

arch/powerpc/kvm/book3s_hv.c module_param(one_vm_per_core, bool, S_IRUGO | S_IWUSR); · line 117

Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -111,7 +111,7 @@ module_param(one_vm_per_core, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(one_vm_per_core, "Only run vCPUs from the same VM on a core (requires indep_threads_mode=N)");
 
 #ifdef CONFIG_KVM_XICS
-static struct kernel_param_ops module_param_ops = {
+static const struct kernel_param_ops module_param_ops = {
 	.set = param_set_int,
 	.get = param_get_int,
 };

Queued, thanks.

Paolo