From: Zoltan Menyhart <Zoltan.Menyhart@bull.net>
To: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org
Subject: __down() fails to provide with acquisition semantics
Date: Fri, 14 Sep 2007 12:47:12 +0200 [thread overview]
Message-ID: <46EA66B0.1000900@bull.net> (raw)
In-Reply-To: <20070807172648.4590c3dd.kamezawa.hiroyu@jp.fujitsu.com>
I have got a concern about "__down()".
Can someone explain me, please, how it is assumed to work?
Apparently, "__down()" fails to provide with acquisition semantics
in certain situations.
Let's assume the semaphore is unavailable and there is nobody
waiting for it.
The next requester enters the slow path.
Let's assume the owner of the semaphore releases it just before
the requester would execute the line:
if (!atomic_add_negative(sleepers - 1, &sem->count)) {
Therefore the loop gets broken, the requester returns without
going to sleep.
atomic_add_negative():
atomic_add_return():
ia64_fetch_and_add():
ia64_fetchadd(i, v, rel)
At least on ia64, "atomic_add_negative()" provides with release
semantics.
"remove_wait_queue_locked()" does not care for acquisition semantics.
"wake_up_locked()" finds an empty list, it does nothing.
"spin_unlock_irqrestore()" does release semantics.
The requester is granted the semaphore and s/he enters the critical
section without making sure that the memory accesses s/he wants to
issue in the critical section cannot be made globally visible before
"atomic_add_negative()" is.
We need an acquisition semantics (at least) before entering any
critical section. Should not we have something like:
if (atomic_add_acq(sleepers - 1, &sem->count) /* ret: new val */ >= 0){
"atomic_add_acq()" would provide with acquisition semantics in
an architecture dependent way.
I think it should be made more explicit that this routine should
provide with the architecture dependent memory fencing.
What is the use of the "wake_up_locked(&sem->wait)"?
The other requester woke up, will find the semaphore unavailable...
Another question: is there any reason keeping an ia64 version when
lib/semaphore-sleepers.c and arch/ia64/kernel/semaphore.c do not
really differ?
Thanks,
Zoltan Menyhart
next prev parent reply other threads:[~2007-09-14 10:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-07 8:24 [BUGFIX][PATCH] flush icache before set_pte() in ia64 take7, [0/2] KAMEZAWA Hiroyuki
2007-08-07 8:26 ` [BUGFIX][PATCH] flush icache before set_pte() in ia64 take7, [1/2] migration fix KAMEZAWA Hiroyuki
2007-09-14 10:47 ` Zoltan Menyhart [this message]
2007-08-07 8:27 ` [BUGFIX][PATCH] flush icache before set_pte() in ia64 take7, [2/2] sync icache dcache KAMEZAWA Hiroyuki
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=46EA66B0.1000900@bull.net \
--to=zoltan.menyhart@bull.net \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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