All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Mark Rutland" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Marco Elver <elver@google.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: core/entry] thread_info: Add helpers to snapshot thread flags
Date: Tue, 30 Nov 2021 23:08:47 -0000	[thread overview]
Message-ID: <163831372740.11128.1099016936986607543.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20211129130653.2037928-2-mark.rutland@arm.com>

The following commit has been merged into the core/entry branch of tip:

Commit-ID:     7ad639840acf2800b5f387c495795f995a67a329
Gitweb:        https://git.kernel.org/tip/7ad639840acf2800b5f387c495795f995a67a329
Author:        Mark Rutland <mark.rutland@arm.com>
AuthorDate:    Mon, 29 Nov 2021 13:06:43 
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 01 Dec 2021 00:06:43 +01:00

thread_info: Add helpers to snapshot thread flags

In <linux/thread_info.h> there are 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, add 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@arm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Marco Elver <elver@google.com>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20211129130653.2037928-2-mark.rutland@arm.com

---
 include/linux/thread_info.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index ad0c4e0..73a6f34 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -118,6 +118,15 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
 	return test_bit(flag, (unsigned long *)&ti->flags);
 }
 
+/*
+ * This may be used in noinstr code, and needs to be __always_inline to prevent
+ * inadvertent instrumentation.
+ */
+static __always_inline unsigned long read_ti_thread_flags(struct thread_info *ti)
+{
+	return READ_ONCE(ti->flags);
+}
+
 #define set_thread_flag(flag) \
 	set_ti_thread_flag(current_thread_info(), flag)
 #define clear_thread_flag(flag) \
@@ -130,6 +139,11 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
 	test_and_clear_ti_thread_flag(current_thread_info(), flag)
 #define test_thread_flag(flag) \
 	test_ti_thread_flag(current_thread_info(), flag)
+#define read_thread_flags() \
+	read_ti_thread_flags(current_thread_info())
+
+#define read_task_thread_flags(t) \
+	read_ti_thread_flags(task_thread_info(t))
 
 #ifdef CONFIG_GENERIC_ENTRY
 #define set_syscall_work(fl) \

  reply	other threads:[~2021-11-30 23:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 13:06 [PATCH v8 00/11] thread_info: use helpers to snapshot thread flags Mark Rutland
2021-11-29 13:06 ` [PATCH v8 01/11] thread_info: add " Mark Rutland
2021-11-30 23:08   ` tip-bot2 for Mark Rutland [this message]
2021-11-29 13:06 ` [PATCH v8 02/11] entry: " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] entry: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 03/11] sched: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] sched: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 04/11] alpha: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] alpha: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 05/11] arm: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] ARM: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 06/11] arm64: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] arm64: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 07/11] microblaze: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] microblaze: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 08/11] openrisc: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] openrisc: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 09/11] powerpc: avoid discarding flags in system_call_exception() Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] powerpc: Avoid " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 10/11] powerpc: snapshot thread flags Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] powerpc: Snapshot " tip-bot2 for Mark Rutland
2021-11-29 13:06 ` [PATCH v8 11/11] x86: snapshot " Mark Rutland
2021-11-30 23:08   ` [tip: core/entry] x86: Snapshot " tip-bot2 for Mark Rutland
  -- strict thread matches above, loose matches on Subject: below --
2021-11-17 16:30 [PATCHv7 01/11] thread_info: add helpers to snapshot " Mark Rutland
2021-11-26 20:23 ` [tip: core/entry] thread_info: Add " tip-bot2 for Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=163831372740.11128.1099016936986607543.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=boqun.feng@gmail.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.