Skip to content

Commit 7abd221

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 033bc52 commit 7abd221

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
@@ -2526,6 +2526,31 @@ static struct hv_driver netvsc_drv = {
25262526
},
25272527
};
25282528

2529+
/* Set VF's namespace same as the synthetic NIC */
2530+
static void netvsc_event_set_vf_ns(struct net_device *ndev)
2531+
{
2532+
struct net_device_context *ndev_ctx = netdev_priv(ndev);
2533+
struct net_device *vf_netdev;
2534+
int ret;
2535+
2536+
vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
2537+
if (!vf_netdev)
2538+
return;
2539+
2540+
if (!net_eq(dev_net(ndev), dev_net(vf_netdev))) {
2541+
ret = dev_change_net_namespace(vf_netdev, dev_net(ndev),
2542+
"eth%d");
2543+
if (ret)
2544+
netdev_err(vf_netdev,
2545+
"Cannot move to same namespace as %s: %d\n",
2546+
ndev->name, ret);
2547+
else
2548+
netdev_info(vf_netdev,
2549+
"Moved VF to namespace with: %s\n",
2550+
ndev->name);
2551+
}
2552+
}
2553+
25292554
/*
25302555
* On Hyper-V, every VF interface is matched with a corresponding
25312556
* synthetic interface. The synthetic interface is presented first
@@ -2538,6 +2563,11 @@ static int netvsc_netdev_event(struct notifier_block *this,
25382563
struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
25392564
int ret = 0;
25402565

2566+
if (event_dev->netdev_ops == &device_ops && event == NETDEV_REGISTER) {
2567+
netvsc_event_set_vf_ns(event_dev);
2568+
return NOTIFY_DONE;
2569+
}
2570+
25412571
ret = check_dev_is_matching_vf(event_dev);
25422572
if (ret != 0)
25432573
return NOTIFY_DONE;

0 commit comments

Comments
 (0)