[PATCH 19/19] context_tracking: Exempt CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK from non-active tracking
From: Frederic Weisbecker
Date: Wed Mar 02 2022 - 10:50:28 EST
Since a CPU may save the state of the context tracking using
exception_enter() before calling into schedule(), we need all CPUs in
the system to track user <-> kernel transitions and not just those that
really need it (nohz_full CPUs).
The following illustrates the issue that could otherwise happen:
CPU 0 (not tracking) CPU 1 (tracking)
------------------- --------------------
// we are past user_enter()
// but this CPU is always in
// CONTEXT_KERNEL
// because it doesn't track user <-> kernel
ctx = exception_enter(); //ctx == CONTEXT_KERNEL
schedule();
===========================================>
return from schedule();
exception_exit(ctx);
//go to user in CONTEXT_KERNEL
However CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK doesn't play those
games because schedule() can't be called between user_enter() and
user_exit() under such config. In this situation we can spare context
tracking on the CPUs that don't need it.
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
Cc: Paul E. McKenney <paulmck@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Neeraj Upadhyay <quic_neeraju@xxxxxxxxxxx>
Cc: Uladzislau Rezki <uladzislau.rezki@xxxxxxxx>
Cc: Joel Fernandes <joel@xxxxxxxxxxxxxxxxx>
Cc: Boqun Feng <boqun.feng@xxxxxxxxx>
Cc: Nicolas Saenz Julienne <nsaenz@xxxxxxxxxx>
Cc: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
Cc: Xiongfeng Wang <wangxiongfeng2@xxxxxxxxxx>
Cc: Yu Liao<liaoyu15@xxxxxxxxxx>
Cc: Phil Auld <pauld@xxxxxxxxxx>
Cc: Paul Gortmaker<paul.gortmaker@xxxxxxxxxxxxx>
Cc: Alex Belits <abelits@xxxxxxxxxxx>
---
kernel/context_tracking.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c
index 87e7b748791c..b1934264f77f 100644
--- a/kernel/context_tracking.c
+++ b/kernel/context_tracking.c
@@ -374,7 +374,7 @@ void noinstr __ct_user_enter(enum ctx_state state)
* when the CPU runs in userspace.
*/
ct_kernel_exit(true, RCU_DYNTICKS_IDX + state);
- } else {
+ } else if (!IS_ENABLED(CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK)) {
/*
* Even if context tracking is disabled on this CPU, because it's outside
* the full dynticks mask for example, we still have to keep track of the
@@ -384,7 +384,8 @@ void noinstr __ct_user_enter(enum ctx_state state)
* handler and then migrate to another CPU, that new CPU must know where
* the exception returns by the time we call exception_exit().
* This information can only be provided by the previous CPU when it called
- * exception_enter().
+ * exception_enter(). CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK is
+ * excused though because it doesn't use exception_enter().
* OTOH we can spare the calls to vtime and RCU when context_tracking.active
* is false because we know that CPU is not tickless.
*/
@@ -460,7 +461,7 @@ void noinstr __ct_user_exit(enum ctx_state state)
trace_user_exit(0);
instrumentation_end();
}
- } else {
+ } else if (!IS_ENABLED(CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK)) {
atomic_sub(state, &ct->state);
}
}
--
2.25.1