lkml.org 
[lkml]   [2010]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch 1/3] printk: fix wake_up_klogd() vs cpu hotplug
On Fri, Nov 26, 2010 at 01:10:08PM +0100, Peter Zijlstra wrote:
> On Fri, 2010-11-26 at 13:00 +0100, Heiko Carstens wrote:
> > plain text document attachment (001_printk_preempt.diff)
> > From: Heiko Carstens <heiko.carstens@de.ibm.com>
> >
> > wake_up_klogd() may get called from preemtible context but uses
> > __raw_get_cpu_var() to write to a per cpu variable. If it gets preempted between
> > getting the address and writing to it, the cpu in question could be offline if
> > the process gets scheduled back and hence writes to the per cpu data of an offline
> > cpu.
> >
> > No idea why that behaviour was introduced with fa33507a "printk: robustify
> > printk, fix #2" which was supposed to fix a "using smp_processor_id() in
> > preemptible" warning.
> >
> > Let's use get_cpu_var() instead which disables preemption and makes sure that
> > the outlined scenario cannot happen.
> >
> > Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> > ---
> > kernel/printk.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > --- a/kernel/printk.c
> > +++ b/kernel/printk.c
> > @@ -1087,8 +1087,10 @@ int printk_needs_cpu(int cpu)
> >
> > void wake_up_klogd(void)
> > {
> > - if (waitqueue_active(&log_wait))
> > - __raw_get_cpu_var(printk_pending) = 1;
> > + if (waitqueue_active(&log_wait)) {
> > + get_cpu_var(printk_pending) = 1;
> > + put_cpu_var(printk_pending);
> > + }
> > }
> >
> > /**
> >
>
> But but but, the cpu can still be offlined between writing this state
> and the next tick happening, right?

Yes, that's what the second patch would fix as a side effect.


\
 
 \ /
  Last update: 2010-11-26 13:15    [W:0.134 / U:0.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site