[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220311151656.GA227315@lothringen>
Date: Fri, 11 Mar 2022 16:16:56 +0100
From: Frederic Weisbecker <frederic@...nel.org>
To: nicolas saenz julienne <nsaenz@...nel.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Peter Zijlstra <peterz@...radead.org>,
Phil Auld <pauld@...hat.com>,
Alex Belits <abelits@...vell.com>,
Xiongfeng Wang <wangxiongfeng2@...wei.com>,
Neeraj Upadhyay <quic_neeraju@...cinc.com>,
Thomas Gleixner <tglx@...utronix.de>,
Yu Liao <liaoyu15@...wei.com>,
Boqun Feng <boqun.feng@...il.com>,
"Paul E . McKenney" <paulmck@...nel.org>,
Marcelo Tosatti <mtosatti@...hat.com>,
Paul Gortmaker <paul.gortmaker@...driver.com>,
Uladzislau Rezki <uladzislau.rezki@...y.com>,
Joel Fernandes <joel@...lfernandes.org>
Subject: Re: [PATCH 19/19] context_tracking: Exempt
CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK from non-active tracking
On Tue, Mar 08, 2022 at 05:15:14PM +0100, nicolas saenz julienne wrote:
> Hi Frederic,
>
> On Wed, 2022-03-02 at 16:48 +0100, Frederic Weisbecker wrote:
> > 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@...nel.org>
> > Cc: Paul E. McKenney <paulmck@...nel.org>
> > Cc: Peter Zijlstra <peterz@...radead.org>
> > Cc: Thomas Gleixner <tglx@...utronix.de>
> > Cc: Neeraj Upadhyay <quic_neeraju@...cinc.com>
> > Cc: Uladzislau Rezki <uladzislau.rezki@...y.com>
> > Cc: Joel Fernandes <joel@...lfernandes.org>
> > Cc: Boqun Feng <boqun.feng@...il.com>
> > Cc: Nicolas Saenz Julienne <nsaenz@...nel.org>
> > Cc: Marcelo Tosatti <mtosatti@...hat.com>
> > Cc: Xiongfeng Wang <wangxiongfeng2@...wei.com>
> > Cc: Yu Liao<liaoyu15@...wei.com>
> > Cc: Phil Auld <pauld@...hat.com>
> > Cc: Paul Gortmaker<paul.gortmaker@...driver.com>
> > Cc: Alex Belits <abelits@...vell.com>
> > ---
> > 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)) {
>
> user entry code assumes that state will be kept on all CPUs as long as context
> tracking is enabled. See kernel/entry/common.c:
>
> static __always_inline void __enter_from_user_mode(struct pt_regs *regs)
> {
> arch_check_user_regs(regs);
> lockdep_hardirqs_off(CALLER_ADDR0);
>
> CT_WARN_ON(ct_state() != CONTEXT_USER); <-- NOT HAPPY ABOUT THIS
> CHANGE
Good point!
So I need to do:
#ifdef CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK
#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled_this_cpu() && (cond))
#else
#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled() && (cond))
#endif
Thanks.
> user_exit_irqoff();
>
> instrumentation_begin();
> trace_hardirqs_off_finish();
> instrumentation_end();
> }
>
> Regards,
> Nicolas
Powered by blists - more mailing lists