lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 20 Mar 2023 17:26:52 +0800
From:   Yue Hu <zbestahu@...il.com>
To:     tj@...nel.org, jiangshanlai@...il.com
Cc:     linux-kernel@...r.kernel.org, huyue2@...lpad.com,
        zhangwen@...lpad.com
Subject: [PATCH] workqueue: Drop the NOT_RUNNING check to flags in worker_{set,clr}_flags

From: Yue Hu <huyue2@...lpad.com>

We know whether the worker flags are belong to WORKER_NOT_RUNNING or not
when we are setting and clearing them.  So check the flags not running
related is unnecessary for both the cases.

Currently, worker_{set,clr}_flags() are all used for WORKER_NOT_RUNNING
except for clearing WORKER_IDLE.  Let's change to directly clear it
instead.  Also, update the comment a little in worker_clr_flags().

Signed-off-by: Yue Hu <huyue2@...lpad.com>
---
 kernel/workqueue.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index de4282736999..c56112cb17c3 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -978,10 +978,8 @@ static inline void worker_set_flags(struct worker *worker, unsigned int flags)
 	WARN_ON_ONCE(worker->task != current);
 
 	/* If transitioning into NOT_RUNNING, adjust nr_running. */
-	if ((flags & WORKER_NOT_RUNNING) &&
-	    !(worker->flags & WORKER_NOT_RUNNING)) {
+	if (!(worker->flags & WORKER_NOT_RUNNING))
 		pool->nr_running--;
-	}
 
 	worker->flags |= flags;
 }
@@ -1007,12 +1005,11 @@ static inline void worker_clr_flags(struct worker *worker, unsigned int flags)
 
 	/*
 	 * If transitioning out of NOT_RUNNING, increment nr_running.  Note
-	 * that the nested NOT_RUNNING is not a noop.  NOT_RUNNING is mask
-	 * of multiple flags, not a single flag.
+	 * that NOT_RUNNING is mask of multiple flags, not a single flag.
 	 */
-	if ((flags & WORKER_NOT_RUNNING) && (oflags & WORKER_NOT_RUNNING))
-		if (!(worker->flags & WORKER_NOT_RUNNING))
-			pool->nr_running++;
+	if ((oflags & WORKER_NOT_RUNNING) &&
+	    (!(worker->flags & WORKER_NOT_RUNNING)))
+		pool->nr_running++;
 }
 
 /**
@@ -1835,7 +1832,9 @@ static void worker_leave_idle(struct worker *worker)
 
 	if (WARN_ON_ONCE(!(worker->flags & WORKER_IDLE)))
 		return;
-	worker_clr_flags(worker, WORKER_IDLE);
+	WARN_ON_ONCE(worker->task != current);
+
+	worker->flags &= ~WORKER_IDLE;
 	pool->nr_idle--;
 	list_del_init(&worker->entry);
 }
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ