public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Jason Seba <jason.seba42@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Tomas Henzl <thenzl@redhat.com>, Jack Wang <xjtuwjp@gmail.com>,
	Suresh Thiagarajan <Suresh.Thiagarajan@pmcs.com>,
	Viswas G <Viswas.G@pmcs.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"JBottomley@parallels.com" <JBottomley@parallels.com>,
	Vasanthalakshmi Tharmarajan 
	<Vasanthalakshmi.Tharmarajan@pmcs.com>,
	linux-kernel@vger.kernel.org
Subject: Re: spinlock_irqsave() && flags (Was: pm80xx: Spinlock fix)
Date: Mon, 23 Dec 2013 19:33:41 +0100	[thread overview]
Message-ID: <20131223183341.GA6082@redhat.com> (raw)
In-Reply-To: <20131223182323.GA8656@gmail.com>

On 12/23, Ingo Molnar wrote:
>
> * Oleg Nesterov <oleg@redhat.com> wrote:
>
> > Initially I thought that this is obviously wrong, irqsave/irqrestore
> > assume that "flags" is owned by the caller, not by the lock. And
> > iirc this was certainly wrong in the past.
> >
> > But when I look at spinlock.c it seems that this code can actually
> > work. _irqsave() writes to FLAGS after it takes the lock, and
> > _irqrestore() has a copy of FLAGS before it drops this lock.
>
> I don't think that's true: if it was then the lock would not be
> irqsave, a hardware-irq could come in after the lock has been taken
> and before flags are saved+disabled.

I do agree that this pattern is not safe, that is why I decided to ask.

But, unless I missed something, with the current implementation
spin_lock_irqsave(lock, global_flags) does:

	unsigned long local_flags;

	local_irq_save(local_flags);
	spin_lock(lock);

	global_flags = local_flags;

so the access to global_flags is actually serialized by lock.

> So AFAICS this is an unsafe pattern, beyond being ugly as hell.

Yes, I think the same.

Oleg.


  reply	other threads:[~2013-12-23 18:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1387366123-3950-1-git-send-email-Viswas.G@pmcs.com>
     [not found] ` <52B8357D.60202@redhat.com>
     [not found]   ` <52B83B89.9040700@gmail.com>
     [not found]     ` <CE2C58F938F4C44EA74FFF880BAA7E5E1C68AA8A@BBYEXM01.pmc-sierra.internal>
     [not found]       ` <CAD0Z9T+69VoSnDY-Sj7a1QfJ-KLJYVyL9=WQ123XMfRvQmGdsg@mail.gmail.com>
     [not found]         ` <52B8518B.4060204@gmail.com>
     [not found]           ` <52B8569D.4050101@redhat.com>
     [not found]             ` <CAD0Z9TK-cn=X3ywSzPnEQN-FB+ue+0dHQ3EHuwonC+KfgrmPMA@mail.gmail.com>
     [not found]               ` <20131223163410.GA28220@redhat.com>
2013-12-23 17:27                 ` spinlock_irqsave() && flags (Was: pm80xx: Spinlock fix) Oleg Nesterov
2013-12-23 18:12                   ` Linus Torvalds
2013-12-23 18:24                     ` Oleg Nesterov
2013-12-23 18:43                       ` Linus Torvalds
2013-12-23 18:23                   ` Ingo Molnar
2013-12-23 18:33                     ` Oleg Nesterov [this message]
2013-12-24  8:29                       ` Ingo Molnar
2013-12-24  9:13                         ` Suresh Thiagarajan
2013-12-24 17:29                           ` James Bottomley
2013-12-27 16:18                           ` Oleg Nesterov
2014-01-02 10:31                             ` Suresh Thiagarajan
2014-01-03 20:02                               ` Dan Williams

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=20131223183341.GA6082@redhat.com \
    --to=oleg@redhat.com \
    --cc=JBottomley@parallels.com \
    --cc=Suresh.Thiagarajan@pmcs.com \
    --cc=Vasanthalakshmi.Tharmarajan@pmcs.com \
    --cc=Viswas.G@pmcs.com \
    --cc=jason.seba42@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=thenzl@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=xjtuwjp@gmail.com \
    /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