From patchwork Sat Jan 9 22:18:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12008769 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B86AC433DB for ; Sat, 9 Jan 2021 22:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 352A1216C4 for ; Sat, 9 Jan 2021 22:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbhAIWT1 (ORCPT ); Sat, 9 Jan 2021 17:19:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbhAIWT0 (ORCPT ); Sat, 9 Jan 2021 17:19:26 -0500 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 912FFC06179F for ; Sat, 9 Jan 2021 14:18:46 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id u12so14272828ilv.3 for ; Sat, 09 Jan 2021 14:18:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zX1KVOpyBappsSnNg0k+iRQDKdP/WgwvzGOnOf5giSM=; b=BGeq7W03A8lmjZg8XncyX650Lto6RshxdOPe1f53P4/zfNFGSOlVKut6tCBo7dzDfm TqFVS/snbOXB2xvRfKfb3KqrbKEPJD+1Weq4LVTbiYcYb2Y+1Vb6SfZ5O6ESa7+MOlcu Hblo5P4w+67sJtPsmkiVpJlP/bdlWlJ0eC38u+abt0tRo3hwVUUbyFXzl3/qSmFlJKty l/zBNO/1dRM7dB1nNqCsVjXFSUr1v1fzXkOrR/M8uexau4N4g4ajIoehvzcm+zPmWM4F l+yHllR39ohGBMhkgvVQWESE9MYLt45CTl6miRBiS+jE4l98n+PnmzOYtFyngdGP3ROB VV0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zX1KVOpyBappsSnNg0k+iRQDKdP/WgwvzGOnOf5giSM=; b=YS3Vk98akiOAztpk5xyRrQLBM3CKiDXge4kNOhFIFgsI1FJDcK5DnFc/GdUYtXT3lX hmET/zSfUtsprg8YDAVcyqTDFIuMPdfuEKF0EwYUD5dRbECu+PEhFJWh/3z0QLGtysEL 67X4QH7TSTCAh1SlFcDqn14Ikm3jPyEXSHZANheZe91QtKw6H9aOjzSfSKfxUwih4OHU hgVTCyMfy6TdtSBFR8L7Gl1tpWPmNd9kvYCAwCn+CvTt4sHG+ondssZiGV5qSOQ2ZjKm eDzYGdiN2WwadGlvjm1/Fl9AQnsOF8qlIXaUdHrzvQVDf55+LgG23lGhFpgea8eo49Z0 0CRQ== X-Gm-Message-State: AOAM530mVDQfruyJpCsS73oZi71LOQLi5UoImbCQtaaTjLnCirvQxsOw P1+U4t+eCtSiGTjtRuZMhIrwX+JxfY4= X-Google-Smtp-Source: ABdhPJySX5220PoPVLXNVuNwllS29zPrjdv+r6BpQty3pvNzngqOVJs+3l//ekcsg1AnV0mdlhWiog== X-Received: by 2002:a05:6e02:18c9:: with SMTP id s9mr8357636ilu.265.1610230725722; Sat, 09 Jan 2021 14:18:45 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f693:9fff:fef4:3e8a]) by smtp.gmail.com with ESMTPSA id i27sm11415849ill.45.2021.01.09.14.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 14:18:45 -0800 (PST) From: Willem de Bruijn To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, Willem de Bruijn , Steven Rostedt , Linus Torvalds Subject: [PATCH net v2 1/3] net: support kmap_local forced debugging in skb_frag_foreach Date: Sat, 9 Jan 2021 17:18:32 -0500 Message-Id: <20210109221834.3459768-2-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210109221834.3459768-1-willemdebruijn.kernel@gmail.com> References: <20210109221834.3459768-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Willem de Bruijn Skb frags may be backed by highmem and/or compound pages. Highmem pages need kmap_atomic mappings to access. But kmap_atomic maps a single page, not the entire compound page. skb_foreach_page iterates over an skb frag, in one step in the common case, page by page only if kmap_atomic must be called for each page. The decision logic is captured in skb_frag_must_loop. CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP extends kmap from highmem to all pages, to increase code coverage. Extend skb_frag_must_loop to this new condition. Link: https://lore.kernel.org/linux-mm/20210106180132.41dc249d@gandalf.local.home/ Fixes: 0e91a0c6984c ("mm/highmem: Provide CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP") Reported-by: Steven Rostedt (VMware) Signed-off-by: Linus Torvalds Signed-off-by: Willem de Bruijn Tested-by: Steven Rostedt (VMware) --- include/linux/skbuff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 333bcdc39635..c858adfb5a82 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -366,7 +366,7 @@ static inline void skb_frag_size_sub(skb_frag_t *frag, int delta) static inline bool skb_frag_must_loop(struct page *p) { #if defined(CONFIG_HIGHMEM) - if (PageHighMem(p)) + if (IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) || PageHighMem(p)) return true; #endif return false; From patchwork Sat Jan 9 22:18:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12008771 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34B48C433E0 for ; Sat, 9 Jan 2021 22:19:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 061B0216C4 for ; Sat, 9 Jan 2021 22:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726283AbhAIWT3 (ORCPT ); Sat, 9 Jan 2021 17:19:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbhAIWT2 (ORCPT ); Sat, 9 Jan 2021 17:19:28 -0500 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A8E7C0617A2 for ; Sat, 9 Jan 2021 14:18:48 -0800 (PST) Received: by mail-il1-x12d.google.com with SMTP id x15so14320216ilq.1 for ; Sat, 09 Jan 2021 14:18:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3CCmCAKZ5+FY+7iiUxor4VqeVOkqFmzZ5x3D/T4EjIs=; b=a5eeRNKr6nCehkbKGg2NtnTDFLZkz2+a/SOZ9tYIclQy6+TfwzQoReExrDcv4W+B7y 8ehBod2KCKBn8LvywMlQCEi8KrPWJ7cOTDWUIDxIgCmxMdmjtwYhgNP11dFyUsGw011Q KTtloQVGIovFm6+eiMxYDKPlfqh1YM4Efl2tIoNlftCBOFGON8E/FgS6KS6zfiz9em0j C56tT6pWurjWi+794hBvHTNlFjkDdP9S+VUQmzmU/l6iX/ni31u+kGpayI2PL1on5xAX HtN9P/E6VZ4DH2WSkR7A0REdI6onbl6Ogw2BJ0B6BO6h292y6h7gPqHg+4ZLkDgnZDxV 0AMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3CCmCAKZ5+FY+7iiUxor4VqeVOkqFmzZ5x3D/T4EjIs=; b=sCdE5h4Y+cp+cW92WEP4OAXfOmxth162N0b9YN1/8RDd2nzf3EeQip3a5Ar+C7fajg ez8YaUcLOE7ESQ9xXz9tQyJbrbO2cd5R2+6fZJ7RZHKsYa2QIr50hk8MwUsLKORNgm3V Otc5wJvtr0vxCaVJ9lHJJxMuqBECc5XEtrolnk8VoLhl3+hBg3eDmB/Y7Zf+lxcdigXy dTDAnBWhRnpLKlQpueBsfJ0wt18JU6dfbIHZLwWUzxMXyAaCzSOJdg1rIdfjHlJcnZDt 0JI83AXOxxKF43+JsPbuy4VAvIM69+zL7ly+tZaFkJC52o0Y+J/aW0f6VJ0akMLust2G 1neg== X-Gm-Message-State: AOAM531dk6FNu3XkaVL2I0FrXiGhfX6NvAthEUVPHJL42hAPbYw66Ls/ Bln4pcTsu5+uyM8zhR+IrIYYeKtdRZM= X-Google-Smtp-Source: ABdhPJxXBOd/gwayNaRKtHJkSmzz8j7EdSKTqIlur4elHSagagr/r78JBxleXRJde03jaJ4iMZxSFw== X-Received: by 2002:a05:6e02:87:: with SMTP id l7mr10135074ilm.57.1610230727414; Sat, 09 Jan 2021 14:18:47 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f693:9fff:fef4:3e8a]) by smtp.gmail.com with ESMTPSA id i27sm11415849ill.45.2021.01.09.14.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 14:18:46 -0800 (PST) From: Willem de Bruijn To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, Willem de Bruijn Subject: [PATCH net v2 2/3] net: compound page support in skb_seq_read Date: Sat, 9 Jan 2021 17:18:33 -0500 Message-Id: <20210109221834.3459768-3-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210109221834.3459768-1-willemdebruijn.kernel@gmail.com> References: <20210109221834.3459768-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Willem de Bruijn skb_seq_read iterates over an skb, returning pointer and length of the next data range with each call. It relies on kmap_atomic to access highmem pages when needed. An skb frag may be backed by a compound page, but kmap_atomic maps only a single page. There are not enough kmap slots to always map all pages concurrently. Instead, if kmap_atomic is needed, iterate over each page. As this increases the number of calls, avoid this unless needed. The necessary condition is captured in skb_frag_must_loop. I tried to make the change as obvious as possible. It should be easy to verify that nothing changes if skb_frag_must_loop returns false. Tested: On an x86 platform with CONFIG_HIGHMEM=y CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP=y CONFIG_NETFILTER_XT_MATCH_STRING=y Run ip link set dev lo mtu 1500 iptables -A OUTPUT -m string --string 'badstring' -algo bm -j ACCEPT dd if=/dev/urandom of=in bs=1M count=20 nc -l -p 8000 > /dev/null & nc -w 1 -q 0 localhost 8000 < in Signed-off-by: Willem de Bruijn --- Changes: v1->v2 - increase frag_off size to u32 --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index c858adfb5a82..5f60c9e907c9 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1203,6 +1203,7 @@ struct skb_seq_state { struct sk_buff *root_skb; struct sk_buff *cur_skb; __u8 *frag_data; + __u32 frag_off; }; void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b6f2b520a9b7..0da035c1e53f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3442,6 +3442,7 @@ void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from, st->root_skb = st->cur_skb = skb; st->frag_idx = st->stepped_offset = 0; st->frag_data = NULL; + st->frag_off = 0; } EXPORT_SYMBOL(skb_prepare_seq_read); @@ -3496,14 +3497,27 @@ unsigned int skb_seq_read(unsigned int consumed, const u8 **data, st->stepped_offset += skb_headlen(st->cur_skb); while (st->frag_idx < skb_shinfo(st->cur_skb)->nr_frags) { + unsigned int pg_idx, pg_off, pg_sz; + frag = &skb_shinfo(st->cur_skb)->frags[st->frag_idx]; - block_limit = skb_frag_size(frag) + st->stepped_offset; + pg_idx = 0; + pg_off = skb_frag_off(frag); + pg_sz = skb_frag_size(frag); + + if (skb_frag_must_loop(skb_frag_page(frag))) { + pg_idx = (pg_off + st->frag_off) >> PAGE_SHIFT; + pg_off = offset_in_page(pg_off + st->frag_off); + pg_sz = min_t(unsigned int, pg_sz - st->frag_off, + PAGE_SIZE - pg_off); + } + + block_limit = pg_sz + st->stepped_offset; if (abs_offset < block_limit) { if (!st->frag_data) - st->frag_data = kmap_atomic(skb_frag_page(frag)); + st->frag_data = kmap_atomic(skb_frag_page(frag) + pg_idx); - *data = (u8 *) st->frag_data + skb_frag_off(frag) + + *data = (u8 *)st->frag_data + pg_off + (abs_offset - st->stepped_offset); return block_limit - abs_offset; @@ -3514,8 +3528,12 @@ unsigned int skb_seq_read(unsigned int consumed, const u8 **data, st->frag_data = NULL; } - st->frag_idx++; - st->stepped_offset += skb_frag_size(frag); + st->stepped_offset += pg_sz; + st->frag_off += pg_sz; + if (st->frag_off == skb_frag_size(frag)) { + st->frag_off = 0; + st->frag_idx++; + } } if (st->frag_data) { From patchwork Sat Jan 9 22:18:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12008773 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E9BEC433E0 for ; Sat, 9 Jan 2021 22:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12777216C4 for ; Sat, 9 Jan 2021 22:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbhAIWTb (ORCPT ); Sat, 9 Jan 2021 17:19:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbhAIWTa (ORCPT ); Sat, 9 Jan 2021 17:19:30 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07C27C0617A3 for ; Sat, 9 Jan 2021 14:18:50 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id u26so13764966iof.3 for ; Sat, 09 Jan 2021 14:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w66f1ZKevlb8Uuzhhrx+rTk8V4QHn7SP2CQf7TQF9Oo=; b=HCxftBJO6Fto1tmxb/jAR4IIKczm3y+Owfm4Tkv64r/ZUdyqgDQTCW3sKZ7YB1IQi6 O8qgDGchSjK9x93nNnbxt+X1QP3Sjfi8e5Ab54wHt4jMr7Q9UJ+MHsAtjiucCBwtcdBv 2fCXa5bgFEVFXOa1LyoX/PhA74sk81+PQ3AUv8cjcugOkVTv4/345kqqr7HPUFBwmkes vEW/COGkHlQVZt8YmaScvVt9MU9Itk+bXzvj8zbohviza79DiR0zU25F7PbULe5YB0C8 wB02XlJ3yDU/vGepcNAwkWljinAFt340cLRf124Tm9os8FkcJ6H7MMCLluGNqECM6T3J SpYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w66f1ZKevlb8Uuzhhrx+rTk8V4QHn7SP2CQf7TQF9Oo=; b=D4Xj2rCpU3vV6+PoM9uCz+ZaAwNvYdESko51ey9oeIEFDVg6Kglo5Ig7zbiqiUySBV ZmaAVDxWSblTXW82BuvSY+84UIoO/eu2ei0MzSt8LmL4Az5qXm5gsQQIxIVf4urDSb0v kIVoXNXmTukpm56uqnYGCg3b9O5cU5ZVBiYfTIY2JgvwSGbS72tQtmrvrcTAfPV12esV SYhB4EDNnkdXqrUcSe7mBoeOKfIiKRy7bVMQgGGUbcdYq2Zz/OVmJQTufixTgoCNnGJ8 4FKHQCJFSIDAwxbhdbS/lxEwfNLYNuESBFWXW8I+0fxTAi7CSg0gwo96I064RhcWFPJS B4/w== X-Gm-Message-State: AOAM532dIFPlCK+K/LtIXjm6O7xYIKU5i1JCHcdrGEmNZIargEoyHUds fsYEQyuWowEGop95sPlk1FxTx8Kim4Q= X-Google-Smtp-Source: ABdhPJyI2q5F2Fn/fnRj4cXcgifp+EIeePuJSf49Wur4tpb0l5TKpmgqJ5QkuDppwqu2wWsm0pm6rQ== X-Received: by 2002:a5e:dd0d:: with SMTP id t13mr10562117iop.132.1610230729135; Sat, 09 Jan 2021 14:18:49 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f693:9fff:fef4:3e8a]) by smtp.gmail.com with ESMTPSA id i27sm11415849ill.45.2021.01.09.14.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 14:18:48 -0800 (PST) From: Willem de Bruijn To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, Willem de Bruijn , Steffen Klassert Subject: [PATCH net v2 3/3] esp: avoid unneeded kmap_atomic call Date: Sat, 9 Jan 2021 17:18:34 -0500 Message-Id: <20210109221834.3459768-4-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210109221834.3459768-1-willemdebruijn.kernel@gmail.com> References: <20210109221834.3459768-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Willem de Bruijn 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: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible") Signed-off-by: Willem de Bruijn Cc: Steffen Klassert Acked-by: Steffen Klassert --- net/ipv4/esp4.c | 7 +------ net/ipv6/esp6.c | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 8b07f3a4f2db..a3271ec3e162 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -443,7 +443,6 @@ static int esp_output_encap(struct xfrm_state *x, struct sk_buff *skb, int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp) { u8 *tail; - u8 *vaddr; int nfrags; int esph_offset; struct page *page; @@ -485,14 +484,10 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * page = pfrag->page; get_page(page); - vaddr = kmap_atomic(page); - - tail = vaddr + pfrag->offset; + tail = page_address(page) + pfrag->offset; esp_output_fill_trailer(tail, esp->tfclen, esp->plen, esp->proto); - kunmap_atomic(vaddr); - nfrags = skb_shinfo(skb)->nr_frags; __skb_fill_page_desc(skb, nfrags, page, pfrag->offset, diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 52c2f063529f..2b804fcebcc6 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -478,7 +478,6 @@ static int esp6_output_encap(struct xfrm_state *x, struct sk_buff *skb, int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp) { u8 *tail; - u8 *vaddr; int nfrags; int esph_offset; struct page *page; @@ -519,14 +518,10 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info page = pfrag->page; get_page(page); - vaddr = kmap_atomic(page); - - tail = vaddr + pfrag->offset; + tail = page_address(page) + pfrag->offset; esp_output_fill_trailer(tail, esp->tfclen, esp->plen, esp->proto); - kunmap_atomic(vaddr); - nfrags = skb_shinfo(skb)->nr_frags; __skb_fill_page_desc(skb, nfrags, page, pfrag->offset,