public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	mingo@elte.hu, tglx@linutronix.de, peterz@infradead.org,
	arjan@infradead.org, rusty@rustcorp.com.au,
	jens.axboe@oracle.com
Subject: Re: Buggy IPI and MTRR code on low memory
Date: Wed, 28 Jan 2009 14:07:25 -0800	[thread overview]
Message-ID: <20090128140725.782f5cc1.akpm@linux-foundation.org> (raw)
In-Reply-To: <alpine.DEB.1.10.0901281621450.25359@gandalf.stny.rr.com>

On Wed, 28 Jan 2009 16:23:32 -0500 (EST)
Steven Rostedt <rostedt@goodmis.org> wrote:

> 
> On Wed, 28 Jan 2009, Andrew Morton wrote:
> 
> > On Wed, 28 Jan 2009 13:12:02 -0800
> > Andrew Morton <akpm@linux-foundation.org> wrote:
> > 
> > > Thought: do we need to do the kmalloc at all?  Perhaps we can instead
> > > use a statically allocated per-cpu call_single_data local to
> > > kernel/smp.c?  It would need a spinlock or something to protect it...
> > 
> > (not a spinlock - get_cpu_var/put_cpu_var will suffice)
> 
> Is that enough?
> 
> The calling IPIs may process the data after smp_call_function is made. 
> What happens if two smp_call_functions are executed one after the other? 
> The second one may corrupt the data if the IPI function has not executed 
> yet.
> 
> We may still need that "RELEASE" flag for that case.
> 

Good point.

Forget I said that - smp_call_function_single() is calling a function
on a *different* CPU, so data which is local to the calling CPU is of
course in the wrong place.

So if we're going to use per-cpu data then we'd need to protect it with
a lock.  We could (should?) have a separate lock for each destination
CPU.

We could make smp_call_function_single() block until the IPI handler
has consumed the call_single_data, in which case we might as well put
the call_single_data, onto the caller's stack, as you've done.

Or we could take the per-cpu spinlock in smp_call_function_single(),
and release it in the IPI handler, after the call_single_data has been
consumed, which is a bit more efficient.  But I have a suspicion that
this is AB/BA deadlockable.

<tries to think of any scenarios>

<fails>

So we have

smp_call_function_single(int cpu)
{
	spin_lock(per_cpu(cpu, locks));
	per_cpu(cpu, call_single_data) = <stuff>
	send_ipi(cpu);
	return;
}

ipi_handler(...)
{
	int cpu = smp_processor_id();
	call_single_data csd = per_cpu(cpu, call_single_data);

	spin_unlock(per_cpu(cpu, locks));
	use(csd);
}

does that work?

Dunno if it's any better than what you have now.  It does however
remove the unpleasant "try kmalloc and if that failed, try something
else" mess.


  reply	other threads:[~2009-01-28 22:08 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-28 16:38 Buggy IPI and MTRR code on low memory Steven Rostedt
2009-01-28 16:41 ` Steven Rostedt
2009-01-28 16:46 ` Peter Zijlstra
2009-01-28 16:56   ` Steven Rostedt
2009-01-28 17:00     ` Peter Zijlstra
2009-01-28 17:24   ` Steven Rostedt
2009-01-28 18:20     ` Peter Zijlstra
2009-01-28 18:52       ` Steven Rostedt
2009-01-28 18:22     ` Arjan van de Ven
2009-01-28 18:34       ` Steven Rostedt
2009-01-28 21:12 ` Andrew Morton
2009-01-28 21:13   ` Andrew Morton
2009-01-28 21:23     ` Steven Rostedt
2009-01-28 22:07       ` Andrew Morton [this message]
2009-01-28 22:47         ` Steven Rostedt
2009-01-28 23:20           ` Andrew Morton
2009-01-28 23:50             ` Steven Rostedt
2009-01-28 23:25 ` Rusty Russell
2009-01-28 23:41   ` Steven Rostedt
2009-01-29  0:52   ` [PATCH] use per cpu data for single cpu ipi calls Steven Rostedt
2009-01-29  1:30     ` Andrew Morton
2009-01-29  1:56       ` Steven Rostedt
2009-01-29  8:49       ` Peter Zijlstra
2009-01-29 11:13         ` Ingo Molnar
2009-01-29 11:41           ` Peter Zijlstra
2009-01-29 13:42             ` Ingo Molnar
2009-01-29 14:07             ` Steven Rostedt
2009-01-29 15:08         ` [PATCH -v2] " Steven Rostedt
2009-01-29 15:33           ` Peter Zijlstra
2009-01-29 16:17             ` Ingo Molnar
2009-01-29 17:21           ` Linus Torvalds
2009-01-29 17:44             ` Steven Rostedt
2009-01-29 17:50               ` Steven Rostedt
2009-01-29 18:08               ` Linus Torvalds
2009-01-29 18:11                 ` Steven Rostedt
2009-01-29 18:23                 ` Peter Zijlstra
2009-01-29 18:31                   ` Steven Rostedt
2009-01-29 18:39                   ` Linus Torvalds
2009-01-29 18:44                     ` Peter Zijlstra
2009-01-30 11:23                       ` Jens Axboe
2009-01-30 12:32                         ` [PATCH -v3] " Peter Zijlstra
2009-01-30 12:38                           ` Jens Axboe
2009-01-30 12:48                             ` Peter Zijlstra
2009-01-30 12:55                               ` Jens Axboe
2009-01-30 12:56                                 ` Jens Axboe
2009-01-30 13:00                                   ` Peter Zijlstra
2009-01-30 13:02                           ` [PATCH -v4] " Peter Zijlstra
2009-01-30 14:51                             ` Ingo Molnar
2009-01-30 16:04                           ` [PATCH -v3] " Linus Torvalds
2009-01-30 16:16                             ` Peter Zijlstra
2009-01-31  8:44                               ` Jens Axboe
2009-01-29 18:49                 ` [PATCH -v2] " Ingo Molnar
2009-01-30  1:55                 ` Rusty Russell
2009-01-29 17:47             ` Peter Zijlstra
2009-01-29 17:55               ` Peter Zijlstra
2009-01-29 18:08                 ` Steven Rostedt
2009-01-30  1:11           ` Rusty Russell

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=20090128140725.782f5cc1.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox