netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, allan.stephens@windriver.com,
	ying.xue@windriver.com,
	Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [PATCH net-next 11/28] tipc: Fix node lock problems during broadcast message reception
Date: Sat, 17 Sep 2011 23:32:07 -0400	[thread overview]
Message-ID: <1316316744-29514-12-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1316316744-29514-1-git-send-email-paul.gortmaker@windriver.com>

From: Allan Stephens <allan.stephens@windriver.com>

Modifies TIPC's incoming broadcast packet handler to ensure that the
node lock associated with the sender of the packet is held whenever
node-related data structure fields are accessed. The routine is also
restructured with a single exit point, making it easier to ensure
the node lock is properly released and the incoming packet is properly
disposed of.

Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 net/tipc/bcast.c |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 5200457..bc01ca6 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -426,20 +426,26 @@ int tipc_bclink_send_msg(struct sk_buff *buf)
 void tipc_bclink_recv_pkt(struct sk_buff *buf)
 {
 	struct tipc_msg *msg = buf_msg(buf);
-	struct tipc_node *node = tipc_node_find(msg_prevnode(msg));
+	struct tipc_node *node;
 	u32 next_in;
 	u32 seqno;
 	struct sk_buff *deferred;
 
-	if (unlikely(!node || !tipc_node_is_up(node) || !node->bclink.supported ||
-		     (msg_mc_netid(msg) != tipc_net_id))) {
-		buf_discard(buf);
-		return;
-	}
+	/* Screen out unwanted broadcast messages */
+
+	if (msg_mc_netid(msg) != tipc_net_id)
+		goto exit;
+
+	node = tipc_node_find(msg_prevnode(msg));
+	if (unlikely(!node))
+		goto exit;
+
+	tipc_node_lock(node);
+	if (unlikely(!node->bclink.supported))
+		goto unlock;
 
 	if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) {
 		if (msg_destnode(msg) == tipc_own_addr) {
-			tipc_node_lock(node);
 			tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
 			tipc_node_unlock(node);
 			spin_lock_bh(&bc_lock);
@@ -449,16 +455,17 @@ void tipc_bclink_recv_pkt(struct sk_buff *buf)
 					      msg_bcgap_to(msg));
 			spin_unlock_bh(&bc_lock);
 		} else {
+			tipc_node_unlock(node);
 			tipc_bclink_peek_nack(msg_destnode(msg),
 					      msg_bcast_tag(msg),
 					      msg_bcgap_after(msg),
 					      msg_bcgap_to(msg));
 		}
-		buf_discard(buf);
-		return;
+		goto exit;
 	}
 
-	tipc_node_lock(node);
+	/* Handle in-sequence broadcast message */
+
 receive:
 	deferred = node->bclink.deferred_head;
 	next_in = mod(node->bclink.last_in + 1);
@@ -491,14 +498,14 @@ receive:
 			tipc_node_unlock(node);
 			tipc_net_route_msg(buf);
 		}
+		buf = NULL;
+		tipc_node_lock(node);
 		if (deferred && (buf_seqno(deferred) == mod(next_in + 1))) {
-			tipc_node_lock(node);
 			buf = deferred;
 			msg = buf_msg(buf);
 			node->bclink.deferred_head = deferred->next;
 			goto receive;
 		}
-		return;
 	} else if (less(next_in, seqno)) {
 		u32 gap_after = node->bclink.gap_after;
 		u32 gap_to = node->bclink.gap_to;
@@ -513,6 +520,7 @@ receive:
 			else if (less(gap_after, seqno) && less(seqno, gap_to))
 				node->bclink.gap_to = seqno;
 		}
+		buf = NULL;
 		if (bclink_ack_allowed(node->bclink.nack_sync)) {
 			if (gap_to != gap_after)
 				bclink_send_nack(node);
@@ -520,9 +528,11 @@ receive:
 		}
 	} else {
 		bcl->stats.duplicates++;
-		buf_discard(buf);
 	}
+unlock:
 	tipc_node_unlock(node);
+exit:
+	buf_discard(buf);
 }
 
 u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr)
-- 
1.7.4.4

  parent reply	other threads:[~2011-09-18  3:32 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-18  3:31 [PATCH net-next 00/28] misc. TIPC updates for what will be 3.2 Paul Gortmaker
2011-09-18  3:31 ` [PATCH net-next 01/28] tipc: Remove obsolete manipulation of message re-route count field Paul Gortmaker
2011-09-18  3:31 ` [PATCH net-next 02/28] tipc: Eliminate obsolete filter for unexpected unicast messages Paul Gortmaker
2011-09-18  3:31 ` [PATCH net-next 03/28] tipc: Display meaningful peer interface name during link creation Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 04/28] tipc: Initialize peer session field of newly created link endpoint Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 05/28] tipc: Enhance filtering of out-dated link reset messages Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 06/28] tipc: Update obsolete references to multicast link Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 07/28] tipc: Cosmetic changes to broadcast bearer send routine Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 08/28] tipc: Remove non-executable code to handle broadcast bearer congestion Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 09/28] tipc: Enhance cleanup of broadcast link when contact with node is lost Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 10/28] tipc: Prevent broadcast link stalling when another node fails Paul Gortmaker
2011-09-18  3:32 ` Paul Gortmaker [this message]
2011-09-18  3:32 ` [PATCH net-next 12/28] tipc: Remove deferred queue head caching during broadcast message reception Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 13/28] tipc: Discard incoming broadcast messages that are unexpected Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 14/28] tipc: Remove obsolete congestion handling when sending a broadcast NACK Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 15/28] tipc: Eliminate redundant check when sending messages Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 16/28] tipc: Prevent rounding issues when saving connect timeout option Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 17/28] tipc: Ensure congested links receive bearer status updates Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 18/28] tipc: Ensure both nodes recognize loss of contact between them Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 19/28] tipc: Fix unsafe device list search when enabling bearer Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 20/28] tipc: Remove redundant " Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 21/28] tipc: Lower limits for number of bearers and media types Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 22/28] tipc: Prevent fragmented messages during initial name table exchange Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 23/28] tipc: relocate/coalesce node cast in tipc_named_node_up Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 24/28] tipc: Enhance sending of bulk name table messages Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 25/28] tipc: Add support for SO_SNDTIMEO socket option Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 26/28] tipc: Simplify prohibition of listen and accept for connectionless sockets Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 27/28] tipc: Remove callback field from subscription structure Paul Gortmaker
2011-09-18  3:32 ` [PATCH net-next 28/28] tipc: Remove unused link event tracking code Paul Gortmaker
2011-09-20 18:41 ` [PATCH net-next 00/28] misc. TIPC updates for what will be 3.2 David Miller

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=1316316744-29514-12-git-send-email-paul.gortmaker@windriver.com \
    --to=paul.gortmaker@windriver.com \
    --cc=allan.stephens@windriver.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=ying.xue@windriver.com \
    /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).