From: Willy Tarreau <willy.lkml@free.fr>
To: linux-kernel@vger.kernel.org
Subject: [BUG] 2.2.1[78] : RTNETLINK lock not properly locking ?
Date: Wed, 22 Nov 2000 10:39:03 +0100 (MET) [thread overview]
Message-ID: <974885943.3a1b9437847da@imp.free.fr> (raw)
Hello !
while I was searching how to implement an rtnl_lock() in the bonding code,
I discovered that the rtnl_shlock() function in 2.2.1[78] could misbehave if
CONFIG_RTNETLINK is not set :
- it will nearly never allow concurrent accesses (seems to be what was
intented when it was written)
- it will not always prevent concurrent accesses, which is weird because
rtnl_lock() only relies on rtnl_shlock() (and exlock, which is empty) to
protect sensible areas
The first case is trivial : one at a time.
(code taken from include/linux/rtnetlink.h, line 639)
while (atomic_read(&rtnl_rlockct))
sleep_on(&rtnl_wait);
atomic_inc(&rtnl_rlockct);
The second case isn't trivial, so I will quote some points in the code :
[rtnl_shlock]
(1) ---------
while (atomic_read(&rtnl_rlockct))
(2) ---------
sleep_on(&rtnl_wait);
(3) ---------
atomic_inc(&rtnl_rlockct);
(4) ---------
[rtnl_shunlock]
(5) ---------
if (atomic_dec_and_test(&rtnl_rlockct))
(6) ---------
wake_up(&rtnl_wait);
(7) ---------
Consider 3 concurrent threads A, B and C.
- First, A needs the lock. Noone has it. It enters (1), then (3), sets the
rtnl_rlockct to 1 and exits at (4).
- now B comes in (1). The lock is already set by A, so B goes to (2) and
sleeps.
- A unlocks. It goes to (5), then (6)
- at this moment, C tries to lock in (1), an succeeds since A has just released
the lock. So it gets the lock and goes to (3), then (4).
- A is at (6) and wakes B up and steps to (7) and exits.
- B is woken up and goes to (3) then (4).
=> B and C both have the lock.
Perhaps I have missed something, but I don't find what. If I'm right, then why
don't we simply keep the same code as for the CONFIG_RTNETLINK case ?
Thanks in advance for any comment,
Regards,
Willy
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next reply other threads:[~2000-11-22 10:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-22 9:39 Willy Tarreau [this message]
2000-11-22 9:46 ` [BUG] 2.2.1[78] : RTNETLINK lock not properly locking ? David S. Miller
2000-11-22 11:27 ` Willy Tarreau
2000-11-22 11:27 ` David S. Miller
2000-11-22 15:36 ` Willy Tarreau
2000-11-22 18:09 ` kuznet
2000-11-23 6:14 ` Willy Tarreau
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=974885943.3a1b9437847da@imp.free.fr \
--to=willy.lkml@free.fr \
--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