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>] [day] [month] [year] [list]
Message-Id: <20241120084813.193339-1-zhen.ni@easystack.cn>
Date: Wed, 20 Nov 2024 16:48:13 +0800
From: Zhen Ni <zhen.ni@...ystack.cn>
To: akpm@...ux-foundation.org,
	brauner@...nel.org,
	oleg@...hat.com,
	tglx@...utronix.de,
	frederic@...nel.org,
	richard.weiyang@...il.com,
	zhangpeng.00@...edance.com
Cc: linux-kernel@...r.kernel.org,
	Zhen Ni <zhen.ni@...ystack.cn>
Subject: [PATCH] kernel/fork: Optimize by avoiding unnecessary locking for kernel threads

Improves the function by checking if the task is a kernel thread
(PF_KTHREAD) before acquiring the task lock. Kernel threads do not
have an associated executable file, so the function now returns NULL
immediately in such cases. This change reduces unnecessary locking
overhead and simplifies the code logic, while maintaining consistent
behavior for regular tasks.

Signed-off-by: Zhen Ni <zhen.ni@...ystack.cn>
---
 kernel/fork.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index e58d27c05788..9fadde6c7c98 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1500,12 +1500,13 @@ struct file *get_task_exe_file(struct task_struct *task)
 	struct file *exe_file = NULL;
 	struct mm_struct *mm;
 
+	if (task->flags & PF_KTHREAD)
+		return NULL;
+
 	task_lock(task);
 	mm = task->mm;
-	if (mm) {
-		if (!(task->flags & PF_KTHREAD))
-			exe_file = get_mm_exe_file(mm);
-	}
+	if (mm)
+		exe_file = get_mm_exe_file(mm);
 	task_unlock(task);
 	return exe_file;
 }
-- 
2.20.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ