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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240613181613.4329-2-kprateek.nayak@amd.com>
Date: Thu, 13 Jun 2024 18:16:00 +0000
From: K Prateek Nayak <kprateek.nayak@....com>
To: <linux-kernel@...r.kernel.org>
CC: "Gautham R. Shenoy" <gautham.shenoy@....com>, K Prateek Nayak
	<kprateek.nayak@....com>, Richard Henderson <richard.henderson@...aro.org>,
	Ivan Kokshaysky <ink@...assic.park.msu.ru>, Matt Turner <mattst88@...il.com>,
	Russell King <linux@...linux.org.uk>, Guo Ren <guoren@...nel.org>, "Michal
 Simek" <monstr@...str.eu>, Dinh Nguyen <dinguyen@...nel.org>, Jonas Bonn
	<jonas@...thpole.se>, Stefan Kristiansson
	<stefan.kristiansson@...nalahti.fi>, Stafford Horne <shorne@...il.com>,
	"James E.J. Bottomley" <James.Bottomley@...senPartnership.com>, Helge Deller
	<deller@....de>, Michael Ellerman <mpe@...erman.id.au>, Nicholas Piggin
	<npiggin@...il.com>, Christophe Leroy <christophe.leroy@...roup.eu>, "Naveen
 N. Rao" <naveen.n.rao@...ux.ibm.com>, Yoshinori Sato
	<ysato@...rs.sourceforge.jp>, Rich Felker <dalias@...c.org>, "John Paul
 Adrian Glaubitz" <glaubitz@...sik.fu-berlin.de>, "David S. Miller"
	<davem@...emloft.net>, Andreas Larsson <andreas@...sler.com>, Thomas Gleixner
	<tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov
	<bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>, "H. Peter Anvin"
	<hpa@...or.com>, "Rafael J. Wysocki" <rafael@...nel.org>, Daniel Lezcano
	<daniel.lezcano@...aro.org>, Peter Zijlstra <peterz@...radead.org>, "Juri
 Lelli" <juri.lelli@...hat.com>, Vincent Guittot <vincent.guittot@...aro.org>,
	Dietmar Eggemann <dietmar.eggemann@....com>, Steven Rostedt
	<rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>, Mel Gorman
	<mgorman@...e.de>, Daniel Bristot de Oliveira <bristot@...hat.com>, "Valentin
 Schneider" <vschneid@...hat.com>, Andrew Donnellan <ajd@...ux.ibm.com>,
	Benjamin Gray <bgray@...ux.ibm.com>, Frederic Weisbecker
	<frederic@...nel.org>, Xin Li <xin3.li@...el.com>, Kees Cook
	<keescook@...omium.org>, Rick Edgecombe <rick.p.edgecombe@...el.com>, "Tony
 Battersby" <tonyb@...ernetics.com>, Bjorn Helgaas <bhelgaas@...gle.com>,
	"Brian Gerst" <brgerst@...il.com>, Leonardo Bras <leobras@...hat.com>, Imran
 Khan <imran.f.khan@...cle.com>, "Paul E. McKenney" <paulmck@...nel.org>, "Rik
 van Riel" <riel@...riel.com>, Tim Chen <tim.c.chen@...ux.intel.com>, David
 Vernet <void@...ifault.com>, Julia Lawall <julia.lawall@...ia.fr>,
	<linux-alpha@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>,
	<linux-csky@...r.kernel.org>, <linux-openrisc@...r.kernel.org>,
	<linux-parisc@...r.kernel.org>, <linuxppc-dev@...ts.ozlabs.org>,
	<linux-sh@...r.kernel.org>, <sparclinux@...r.kernel.org>,
	<linux-pm@...r.kernel.org>, <x86@...nel.org>
Subject: [PATCH v2 01/14] thread_info: Add helpers to test and clear TIF_NOTIFY_IPI

From: "Gautham R. Shenoy" <gautham.shenoy@....com>

Introduce the notion of TIF_NOTIFY_IPI flag. When a processor in
TIF_POLLING mode needs to process an IPI, the sender sets NEED_RESCHED
bit in idle task's thread_info to pull the target out of idle and avoids
sending an interrupt to the idle CPU. When NEED_RESCHED is set, the
scheduler assumes that a new task has been queued on the idle CPU and
calls schedule_idle(), however, it is not necessary that an IPI on an
idle CPU will necessarily end up waking a task on the said CPU. To avoid
spurious calls to schedule_idle() assuming an IPI on an idle CPU will
always wake a task on the said CPU, TIF_NOTIFY_IPI will be used to pull
a TIF_POLLING CPU out of idle.

Since the IPI handlers are processed before the call to schedule_idle(),
schedule_idle() will be called only if one of the handlers have woken up
a new task on the CPU and has set NEED_RESCHED.

Add tif_notify_ipi() and current_clr_notify_ipi() helpers to test if
TIF_NOTIFY_IPI is set in the current task's thread_info, and to clear it
respectively. These interfaces will be used in subsequent patches as
TIF_NOTIFY_IPI notion is integrated in the scheduler and in the idle
path.

[ prateek: Split the changes into a separate patch, add commit log ]

Cc: Richard Henderson <richard.henderson@...aro.org>
Cc: Ivan Kokshaysky <ink@...assic.park.msu.ru>
Cc: Matt Turner <mattst88@...il.com>
Cc: Russell King <linux@...linux.org.uk>
Cc: Guo Ren <guoren@...nel.org>
Cc: Michal Simek <monstr@...str.eu>
Cc: Dinh Nguyen <dinguyen@...nel.org>
Cc: Jonas Bonn <jonas@...thpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@...nalahti.fi>
Cc: Stafford Horne <shorne@...il.com>
Cc: "James E.J. Bottomley" <James.Bottomley@...senPartnership.com>
Cc: Helge Deller <deller@....de>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Nicholas Piggin <npiggin@...il.com>
Cc: Christophe Leroy <christophe.leroy@...roup.eu>
Cc: "Naveen N. Rao" <naveen.n.rao@...ux.ibm.com>
Cc: Yoshinori Sato <ysato@...rs.sourceforge.jp>
Cc: Rich Felker <dalias@...c.org>
Cc: John Paul Adrian Glaubitz <glaubitz@...sik.fu-berlin.de>
Cc: "David S. Miller" <davem@...emloft.net>
Cc: Andreas Larsson <andreas@...sler.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Borislav Petkov <bp@...en8.de>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: "H. Peter Anvin" <hpa@...or.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>
Cc: Daniel Lezcano <daniel.lezcano@...aro.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Juri Lelli <juri.lelli@...hat.com>
Cc: Vincent Guittot <vincent.guittot@...aro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@....com>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Ben Segall <bsegall@...gle.com>
Cc: Mel Gorman <mgorman@...e.de>
Cc: Daniel Bristot de Oliveira <bristot@...hat.com>
Cc: Valentin Schneider <vschneid@...hat.com>
Cc: Andrew Donnellan <ajd@...ux.ibm.com>
Cc: Benjamin Gray <bgray@...ux.ibm.com>
Cc: Frederic Weisbecker <frederic@...nel.org>
Cc: Xin Li <xin3.li@...el.com>
Cc: Kees Cook <keescook@...omium.org>
Cc: Rick Edgecombe <rick.p.edgecombe@...el.com>
Cc: Tony Battersby <tonyb@...ernetics.com>
Cc: Bjorn Helgaas <bhelgaas@...gle.com>
Cc: Brian Gerst <brgerst@...il.com>
Cc: Leonardo Bras <leobras@...hat.com>
Cc: Imran Khan <imran.f.khan@...cle.com>
Cc: "Paul E. McKenney" <paulmck@...nel.org>
Cc: Rik van Riel <riel@...riel.com>
Cc: Tim Chen <tim.c.chen@...ux.intel.com>
Cc: David Vernet <void@...ifault.com>
Cc: Julia Lawall <julia.lawall@...ia.fr>
Cc: linux-alpha@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Cc: linux-arm-kernel@...ts.infradead.org
Cc: linux-csky@...r.kernel.org
Cc: linux-openrisc@...r.kernel.org
Cc: linux-parisc@...r.kernel.org
Cc: linuxppc-dev@...ts.ozlabs.org
Cc: linux-sh@...r.kernel.org
Cc: sparclinux@...r.kernel.org
Cc: linux-pm@...r.kernel.org
Cc: x86@...nel.org
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@....com>
Co-developed-by: K Prateek Nayak <kprateek.nayak@....com>
Signed-off-by: K Prateek Nayak <kprateek.nayak@....com>
---
v1..v2:
o No changes.
---
 include/linux/thread_info.h | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 9ea0b28068f4..1e10dd8c0227 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -195,6 +195,49 @@ static __always_inline bool tif_need_resched(void)
 
 #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
 
+#ifdef TIF_NOTIFY_IPI
+
+#ifdef _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H
+
+static __always_inline bool tif_notify_ipi(void)
+{
+	return arch_test_bit(TIF_NOTIFY_IPI,
+			     (unsigned long *)(&current_thread_info()->flags));
+}
+
+static __always_inline void current_clr_notify_ipi(void)
+{
+	arch_clear_bit(TIF_NOTIFY_IPI,
+		       (unsigned long *)(&current_thread_info()->flags));
+}
+
+#else
+
+static __always_inline bool tif_notify_ipi(void)
+{
+	return test_bit(TIF_NOTIFY_IPI,
+			(unsigned long *)(&current_thread_info()->flags));
+}
+
+static __always_inline void current_clr_notify_ipi(void)
+{
+	clear_bit(TIF_NOTIFY_IPI,
+		  (unsigned long *)(&current_thread_info()->flags));
+}
+
+#endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
+
+#else /* !TIF_NOTIFY_IPI */
+
+static __always_inline bool tif_notify_ipi(void)
+{
+	return false;
+}
+
+static __always_inline void current_clr_notify_ipi(void) { }
+
+#endif /* TIF_NOTIFY_IPI */
+
 #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
 static inline int arch_within_stack_frames(const void * const stack,
 					   const void * const stackend,
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ