linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v2] callchain: Annotate RCU pointer with __rcu
@ 2020-01-30 14:18 Amol Grover
  2020-02-14 18:20 ` Amol Grover
  0 siblings, 1 reply; 2+ messages in thread
From: Amol Grover @ 2020-01-30 14:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim
  Cc: Paul E . McKenney, linux-kernel, Madhuparna Bhowmik,
	Joel Fernandes, linux-kernel-mentees

Fixes following instances of sparse error
error: incompatible types in comparison expression
(different address spaces)
kernel/events/callchain.c:66:9: error: incompatible types in comparison
kernel/events/callchain.c:96:9: error: incompatible types in comparison
kernel/events/callchain.c:161:19: error: incompatible types in comparison

This introduces the following warning
kernel/events/callchain.c:65:17: warning: incorrect type in assignment
which is fixed as below

callchain_cpus_entries is annotated as an RCU pointer.
Hence rcu_dereference_protected or similar RCU API is
required to dereference the pointer.

Signed-off-by: Amol Grover <frextrite@gmail.com>
---
v2:
- Squash both the commits into a single one.

 kernel/events/callchain.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index c2b41a263166..a672d02a1b3a 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -32,7 +32,7 @@ static inline size_t perf_callchain_entry__sizeof(void)
 static DEFINE_PER_CPU(int, callchain_recursion[PERF_NR_CONTEXTS]);
 static atomic_t nr_callchain_events;
 static DEFINE_MUTEX(callchain_mutex);
-static struct callchain_cpus_entries *callchain_cpus_entries;
+static struct callchain_cpus_entries __rcu *callchain_cpus_entries;
 
 
 __weak void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
@@ -62,7 +62,8 @@ static void release_callchain_buffers(void)
 {
 	struct callchain_cpus_entries *entries;
 
-	entries = callchain_cpus_entries;
+	entries = rcu_dereference_protected(callchain_cpus_entries,
+					    lockdep_is_held(&callchain_mutex));
 	RCU_INIT_POINTER(callchain_cpus_entries, NULL);
 	call_rcu(&entries->rcu_head, release_callchain_buffers_rcu);
 }
-- 
2.24.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v2] callchain: Annotate RCU pointer with __rcu
  2020-01-30 14:18 [Linux-kernel-mentees] [PATCH v2] callchain: Annotate RCU pointer with __rcu Amol Grover
@ 2020-02-14 18:20 ` Amol Grover
  0 siblings, 0 replies; 2+ messages in thread
From: Amol Grover @ 2020-02-14 18:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim
  Cc: Joel Fernandes, Madhuparna Bhowmik, linux-kernel-mentees,
	linux-kernel, Paul E . McKenney

On Thu, Jan 30, 2020 at 07:48:19PM +0530, Amol Grover wrote:
> Fixes following instances of sparse error
> error: incompatible types in comparison expression
> (different address spaces)
> kernel/events/callchain.c:66:9: error: incompatible types in comparison
> kernel/events/callchain.c:96:9: error: incompatible types in comparison
> kernel/events/callchain.c:161:19: error: incompatible types in comparison
> 
> This introduces the following warning
> kernel/events/callchain.c:65:17: warning: incorrect type in assignment
> which is fixed as below
> 
> callchain_cpus_entries is annotated as an RCU pointer.
> Hence rcu_dereference_protected or similar RCU API is
> required to dereference the pointer.
> 
> Signed-off-by: Amol Grover <frextrite@gmail.com>

Hey Peter,

Can you have a look at this patch as well? I have already done the
requested changes.

Thanks
Amol

> ---
> v2:
> - Squash both the commits into a single one.
> 
>  kernel/events/callchain.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
> index c2b41a263166..a672d02a1b3a 100644
> --- a/kernel/events/callchain.c
> +++ b/kernel/events/callchain.c
> @@ -32,7 +32,7 @@ static inline size_t perf_callchain_entry__sizeof(void)
>  static DEFINE_PER_CPU(int, callchain_recursion[PERF_NR_CONTEXTS]);
>  static atomic_t nr_callchain_events;
>  static DEFINE_MUTEX(callchain_mutex);
> -static struct callchain_cpus_entries *callchain_cpus_entries;
> +static struct callchain_cpus_entries __rcu *callchain_cpus_entries;
>  
>  
>  __weak void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
> @@ -62,7 +62,8 @@ static void release_callchain_buffers(void)
>  {
>  	struct callchain_cpus_entries *entries;
>  
> -	entries = callchain_cpus_entries;
> +	entries = rcu_dereference_protected(callchain_cpus_entries,
> +					    lockdep_is_held(&callchain_mutex));
>  	RCU_INIT_POINTER(callchain_cpus_entries, NULL);
>  	call_rcu(&entries->rcu_head, release_callchain_buffers_rcu);
>  }
> -- 
> 2.24.1
> 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-14 18:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30 14:18 [Linux-kernel-mentees] [PATCH v2] callchain: Annotate RCU pointer with __rcu Amol Grover
2020-02-14 18:20 ` Amol Grover

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).