netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Santosh Shilimkar <santosh.shilimkar@oracle.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, linux-kernel@vger.kernel.org,
	ssantosh@kernel.org,
	Santosh Shilimkar <santosh.shilimkar@oracle.com>
Subject: [PATCH v3 03/14] RDS: fix rds_sock reference bug while doing bind
Date: Mon,  5 Oct 2015 10:56:26 -0700	[thread overview]
Message-ID: <1444067797-14101-4-git-send-email-santosh.shilimkar@oracle.com> (raw)
In-Reply-To: <1444067797-14101-1-git-send-email-santosh.shilimkar@oracle.com>

One need to take rds socket reference while using it and release it
once done with it. rds_add_bind() code path does not do that so
lets fix it.

Signed-off-by: Santosh Shilimkar <ssantosh@kernel.org>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
---
 net/rds/bind.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/net/rds/bind.c b/net/rds/bind.c
index 01989e2..166c605 100644
--- a/net/rds/bind.c
+++ b/net/rds/bind.c
@@ -61,8 +61,10 @@ static struct rds_sock *rds_bind_lookup(__be32 addr, __be16 port,
 		cmp = ((u64)be32_to_cpu(rs->rs_bound_addr) << 32) |
 		      be16_to_cpu(rs->rs_bound_port);
 
-		if (cmp == needle)
+		if (cmp == needle) {
+			rds_sock_addref(rs);
 			return rs;
+		}
 	}
 
 	if (insert) {
@@ -94,10 +96,10 @@ struct rds_sock *rds_find_bound(__be32 addr, __be16 port)
 	rs = rds_bind_lookup(addr, port, NULL);
 	read_unlock_irqrestore(&rds_bind_lock, flags);
 
-	if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD))
-		rds_sock_addref(rs);
-	else
+	if (rs && sock_flag(rds_rs_to_sk(rs), SOCK_DEAD)) {
+		rds_sock_put(rs);
 		rs = NULL;
+	}
 
 	rdsdebug("returning rs %p for %pI4:%u\n", rs, &addr,
 		ntohs(port));
@@ -123,14 +125,18 @@ static int rds_add_bound(struct rds_sock *rs, __be32 addr, __be16 *port)
 	write_lock_irqsave(&rds_bind_lock, flags);
 
 	do {
+		struct rds_sock *rrs;
 		if (rover == 0)
 			rover++;
-		if (!rds_bind_lookup(addr, cpu_to_be16(rover), rs)) {
+		rrs = rds_bind_lookup(addr, cpu_to_be16(rover), rs);
+		if (!rrs) {
 			*port = rs->rs_bound_port;
 			ret = 0;
 			rdsdebug("rs %p binding to %pI4:%d\n",
 			  rs, &addr, (int)ntohs(*port));
 			break;
+		} else {
+			rds_sock_put(rrs);
 		}
 	} while (rover++ != last);
 
-- 
1.9.1

  parent reply	other threads:[~2015-10-05 17:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-05 17:56 [PATCH v3 00/14] RDS: connection scalability and performance improvements Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 01/14] RDS: use kfree_rcu in rds_ib_remove_ipaddr Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 02/14] RDS: make socket bind/release locking scheme simple and more efficient Santosh Shilimkar
2015-10-05 17:56 ` Santosh Shilimkar [this message]
2015-10-05 17:56 ` [PATCH v3 04/14] RDS: Use per-bucket rw lock for bind hash-table Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 05/14] RDS: defer the over_batch work to send worker Santosh Shilimkar
2015-10-05 18:31   ` santosh shilimkar
2015-10-05 17:56 ` [PATCH v3 06/14] RDS: use rds_send_xmit() state instead of RDS_LL_SEND_FULL Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 07/14] RDS: IB: ack more receive completions to improve performance Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 08/14] RDS: IB: split send completion handling and do batch ack Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 09/14] RDS: IB: handle rds_ibdev release case instead of crashing the kernel Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 10/14] RDS: IB: fix the rds_ib_fmr_wq kick call Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 11/14] RDS: IB: use already available pool handle from ibmr Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 12/14] RDS: IB: mark rds_ib_fmr_wq static Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 13/14] RDS: IB: use max_mr from HCA caps than max_fmr Santosh Shilimkar
2015-10-05 17:56 ` [PATCH v3 14/14] RDS: IB: split mr pool to improve 8K messages performance Santosh Shilimkar
2015-10-07  9:16 ` [PATCH v3 00/14] RDS: connection scalability and performance improvements David Miller
2015-10-07 15:58   ` santosh.shilimkar

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=1444067797-14101-4-git-send-email-santosh.shilimkar@oracle.com \
    --to=santosh.shilimkar@oracle.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ssantosh@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).