netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 4/4] batman-adv: Make vis info stack traversal threadsafe
Date: Sun, 30 Jan 2011 10:38:52 +0100	[thread overview]
Message-ID: <1296380332-4269-4-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <201101301036.57928.sven@narfation.org>

The batman-adv vis server has to a stack which stores all information
about packets which should be send later. This stack is protected
with a spinlock that is used to prevent concurrent write access to it.

The send_vis_packets function has to take all elements from the stack
and send them to other hosts over the primary interface. The send will
be initiated without the lock which protects the stack.

The implementation using list_for_each_entry_safe has the problem that
it stores the next element as "safe ptr" to allow the deletion of the
current element in the list. The list may be modified during the
unlock/lock pair in the loop body which may make the safe pointer
not pointing to correct next element.

It is safer to remove and use the first element from the stack until no
elements are available. This does not need reduntant information which
would have to be validated each time the lock was removed.

Reported-by: Russell Senior <russell@personaltelco.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 net/batman-adv/vis.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index 988296c..de1022c 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -816,7 +816,7 @@ static void send_vis_packets(struct work_struct *work)
 		container_of(work, struct delayed_work, work);
 	struct bat_priv *bat_priv =
 		container_of(delayed_work, struct bat_priv, vis_work);
-	struct vis_info *info, *temp;
+	struct vis_info *info;
 
 	spin_lock_bh(&bat_priv->vis_hash_lock);
 	purge_vis_packets(bat_priv);
@@ -826,8 +826,9 @@ static void send_vis_packets(struct work_struct *work)
 		send_list_add(bat_priv, bat_priv->my_vis_info);
 	}
 
-	list_for_each_entry_safe(info, temp, &bat_priv->vis_send_list,
-				 send_list) {
+	while (!list_empty(&bat_priv->vis_send_list)) {
+		info = list_first_entry(&bat_priv->vis_send_list,
+					typeof(*info), send_list);
 
 		kref_get(&info->refcount);
 		spin_unlock_bh(&bat_priv->vis_hash_lock);
-- 
1.7.2.3


  parent reply	other threads:[~2011-01-30  9:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-29 21:47 pull request: batman-adv 2011-01-29 Sven Eckelmann
     [not found] ` <1296337660-12376-1-git-send-email-sven-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>
2011-01-29 21:47   ` [PATCH 01/13] batman-adv: Fix kernel panic when fetching vis data on a vis server Sven Eckelmann
2011-01-29 21:47   ` [PATCH 02/13] batman-adv: Create roughly equal sized fragments Sven Eckelmann
2011-01-29 21:47   ` [PATCH 03/13] batman-adv: Calculate correct size for merged packets Sven Eckelmann
2011-01-29 21:47   ` [PATCH 04/13] batman-adv: Remove vis info on hashing errors Sven Eckelmann
2011-01-29 21:47   ` [PATCH 05/13] batman-adv: Remove vis info element in free_info Sven Eckelmann
2011-01-29 21:47   ` [PATCH 06/13] batman-adv: Make vis info stack traversal threadsafe Sven Eckelmann
2011-01-29 21:47   ` [PATCH 07/13] batman-adv: remove unused parameters Sven Eckelmann
2011-01-29 21:47   ` [PATCH 08/13] batman-adv: Remove dangling declaration of hash_remove_element Sven Eckelmann
2011-01-29 21:47   ` [PATCH 09/13] batman-adv: Remove unused definitions Sven Eckelmann
2011-01-29 21:47   ` [PATCH 10/13] batman-adv: Remove declaration of batman_skb_recv Sven Eckelmann
2011-01-29 21:47   ` [PATCH 11/13] batman-adv: Remove unused variables Sven Eckelmann
2011-01-29 21:47   ` [PATCH 12/13] batman-adv: Update copyright years Sven Eckelmann
2011-01-29 21:47   ` [PATCH 13/13] batman-adv: Merge README of v2011.0.0 release Sven Eckelmann
2011-01-30  3:08   ` pull request: batman-adv 2011-01-29 David Miller
     [not found]     ` <20110129.190815.226768755.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-01-30  9:36       ` Sven Eckelmann
2011-01-30  9:38         ` [PATCH 1/4] batman-adv: Fix kernel panic when fetching vis data on a vis server Sven Eckelmann
2011-01-30  9:38         ` [PATCH 2/4] batman-adv: Remove vis info on hashing errors Sven Eckelmann
2011-01-30  9:38         ` [PATCH 3/4] batman-adv: Remove vis info element in free_info Sven Eckelmann
2011-01-30  9:38         ` Sven Eckelmann [this message]
     [not found]         ` <201101301036.57928.sven-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>
2011-01-30 11:56           ` pull request: batman-adv 2011-01-29 David Miller
  -- strict thread matches above, loose matches on Subject: below --
2011-01-30 12:11 pull request: batman-adv 2011-01-30 Sven Eckelmann
2011-01-30 12:11 ` [PATCH 4/4] batman-adv: Make vis info stack traversal threadsafe 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=1296380332-4269-4-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.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).