Skip to contentSkip to conversation

net/smc: ib_query_gid() patches

PATCH Superseded Ursula Braun 4 participants 6 messages Oct 10, 2017 2 messages not in the archive

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover net/smc: ib_query_gid() patches

Dave,

triggered by Parav Pandit here are 2 cleanup patches for usage of ib_query_gid() in the smc-code.

Thanks, Ursula

Ursula Braun (2):
net/smc: replace function pointer get_netdev() net/smc: dev_put for netdev after usage of ib_query_gid()

 net/smc/smc_core.c | 11 +++++++----
 net/smc/smc_ib.c   | 26 +++++++++-----------------
 2 files changed, 16 insertions(+), 21 deletions(-)
Signature · 6 lines
2.13.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH 1/2 net/smc: replace function pointer get_netdev()

In reply to a message not in the archive

SMC should not open code the function pointer get_netdev of the IB device. Replacing ib_query_gid(..., NULL) with ib_query_gid(..., gid_attr) allows access to the netdev.

---
 net/smc/smc_ib.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
net/smc/smc_ib.c +9 -17
index 0b5852299158..b428c0f6c782 100644
@@ -369,26 +369,17 @@ void smc_ib_buf_unmap_sg(struct smc_ib_device *smcibdev,
 
 static int smc_ib_fill_gid_and_mac(struct smc_ib_device *smcibdev, u8 ibport)
 {
-	struct net_device *ndev;
+	struct ib_gid_attr gattr;
 	int rc;
 
 	rc = ib_query_gid(smcibdev->ibdev, ibport, 0,
-			  &smcibdev->gid[ibport - 1], NULL);
-	/* the SMC protocol requires specification of the roce MAC address;
-	 * if net_device cannot be determined, it can be derived from gid 0
-	 */
-	ndev = smcibdev->ibdev->get_netdev(smcibdev->ibdev, ibport);
-	if (ndev) {
-		memcpy(&smcibdev->mac, ndev->dev_addr, ETH_ALEN);
-		dev_put(ndev);
-	} else if (!rc) {
-		memcpy(&smcibdev->mac[ibport - 1][0],
-		       &smcibdev->gid[ibport - 1].raw[8], 3);
-		memcpy(&smcibdev->mac[ibport - 1][3],
-		       &smcibdev->gid[ibport - 1].raw[13], 3);
-		smcibdev->mac[ibport - 1][0] &= ~0x02;
-	}
-	return rc;
+			  &smcibdev->gid[ibport - 1], &gattr);
+	if (rc || !gattr.ndev)
+		return -ENODEV;
+
+	memcpy(smcibdev->mac[ibport - 1], gattr.ndev->dev_addr, ETH_ALEN);
+	dev_put(gattr.ndev);
+	return 0;
 }
 
 /* Create an identifier unique for this instance of SMC-R.
@@ -419,6 +410,7 @@ int smc_ib_remember_port_attr(struct smc_ib_device *smcibdev, u8 ibport)
 			   &smcibdev->pattr[ibport - 1]);
 	if (rc)
 		goto out;
+	/* the SMC protocol requires specification of the roce MAC address */
 	rc = smc_ib_fill_gid_and_mac(smcibdev, ibport);
 	if (rc)
 		goto out;
Signature · 6 lines
2.13.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 2/2 net/smc: dev_put for netdev after usage of ib_query_gid()

In reply to Ursula Braun

For ROCEs ib_query_gid() takes a reference count on the net_device. This reference count must be decreased by the caller.

---
 net/smc/smc_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/smc/smc_core.c +7 -4
index 20b66e79c5d6..e93a31ec3cc2 100644
@@ -380,10 +380,13 @@ static int smc_link_determine_gid(struct smc_link_group *lgr)
 		if (ib_query_gid(lnk->smcibdev->ibdev, lnk->ibport, i, &gid,
 				 &gattr))
 			continue;
-		if (gattr.ndev &&
-		    (vlan_dev_vlan_id(gattr.ndev) == lgr->vlan_id)) {
-			lnk->gid = gid;
-			return 0;
+		if (gattr.ndev) {
+			if (vlan_dev_vlan_id(gattr.ndev) == lgr->vlan_id) {
+				lnk->gid = gid;
+				dev_put(gattr.ndev);
+				return 0;
+			}
+			dev_put(gattr.ndev);
 		}
 	}
 	return -ENODEV;
Signature · 1 line
2.13.5
Reviewed-by on v1 1/2
#3 lore raw

RE: [PATCH net 1/2] net/smc: replace function pointer get_netdev()

In reply to Ursula Braun
Quoted 12 lines

-----Original Message-----
From: Ursula Braun [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 9:14 AM
To: [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Parav Pandit <[email protected]>
Subject: [PATCH net 1/2] net/smc: replace function pointer get_netdev()

Quoted 6 lines

SMC should not open code the function pointer get_netdev of the IB device. Replacing ib_query_gid(..., NULL) with ib_query_gid(..., gid_attr) allows access to the netdev.

Looks fine to me. Minor nit below.

Quoted 45 lines
---
 net/smc/smc_ib.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
net/smc/smc_ib.c index renamed from net/smc/smc_ib.c +0 -0

0b5852299158..b428c0f6c782 100644

net/smc/smc_ib.c +8 -17
@@ -369,26 +369,17 @@ void smc_ib_buf_unmap_sg(struct smc_ib_device
 *smcibdev,
 
 static int smc_ib_fill_gid_and_mac(struct smc_ib_device *smcibdev, u8 ibport)
 {
-	struct net_device *ndev;
+	struct ib_gid_attr gattr;
 	int rc;
 
 	rc = ib_query_gid(smcibdev->ibdev, ibport, 0,
-			  &smcibdev->gid[ibport - 1], NULL);
-	/* the SMC protocol requires specification of the roce MAC address;
-	 * if net_device cannot be determined, it can be derived from gid 0
-	 */
-	ndev = smcibdev->ibdev->get_netdev(smcibdev->ibdev, ibport);
-	if (ndev) {
-		memcpy(&smcibdev->mac, ndev->dev_addr, ETH_ALEN);
-		dev_put(ndev);
-	} else if (!rc) {
-		memcpy(&smcibdev->mac[ibport - 1][0],
-		       &smcibdev->gid[ibport - 1].raw[8], 3);
-		memcpy(&smcibdev->mac[ibport - 1][3],
-		       &smcibdev->gid[ibport - 1].raw[13], 3);
-		smcibdev->mac[ibport - 1][0] &= ~0x02;
-	}
-	return rc;
+			  &smcibdev->gid[ibport - 1], &gattr);
+	if (rc || !gattr.ndev)
+		return -ENODEV;
+
+	memcpy(smcibdev->mac[ibport - 1], gattr.ndev->dev_addr, ETH_ALEN);
+	dev_put(gattr.ndev);
+	return 0;
 }
 

/* Create an identifier unique for this instance of SMC-R.

net/smc/smc_ib.c int smc_ib_remember_port_attr(struct smc_ib_device · line 414

Quoted 5 lines
net/smc/smc_ib.c +1 -0
@@ -419,6 +410,7 @@ int smc_ib_remember_port_attr(struct smc_ib_device
 *smcibdev, u8 ibport)
 			   &smcibdev->pattr[ibport - 1]);
 	if (rc)
 		goto out;
+	/* the SMC protocol requires specification of the roce MAC address */

RoCE MAC address

Quoted 5 lines
net/smc/smc_ib.c +0 -0
 	rc = smc_ib_fill_gid_and_mac(smcibdev, ibport);
 	if (rc)

goto out;
--
2.13.5

#5 lore raw

RE: [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid()

In reply to Ursula Braun
Quoted 13 lines

-----Original Message-----
From: Ursula Braun [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 9:14 AM
To: [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Parav Pandit <[email protected]>
Subject: [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid()

Quoted 4 lines

For ROCEs ib_query_gid() takes a reference count on the net_device. This reference count must be decreased by the caller.

Quoted 9 lines
---
 net/smc/smc_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/smc/smc_core.c index renamed from net/smc/smc_core.c +0 -0

20b66e79c5d6..e93a31ec3cc2 100644

net/smc/smc_core.c static int smc_link_determine_gid(struct · line 385

Quoted 10 lines
net/smc/smc_core.c +2 -4
@@ -380,10 +380,13 @@ static int smc_link_determine_gid(struct
 smc_link_group *lgr)
 		if (ib_query_gid(lnk->smcibdev->ibdev, lnk->ibport, i, &gid,
 				 &gattr))
 			continue;
-		if (gattr.ndev &&
-		    (vlan_dev_vlan_id(gattr.ndev) == lgr->vlan_id)) {
-			lnk->gid = gid;
-			return 0;
+		if (gattr.ndev) {
+			if (vlan_dev_vlan_id(gattr.ndev) == lgr->vlan_id) {

This needs to be changed to

If (gattr.ndev) {
	if (is_vlan_dev(gattr.ndev)) && 
	    vlan_dev_vlan_id(gattr.ndev) == lgr->vlan_id) {
	...
}

Without this check, on vlan disabled kernel at compile time, kernel will crash on vlan_dev_vlan_id(). Please fix this part, rest code looks fine.

#7 lore raw

RE: [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid()

In reply to a message not in the archive
Quoted 8 lines

-----Original Message-----

Quoted 4 lines

For ROCEs ib_query_gid() takes a reference count on the net_device. This reference count must be decreased by the caller.

Also add 'Fixes' line that introduced this bug.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html