All of lore.kernel.org
 help / color / mirror / Atom feed
From: jszhang@marvell.com (Jisheng Zhang)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: cpuidle: declare cpuidle_ops __read_mostly
Date: Wed, 10 Aug 2016 19:06:44 +0800	[thread overview]
Message-ID: <20160810190644.68966492@xhacker> (raw)
In-Reply-To: <8191851.HcPOqTYLq8@wuerfel>

Dear Arnd,

On Wed, 10 Aug 2016 12:47:21 +0200 Arnd Bergmann wrote:

> On Wednesday, August 10, 2016 5:19:26 PM CEST Jisheng Zhang wrote:
> > Dear Arnd,
> > 
> > On Wed, 10 Aug 2016 10:57:57 +0200 Arnd Bergmann wrote:
> >   
> > > On Wednesday, August 10, 2016 4:49:57 PM CEST Jisheng Zhang wrote:  
> > > > diff --git a/arch/arm/kernel/cpuidle.c b/arch/arm/kernel/cpuidle.c
> > > > index 7dccc96..762e0929 100644
> > > > --- a/arch/arm/kernel/cpuidle.c
> > > > +++ b/arch/arm/kernel/cpuidle.c
> > > > @@ -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?
> > >   
> > 
> > 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?  
> 
> 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.
> 

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

WARNING: multiple messages have this Message-ID (diff)
From: Jisheng Zhang <jszhang@marvell.com>
To: Arnd Bergmann <arnd@arndb.de>, <linux@armlinux.org.uk>,
	<daniel.lezcano@linaro.org>
Cc: <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ARM: cpuidle: declare cpuidle_ops __read_mostly
Date: Wed, 10 Aug 2016 19:06:44 +0800	[thread overview]
Message-ID: <20160810190644.68966492@xhacker> (raw)
In-Reply-To: <8191851.HcPOqTYLq8@wuerfel>

Dear Arnd,

On Wed, 10 Aug 2016 12:47:21 +0200 Arnd Bergmann wrote:

> On Wednesday, August 10, 2016 5:19:26 PM CEST Jisheng Zhang wrote:
> > Dear Arnd,
> > 
> > On Wed, 10 Aug 2016 10:57:57 +0200 Arnd Bergmann wrote:
> >   
> > > On Wednesday, August 10, 2016 4:49:57 PM CEST Jisheng Zhang wrote:  
> > > > diff --git a/arch/arm/kernel/cpuidle.c b/arch/arm/kernel/cpuidle.c
> > > > index 7dccc96..762e0929 100644
> > > > --- a/arch/arm/kernel/cpuidle.c
> > > > +++ b/arch/arm/kernel/cpuidle.c
> > > > @@ -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?
> > >   
> > 
> > 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?  
> 
> 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.
> 

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

  reply	other threads:[~2016-08-10 11:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10  8:49 [PATCH] ARM: cpuidle: declare cpuidle_ops __read_mostly Jisheng Zhang
2016-08-10  8:49 ` Jisheng Zhang
2016-08-10  8:57 ` Arnd Bergmann
2016-08-10  8:57   ` Arnd Bergmann
2016-08-10  9:19   ` Jisheng Zhang
2016-08-10  9:19     ` Jisheng Zhang
2016-08-10 10:47     ` Arnd Bergmann
2016-08-10 10:47       ` Arnd Bergmann
2016-08-10 11:06       ` Jisheng Zhang [this message]
2016-08-10 11:06         ` Jisheng Zhang
2016-08-10  9:54 ` Jisheng Zhang
2016-08-10  9:54   ` Jisheng Zhang
2016-08-10 10:49   ` Arnd Bergmann
2016-08-10 10:49     ` Arnd Bergmann

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=20160810190644.68966492@xhacker \
    --to=jszhang@marvell.com \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.