All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH v2 03/30] batman-adv: Avoid recursive call_rcu for batadv_nc_node
Date: Sun, 20 Dec 2015 14:17:43 +0100	[thread overview]
Message-ID: <1450617490-3544-3-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1450617490-3544-1-git-send-email-sven@narfation.org>

The batadv_nc_node_free_ref function uses call_rcu to delay the free of the
batadv_nc_node object until no (already started) rcu_read_lock is enabled
anymore. This makes sure that no context is still trying to access the
object which should be removed. But batadv_nc_node also contains a
reference to orig_node which must be removed.

The reference drop of orig_node was done in the call_rcu function
batadv_nc_node_free_rcu but should actually be done in the
batadv_claim_release function to avoid nested call_rcus. This is important
because rcu_barrier (e.g. batadv_softif_free or batadv_exit) will not
detect the inner call_rcu as relevant for its execution. Otherwise this
barrier will most likely be inserted in the queue before the callback of
the first call_rcu was executed. The caller of rcu_barrier will therefore
continue to run before the inner call_rcu callback finished.

Fixes: 3ed7ada3f0bb ("batman-adv: network coding - detect coding nodes and remove these after timeout")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
v2:
 - split patchset into fixes and kref migration to make it easier when the
   decision is made where each patch will be applied

 net/batman-adv/network-coding.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 56100c5..31efa58 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -207,17 +207,14 @@ void batadv_nc_init_orig(struct batadv_orig_node *orig_node)
 }
 
 /**
- * batadv_nc_node_free_rcu - rcu callback to free an nc node and remove
- *  its refcount on the orig_node
- * @rcu: rcu pointer of the nc node
+ * batadv_nc_node_release - release nc_node from lists and queue for free after
+ *  rcu grace period
+ * @nc_node: the nc node to free
  */
-static void batadv_nc_node_free_rcu(struct rcu_head *rcu)
+static void batadv_nc_node_release(struct batadv_nc_node *nc_node)
 {
-	struct batadv_nc_node *nc_node;
-
-	nc_node = container_of(rcu, struct batadv_nc_node, rcu);
 	batadv_orig_node_free_ref(nc_node->orig_node);
-	kfree(nc_node);
+	kfree_rcu(nc_node, rcu);
 }
 
 /**
@@ -228,7 +225,7 @@ static void batadv_nc_node_free_rcu(struct rcu_head *rcu)
 static void batadv_nc_node_free_ref(struct batadv_nc_node *nc_node)
 {
 	if (atomic_dec_and_test(&nc_node->refcount))
-		call_rcu(&nc_node->rcu, batadv_nc_node_free_rcu);
+		batadv_nc_node_release(nc_node);
 }
 
 /**
-- 
2.6.4


  parent reply	other threads:[~2015-12-20 13:17 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-20 13:17 [B.A.T.M.A.N.] [PATCH v2 01/30] batman-adv: Fix list removal of batadv_hardif_neigh_node Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 02/30] batman-adv: Avoid recursive call_rcu for batadv_bla_claim Sven Eckelmann
2015-12-20 13:17 ` Sven Eckelmann [this message]
2016-01-04 16:04   ` [B.A.T.M.A.N.] [PATCH v2 03/30] batman-adv: Avoid recursive call_rcu for batadv_nc_node Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 04/30] batman-adv: Drop immediate orig_node free function Sven Eckelmann
2016-01-04 16:32   ` Linus Lüssing
2016-01-04 16:47   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 05/30] batman-adv: Drop immediate batadv_orig_ifinfo " Sven Eckelmann
2016-01-04 18:59   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 06/30] batman-adv: Drop immediate batadv_neigh_node " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 07/30] batman-adv: Drop immediate batadv_hardif_neigh_node " Sven Eckelmann
2016-01-05  1:31   ` Linus Lüssing
2016-01-05  1:50     ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 08/30] batman-adv: Drop immediate neigh_ifinfo " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 09/30] batman-adv: Drop immediate batadv_hard_iface " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 10/30] batman-adv: Drop reference to netdevice on last reference Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 11/30] batman-adv: Add compatibility code for kref_get_unless_zero Sven Eckelmann
2015-12-31 23:14   ` [B.A.T.M.A.N.] [PATCH v3 " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 12/30] batman-adv: Convert batadv_hardif_neigh_node to kref Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 13/30] batman-adv: Convert batadv_gw_node " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 14/30] batman-adv: Convert batadv_softif_vlan " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 15/30] batman-adv: Convert batadv_bla_backbone_gw " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 16/30] batman-adv: Convert batadv_bla_claim " Sven Eckelmann
2016-01-05  4:43   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 17/30] batman-adv: Convert batadv_nc_node " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 18/30] batman-adv: Convert batadv_nc_path " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 19/30] batman-adv: Convert batadv_dat_entry " Sven Eckelmann
2016-01-05  4:45   ` Linus Lüssing
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 20/30] batman-adv: Convert batadv_tvlv_container " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 21/30] batman-adv: Convert batadv_tvlv_handler " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 22/30] batman-adv: Convert batadv_tt_orig_list_entry " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 23/30] batman-adv: Convert batadv_neigh_ifinfo " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 24/30] batman-adv: Convert batadv_orig_ifinfo " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 25/30] batman-adv: Convert batadv_neigh_node " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 26/30] batman-adv: Convert batadv_hard_iface " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 27/30] batman-adv: Convert batadv_orig_node_vlan " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 28/30] batman-adv: Convert batadv_orig_node " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 29/30] batman-adv: Convert batadv_tt_common_entry " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 30/30] batman-adv: Rename *_free_ref function to *_put Sven Eckelmann
2016-01-04 16:03 ` [B.A.T.M.A.N.] [PATCH v2 01/30] batman-adv: Fix list removal of batadv_hardif_neigh_node Linus Lüssing
2016-01-05  5:02 ` Linus Lüssing
2016-01-05  9:18   ` 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=1450617490-3544-3-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.