From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>,
Matthias Tafelmeier <matthias.tafelmeier@gmx.net>
Subject: [PATCH v4 net 02/17] net: Fix data-races around weight_p and dev_weight_[rt]x_bias.
Date: Tue, 23 Aug 2022 10:46:45 -0700 [thread overview]
Message-ID: <20220823174700.88411-3-kuniyu@amazon.com> (raw)
In-Reply-To: <20220823174700.88411-1-kuniyu@amazon.com>
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 <kuniyu@amazon.com>
---
CC: Matthias Tafelmeier <matthias.tafelmeier@gmx.net>
---
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 716df64fcfa5..b5b92dcd5eea 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5918,7 +5918,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 71a13596ea2b..725891527814 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 d47b9689eba6..99b697ad2b98 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.30.2
next prev parent reply other threads:[~2022-08-23 19:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 17:46 [PATCH v4 net 00/17] net: sysctl: Fix data-races around net.core.XXX Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 01/17] net: Fix data-races around sysctl_[rw]mem_(max|default) Kuniyuki Iwashima
2022-08-23 17:46 ` Kuniyuki Iwashima [this message]
2022-08-23 17:46 ` [PATCH v4 net 03/17] net: Fix data-races around netdev_max_backlog Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 04/17] net: Fix data-races around netdev_tstamp_prequeue Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 05/17] ratelimit: Fix data-races in ___ratelimit() Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 06/17] net: Fix data-races around sysctl_optmem_max Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 07/17] net: Fix a data-race around sysctl_tstamp_allow_data Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 08/17] net: Fix a data-race around sysctl_net_busy_poll Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 09/17] net: Fix a data-race around sysctl_net_busy_read Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 10/17] net: Fix a data-race around netdev_budget Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 11/17] net: Fix data-races around sysctl_max_skb_frags Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 12/17] net: Fix a data-race around netdev_budget_usecs Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 13/17] net: Fix data-races around sysctl_fb_tunnels_only_for_init_net Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 14/17] net: Fix data-races around sysctl_devconf_inherit_init_net Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 15/17] net: Fix a data-race around gro_normal_batch Kuniyuki Iwashima
2022-08-23 17:46 ` [PATCH v4 net 16/17] net: Fix a data-race around netdev_unregister_timeout_secs Kuniyuki Iwashima
2022-08-23 17:47 ` [PATCH v4 net 17/17] net: Fix a data-race around sysctl_somaxconn Kuniyuki Iwashima
2022-08-24 13:00 ` [PATCH v4 net 00/17] net: sysctl: Fix data-races around net.core.XXX patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220823174700.88411-3-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=matthias.tafelmeier@gmx.net \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.