Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp847916pxb; Fri, 16 Apr 2021 21:53:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZVCqC3qD7X8j/JQkuzIVHaWaRuYWOHChBiAfGZXBMxrtOJWcidyxXG6JEnW2fKmk8dgH3 X-Received: by 2002:a05:6402:10c6:: with SMTP id p6mr13778682edu.241.1618635229785; Fri, 16 Apr 2021 21:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618635229; cv=none; d=google.com; s=arc-20160816; b=aLJTcSKUm90hgHrupy62NaXXtWOJ7cuewxNiYUtOUkh+RA2dl3vYWx9ScpgQ8kNEpw VRkEJSfPWKoU4+r6uCAGOTlEBRS+3d/QK0H3A09Wz75/ifP/zno6AbyYEZajUuIvxZrm 8B40GBgzGbtaWMUjOy1pmKyxEzbonyJVH1tVfdAdDhj3t8hrSASUyvPXtQgnehLsKgx5 XGnMzVu6NDFNrZe08joThoSMUaPuR03IZZpCmviGbut2QlnhnrG6dUDAtCVQSUbgfZk4 KiXwisfoyw4cWnjvWSsLQILMcdnYeEwTj5MVRkp00Fu2O9CLHVfHCTMSjwODb62yx0nl GRkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZTumkKaTkisDrVEGWZBcCaLBAoi1QTIBQo+X8LGcUjo=; b=oezQeA5XaT67a5itHqd2lGbyTHKkNQW4BP5NeYEF7V/MkYno5r0w75lXSh6pn3NKts qLrE7PBiG+0ZXuO3KVan2XyzizkaO2fuPY/xfjAvGba1fAvWTXe984CRws82Ws0dZ1Rj LLpfKso5T1Dw3Q6gJBAiXpEkQ4iuVLXghWGY6fbVCGmtYNBjNBCN5Cr8I6uCmmRfIiZR iw+KfaK4nGhLtwBrY7mwjNdCSXa2+KMps53L72cgC8oBSrg5WgjzOrqHaEF7QFhUYOY5 fTB239Gx9nFqKmDT3JKirDnOpzO/pHFBh0n9Jnp+2bswoqFmBvVXcx6I38cVLcw/eF3X cfww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dqt+EWPw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz6si6551855edb.335.2021.04.16.21.53.27; Fri, 16 Apr 2021 21:53:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dqt+EWPw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbhDQEwq (ORCPT + 99 others); Sat, 17 Apr 2021 00:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229962AbhDQEwq (ORCPT ); Sat, 17 Apr 2021 00:52:46 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85490C061574 for ; Fri, 16 Apr 2021 21:52:20 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id k73so26135914ybf.3 for ; Fri, 16 Apr 2021 21:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZTumkKaTkisDrVEGWZBcCaLBAoi1QTIBQo+X8LGcUjo=; b=dqt+EWPwP/WHYWqJzXJQaCIP4vGaehR/VRB2lgjPVk8f6udXtMxrtsqxBAQRnn+2du FFq/5FZzhd+1GIQlc1pjZH75sBWN8GmXnJWk3WYva1rK0Z02ExA/1zg5PCez/qJqHEZJ 9M+CxqZHoMCB2/9U7W5BOLXXGy8DVb6h08oHQObnNjdWLz5vjUxIZ2O3VIdWG0X7rrqt 5jrITktyp9P3xIOcgILsmGKMDjKGx3pyCAXOjT59CmmBgcuZWZwagWYU2HyjWNfznY4k EoM6klST9gvyvlooLCmqwgaRXJD6FmD2Cz478wqCwwWHf5JNynsm9BhBwn4/03dEgZBV brTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZTumkKaTkisDrVEGWZBcCaLBAoi1QTIBQo+X8LGcUjo=; b=K5tbV+5SuR2ldxoeCLrTZUqRE6QXOhmSMkfiplslnAScC7sxkeFxODt/fiMD1FqiR5 7866v/VckKOdhtYvOsOtPl3oaZ6JNQfC8DUYC/Q5wIYY32cZhVxPh30K4sU6ONlUfzT0 +vWOdNAT0CHhQqVc0GiJsCFhCry2es6MQTkGP4XIC+5N48kz8QQH9vNj6/IyHGRPUE0l GgVPyX2yMFRxvD/M4BjGcDCV32xIt8cN5KwQxUHbHB4WvSQzabPojuhdIpoKT4j2n9Kj C1pMnOqwGbwDZrNHUF964X6rWX9/+gdzTNNUzLJ4Y8vF2aZafwi2TIPLVSPz8cPU5Jzq IJjA== X-Gm-Message-State: AOAM533nDM1AR81n0GgKbMueDB2+id746m876l/dOB2ifzKj6ANGclL+ FZ2bwF7TsouIguBclMgNclCxIhWyYwAkU3pFyuIXmw== X-Received: by 2002:a25:7650:: with SMTP id r77mr3762283ybc.446.1618635139396; Fri, 16 Apr 2021 21:52:19 -0700 (PDT) MIME-Version: 1.0 References: <20210417000839.6618-1-xie.he.0141@gmail.com> In-Reply-To: <20210417000839.6618-1-xie.he.0141@gmail.com> From: Eric Dumazet Date: Sat, 17 Apr 2021 06:52:08 +0200 Message-ID: Subject: Re: [PATCH net] net/core/dev.c: Ensure pfmemalloc skbs are correctly handled when receiving To: Xie He Cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Andrii Nakryiko , Wei Wang , Cong Wang , Taehee Yoo , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Mel Gorman , Andrew Morton , netdev , LKML , Neil Brown , Peter Zijlstra , Jiri Slaby , Mike Christie , Eric B Munson , Eric Dumazet , Sebastian Andrzej Siewior , Christoph Lameter Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 17, 2021 at 2:08 AM Xie He wrote: > > 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 */ > -- > 2.27.0 > The race window has been considered to be small that we prefer the code as it is. The reason why we prefer current code is that we use a static key for the implementation of sk_memalloc_socks() Trading some minor condition (race) with extra cycles for each received packet is a serious concern. What matters is a persistent condition that would _deplete_ memory, not for a dozen of packets, but thousands. Can you demonstrate such an issue ?