Skip to contentSkip to conversation

RDMA/cma: Rollback source IP address if failing to acquire device

PATCH Superseded Myungho Jung 2 participants 3 messages Jan 4, 2019 – Jan 10, 2019 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/cma: Rollback source IP address if failing to acquire device

If cma_acquire_dev_by_src_ip() returns error in addr_handler(), the device state changes back to RDMA_CM_ADDR_BOUND but the resolved source IP address is still left. After that, if rdma_destroy_id() is called after rdma_listen(), the device is freed without removed from listen_any_list in cma_cancel_operation(). Revert to the previous IP address if acquiring device fails.

---
 drivers/infiniband/core/cma.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/infiniband/core/cma.c +7 -1
index 63a7cc00bae0..d27c3b154e71 100644
@@ -2963,13 +2963,17 @@ static void addr_handler(int status, struct sockaddr *src_addr,
 {
 	struct rdma_id_private *id_priv = context;
 	struct rdma_cm_event event = {};
+	struct sockaddr *addr;
+	struct sockaddr_storage old_addr;
 
 	mutex_lock(&id_priv->handler_mutex);
 	if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY,
 			   RDMA_CM_ADDR_RESOLVED))
 		goto out;
 
-	memcpy(cma_src_addr(id_priv), src_addr, rdma_addr_size(src_addr));
+	addr = cma_src_addr(id_priv);
+	memcpy(&old_addr, addr, rdma_addr_size(addr));
+	memcpy(addr, src_addr, rdma_addr_size(src_addr));
 	if (!status && !id_priv->cma_dev) {
 		status = cma_acquire_dev_by_src_ip(id_priv);
 		if (status)
@@ -2980,6 +2984,8 @@ static void addr_handler(int status, struct sockaddr *src_addr,
 	}
 
 	if (status) {
+		memcpy(addr, &old_addr,
+		       rdma_addr_size((struct sockaddr *)&old_addr));
 		if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
 				   RDMA_CM_ADDR_BOUND))
 			goto out;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines

-----Original Message-----
From: [email protected] <linux-rdma- [email protected]> On Behalf Of Myungho Jung
Sent: Friday, January 4, 2019 12:46 AM
To: Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH] RDMA/cma: Rollback source IP address if failing to acquire device

If cma_acquire_dev_by_src_ip() returns error in addr_handler(), the device state changes back to RDMA_CM_ADDR_BOUND but the resolved source IP address is still left. After that, if rdma_destroy_id() is called after rdma_listen(), the device is freed without removed from listen_any_list in cma_cancel_operation(). Revert to the previous IP address if acquiring device fails.

---
 drivers/infiniband/core/cma.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/infiniband/core/cma.c +2 -0
index 63a7cc00bae0..d27c3b154e71 100644
@@ -2963,13 +2963,17 @@ static void addr_handler(int status, struct
 sockaddr *src_addr,  {
 	struct rdma_id_private *id_priv = context;
 	struct rdma_cm_event event = {};
+	struct sockaddr *addr;
+	struct sockaddr_storage old_addr;

drivers/infiniband/core/cma.c static void addr_handler(int status, struct · line 2976

Quoted 10 lines
drivers/infiniband/core/cma.c +2 -1
 
 	mutex_lock(&id_priv->handler_mutex);
 	if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY,
 			   RDMA_CM_ADDR_RESOLVED))
 		goto out;
 
-	memcpy(cma_src_addr(id_priv), src_addr,
 rdma_addr_size(src_addr));
+	addr = cma_src_addr(id_priv);
+	memcpy(&old_addr, addr, rdma_addr_size(addr));

Please add a comment here in the patch, why we need to store the old src address and restore back. /*
* Store the previous src address, so that if we fail to acquire matching rdma device,
* old address can be restored back, which helps to cancel the cma listen operation
* correctly.
*/

Quoted 13 lines
drivers/infiniband/core/cma.c +1 -0
+	memcpy(addr, src_addr, rdma_addr_size(src_addr));
 	if (!status && !id_priv->cma_dev) {
 		status = cma_acquire_dev_by_src_ip(id_priv);
drivers/infiniband/core/cma.c +2 -0
 		if (status)
@@ -2980,6 +2984,8 @@ static void addr_handler(int status, struct sockaddr
 *src_addr,
 	}
 
 	if (status) {
+		memcpy(addr, &old_addr,
+		       rdma_addr_size((struct sockaddr *)&old_addr));
 		if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
 				   RDMA_CM_ADDR_BOUND))
Quoted 3 lines

goto out;
--
2.17.1

#2 lore raw
Quoted 58 lines · Parav Pandit
Quoted 34 lines

-----Original Message-----
From: [email protected] <linux-rdma- [email protected]> On Behalf Of Myungho Jung
Sent: Friday, January 4, 2019 12:46 AM
To: Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH] RDMA/cma: Rollback source IP address if failing to acquire device

If cma_acquire_dev_by_src_ip() returns error in addr_handler(), the device state changes back to RDMA_CM_ADDR_BOUND but the resolved source IP address is still left. After that, if rdma_destroy_id() is called after rdma_listen(), the device is freed without removed from listen_any_list in cma_cancel_operation(). Revert to the previous IP address if acquiring device fails.

---
 drivers/infiniband/core/cma.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/infiniband/core/cma.c +2 -0
index 63a7cc00bae0..d27c3b154e71 100644
@@ -2963,13 +2963,17 @@ static void addr_handler(int status, struct
 sockaddr *src_addr,  {
 	struct rdma_id_private *id_priv = context;
 	struct rdma_cm_event event = {};
+	struct sockaddr *addr;
+	struct sockaddr_storage old_addr;

drivers/infiniband/core/cma.c static void addr_handler(int status, struct · line 2976

Quoted 10 lines
drivers/infiniband/core/cma.c +2 -1
 
 	mutex_lock(&id_priv->handler_mutex);
 	if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY,
 			   RDMA_CM_ADDR_RESOLVED))
 		goto out;
 
-	memcpy(cma_src_addr(id_priv), src_addr,
 rdma_addr_size(src_addr));
+	addr = cma_src_addr(id_priv);
+	memcpy(&old_addr, addr, rdma_addr_size(addr));

Please add a comment here in the patch, why we need to store the old src address and restore back. /*
* Store the previous src address, so that if we fail to acquire matching rdma device,
* old address can be restored back, which helps to cancel the cma listen operation
* correctly.
*/

Quoted 8 lines
drivers/infiniband/core/cma.c +1 -0
+	memcpy(addr, src_addr, rdma_addr_size(src_addr));
 	if (!status && !id_priv->cma_dev) {
 		status = cma_acquire_dev_by_src_ip(id_priv);
drivers/infiniband/core/cma.c +0 -0
 		if (status)
@@ -2980,6 +2984,8 @@ static void addr_handler(int status, struct sockaddr
 *src_addr,
 	}
 
Quoted 10 lines
Quoted 8 lines
drivers/infiniband/core/cma.c +2 -0
 	if (status) {
+		memcpy(addr, &old_addr,
+		       rdma_addr_size((struct sockaddr *)&old_addr));
 		if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
 				   RDMA_CM_ADDR_BOUND))

goto out;
--
2.17.1

Hi Parav,

Thanks for review. Let me update and resubmit patch.

Thanks,
Myungho