public inbox for b.a.t.m.a.n@lists.open-mesh.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 v4 10/31] batman-adv: Drop immediate batadv_hard_iface free function
Date: Tue,  5 Jan 2016 12:06:25 +0100	[thread overview]
Message-ID: <1451992006-13191-10-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1451992006-13191-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_hardif_free_ref.

Fixes: 9bb33b8d88e3 ("batman-adv: split tq information in neigh_node struct")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
v4:
 - fix function names in commit messages
 - fix double whitespace in batadv_tt_orig_list_entry_release kerneldoc
 - add extra patch for batadv_claim_free_ref kerneldoc fix
 - change the phrase "free it" in all *_free_ref/*_put functions to "release it"
v3:
 - update copyright year
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/hard-interface.h | 12 ------------
 net/batman-adv/originator.c     | 15 +++++++--------
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 5a31420..7b12ea8 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -75,18 +75,6 @@ batadv_hardif_free_ref(struct batadv_hard_iface *hard_iface)
 		call_rcu(&hard_iface->rcu, batadv_hardif_free_rcu);
 }
 
-/**
- * batadv_hardif_free_ref_now - decrement the hard interface refcounter and
- *  possibly free it (without rcu callback)
- * @hard_iface: the hard interface to free
- */
-static inline void
-batadv_hardif_free_ref_now(struct batadv_hard_iface *hard_iface)
-{
-	if (atomic_dec_and_test(&hard_iface->refcount))
-		batadv_hardif_free_rcu(&hard_iface->rcu);
-}
-
 static inline struct batadv_hard_iface *
 batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
 {
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 229651f..f6ca4e5 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -221,18 +221,17 @@ void batadv_hardif_neigh_free_ref(struct batadv_hardif_neigh_node *hardif_neigh)
 }
 
 /**
- * batadv_neigh_node_free_rcu - free the neigh_node
- * @rcu: rcu pointer of the neigh_node
+ * batadv_neigh_node_release - release neigh_node from lists and queue for
+ *  free after rcu grace period
+ * @neigh_node: neigh neighbor to free
  */
-static void batadv_neigh_node_free_rcu(struct rcu_head *rcu)
+static void batadv_neigh_node_release(struct batadv_neigh_node *neigh_node)
 {
 	struct hlist_node *node_tmp;
-	struct batadv_neigh_node *neigh_node;
 	struct batadv_hardif_neigh_node *hardif_neigh;
 	struct batadv_neigh_ifinfo *neigh_ifinfo;
 	struct batadv_algo_ops *bao;
 
-	neigh_node = container_of(rcu, struct batadv_neigh_node, rcu);
 	bao = neigh_node->orig_node->bat_priv->bat_algo_ops;
 
 	hlist_for_each_entry_safe(neigh_ifinfo, node_tmp,
@@ -251,9 +250,9 @@ static void batadv_neigh_node_free_rcu(struct rcu_head *rcu)
 	if (bao->bat_neigh_free)
 		bao->bat_neigh_free(neigh_node);
 
-	batadv_hardif_free_ref_now(neigh_node->if_incoming);
+	batadv_hardif_free_ref(neigh_node->if_incoming);
 
-	kfree(neigh_node);
+	kfree_rcu(neigh_node, rcu);
 }
 
 /**
@@ -264,7 +263,7 @@ static void batadv_neigh_node_free_rcu(struct rcu_head *rcu)
 void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node)
 {
 	if (atomic_dec_and_test(&neigh_node->refcount))
-		call_rcu(&neigh_node->rcu, batadv_neigh_node_free_rcu);
+		batadv_neigh_node_release(neigh_node);
 }
 
 /**
-- 
2.6.4


  parent reply	other threads:[~2016-01-05 11:06 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-05 11:06 [B.A.T.M.A.N.] [PATCH v4 01/31] batman-adv: Fix kernel-doc for batadv_claim_free_ref Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 02/31] batman-adv: Fix list removal of batadv_hardif_neigh_node Sven Eckelmann
2016-01-06 16:04   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 03/31] batman-adv: Avoid recursive call_rcu for batadv_bla_claim Sven Eckelmann
2016-01-06 16:12   ` Marek Lindner
2016-01-14 14:24   ` Simon Wunderlich
2016-01-14 14:28   ` [B.A.T.M.A.N.] [PATCH v5 " Sven Eckelmann
2016-01-16  4:49     ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 04/31] batman-adv: Avoid recursive call_rcu for batadv_nc_node Sven Eckelmann
2016-01-16  4:54   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 05/31] batman-adv: Drop immediate orig_node free function Sven Eckelmann
2016-01-11 15:50   ` Antonio Quartulli
2016-01-16  4:58   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 06/31] batman-adv: Drop immediate batadv_orig_ifinfo " Sven Eckelmann
2016-01-16  5:11   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 07/31] batman-adv: Drop immediate batadv_neigh_node " Sven Eckelmann
2016-01-16  5:17   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 08/31] batman-adv: Drop immediate batadv_hardif_neigh_node " Sven Eckelmann
2016-01-16  5:23   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 09/31] batman-adv: Drop immediate neigh_ifinfo " Sven Eckelmann
2016-01-16  5:25   ` Marek Lindner
2016-01-05 11:06 ` Sven Eckelmann [this message]
2016-01-16  5:30   ` [B.A.T.M.A.N.] [PATCH v4 10/31] batman-adv: Drop immediate batadv_hard_iface " Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 11/31] batman-adv: Drop reference to netdevice on last reference Sven Eckelmann
2016-01-11 15:58   ` Antonio Quartulli
2016-01-11 16:05     ` Sven Eckelmann
2016-01-11 16:04       ` Antonio Quartulli
2016-01-16  5:33   ` Marek Lindner
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 12/31] batman-adv: Add compatibility code for kref_get_unless_zero Sven Eckelmann
2016-01-07  3:39   ` Linus Lüssing
2016-01-07  8:32     ` Sven Eckelmann
2016-01-07  8:53   ` [B.A.T.M.A.N.] [PATCH v5 " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 13/31] batman-adv: Convert batadv_hardif_neigh_node to kref Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 14/31] batman-adv: Convert batadv_gw_node " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 15/31] batman-adv: Convert batadv_softif_vlan " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 16/31] batman-adv: Convert batadv_bla_backbone_gw " Sven Eckelmann
2016-01-14 14:26   ` Simon Wunderlich
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 17/31] batman-adv: Convert batadv_bla_claim " Sven Eckelmann
2016-01-14 14:25   ` Simon Wunderlich
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 18/31] batman-adv: Convert batadv_nc_node " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 19/31] batman-adv: Convert batadv_nc_path " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 20/31] batman-adv: Convert batadv_dat_entry " Sven Eckelmann
2016-01-11 16:07   ` Antonio Quartulli
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 21/31] batman-adv: Convert batadv_tvlv_container " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 22/31] batman-adv: Convert batadv_tvlv_handler " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 23/31] batman-adv: Convert batadv_tt_orig_list_entry " Sven Eckelmann
2016-01-11 16:12   ` Antonio Quartulli
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 24/31] batman-adv: Convert batadv_neigh_ifinfo " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 25/31] batman-adv: Convert batadv_orig_ifinfo " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 26/31] batman-adv: Convert batadv_neigh_node " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 27/31] batman-adv: Convert batadv_hard_iface " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 28/31] batman-adv: Convert batadv_orig_node_vlan " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 29/31] batman-adv: Convert batadv_orig_node " Sven Eckelmann
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 30/31] batman-adv: Convert batadv_tt_common_entry " Sven Eckelmann
2016-01-11 16:16   ` Antonio Quartulli
2016-01-05 11:06 ` [B.A.T.M.A.N.] [PATCH v4 31/31] batman-adv: Rename *_free_ref function to *_put Sven Eckelmann
2016-01-06 15:53 ` [B.A.T.M.A.N.] [PATCH v4 01/31] batman-adv: Fix kernel-doc for batadv_claim_free_ref Marek Lindner

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=1451992006-13191-10-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox