提交 e6d7bbfb 编写于 作者: K Kuniyuki Iwashima 提交者: Zheng Zengkai

net: Fix data-races around weight_p and dev_weight_[rt]x_bias.

stable inclusion
from stable-v5.10.140
commit b498a1b0171e7152ce5a837c7f74b4c1a296586f
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I63FTT

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b498a1b0171e7152ce5a837c7f74b4c1a296586f

--------------------------------

[ Upstream commit bf955b5a ]

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: 3d48b53f ("net: dev_weight: TX/RX orthogonality")
Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Signed-off-by: NKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 a41540be
...@@ -6377,7 +6377,7 @@ static int process_backlog(struct napi_struct *napi, int quota) ...@@ -6377,7 +6377,7 @@ static int process_backlog(struct napi_struct *napi, int quota)
net_rps_action_and_irq_enable(sd); net_rps_action_and_irq_enable(sd);
} }
napi->weight = dev_rx_weight; napi->weight = READ_ONCE(dev_rx_weight);
while (again) { while (again) {
struct sk_buff *skb; struct sk_buff *skb;
......
...@@ -235,14 +235,17 @@ static int set_default_qdisc(struct ctl_table *table, int write, ...@@ -235,14 +235,17 @@ static int set_default_qdisc(struct ctl_table *table, int write,
static int proc_do_dev_weight(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) 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); ret = proc_dointvec(table, write, buffer, lenp, ppos);
if (ret != 0) if (!ret && write) {
return ret; weight = READ_ONCE(weight_p);
WRITE_ONCE(dev_rx_weight, weight * dev_weight_rx_bias);
dev_rx_weight = weight_p * dev_weight_rx_bias; WRITE_ONCE(dev_tx_weight, weight * dev_weight_tx_bias);
dev_tx_weight = weight_p * dev_weight_tx_bias; }
mutex_unlock(&dev_weight_mutex);
return ret; return ret;
} }
......
...@@ -403,7 +403,7 @@ static inline bool qdisc_restart(struct Qdisc *q, int *packets) ...@@ -403,7 +403,7 @@ static inline bool qdisc_restart(struct Qdisc *q, int *packets)
void __qdisc_run(struct Qdisc *q) void __qdisc_run(struct Qdisc *q)
{ {
int quota = dev_tx_weight; int quota = READ_ONCE(dev_tx_weight);
int packets; int packets;
while (qdisc_restart(q, &packets)) { while (qdisc_restart(q, &packets)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册