| From f57826291fc2ff833c01b39c01fa5b74b69485da Mon Sep 17 00:00:00 2001 |
| From: Sam Shih <sam.shih@mediatek.com> |
| Date: Fri, 2 Jun 2023 13:06:29 +0800 |
| Subject: [PATCH] [networking][999-2709-fix-race-inside-napi-enable.patch] |
| |
| --- |
| net/core/dev.c | 16 ++++++++++------ |
| 1 file changed, 10 insertions(+), 6 deletions(-) |
| |
| diff --git a/net/core/dev.c b/net/core/dev.c |
| index 81892cd83..503af0034 100644 |
| --- a/net/core/dev.c |
| +++ b/net/core/dev.c |
| @@ -6413,12 +6413,16 @@ EXPORT_SYMBOL(napi_disable); |
| */ |
| void napi_enable(struct napi_struct *n) |
| { |
| - BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state)); |
| - smp_mb__before_atomic(); |
| - clear_bit(NAPI_STATE_SCHED, &n->state); |
| - clear_bit(NAPI_STATE_NPSVC, &n->state); |
| - if (n->dev->threaded && n->thread) |
| - set_bit(NAPI_STATE_THREADED, &n->state); |
| + unsigned long val, new; |
| + |
| + do { |
| + val = READ_ONCE(n->state); |
| + BUG_ON(!test_bit(NAPI_STATE_SCHED, &val)); |
| + |
| + new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC); |
| + if (n->dev->threaded && n->thread) |
| + new |= NAPIF_STATE_THREADED; |
| + } while (cmpxchg(&n->state, val, new) != val); |
| } |
| EXPORT_SYMBOL(napi_enable); |
| |
| -- |
| 2.34.1 |
| |