Skip to content

Commit

Permalink
Merge branch 'hv_netvsc-prevent-packet-loss-during-vf-add-remove'
Browse files Browse the repository at this point in the history
Long Li says:

====================
hv_netvsc: Prevent packet loss during VF add/remove

This patch set fixes issues with packet loss on VF add/remove.
====================

Link: https://lore.kernel.org/r/1610153623-17500-1-git-send-email-longli@linuxonhyperv.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jan 13, 2021
2 parents 2c82b7f + 34b06a2 commit b866e72
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
37 changes: 34 additions & 3 deletions drivers/net/hyperv/netvsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void netvsc_switch_datapath(struct net_device *ndev, bool vf)
struct netvsc_device *nv_dev = rtnl_dereference(net_device_ctx->nvdev);
struct nvsp_message *init_pkt = &nv_dev->channel_init_pkt;

/* Block sending traffic to VF if it's about to be gone */
if (!vf)
net_device_ctx->data_path_is_vf = vf;

memset(init_pkt, 0, sizeof(struct nvsp_message));
init_pkt->hdr.msg_type = NVSP_MSG4_TYPE_SWITCH_DATA_PATH;
if (vf)
Expand All @@ -50,8 +54,11 @@ void netvsc_switch_datapath(struct net_device *ndev, bool vf)

vmbus_sendpacket(dev->channel, init_pkt,
sizeof(struct nvsp_message),
VMBUS_RQST_ID_NO_RESPONSE,
VM_PKT_DATA_INBAND, 0);
(unsigned long)init_pkt,
VM_PKT_DATA_INBAND,
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
wait_for_completion(&nv_dev->channel_init_wait);
net_device_ctx->data_path_is_vf = vf;
}

/* Worker to setup sub channels on initial setup
Expand Down Expand Up @@ -754,15 +761,39 @@ static void netvsc_send_completion(struct net_device *ndev,
const struct vmpacket_descriptor *desc,
int budget)
{
const struct nvsp_message *nvsp_packet = hv_pkt_data(desc);
const struct nvsp_message *nvsp_packet;
u32 msglen = hv_pkt_datalen(desc);
struct nvsp_message *pkt_rqst;
u64 cmd_rqst;

/* First check if this is a VMBUS completion without data payload */
if (!msglen) {
cmd_rqst = vmbus_request_addr(&incoming_channel->requestor,
(u64)desc->trans_id);
if (cmd_rqst == VMBUS_RQST_ERROR) {
netdev_err(ndev, "Invalid transaction id\n");
return;
}

pkt_rqst = (struct nvsp_message *)(uintptr_t)cmd_rqst;
switch (pkt_rqst->hdr.msg_type) {
case NVSP_MSG4_TYPE_SWITCH_DATA_PATH:
complete(&net_device->channel_init_wait);
break;

default:
netdev_err(ndev, "Unexpected VMBUS completion!!\n");
}
return;
}

/* Ensure packet is big enough to read header fields */
if (msglen < sizeof(struct nvsp_message_header)) {
netdev_err(ndev, "nvsp_message length too small: %u\n", msglen);
return;
}

nvsp_packet = hv_pkt_data(desc);
switch (nvsp_packet->hdr.msg_type) {
case NVSP_MSG_TYPE_INIT_COMPLETE:
if (msglen < sizeof(struct nvsp_message_header) +
Expand Down
14 changes: 9 additions & 5 deletions drivers/net/hyperv/netvsc_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ static int netvsc_xmit(struct sk_buff *skb, struct net_device *net, bool xdp_tx)
*/
vf_netdev = rcu_dereference_bh(net_device_ctx->vf_netdev);
if (vf_netdev && netif_running(vf_netdev) &&
netif_carrier_ok(vf_netdev) && !netpoll_tx_running(net))
netif_carrier_ok(vf_netdev) && !netpoll_tx_running(net) &&
net_device_ctx->data_path_is_vf)
return netvsc_vf_xmit(net, vf_netdev, skb);

/* We will atmost need two pages to describe the rndis
Expand Down Expand Up @@ -2381,12 +2382,15 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
* During hibernation, if a VF NIC driver (e.g. mlx5) preserves the network
* interface, there is only the CHANGE event and no UP or DOWN event.
*/
static int netvsc_vf_changed(struct net_device *vf_netdev)
static int netvsc_vf_changed(struct net_device *vf_netdev, unsigned long event)
{
struct net_device_context *net_device_ctx;
struct netvsc_device *netvsc_dev;
struct net_device *ndev;
bool vf_is_up = netif_running(vf_netdev);
bool vf_is_up = false;

if (event != NETDEV_GOING_DOWN)
vf_is_up = netif_running(vf_netdev);

ndev = get_netvsc_byref(vf_netdev);
if (!ndev)
Expand All @@ -2399,7 +2403,6 @@ static int netvsc_vf_changed(struct net_device *vf_netdev)

if (net_device_ctx->data_path_is_vf == vf_is_up)
return NOTIFY_OK;
net_device_ctx->data_path_is_vf = vf_is_up;

netvsc_switch_datapath(ndev, vf_is_up);
netdev_info(ndev, "Data path switched %s VF: %s\n",
Expand Down Expand Up @@ -2716,7 +2719,8 @@ static int netvsc_netdev_event(struct notifier_block *this,
case NETDEV_UP:
case NETDEV_DOWN:
case NETDEV_CHANGE:
return netvsc_vf_changed(event_dev);
case NETDEV_GOING_DOWN:
return netvsc_vf_changed(event_dev, event);
default:
return NOTIFY_DONE;
}
Expand Down

0 comments on commit b866e72

Please sign in to comment.