From: Amol Grover <frextrite@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
Joel Fernandes <joel@joelfernandes.org>,
Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Amol Grover <frextrite@gmail.com>
Subject: [PATCH] events: Annotate parent_ctx with __rcu
Date: Sat, 8 Feb 2020 20:16:49 +0530 [thread overview]
Message-ID: <20200208144648.18833-1-frextrite@gmail.com> (raw)
parent_ctx is used under RCU context in kernel/events/core.c,
tell sparse about it aswell.
Fixes the following instances of sparse error:
kernel/events/core.c:3221:18: error: incompatible types in comparison
kernel/events/core.c:3222:23: error: incompatible types in comparison
This introduces the following two sparse errors:
kernel/events/core.c:3117:18: error: incompatible types in comparison
kernel/events/core.c:3121:30: error: incompatible types in comparison
Hence, use rcu_dereference() to access parent_ctx and silence
the newly introduced errors.
Signed-off-by: Amol Grover <frextrite@gmail.com>
---
include/linux/perf_event.h | 2 +-
kernel/events/core.c | 11 ++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 6d4c22aee384..e18a7bdc6f98 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -810,7 +810,7 @@ struct perf_event_context {
* These fields let us detect when two contexts have both
* been cloned (inherited) from a common ancestor.
*/
- struct perf_event_context *parent_ctx;
+ struct perf_event_context __rcu *parent_ctx;
u64 parent_gen;
u64 generation;
int pin_count;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2173c23c25b4..2a8c5670b254 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3106,26 +3106,31 @@ static void ctx_sched_out(struct perf_event_context *ctx,
static int context_equiv(struct perf_event_context *ctx1,
struct perf_event_context *ctx2)
{
+ struct perf_event_context *parent_ctx1, *parent_ctx2;
+
lockdep_assert_held(&ctx1->lock);
lockdep_assert_held(&ctx2->lock);
+ parent_ctx1 = rcu_dereference(ctx1->parent_ctx);
+ parent_ctx2 = rcu_dereference(ctx2->parent_ctx);
+
/* Pinning disables the swap optimization */
if (ctx1->pin_count || ctx2->pin_count)
return 0;
/* If ctx1 is the parent of ctx2 */
- if (ctx1 == ctx2->parent_ctx && ctx1->generation == ctx2->parent_gen)
+ if (ctx1 == parent_ctx2 && ctx1->generation == ctx2->parent_gen)
return 1;
/* If ctx2 is the parent of ctx1 */
- if (ctx1->parent_ctx == ctx2 && ctx1->parent_gen == ctx2->generation)
+ if (parent_ctx1 == ctx2 && ctx1->parent_gen == ctx2->generation)
return 1;
/*
* If ctx1 and ctx2 have the same parent; we flatten the parent
* hierarchy, see perf_event_init_context().
*/
- if (ctx1->parent_ctx && ctx1->parent_ctx == ctx2->parent_ctx &&
+ if (ctx1->parent_ctx && parent_ctx1 == parent_ctx2 &&
ctx1->parent_gen == ctx2->parent_gen)
return 1;
--
2.24.1
next reply other threads:[~2020-02-08 14:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-08 14:46 Amol Grover [this message]
2020-02-10 9:36 ` [PATCH] events: Annotate parent_ctx with __rcu Peter Zijlstra
2020-02-10 12:59 ` Amol Grover
2020-02-10 13:34 ` Peter Zijlstra
2020-02-10 16:47 ` Amol Grover
2020-02-10 17:08 ` Joel Fernandes
2020-02-13 6:44 ` Amol Grover
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=20200208144648.18833-1-frextrite@gmail.com \
--to=frextrite@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=joel@joelfernandes.org \
--cc=jolsa@redhat.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madhuparnabhowmik10@gmail.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.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