netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] net/smc: ib_query_gid() patches
@ 2017-10-10 14:13 Ursula Braun
       [not found] ` <20171010141351.87700-1-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
  2017-10-10 14:13 ` [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid() Ursula Braun
  0 siblings, 2 replies; 6+ messages in thread
From: Ursula Braun @ 2017-10-10 14:13 UTC (permalink / raw)
  To: davem-fT/PcQaiUtIeIZ0/mPfg9Q
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	linux-s390-u79uwXL29TY76Z2rM5mHXA,
	jwi-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	schwidefsky-tA70FqPdS9bQT0dZR+AlfA,
	heiko.carstens-tA70FqPdS9bQT0dZR+AlfA,
	raspl-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	parav-VPRAkNaXOzVWk0Htik3J/w

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(-)

-- 
2.13.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 1/2] net/smc: replace function pointer get_netdev()
       [not found] ` <20171010141351.87700-1-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
@ 2017-10-10 14:13   ` Ursula Braun
  2017-10-10 17:01     ` Parav Pandit
  0 siblings, 1 reply; 6+ messages in thread
From: Ursula Braun @ 2017-10-10 14:13 UTC (permalink / raw)
  To: davem-fT/PcQaiUtIeIZ0/mPfg9Q
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	linux-s390-u79uwXL29TY76Z2rM5mHXA,
	jwi-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	schwidefsky-tA70FqPdS9bQT0dZR+AlfA,
	heiko.carstens-tA70FqPdS9bQT0dZR+AlfA,
	raspl-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	parav-VPRAkNaXOzVWk0Htik3J/w

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.

Signed-off-by: Ursula Braun <ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Suggested-by: Parav Pandit <parav-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 net/smc/smc_ib.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c
index 0b5852299158..b428c0f6c782 100644
--- a/net/smc/smc_ib.c
+++ b/net/smc/smc_ib.c
@@ -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;
-- 
2.13.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid()
  2017-10-10 14:13 [PATCH net 0/2] net/smc: ib_query_gid() patches Ursula Braun
       [not found] ` <20171010141351.87700-1-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
@ 2017-10-10 14:13 ` Ursula Braun
  2017-10-10 17:09   ` Parav Pandit
  1 sibling, 1 reply; 6+ messages in thread
From: Ursula Braun @ 2017-10-10 14:13 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-rdma, linux-s390, jwi, schwidefsky, heiko.carstens,
	raspl, ubraun, parav

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

Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
---
 net/smc/smc_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 20b66e79c5d6..e93a31ec3cc2 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -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;
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH net 1/2] net/smc: replace function pointer get_netdev()
  2017-10-10 14:13   ` [PATCH net 1/2] net/smc: replace function pointer get_netdev() Ursula Braun
@ 2017-10-10 17:01     ` Parav Pandit
  0 siblings, 0 replies; 6+ messages in thread
From: Parav Pandit @ 2017-10-10 17:01 UTC (permalink / raw)
  To: Ursula Braun, davem@davemloft.net
  Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-s390@vger.kernel.org, jwi@linux.vnet.ibm.com,
	schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com,
	raspl@linux.vnet.ibm.com



> -----Original Message-----
> From: Ursula Braun [mailto:ubraun@linux.vnet.ibm.com]
> Sent: Tuesday, October 10, 2017 9:14 AM
> To: davem@davemloft.net
> Cc: netdev@vger.kernel.org; linux-rdma@vger.kernel.org; linux-
> s390@vger.kernel.org; jwi@linux.vnet.ibm.com; schwidefsky@de.ibm.com;
> heiko.carstens@de.ibm.com; raspl@linux.vnet.ibm.com;
> ubraun@linux.vnet.ibm.com; Parav Pandit <parav@mellanox.com>
> Subject: [PATCH net 1/2] net/smc: replace function pointer get_netdev()
> 
> 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.
> 
> Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
> Suggested-by: Parav Pandit <parav@mellanox.com>
Looks fine to me. Minor nit below.
Reviewed-by: Parav Pandit <parav@mellanox.com>

> ---
>  net/smc/smc_ib.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c index
> 0b5852299158..b428c0f6c782 100644
> --- a/net/smc/smc_ib.c
> +++ b/net/smc/smc_ib.c
> @@ -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 */
RoCE MAC address

>  	rc = smc_ib_fill_gid_and_mac(smcibdev, ibport);
>  	if (rc)
>  		goto out;
> --
> 2.13.5

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid()
  2017-10-10 14:13 ` [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid() Ursula Braun
@ 2017-10-10 17:09   ` Parav Pandit
       [not found]     ` <VI1PR0502MB30088E4F58036AB3A06822E8D1750-o1MPJYiShExKsLr+rGaxW8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Parav Pandit @ 2017-10-10 17:09 UTC (permalink / raw)
  To: Ursula Braun, davem@davemloft.net
  Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-s390@vger.kernel.org, jwi@linux.vnet.ibm.com,
	schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com,
	raspl@linux.vnet.ibm.com



> -----Original Message-----
> From: Ursula Braun [mailto:ubraun@linux.vnet.ibm.com]
> Sent: Tuesday, October 10, 2017 9:14 AM
> To: davem@davemloft.net
> Cc: netdev@vger.kernel.org; linux-rdma@vger.kernel.org; linux-
> s390@vger.kernel.org; jwi@linux.vnet.ibm.com; schwidefsky@de.ibm.com;
> heiko.carstens@de.ibm.com; raspl@linux.vnet.ibm.com;
> ubraun@linux.vnet.ibm.com; Parav Pandit <parav@mellanox.com>
> Subject: [PATCH net 2/2] net/smc: dev_put for netdev after usage of
> ib_query_gid()
> 
> For ROCEs ib_query_gid() takes a reference count on the net_device.
> This reference count must be decreased by the caller.
> 
> Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
Reported-by: Parav Pandit <parav@mellanox.com>

> ---
>  net/smc/smc_core.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index
> 20b66e79c5d6..e93a31ec3cc2 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid()
       [not found]     ` <VI1PR0502MB30088E4F58036AB3A06822E8D1750-o1MPJYiShExKsLr+rGaxW8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
@ 2017-10-10 19:04       ` Parav Pandit
  0 siblings, 0 replies; 6+ messages in thread
From: Parav Pandit @ 2017-10-10 19:04 UTC (permalink / raw)
  To: Parav Pandit, Ursula Braun,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-s390-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	jwi-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
	schwidefsky-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org,
	heiko.carstens-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org,
	raspl-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org


> -----Original Message-----
> > For ROCEs ib_query_gid() takes a reference count on the net_device.
> > This reference count must be decreased by the caller.
> >
> > Signed-off-by: Ursula Braun <ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> Reported-by: Parav Pandit <parav-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> 
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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-10 19:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-10 14:13 [PATCH net 0/2] net/smc: ib_query_gid() patches Ursula Braun
     [not found] ` <20171010141351.87700-1-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-10-10 14:13   ` [PATCH net 1/2] net/smc: replace function pointer get_netdev() Ursula Braun
2017-10-10 17:01     ` Parav Pandit
2017-10-10 14:13 ` [PATCH net 2/2] net/smc: dev_put for netdev after usage of ib_query_gid() Ursula Braun
2017-10-10 17:09   ` Parav Pandit
     [not found]     ` <VI1PR0502MB30088E4F58036AB3A06822E8D1750-o1MPJYiShExKsLr+rGaxW8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2017-10-10 19:04       ` Parav Pandit

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).