Skip to content

Commit 04d748d

Browse files
haiyangzgregkh
authored andcommitted
hv_netvsc: Fix VF namespace also in synthetic NIC NETDEV_REGISTER event
commit 4c26280 upstream. 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: stable@vger.kernel.org Fixes: c0a41b8 ("hv_netvsc: move VF to same namespace as netvsc device") Suggested-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/1729275922-17595-1-git-send-email-haiyangz@microsoft.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1e8fbd2 commit 04d748d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

drivers/net/hyperv/netvsc_drv.c

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

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

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

0 commit comments

Comments
 (0)