Skip to content

Commit ecb2cf1

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull networking fixes from David Miller: "A couple interesting SKB fragment handling fixes, plus the usual small bits here and there: 1) Fix 64-bit divide build failure on 32-bit platforms in mlx5, from Tim Gardner. 2) Get rid of a stupid reimplementation on "%*phC" in our sysfs MAC address printing helper. 3) Fix NETIF_F_SG capability advertisement in hyperv driver, if the device can't do checksumming offloads then it shouldn't say it can do SG either. From Haiyang Zhang. 4) bgmac needs to depend on PHYLIB, from Hauke Mehrtens. 5) Don't leak DMA mappings on mapping failures, from Neil Horman. 6) We need to reset the transport header of SKBs in ipv4 before we attempt to perform early socket demux, just like ipv6 does. From Eric Dumazet. 7) Add missing locking on vxlan device removal, from Stephen Hemminger. 8) xen-netfront has to make two passes over an SKB to prepare it for transfer. One pass calculates the number of slots needed, the second massages the SKB and fills the slots. Unfortunately, the first pass doesn't calculate the number of slots properly so we can end up trying to build a MAX_SKB_FRAGS + 1 SKB which doesn't work out so well. Fix from Jan Beulich with help and discussion with several others. 9) Fix a similar problem in tun and macvtap, which have to split up scatter-gather elements at PAGE_SIZE boundaries. Don't do zerocopy if it would result in a > MAX_SKB_FRAGS skb. Fixes from Jason Wang. 10) On receive, once we've decoded the VLAN state completely, clear skb->vlan_tci. Otherwise demuxed tunnels underneath can trigger the VLAN code again, corrupting the packet. Fix from Eric Dumazet" * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: vlan: fix a race in egress prio management vlan: mask vlan prio bits macvtap: do not zerocopy if iov needs more pages than MAX_SKB_FRAGS tuntap: do not zerocopy if iov needs more pages than MAX_SKB_FRAGS pkt_sched: sch_qfq: remove a source of high packet delay/jitter xen-netfront: pull on receive skb may need to happen earlier vxlan: add necessary locking on device removal hyperv: Fix the NETIF_F_SG flag setting in netvsc net: Fix sysfs_format_mac() code duplication. be2net: Fix to avoid hardware workaround when not needed macvtap: do not assume 802.1Q when send vlan packets macvtap: fix the missing ret value of TUNSETQUEUE ipv4: set transport header earlier mlx5 core: Fix __udivdi3 when compiling for 32 bit arches bgmac: add dependency to phylib net/irda: fixed style issues in irlan_eth ethtool: fixed trailing statements in ethtool ndisc: bool initializations should use true and false atl1e: unmap partially mapped skb on dma error and free skb
2 parents ee114b9 + 3e3aac4 commit ecb2cf1

File tree

19 files changed

+248
-164
lines changed

19 files changed

+248
-164
lines changed

drivers/net/ethernet/atheros/atl1e/atl1e_main.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,7 @@ static int atl1e_tx_map(struct atl1e_adapter *adapter,
16781678
u16 f;
16791679
int segment;
16801680
int ring_start = adapter->tx_ring.next_to_use;
1681+
int ring_end;
16811682

16821683
nr_frags = skb_shinfo(skb)->nr_frags;
16831684
segment = (tpd->word3 >> TPD_SEGMENT_EN_SHIFT) & TPD_SEGMENT_EN_MASK;
@@ -1721,6 +1722,15 @@ static int atl1e_tx_map(struct atl1e_adapter *adapter,
17211722
map_len, PCI_DMA_TODEVICE);
17221723

17231724
if (dma_mapping_error(&adapter->pdev->dev, tx_buffer->dma)) {
1725+
/* We need to unwind the mappings we've done */
1726+
ring_end = adapter->tx_ring.next_to_use;
1727+
adapter->tx_ring.next_to_use = ring_start;
1728+
while (adapter->tx_ring.next_to_use != ring_end) {
1729+
tpd = atl1e_get_tpd(adapter);
1730+
tx_buffer = atl1e_get_tx_buffer(adapter, tpd);
1731+
pci_unmap_single(adapter->pdev, tx_buffer->dma,
1732+
tx_buffer->length, PCI_DMA_TODEVICE);
1733+
}
17241734
/* Reset the tx rings next pointer */
17251735
adapter->tx_ring.next_to_use = ring_start;
17261736
return -ENOSPC;
@@ -1763,6 +1773,16 @@ static int atl1e_tx_map(struct atl1e_adapter *adapter,
17631773
DMA_TO_DEVICE);
17641774

17651775
if (dma_mapping_error(&adapter->pdev->dev, tx_buffer->dma)) {
1776+
/* We need to unwind the mappings we've done */
1777+
ring_end = adapter->tx_ring.next_to_use;
1778+
adapter->tx_ring.next_to_use = ring_start;
1779+
while (adapter->tx_ring.next_to_use != ring_end) {
1780+
tpd = atl1e_get_tpd(adapter);
1781+
tx_buffer = atl1e_get_tx_buffer(adapter, tpd);
1782+
dma_unmap_page(&adapter->pdev->dev, tx_buffer->dma,
1783+
tx_buffer->length, DMA_TO_DEVICE);
1784+
}
1785+
17661786
/* Reset the ring next to use pointer */
17671787
adapter->tx_ring.next_to_use = ring_start;
17681788
return -ENOSPC;
@@ -1853,8 +1873,10 @@ static netdev_tx_t atl1e_xmit_frame(struct sk_buff *skb,
18531873
return NETDEV_TX_OK;
18541874
}
18551875

1856-
if (atl1e_tx_map(adapter, skb, tpd))
1876+
if (atl1e_tx_map(adapter, skb, tpd)) {
1877+
dev_kfree_skb_any(skb);
18571878
goto out;
1879+
}
18581880

18591881
atl1e_tx_queue(adapter, tpd_req, tpd);
18601882

drivers/net/ethernet/broadcom/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ config BNX2X_SRIOV
131131
config BGMAC
132132
tristate "BCMA bus GBit core support"
133133
depends on BCMA_HOST_SOC && HAS_DMA
134+
select PHYLIB
134135
---help---
135136
This driver supports GBit MAC and BCM4706 GBit MAC cores on BCMA bus.
136137
They can be found on BCM47xx SoCs and provide gigabit ethernet.

drivers/net/ethernet/emulex/benet/be_main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,22 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
782782

783783
if (vlan_tx_tag_present(skb))
784784
vlan_tag = be_get_tx_vlan_tag(adapter, skb);
785-
else if (qnq_async_evt_rcvd(adapter) && adapter->pvid)
786-
vlan_tag = adapter->pvid;
785+
786+
if (qnq_async_evt_rcvd(adapter) && adapter->pvid) {
787+
if (!vlan_tag)
788+
vlan_tag = adapter->pvid;
789+
/* f/w workaround to set skip_hw_vlan = 1, informs the F/W to
790+
* skip VLAN insertion
791+
*/
792+
if (skip_hw_vlan)
793+
*skip_hw_vlan = true;
794+
}
787795

788796
if (vlan_tag) {
789797
skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
790798
if (unlikely(!skb))
791799
return skb;
792800
skb->vlan_tci = 0;
793-
if (skip_hw_vlan)
794-
*skip_hw_vlan = true;
795801
}
796802

797803
/* Insert the outer VLAN, if any */

drivers/net/ethernet/mellanox/mlx5/core/debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
156156
stats = filp->private_data;
157157
spin_lock(&stats->lock);
158158
if (stats->n)
159-
field = stats->sum / stats->n;
159+
field = div64_u64(stats->sum, stats->n);
160160
spin_unlock(&stats->lock);
161161
ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
162162
if (ret > 0) {

drivers/net/hyperv/netvsc_drv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ static int netvsc_probe(struct hv_device *dev,
431431
net->netdev_ops = &device_ops;
432432

433433
/* TODO: Add GSO and Checksum offload */
434-
net->hw_features = NETIF_F_SG;
435-
net->features = NETIF_F_SG | NETIF_F_HW_VLAN_CTAG_TX;
434+
net->hw_features = 0;
435+
net->features = NETIF_F_HW_VLAN_CTAG_TX;
436436

437437
SET_ETHTOOL_OPS(net, &ethtool_ops);
438438
SET_NETDEV_DEV(net, &dev->device);

drivers/net/macvtap.c

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,28 @@ static int macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
698698
return 0;
699699
}
700700

701+
static unsigned long iov_pages(const struct iovec *iv, int offset,
702+
unsigned long nr_segs)
703+
{
704+
unsigned long seg, base;
705+
int pages = 0, len, size;
706+
707+
while (nr_segs && (offset >= iv->iov_len)) {
708+
offset -= iv->iov_len;
709+
++iv;
710+
--nr_segs;
711+
}
712+
713+
for (seg = 0; seg < nr_segs; seg++) {
714+
base = (unsigned long)iv[seg].iov_base + offset;
715+
len = iv[seg].iov_len - offset;
716+
size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
717+
pages += size;
718+
offset = 0;
719+
}
720+
721+
return pages;
722+
}
701723

702724
/* Get packet from user space buffer */
703725
static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
@@ -744,31 +766,15 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
744766
if (unlikely(count > UIO_MAXIOV))
745767
goto err;
746768

747-
if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY))
748-
zerocopy = true;
749-
750-
if (zerocopy) {
751-
/* Userspace may produce vectors with count greater than
752-
* MAX_SKB_FRAGS, so we need to linearize parts of the skb
753-
* to let the rest of data to be fit in the frags.
754-
*/
755-
if (count > MAX_SKB_FRAGS) {
756-
copylen = iov_length(iv, count - MAX_SKB_FRAGS);
757-
if (copylen < vnet_hdr_len)
758-
copylen = 0;
759-
else
760-
copylen -= vnet_hdr_len;
761-
}
762-
/* There are 256 bytes to be copied in skb, so there is enough
763-
* room for skb expand head in case it is used.
764-
* The rest buffer is mapped from userspace.
765-
*/
766-
if (copylen < vnet_hdr.hdr_len)
767-
copylen = vnet_hdr.hdr_len;
768-
if (!copylen)
769-
copylen = GOODCOPY_LEN;
769+
if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
770+
copylen = vnet_hdr.hdr_len ? vnet_hdr.hdr_len : GOODCOPY_LEN;
770771
linear = copylen;
771-
} else {
772+
if (iov_pages(iv, vnet_hdr_len + copylen, count)
773+
<= MAX_SKB_FRAGS)
774+
zerocopy = true;
775+
}
776+
777+
if (!zerocopy) {
772778
copylen = len;
773779
linear = vnet_hdr.hdr_len;
774780
}
@@ -780,9 +786,15 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
780786

781787
if (zerocopy)
782788
err = zerocopy_sg_from_iovec(skb, iv, vnet_hdr_len, count);
783-
else
789+
else {
784790
err = skb_copy_datagram_from_iovec(skb, 0, iv, vnet_hdr_len,
785791
len);
792+
if (!err && m && m->msg_control) {
793+
struct ubuf_info *uarg = m->msg_control;
794+
uarg->callback(uarg, false);
795+
}
796+
}
797+
786798
if (err)
787799
goto err_kfree;
788800

@@ -873,7 +885,7 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
873885
__be16 h_vlan_proto;
874886
__be16 h_vlan_TCI;
875887
} veth;
876-
veth.h_vlan_proto = htons(ETH_P_8021Q);
888+
veth.h_vlan_proto = skb->vlan_proto;
877889
veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb));
878890

879891
vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
@@ -1107,6 +1119,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
11071119
rtnl_lock();
11081120
ret = macvtap_ioctl_set_queue(file, u);
11091121
rtnl_unlock();
1122+
return ret;
11101123

11111124
case TUNGETFEATURES:
11121125
if (put_user(IFF_TAP | IFF_NO_PI | IFF_VNET_HDR |

drivers/net/tun.c

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,29 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
10351035
return 0;
10361036
}
10371037

1038+
static unsigned long iov_pages(const struct iovec *iv, int offset,
1039+
unsigned long nr_segs)
1040+
{
1041+
unsigned long seg, base;
1042+
int pages = 0, len, size;
1043+
1044+
while (nr_segs && (offset >= iv->iov_len)) {
1045+
offset -= iv->iov_len;
1046+
++iv;
1047+
--nr_segs;
1048+
}
1049+
1050+
for (seg = 0; seg < nr_segs; seg++) {
1051+
base = (unsigned long)iv[seg].iov_base + offset;
1052+
len = iv[seg].iov_len - offset;
1053+
size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
1054+
pages += size;
1055+
offset = 0;
1056+
}
1057+
1058+
return pages;
1059+
}
1060+
10381061
/* Get packet from user space buffer */
10391062
static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
10401063
void *msg_control, const struct iovec *iv,
@@ -1082,32 +1105,18 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
10821105
return -EINVAL;
10831106
}
10841107

1085-
if (msg_control)
1086-
zerocopy = true;
1087-
1088-
if (zerocopy) {
1089-
/* Userspace may produce vectors with count greater than
1090-
* MAX_SKB_FRAGS, so we need to linearize parts of the skb
1091-
* to let the rest of data to be fit in the frags.
1092-
*/
1093-
if (count > MAX_SKB_FRAGS) {
1094-
copylen = iov_length(iv, count - MAX_SKB_FRAGS);
1095-
if (copylen < offset)
1096-
copylen = 0;
1097-
else
1098-
copylen -= offset;
1099-
} else
1100-
copylen = 0;
1101-
/* There are 256 bytes to be copied in skb, so there is enough
1102-
* room for skb expand head in case it is used.
1108+
if (msg_control) {
1109+
/* There are 256 bytes to be copied in skb, so there is
1110+
* enough room for skb expand head in case it is used.
11031111
* The rest of the buffer is mapped from userspace.
11041112
*/
1105-
if (copylen < gso.hdr_len)
1106-
copylen = gso.hdr_len;
1107-
if (!copylen)
1108-
copylen = GOODCOPY_LEN;
1113+
copylen = gso.hdr_len ? gso.hdr_len : GOODCOPY_LEN;
11091114
linear = copylen;
1110-
} else {
1115+
if (iov_pages(iv, offset + copylen, count) <= MAX_SKB_FRAGS)
1116+
zerocopy = true;
1117+
}
1118+
1119+
if (!zerocopy) {
11111120
copylen = len;
11121121
linear = gso.hdr_len;
11131122
}
@@ -1121,8 +1130,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11211130

11221131
if (zerocopy)
11231132
err = zerocopy_sg_from_iovec(skb, iv, offset, count);
1124-
else
1133+
else {
11251134
err = skb_copy_datagram_from_iovec(skb, 0, iv, offset, len);
1135+
if (!err && msg_control) {
1136+
struct ubuf_info *uarg = msg_control;
1137+
uarg->callback(uarg, false);
1138+
}
1139+
}
11261140

11271141
if (err) {
11281142
tun->dev->stats.rx_dropped++;

drivers/net/vxlan.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,9 +1767,15 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
17671767

17681768
static void vxlan_dellink(struct net_device *dev, struct list_head *head)
17691769
{
1770+
struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
17701771
struct vxlan_dev *vxlan = netdev_priv(dev);
17711772

1773+
flush_workqueue(vxlan_wq);
1774+
1775+
spin_lock(&vn->sock_lock);
17721776
hlist_del_rcu(&vxlan->hlist);
1777+
spin_unlock(&vn->sock_lock);
1778+
17731779
list_del(&vxlan->next);
17741780
unregister_netdevice_queue(dev, head);
17751781
}

drivers/net/xen-netfront.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ static void xennet_alloc_rx_buffers(struct net_device *dev)
286286
break;
287287
}
288288

289-
__skb_fill_page_desc(skb, 0, page, 0, 0);
290-
skb_shinfo(skb)->nr_frags = 1;
289+
skb_add_rx_frag(skb, 0, page, 0, 0, PAGE_SIZE);
291290
__skb_queue_tail(&np->rx_batch, skb);
292291
}
293292

@@ -831,7 +830,6 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,
831830
struct sk_buff_head *list)
832831
{
833832
struct skb_shared_info *shinfo = skb_shinfo(skb);
834-
int nr_frags = shinfo->nr_frags;
835833
RING_IDX cons = np->rx.rsp_cons;
836834
struct sk_buff *nskb;
837835

@@ -840,19 +838,21 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,
840838
RING_GET_RESPONSE(&np->rx, ++cons);
841839
skb_frag_t *nfrag = &skb_shinfo(nskb)->frags[0];
842840

843-
__skb_fill_page_desc(skb, nr_frags,
844-
skb_frag_page(nfrag),
845-
rx->offset, rx->status);
841+
if (shinfo->nr_frags == MAX_SKB_FRAGS) {
842+
unsigned int pull_to = NETFRONT_SKB_CB(skb)->pull_to;
846843

847-
skb->data_len += rx->status;
844+
BUG_ON(pull_to <= skb_headlen(skb));
845+
__pskb_pull_tail(skb, pull_to - skb_headlen(skb));
846+
}
847+
BUG_ON(shinfo->nr_frags >= MAX_SKB_FRAGS);
848+
849+
skb_add_rx_frag(skb, shinfo->nr_frags, skb_frag_page(nfrag),
850+
rx->offset, rx->status, PAGE_SIZE);
848851

849852
skb_shinfo(nskb)->nr_frags = 0;
850853
kfree_skb(nskb);
851-
852-
nr_frags++;
853854
}
854855

855-
shinfo->nr_frags = nr_frags;
856856
return cons;
857857
}
858858

@@ -933,7 +933,8 @@ static int handle_incoming_queue(struct net_device *dev,
933933
while ((skb = __skb_dequeue(rxq)) != NULL) {
934934
int pull_to = NETFRONT_SKB_CB(skb)->pull_to;
935935

936-
__pskb_pull_tail(skb, pull_to - skb_headlen(skb));
936+
if (pull_to > skb_headlen(skb))
937+
__pskb_pull_tail(skb, pull_to - skb_headlen(skb));
937938

938939
/* Ethernet work: Delayed to here as it peeks the header. */
939940
skb->protocol = eth_type_trans(skb, dev);
@@ -1019,16 +1020,10 @@ static int xennet_poll(struct napi_struct *napi, int budget)
10191020
skb_shinfo(skb)->frags[0].page_offset = rx->offset;
10201021
skb_frag_size_set(&skb_shinfo(skb)->frags[0], rx->status);
10211022
skb->data_len = rx->status;
1023+
skb->len += rx->status;
10221024

10231025
i = xennet_fill_frags(np, skb, &tmpq);
10241026

1025-
/*
1026-
* Truesize is the actual allocation size, even if the
1027-
* allocation is only partially used.
1028-
*/
1029-
skb->truesize += PAGE_SIZE * skb_shinfo(skb)->nr_frags;
1030-
skb->len += skb->data_len;
1031-
10321027
if (rx->flags & XEN_NETRXF_csum_blank)
10331028
skb->ip_summed = CHECKSUM_PARTIAL;
10341029
else if (rx->flags & XEN_NETRXF_data_validated)

include/linux/if_vlan.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ static inline int is_vlan_dev(struct net_device *dev)
7979
}
8080

8181
#define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT)
82-
#define vlan_tx_nonzero_tag_present(__skb) \
83-
(vlan_tx_tag_present(__skb) && ((__skb)->vlan_tci & VLAN_VID_MASK))
8482
#define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT)
83+
#define vlan_tx_tag_get_id(__skb) ((__skb)->vlan_tci & VLAN_VID_MASK)
8584

8685
#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
8786

0 commit comments

Comments
 (0)