From patchwork Fri Jan 8 17:11:50 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: 12007071 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.8 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 76236C433E6 for ; Fri, 8 Jan 2021 17:12:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48AC923A00 for ; Fri, 8 Jan 2021 17:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728310AbhAHRMi (ORCPT ); Fri, 8 Jan 2021 12:12:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727714AbhAHRMh (ORCPT ); Fri, 8 Jan 2021 12:12:37 -0500 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3248C061381 for ; Fri, 8 Jan 2021 09:11:57 -0800 (PST) Received: by mail-qt1-x82d.google.com with SMTP id h19so6956696qtq.13 for ; Fri, 08 Jan 2021 09:11:57 -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=Gns2tIgzxbMxLmQ+hdSG92lrKSG/hYJQU0qqJMpNzRJHfIL2ig4zjnsZp43bS3ICzF oDsOAat1aB9Qf7DHMRrjtHN374clGzzlWGjD30rZ88hFz94t5WvFk6drTWe/o/lauv/3 kJ5ZU71117ofgazcQwMFUwsCn7cAKgtDXykYpbypgDp/frdsXXO6Gar5GKVWrOB5xwjH xRW58E/oV/9pRPgkcP0/tNeORR/sY66zrbsz7h4S0deEE6qngN3reG1Hiq8JIuAlmIDr PksFSe9pSy0IV+h1mIXHmlr0PBmicOE8f6CyUi2sEQGOdUVwwY7yOXUSGXEFkgrLg9Sx cPLA== 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=WckpWdLoNzimXXnBDIA5TEkuI8TYqXJSiTZ3bv7MCiDXpcAriA2aWxXB+8m1c+cXSH YS7NJBKNn9zEMo7XyXJ4S9XIDJ2d5jZm6jazIV0Ivt8uX7GLkrRTDSsWpzhCAtWBGkbF lZPP4DI39KfnzpONyn7fBZ85KVVvBsuhN9gUyxS6xutW9t/P1pMpkOwiIwMw5ZdqyIAj lLpxdvuOeKsMx9CR3P5wgAYEsp6a2JWAKlQ8M+eQ94n2vraDTFmLxAc14D2gbGy1SDzo /2NeksioRUNeVNkkc3zkJbqlzICeFkqWF/BA7KPYDvAhSNGZuWTFBsHBUhQRgEOEZPNA fmTQ== X-Gm-Message-State: AOAM530mCRIIH6p/ukj9pZ8vyWGFtqero3txIUZxidPZzf+mrnTrPJJC 478s+7lDThIZ2tyvSWu6+eQf02J4+ko= X-Google-Smtp-Source: ABdhPJzgjMxHdL206Nwy03LxFc5ollQ6smzj160B+5ezhnZ3D6f6R9DAFo0XteTWbb9kLr1NH32H5w== X-Received: by 2002:ac8:6f77:: with SMTP id u23mr4486363qtv.118.1610125916643; Fri, 08 Jan 2021 09:11:56 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f693:9fff:fef4:3e8a]) by smtp.gmail.com with ESMTPSA id c2sm5081600qke.109.2021.01.08.09.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 09:11:55 -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 1/3] net: support kmap_local forced debugging in skb_frag_foreach Date: Fri, 8 Jan 2021 12:11:50 -0500 Message-Id: <20210108171152.2961251-2-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210108171152.2961251-1-willemdebruijn.kernel@gmail.com> References: <20210108171152.2961251-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 Fri Jan 8 17:11:51 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: 12007073 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.8 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 87930C43381 for ; Fri, 8 Jan 2021 17:13:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4551322E02 for ; Fri, 8 Jan 2021 17:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728355AbhAHRMk (ORCPT ); Fri, 8 Jan 2021 12:12:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727714AbhAHRMi (ORCPT ); Fri, 8 Jan 2021 12:12:38 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAAF5C0612EA for ; Fri, 8 Jan 2021 09:11:58 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id z9so7000836qtn.4 for ; Fri, 08 Jan 2021 09:11:58 -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=ErZAiVJLhWp/t0+f/uIDA2ze7Up4XbAYrW4zfl6dXDc=; b=sTxyXO+NZvRmAOG/eFW+zHk7qPhOPlGLRKbsQFdhSHUKpCGCmqHYvGfRSdHEzJWPwS /UZjPtPd8sgeB+f9IDN8Wxq/SJCkikmC0ENY5jN77Am1DHT4lixFJ9mld5d1DZ8tolrm La3B6PCYnS3px64wXPyMJeTbvH7570seQuqaXsmpia3f2T8osl7VDzPZKJlkSiZvtbSV GQxj8333eq5u/EKS1H6IDnF9yu0hgvmZA6nAXQzd7tO3kx0/SF9NM4V89UoeyQIlknxb qZDoqIsbB6RELFiH2GWoeDYfpCcTbaUIHm8gBc+LfvX16BhoJbglbKsOJ3l427iVg/n6 kQLA== 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=ErZAiVJLhWp/t0+f/uIDA2ze7Up4XbAYrW4zfl6dXDc=; b=cVbNhWKgekDZhUFVmSJRICq1HIPvgkIGQ2a2mFoG0+12xCD7ittzTwOxPH7O14KEl2 bCHn6jWLhYTKesR+dKtggkfo4zDehIf1XWDj7tZ0QuDJebF3B7NyZk0o+J5oLKCrbtdy aFa5C4Jx2kXm1yoe9z/BpaOXQMYsBAcm6rr153m+AALq3788+GaXvQK9dGA/erW2OIs+ AHCIrSLXREf92naj4HQrw/aU1SuL0eWvPevIEHT9tawaiUjsrXsoy1x02fEWjTTu5120 VgVHR96Ac1gsQQEdw/FyXU6XC+bWhSKKmb0ZWRB+eLwmABnD0dtQpLKn9SqpMiu4JRZs /jrw== X-Gm-Message-State: AOAM533aCn31BftWLZwcBj5GHV48MNuvXg9c/2JuXxs81f0JvWuZ3QP8 +yBNQcZSJFsslEpllBMZvSmZY5NXwFk= X-Google-Smtp-Source: ABdhPJzf9xZd07nMJSnl2R2ucDEHBWznZwzvTcqTW6FtpcD6tTi408I2VOw3aIkNvWxhp0otqbVNow== X-Received: by 2002:aed:3482:: with SMTP id x2mr4449293qtd.368.1610125917615; Fri, 08 Jan 2021 09:11:57 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f693:9fff:fef4:3e8a]) by smtp.gmail.com with ESMTPSA id c2sm5081600qke.109.2021.01.08.09.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 09:11:56 -0800 (PST) From: Willem de Bruijn To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, Willem de Bruijn Subject: [PATCH net 2/3] net: compound page support in skb_seq_read Date: Fri, 8 Jan 2021 12:11:51 -0500 Message-Id: <20210108171152.2961251-3-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210108171152.2961251-1-willemdebruijn.kernel@gmail.com> References: <20210108171152.2961251-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 --- 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..68ffd3f115c1 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; + __u16 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 f62cae3f75d8..4acf45154b17 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 Fri Jan 8 17:11:52 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: 12007075 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.8 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 9A171C433E9 for ; Fri, 8 Jan 2021 17:13:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AC2023A05 for ; Fri, 8 Jan 2021 17:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728382AbhAHRMo (ORCPT ); Fri, 8 Jan 2021 12:12:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727252AbhAHRMk (ORCPT ); Fri, 8 Jan 2021 12:12:40 -0500 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C663BC0612FD for ; Fri, 8 Jan 2021 09:11:59 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id z3so6970769qtw.9 for ; Fri, 08 Jan 2021 09:11:59 -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=OLQKzZhbc8dBDAE91N2+hR3D310lXs0s6svgMaeHQLcO/ATZxlwzVDg+W0uxkp0ioP fjwu5KrmMGOH//RVWcrulso+xlx3lxMQZ2rNUuqSOetu937SqVYhmVedBbWX5whAEpY4 FMEaB2fIGg4bwukLyM9gJcZM97OOUx1r8BT/3zVQ/sKTLbgpRWP0RDJE1ICu8iAJDFxB hZcAWYvaxfT1sFMtOdxMUL6cjOOOxMtObu5xIyke3G+nVPv1GiCRoEbzgfnU1KUOhmXq +8sxTuwGqLwWzWWg3r5ztLIY0hn2aVt2Lsu/LLLFjfxIDqn6WEpa7ga6tOeP05AQyjVY OP6A== 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=R1WCJ3TWJ5P26zJdikJ/Tt+ESNAl5sI/HyAXMTfikhNJL3KWZ5b1TZcksF3zzWAlPy r9wyD9kNOhNyBmDXHW56ruqZRxZIEzfWGEPxkS8LdyoOk+C3emB+I2sfpMIToLZGTkAO Ybstp25XsNFBMesTM7Va6hiZnrFYVgsWBCP1sO10qqDH2G6Ip7b2vQNGHR165GZmU/sr LDnJTa+Ngn1kxu/roz81yyBlHHA3HUpIZ48D/ke1Qmu9FXcRNqoYsrDI1N27gaJoLtPq sSObe/ywT8Uct2vrtnBXw2beBGsghEdmqH18kV5QsrVWlRsJk0rD1OHzse3edLfs/Ses lhHQ== X-Gm-Message-State: AOAM532MKZ6Q1s/bovLXT6UFYvGLrikdXfH7Pkzx953tk8poZOlKv+3J Q0jtbrTmwMIJDyU9HcAwE5RpeSw67XM= X-Google-Smtp-Source: ABdhPJyhcSS+Cco1suepuC+PlCNOu0xn/VeI8ycAjLpBOvs5skd1u0VHwZ5pimVRCcfSfWesFGp/fA== X-Received: by 2002:a05:622a:208:: with SMTP id b8mr4549621qtx.124.1610125918609; Fri, 08 Jan 2021 09:11:58 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f693:9fff:fef4:3e8a]) by smtp.gmail.com with ESMTPSA id c2sm5081600qke.109.2021.01.08.09.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 09:11:57 -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 3/3] esp: avoid unneeded kmap_atomic call Date: Fri, 8 Jan 2021 12:11:52 -0500 Message-Id: <20210108171152.2961251-4-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210108171152.2961251-1-willemdebruijn.kernel@gmail.com> References: <20210108171152.2961251-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 --- 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,