Skip to contentSkip to conversation

hv_netvsc: set device master/slave flags on bonding

PATCH In review [email protected] 3 participants 4 messages Feb 28, 2025 – Mar 5, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hv_netvsc: set device master/slave flags on bonding

From: Long Li <[email protected]>

Currently netvsc only sets the SLAVE flag on VF netdev when it's bonded. It should also set the MASTER flag on itself and clear all those flags when the VF is unbonded.

---
 drivers/net/hyperv/netvsc_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/hyperv/netvsc_drv.c +6 -0
index d6c4abfc3a28..7ac18fede2f3 100644
@@ -2204,6 +2204,7 @@ static int netvsc_vf_join(struct net_device *vf_netdev,
 		goto rx_handler_failed;
 	}
 
+	ndev->flags |= IFF_MASTER;
 	ret = netdev_master_upper_dev_link(vf_netdev, ndev,
 					   NULL, NULL, NULL);
 	if (ret != 0) {
@@ -2484,7 +2485,12 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)
 
 	reinit_completion(&net_device_ctx->vf_add);
 	netdev_rx_handler_unregister(vf_netdev);
+
+	/* Unlink the slave device and clear flag */
+	vf_netdev->flags &= ~IFF_SLAVE;
+	ndev->flags &= ~IFF_MASTER;
 	netdev_upper_dev_unlink(vf_netdev, ndev);
+
 	RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL);
 	dev_put(vf_netdev);
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Fri, Feb 28, 2025 at 11:25:13PM +0100, [email protected] wrote:

From: Long Li <[email protected]>

Currently netvsc only sets the SLAVE flag on VF netdev when it's bonded. It should also set the MASTER flag on itself and clear all those flags when the VF is unbonded.

I don't understand why you need this. Who looks at these flags?

Quoted 35 lines

---
drivers/net/hyperv/netvsc_drv.c | 6 ++++++

1 file changed, 6 insertions(+)
drivers/net/hyperv/netvsc_drv.c +6 -0
index d6c4abfc3a28..7ac18fede2f3 100644
@@ -2204,6 +2204,7 @@ static int netvsc_vf_join(struct net_device *vf_netdev,
 		goto rx_handler_failed;
 	}
 
+	ndev->flags |= IFF_MASTER;
 	ret = netdev_master_upper_dev_link(vf_netdev, ndev,
 					   NULL, NULL, NULL);
 	if (ret != 0) {
@@ -2484,7 +2485,12 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)
 
 	reinit_completion(&net_device_ctx->vf_add);
 	netdev_rx_handler_unregister(vf_netdev);
+
+	/* Unlink the slave device and clear flag */
+	vf_netdev->flags &= ~IFF_SLAVE;
+	ndev->flags &= ~IFF_MASTER;
 	netdev_upper_dev_unlink(vf_netdev, ndev);
+
 	RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL);
 	dev_put(vf_netdev);
 
Signature · 1 line
2.34.1
#2 lore raw
Quoted 11 lines

Subject: [EXTERNAL] Re: [PATCH] hv_netvsc: set device master/slave flags on bonding

Quoted 5 lines · Fri, Feb 28, 2025 at 11:25:13PM +0100, [email protected] wrote:

From: Long Li <[email protected]>

Currently netvsc only sets the SLAVE flag on VF netdev when it's bonded. It should also set the MASTER flag on itself and clear all those flags when the VF is unbonded.

I don't understand why you need this. Who looks at these flags?

The SLAVE flag is checked here:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/microsoft/mana/mana_en.c?h=v6.14-rc5#n3144
and is also checked in some user-mode programs.

There is no code checking for MASTER currently. It is added for completeness. SLAVE doesn't make sense without a MASTER.

Quoted 40 lines

drivers/net/hyperv/netvsc_drv.c static int netvsc_vf_join(struct net_device

Quoted 14 lines

---
drivers/net/hyperv/netvsc_drv.c | 6 ++++++

1 file changed, 6 insertions(+)
(quoted diff) +0 -0

b/drivers/net/hyperv/netvsc_drv.c index d6c4abfc3a28..7ac18fede2f3 100644

drivers/net/hyperv/netvsc_drv.c +0 -0
@@ -2204,6 +2204,7 @@ static int netvsc_vf_join(struct net_device

*vf_netdev,

Quoted 25 lines
drivers/net/hyperv/netvsc_drv.c +6 -1
 		goto rx_handler_failed;
 	}
 
+	ndev->flags |= IFF_MASTER;
 	ret = netdev_master_upper_dev_link(vf_netdev, ndev,
 					   NULL, NULL, NULL);
 	if (ret != 0) {
@@ -2484,7 +2485,12 @@ static int netvsc_unregister_vf(struct
 net_device *vf_netdev)
 
 	reinit_completion(&net_device_ctx->vf_add);
 	netdev_rx_handler_unregister(vf_netdev);
+
+	/* Unlink the slave device and clear flag */
+	vf_netdev->flags &= ~IFF_SLAVE;
+	ndev->flags &= ~IFF_MASTER;
 	netdev_upper_dev_unlink(vf_netdev, ndev);
+
 	RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL);
 	dev_put(vf_netdev);
 
--

2.34.1

#3 lore raw
Quoted 6 lines · Mon, Mar 03, 2025 at 07:47:37PM +0100, [email protected] wrote:
Quoted 6 lines

Subject: [EXTERNAL] Re: [PATCH] hv_netvsc: set device master/slave flags on bonding

Quoted 2 lines · Fri, Feb 28, 2025 at 11:25:13PM +0100, [email protected] wrote:

From: Long Li <[email protected]>

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Currently netvsc only sets the SLAVE flag on VF netdev when it's bonded. It should also set the MASTER flag on itself and clear all those flags when the VF is unbonded.

I don't understand why you need this. Who looks at these flags?

The SLAVE flag is checked here:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/microsoft/mana/mana_en.c?h=v6.14-rc5#n3144

In kernel. We have other means. The check is incorrect. The code should use netif_is_*_port() herlper. Does not exist, add it.

Quoted 1 line

and is also checked in some user-mode programs.

As currently it is not exposed, it can't be checked. Don't add it.

Quoted 2 lines

There is no code checking for MASTER currently. It is added for completeness. SLAVE doesn't make sense without a MASTER.

Does not make sense. Either you need it or not. If not, don't add it.

NAK. Please let IFF_MASTER and IFF_SLAVE rot.

Quoted 41 lines
Quoted 41 lines

drivers/net/hyperv/netvsc_drv.c static int netvsc_vf_join(struct net_device

Quoted 15 lines

---
drivers/net/hyperv/netvsc_drv.c | 6 ++++++

1 file changed, 6 insertions(+)
(quoted diff) +0 -0

b/drivers/net/hyperv/netvsc_drv.c index d6c4abfc3a28..7ac18fede2f3 100644

drivers/net/hyperv/netvsc_drv.c +0 -0
@@ -2204,6 +2204,7 @@ static int netvsc_vf_join(struct net_device

*vf_netdev,

Quoted 25 lines
drivers/net/hyperv/netvsc_drv.c +6 -1
 		goto rx_handler_failed;
 	}
 
+	ndev->flags |= IFF_MASTER;
 	ret = netdev_master_upper_dev_link(vf_netdev, ndev,
 					   NULL, NULL, NULL);
 	if (ret != 0) {
@@ -2484,7 +2485,12 @@ static int netvsc_unregister_vf(struct
 net_device *vf_netdev)
 
 	reinit_completion(&net_device_ctx->vf_add);
 	netdev_rx_handler_unregister(vf_netdev);
+
+	/* Unlink the slave device and clear flag */
+	vf_netdev->flags &= ~IFF_SLAVE;
+	ndev->flags &= ~IFF_MASTER;
 	netdev_upper_dev_unlink(vf_netdev, ndev);
+
 	RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL);
 	dev_put(vf_netdev);
 
--

2.34.1