From nobody Sun Sep 7 12:19:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F9BECAAD5 for ; Fri, 2 Sep 2022 14:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235644AbiIBOp0 (ORCPT ); Fri, 2 Sep 2022 10:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236684AbiIBOot (ORCPT ); Fri, 2 Sep 2022 10:44:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC83A1208EC; Fri, 2 Sep 2022 07:05:38 -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 ams.source.kernel.org (Postfix) with ESMTPS id 51065B82A98; Fri, 2 Sep 2022 12:29:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B7BDC43141; Fri, 2 Sep 2022 12:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121764; bh=/EW6F/J4y5L/YIuTw42ImToh41zLmkwyEW0r/Ibql/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lv01Q8nylIFpEDkoYq3p9o7BcSLOg5XwxsjK412suAdk6nbZOFKjAHz5kocOnYdp9 GeC0Db/JBEokfvELamIu/UzF/ylgYC/5gZa6ASX6ABSILKDT5ITvkArlo6RcLk/k2B WxyBuYbc7Z3QeLsnDCnmoSgo76Qb7TqOkArFLykM= 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.4 26/77] net: Fix data-races around weight_p and dev_weight_[rt]x_bias. Date: Fri, 2 Sep 2022 14:18:35 +0200 Message-Id: <20220902121404.515887262@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121403.569927325@linuxfoundation.org> References: <20220902121403.569927325@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit bf955b5ab8f6f7b0632cdef8e36b14e4f6e77829 ] While reading weight_p, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Also, dev_[rt]x_weight can be read/written at the same time. So, we need to use READ_ONCE() and WRITE_ONCE() for its access. Moreover, to use the same weight_p while changing dev_[rt]x_weight, we add a mutex in proc_do_dev_weight(). Fixes: 3d48b53fb2ae ("net: dev_weight: TX/RX orthogonality") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/dev.c | 2 +- net/core/sysctl_net_core.c | 15 +++++++++------ net/sched/sch_generic.c | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index a03036456221b..517fb03a0bb89 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5892,7 +5892,7 @@ static int process_backlog(struct napi_struct *napi, = int quota) net_rps_action_and_irq_enable(sd); } =20 - napi->weight =3D dev_rx_weight; + napi->weight =3D READ_ONCE(dev_rx_weight); while (again) { struct sk_buff *skb; =20 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 48041f50ecfb4..586598887095d 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -238,14 +238,17 @@ static int set_default_qdisc(struct ctl_table *table,= int write, static int proc_do_dev_weight(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret; + static DEFINE_MUTEX(dev_weight_mutex); + int ret, weight; =20 + mutex_lock(&dev_weight_mutex); ret =3D proc_dointvec(table, write, buffer, lenp, ppos); - if (ret !=3D 0) - return ret; - - dev_rx_weight =3D weight_p * dev_weight_rx_bias; - dev_tx_weight =3D weight_p * dev_weight_tx_bias; + if (!ret && write) { + weight =3D READ_ONCE(weight_p); + WRITE_ONCE(dev_rx_weight, weight * dev_weight_rx_bias); + WRITE_ONCE(dev_tx_weight, weight * dev_weight_tx_bias); + } + mutex_unlock(&dev_weight_mutex); =20 return ret; } diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index ae5847de94c88..81fcf6c5bde96 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -403,7 +403,7 @@ static inline bool qdisc_restart(struct Qdisc *q, int *= packets) =20 void __qdisc_run(struct Qdisc *q) { - int quota =3D dev_tx_weight; + int quota =3D READ_ONCE(dev_tx_weight); int packets; =20 while (qdisc_restart(q, &packets)) { --=20 2.35.1