Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3083312rwe; Mon, 29 Aug 2022 05:40:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR7GOr3Vzx8Z0+2ObWPWj+I4vRI3HGPAivWrmUplcir8Zdd0L1u0/5pH/UzwmpmUWgyt+yHn X-Received: by 2002:a17:902:ce04:b0:172:9ff7:6747 with SMTP id k4-20020a170902ce0400b001729ff76747mr15529323plg.166.1661776806641; Mon, 29 Aug 2022 05:40:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776806; cv=none; d=google.com; s=arc-20160816; b=Dq2aZjrmM70oXtm4hLKFXpCdZhznZNJXMAKe3lM35xNIdIqgF5cGQ5aVGraNfVyTAM 0IVmDUVuKwxwukzze3XPzvCrMSVFP72hVAdYjycx64zi76tnWTjWHoPIjwTy5btM4LGc 5ZsbY9EKoweDhT2Mfx1jFzPKGw43/xL++f4DCwEsMIbnQIkde4oy9W8JBJw5R0ilhVHk eq3PKmRkcMSTKTcGrtCEZr/VSpjhUU0aBCeL9NIUuxPpWH/bN1a2InC89udpJy9f4w8V QQpb7LpVJgFYsexsO+szNNsRCh72T+Vm1ZPyOmCnnJey4Fcu/abM7a+v8QGUZw4ka1C8 erBQ== 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=DLqofXvbNC8cH+S2Z7MwHIDwk7Rd9Z8Jk440Qq96nec=; b=NsSE9/HFXdpoAeliiXmISj2O1ztJRuYyXMO249PUFNwp8VI1Q0IimjAvBmXZZovRKs u4m5fyywSI+ncdcC35sni9GUiOXKfvej/U/G6EKNd3vrxh/JI5PsdH/RUQZW4nrvQG01 ttcsdbtjC1QaiLP0NILPhhgmxl1LtcjWG96Yrt8n2tyqaU0VgZeGOV+pH63T9uRXbhTo XbUZP9bSYMO9IlZCDA6g/pQTGRESZa3f4IzBHdxRbv9R5gCYKpE9Nxi7BJypwjd/tT7L VSSBzuhfxTmUmn0QsSkjGPgJCAMJQq1A7E1jkLtz1Q8Bxz9NuT8aXwijtjxOnNpLKm0F Icwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wdx6x8uN; 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 e16-20020a17090301d000b0016f16417f6dsi10130201plh.16.2022.08.29.05.39.55; Mon, 29 Aug 2022 05:40:06 -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=wdx6x8uN; 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 S232124AbiH2L0b (ORCPT + 99 others); Mon, 29 Aug 2022 07:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232214AbiH2LYc (ORCPT ); Mon, 29 Aug 2022 07:24:32 -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 3D7256E2C9; Mon, 29 Aug 2022 04:15:32 -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 7E6E1B80F9A; Mon, 29 Aug 2022 11:14:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E09F6C433D6; Mon, 29 Aug 2022 11:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771698; bh=Lc7mfpZ230zhoqdfL0jETz1vDyxhu8c+IZPgx0O7SYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wdx6x8uN6DaQge9JC+eoioY4My0sdFwSlwB0aWlZS+LuhrGL2mut/k1E9XYNojZz5 CeV1JkX2GsgB2jXLvqI7zZ/ZEUjcNlAznWyhk9a1H3q9E2u9YFyeSklb4YhMBYtGW4 vDei2mSnxwCy3ckgmJzzn5IIYwCYQu4EWjKVywXo= 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.19 066/158] net: Fix data-races around weight_p and dev_weight_[rt]x_bias. Date: Mon, 29 Aug 2022 12:58:36 +0200 Message-Id: <20220829105811.482307278@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@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 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 30a1603a7225c..2a7d81cd9e2ea 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5917,7 +5917,7 @@ static int process_backlog(struct napi_struct *napi, int quota) net_rps_action_and_irq_enable(sd); } - napi->weight = dev_rx_weight; + napi->weight = READ_ONCE(dev_rx_weight); while (again) { struct sk_buff *skb; diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 71a13596ea2bf..725891527814c 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -234,14 +234,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 *buffer, size_t *lenp, loff_t *ppos) { - int ret; + static DEFINE_MUTEX(dev_weight_mutex); + int ret, weight; + mutex_lock(&dev_weight_mutex); ret = proc_dointvec(table, write, buffer, lenp, ppos); - if (ret != 0) - return ret; - - dev_rx_weight = weight_p * dev_weight_rx_bias; - dev_tx_weight = weight_p * dev_weight_tx_bias; + if (!ret && write) { + weight = 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); return ret; } diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index dba0b3e24af5e..a64c3c1541118 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -409,7 +409,7 @@ static inline bool qdisc_restart(struct Qdisc *q, int *packets) void __qdisc_run(struct Qdisc *q) { - int quota = dev_tx_weight; + int quota = READ_ONCE(dev_tx_weight); int packets; while (qdisc_restart(q, &packets)) { -- 2.35.1