From patchwork Tue Dec 15 23:31:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 4833 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dkim=pass reason="1024-bit key; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=iPA2b+eE; dkim-adsp=pass; dkim-atps=neutral Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id A27EA81944 for ; Wed, 16 Dec 2015 00:32:21 +0100 (CET) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a02:3100:260c:3afd:2066:82e6:79c1:88d8]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 43B93110102; Wed, 16 Dec 2015 00:32:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=20121; t=1450222341; bh=1rgiPcdPzTKBtaIeXredatmaYILgyG0b7/d4W638oIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iPA2b+eED3pDyOMii3XtIPwJOMwVqlS5Y2aF7mwJVgryJd66725dxSWnrbGPk4JKl +hjyeU1CtEgjwrTw8n7BMAKlUnGuqEKlcghqFkmwn9TWn/PrcBpyMo5utrZ7Y7Ivvo SKl8z4ZcO24rGD7BnPMZoD2yogMHCDXI4eyFk1uU= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 16 Dec 2015 00:31:37 +0100 Message-Id: <1450222316-1764-4-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1450222316-1764-1-git-send-email-sven@narfation.org> References: <1450222316-1764-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH 04/23] batman-adv: Drop immediate free functions for batadv_hardif_neigh_node X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Dec 2015 23:32:21 -0000 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 delete the entry from the lists and immediately frees the entry. This has to be avoided and thus these functions must be removed and all functions have to use instead batadv_hardif_neigh_put. Signed-off-by: Sven Eckelmann --- net/batman-adv/originator.c | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 18305d3..7735118 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -219,38 +219,6 @@ batadv_hardif_neigh_free(struct batadv_hardif_neigh_node *hardif_neigh) } /** - * batadv_hardif_neigh_release_now - release hardif neigh node from lists and - * free without waiting for rcu grace period - * @ref: kref pointer of the neigh_node - */ -static void batadv_hardif_neigh_release_now(struct kref *ref) -{ - struct batadv_hardif_neigh_node *hardif_neigh; - - hardif_neigh = container_of(ref, struct batadv_hardif_neigh_node, - refcount); - - spin_lock_bh(&hardif_neigh->if_incoming->neigh_list_lock); - hlist_del_init_rcu(&hardif_neigh->list); - spin_unlock_bh(&hardif_neigh->if_incoming->neigh_list_lock); - - batadv_hardif_free_ref_now(hardif_neigh->if_incoming); - - batadv_hardif_neigh_free(hardif_neigh); -} - -/** - * batadv_hardif_neigh_put_now - decrement the hardif neighbors refcounter - * and possibly release it (without rcu callback) - * @hardif_neigh: hardif neigh neighbor to free - */ -static void -batadv_hardif_neigh_put_now(struct batadv_hardif_neigh_node *hardif_neigh) -{ - kref_put(&hardif_neigh->refcount, batadv_hardif_neigh_release_now); -} - -/** * batadv_hardif_neigh_free_rcu - free the hardif neigh_node * @rcu: rcu pointer of the neigh_node */ @@ -263,11 +231,11 @@ static void batadv_hardif_neigh_free_rcu(struct rcu_head *rcu) } /** - * batadv_hardif_neigh_release_rcu - release hardif neigh node from lists and + * batadv_hardif_neigh_release - release hardif neigh node from lists and * queue for free after rcu grace period * * @ref: kref pointer of the neigh_node */ -static void batadv_hardif_neigh_release_rcu(struct kref *ref) +static void batadv_hardif_neigh_release(struct kref *ref) { struct batadv_hardif_neigh_node *hardif_neigh; @@ -290,7 +258,7 @@ static void batadv_hardif_neigh_release_rcu(struct kref *ref) */ void batadv_hardif_neigh_put(struct batadv_hardif_neigh_node *hardif_neigh) { - kref_put(&hardif_neigh->refcount, batadv_hardif_neigh_release_rcu); + kref_put(&hardif_neigh->refcount, batadv_hardif_neigh_release); } /** @@ -317,8 +285,8 @@ static void batadv_neigh_node_free_rcu(struct rcu_head *rcu) neigh_node->addr); if (hardif_neigh) { /* batadv_hardif_neigh_get() increases refcount too */ - batadv_hardif_neigh_put_now(hardif_neigh); - batadv_hardif_neigh_put_now(hardif_neigh); + batadv_hardif_neigh_put(hardif_neigh); + batadv_hardif_neigh_put(hardif_neigh); } if (bao->bat_neigh_free)