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 04/30] batman-adv: Drop immediate orig_node free function
Date: Sun, 20 Dec 2015 14:17:44 +0100	[thread overview]
Message-ID: <1450617490-3544-4-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1450617490-3544-1-git-send-email-sven@narfation.org>

It is not allowed to free the memory of an object which is part of a list
which is protected by rcu-read-side-critical sections without making sure
that no other context is accessing the object anymore. This usually happens
by removing the references to this object and then waiting until the rcu
grace period is over and no one (allowedly) accesses it anymore.

But the _now functions ignore this completely. They free the object
directly even when a different context still tries to access it. This has
to be avoided and thus these functions must be removed and all functions
have to use batadv_orig_node_free_ref.

Fixes: c8bda218468a ("batman-adv: Fix rcu_barrier() miss due to double call_rcu() in TT code")
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/originator.c        | 11 -----------
 net/batman-adv/originator.h        |  1 -
 net/batman-adv/translation-table.c | 28 +++++++++++++---------------
 3 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 2681c7d..e1eda97 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -835,17 +835,6 @@ void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node)
 		call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
 }
 
-/**
- * batadv_orig_node_free_ref_now - decrement the orig node refcounter and
- * possibly free it (without rcu callback)
- * @orig_node: the orig node to free
- */
-void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node)
-{
-	if (atomic_dec_and_test(&orig_node->refcount))
-		batadv_orig_node_free_rcu(&orig_node->rcu);
-}
-
 void batadv_originator_free(struct batadv_priv *bat_priv)
 {
 	struct batadv_hashtable *hash = bat_priv->orig_hash;
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 2955775..cf07304 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -38,7 +38,6 @@ int batadv_originator_init(struct batadv_priv *bat_priv);
 void batadv_originator_free(struct batadv_priv *bat_priv);
 void batadv_purge_orig_ref(struct batadv_priv *bat_priv);
 void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node);
-void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node);
 struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
 					      const u8 *addr);
 struct batadv_hardif_neigh_node *
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 1ca8831..96c3577 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -248,20 +248,6 @@ int batadv_tt_global_hash_count(struct batadv_priv *bat_priv,
 	return count;
 }
 
-static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
-{
-	struct batadv_tt_orig_list_entry *orig_entry;
-
-	orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
-
-	/* We are in an rcu callback here, therefore we cannot use
-	 * batadv_orig_node_free_ref() and its call_rcu():
-	 * An rcu_barrier() wouldn't wait for that to finish
-	 */
-	batadv_orig_node_free_ref_now(orig_entry->orig_node);
-	kfree(orig_entry);
-}
-
 /**
  * batadv_tt_local_size_mod - change the size by v of the local table identified
  *  by vid
@@ -357,13 +343,25 @@ static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
 	batadv_tt_global_size_mod(orig_node, vid, -1);
 }
 
+/**
+ * batadv_tt_orig_list_entry_release - release  tt orig entry from lists and
+ *  queue for free after rcu grace period
+ * @orig_entry: tt orig entry to be free'd
+ */
+static void
+batadv_tt_orig_list_entry_release(struct batadv_tt_orig_list_entry *orig_entry)
+{
+	batadv_orig_node_free_ref(orig_entry->orig_node);
+	kfree_rcu(orig_entry, rcu);
+}
+
 static void
 batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry)
 {
 	if (!atomic_dec_and_test(&orig_entry->refcount))
 		return;
 
-	call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
+	batadv_tt_orig_list_entry_release(orig_entry);
 }
 
 /**
-- 
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 ` [B.A.T.M.A.N.] [PATCH v2 03/30] batman-adv: Avoid recursive call_rcu for batadv_nc_node Sven Eckelmann
2016-01-04 16:04   ` Linus Lüssing
2015-12-20 13:17 ` Sven Eckelmann [this message]
2016-01-04 16:32   ` [B.A.T.M.A.N.] [PATCH v2 04/30] batman-adv: Drop immediate orig_node free function 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-4-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.