Skip to content

Commit 4c26280

Browse files
haiyangzPaolo Abeni
authored andcommitted
hv_netvsc: Fix VF namespace also in synthetic NIC NETDEV_REGISTER event
The existing code moves VF to the same namespace as the synthetic NIC during netvsc_register_vf(). But, if the synthetic device is moved to a new namespace after the VF registration, the VF won't be moved together. To make the behavior more consistent, add a namespace check for synthetic NIC's NETDEV_REGISTER event (generated during its move), and move the VF if it is not in the same namespace. Cc: [email protected] Fixes: c0a41b8 ("hv_netvsc: move VF to same namespace as netvsc device") Suggested-by: Stephen Hemminger <[email protected]> Signed-off-by: Haiyang Zhang <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent ee76eb2 commit 4c26280

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/net/hyperv/netvsc_drv.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,31 @@ static struct hv_driver netvsc_drv = {
27982798
},
27992799
};
28002800

2801+
/* Set VF's namespace same as the synthetic NIC */
2802+
static void netvsc_event_set_vf_ns(struct net_device *ndev)
2803+
{
2804+
struct net_device_context *ndev_ctx = netdev_priv(ndev);
2805+
struct net_device *vf_netdev;
2806+
int ret;
2807+
2808+
vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
2809+
if (!vf_netdev)
2810+
return;
2811+
2812+
if (!net_eq(dev_net(ndev), dev_net(vf_netdev))) {
2813+
ret = dev_change_net_namespace(vf_netdev, dev_net(ndev),
2814+
"eth%d");
2815+
if (ret)
2816+
netdev_err(vf_netdev,
2817+
"Cannot move to same namespace as %s: %d\n",
2818+
ndev->name, ret);
2819+
else
2820+
netdev_info(vf_netdev,
2821+
"Moved VF to namespace with: %s\n",
2822+
ndev->name);
2823+
}
2824+
}
2825+
28012826
/*
28022827
* On Hyper-V, every VF interface is matched with a corresponding
28032828
* synthetic interface. The synthetic interface is presented first
@@ -2810,6 +2835,11 @@ static int netvsc_netdev_event(struct notifier_block *this,
28102835
struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
28112836
int ret = 0;
28122837

2838+
if (event_dev->netdev_ops == &device_ops && event == NETDEV_REGISTER) {
2839+
netvsc_event_set_vf_ns(event_dev);
2840+
return NOTIFY_DONE;
2841+
}
2842+
28132843
ret = check_dev_is_matching_vf(event_dev);
28142844
if (ret != 0)
28152845
return NOTIFY_DONE;

0 commit comments

Comments
 (0)