netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: Destroy previously created kthreads after failing to set napi threaded mode
@ 2023-06-30  5:43 Zqiang
  2023-06-30 15:32 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Zqiang @ 2023-06-30  5:43 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, qiang.zhang1211; +Cc: netdev, linux-kernel

When setting 1 to enable napi threaded mode, will traverse dev->napi_list
and create kthread for napi->thread, if creation fails, the dev->threaded
will be set to false and we will clear NAPI_STATE_THREADED bit for all
napi->state in dev->napi_list, even if some napi that has successfully
created the kthread before. as a result, for successfully created napi
kthread, they will never be used.

This commit therefore destroy previously created napi->thread if setting
napi threaded mode fails.

Signed-off-by: Zqiang <qiang.zhang1211@gmail.com>
---
 v1->v2:
 Set napi->thread pointer is NULL.

 net/core/dev.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 69a3e544676c..6125a1b1e019 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6317,10 +6317,15 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
 	 * This should not cause hiccups/stalls to the live traffic.
 	 */
 	list_for_each_entry(napi, &dev->napi_list, dev_list) {
-		if (threaded)
+		if (threaded) {
 			set_bit(NAPI_STATE_THREADED, &napi->state);
-		else
+		} else {
 			clear_bit(NAPI_STATE_THREADED, &napi->state);
+			if (napi->thread) {
+				kthread_stop(napi->thread);
+				napi->thread = NULL;
+			}
+		}
 	}
 
 	return err;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] net: Destroy previously created kthreads after failing to set napi threaded mode
  2023-06-30  5:43 [PATCH v2] net: Destroy previously created kthreads after failing to set napi threaded mode Zqiang
@ 2023-06-30 15:32 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2023-06-30 15:32 UTC (permalink / raw)
  To: Zqiang; +Cc: davem, edumazet, pabeni, netdev, linux-kernel

On Fri, 30 Jun 2023 13:43:53 +0800 Zqiang wrote:
> When setting 1 to enable napi threaded mode, will traverse dev->napi_list
> and create kthread for napi->thread, if creation fails, the dev->threaded
> will be set to false and we will clear NAPI_STATE_THREADED bit for all
> napi->state in dev->napi_list, even if some napi that has successfully
> created the kthread before. as a result, for successfully created napi
> kthread, they will never be used.
> 
> This commit therefore destroy previously created napi->thread if setting
> napi threaded mode fails.

Please don't send two patches in less than 24h, unless someone asks you
to on the list. A lot of people read the list from the oldest postings,
won't notice the newer one, and it will split the discussion.
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-30 15:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-30  5:43 [PATCH v2] net: Destroy previously created kthreads after failing to set napi threaded mode Zqiang
2023-06-30 15:32 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).