From patchwork Sat Apr 17 00:08:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 12209389 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 38293C433B4 for ; Sat, 17 Apr 2021 00:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EFE7610A6 for ; Sat, 17 Apr 2021 00:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235056AbhDQAJN (ORCPT ); Fri, 16 Apr 2021 20:09:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231958AbhDQAJM (ORCPT ); Fri, 16 Apr 2021 20:09:12 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10864C061574; Fri, 16 Apr 2021 17:08:46 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id k18so24641465oik.1; Fri, 16 Apr 2021 17:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l+SBgGodGdq7Avc2jggMLnF2zV3Ob0afS8608XVNpnw=; b=X26QAbdeJzDMr4hktMfF9kTny7p9YNbmXTueSTq0SXht1I3YmMlxDGzfy2OoIcpt04 WEp++OLYgzjNRP+DkEWERKyELwA0AynhvBM67f4ciMUlQ9HjrO0M0cmMMxhRri1NX+5H nAWv4ZeqLw7LpV7m1PAdwTOabPcySmhQDKU+TXcIt7zmG+7ueDcLMe1nnDonR8M6dXY2 hWbUvY9LLAhbXF5UQavH4NYMBAeHFfAvHuk97aU0Sr5x+WoKJVxF3DHqmgrtJYDAjWwm MeoJ3WzHucYu4OMxYqhgIipsoavdpFiI7OngFlE9dLD4/kO95JCdgZWqbLfVQujBNiMs DCgg== 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:mime-version :content-transfer-encoding; bh=l+SBgGodGdq7Avc2jggMLnF2zV3Ob0afS8608XVNpnw=; b=oDuqI0qjkelXDNX3wuBr9+TwMPf3q5RS+/B0Ew0xquCtXtLY73FUMmLqtYw2sUQ8Vg tMPkmH+oRjdczT7GnckvRHqRRquKHirHFbw7/+G9FaBqEW+4ZGpPA543OjvDqyw2fKPE Rm403lz1qxEE+It2qhf8HcfUE5SvOUWMtF0oLttEUZshfEmynDPt3/q4ac7IuW3fIxNN lfL01MgHjG0ej9d9afcqQ3BF1AEYQn+U8vknjxt+tdjHYf/GP3EvtcYz6RQSUOYLB4AR BSfRJgIXf+LfEtfEMoH9VEujzaNlR+rNTVuZYNHFrvQgWapnP8OGsUof3uEsRN8AB94l q8zQ== X-Gm-Message-State: AOAM5332HtnoVqlysFETI65393f/kFxRJ+TGTa2GG+s3RdfJGenrDlNx TYPPOZ+pHrA7wCnrjZHXsmM= X-Google-Smtp-Source: ABdhPJz6ulZHPqYgcA72j40r5a/JKii+fnmlAoNA9VjfIor3LYVdBlZRvtOpxPSJbzpH/hcWRuG8zQ== X-Received: by 2002:a05:6808:28b:: with SMTP id z11mr8509958oic.3.1618618125077; Fri, 16 Apr 2021 17:08:45 -0700 (PDT) Received: from shane-XPS-13-9380.attlocal.net ([2600:1700:4ca1:ade0:7fc9:3f8c:9a56:c021]) by smtp.gmail.com with ESMTPSA id l203sm1713585oig.41.2021.04.16.17.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 17:08:44 -0700 (PDT) From: Xie He To: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Andrii Nakryiko , Eric Dumazet , Wei Wang , Cong Wang , Taehee Yoo , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Mel Gorman , Andrew Morton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xie He , Neil Brown , Peter Zijlstra , Jiri Slaby , Mike Christie , Eric B Munson , Eric Dumazet , Sebastian Andrzej Siewior , Christoph Lameter Subject: [PATCH net] net/core/dev.c: Ensure pfmemalloc skbs are correctly handled when receiving Date: Fri, 16 Apr 2021 17:08:38 -0700 Message-Id: <20210417000839.6618-1-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When an skb is allocated by "__netdev_alloc_skb" in "net/core/skbuff.c", if "sk_memalloc_socks()" is true, and if there's not sufficient memory, the skb would be allocated using emergency memory reserves. This kind of skbs are called pfmemalloc skbs. pfmemalloc skbs must be specially handled in "net/core/dev.c" when receiving. They must NOT be delivered to the target protocol if "skb_pfmemalloc_protocol(skb)" is false. However, if, after a pfmemalloc skb is allocated and before it reaches the code in "__netif_receive_skb", "sk_memalloc_socks()" becomes false, then the skb will be handled by "__netif_receive_skb" as a normal skb. This causes the skb to be delivered to the target protocol even if "skb_pfmemalloc_protocol(skb)" is false. This patch fixes this problem by ensuring all pfmemalloc skbs are handled by "__netif_receive_skb" as pfmemalloc skbs. "__netif_receive_skb_list" has the same problem as "__netif_receive_skb". This patch also fixes it. Fixes: b4b9e3558508 ("netvm: set PF_MEMALLOC as appropriate during SKB processing") Cc: Mel Gorman Cc: David S. Miller Cc: Neil Brown Cc: Peter Zijlstra Cc: Jiri Slaby Cc: Mike Christie Cc: Eric B Munson Cc: Eric Dumazet Cc: Sebastian Andrzej Siewior Cc: Christoph Lameter Cc: Andrew Morton Signed-off-by: Xie He --- net/core/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 1f79b9aa9a3f..3e6b7879daef 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5479,7 +5479,7 @@ static int __netif_receive_skb(struct sk_buff *skb) { int ret; - if (sk_memalloc_socks() && skb_pfmemalloc(skb)) { + if (skb_pfmemalloc(skb)) { unsigned int noreclaim_flag; /* @@ -5507,7 +5507,7 @@ static void __netif_receive_skb_list(struct list_head *head) bool pfmemalloc = false; /* Is current sublist PF_MEMALLOC? */ list_for_each_entry_safe(skb, next, head, list) { - if ((sk_memalloc_socks() && skb_pfmemalloc(skb)) != pfmemalloc) { + if (skb_pfmemalloc(skb) != pfmemalloc) { struct list_head sublist; /* Handle the previous sublist */