net: add skb_frag_foreach_page and use with kmap_atomic
Subsystems (2)
From: Willem de Bruijn <[email protected]>
Skb frags may contain compound pages. Various operations map frags temporarily using kmap_atomic, but this function works on single pages, not whole compound pages. The distinction is only relevant for high mem pages that require temporary mappings.
Introduce a looping mechanism that for compound highmem pages maps one page at a time, does not change behavior on other pages. Use the loop in the kmap_atomic callers in net/core/skbuff.c.
Verified by triggering skb_copy_bits with
tcpdump -n -c 100 -i ${DEV} -w /dev/null &
netperf -t TCP_STREAM -H ${HOST} and by triggering __skb_checksum with
ethtool -K ${DEV} tx off repeated the tests with looping on a non-highmem platform (x86_64) by making skb_frag_must_loop always return true.
---
Changes
RFC -> v1: rebased only
--- include/linux/skbuff.h | 36 +++++++++++++++++++++ net/core/skbuff.c | 88 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 95 insertions(+), 29 deletions(-)
include/linux/skbuff.h +36 -0
@@ -345,6 +345,42 @@ static inline void skb_frag_size_sub(skb_frag_t *frag, int delta) frag->size -= delta; } +static inline bool skb_frag_must_loop (struct page *p) +{ +#if defined(CONFIG_HIGHMEM ) +if (PageHighMem (p)) +return true; +#endif +return false; +} + +/** +* skb_frag_foreach_page - loop over pages in a fragment +* +* @f: skb frag to operate on +* @f_off: offset from start of f->page.p +* @f_len: length from f_off to loop over +* @p: (temp var) current page +* @p_off: (temp var) offset from start of current page, +* non-zero only on first page. +* @p_len: (temp var) length in current page, +* < PAGE_SIZE only on first and last page. +* @copied: (temp var) length so far, excluding current p_len. +* +* A fragment can hold a compound page, in which case per-page +* operations, notably kmap_atomic, must be called for each +* regular page. +*/ +#define skb_frag_foreach_page (f, f_off, f_len, p, p_off, p_len, copied) \ + for (p = skb_frag_page(f) + ((f_off) >> PAGE_SHIFT), \ + p_off = (f_off) & (PAGE_SIZE - 1), \ + p_len = skb_frag_must_loop(p) ? \ + min_t(u32, f_len, PAGE_SIZE - p_off) : f_len, \ + copied = 0; \ + copied < f_len; \ + copied += p_len, p++, p_off = 0, \ + p_len = min_t(u32, f_len - copied, PAGE_SIZE)) \ +#define HAVE_HW_TIME_STAMP /**
net/core/skbuff.c +59 -29
152 lines not on this page · raw message
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
From: Willem de Bruijn <[email protected]>
Date: Mon, 31 Jul 2017 08:15:47 -0400
Quoted 16 lines
From: Willem de Bruijn <[email protected]>
Skb frags may contain compound pages. Various operations map frags temporarily using
kmap_atomic, but this function works on single pages, not whole compound pages. The distinction is only relevant for high mem pages that require temporary mappings.Introduce a looping mechanism that for compound highmem pages maps one page at a time, does not change behavior on other pages. Use the loop in the
kmap_atomiccallers innet/core/skbuff.c.Verified by triggering
skb_copy_bitswithtcpdump -n -c 100 -i ${DEV} -w /dev/null & netperf -t TCP_STREAM -H ${HOST}
Quoted 8 lines
and by triggering
__skb_checksumwithethtool -K ${DEV} tx offrepeated the tests with looping on a non-highmem platform (
x86_64) by makingskb_frag_must_loopalways return true.Signed-off-by Willem de Bruijn <[email protected]>
Ok, this looks good.
Thanks for following up on this.
Applied.