blob: 0d90686a0a673e4a90ccd8557025873a4ecd7f5c [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From f57826291fc2ff833c01b39c01fa5b74b69485da Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:29 +0800
4Subject: [PATCH] [networking][999-2709-fix-race-inside-napi-enable.patch]
5
6---
7 net/core/dev.c | 16 ++++++++++------
8 1 file changed, 10 insertions(+), 6 deletions(-)
9
10diff --git a/net/core/dev.c b/net/core/dev.c
11index 81892cd83..503af0034 100644
12--- a/net/core/dev.c
13+++ b/net/core/dev.c
14@@ -6413,12 +6413,16 @@ EXPORT_SYMBOL(napi_disable);
15 */
16 void napi_enable(struct napi_struct *n)
17 {
18- BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
19- smp_mb__before_atomic();
20- clear_bit(NAPI_STATE_SCHED, &n->state);
21- clear_bit(NAPI_STATE_NPSVC, &n->state);
22- if (n->dev->threaded && n->thread)
23- set_bit(NAPI_STATE_THREADED, &n->state);
24+ unsigned long val, new;
25+
26+ do {
27+ val = READ_ONCE(n->state);
28+ BUG_ON(!test_bit(NAPI_STATE_SCHED, &val));
29+
30+ new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC);
31+ if (n->dev->threaded && n->thread)
32+ new |= NAPIF_STATE_THREADED;
33+ } while (cmpxchg(&n->state, val, new) != val);
34 }
35 EXPORT_SYMBOL(napi_enable);
36
37--
382.34.1
39