ARM: cpuidle: declare cpuidle_ops __read_mostly
PATCH 1/1 ARM: cpuidle: declare cpuidle_ops __read_mostly
cpuidle_ops is initialized once by arm_cpuidle_read_ops() during initialization, and thereafter is mostly read in arm_cpuidle_suspend()
The fact that it is mostly read and not written to makes it candidates for __read_mostly declarations.
--- arch/arm/kernel/cpuidle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kernel/cpuidle.c +1 -1
@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end); -static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;/** * arm_cpuidle_simple_enter() - a wrapper to cpu_do_idle()
Signature · 1 line
2.8.1
arch/arm/kernel/cpuidle.c extern struct of_cpuidle_method __cpuidle_method_of_table[]; · line 22
Quoted 10 lines · CEST Jisheng Zhang
arch/arm/kernel/cpuidle.c +1
-1@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end); -static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;
Should this perhaps be percpu data instead?
Arnd
Dear Arnd,
Quoted 9 lines · On Wed, 10 Aug 2016 10:57:57 +0200 Arnd Bergmann wrote:
Quoted 8 lines · CEST Jisheng Zhang
arch/arm/kernel/cpuidle.c +0
-0@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end);
Quoted 5 lines
arch/arm/kernel/cpuidle.c extern struct of_cpuidle_method __cpuidle_method_of_table[]; · line 22
Quoted 2 lines
arch/arm/kernel/cpuidle.c +1
-1-static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;Should this perhaps be percpu data instead?
Per my understanding, percpu is used for those vars with normal read/write frequency, while the cpuidle_ops is read mostly, so IMHO, __read_mostly is suitable, what do you think?
Thanks,
Jisheng
Quoted 16 lines · On Wed, 10 Aug 2016 16:49:57 +0800 Jisheng Zhang wrote:
cpuidle_opsis initialized once byarm_cpuidle_read_ops()during initialization, and thereafter is mostly read inarm_cpuidle_suspend()The fact that it is mostly read and not written to makes it candidates for
__read_mostlydeclarations.Signed-off-by Jisheng Zhang <[email protected]>--- arch/arm/kernel/cpuidle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/kernel/cpuidle.c +0
-0
arch/arm/kernel/cpuidle.c extern struct of_cpuidle_method __cpuidle_method_of_table[]; · line 22
Quoted 5 lines
arch/arm/kernel/cpuidle.c +1
-1@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end); -static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;
oops, I just found that "arm: apply more __ro_after_init" from Kees marked cpuidle_ops as __ro_after_init, that also meet my need, so let's drop my patch.
Thanks,
Jisheng
Quoted 19 lines · CEST Jisheng Zhang
Dear Arnd,
Quoted 9 lines · On Wed, 10 Aug 2016 10:57:57 +0200 Arnd Bergmann wrote:
Quoted 8 lines · CEST Jisheng Zhang
arch/arm/kernel/cpuidle.c +0
-0@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end);Quoted 5 lines
arch/arm/kernel/cpuidle.c extern struct of_cpuidle_method __cpuidle_method_of_table[]; · line 22
Quoted 2 lines
arch/arm/kernel/cpuidle.c +1
-1-static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;Should this perhaps be percpu data instead?
Quoted 3 lines
Per my understanding, percpu is used for those vars with normal read/write frequency, while the
cpuidle_opsis read mostly, so IMHO,__read_mostlyis suitable, what do you think?
You are right, __read_mostly is better than the normal .data section here, but percpu is also better than .data because it saves a little memory on machines that have few present CPUs than CONFIG_NR_CPUS.
So both have their advantages, we just need to pick a preference.
Actually __ro_after_init would be even better than __read_mostly here I think, as this is only updated in an __init function. I guess using that would have the added security advantage of preventing an attacker from writing to the function pointers when they find a way to overflow an access in the percpu data section.
Arnd
Quoted 21 lines · CEST Jisheng Zhang
Quoted 19 lines · On Wed, 10 Aug 2016 16:49:57 +0800 Jisheng Zhang wrote:
cpuidle_opsis initialized once byarm_cpuidle_read_ops()during initialization, and thereafter is mostly read inarm_cpuidle_suspend()The fact that it is mostly read and not written to makes it candidates for
__read_mostlydeclarations.Signed-off-by Jisheng Zhang <[email protected]>--- arch/arm/kernel/cpuidle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/kernel/cpuidle.c +0
-0@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end);
Quoted 9 lines
arch/arm/kernel/cpuidle.c extern struct of_cpuidle_method __cpuidle_method_of_table[]; · line 22
Quoted 2 lines
arch/arm/kernel/cpuidle.c +1
-1-static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;oops, I just found that "arm: apply more
__ro_after_init" from Kees markedcpuidle_opsas__ro_after_init, that also meet my need, so let's drop my patch.
Ok, just saw this reply and that matches up with what I just wrote as well.
Thanks,
Arnd
Dear Arnd,
Quoted 28 lines · On Wed, 10 Aug 2016 12:47:21 +0200 Arnd Bergmann wrote:
Quoted 19 lines · CEST Jisheng Zhang
Dear Arnd,
Quoted 9 lines · On Wed, 10 Aug 2016 10:57:57 +0200 Arnd Bergmann wrote:
Quoted 8 lines · CEST Jisheng Zhang
arch/arm/kernel/cpuidle.c +0
-0@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[]; static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel__used __section (__cpuidle_method_of_table_end);Quoted 5 lines
arch/arm/kernel/cpuidle.c extern struct of_cpuidle_method __cpuidle_method_of_table[]; · line 22
Quoted 2 lines
arch/arm/kernel/cpuidle.c +1
-1-static struct cpuidle_ops cpuidle_ops[NR_CPUS ]; +static struct cpuidle_ops cpuidle_ops[NR_CPUS ]__read_mostly ;Should this perhaps be percpu data instead?
Quoted 3 lines
Per my understanding, percpu is used for those vars with normal read/write frequency, while the
cpuidle_opsis read mostly, so IMHO,__read_mostlyis suitable, what do you think?You are right,
__read_mostlyis better than the normal .data section here, but percpu is also better than .data because it saves a little memory on machines that have few present CPUs thanCONFIG_NR_CPUS.
Quoted 8 lines
So both have their advantages, we just need to pick a preference.
Actually
__ro_after_initwould be even better than__read_mostlyhere I think, as this is only updated in an__initfunction. I guess using that would have the added security advantage of preventing an attacker from writing to the function pointers when they find a way to overflow an access in the percpu data section.
Got it, thanks for the detailed explanations.
And I think the answer to questions:
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-August/448057.html
and
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-August/448059.html
are both "yes"
Thanks,
Jisheng