Skip to content

Commit ec47ea8

Browse files
Alexander Duyckdavem330
authored andcommitted
skb: Add inline helper for getting the skb end offset from head
With the recent changes for how we compute the skb truesize it occurs to me we are probably going to have a lot of calls to skb_end_pointer - skb->head. Instead of running all over the place doing that it would make more sense to just make it a separate inline skb_end_offset(skb) that way we can return the correct value without having gcc having to do all the optimization to cancel out skb->head - skb->head. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3e24591 commit ec47ea8

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

drivers/atm/ambassador.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ static void fill_rx_pool (amb_dev * dev, unsigned char pool,
802802
}
803803
// cast needed as there is no %? for pointer differences
804804
PRINTD (DBG_SKB, "allocated skb at %p, head %p, area %li",
805-
skb, skb->head, (long) (skb_end_pointer(skb) - skb->head));
805+
skb, skb->head, (long) skb_end_offset(skb));
806806
rx.handle = virt_to_bus (skb);
807807
rx.host_address = cpu_to_be32 (virt_to_bus (skb->data));
808808
if (rx_give (dev, &rx, pool))

drivers/atm/idt77252.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
12581258
tail = readl(SAR_REG_RAWCT);
12591259

12601260
pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(queue),
1261-
skb_end_pointer(queue) - queue->head - 16,
1261+
skb_end_offset(queue) - 16,
12621262
PCI_DMA_FROMDEVICE);
12631263

12641264
while (head != tail) {

drivers/net/wimax/i2400m/usb-rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct sk_buff *i2400mu_rx(struct i2400mu *i2400mu, struct sk_buff *rx_skb)
277277
d_printf(1, dev, "RX: size changed to %d, received %d, "
278278
"copied %d, capacity %ld\n",
279279
rx_size, read_size, rx_skb->len,
280-
(long) (skb_end_pointer(new_skb) - new_skb->head));
280+
(long) skb_end_offset(new_skb));
281281
goto retry;
282282
}
283283
/* In most cases, it happens due to the hardware scheduling a

drivers/staging/octeon/ethernet-tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
344344
}
345345
if (unlikely
346346
(skb->truesize !=
347-
sizeof(*skb) + skb_end_pointer(skb) - skb->head)) {
347+
sizeof(*skb) + skb_end_offset(skb))) {
348348
/*
349349
printk("TX buffer truesize has been changed\n");
350350
*/

include/linux/skbuff.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,21 @@ static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
645645
{
646646
return skb->head + skb->end;
647647
}
648+
649+
static inline unsigned int skb_end_offset(const struct sk_buff *skb)
650+
{
651+
return skb->end;
652+
}
648653
#else
649654
static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
650655
{
651656
return skb->end;
652657
}
658+
659+
static inline unsigned int skb_end_offset(const struct sk_buff *skb)
660+
{
661+
return skb->end - skb->head;
662+
}
653663
#endif
654664

655665
/* Internal */
@@ -2558,7 +2568,7 @@ static inline bool skb_is_recycleable(const struct sk_buff *skb, int skb_size)
25582568
return false;
25592569

25602570
skb_size = SKB_DATA_ALIGN(skb_size + NET_SKB_PAD);
2561-
if (skb_end_pointer(skb) - skb->head < skb_size)
2571+
if (skb_end_offset(skb) < skb_size)
25622572
return false;
25632573

25642574
if (skb_shared(skb) || skb_cloned(skb))

net/core/skbuff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
829829
struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
830830
{
831831
int headerlen = skb_headroom(skb);
832-
unsigned int size = (skb_end_pointer(skb) - skb->head) + skb->data_len;
832+
unsigned int size = skb_end_offset(skb) + skb->data_len;
833833
struct sk_buff *n = alloc_skb(size, gfp_mask);
834834

835835
if (!n)
@@ -930,7 +930,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
930930
{
931931
int i;
932932
u8 *data;
933-
int size = nhead + (skb_end_pointer(skb) - skb->head) + ntail;
933+
int size = nhead + skb_end_offset(skb) + ntail;
934934
long off;
935935

936936
BUG_ON(nhead < 0);
@@ -2727,14 +2727,13 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
27272727
if (unlikely(!nskb))
27282728
goto err;
27292729

2730-
hsize = skb_end_pointer(nskb) - nskb->head;
2730+
hsize = skb_end_offset(nskb);
27312731
if (skb_cow_head(nskb, doffset + headroom)) {
27322732
kfree_skb(nskb);
27332733
goto err;
27342734
}
27352735

2736-
nskb->truesize += skb_end_pointer(nskb) - nskb->head -
2737-
hsize;
2736+
nskb->truesize += skb_end_offset(nskb) - hsize;
27382737
skb_release_head_state(nskb);
27392738
__skb_push(nskb, doffset);
27402739
} else {
@@ -2883,7 +2882,8 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb)
28832882
skb_frag_size_sub(frag, offset);
28842883

28852884
/* all fragments truesize : remove (head size + sk_buff) */
2886-
delta_truesize = skb->truesize - SKB_TRUESIZE(skb_end_pointer(skb) - skb->head);
2885+
delta_truesize = skb->truesize -
2886+
SKB_TRUESIZE(skb_end_offset(skb));
28872887

28882888
skb->truesize -= skb->data_len;
28892889
skb->len -= skb->data_len;

0 commit comments

Comments
 (0)