Skip to content

Commit 2641363

Browse files
wdebruijgregkh
authored andcommitted
esp: avoid unneeded kmap_atomic call
[ Upstream commit 9bd6b62 ] esp(6)_output_head uses skb_page_frag_refill to allocate a buffer for the esp trailer. It accesses the page with kmap_atomic to handle highmem. But skb_page_frag_refill can return compound pages, of which kmap_atomic only maps the first underlying page. skb_page_frag_refill does not return highmem, because flag __GFP_HIGHMEM is not set. ESP uses it in the same manner as TCP. That also does not call kmap_atomic, but directly uses page_address, in skb_copy_to_page_nocache. Do the same for ESP. This issue has become easier to trigger with recent kmap local debugging feature CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP. Fixes: cac2661 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30 ("esp6: Avoid skb_cow_data whenever possible") Signed-off-by: Willem de Bruijn <[email protected]> Acked-by: Steffen Klassert <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3c64191 commit 2641363

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

net/ipv4/esp4.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ static int esp_output_encap(struct xfrm_state *x, struct sk_buff *skb,
443443
int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
444444
{
445445
u8 *tail;
446-
u8 *vaddr;
447446
int nfrags;
448447
int esph_offset;
449448
struct page *page;
@@ -485,14 +484,10 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
485484
page = pfrag->page;
486485
get_page(page);
487486

488-
vaddr = kmap_atomic(page);
489-
490-
tail = vaddr + pfrag->offset;
487+
tail = page_address(page) + pfrag->offset;
491488

492489
esp_output_fill_trailer(tail, esp->tfclen, esp->plen, esp->proto);
493490

494-
kunmap_atomic(vaddr);
495-
496491
nfrags = skb_shinfo(skb)->nr_frags;
497492

498493
__skb_fill_page_desc(skb, nfrags, page, pfrag->offset,

net/ipv6/esp6.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ static int esp6_output_encap(struct xfrm_state *x, struct sk_buff *skb,
478478
int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
479479
{
480480
u8 *tail;
481-
u8 *vaddr;
482481
int nfrags;
483482
int esph_offset;
484483
struct page *page;
@@ -519,14 +518,10 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
519518
page = pfrag->page;
520519
get_page(page);
521520

522-
vaddr = kmap_atomic(page);
523-
524-
tail = vaddr + pfrag->offset;
521+
tail = page_address(page) + pfrag->offset;
525522

526523
esp_output_fill_trailer(tail, esp->tfclen, esp->plen, esp->proto);
527524

528-
kunmap_atomic(vaddr);
529-
530525
nfrags = skb_shinfo(skb)->nr_frags;
531526

532527
__skb_fill_page_desc(skb, nfrags, page, pfrag->offset,

0 commit comments

Comments
 (0)