Re: netdevice notifier and device private data
Hi, On Sat, Jun 09, 2018 at 03:01:18PM -0400, Michael Richardson wrote: > > Alexander Aring wrote: > > Futhermore user space programs e.g. radvd will do 6lowpan specific > > handling on 6lowpan dev->type, it will not work either on tun > > devices. > > > I know that wpantund from NestLabs do this switch, I am very > > curious about the reason but I think they do it because the name > > is 6LoWPAN. But wpantund is just a SLIP like protocol with > > additional radio/foo commands. > > How do they change it then, and what does it do? They change it with the ioctl() of tun characte device, see [0]. What it does, it just changing the interface type to something else, also there is no check at all that Linux has this interface type. User space software e.g. radvd [1] will evaluate this type and doing specific handling. Obviously changing it to 6LoWPAN and using this code will confuse everything, because the handling makes only sense for a 6LoWPAN Linux interface which actually also use the 6LoWPAN subsystem. They just using tun as all other to feed a IPv6 stack on a remote microcontroller e.g. openthread, contiki, riot. via slip. (wpantund also allow some radio, foo configuration). > It totally seems like broken behaviour. Maybe it's not even intentional. > Maybe they are just foobar. > They simple don't know what they doing... somebody thought 6LoWPAN need to be 6LoWPAN, but they actually don't use the 6LoWPAN handling inside the kernel. _Except_ they doing out of tree stuff which I don't believe. According to [0] it also works with tun default (I suppsoe raw IPv6), because ifdef. And they should not change it because they don't use in-kernel 6LoWPAN functionality. I really think that this tun/tap feature makes a lot of trouble for some type changes. I probably introduce lowpan_dev pointer to netdevice and then check if it's really a 6LoPWAN interface, a dev->type will not garantuee anymore you have a 6LoWPAN interface. At least in user space it's not possible to have a check if you really have a 6LoWPAN interface. - Alex [0] https://github.com/openthread/wpantund/blob/master/src/util/tunnel.c#L180 [1] https://github.com/reubenhwk/radvd/blob/master/device-linux.c#L75
[PATCH RFC v2 0/9] veth: Driver XDP
From: Toshiaki Makita This patch set introduces driver XDP for veth. Basically this is used in conjunction with redirect action of another XDP program. NIC ---> veth===veth (XDP) (redirect)(XDP) In this case xdp_frame can be forwarded to the peer veth without modification, so we can expect far better performance than generic XDP. The envisioned use cases are: * Container managed XDP program Container host redirects frames to containers by XDP redirect action, and privileged containers can deploy their own XDP programs. * XDP program cascading Two or more XDP programs can be called for each packet by redirecting xdp frames to veth. * Internal interface for an XDP bridge When using XDP redirection to create a virtual bridge, veth can be used to create an internal interface for the bridge. With single core and simple XDP programs which only redirect and drop packets, I got 10.5 Mpps redirect/drop rate with i40e 25G NIC + veth. XXV710 (i40e) --- (XDP redirect) --> veth===veth (XDP drop) This changeset is making use of NAPI to implement ndo_xdp_xmit and XDP_TX/REDIRECT. This is mainly because XDP heavily relies on NAPI context. This patchset is based on top of net-next commit 75d4e704fa8d (netdev-FAQ: clarify DaveM's position for stable backports). Any feedback is welcome. Thanks! v2: - Squash NAPI patch with "Add driver XDP" patch. - Remove conversion from xdp_frame to skb when NAPI is not enabled. - Introduce per-queue XDP ring (patch 8). - Introduce bulk skb xmit when XDP is enabled on the peer (patch 9). Toshiaki Makita (9): net: Export skb_headers_offset_update veth: Add driver XDP veth: Avoid drops by oversized packets when XDP is enabled veth: Add another napi ring for ndo_xdp_xmit and handle xdp_frames veth: Add ndo_xdp_xmit xdp: Add a flag for disabling napi_direct of xdp_return_frame in xdp_mem_info veth: Add XDP TX and REDIRECT veth: Support per queue XDP ring veth: Bulk skb xmit for XDP path drivers/net/veth.c | 734 - include/linux/filter.h | 16 ++ include/linux/skbuff.h | 1 + include/net/xdp.h | 4 + net/core/filter.c | 11 +- net/core/skbuff.c | 3 +- net/core/xdp.c | 6 +- 7 files changed, 753 insertions(+), 22 deletions(-) -- 2.14.3
[PATCH RFC v2 9/9] veth: Bulk skb xmit for XDP path
From: Toshiaki Makita Aquire txq lock instead of rxq ptr_ring lock so we avoid per-packet lock when skb->xmit_more is true. We ensure that rxqs are always not less than txqs and txq to rxq is one to one mapping, so we can completely remove rxq side lock. Since we removed rxq side lock, this change does not increase the number of locking even when bulk sending is not possible, e.g. non-GSO packets. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 67debd3eafe6..376d70f983e5 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -138,7 +138,7 @@ static void __veth_xdp_flush(struct veth_rq *rq) static int veth_xdp_rx(struct veth_rq *rq, struct sk_buff *skb) { - if (unlikely(ptr_ring_produce(&rq->xdp_ring, skb))) { + if (unlikely(__ptr_ring_produce(&rq->xdp_ring, skb))) { dev_kfree_skb_any(skb); return NET_RX_DROP; } @@ -188,7 +188,7 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) atomic64_inc(&priv->dropped); } - if (rcv_xdp) + if (rcv_xdp && !skb->xmit_more) __veth_xdp_flush(rq); rcu_read_unlock(); @@ -829,15 +829,21 @@ static netdev_features_t veth_fix_features(struct net_device *dev, { struct veth_priv *priv = netdev_priv(dev); struct net_device *peer; + bool xdp = false; peer = rtnl_dereference(priv->peer); if (peer) { struct veth_priv *peer_priv = netdev_priv(peer); if (rtnl_dereference(peer_priv->rq[0].xdp_prog)) - features &= ~NETIF_F_GSO_SOFTWARE; + xdp = true; } + if (xdp) + features &= ~(NETIF_F_GSO_SOFTWARE | NETIF_F_LLTX); + else + features |= NETIF_F_LLTX; + return features; } -- 2.14.3
[PATCH RFC v2 6/9] xdp: Add a flag for disabling napi_direct of xdp_return_frame in xdp_mem_info
From: Toshiaki Makita We need some mechanism to disable napi_direct on calling xdp_return_frame_rx_napi() from some context. When veth gets support of XDP_REDIRECT, it will redirects packets which are redirected from other devices. On redirection veth will reuse xdp_mem_info of the redirection source device to make return_frame work. But in this case .ndo_xdp_xmit() called from veth redirection uses xdp_mem_info which is not guarded by NAPI, because the .ndo_xdp_xmit is not called directly from the rxq which owns the xdp_mem_info. This approach introduces a flag in xdp_mem_info to indicate that napi_direct should be disabled even when _rx_napi variant is used. Signed-off-by: Toshiaki Makita --- include/net/xdp.h | 4 net/core/xdp.c| 6 -- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/net/xdp.h b/include/net/xdp.h index 2deea7166a34..ea0c80f6c8ee 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -41,6 +41,9 @@ enum xdp_mem_type { MEM_TYPE_MAX, }; +/* XDP flags for xdp_mem_info */ +#define XDP_MEM_RF_NO_DIRECT BIT(0) /* don't use napi_direct */ + /* XDP flags for ndo_xdp_xmit */ #define XDP_XMIT_FLUSH (1U << 0) /* doorbell signal consumer */ #define XDP_XMIT_FLAGS_MASKXDP_XMIT_FLUSH @@ -48,6 +51,7 @@ enum xdp_mem_type { struct xdp_mem_info { u32 type; /* enum xdp_mem_type, but known size type */ u32 id; + u32 flags; }; struct page_pool; diff --git a/net/core/xdp.c b/net/core/xdp.c index 9d1f22072d5d..e94f146360b2 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -327,10 +327,12 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct, /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */ xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params); page = virt_to_head_page(data); - if (xa) + if (xa) { + napi_direct &= !(mem->flags & XDP_MEM_RF_NO_DIRECT); page_pool_put_page(xa->page_pool, page, napi_direct); - else + } else { put_page(page); + } rcu_read_unlock(); break; case MEM_TYPE_PAGE_SHARED: -- 2.14.3
[PATCH RFC v2 5/9] veth: Add ndo_xdp_xmit
From: Toshiaki Makita This allows NIC's XDP to redirect packets to veth. The destination veth device enqueues redirected packets to the napi ring of its peer, then they are processed by XDP on its peer veth device. This can be thought as calling another XDP program by XDP program using REDIRECT, when the peer enables driver XDP. Note that when the peer veth device does not set driver xdp, redirected packets will be dropped because the peer is not ready for NAPI. v2: - Drop the part converting xdp_frame into skb when XDP is not enabled. - Implement bulk interface of ndo_xdp_xmit. - Implement XDP_XMIT_FLUSH bit and drop ndo_xdp_flush. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 39 +++ include/linux/filter.h | 16 net/core/filter.c | 11 +-- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index cb3fa558fbe0..b809d609a642 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -254,6 +255,43 @@ static struct sk_buff *veth_build_skb(void *head, int headroom, int len, return skb; } +static int veth_xdp_xmit(struct net_device *dev, int n, +struct xdp_frame **frames, u32 flags) +{ + struct veth_priv *rcv_priv, *priv = netdev_priv(dev); + struct net_device *rcv; + int i, drops = 0; + + if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) + return -EINVAL; + + rcv = rcu_dereference(priv->peer); + if (unlikely(!rcv)) + return -ENXIO; + + rcv_priv = netdev_priv(rcv); + /* xdp_ring is initialized on receive side? */ + if (!rcu_access_pointer(rcv_priv->xdp_prog)) + return -ENXIO; + + spin_lock(&rcv_priv->xdp_tx_ring.producer_lock); + for (i = 0; i < n; i++) { + struct xdp_frame *frame = frames[i]; + + if (unlikely(xdp_ok_fwd_dev(rcv, frame->len) || +__ptr_ring_produce(&rcv_priv->xdp_tx_ring, frame))) { + xdp_return_frame_rx_napi(frame); + drops++; + } + } + spin_unlock(&rcv_priv->xdp_tx_ring.producer_lock); + + if (flags & XDP_XMIT_FLUSH) + __veth_xdp_flush(rcv_priv); + + return n - drops; +} + static struct sk_buff *veth_xdp_rcv_one(struct veth_priv *priv, struct xdp_frame *frame) { @@ -770,6 +808,7 @@ static const struct net_device_ops veth_netdev_ops = { .ndo_features_check = passthru_features_check, .ndo_set_rx_headroom= veth_set_rx_headroom, .ndo_bpf= veth_xdp, + .ndo_xdp_xmit = veth_xdp_xmit, }; #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \ diff --git a/include/linux/filter.h b/include/linux/filter.h index 45fc0f5000d8..12777eb70b40 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -786,6 +787,21 @@ static inline bool bpf_dump_raw_ok(void) struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, const struct bpf_insn *patch, u32 len); +static __always_inline int +xdp_ok_fwd_dev(const struct net_device *fwd, unsigned int pktlen) +{ + unsigned int len; + + if (unlikely(!(fwd->flags & IFF_UP))) + return -ENETDOWN; + + len = fwd->mtu + fwd->hard_header_len + VLAN_HLEN; + if (pktlen > len) + return -EMSGSIZE; + + return 0; +} + /* The pair of xdp_do_redirect and xdp_do_flush_map MUST be called in the * same cpu context. Further for best results no more than a single map * for the do_redirect/do_flush pair should be used. This limitation is diff --git a/net/core/filter.c b/net/core/filter.c index 3d9ba7e5965a..05d9e84566a4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3216,16 +3216,7 @@ EXPORT_SYMBOL_GPL(xdp_do_redirect); static int __xdp_generic_ok_fwd_dev(struct sk_buff *skb, struct net_device *fwd) { - unsigned int len; - - if (unlikely(!(fwd->flags & IFF_UP))) - return -ENETDOWN; - - len = fwd->mtu + fwd->hard_header_len + VLAN_HLEN; - if (skb->len > len) - return -EMSGSIZE; - - return 0; + return xdp_ok_fwd_dev(fwd, skb->len); } static int xdp_do_generic_redirect_map(struct net_device *dev, -- 2.14.3
[PATCH RFC v2 2/9] veth: Add driver XDP
From: Toshiaki Makita This is basic implementation of veth driver XDP. Incoming packets are sent from the peer veth device in the form of skb, so this is generally doing the same thing as generic XDP. This itself is not so useful, but a starting point to implement other useful veth XDP features like TX and REDIRECT. This introduces NAPI when XDP is enabled, because XDP is now heavily relies on NAPI context. Use ptr_ring to emulate NIC ring. Tx function enqueues packets to the ring and peer NAPI handler drains the ring. Currently only one ring is allocated for each veth device, so it does not scale on multiqueue env. This can be resolved by allocating rings on the per-queue basis later. Note that NAPI is not used but netif_rx is used when XDP is not loaded, so this does not change the default behaviour. v2: - Squashed with the patch adding NAPI. - Implement adjust_tail. - Don't acquire consumer lock because it is guarded by NAPI. - Make poll_controller noop since it is unnecessary. - Register rxq_info on enabling XDP rather than on opening the device. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 357 +++-- 1 file changed, 350 insertions(+), 7 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index a69ad39ee57e..317ec92cf816 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -19,10 +19,18 @@ #include #include #include +#include +#include +#include +#include +#include #define DRV_NAME "veth" #define DRV_VERSION"1.0" +#define VETH_RING_SIZE 256 +#define VETH_XDP_HEADROOM (XDP_PACKET_HEADROOM + NET_IP_ALIGN) + struct pcpu_vstats { u64 packets; u64 bytes; @@ -30,9 +38,15 @@ struct pcpu_vstats { }; struct veth_priv { + struct napi_struct xdp_napi; + struct net_device *dev; + struct bpf_prog __rcu *xdp_prog; struct net_device __rcu *peer; atomic64_t dropped; unsignedrequested_headroom; + boolrx_notify_masked; + struct ptr_ring xdp_ring; + struct xdp_rxq_info xdp_rxq; }; /* @@ -98,11 +112,43 @@ static const struct ethtool_ops veth_ethtool_ops = { .get_link_ksettings = veth_get_link_ksettings, }; -static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) +/* general routines */ + +static void __veth_xdp_flush(struct veth_priv *priv) +{ + /* Write ptr_ring before reading rx_notify_masked */ + smp_mb(); + if (!priv->rx_notify_masked) { + priv->rx_notify_masked = true; + napi_schedule(&priv->xdp_napi); + } +} + +static int veth_xdp_rx(struct veth_priv *priv, struct sk_buff *skb) +{ + if (unlikely(ptr_ring_produce(&priv->xdp_ring, skb))) { + dev_kfree_skb_any(skb); + return NET_RX_DROP; + } + + return NET_RX_SUCCESS; +} + +static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, bool xdp) { struct veth_priv *priv = netdev_priv(dev); + + return __dev_forward_skb(dev, skb) ?: xdp ? + veth_xdp_rx(priv, skb) : + netif_rx(skb); +} + +static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) +{ + struct veth_priv *rcv_priv, *priv = netdev_priv(dev); struct net_device *rcv; int length = skb->len; + bool rcv_xdp = false; rcu_read_lock(); rcv = rcu_dereference(priv->peer); @@ -111,7 +157,10 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) goto drop; } - if (likely(dev_forward_skb(rcv, skb) == NET_RX_SUCCESS)) { + rcv_priv = netdev_priv(rcv); + rcv_xdp = rcu_access_pointer(rcv_priv->xdp_prog); + + if (likely(veth_forward_skb(rcv, skb, rcv_xdp) == NET_RX_SUCCESS)) { struct pcpu_vstats *stats = this_cpu_ptr(dev->vstats); u64_stats_update_begin(&stats->syncp); @@ -122,14 +171,15 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) drop: atomic64_inc(&priv->dropped); } + + if (rcv_xdp) + __veth_xdp_flush(rcv_priv); + rcu_read_unlock(); + return NETDEV_TX_OK; } -/* - * general routines - */ - static u64 veth_stats_one(struct pcpu_vstats *result, struct net_device *dev) { struct veth_priv *priv = netdev_priv(dev); @@ -179,18 +229,245 @@ static void veth_set_multicast_list(struct net_device *dev) { } +static struct sk_buff *veth_build_skb(void *head, int headroom, int len, + int buflen) +{ + struct sk_buff *skb; + + if (!buflen) { + buflen = SKB_DATA_ALIGN(headroom + len) + +SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + } + skb = build_skb(head, buf
[PATCH RFC v2 4/9] veth: Add another napi ring for ndo_xdp_xmit and handle xdp_frames
From: Toshiaki Makita This is preparation for XDP TX and ndo_xdp_xmit. Add another napi ring and handle redirected xdp_frames through it. v2: - Use another ring instead of using flag to differentiate skb and xdp_frame. This approach makes bulk skb transmit possible in veth_xmit later. - Clear xdp_frame feilds in skb->head. - Implement adjust_tail. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 125 - 1 file changed, 114 insertions(+), 11 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 88d349da72cc..cb3fa558fbe0 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -46,6 +46,7 @@ struct veth_priv { unsignedrequested_headroom; boolrx_notify_masked; struct ptr_ring xdp_ring; + struct ptr_ring xdp_tx_ring; struct xdp_rxq_info xdp_rxq; }; @@ -114,6 +115,11 @@ static const struct ethtool_ops veth_ethtool_ops = { /* general routines */ +static void veth_xdp_free(void *frame) +{ + xdp_return_frame(frame); +} + static void __veth_xdp_flush(struct veth_priv *priv) { /* Write ptr_ring before reading rx_notify_masked */ @@ -248,6 +254,61 @@ static struct sk_buff *veth_build_skb(void *head, int headroom, int len, return skb; } +static struct sk_buff *veth_xdp_rcv_one(struct veth_priv *priv, + struct xdp_frame *frame) +{ + int len = frame->len, delta = 0; + struct bpf_prog *xdp_prog; + unsigned int headroom; + struct sk_buff *skb; + + rcu_read_lock(); + xdp_prog = rcu_dereference(priv->xdp_prog); + if (xdp_prog) { + struct xdp_buff xdp; + u32 act; + + xdp.data_hard_start = frame->data - frame->headroom; + xdp.data = frame->data; + xdp.data_end = frame->data + frame->len; + xdp.data_meta = frame->data - frame->metasize; + xdp.rxq = &priv->xdp_rxq; + + act = bpf_prog_run_xdp(xdp_prog, &xdp); + + switch (act) { + case XDP_PASS: + delta = frame->data - xdp.data; + len = xdp.data_end - xdp.data; + break; + default: + bpf_warn_invalid_xdp_action(act); + case XDP_ABORTED: + trace_xdp_exception(priv->dev, xdp_prog, act); + case XDP_DROP: + goto err_xdp; + } + } + rcu_read_unlock(); + + headroom = frame->data - delta - (void *)frame; + skb = veth_build_skb(frame, headroom, len, 0); + if (!skb) { + xdp_return_frame(frame); + goto err; + } + + memset(frame, 0, sizeof(*frame)); + skb->protocol = eth_type_trans(skb, priv->dev); +err: + return skb; +err_xdp: + rcu_read_unlock(); + xdp_return_frame(frame); + + return NULL; +} + static struct sk_buff *veth_xdp_rcv_skb(struct veth_priv *priv, struct sk_buff *skb) { @@ -352,21 +413,53 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_priv *priv, static int veth_xdp_rcv(struct veth_priv *priv, int budget) { - int i, done = 0; + int done = 0; + bool more; - for (i = 0; i < budget; i++) { - struct sk_buff *skb = __ptr_ring_consume(&priv->xdp_ring); + do { + int curr_budget, i; + bool curr_more; - if (!skb) - break; + more = false; - skb = veth_xdp_rcv_skb(priv, skb); + curr_more = true; + curr_budget = min(budget - done, budget >> 1); + for (i = 0; i < curr_budget; i++) { + struct xdp_frame *frame; + struct sk_buff *skb; - if (skb) - napi_gro_receive(&priv->xdp_napi, skb); + frame = __ptr_ring_consume(&priv->xdp_tx_ring); + if (!frame) { + curr_more = false; + break; + } - done++; - } + skb = veth_xdp_rcv_one(priv, frame); + if (skb) + napi_gro_receive(&priv->xdp_napi, skb); + + done++; + } + more |= curr_more; + + curr_more = true; + curr_budget = min(budget - done, budget >> 1); + for (i = 0; i < curr_budget; i++) { + struct sk_buff *skb = __ptr_ring_consume(&priv->xdp_ring); + + if (!skb) { + curr_more = false; + break; +
[PATCH RFC v2 3/9] veth: Avoid drops by oversized packets when XDP is enabled
From: Toshiaki Makita All oversized packets including GSO packets are dropped if XDP is enabled on receiver side, so don't send such packets from peer. Drop TSO and SCTP fragmentation features so that veth devices themselves segment packets with XDP enabled. Also cap MTU accordingly. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 49 +++-- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 317ec92cf816..88d349da72cc 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -533,6 +533,23 @@ static int veth_get_iflink(const struct net_device *dev) return iflink; } +static netdev_features_t veth_fix_features(struct net_device *dev, + netdev_features_t features) +{ + struct veth_priv *priv = netdev_priv(dev); + struct net_device *peer; + + peer = rtnl_dereference(priv->peer); + if (peer) { + struct veth_priv *peer_priv = netdev_priv(peer); + + if (rtnl_dereference(peer_priv->xdp_prog)) + features &= ~NETIF_F_GSO_SOFTWARE; + } + + return features; +} + static void veth_set_rx_headroom(struct net_device *dev, int new_hr) { struct veth_priv *peer_priv, *priv = netdev_priv(dev); @@ -571,10 +588,19 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, if (!peer) return -ENOTCONN; - if (!old_prog && dev->flags & IFF_UP) { - err = veth_enable_xdp(dev); - if (err) - return err; + if (!old_prog) { + if (dev->flags & IFF_UP) { + err = veth_enable_xdp(dev); + if (err) + return err; + } + + peer->hw_features &= ~NETIF_F_GSO_SOFTWARE; + peer->max_mtu = PAGE_SIZE - VETH_XDP_HEADROOM - + peer->hard_header_len - + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + if (peer->mtu > peer->max_mtu) + dev_set_mtu(peer, peer->max_mtu); } } @@ -582,10 +608,20 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, if (old_prog) { bpf_prog_put(old_prog); - if (!prog && dev->flags & IFF_UP) - veth_disable_xdp(dev); + if (!prog) { + if (dev->flags & IFF_UP) + veth_disable_xdp(dev); + + if (peer) { + peer->hw_features |= NETIF_F_GSO_SOFTWARE; + peer->max_mtu = ETH_MAX_MTU; + } + } } + if ((!!old_prog ^ !!prog) && peer) + netdev_update_features(peer); + return 0; } @@ -627,6 +663,7 @@ static const struct net_device_ops veth_netdev_ops = { .ndo_poll_controller= veth_poll_controller, #endif .ndo_get_iflink = veth_get_iflink, + .ndo_fix_features = veth_fix_features, .ndo_features_check = passthru_features_check, .ndo_set_rx_headroom= veth_set_rx_headroom, .ndo_bpf= veth_xdp, -- 2.14.3
[PATCH RFC v2 8/9] veth: Support per queue XDP ring
From: Toshiaki Makita Move XDP and napi related fields in veth_priv to newly created veth_rq structure. When xdp_frames are enqueued from ndo_xdp_xmit and XDP_TX, rxq is selected by current cpu. When skbs are enqueued from the peer device, rxq is determined by its peer's txq. In this way we can implement bulk packet send using skb->xmit_more later. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 290 +++-- 1 file changed, 191 insertions(+), 99 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index a47e1ba7d7e6..67debd3eafe6 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -38,20 +38,24 @@ struct pcpu_vstats { struct u64_stats_sync syncp; }; -struct veth_priv { +struct veth_rq { struct napi_struct xdp_napi; struct net_device *dev; struct bpf_prog __rcu *xdp_prog; - struct net_device __rcu *peer; - atomic64_t dropped; struct xdp_mem_info xdp_mem; - unsignedrequested_headroom; boolrx_notify_masked; struct ptr_ring xdp_ring; struct ptr_ring xdp_tx_ring; struct xdp_rxq_info xdp_rxq; }; +struct veth_priv { + struct net_device __rcu *peer; + atomic64_t dropped; + struct veth_rq *rq; + unsigned intrequested_headroom; +}; + /* * ethtool interface */ @@ -122,19 +126,19 @@ static void veth_xdp_free(void *frame) xdp_return_frame(frame); } -static void __veth_xdp_flush(struct veth_priv *priv) +static void __veth_xdp_flush(struct veth_rq *rq) { /* Write ptr_ring before reading rx_notify_masked */ smp_mb(); - if (!priv->rx_notify_masked) { - priv->rx_notify_masked = true; - napi_schedule(&priv->xdp_napi); + if (!rq->rx_notify_masked) { + rq->rx_notify_masked = true; + napi_schedule(&rq->xdp_napi); } } -static int veth_xdp_rx(struct veth_priv *priv, struct sk_buff *skb) +static int veth_xdp_rx(struct veth_rq *rq, struct sk_buff *skb) { - if (unlikely(ptr_ring_produce(&priv->xdp_ring, skb))) { + if (unlikely(ptr_ring_produce(&rq->xdp_ring, skb))) { dev_kfree_skb_any(skb); return NET_RX_DROP; } @@ -142,12 +146,11 @@ static int veth_xdp_rx(struct veth_priv *priv, struct sk_buff *skb) return NET_RX_SUCCESS; } -static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, bool xdp) +static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, + struct veth_rq *rq, bool xdp) { - struct veth_priv *priv = netdev_priv(dev); - return __dev_forward_skb(dev, skb) ?: xdp ? - veth_xdp_rx(priv, skb) : + veth_xdp_rx(rq, skb) : netif_rx(skb); } @@ -157,6 +160,8 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) struct net_device *rcv; int length = skb->len; bool rcv_xdp = false; + struct veth_rq *rq; + int rxq; rcu_read_lock(); rcv = rcu_dereference(priv->peer); @@ -166,9 +171,12 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) } rcv_priv = netdev_priv(rcv); - rcv_xdp = rcu_access_pointer(rcv_priv->xdp_prog); + rxq = skb_get_queue_mapping(skb); + skb_record_rx_queue(skb, rxq); + rq = &rcv_priv->rq[rxq]; + rcv_xdp = rcu_access_pointer(rq->xdp_prog); - if (likely(veth_forward_skb(rcv, skb, rcv_xdp) == NET_RX_SUCCESS)) { + if (likely(veth_forward_skb(rcv, skb, rq, rcv_xdp) == NET_RX_SUCCESS)) { struct pcpu_vstats *stats = this_cpu_ptr(dev->vstats); u64_stats_update_begin(&stats->syncp); @@ -181,7 +189,7 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) } if (rcv_xdp) - __veth_xdp_flush(rcv_priv); + __veth_xdp_flush(rq); rcu_read_unlock(); @@ -256,11 +264,17 @@ static struct sk_buff *veth_build_skb(void *head, int headroom, int len, return skb; } +static int veth_select_rxq(struct net_device *dev) +{ + return smp_processor_id() % dev->real_num_rx_queues; +} + static int veth_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, u32 flags) { struct veth_priv *rcv_priv, *priv = netdev_priv(dev); struct net_device *rcv; + struct veth_rq *rq; int i, drops = 0; if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) @@ -271,24 +285,25 @@ static int veth_xdp_xmit(struct net_device *dev, int n, return -ENXIO; rcv_priv = netdev_priv(rcv); + rq = &rcv_priv->rq[veth_select_rxq(rcv)]; /* xdp_ring is initialized on receive side? */ -
[PATCH RFC v2 1/9] net: Export skb_headers_offset_update
From: Toshiaki Makita v2: - Drop skb_copy_header part because it has already been exported now. Signed-off-by: Toshiaki Makita --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 164cdedf6012..2bdba543fda7 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1030,6 +1030,7 @@ static inline struct sk_buff *alloc_skb_fclone(unsigned int size, } struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src); +void skb_headers_offset_update(struct sk_buff *skb, int off); int skb_copy_ubufs(struct sk_buff *skb, gfp_t gfp_mask); struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t priority); void skb_copy_header(struct sk_buff *new, const struct sk_buff *old); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c642304f178c..180ab7d7f84f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1290,7 +1290,7 @@ struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask) } EXPORT_SYMBOL(skb_clone); -static void skb_headers_offset_update(struct sk_buff *skb, int off) +void skb_headers_offset_update(struct sk_buff *skb, int off) { /* Only adjust this if it actually is csum_start rather than csum */ if (skb->ip_summed == CHECKSUM_PARTIAL) @@ -1304,6 +1304,7 @@ static void skb_headers_offset_update(struct sk_buff *skb, int off) skb->inner_network_header += off; skb->inner_mac_header += off; } +EXPORT_SYMBOL(skb_headers_offset_update); void skb_copy_header(struct sk_buff *new, const struct sk_buff *old) { -- 2.14.3
[PATCH RFC v2 7/9] veth: Add XDP TX and REDIRECT
From: Toshiaki Makita This allows further redirection of xdp_frames like NIC -> veth--veth -> veth--veth (XDP) (XDP) (XDP) The intermediate XDP, redirecting packets from NIC to the other veth, reuses xdp_mem_info from NIC so that page recycling of the NIC works on the destination veth's XDP. In this way return_frame is not fully guarded by NAPI, since another NAPI handler on another cpu may use the same xdp_mem_info concurrently. Thus disable napi_direct by XDP_MEM_RF_NO_DIRECT flag. Signed-off-by: Toshiaki Makita --- drivers/net/veth.c | 110 + 1 file changed, 103 insertions(+), 7 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index b809d609a642..a47e1ba7d7e6 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -44,6 +44,7 @@ struct veth_priv { struct bpf_prog __rcu *xdp_prog; struct net_device __rcu *peer; atomic64_t dropped; + struct xdp_mem_info xdp_mem; unsignedrequested_headroom; boolrx_notify_masked; struct ptr_ring xdp_ring; @@ -292,10 +293,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n, return n - drops; } +static void veth_xdp_flush(struct net_device *dev) +{ + struct veth_priv *rcv_priv, *priv = netdev_priv(dev); + struct net_device *rcv; + + rcu_read_lock(); + rcv = rcu_dereference(priv->peer); + if (unlikely(!rcv)) + goto out; + + rcv_priv = netdev_priv(rcv); + /* xdp_ring is initialized on receive side? */ + if (unlikely(!rcu_access_pointer(rcv_priv->xdp_prog))) + goto out; + + __veth_xdp_flush(rcv_priv); +out: + rcu_read_unlock(); +} + +static int veth_xdp_tx(struct net_device *dev, struct xdp_buff *xdp) +{ + struct xdp_frame *frame = convert_to_xdp_frame(xdp); + + if (unlikely(!frame)) + return -EOVERFLOW; + + return veth_xdp_xmit(dev, 1, &frame, 0); +} + static struct sk_buff *veth_xdp_rcv_one(struct veth_priv *priv, - struct xdp_frame *frame) + struct xdp_frame *frame, bool *xdp_xmit, + bool *xdp_redir) { int len = frame->len, delta = 0; + struct xdp_frame orig_frame; struct bpf_prog *xdp_prog; unsigned int headroom; struct sk_buff *skb; @@ -319,6 +352,31 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_priv *priv, delta = frame->data - xdp.data; len = xdp.data_end - xdp.data; break; + case XDP_TX: + orig_frame = *frame; + xdp.data_hard_start = frame; + xdp.rxq->mem = frame->mem; + xdp.rxq->mem.flags |= XDP_MEM_RF_NO_DIRECT; + if (unlikely(veth_xdp_tx(priv->dev, &xdp))) { + trace_xdp_exception(priv->dev, xdp_prog, act); + frame = &orig_frame; + goto err_xdp; + } + *xdp_xmit = true; + rcu_read_unlock(); + goto xdp_xmit; + case XDP_REDIRECT: + orig_frame = *frame; + xdp.data_hard_start = frame; + xdp.rxq->mem = frame->mem; + xdp.rxq->mem.flags |= XDP_MEM_RF_NO_DIRECT; + if (xdp_do_redirect(priv->dev, &xdp, xdp_prog)) { + frame = &orig_frame; + goto err_xdp; + } + *xdp_redir = true; + rcu_read_unlock(); + goto xdp_xmit; default: bpf_warn_invalid_xdp_action(act); case XDP_ABORTED: @@ -343,12 +401,13 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_priv *priv, err_xdp: rcu_read_unlock(); xdp_return_frame(frame); - +xdp_xmit: return NULL; } static struct sk_buff *veth_xdp_rcv_skb(struct veth_priv *priv, - struct sk_buff *skb) + struct sk_buff *skb, bool *xdp_xmit, + bool *xdp_redir) { u32 pktlen, headroom, act, metalen; void *orig_data, *orig_data_end; @@ -417,6 +476,26 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_priv *priv, switch (act) { case XDP_PASS: break; + case XDP_TX: + get_page(virt_to_page(xdp.data)); + dev_consume_skb_any(skb); + xdp.rxq->mem = priv->xdp_mem; + if (unlikely(veth_xdp_tx(priv->dev, &xdp))) { +
[ 54.304576] eth0: hw csum failure
Hi there, I am getting the following in dmesg upon startup from [ 54.304576] eth0: hw csum failure [ 54.304610] CPU: 0 PID: 0 Comm: swapper Not tainted 4.17.0+ #3 [ 54.304616] Call Trace: [ 54.304633] [dffedbd0] [c069d178] __skb_checksum_complete+0xf0/0x108 (unreliable) [ 54.304653] [dffedbf0] [c077711c] tcp_v4_rcv+0x604/0xe00 [ 54.304668] [dffedc70] [c0730c98] ip_local_deliver_finish+0xa8/0x3c4 [ 54.304677] [dffedcb0] [c0731aa4] ip_local_deliver+0xf0/0x154 [ 54.304687] [dffedcf0] [c0731f50] ip_rcv+0x448/0x774 [ 54.304701] [dffedd50] [c06adeac] __netif_receive_skb_core+0x5e8/0x1184 [ 54.304712] [dffedde0] [c06badec] napi_gro_receive+0x160/0x22c [ 54.304729] [dffede10] [e1560590] gem_poll+0x7fc/0x1ac0 [sungem] [ 54.304738] [dffedee0] [c06ba0bc] net_rx_action+0x34c/0x618 [ 54.304750] [dffedf60] [c07fc904] __do_softirq+0x16c/0x5f0 [ 54.304763] [dffedfd0] [c0064c9c] irq_exit+0x110/0x1a8 [ 54.304777] [dffedff0] [c0016170] call_do_irq+0x24/0x3c [ 54.304791] [c0cf5e80] [c0009a84] do_IRQ+0x98/0x1a0 [ 54.304801] [c0cf5eb0] [c001b474] ret_from_except+0x0/0x14 [ 54.304812] --- interrupt: 501 at arch_cpu_idle+0x30/0x78 LR = arch_cpu_idle+0x30/0x78 [ 54.304821] [c0cf5f70] [c0cf4000] 0xc0cf4000 (unreliable) [ 54.304836] [c0cf5f80] [c00a3868] do_idle+0xc4/0x158 [ 54.304845] [c0cf5fb0] [c00a3ab4] cpu_startup_entry+0x24/0x28 [ 54.304856] [c0cf5fc0] [c0997820] start_kernel+0x47c/0x490 [ 54.304864] [c0cf5ff0] [3444] 0x3444 [ 54.309112] eth0: hw csum failure [ 54.309133] CPU: 0 PID: 7 Comm: ksoftirqd/0 Not tainted 4.17.0+ #3 [ 54.309138] Call Trace: [ 54.309154] [df503ab0] [c069d178] __skb_checksum_complete+0xf0/0x108 (unreliable) [ 54.309172] [df503ad0] [c077711c] tcp_v4_rcv+0x604/0xe00 [ 54.309184] [df503b50] [c0730c98] ip_local_deliver_finish+0xa8/0x3c4 [ 54.309191] [df503b90] [c0731aa4] ip_local_deliver+0xf0/0x154 [ 54.309199] [df503bd0] [c0731f50] ip_rcv+0x448/0x774 [ 54.309211] [df503c30] [c06adeac] __netif_receive_skb_core+0x5e8/0x1184 [ 54.309220] [df503cc0] [c06badec] napi_gro_receive+0x160/0x22c [ 54.309235] [df503cf0] [e1560590] gem_poll+0x7fc/0x1ac0 [sungem] [ 54.309242] [df503dc0] [c06ba0bc] net_rx_action+0x34c/0x618 [ 54.309252] [df503e40] [c07fc904] __do_softirq+0x16c/0x5f0 [ 54.309263] [df503eb0] [c00649c8] run_ksoftirqd+0x68/0x9c [ 54.309276] [df503ec0] [c009477c] smpboot_thread_fn+0x1bc/0x324 [ 54.309289] [df503f10] [c008e01c] kthread+0x138/0x1f0 [ 54.309296] [df503f40] [c001b1c4] ret_from_kernel_thread+0x14/0x1c [ 55.829670] eth0: hw csum failure [ 55.829703] CPU: 0 PID: 0 Comm: swapper Not tainted 4.17.0+ #3 [ 55.829709] Call Trace: [ 55.829726] [dffedbd0] [c069d178] __skb_checksum_complete+0xf0/0x108 (unreliable) [ 55.829746] [dffedbf0] [c077711c] tcp_v4_rcv+0x604/0xe00 [ 55.829760] [dffedc70] [c0730c98] ip_local_deliver_finish+0xa8/0x3c4 [ 55.829770] [dffedcb0] [c0731aa4] ip_local_deliver+0xf0/0x154 [ 55.829779] [dffedcf0] [c0731f50] ip_rcv+0x448/0x774 [ 55.829793] [dffedd50] [c06adeac] __netif_receive_skb_core+0x5e8/0x1184 [ 55.829804] [dffedde0] [c06badec] napi_gro_receive+0x160/0x22c [ 55.829820] [dffede10] [e1560590] gem_poll+0x7fc/0x1ac0 [sungem] [ 55.829830] [dffedee0] [c06ba0bc] net_rx_action+0x34c/0x618 [ 55.829842] [dffedf60] [c07fc904] __do_softirq+0x16c/0x5f0 [ 55.829855] [dffedfd0] [c0064c9c] irq_exit+0x110/0x1a8 [ 55.829869] [dffedff0] [c0016170] call_do_irq+0x24/0x3c [ 55.829883] [c0cf5e80] [c0009a84] do_IRQ+0x98/0x1a0 [ 55.829892] [c0cf5eb0] [c001b474] ret_from_except+0x0/0x14 [ 55.829904] --- interrupt: 501 at arch_cpu_idle+0x30/0x78 LR = arch_cpu_idle+0x30/0x78 [ 55.829912] [c0cf5f70] [c0cf4000] 0xc0cf4000 (unreliable) [ 55.829927] [c0cf5f80] [c00a3868] do_idle+0xc4/0x158 [ 55.829936] [c0cf5fb0] [c00a3ab4] cpu_startup_entry+0x24/0x28 [ 55.829947] [c0cf5fc0] [c0997820] start_kernel+0x47c/0x490 [ 55.829955] [c0cf5ff0] [3444] 0x3444 [ 55.831823] eth0: hw csum failure ... Do you want me to run a bit-bisect ?
Re: [Patch net] socket: close race condition between sock_close() and sockfs_setattr()
From: Cong Wang Date: Thu, 7 Jun 2018 13:39:49 -0700 > fchownat() doesn't even hold refcnt of fd until it figures out > fd is really needed (otherwise is ignored) and releases it after > it resolves the path. This means sock_close() could race with > sockfs_setattr(), which leads to a NULL pointer dereference > since typically we set sock->sk to NULL in ->release(). > > As pointed out by Al, this is unique to sockfs. So we can fix this > in socket layer by acquiring inode_lock in sock_close() and > checking against NULL in sockfs_setattr(). > > sock_release() is called in many places, only the sock_close() > path matters here. And fortunately, this should not affect normal > sock_close() as it is only called when the last fd refcnt is gone. > It only affects sock_close() with a parallel sockfs_setattr() in > progress, which is not common. > > Fixes: 86741ec25462 ("net: core: Add a UID field to struct sock.") > Reported-by: shankarapailoor > Cc: Tetsuo Handa > Cc: Lorenzo Colitti > Cc: Al Viro > Signed-off-by: Cong Wang I'm applying this for now, it is at least a step towards fixing all of these issues. If it is really offensive, I can revert, just tell me.
Re: [PATCH v6 net] stmmac: strip all VLAN tag types when kernel 802.1Q support is selected
From: Elad Nachman Date: Fri, 8 Jun 2018 12:19:29 +0300 > stmmac reception handler calls stmmac_rx_vlan() to strip the vlan before > calling napi_gro_receive(). > > The function assumes VLAN tagged frames are always tagged with > 802.1Q protocol, and assigns ETH_P_8021Q to the skb by hard-coding > the parameter on call to __vlan_hwaccel_put_tag() . > > This causes packets not to be passed to the VLAN slave if it was created > with 802.1AD protocol > (ip link add link eth0 eth0.100 type vlan proto 802.1ad id 100). > > This fix passes the protocol from the VLAN header into > __vlan_hwaccel_put_tag() instead of using the hard-coded value of > ETH_P_8021Q. > > NETIF_F_HW_VLAN_CTAG_RX check was removed and instead the strip action > is dependent upon a preprocessor define which is defined when 802.1Q > support is selected in the kernel config. > > NETIF_F_HW_VLAN_STAG_RX feature was added to be in line with the driver > actual abilities. > > Signed-off-by: Elad Nachman You can't remove the NETIF_F_* checks. If the user doesn't have VLAN offloading enabled, the VLAN tags should be left in the packet as-is. It can't be controlled by a CPP check.
Re: [PATCH] net: phy: dp83822: use BMCR_ANENABLE instead of BMSR_ANEGCAPABLE for DP83620
From: Alvaro Gamez Machado Date: Fri, 8 Jun 2018 12:23:39 +0200 > DP83620 register set is compatible with the DP83848, but it also supports > 100base-FX. When the hardware is configured such as that fiber mode is > enabled, autonegotiation is not possible. > > The chip, however, doesn't expose this information via BMSR_ANEGCAPABLE. > Instead, this bit is always set high, even if the particular hardware > configuration makes it so that auto negotiation is not possible [1]. Under > these circumstances, the phy subsystem keeps trying for autonegotiation to > happen, without success. > > Hereby, we inspect BMCR_ANENABLE bit after genphy_config_init, which on > reset is set to 0 when auto negotiation is disabled, and so we use this > value instead of BMSR_ANEGCAPABLE. > > [1] https://e2e.ti.com/support/interface/ethernet/f/903/p/697165/2571170 > > Signed-off-by: Alvaro Gamez Machado Applied and queued up for -stable, thanks.
Re: [Patch net] socket: close race condition between sock_close() and sockfs_setattr()
On Sun, Jun 10, 2018 at 12:27 PM, David Miller wrote: > I'm applying this for now, it is at least a step towards fixing > all of these issues. > > If it is really offensive, I can revert, just tell me. Thanks, David! Unless there is something fundamentally broken, there is no reason to revert it. The only risk here is some possible deadlock, but I am ready to fix any deadlock report caused by this patch. :)
[PATCH net] ipv6: allow PMTU exceptions to local routes
IPVS setups with local client and remote tunnel server need to create exception for the local virtual IP. What we do is to change PMTU from 64KB (on "lo") to 1460 in the common case. Suggested-by: Martin KaFai Lau Fixes: 45e4fd26683c ("ipv6: Only create RTF_CACHE routes after encountering pmtu exception") Fixes: 7343ff31ebf0 ("ipv6: Don't create clones of host routes.") Signed-off-by: Julian Anastasov --- net/ipv6/route.c | 3 --- 1 file changed, 3 deletions(-) Note: I failed to build 2.6.38 kernel for the test but I think commit 7343ff31ebf0 looks as the one that added the restriction to change PMTU for local IPs. So, I'm not sure from how long time the issue with local IPVS clients and tunnelling method exists. May be it worked between 2.6.28 and 2.6.37. diff --git a/net/ipv6/route.c b/net/ipv6/route.c index fb95698..86a0e43 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2307,9 +2307,6 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk, const struct in6_addr *daddr, *saddr; struct rt6_info *rt6 = (struct rt6_info *)dst; - if (rt6->rt6i_flags & RTF_LOCAL) - return; - if (dst_metric_locked(dst, RTAX_MTU)) return; -- 2.9.5
[PATCH net-next] vlan: implement vlan id and protocol changes
From: "Charles (Chas) Williams" vlan_changelink silently ignores attempts to change the vlan id or protocol id of an existing vlan interface. Implement by adding the new vlan id and protocol to the interface's vlan group and then removing the old vlan id and protocol from the vlan group. Signed-off-by: Chas Williams <3ch...@gmail.com> --- include/linux/netdevice.h | 1 + net/8021q/vlan.c | 4 ++-- net/8021q/vlan.h | 2 ++ net/8021q/vlan_netlink.c | 38 ++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3ec9850c7936..a95ae238addf 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2409,6 +2409,7 @@ enum netdev_cmd { NETDEV_CVLAN_FILTER_DROP_INFO, NETDEV_SVLAN_FILTER_PUSH_INFO, NETDEV_SVLAN_FILTER_DROP_INFO, + NETDEV_CHANGEVLAN, }; const char *netdev_cmd_to_name(enum netdev_cmd cmd); diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 73a65789271b..b5e0ad1a581a 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -51,8 +51,8 @@ const char vlan_version[] = DRV_VERSION; /* End of global variables definitions. */ -static int vlan_group_prealloc_vid(struct vlan_group *vg, - __be16 vlan_proto, u16 vlan_id) +int vlan_group_prealloc_vid(struct vlan_group *vg, + __be16 vlan_proto, u16 vlan_id) { struct net_device **array; unsigned int pidx, vidx; diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 44df1c3df02d..c734dd21d70d 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -116,6 +116,8 @@ int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack); void unregister_vlan_dev(struct net_device *dev, struct list_head *head); bool vlan_dev_inherit_address(struct net_device *dev, struct net_device *real_dev); +int vlan_group_prealloc_vid(struct vlan_group *vg, + __be16 vlan_proto, u16 vlan_id); static inline u32 vlan_get_ingress_priority(struct net_device *dev, u16 vlan_tci) diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index 9b60c1e399e2..0e59babe6651 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -107,10 +107,48 @@ static int vlan_changelink(struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { + struct vlan_dev_priv *vlan = vlan_dev_priv(dev); struct ifla_vlan_flags *flags; struct ifla_vlan_qos_mapping *m; struct nlattr *attr; int rem; + int err; + __be16 vlan_proto = vlan->vlan_proto; + u16 vlan_id = vlan->vlan_id; + + if (data[IFLA_VLAN_ID]) + vlan_id = nla_get_u16(data[IFLA_VLAN_ID]); + + if (data[IFLA_VLAN_PROTOCOL]) + vlan_proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]); + + if (vlan->vlan_id != vlan_id || vlan->vlan_proto != vlan_proto) { + struct net_device *real_dev = vlan->real_dev; + struct vlan_info *vlan_info; + struct vlan_group *grp; + __be16 old_vlan_proto = vlan->vlan_proto; + u16 old_vlan_id = vlan->vlan_id; + + err = vlan_vid_add(real_dev, vlan_proto, vlan_id); + if (err) + return err; + vlan_info = rtnl_dereference(real_dev->vlan_info); + grp = &vlan_info->grp; + err = vlan_group_prealloc_vid(grp, vlan_proto, vlan_id); + if (err < 0) { + vlan_vid_del(real_dev, vlan_proto, vlan_id); + return err; + } + vlan_group_set_device(grp, vlan_proto, vlan_id, dev); + vlan->vlan_proto = vlan_proto; + vlan->vlan_id = vlan_id; + + vlan_group_set_device(grp, old_vlan_proto, old_vlan_id, NULL); + vlan_vid_del(real_dev, old_vlan_proto, old_vlan_id); + + err = call_netdevice_notifiers(NETDEV_CHANGEVLAN, dev); + notifier_to_errno(err); + } if (data[IFLA_VLAN_FLAGS]) { flags = nla_data(data[IFLA_VLAN_FLAGS]); -- 2.14.3
Re: [PATCH net-next] vlan: implement vlan id and protocol changes
Hi Charles, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on net-next/master] url: https://github.com/0day-ci/linux/commits/Chas-Williams/vlan-implement-vlan-id-and-protocol-changes/20180611-072123 config: parisc-c3000_defconfig (attached as .config) compiler: hppa-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=parisc All warnings (new ones prefixed by >>): net/core/dev.c: In function 'netdev_cmd_to_name': >> net/core/dev.c:1580:2: warning: enumeration value 'NETDEV_CHANGEVLAN' not >> handled in switch [-Wswitch] switch (cmd) { ^~ vim +/NETDEV_CHANGEVLAN +1580 net/core/dev.c 56f5aa77 Michael Chan 2017-12-16 1574 ede2762d Kirill Tkhai 2018-03-23 1575 const char *netdev_cmd_to_name(enum netdev_cmd cmd) ede2762d Kirill Tkhai 2018-03-23 1576 { ede2762d Kirill Tkhai 2018-03-23 1577 #define N(val) \ ede2762d Kirill Tkhai 2018-03-23 1578 case NETDEV_##val: \ ede2762d Kirill Tkhai 2018-03-23 1579 return "NETDEV_" __stringify(val); ede2762d Kirill Tkhai 2018-03-23 @1580 switch (cmd) { ede2762d Kirill Tkhai 2018-03-23 1581 N(UP) N(DOWN) N(REBOOT) N(CHANGE) N(REGISTER) N(UNREGISTER) ede2762d Kirill Tkhai 2018-03-23 1582 N(CHANGEMTU) N(CHANGEADDR) N(GOING_DOWN) N(CHANGENAME) N(FEAT_CHANGE) ede2762d Kirill Tkhai 2018-03-23 1583 N(BONDING_FAILOVER) N(PRE_UP) N(PRE_TYPE_CHANGE) N(POST_TYPE_CHANGE) ede2762d Kirill Tkhai 2018-03-23 1584 N(POST_INIT) N(RELEASE) N(NOTIFY_PEERS) N(JOIN) N(CHANGEUPPER) ede2762d Kirill Tkhai 2018-03-23 1585 N(RESEND_IGMP) N(PRECHANGEMTU) N(CHANGEINFODATA) N(BONDING_INFO) ede2762d Kirill Tkhai 2018-03-23 1586 N(PRECHANGEUPPER) N(CHANGELOWERSTATE) N(UDP_TUNNEL_PUSH_INFO) ede2762d Kirill Tkhai 2018-03-23 1587 N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN) 9daae9bd Gal Pressman 2018-03-28 1588 N(CVLAN_FILTER_PUSH_INFO) N(CVLAN_FILTER_DROP_INFO) 9daae9bd Gal Pressman 2018-03-28 1589 N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO) 3f5ecd8a Kirill Tkhai 2018-04-26 1590 } ede2762d Kirill Tkhai 2018-03-23 1591 #undef N ede2762d Kirill Tkhai 2018-03-23 1592 return "UNKNOWN_NETDEV_EVENT"; ede2762d Kirill Tkhai 2018-03-23 1593 } ede2762d Kirill Tkhai 2018-03-23 1594 EXPORT_SYMBOL_GPL(netdev_cmd_to_name); ede2762d Kirill Tkhai 2018-03-23 1595 :: The code at line 1580 was first introduced by commit :: ede2762d93ff16e0974f7446516b46b1022db213 net: Make NETDEV_XXX commands enum { } :: TO: Kirill Tkhai :: CC: David S. Miller --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
Re: [PATCH v6 net] stmmac: strip all VLAN tag types when kernel 802.1Q support is selected
On 2018/06/11 4:29, David Miller wrote: > From: Elad Nachman > Date: Fri, 8 Jun 2018 12:19:29 +0300 > >> stmmac reception handler calls stmmac_rx_vlan() to strip the vlan before >> calling napi_gro_receive(). >> >> The function assumes VLAN tagged frames are always tagged with >> 802.1Q protocol, and assigns ETH_P_8021Q to the skb by hard-coding >> the parameter on call to __vlan_hwaccel_put_tag() . >> >> This causes packets not to be passed to the VLAN slave if it was created >> with 802.1AD protocol >> (ip link add link eth0 eth0.100 type vlan proto 802.1ad id 100). >> >> This fix passes the protocol from the VLAN header into >> __vlan_hwaccel_put_tag() instead of using the hard-coded value of >> ETH_P_8021Q. >> >> NETIF_F_HW_VLAN_CTAG_RX check was removed and instead the strip action >> is dependent upon a preprocessor define which is defined when 802.1Q >> support is selected in the kernel config. >> >> NETIF_F_HW_VLAN_STAG_RX feature was added to be in line with the driver >> actual abilities. >> >> Signed-off-by: Elad Nachman > > You can't remove the NETIF_F_* checks. > > If the user doesn't have VLAN offloading enabled, the VLAN tags should > be left in the packet as-is. > > It can't be controlled by a CPP check. David, NETIF_F_HW_VALN_*_RX is not user-controllable in this driver because hw_features does not include them. But this can break when those features are added to hw_features so if David does not like this situation I think we need the condition anyway. -- Toshiaki Makita
Re: netdevice notifier and device private data
Alexander Aring wrote: >> It totally seems like broken behaviour. Maybe it's not even >> intentional. Maybe they are just foobar. > They simple don't know what they doing... somebody thought 6LoWPAN need > to be 6LoWPAN, but they actually don't use the 6LoWPAN handling inside > the kernel. _Except_ they doing out of tree stuff which I don't > believe. So, it seems like this ioctl() should be disabled, or restricted to cases that actually work. hate to break their code, but if it's broken anyway, at least the kernel won't crash under them. > According to [0] it also works with tun default (I suppsoe raw IPv6), > because ifdef. And they should not change it because they don't use > in-kernel 6LoWPAN functionality. > I really think that this tun/tap feature makes a lot of trouble for > some type changes. I probably introduce lowpan_dev pointer to netdevice > and then check if it's really a 6LoPWAN interface, a dev->type will not > garantuee anymore you have a 6LoWPAN interface. At least in user space > it's not possible to have a check if you really have a 6LoWPAN > interface. > - Alex > [0] > https://github.com/openthread/wpantund/blob/master/src/util/tunnel.c#L180 > [1] https://github.com/reubenhwk/radvd/blob/master/device-linux.c#L75 -- Michael Richardson , Sandelman Software Works -= IPv6 IoT consulting =- signature.asc Description: PGP signature