[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANpmjNOvnqE29mMU++K0VMibF8xMixJXRDqbDKXjXuxobAfM1Q@mail.gmail.com>
Date: Thu, 10 Jun 2021 11:01:34 +0200
From: Marco Elver <elver@...gle.com>
To: Mark Rutland <mark.rutland@....com>
Cc: LKML <linux-kernel@...r.kernel.org>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Boqun Feng <boqun.feng@...il.com>,
Borislav Petkov <bp@...en8.de>,
Catalin Marinas <catalin.marinas@....com>,
Dmitry Vyukov <dvyukov@...gle.com>,
Ivan Kokshaysky <ink@...assic.park.msu.ru>, jonas@...thpole.se,
juri.lelli@...hat.com,
Russell King - ARM Linux admin <linux@...linux.org.uk>,
Andy Lutomirski <luto@...nel.org>,
Matt Turner <mattst88@...il.com>,
Ingo Molnar <mingo@...hat.com>,
Michal Simek <monstr@...str.eu>,
Michael Ellerman <mpe@...erman.id.au>,
"Paul E. McKenney" <paulmck@...nel.org>,
Paul Mackerras <paulus@...ba.org>,
Peter Zijlstra <peterz@...radead.org>,
Richard Henderson <rth@...ddle.net>, shorne@...il.com,
stefan.kristiansson@...nalahti.fi,
Thomas Gleixner <tglx@...utronix.de>,
vincent.guittot@...aro.org, Will Deacon <will@...nel.org>
Subject: Re: [RFC PATCH 01/10] thread_info: add helpers to snapshot thread flags
On Wed, 9 Jun 2021 at 14:20, Mark Rutland <mark.rutland@....com> wrote:
>
> We have common helpers to manipulate individual thread flags, but where
> code wants to check several flags at once, it must open code reading
> current_thread_info()->flags and operating on a snapshot.
>
> As some flags can be set remotely it's necessary to use READ_ONCE() to
> get a consistent snapshot even when IRQs are disabled, but some code
> forgets to do this. Generally this is unlike to cause a problem in
> practice, but it is somewhat unsound, and KCSAN will legitimately warn
> that there is a data race.
>
> To make it easier to do the right thing, and to highlight that
> concurrent modification is possible, let's add a new helpers to snapshot
> the flags, which should be used in preference to plain reads.
> Subsequent patches will move existing code to use the new helpers.
>
> Signed-off-by: Mark Rutland <mark.rutland@....com>
> Cc: Boqun Feng <boqun.feng@...il.com>
> Cc: Dmitry Vyukov <dvyukov@...gle.com>
> Cc: Marco Elver <elver@...gle.com>
> Cc: Paul E. McKenney <paulmck@...nel.org>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: Will Deacon <will@...nel.org>
Acked-by: Marco Elver <elver@...gle.com>
> ---
> include/linux/thread_info.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
> index 157762db9d4b..f3769842046d 100644
> --- a/include/linux/thread_info.h
> +++ b/include/linux/thread_info.h
> @@ -117,6 +117,11 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
> return test_bit(flag, (unsigned long *)&ti->flags);
> }
>
> +static inline unsigned long read_ti_thread_flags(struct thread_info *ti)
> +{
> + return READ_ONCE(ti->flags);
> +}
> +
Are some of the callers 'noinstr'? I haven't seen it in this series
yet, but if yes, then not inlining (which some compilers may do with
heavier instrumentation) might cause issues and this could be
__always_inline.
Thanks,
-- Marco
Powered by blists - more mailing lists