Commit bb7ffb6b authored by Paolo Abeni's avatar Paolo Abeni Committed by Greg Kroah-Hartman

net: pktgen: fix pkt_size

[ Upstream commit 63d75463 ]

The commit 879c7220 ("net: pktgen: Observe needed_headroom
of the device") increased the 'pkt_overhead' field value by
LL_RESERVED_SPACE.
As a side effect the generated packet size, computed as:

	/* Eth + IPh + UDPh + mpls */
	datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
		  pkt_dev->pkt_overhead;

is decreased by the same value.
The above changed slightly the behavior of existing pktgen users,
and made the procfs interface somewhat inconsistent.
Fix it by restoring the previous pkt_overhead value and using
LL_RESERVED_SPACE as extralen in skb allocation.
Also, change pktgen_alloc_skb() to only partially reserve
the headroom to allow the caller to prefetch from ll header
start.

v1 -> v2:
 - fixed some typos in the comments

Fixes: 879c7220 ("net: pktgen: Observe needed_headroom of the device")
Suggested-by: default avatarBen Greear <greearb@candelatech.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bc5d8ced
...@@ -2278,7 +2278,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) ...@@ -2278,7 +2278,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev) static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
{ {
pkt_dev->pkt_overhead = LL_RESERVED_SPACE(pkt_dev->odev); pkt_dev->pkt_overhead = 0;
pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32); pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32);
pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev); pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev);
pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev); pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev);
...@@ -2769,13 +2769,13 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb, ...@@ -2769,13 +2769,13 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb,
} }
static struct sk_buff *pktgen_alloc_skb(struct net_device *dev, static struct sk_buff *pktgen_alloc_skb(struct net_device *dev,
struct pktgen_dev *pkt_dev, struct pktgen_dev *pkt_dev)
unsigned int extralen)
{ {
unsigned int extralen = LL_RESERVED_SPACE(dev);
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
unsigned int size = pkt_dev->cur_pkt_size + 64 + extralen + unsigned int size;
pkt_dev->pkt_overhead;
size = pkt_dev->cur_pkt_size + 64 + extralen + pkt_dev->pkt_overhead;
if (pkt_dev->flags & F_NODE) { if (pkt_dev->flags & F_NODE) {
int node = pkt_dev->node >= 0 ? pkt_dev->node : numa_node_id(); int node = pkt_dev->node >= 0 ? pkt_dev->node : numa_node_id();
...@@ -2788,8 +2788,9 @@ static struct sk_buff *pktgen_alloc_skb(struct net_device *dev, ...@@ -2788,8 +2788,9 @@ static struct sk_buff *pktgen_alloc_skb(struct net_device *dev,
skb = __netdev_alloc_skb(dev, size, GFP_NOWAIT); skb = __netdev_alloc_skb(dev, size, GFP_NOWAIT);
} }
/* the caller pre-fetches from skb->data and reserves for the mac hdr */
if (likely(skb)) if (likely(skb))
skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reserve(skb, extralen - 16);
return skb; return skb;
} }
...@@ -2822,16 +2823,14 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev, ...@@ -2822,16 +2823,14 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
mod_cur_headers(pkt_dev); mod_cur_headers(pkt_dev);
queue_map = pkt_dev->cur_queue_map; queue_map = pkt_dev->cur_queue_map;
datalen = (odev->hard_header_len + 16) & ~0xf; skb = pktgen_alloc_skb(odev, pkt_dev);
skb = pktgen_alloc_skb(odev, pkt_dev, datalen);
if (!skb) { if (!skb) {
sprintf(pkt_dev->result, "No memory"); sprintf(pkt_dev->result, "No memory");
return NULL; return NULL;
} }
prefetchw(skb->data); prefetchw(skb->data);
skb_reserve(skb, datalen); skb_reserve(skb, 16);
/* Reserve for ethernet and IP header */ /* Reserve for ethernet and IP header */
eth = (__u8 *) skb_push(skb, 14); eth = (__u8 *) skb_push(skb, 14);
...@@ -2951,7 +2950,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev, ...@@ -2951,7 +2950,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
mod_cur_headers(pkt_dev); mod_cur_headers(pkt_dev);
queue_map = pkt_dev->cur_queue_map; queue_map = pkt_dev->cur_queue_map;
skb = pktgen_alloc_skb(odev, pkt_dev, 16); skb = pktgen_alloc_skb(odev, pkt_dev);
if (!skb) { if (!skb) {
sprintf(pkt_dev->result, "No memory"); sprintf(pkt_dev->result, "No memory");
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment