mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com,
	kernel-team@fb.com, mingo@kernel.org
Cc: elver@google.com, andreyknvl@google.com, glider@google.com,
	dvyukov@google.com, cai@lca.pw, boqun.feng@gmail.com,
	Mark Rutland <mark.rutland@arm.com>,
	"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH kcsan 01/29] kcsan: Refactor reading of instrumented memory
Date: Tue, 14 Dec 2021 14:04:11 -0800	[thread overview]
Message-ID: <20211214220439.2236564-1-paulmck@kernel.org> (raw)
In-Reply-To: <20211214220356.GA2236323@paulmck-ThinkPad-P17-Gen-1>

From: Marco Elver <elver@google.com>

Factor out the switch statement reading instrumented memory into a
helper read_instrumented_memory().

No functional change.

Signed-off-by: Marco Elver <elver@google.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 kernel/kcsan/core.c | 51 +++++++++++++++------------------------------
 1 file changed, 17 insertions(+), 34 deletions(-)

diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c
index 4b84c8e7884b4..6bfd3040f46be 100644
--- a/kernel/kcsan/core.c
+++ b/kernel/kcsan/core.c
@@ -325,6 +325,21 @@ static void delay_access(int type)
 	udelay(delay);
 }
 
+/*
+ * Reads the instrumented memory for value change detection; value change
+ * detection is currently done for accesses up to a size of 8 bytes.
+ */
+static __always_inline u64 read_instrumented_memory(const volatile void *ptr, size_t size)
+{
+	switch (size) {
+	case 1:  return READ_ONCE(*(const u8 *)ptr);
+	case 2:  return READ_ONCE(*(const u16 *)ptr);
+	case 4:  return READ_ONCE(*(const u32 *)ptr);
+	case 8:  return READ_ONCE(*(const u64 *)ptr);
+	default: return 0; /* Ignore; we do not diff the values. */
+	}
+}
+
 void kcsan_save_irqtrace(struct task_struct *task)
 {
 #ifdef CONFIG_TRACE_IRQFLAGS
@@ -482,23 +497,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned
 	 * Read the current value, to later check and infer a race if the data
 	 * was modified via a non-instrumented access, e.g. from a device.
 	 */
-	old = 0;
-	switch (size) {
-	case 1:
-		old = READ_ONCE(*(const u8 *)ptr);
-		break;
-	case 2:
-		old = READ_ONCE(*(const u16 *)ptr);
-		break;
-	case 4:
-		old = READ_ONCE(*(const u32 *)ptr);
-		break;
-	case 8:
-		old = READ_ONCE(*(const u64 *)ptr);
-		break;
-	default:
-		break; /* ignore; we do not diff the values */
-	}
+	old = read_instrumented_memory(ptr, size);
 
 	/*
 	 * Delay this thread, to increase probability of observing a racy
@@ -511,23 +510,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned
 	 * racy access.
 	 */
 	access_mask = ctx->access_mask;
-	new = 0;
-	switch (size) {
-	case 1:
-		new = READ_ONCE(*(const u8 *)ptr);
-		break;
-	case 2:
-		new = READ_ONCE(*(const u16 *)ptr);
-		break;
-	case 4:
-		new = READ_ONCE(*(const u32 *)ptr);
-		break;
-	case 8:
-		new = READ_ONCE(*(const u64 *)ptr);
-		break;
-	default:
-		break; /* ignore; we do not diff the values */
-	}
+	new = read_instrumented_memory(ptr, size);
 
 	diff = old ^ new;
 	if (access_mask)
-- 
2.31.1.189.g2e36527f23


  reply	other threads:[~2021-12-14 22:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14 22:03 [PATCH kcsan 0/29] Kernel Concurrency Sanitizer (KCSAN) updates for v5.17 Paul E. McKenney
2021-12-14 22:04 ` Paul E. McKenney [this message]
2021-12-14 22:04 ` [PATCH kcsan 02/29] kcsan: Remove redundant zero-initialization of globals Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 03/29] kcsan: Avoid checking scoped accesses from nested contexts Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 04/29] kcsan: Add core support for a subset of weak memory modeling Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 05/29] kcsan: Add core memory barrier instrumentation functions Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 06/29] kcsan, kbuild: Add option for barrier instrumentation only Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 07/29] kcsan: Call scoped accesses reordered in reports Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 08/29] kcsan: Show location access was reordered to Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 09/29] kcsan: Document modeling of weak memory Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 10/29] kcsan: test: Match reordered or normal accesses Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 11/29] kcsan: test: Add test cases for memory barrier instrumentation Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 12/29] kcsan: Ignore GCC 11+ warnings about TSan runtime support Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 13/29] kcsan: selftest: Add test case to check memory barrier instrumentation Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 14/29] locking/barriers, kcsan: Add instrumentation for barriers Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 15/29] locking/barriers, kcsan: Support generic instrumentation Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 16/29] locking/atomics, kcsan: Add instrumentation for barriers Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 17/29] asm-generic/bitops, " Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 18/29] x86/barriers, kcsan: Use generic instrumentation for non-smp barriers Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 19/29] x86/qspinlock, kcsan: Instrument barrier of pv_queued_spin_unlock() Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 20/29] mm, kcsan: Enable barrier instrumentation Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 21/29] sched, kcsan: Enable memory " Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 22/29] objtool, kcsan: Add memory barrier instrumentation to whitelist Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 23/29] objtool, kcsan: Remove memory barrier instrumentation from noinstr Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 24/29] compiler_attributes.h: Add __disable_sanitizer_instrumentation Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 25/29] kcsan: Support WEAK_MEMORY with Clang where no objtool support exists Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 26/29] kcsan: Make barrier tests compatible with lockdep Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 27/29] kcsan: Turn barrier instrumentation into macros Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 28/29] kcsan: Avoid nested contexts reading inconsistent reorder_access Paul E. McKenney
2021-12-14 22:04 ` [PATCH kcsan 29/29] kcsan: Only test clear_bit_unlock_is_negative_byte if arch defines it Paul E. McKenney

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=20211214220439.2236564-1-paulmck@kernel.org \
    --to=paulmck@kernel.org \
    --cc=andreyknvl@google.com \
    --cc=boqun.feng@gmail.com \
    --cc=cai@lca.pw \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®