From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [B.A.T.M.A.N.] Adding of basic gw_node/batman_if refcnt
Date: Fri, 17 Sep 2010 03:17:27 +0200 [thread overview]
Message-ID: <201009170317.28338.sven.eckelmann@gmx.de> (raw)
In-Reply-To: <1284672174-27464-1-git-send-email-sven.eckelmann@gmx.de>
[-- Attachment #1: Type: Text/Plain, Size: 1881 bytes --]
Sven Eckelmann wrote:
> Hi,
>
> if anyone wants to start to track all usage cases of the batman_if and
> gw_node then he can use the functions defined in following two patches.
> The patches are not fixes, but they provide a starting point for the
> actual bugfix.
Please ignore
[PATCH 1/2] batman-adv: Use refcnt to track usage count of gw_node
[PATCH 2/2] batman-adv: Use refcnt to track usage count of batman_if
[PATCH 2/2] batman-adv: Use refcnt to track usage count of batman_if
The problem is that the refcnt check must be done after the grace period and
not before. Otherwise we may think that nobody uses it anymore, but instead it
is still referenced inside a rcu_read_lock...rcu_read_unlock and the refcnt
will be updated a little bit later than the refcnt check is made.
rcu_read_lock | xyz_write_lock
xyz_list_rcu { | xyz_list_del_rcu(x->list)
.... | xyz_put(x)
xyz_hold(x) | -> call_rcu(free_xyz)
.... |
rcu_read_unlock |
| -> free_xyz(x)
I will repost the whole patch set later. The solution is to use
synchronize_rcu instead of call_rcu and calling free_xyz directly. This
solution is not possible if sleeping is not allowed in that situation or it is
relative time critical.
Another way is to add a deleted flag and an extra spinlock. This spinlock must
be used before "put"ting/holding an element in rcu_read_lock. So the reader
side would need following code:
spin_lock(&x->lock);
if (x->deleted) {
be confused and dont use it as valid candidate
} else {
mark it as valid candidate and hold it
}
spin_unlock(&x->lock);
on the updater/writer site we must use something like that:
spin_lock(&x->lock);
list_del_rcu(&x->list);
x->deleted = 1;
spin_unlock(&x->lock);
put element
Best regards,
Sven
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2010-09-17 1:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-16 20:18 [B.A.T.M.A.N.] Initial rcu locking patchset Sven Eckelmann
2010-09-16 20:18 ` [B.A.T.M.A.N.] [PATCH 1/4] batman-adv: Introduce if_list_lock to protect if_list Sven Eckelmann
2010-09-16 20:18 ` [B.A.T.M.A.N.] [PATCH 2/4] batman-adv: Protect update side of gw_list Sven Eckelmann
2010-09-16 20:18 ` [B.A.T.M.A.N.] [PATCH 3/4] batman-adv: Always protect list_for_each_entry_rcu with RCU Sven Eckelmann
2010-09-16 20:18 ` [B.A.T.M.A.N.] [PATCH 4/4] batman-adv: Remove unneeded rcu_read_lock Sven Eckelmann
2010-09-16 21:22 ` [B.A.T.M.A.N.] Adding of basic gw_node/batman_if refcnt Sven Eckelmann
2010-09-17 1:17 ` Sven Eckelmann [this message]
2010-09-16 21:22 ` [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: Use refcnt to track usage count of gw_node Sven Eckelmann
2010-09-16 21:22 ` [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: Use refcnt to track usage count of batman_if Sven Eckelmann
2010-09-16 21:32 ` Sven Eckelmann
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=201009170317.28338.sven.eckelmann@gmx.de \
--to=sven.eckelmann@gmx.de \
--cc=b.a.t.m.a.n@lists.open-mesh.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;
as well as URLs for NNTP newsgroup(s).