Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1241627

[PATCH v4 03/14] RDS: fix rds_sock reference bug while doing bind

From Santosh Shilimkar <santosh.shilimkar@oracle.com>
Newsgroups linux.kernel
Subject [PATCH v4 03/14] RDS: fix rds_sock reference bug while doing bind
Date 2015-10-07 18:00 +0200
Message-ID <qgZij-T6-35@gated-at.bofh.it> (permalink)
References <qgZii-T6-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/14] RDS: connection scalability and performance improvements Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 10/14] RDS: IB: fix the rds_ib_fmr_wq kick call Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 11/14] RDS: IB: use already available pool handle from ibmr Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 14/14] RDS: IB: split mr pool to improve 8K messages performance Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 13/14] RDS: IB: use max_mr from HCA caps than max_fmr Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 09/14] RDS: IB: handle rds_ibdev release case instead of crashing the kernel Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 07/14] RDS: IB: ack more receive completions to improve performance Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 03/14] RDS: fix rds_sock reference bug while doing bind Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 06/14] RDS: use rds_send_xmit() state instead of RDS_LL_SEND_FULL Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 12/14] RDS: IB: mark rds_ib_fmr_wq static Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 01/14] RDS: use kfree_rcu in rds_ib_remove_ipaddr Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 08/14] RDS: IB: split send completion handling and do batch ack Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 02/14] RDS: make socket bind/release locking scheme simple and more efficient Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 05/14] RDS: defer the over_batch work to send worker Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  [PATCH v4 04/14] RDS: Use per-bucket rw lock for bind hash-table Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-10-07 18:00 +0200
  Re: [PATCH v4 00/14] RDS: connection scalability and performance  improvements David Miller <davem@davemloft.net> - 2015-10-08 13:30 +0200

csiph-web