Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3052993rwe; Mon, 29 Aug 2022 05:11:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7IcFBVjH/cci6ALq6trhnFMz5RDP57q/N2czclsGkBiOVtGzZOirtWlE/17AJiyMRFoA4c X-Received: by 2002:a17:907:87b0:b0:738:e618:99ca with SMTP id qv48-20020a17090787b000b00738e61899camr13137614ejc.357.1661775101653; Mon, 29 Aug 2022 05:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775101; cv=none; d=google.com; s=arc-20160816; b=Z4B60DR/vhfWUR2WcMvhnMlhmnBAnP5R3GiCebStP4tJSvctojmKQYh4K+qPKLCeav FmLg2mRwVgpfcX9/nenpcLZH751x1g//YZWWtTnpb51t0PE/u2rVF2nMm8hPqs/wInRe hxKI/KwlMW6bItQ8iQt9xbbQc1JveV1/n7mZ5E5YASsfFo7U5f9iPYY2vzFkAmKdutNY U7NfOwQGPZ5Sc9SKwwqyOccNqgfNoD2JOcoqljyHGz06W3d4gUpKMXcRi8elnFMVGRgQ 7o9qZUP3tq89wYkCRryb5IFVcWK0VzGYnZrS81eNYKyz31tDwSRgjaB4MHR6ZvRsuxdJ FG2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fpz7G2vfhTiU2sqTjSSh61mAriDaRrPuHrfw1pE01Bs=; b=V9xCuEZU4CvD/nLQgULhrV+RVpZ0PraxorWHMZEIxryGuK8iWu4bMkzGTCHdcmZNyZ 0Agy+L8dGd9PCFQ7nFIVK4itutJpFvOFX4lYldNmzz5xacfYdmRAzFjeifj0mpyOJi1X L+3Ljyyl3k6ArJg9Le4N1MEcSB+PejtdVv8XrUKCRM2rEtIHqGaITUm03BPG0Erc10CD lbz1EBVZtPnQ1uckxwX2xARLmHTO3N0xK5xr4mwIoqgeB1+LcDTs2sadlDYB8tMRFSDV K+Y13BUGD9rGnwNIYw1py28KmD25ztjxFCs3x/ZXyIUYEsWPx9qK9Vri6aX81tBY2tfQ b77A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ck4Zbxrk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm22-20020a170907949600b00734be0ce32esi5274088ejc.688.2022.08.29.05.11.15; Mon, 29 Aug 2022 05:11:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ck4Zbxrk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbiH2Lay (ORCPT + 99 others); Mon, 29 Aug 2022 07:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232487AbiH2L3I (ORCPT ); Mon, 29 Aug 2022 07:29:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A9BD78BD2; Mon, 29 Aug 2022 04:17:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1444A61128; Mon, 29 Aug 2022 11:05:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CFD5C433D6; Mon, 29 Aug 2022 11:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771150; bh=eTejDpS13D/jixJdgnj9+fUID/w5E/ssspcErqeGyTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ck4ZbxrkW9wDjSCgcmvc+/5P8STVcaQgxrkCyBlgbQ6BM63GrI12OI3VBt5e45Ppf j/Pf7xDqK+s95e2jTF1nmnWlkEPFfpGA+a3COcsBrPFE2YLaRtg9UB7SYGZZqN4CSv 0yTu9dZbQWw3n6eg0uBDQpIxpqRYqG3LQQklExK4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 072/136] net: Fix data-races around netdev_max_backlog. Date: Mon, 29 Aug 2022 12:58:59 +0200 Message-Id: <20220829105807.589560174@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105804.609007228@linuxfoundation.org> References: <20220829105804.609007228@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima [ Upstream commit 5dcd08cd19912892586c6082d56718333e2d19db ] While reading netdev_max_backlog, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. While at it, we remove the unnecessary spaces in the doc. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- Documentation/admin-guide/sysctl/net.rst | 2 +- net/core/dev.c | 4 ++-- net/core/gro_cells.c | 2 +- net/xfrm/espintcp.c | 2 +- net/xfrm/xfrm_input.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst index 4150f74c521a8..5310f398794c1 100644 --- a/Documentation/admin-guide/sysctl/net.rst +++ b/Documentation/admin-guide/sysctl/net.rst @@ -271,7 +271,7 @@ poll cycle or the number of packets processed reaches netdev_budget. netdev_max_backlog ------------------ -Maximum number of packets, queued on the INPUT side, when the interface +Maximum number of packets, queued on the INPUT side, when the interface receives packets faster than kernel can process them. netdev_rss_key diff --git a/net/core/dev.c b/net/core/dev.c index 1a0de071fcf45..87cf2e0d8f6f1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4589,7 +4589,7 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen) struct softnet_data *sd; unsigned int old_flow, new_flow; - if (qlen < (netdev_max_backlog >> 1)) + if (qlen < (READ_ONCE(netdev_max_backlog) >> 1)) return false; sd = this_cpu_ptr(&softnet_data); @@ -4637,7 +4637,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu, if (!netif_running(skb->dev)) goto drop; qlen = skb_queue_len(&sd->input_pkt_queue); - if (qlen <= netdev_max_backlog && !skb_flow_limit(skb, qlen)) { + if (qlen <= READ_ONCE(netdev_max_backlog) && !skb_flow_limit(skb, qlen)) { if (qlen) { enqueue: __skb_queue_tail(&sd->input_pkt_queue, skb); diff --git a/net/core/gro_cells.c b/net/core/gro_cells.c index 6eb2e5ec2c506..2f66f3f295630 100644 --- a/net/core/gro_cells.c +++ b/net/core/gro_cells.c @@ -26,7 +26,7 @@ int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb) cell = this_cpu_ptr(gcells->cells); - if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) { + if (skb_queue_len(&cell->napi_skbs) > READ_ONCE(netdev_max_backlog)) { drop: atomic_long_inc(&dev->rx_dropped); kfree_skb(skb); diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c index 1f08ebf7d80c5..24ca49ecebea3 100644 --- a/net/xfrm/espintcp.c +++ b/net/xfrm/espintcp.c @@ -170,7 +170,7 @@ int espintcp_queue_out(struct sock *sk, struct sk_buff *skb) { struct espintcp_ctx *ctx = espintcp_getctx(sk); - if (skb_queue_len(&ctx->out_queue) >= netdev_max_backlog) + if (skb_queue_len(&ctx->out_queue) >= READ_ONCE(netdev_max_backlog)) return -ENOBUFS; __skb_queue_tail(&ctx->out_queue, skb); diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c index 3df0861d4390f..5f34bc378fdcf 100644 --- a/net/xfrm/xfrm_input.c +++ b/net/xfrm/xfrm_input.c @@ -782,7 +782,7 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb, trans = this_cpu_ptr(&xfrm_trans_tasklet); - if (skb_queue_len(&trans->queue) >= netdev_max_backlog) + if (skb_queue_len(&trans->queue) >= READ_ONCE(netdev_max_backlog)) return -ENOBUFS; BUILD_BUG_ON(sizeof(struct xfrm_trans_cb) > sizeof(skb->cb)); -- 2.35.1