4cebb475eb
... so that we can make sure the rings are not freed until all SKBs in internal queues are consumed. 1. The VM is receiving packets through bonding + bridge + netback + netfront. 2. For some unknown reason at least one packet remains in the rx queue and is not delivered to the domU immediately by netback. 3. The VM finishes shutting down. 4. The shared ring between dom0 and domU is freed. 5. then xen-netback continues processing the pending requests and tries to put the packet into the now already released shared ring. > XXXlan0: port 9(vif26.0) entered disabled state > BUG: unable to handle kernel paging request at ffffc900108641d8 > IP: [<ffffffffa04147dc>] xen_netbk_rx_action+0x18b/0x6f0 [xen_netback] > PGD 57e20067 PUD 57e21067 PMD 571a7067 PTE 0 > Oops: 0000 [#1] SMP > ... > CPU: 0 PID: 12587 Comm: netback/0 Not tainted 3.10.0-ucs58-amd64 #1 Debian 3.10.11-1.58.201405060908 > Hardware name: FUJITSU PRIMERGY BX620 S6/D3051, BIOS 080015 Rev.3C78.3051 07/22/2011 > task: ffff880004b067c0 ti: ffff8800561ec000 task.ti: ffff8800561ec000 > RIP: e030:[<ffffffffa04147dc>] [<ffffffffa04147dc>] xen_netbk_rx_action+0x18b/0x6f0 [xen_netback] > RSP: e02b:ffff8800561edce8 EFLAGS: 00010202 > RAX: ffffc900104adac0 RBX: ffff8800541e95c0 RCX: ffffc90010864000 > RDX: 000000000000003b RSI: 0000000000000000 RDI: ffff880040014380 > RBP: ffff8800570e6800 R08: 0000000000000000 R09: ffff880004799800 > R10: ffffffff813ca115 R11: ffff88005e4fdb08 R12: ffff880054e6f800 > R13: ffff8800561edd58 R14: ffffc900104a1000 R15: 0000000000000000 > FS: 00007f19a54a8700(0000) GS:ffff88005da00000(0000) knlGS:0000000000000000 > CS: e033 DS: 0000 ES: 0000 CR0: 000000008005003b > CR2: ffffc900108641d8 CR3: 0000000054cb3000 CR4: 0000000000002660 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 > Stack: > ffff880004b06ba0 0000000000000000 ffff88005da13ec0 ffff88005da13ec0 > 0000000004b067c0 ffffc900104a8ac0 ffffc900104a1020 000000005da13ec0 > 0000000000000000 0000000000000001 ffffc900104a8ac0 ffffc900104adac0 > Call Trace: > [<ffffffff813ca32d>] ? _raw_spin_lock_irqsave+0x11/0x2f > [<ffffffffa0416033>] ? xen_netbk_kthread+0x174/0x841 [xen_netback] > [<ffffffff8105d373>] ? wake_up_bit+0x20/0x20 > [<ffffffffa0415ebf>] ? xen_netbk_tx_build_gops+0xce8/0xce8 [xen_netback] > [<ffffffff8105cd73>] ? kthread_freezable_should_stop+0x56/0x56 > [<ffffffffa0415ebf>] ? xen_netbk_tx_build_gops+0xce8/0xce8 [xen_netback] > [<ffffffff8105ce1e>] ? kthread+0xab/0xb3 > [<ffffffff81003638>] ? xen_end_context_switch+0xe/0x1c > [<ffffffff8105cd73>] ? kthread_freezable_should_stop+0x56/0x56 > [<ffffffff813cfbfc>] ? ret_from_fork+0x7c/0xb0 > [<ffffffff8105cd73>] ? kthread_freezable_should_stop+0x56/0x56 > Code: 8b b3 d0 00 00 00 48 8b bb d8 00 00 00 0f b7 74 37 02 89 70 08 eb 07 c7 40 08 00 00 00 00 89 d2 c7 40 04 00 00 00 00 48 83 c2 08 <0f> b7 34 d1 89 30 c7 44 24 60 00 00 00 00 8b 44 d1 04 89 44 24 > RIP [<ffffffffa04147dc>] xen_netbk_rx_action+0x18b/0x6f0 [xen_netback] > RSP <ffff8800561edce8> > CR2: ffffc900108641d8 Track the shared ring buffer being unmapped and drop those packets. Ref-count the rings as followed: map -> set to 1 start_xmit -> inc when queueing SKB to internal queue rx_action -> dec after finishing processing a SKB unmap -> dec and wait to be 0 Note that this is different from ref counting the vif structure itself. Currently only guest Rx path is taken care of because that's where the bug surfaced. This bug doesn't exist in kernel >=3.12 as multi-queue support was added there. Link: <https://lists.xenproject.org/archives/html/xen-devel/2014-06/msg00818.html> Signed-off-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: Philipp Hahn <hahn@univention.de> Cc: David Vrabel <david.vrabel@citrix.com> Tested-by: Philipp Hahn <hahn@univention.de> Signed-off-by: Willy Tarreau <w@1wt.eu>
400 lines
9.3 KiB
C
400 lines
9.3 KiB
C
/*
|
|
* Network-device interface management.
|
|
*
|
|
* Copyright (c) 2004-2005, Keir Fraser
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
* as published by the Free Software Foundation; or, when distributed
|
|
* separately from the Linux kernel or incorporated into other
|
|
* software packages, subject to the following license:
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this source file (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use, copy, modify,
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
* and to permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include "common.h"
|
|
|
|
#include <linux/ethtool.h>
|
|
#include <linux/rtnetlink.h>
|
|
#include <linux/if_vlan.h>
|
|
|
|
#include <xen/events.h>
|
|
#include <asm/xen/hypercall.h>
|
|
|
|
#define XENVIF_QUEUE_LENGTH 32
|
|
|
|
void xenvif_get(struct xenvif *vif)
|
|
{
|
|
atomic_inc(&vif->refcnt);
|
|
}
|
|
|
|
void xenvif_get_rings(struct xenvif *vif)
|
|
{
|
|
atomic_inc(&vif->ring_refcnt);
|
|
}
|
|
|
|
void xenvif_put(struct xenvif *vif)
|
|
{
|
|
if (atomic_dec_and_test(&vif->refcnt))
|
|
wake_up(&vif->waiting_to_free);
|
|
}
|
|
|
|
void xenvif_put_rings(struct xenvif *vif)
|
|
{
|
|
if (atomic_dec_and_test(&vif->ring_refcnt))
|
|
wake_up(&vif->waiting_to_unmap);
|
|
}
|
|
|
|
int xenvif_schedulable(struct xenvif *vif)
|
|
{
|
|
return netif_running(vif->dev) && netif_carrier_ok(vif->dev);
|
|
}
|
|
|
|
static int xenvif_rx_schedulable(struct xenvif *vif)
|
|
{
|
|
return xenvif_schedulable(vif) && !xen_netbk_rx_ring_full(vif);
|
|
}
|
|
|
|
static irqreturn_t xenvif_interrupt(int irq, void *dev_id)
|
|
{
|
|
struct xenvif *vif = dev_id;
|
|
|
|
if (vif->netbk == NULL)
|
|
return IRQ_NONE;
|
|
|
|
xen_netbk_schedule_xenvif(vif);
|
|
|
|
if (xenvif_rx_schedulable(vif))
|
|
netif_wake_queue(vif->dev);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
|
{
|
|
struct xenvif *vif = netdev_priv(dev);
|
|
|
|
BUG_ON(skb->dev != dev);
|
|
|
|
if (vif->netbk == NULL)
|
|
goto drop;
|
|
|
|
/* Drop the packet if the target domain has no receive buffers. */
|
|
if (!xenvif_rx_schedulable(vif))
|
|
goto drop;
|
|
|
|
/* Reserve ring slots for the worst-case number of fragments. */
|
|
vif->rx_req_cons_peek += xen_netbk_count_skb_slots(vif, skb);
|
|
xenvif_get(vif);
|
|
xenvif_get_rings(vif);
|
|
|
|
if (vif->can_queue && xen_netbk_must_stop_queue(vif))
|
|
netif_stop_queue(dev);
|
|
|
|
xen_netbk_queue_tx_skb(vif, skb);
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
drop:
|
|
vif->dev->stats.tx_dropped++;
|
|
dev_kfree_skb(skb);
|
|
return NETDEV_TX_OK;
|
|
}
|
|
|
|
void xenvif_receive_skb(struct xenvif *vif, struct sk_buff *skb)
|
|
{
|
|
netif_rx_ni(skb);
|
|
}
|
|
|
|
void xenvif_notify_tx_completion(struct xenvif *vif)
|
|
{
|
|
if (netif_queue_stopped(vif->dev) && xenvif_rx_schedulable(vif))
|
|
netif_wake_queue(vif->dev);
|
|
}
|
|
|
|
static struct net_device_stats *xenvif_get_stats(struct net_device *dev)
|
|
{
|
|
struct xenvif *vif = netdev_priv(dev);
|
|
return &vif->dev->stats;
|
|
}
|
|
|
|
static void xenvif_up(struct xenvif *vif)
|
|
{
|
|
xen_netbk_add_xenvif(vif);
|
|
enable_irq(vif->irq);
|
|
xen_netbk_check_rx_xenvif(vif);
|
|
}
|
|
|
|
static void xenvif_down(struct xenvif *vif)
|
|
{
|
|
disable_irq(vif->irq);
|
|
del_timer_sync(&vif->credit_timeout);
|
|
xen_netbk_deschedule_xenvif(vif);
|
|
xen_netbk_remove_xenvif(vif);
|
|
}
|
|
|
|
static int xenvif_open(struct net_device *dev)
|
|
{
|
|
struct xenvif *vif = netdev_priv(dev);
|
|
if (netif_carrier_ok(dev))
|
|
xenvif_up(vif);
|
|
netif_start_queue(dev);
|
|
return 0;
|
|
}
|
|
|
|
static int xenvif_close(struct net_device *dev)
|
|
{
|
|
struct xenvif *vif = netdev_priv(dev);
|
|
if (netif_carrier_ok(dev))
|
|
xenvif_down(vif);
|
|
netif_stop_queue(dev);
|
|
return 0;
|
|
}
|
|
|
|
static int xenvif_change_mtu(struct net_device *dev, int mtu)
|
|
{
|
|
struct xenvif *vif = netdev_priv(dev);
|
|
int max = vif->can_sg ? 65535 - VLAN_ETH_HLEN : ETH_DATA_LEN;
|
|
|
|
if (mtu > max)
|
|
return -EINVAL;
|
|
dev->mtu = mtu;
|
|
return 0;
|
|
}
|
|
|
|
static netdev_features_t xenvif_fix_features(struct net_device *dev,
|
|
netdev_features_t features)
|
|
{
|
|
struct xenvif *vif = netdev_priv(dev);
|
|
|
|
if (!vif->can_sg)
|
|
features &= ~NETIF_F_SG;
|
|
if (!vif->gso && !vif->gso_prefix)
|
|
features &= ~NETIF_F_TSO;
|
|
if (!vif->csum)
|
|
features &= ~NETIF_F_IP_CSUM;
|
|
|
|
return features;
|
|
}
|
|
|
|
static const struct xenvif_stat {
|
|
char name[ETH_GSTRING_LEN];
|
|
u16 offset;
|
|
} xenvif_stats[] = {
|
|
{
|
|
"rx_gso_checksum_fixup",
|
|
offsetof(struct xenvif, rx_gso_checksum_fixup)
|
|
},
|
|
};
|
|
|
|
static int xenvif_get_sset_count(struct net_device *dev, int string_set)
|
|
{
|
|
switch (string_set) {
|
|
case ETH_SS_STATS:
|
|
return ARRAY_SIZE(xenvif_stats);
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
static void xenvif_get_ethtool_stats(struct net_device *dev,
|
|
struct ethtool_stats *stats, u64 * data)
|
|
{
|
|
void *vif = netdev_priv(dev);
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(xenvif_stats); i++)
|
|
data[i] = *(unsigned long *)(vif + xenvif_stats[i].offset);
|
|
}
|
|
|
|
static void xenvif_get_strings(struct net_device *dev, u32 stringset, u8 * data)
|
|
{
|
|
int i;
|
|
|
|
switch (stringset) {
|
|
case ETH_SS_STATS:
|
|
for (i = 0; i < ARRAY_SIZE(xenvif_stats); i++)
|
|
memcpy(data + i * ETH_GSTRING_LEN,
|
|
xenvif_stats[i].name, ETH_GSTRING_LEN);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static const struct ethtool_ops xenvif_ethtool_ops = {
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
.get_sset_count = xenvif_get_sset_count,
|
|
.get_ethtool_stats = xenvif_get_ethtool_stats,
|
|
.get_strings = xenvif_get_strings,
|
|
};
|
|
|
|
static const struct net_device_ops xenvif_netdev_ops = {
|
|
.ndo_start_xmit = xenvif_start_xmit,
|
|
.ndo_get_stats = xenvif_get_stats,
|
|
.ndo_open = xenvif_open,
|
|
.ndo_stop = xenvif_close,
|
|
.ndo_change_mtu = xenvif_change_mtu,
|
|
.ndo_fix_features = xenvif_fix_features,
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
};
|
|
|
|
struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
|
|
unsigned int handle)
|
|
{
|
|
int err;
|
|
struct net_device *dev;
|
|
struct xenvif *vif;
|
|
char name[IFNAMSIZ] = {};
|
|
|
|
snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
|
|
dev = alloc_netdev(sizeof(struct xenvif), name, ether_setup);
|
|
if (dev == NULL) {
|
|
pr_warn("Could not allocate netdev\n");
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
|
|
SET_NETDEV_DEV(dev, parent);
|
|
|
|
vif = netdev_priv(dev);
|
|
vif->domid = domid;
|
|
vif->handle = handle;
|
|
vif->netbk = NULL;
|
|
vif->can_sg = 1;
|
|
vif->csum = 1;
|
|
atomic_set(&vif->refcnt, 1);
|
|
init_waitqueue_head(&vif->waiting_to_free);
|
|
vif->dev = dev;
|
|
INIT_LIST_HEAD(&vif->schedule_list);
|
|
INIT_LIST_HEAD(&vif->notify_list);
|
|
init_waitqueue_head(&vif->waiting_to_unmap);
|
|
|
|
vif->credit_bytes = vif->remaining_credit = ~0UL;
|
|
vif->credit_usec = 0UL;
|
|
init_timer(&vif->credit_timeout);
|
|
vif->credit_window_start = get_jiffies_64();
|
|
|
|
dev->netdev_ops = &xenvif_netdev_ops;
|
|
dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
|
|
dev->features = dev->hw_features;
|
|
SET_ETHTOOL_OPS(dev, &xenvif_ethtool_ops);
|
|
|
|
dev->tx_queue_len = XENVIF_QUEUE_LENGTH;
|
|
|
|
/*
|
|
* Initialise a dummy MAC address. We choose the numerically
|
|
* largest non-broadcast address to prevent the address getting
|
|
* stolen by an Ethernet bridge for STP purposes.
|
|
* (FE:FF:FF:FF:FF:FF)
|
|
*/
|
|
memset(dev->dev_addr, 0xFF, ETH_ALEN);
|
|
dev->dev_addr[0] &= ~0x01;
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
err = register_netdev(dev);
|
|
if (err) {
|
|
netdev_warn(dev, "Could not register device: err=%d\n", err);
|
|
free_netdev(dev);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
netdev_dbg(dev, "Successfully created xenvif\n");
|
|
|
|
__module_get(THIS_MODULE);
|
|
|
|
return vif;
|
|
}
|
|
|
|
int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
|
|
unsigned long rx_ring_ref, unsigned int evtchn)
|
|
{
|
|
int err = -ENOMEM;
|
|
|
|
/* Already connected through? */
|
|
if (vif->irq)
|
|
return 0;
|
|
|
|
err = xen_netbk_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
|
|
if (err < 0)
|
|
goto err;
|
|
|
|
err = bind_interdomain_evtchn_to_irqhandler(
|
|
vif->domid, evtchn, xenvif_interrupt, 0,
|
|
vif->dev->name, vif);
|
|
if (err < 0)
|
|
goto err_unmap;
|
|
vif->irq = err;
|
|
disable_irq(vif->irq);
|
|
|
|
xenvif_get(vif);
|
|
|
|
rtnl_lock();
|
|
if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
|
|
dev_set_mtu(vif->dev, ETH_DATA_LEN);
|
|
netdev_update_features(vif->dev);
|
|
netif_carrier_on(vif->dev);
|
|
if (netif_running(vif->dev))
|
|
xenvif_up(vif);
|
|
rtnl_unlock();
|
|
|
|
return 0;
|
|
err_unmap:
|
|
xen_netbk_unmap_frontend_rings(vif);
|
|
err:
|
|
return err;
|
|
}
|
|
|
|
void xenvif_carrier_off(struct xenvif *vif)
|
|
{
|
|
struct net_device *dev = vif->dev;
|
|
|
|
rtnl_lock();
|
|
netif_carrier_off(dev); /* discard queued packets */
|
|
if (netif_running(dev))
|
|
xenvif_down(vif);
|
|
rtnl_unlock();
|
|
xenvif_put(vif);
|
|
}
|
|
|
|
void xenvif_disconnect(struct xenvif *vif)
|
|
{
|
|
if (netif_carrier_ok(vif->dev))
|
|
xenvif_carrier_off(vif);
|
|
|
|
disable_irq(vif->irq);
|
|
xen_netbk_unmap_frontend_rings(vif);
|
|
if (vif->irq) {
|
|
unbind_from_irqhandler(vif->irq, vif);
|
|
vif->irq = 0;
|
|
}
|
|
}
|
|
|
|
void xenvif_free(struct xenvif *vif)
|
|
{
|
|
atomic_dec(&vif->refcnt);
|
|
wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
|
|
|
|
unregister_netdev(vif->dev);
|
|
|
|
free_netdev(vif->dev);
|
|
|
|
module_put(THIS_MODULE);
|
|
}
|