diff mbox series

[rdma-next,v3,1/1] RDMA/mana_ib: Set correct device into ib

Message ID 1720705077-322-1-git-send-email-kotaranov@linux.microsoft.com (mailing list archive)
State Accepted
Headers show
Series [rdma-next,v3,1/1] RDMA/mana_ib: Set correct device into ib | expand

Commit Message

Konstantin Taranov July 11, 2024, 1:37 p.m. UTC
From: Konstantin Taranov <kotaranov@microsoft.com>

Add mana_get_primary_netdev_rcu helper to get a primary
netdevice for a given port. When mana is used with
netvsc, the VF netdev is controlled by an upper netvsc
device. In a baremetal case, the VF netdev is the
primary device.

Use the mana_get_primary_netdev_rcu() helper in the mana_ib
to get the correct device for querying network states.

Fixes: 8b184e4f1c32 ("RDMA/mana_ib: Enable RoCE on port 1")
Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
---
I would appreciate if I could get Acks on it from:
* netvsc maintainers (e.g., Haiyang)
* net maintainers (e.g., Jakub, David, Eric, Paolo)

v1->v2:
Leon Romanovsky asked to make a helper in the net/mana and get
acks from net maintainers.
v2->v3:
Added warn on rcu lock not held. 
Use the word "primary" instead of "master"
Merged two commits into one and submitted to rdma-next

 drivers/infiniband/hw/mana/device.c           | 16 ++++++++--------
 drivers/net/ethernet/microsoft/mana/mana_en.c | 19 +++++++++++++++++++
 include/net/mana/mana.h                       |  2 ++
 3 files changed, 29 insertions(+), 8 deletions(-)

Comments

Long Li July 12, 2024, 11:18 p.m. UTC | #1
> Subject: [PATCH rdma-next v3 1/1] RDMA/mana_ib: Set correct device into ib
> 
> From: Konstantin Taranov <kotaranov@microsoft.com>
> 
> Add mana_get_primary_netdev_rcu helper to get a primary netdevice for a given
> port. When mana is used with netvsc, the VF netdev is controlled by an upper
> netvsc device. In a baremetal case, the VF netdev is the primary device.
> 
> Use the mana_get_primary_netdev_rcu() helper in the mana_ib to get the
> correct device for querying network states.
> 
> Fixes: 8b184e4f1c32 ("RDMA/mana_ib: Enable RoCE on port 1")
> Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>

Reviewed-by: Long Li <longli@microsoft.com>

> ---
> I would appreciate if I could get Acks on it from:
> * netvsc maintainers (e.g., Haiyang)
> * net maintainers (e.g., Jakub, David, Eric, Paolo)
> 
> v1->v2:
> Leon Romanovsky asked to make a helper in the net/mana and get acks from net
> maintainers.
> v2->v3:
> Added warn on rcu lock not held.
> Use the word "primary" instead of "master"
> Merged two commits into one and submitted to rdma-next
> 
>  drivers/infiniband/hw/mana/device.c           | 16 ++++++++--------
>  drivers/net/ethernet/microsoft/mana/mana_en.c | 19 +++++++++++++++++++
>  include/net/mana/mana.h                       |  2 ++
>  3 files changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mana/device.c
> b/drivers/infiniband/hw/mana/device.c
> index b07a8e2e838f..7ac01918ef7c 100644
> --- a/drivers/infiniband/hw/mana/device.c
> +++ b/drivers/infiniband/hw/mana/device.c
> @@ -56,7 +56,7 @@ static int mana_ib_probe(struct auxiliary_device *adev,  {
>  	struct mana_adev *madev = container_of(adev, struct mana_adev,
> adev);
>  	struct gdma_dev *mdev = madev->mdev;
> -	struct net_device *upper_ndev;
> +	struct net_device *ndev;
>  	struct mana_context *mc;
>  	struct mana_ib_dev *dev;
>  	u8 mac_addr[ETH_ALEN];
> @@ -84,17 +84,17 @@ static int mana_ib_probe(struct auxiliary_device *adev,
>  	dev->ib_dev.num_comp_vectors = mdev->gdma_context-
> >max_num_queues;
>  	dev->ib_dev.dev.parent = mdev->gdma_context->dev;
> 
> -	rcu_read_lock(); /* required to get upper dev */
> -	upper_ndev = netdev_master_upper_dev_get_rcu(mc->ports[0]);
> -	if (!upper_ndev) {
> +	rcu_read_lock(); /* required to get primary netdev */
> +	ndev = mana_get_primary_netdev_rcu(mc, 0);
> +	if (!ndev) {
>  		rcu_read_unlock();
>  		ret = -ENODEV;
> -		ibdev_err(&dev->ib_dev, "Failed to get master netdev");
> +		ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
>  		goto free_ib_device;
>  	}
> -	ether_addr_copy(mac_addr, upper_ndev->dev_addr);
> -	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, upper_ndev-
> >dev_addr);
> -	ret = ib_device_set_netdev(&dev->ib_dev, upper_ndev, 1);
> +	ether_addr_copy(mac_addr, ndev->dev_addr);
> +	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
> +	ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
>  	rcu_read_unlock();
>  	if (ret) {
>  		ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c
> b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index b89ad4afd66e..68c2bea2c022 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
> @@ -3007,3 +3007,22 @@ void mana_remove(struct gdma_dev *gd, bool
> suspending)
>  	gd->gdma_context = NULL;
>  	kfree(ac);
>  }
> +
> +struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac,
> +u32 port_index) {
> +	struct net_device *ndev;
> +
> +	RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
> +			 "Taking primary netdev without holding the RCU read
> lock");
> +	if (port_index >= ac->num_ports)
> +		return NULL;
> +
> +	/* When mana is used in netvsc, the upper netdevice should be returned.
> */
> +	if (ac->ports[port_index]->flags & IFF_SLAVE)
> +		ndev = netdev_master_upper_dev_get_rcu(ac-
> >ports[port_index]);
> +	else
> +		ndev = ac->ports[port_index];
> +
> +	return ndev;
> +}
> +EXPORT_SYMBOL_NS(mana_get_primary_netdev_rcu, NET_MANA);
> diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index
> 59823901b74f..f9b4b0dcb69f 100644
> --- a/include/net/mana/mana.h
> +++ b/include/net/mana/mana.h
> @@ -797,4 +797,6 @@ void mana_destroy_wq_obj(struct mana_port_context
> *apc, u32 wq_type,  int mana_cfg_vport(struct mana_port_context *apc, u32
> protection_dom_id,
>  		   u32 doorbell_pg_id);
>  void mana_uncfg_vport(struct mana_port_context *apc);
> +
> +struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac,
> +u32 port_index);
>  #endif /* _MANA_H */
> --
> 2.43.0
Zhu Yanjun July 13, 2024, 4:41 a.m. UTC | #2
在 2024/7/11 15:37, Konstantin Taranov 写道:
> From: Konstantin Taranov <kotaranov@microsoft.com>
> 
> Add mana_get_primary_netdev_rcu helper to get a primary
> netdevice for a given port. When mana is used with
> netvsc, the VF netdev is controlled by an upper netvsc
> device. In a baremetal case, the VF netdev is the
> primary device.
> 
> Use the mana_get_primary_netdev_rcu() helper in the mana_ib
> to get the correct device for querying network states.
> 
> Fixes: 8b184e4f1c32 ("RDMA/mana_ib: Enable RoCE on port 1")
> Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
> ---
> I would appreciate if I could get Acks on it from:
> * netvsc maintainers (e.g., Haiyang)
> * net maintainers (e.g., Jakub, David, Eric, Paolo)
> 
> v1->v2:
> Leon Romanovsky asked to make a helper in the net/mana and get
> acks from net maintainers.
> v2->v3:
> Added warn on rcu lock not held.
> Use the word "primary" instead of "master"
> Merged two commits into one and submitted to rdma-next
> 
>   drivers/infiniband/hw/mana/device.c           | 16 ++++++++--------
>   drivers/net/ethernet/microsoft/mana/mana_en.c | 19 +++++++++++++++++++
>   include/net/mana/mana.h                       |  2 ++
>   3 files changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c
> index b07a8e2e838f..7ac01918ef7c 100644
> --- a/drivers/infiniband/hw/mana/device.c
> +++ b/drivers/infiniband/hw/mana/device.c
> @@ -56,7 +56,7 @@ static int mana_ib_probe(struct auxiliary_device *adev,
>   {
>   	struct mana_adev *madev = container_of(adev, struct mana_adev, adev);
>   	struct gdma_dev *mdev = madev->mdev;
> -	struct net_device *upper_ndev;
> +	struct net_device *ndev;
>   	struct mana_context *mc;
>   	struct mana_ib_dev *dev;
>   	u8 mac_addr[ETH_ALEN];
> @@ -84,17 +84,17 @@ static int mana_ib_probe(struct auxiliary_device *adev,
>   	dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues;
>   	dev->ib_dev.dev.parent = mdev->gdma_context->dev;
>   
> -	rcu_read_lock(); /* required to get upper dev */
> -	upper_ndev = netdev_master_upper_dev_get_rcu(mc->ports[0]);
> -	if (!upper_ndev) {
> +	rcu_read_lock(); /* required to get primary netdev */
> +	ndev = mana_get_primary_netdev_rcu(mc, 0);
> +	if (!ndev) {
>   		rcu_read_unlock();
>   		ret = -ENODEV;
> -		ibdev_err(&dev->ib_dev, "Failed to get master netdev");
> +		ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
>   		goto free_ib_device;
>   	}
> -	ether_addr_copy(mac_addr, upper_ndev->dev_addr);
> -	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, upper_ndev->dev_addr);
> -	ret = ib_device_set_netdev(&dev->ib_dev, upper_ndev, 1);
> +	ether_addr_copy(mac_addr, ndev->dev_addr);
> +	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
> +	ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
>   	rcu_read_unlock();
>   	if (ret) {
>   		ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index b89ad4afd66e..68c2bea2c022 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
> @@ -3007,3 +3007,22 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
>   	gd->gdma_context = NULL;
>   	kfree(ac);
>   }
> +
> +struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index)
> +{
> +	struct net_device *ndev;
> +
> +	RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
> +			 "Taking primary netdev without holding the RCU read lock");

Thanks a lot.
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>

Zhu Yanjun

> +	if (port_index >= ac->num_ports)
> +		return NULL;
> +
> +	/* When mana is used in netvsc, the upper netdevice should be returned. */
> +	if (ac->ports[port_index]->flags & IFF_SLAVE)
> +		ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
> +	else
> +		ndev = ac->ports[port_index];
> +
> +	return ndev;
> +}
> +EXPORT_SYMBOL_NS(mana_get_primary_netdev_rcu, NET_MANA);
> diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
> index 59823901b74f..f9b4b0dcb69f 100644
> --- a/include/net/mana/mana.h
> +++ b/include/net/mana/mana.h
> @@ -797,4 +797,6 @@ void mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type,
>   int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id,
>   		   u32 doorbell_pg_id);
>   void mana_uncfg_vport(struct mana_port_context *apc);
> +
> +struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index);
>   #endif /* _MANA_H */
Leon Romanovsky July 14, 2024, 7:50 a.m. UTC | #3
On Thu, 11 Jul 2024 06:37:57 -0700, Konstantin Taranov wrote:
> Add mana_get_primary_netdev_rcu helper to get a primary
> netdevice for a given port. When mana is used with
> netvsc, the VF netdev is controlled by an upper netvsc
> device. In a baremetal case, the VF netdev is the
> primary device.
> 
> Use the mana_get_primary_netdev_rcu() helper in the mana_ib
> to get the correct device for querying network states.
> 
> [...]

Applied, thanks!

[1/1] RDMA/mana_ib: Set correct device into ib
      https://git.kernel.org/rdma/rdma/c/1df03a4b44146c

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c
index b07a8e2e838f..7ac01918ef7c 100644
--- a/drivers/infiniband/hw/mana/device.c
+++ b/drivers/infiniband/hw/mana/device.c
@@ -56,7 +56,7 @@  static int mana_ib_probe(struct auxiliary_device *adev,
 {
 	struct mana_adev *madev = container_of(adev, struct mana_adev, adev);
 	struct gdma_dev *mdev = madev->mdev;
-	struct net_device *upper_ndev;
+	struct net_device *ndev;
 	struct mana_context *mc;
 	struct mana_ib_dev *dev;
 	u8 mac_addr[ETH_ALEN];
@@ -84,17 +84,17 @@  static int mana_ib_probe(struct auxiliary_device *adev,
 	dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues;
 	dev->ib_dev.dev.parent = mdev->gdma_context->dev;
 
-	rcu_read_lock(); /* required to get upper dev */
-	upper_ndev = netdev_master_upper_dev_get_rcu(mc->ports[0]);
-	if (!upper_ndev) {
+	rcu_read_lock(); /* required to get primary netdev */
+	ndev = mana_get_primary_netdev_rcu(mc, 0);
+	if (!ndev) {
 		rcu_read_unlock();
 		ret = -ENODEV;
-		ibdev_err(&dev->ib_dev, "Failed to get master netdev");
+		ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
 		goto free_ib_device;
 	}
-	ether_addr_copy(mac_addr, upper_ndev->dev_addr);
-	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, upper_ndev->dev_addr);
-	ret = ib_device_set_netdev(&dev->ib_dev, upper_ndev, 1);
+	ether_addr_copy(mac_addr, ndev->dev_addr);
+	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
+	ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
 	rcu_read_unlock();
 	if (ret) {
 		ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index b89ad4afd66e..68c2bea2c022 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -3007,3 +3007,22 @@  void mana_remove(struct gdma_dev *gd, bool suspending)
 	gd->gdma_context = NULL;
 	kfree(ac);
 }
+
+struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index)
+{
+	struct net_device *ndev;
+
+	RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
+			 "Taking primary netdev without holding the RCU read lock");
+	if (port_index >= ac->num_ports)
+		return NULL;
+
+	/* When mana is used in netvsc, the upper netdevice should be returned. */
+	if (ac->ports[port_index]->flags & IFF_SLAVE)
+		ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
+	else
+		ndev = ac->ports[port_index];
+
+	return ndev;
+}
+EXPORT_SYMBOL_NS(mana_get_primary_netdev_rcu, NET_MANA);
diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
index 59823901b74f..f9b4b0dcb69f 100644
--- a/include/net/mana/mana.h
+++ b/include/net/mana/mana.h
@@ -797,4 +797,6 @@  void mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type,
 int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id,
 		   u32 doorbell_pg_id);
 void mana_uncfg_vport(struct mana_port_context *apc);
+
+struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index);
 #endif /* _MANA_H */