mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Austin Clements <amdragon+kernelbugzilla@mit.edu>,
	Ingo Molnar <mingo@elte.hu>, john stultz <johnstul@us.ibm.com>,
	Michael Kerrisk <mtk.manpages@googlemail.com>,
	Roland McGrath <roland@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] posix timers: use SIGQUEUE_CANCELLED when the timer is destroyed
Date: Sun, 18 May 2008 10:24:25 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.1.10.0805181024050.3020@woody.linux-foundation.org> (raw)
In-Reply-To: <20080518171543.GA25855@tv-sign.ru>



On Sun, 18 May 2008, Oleg Nesterov wrote:
> 
> Initially, I did
> 
> 	q->flags |= SIGQUEUE_CANCELLED;
> 	spin_lock_irqsave(lock, flags);
> 	q->flags &= ~SIGQUEUE_PREALLOC;
> 
> to document the fact that SIGQUEUE_CANCELLED can be set lockless, but
> then "optimized" the code, couldn't help myself... Besides, the code
> above looks really confusing without the fat comment.

Oh, and the above is *wrong*.

Why?

Becayse if SIGQUEUE_PREALLOC setting needs the lock, then setting any 
*other* bit in that word will also need the lock!

That's because

	q->flags |= SIGQUEUE_CANCELLED;

writes those other bits too - admittedly with the value they were read 
just before, but if it races with something setting SIGQUEUE_PREALLOC that 
doesn't matter - the newly written version will simply be wrong.

So the rule is that if one bit of a word needs locking, then they *all* 
do.

(On alpha, this is true even for whole bytes or shortwords - because a 
byte/shortword write is actually "read word, update byte/short, write 
word" sequence on older CPU's. So you cannot do atomic byte updates, and 
need to use locks).

			Linus

  reply	other threads:[~2008-05-18 17:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-17 15:14 Oleg Nesterov
2008-05-17 15:31 ` Oleg Nesterov
2008-05-17 17:11   ` Linus Torvalds
2008-05-18 17:15     ` Oleg Nesterov
2008-05-18 17:24       ` Linus Torvalds [this message]
2008-05-18 17:40         ` Linus Torvalds
2008-05-18 17:46         ` Oleg Nesterov
2008-05-21  2:27       ` Roland McGrath

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=alpine.LFD.1.10.0805181024050.3020@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=amdragon+kernelbugzilla@mit.edu \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mtk.manpages@googlemail.com \
    --cc=oleg@tv-sign.ru \
    --cc=roland@redhat.com \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®