Skip to contentSkip to conversation

RCU fixes for rcu_assign_pointer() usage

PATCH In review Joel Fernandes (Google) 4 participants 15 messages Mar 21, 2019 – Apr 3, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover RCU fixes for rcu_assign_pointer() usage

This is just a resend with scheduler patches split from the driver fixes and Paul's Reviewed-by(s) added.

These patches fix various sparse errors ccaused as a result of the recent check to add rcu_check_sparse() to rcu_assign_pointer(). The errors are due to missing annotations. The annotations added in the series can also help avoid future incorrect usages and bugs so it is a good idea to do in any case.

RFC v1 -> Patch v2:
Made changes based on Peter Zijlstra review.

Joel Fernandes (Google) (4):
sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu
sched_domain: Annotate RCU pointers properly
rcuwait: Annotate task_struct with __rcu
sched: Annotate perf_domain pointer with __rcu

include/linux/rcuwait.h        |  2 +-
include/linux/sched/topology.h |  4 ++--
kernel/sched/cpufreq.c         |  2 +-
kernel/sched/sched.h           | 18 +++++++++---------
kernel/sched/topology.c        | 10 +++++-----
5 files changed, 18 insertions(+), 18 deletions(-)

--
2.21.0.225.g810b269d1ac-goog

#1 lore raw

PATCH v2 1/4 sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu

Recently I added an RCU annotation check to rcu_assign_pointer(). All pointers assigned to RCU protected data are to be annotated with __rcu inorder to be able to use rcu_assign_pointer() similar to checks in other RCU APIs.

This resulted in a sparse error: kernel//sched/cpufreq.c:41:9: sparse:
error: incompatible types in comparison expression (different address spaces)

Fix this by annotating cpufreq_update_util_data pointer with __rcu. This will also help sparse catch any future RCU misuage bugs.

---
 kernel/sched/cpufreq.c | 2 +-
 kernel/sched/sched.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpufreq.c +1 -1
index 835671f0f917..b5dcd1d83c7f 100644
@@ -7,7 +7,7 @@
  */
 #include "sched.h"
 
-DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
+DEFINE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
 
 /**
  * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer.
kernel/sched/sched.h +1 -1
index efa686eeff26..713715dd00cf 100644
@@ -2185,7 +2185,7 @@ static inline u64 irq_time_read(int cpu)
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 #ifdef CONFIG_CPU_FREQ
-DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
+DECLARE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
 
 /**
  * cpufreq_update_util - Take a note about CPU utilization changes.
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#2 lore raw

[tip:sched/core] sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu

sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu
Commit-ID:  8f9affdf4094bde418a0dbd8b52bb503ee486469
Gitweb:     https://git.kernel.org/tip/8f9affdf4094bde418a0dbd8b52bb503ee486469
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:23 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 09:51:01 +0200

sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu

Recently I added an RCU annotation check to rcu_assign_pointer(). All pointers assigned to RCU protected data are to be annotated with __rcu inorder to be able to use rcu_assign_pointer() similar to checks in other RCU APIs.

This resulted in a sparse error:

kernel//sched/cpufreq.c:41:9: sparse: error: incompatible types in comparison expression (different address spaces)

Fix this by annotating cpufreq_update_util_data pointer with __rcu. This will also help sparse catch any future RCU misuage bugs.

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/sched/cpufreq.c | 2 +-
 kernel/sched/sched.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpufreq.c +1 -1
index 835671f0f917..b5dcd1d83c7f 100644
@@ -7,7 +7,7 @@
  */
 #include "sched.h"
 
-DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
+DEFINE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
 
 /**
  * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer.
kernel/sched/sched.h +1 -1
index efa686eeff26..713715dd00cf 100644
@@ -2185,7 +2185,7 @@ static inline u64 irq_time_read(int cpu)
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 #ifdef CONFIG_CPU_FREQ
-DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
+DECLARE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
 
 /**
  * cpufreq_update_util - Take a note about CPU utilization changes.
#3 lore raw

[tip:sched/core] sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu

In reply to Joel Fernandes (Google)
sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu
Commit-ID:  b10abd0a8859493a93c6b8020f2be2587557749d
Gitweb:     https://git.kernel.org/tip/b10abd0a8859493a93c6b8020f2be2587557749d
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:23 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 12:34:31 +0200

sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu

Recently I added an RCU annotation check to rcu_assign_pointer(). All pointers assigned to RCU protected data are to be annotated with __rcu inorder to be able to use rcu_assign_pointer() similar to checks in other RCU APIs.

This resulted in a sparse error:

kernel//sched/cpufreq.c:41:9: sparse: error: incompatible types in comparison expression (different address spaces)

Fix this by annotating cpufreq_update_util_data pointer with __rcu. This will also help sparse catch any future RCU misuage bugs.

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/sched/cpufreq.c | 2 +-
 kernel/sched/sched.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpufreq.c +1 -1
index 835671f0f917..b5dcd1d83c7f 100644
@@ -7,7 +7,7 @@
  */
 #include "sched.h"
 
-DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
+DEFINE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
 
 /**
  * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer.
kernel/sched/sched.h +1 -1
index efa686eeff26..713715dd00cf 100644
@@ -2185,7 +2185,7 @@ static inline u64 irq_time_read(int cpu)
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 #ifdef CONFIG_CPU_FREQ
-DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
+DECLARE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
 
 /**
  * cpufreq_update_util - Take a note about CPU utilization changes.
#4 lore raw

PATCH v2 2/4 sched_domain: Annotate RCU pointers properly

In reply to Joel Fernandes (Google)

The scheduler uses RCU API in various places to access sched_domain pointers. These cause sparse errors as below.

Many new errors show up because of an annotation check I added to rcu_assign_pointer(). Let us annotate the pointers correctly which also will help sparse catch any potential future bugs.

This fixes the following sparse errors:

rt.c:1681:9: error: incompatible types in comparison expression deadline.c:1904:9: error: incompatible types in comparison expression core.c:519:9: error: incompatible types in comparison expression core.c:1634:17: error: incompatible types in comparison expression fair.c:6193:14: error: incompatible types in comparison expression fair.c:9883:22: error: incompatible types in comparison expression fair.c:9897:9: error: incompatible types in comparison expression sched.h:1287:9: error: incompatible types in comparison expression topology.c:612:9: error: incompatible types in comparison expression topology.c:615:9: error: incompatible types in comparison expression sched.h:1300:9: error: incompatible types in comparison expression topology.c:618:9: error: incompatible types in comparison expression sched.h:1287:9: error: incompatible types in comparison expression topology.c:621:9: error: incompatible types in comparison expression sched.h:1300:9: error: incompatible types in comparison expression topology.c:624:9: error: incompatible types in comparison expression topology.c:671:9: error: incompatible types in comparison expression stats.c:45:17: error: incompatible types in comparison expression fair.c:5998:15: error: incompatible types in comparison expression fair.c:5989:15: error: incompatible types in comparison expression fair.c:5998:15: error: incompatible types in comparison expression fair.c:5989:15: error: incompatible types in comparison expression fair.c:6120:19: error: incompatible types in comparison expression fair.c:6506:14: error: incompatible types in comparison expression fair.c:6515:14: error: incompatible types in comparison expression fair.c:6623:9: error: incompatible types in comparison expression fair.c:5970:17: error: incompatible types in comparison expression fair.c:8642:21: error: incompatible types in comparison expression fair.c:9253:9: error: incompatible types in comparison expression fair.c:9331:9: error: incompatible types in comparison expression fair.c:9519:15: error: incompatible types in comparison expression fair.c:9533:14: error: incompatible types in comparison expression fair.c:9542:14: error: incompatible types in comparison expression fair.c:9567:14: error: incompatible types in comparison expression fair.c:9597:14: error: incompatible types in comparison expression fair.c:9421:16: error: incompatible types in comparison expression fair.c:9421:16: error: incompatible types in comparison expression

---
 include/linux/sched/topology.h |  4 ++--
 kernel/sched/sched.h           | 14 +++++++-------
 kernel/sched/topology.c        | 10 +++++-----
 3 files changed, 14 insertions(+), 14 deletions(-)
include/linux/sched/topology.h +2 -2
index 57c7ed3fe465..cfc0a89a7159 100644
@@ -76,8 +76,8 @@ struct sched_domain_shared {
 
 struct sched_domain {
 	/* These fields must be setup */
-	struct sched_domain *parent;	/* top domain must be null terminated */
-	struct sched_domain *child;	/* bottom domain must be null terminated */
+	struct sched_domain __rcu *parent;	/* top domain must be null terminated */
+	struct sched_domain __rcu *child;	/* bottom domain must be null terminated */
 	struct sched_group *groups;	/* the balancing groups of the domain */
 	unsigned long min_interval;	/* Minimum balance interval ms */
 	unsigned long max_interval;	/* Maximum balance interval ms */
kernel/sched/sched.h +7 -7
index 713715dd00cf..2b452d68ab2e 100644
@@ -869,8 +869,8 @@ struct rq {
 	atomic_t		nr_iowait;
 
 #ifdef CONFIG_SMP
-	struct root_domain	*rd;
-	struct sched_domain	*sd;
+	struct root_domain		*rd;
+	struct sched_domain __rcu	*sd;
 
 	unsigned long		cpu_capacity;
 	unsigned long		cpu_capacity_orig;
@@ -1324,13 +1324,13 @@ static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
 	return sd;
 }
 
-DECLARE_PER_CPU(struct sched_domain *, sd_llc);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_llc);
 DECLARE_PER_CPU(int, sd_llc_size);
 DECLARE_PER_CPU(int, sd_llc_id);
-DECLARE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
-DECLARE_PER_CPU(struct sched_domain *, sd_numa);
-DECLARE_PER_CPU(struct sched_domain *, sd_asym_packing);
-DECLARE_PER_CPU(struct sched_domain *, sd_asym_cpucapacity);
+DECLARE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_numa);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
 extern struct static_key_false sched_asym_cpucapacity;
 
 struct sched_group_capacity {
kernel/sched/topology.c +5 -5
index ab7f371a3a17..64bec54ded3e 100644
@@ -615,13 +615,13 @@ static void destroy_sched_domains(struct sched_domain *sd)
  * the cpumask of the domain), this allows us to quickly tell if
  * two CPUs are in the same cache domain, see cpus_share_cache().
  */
-DEFINE_PER_CPU(struct sched_domain *, sd_llc);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_llc);
 DEFINE_PER_CPU(int, sd_llc_size);
 DEFINE_PER_CPU(int, sd_llc_id);
-DEFINE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
-DEFINE_PER_CPU(struct sched_domain *, sd_numa);
-DEFINE_PER_CPU(struct sched_domain *, sd_asym_packing);
-DEFINE_PER_CPU(struct sched_domain *, sd_asym_cpucapacity);
+DEFINE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_numa);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
 DEFINE_STATIC_KEY_FALSE(sched_asym_cpucapacity);
 
 static void update_top_cache_domain(int cpu)
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#5 lore raw

[tip:sched/core] sched_domain: Annotate RCU pointers properly

sched_domain: Annotate RCU pointers properly
Commit-ID:  8e000ec0716d953f905e8f8ca2a6c71bb31bbf5d
Gitweb:     https://git.kernel.org/tip/8e000ec0716d953f905e8f8ca2a6c71bb31bbf5d
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:24 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 09:51:03 +0200

sched_domain: Annotate RCU pointers properly

The scheduler uses RCU API in various places to access sched_domain pointers. These cause sparse errors as below.

Many new errors show up because of an annotation check I added to rcu_assign_pointer(). Let us annotate the pointers correctly which also will help sparse catch any potential future bugs.

This fixes the following sparse errors:

rt.c:1681:9: error: incompatible types in comparison expression deadline.c:1904:9: error: incompatible types in comparison expression core.c:519:9: error: incompatible types in comparison expression core.c:1634:17: error: incompatible types in comparison expression fair.c:6193:14: error: incompatible types in comparison expression fair.c:9883:22: error: incompatible types in comparison expression fair.c:9897:9: error: incompatible types in comparison expression sched.h:1287:9: error: incompatible types in comparison expression topology.c:612:9: error: incompatible types in comparison expression topology.c:615:9: error: incompatible types in comparison expression sched.h:1300:9: error: incompatible types in comparison expression topology.c:618:9: error: incompatible types in comparison expression sched.h:1287:9: error: incompatible types in comparison expression topology.c:621:9: error: incompatible types in comparison expression sched.h:1300:9: error: incompatible types in comparison expression topology.c:624:9: error: incompatible types in comparison expression topology.c:671:9: error: incompatible types in comparison expression stats.c:45:17: error: incompatible types in comparison expression fair.c:5998:15: error: incompatible types in comparison expression fair.c:5989:15: error: incompatible types in comparison expression fair.c:5998:15: error: incompatible types in comparison expression fair.c:5989:15: error: incompatible types in comparison expression fair.c:6120:19: error: incompatible types in comparison expression fair.c:6506:14: error: incompatible types in comparison expression fair.c:6515:14: error: incompatible types in comparison expression fair.c:6623:9: error: incompatible types in comparison expression fair.c:5970:17: error: incompatible types in comparison expression fair.c:8642:21: error: incompatible types in comparison expression fair.c:9253:9: error: incompatible types in comparison expression fair.c:9331:9: error: incompatible types in comparison expression fair.c:9519:15: error: incompatible types in comparison expression fair.c:9533:14: error: incompatible types in comparison expression fair.c:9542:14: error: incompatible types in comparison expression fair.c:9567:14: error: incompatible types in comparison expression fair.c:9597:14: error: incompatible types in comparison expression fair.c:9421:16: error: incompatible types in comparison expression fair.c:9421:16: error: incompatible types in comparison expression

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/sched/topology.h |  4 ++--
 kernel/sched/sched.h           | 14 +++++++-------
 kernel/sched/topology.c        | 10 +++++-----
 3 files changed, 14 insertions(+), 14 deletions(-)
include/linux/sched/topology.h +2 -2
index 57c7ed3fe465..cfc0a89a7159 100644
@@ -76,8 +76,8 @@ struct sched_domain_shared {
 
 struct sched_domain {
 	/* These fields must be setup */
-	struct sched_domain *parent;	/* top domain must be null terminated */
-	struct sched_domain *child;	/* bottom domain must be null terminated */
+	struct sched_domain __rcu *parent;	/* top domain must be null terminated */
+	struct sched_domain __rcu *child;	/* bottom domain must be null terminated */
 	struct sched_group *groups;	/* the balancing groups of the domain */
 	unsigned long min_interval;	/* Minimum balance interval ms */
 	unsigned long max_interval;	/* Maximum balance interval ms */
kernel/sched/sched.h +7 -7
index 713715dd00cf..2b452d68ab2e 100644
@@ -869,8 +869,8 @@ struct rq {
 	atomic_t		nr_iowait;
 
 #ifdef CONFIG_SMP
-	struct root_domain	*rd;
-	struct sched_domain	*sd;
+	struct root_domain		*rd;
+	struct sched_domain __rcu	*sd;
 
 	unsigned long		cpu_capacity;
 	unsigned long		cpu_capacity_orig;
@@ -1324,13 +1324,13 @@ static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
 	return sd;
 }
 
-DECLARE_PER_CPU(struct sched_domain *, sd_llc);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_llc);
 DECLARE_PER_CPU(int, sd_llc_size);
 DECLARE_PER_CPU(int, sd_llc_id);
-DECLARE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
-DECLARE_PER_CPU(struct sched_domain *, sd_numa);
-DECLARE_PER_CPU(struct sched_domain *, sd_asym_packing);
-DECLARE_PER_CPU(struct sched_domain *, sd_asym_cpucapacity);
+DECLARE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_numa);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
 extern struct static_key_false sched_asym_cpucapacity;
 
 struct sched_group_capacity {
kernel/sched/topology.c +5 -5
index ab7f371a3a17..64bec54ded3e 100644
@@ -615,13 +615,13 @@ static void destroy_sched_domains(struct sched_domain *sd)
  * the cpumask of the domain), this allows us to quickly tell if
  * two CPUs are in the same cache domain, see cpus_share_cache().
  */
-DEFINE_PER_CPU(struct sched_domain *, sd_llc);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_llc);
 DEFINE_PER_CPU(int, sd_llc_size);
 DEFINE_PER_CPU(int, sd_llc_id);
-DEFINE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
-DEFINE_PER_CPU(struct sched_domain *, sd_numa);
-DEFINE_PER_CPU(struct sched_domain *, sd_asym_packing);
-DEFINE_PER_CPU(struct sched_domain *, sd_asym_cpucapacity);
+DEFINE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_numa);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
 DEFINE_STATIC_KEY_FALSE(sched_asym_cpucapacity);
 
 static void update_top_cache_domain(int cpu)
#6 lore raw

[tip:sched/core] sched_domain: Annotate RCU pointers properly

In reply to Joel Fernandes (Google)
sched_domain: Annotate RCU pointers properly
Commit-ID:  994aeb7a93e43d28f6074195ccb03a384342e1bf
Gitweb:     https://git.kernel.org/tip/994aeb7a93e43d28f6074195ccb03a384342e1bf
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:24 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 12:34:31 +0200

sched_domain: Annotate RCU pointers properly

The scheduler uses RCU API in various places to access sched_domain pointers. These cause sparse errors as below.

Many new errors show up because of an annotation check I added to rcu_assign_pointer(). Let us annotate the pointers correctly which also will help sparse catch any potential future bugs.

This fixes the following sparse errors:

rt.c:1681:9: error: incompatible types in comparison expression deadline.c:1904:9: error: incompatible types in comparison expression core.c:519:9: error: incompatible types in comparison expression core.c:1634:17: error: incompatible types in comparison expression fair.c:6193:14: error: incompatible types in comparison expression fair.c:9883:22: error: incompatible types in comparison expression fair.c:9897:9: error: incompatible types in comparison expression sched.h:1287:9: error: incompatible types in comparison expression topology.c:612:9: error: incompatible types in comparison expression topology.c:615:9: error: incompatible types in comparison expression sched.h:1300:9: error: incompatible types in comparison expression topology.c:618:9: error: incompatible types in comparison expression sched.h:1287:9: error: incompatible types in comparison expression topology.c:621:9: error: incompatible types in comparison expression sched.h:1300:9: error: incompatible types in comparison expression topology.c:624:9: error: incompatible types in comparison expression topology.c:671:9: error: incompatible types in comparison expression stats.c:45:17: error: incompatible types in comparison expression fair.c:5998:15: error: incompatible types in comparison expression fair.c:5989:15: error: incompatible types in comparison expression fair.c:5998:15: error: incompatible types in comparison expression fair.c:5989:15: error: incompatible types in comparison expression fair.c:6120:19: error: incompatible types in comparison expression fair.c:6506:14: error: incompatible types in comparison expression fair.c:6515:14: error: incompatible types in comparison expression fair.c:6623:9: error: incompatible types in comparison expression fair.c:5970:17: error: incompatible types in comparison expression fair.c:8642:21: error: incompatible types in comparison expression fair.c:9253:9: error: incompatible types in comparison expression fair.c:9331:9: error: incompatible types in comparison expression fair.c:9519:15: error: incompatible types in comparison expression fair.c:9533:14: error: incompatible types in comparison expression fair.c:9542:14: error: incompatible types in comparison expression fair.c:9567:14: error: incompatible types in comparison expression fair.c:9597:14: error: incompatible types in comparison expression fair.c:9421:16: error: incompatible types in comparison expression fair.c:9421:16: error: incompatible types in comparison expression

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/sched/topology.h |  4 ++--
 kernel/sched/sched.h           | 14 +++++++-------
 kernel/sched/topology.c        | 10 +++++-----
 3 files changed, 14 insertions(+), 14 deletions(-)
include/linux/sched/topology.h +2 -2
index 57c7ed3fe465..cfc0a89a7159 100644
@@ -76,8 +76,8 @@ struct sched_domain_shared {
 
 struct sched_domain {
 	/* These fields must be setup */
-	struct sched_domain *parent;	/* top domain must be null terminated */
-	struct sched_domain *child;	/* bottom domain must be null terminated */
+	struct sched_domain __rcu *parent;	/* top domain must be null terminated */
+	struct sched_domain __rcu *child;	/* bottom domain must be null terminated */
 	struct sched_group *groups;	/* the balancing groups of the domain */
 	unsigned long min_interval;	/* Minimum balance interval ms */
 	unsigned long max_interval;	/* Maximum balance interval ms */
kernel/sched/sched.h +7 -7
index 713715dd00cf..2b452d68ab2e 100644
@@ -869,8 +869,8 @@ struct rq {
 	atomic_t		nr_iowait;
 
 #ifdef CONFIG_SMP
-	struct root_domain	*rd;
-	struct sched_domain	*sd;
+	struct root_domain		*rd;
+	struct sched_domain __rcu	*sd;
 
 	unsigned long		cpu_capacity;
 	unsigned long		cpu_capacity_orig;
@@ -1324,13 +1324,13 @@ static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
 	return sd;
 }
 
-DECLARE_PER_CPU(struct sched_domain *, sd_llc);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_llc);
 DECLARE_PER_CPU(int, sd_llc_size);
 DECLARE_PER_CPU(int, sd_llc_id);
-DECLARE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
-DECLARE_PER_CPU(struct sched_domain *, sd_numa);
-DECLARE_PER_CPU(struct sched_domain *, sd_asym_packing);
-DECLARE_PER_CPU(struct sched_domain *, sd_asym_cpucapacity);
+DECLARE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_numa);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
+DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
 extern struct static_key_false sched_asym_cpucapacity;
 
 struct sched_group_capacity {
kernel/sched/topology.c +5 -5
index ab7f371a3a17..64bec54ded3e 100644
@@ -615,13 +615,13 @@ static void destroy_sched_domains(struct sched_domain *sd)
  * the cpumask of the domain), this allows us to quickly tell if
  * two CPUs are in the same cache domain, see cpus_share_cache().
  */
-DEFINE_PER_CPU(struct sched_domain *, sd_llc);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_llc);
 DEFINE_PER_CPU(int, sd_llc_size);
 DEFINE_PER_CPU(int, sd_llc_id);
-DEFINE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
-DEFINE_PER_CPU(struct sched_domain *, sd_numa);
-DEFINE_PER_CPU(struct sched_domain *, sd_asym_packing);
-DEFINE_PER_CPU(struct sched_domain *, sd_asym_cpucapacity);
+DEFINE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_numa);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
+DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
 DEFINE_STATIC_KEY_FALSE(sched_asym_cpucapacity);
 
 static void update_top_cache_domain(int cpu)
#7 lore raw

PATCH v2 3/4 rcuwait: Annotate task_struct with __rcu

In reply to Joel Fernandes (Google)

This suppresses sparse error generated due to the recently added rcu_assign_pointer sparse check.

percpu-rwsem.c:162:9: sparse: error: incompatible types in comparison expression exit.c:316:16: sparse: error: incompatible types in comparison expression

---
 include/linux/rcuwait.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rcuwait.h +1 -1
index 90bfa3279a01..563290fc194f 100644
@@ -18,7 +18,7 @@
  * awoken.
  */
 struct rcuwait {
-	struct task_struct *task;
+	struct task_struct __rcu *task;
 };
 
 #define __RCUWAIT_INITIALIZER(name)		\
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#8 lore raw

[tip:sched/core] rcuwait: Annotate task_struct with __rcu

rcuwait: Annotate task_struct with __rcu
Commit-ID:  ea3ce866b568e087737df666c2c035496f54fdcb
Gitweb:     https://git.kernel.org/tip/ea3ce866b568e087737df666c2c035496f54fdcb
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:25 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 09:51:04 +0200

rcuwait: Annotate task_struct with __rcu

This suppresses sparse error generated due to the recently added rcu_assign_pointer sparse check.

percpu-rwsem.c:162:9: sparse: error: incompatible types in comparison expression exit.c:316:16: sparse: error: incompatible types in comparison expression

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/rcuwait.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rcuwait.h +1 -1
index 90bfa3279a01..563290fc194f 100644
@@ -18,7 +18,7 @@
  * awoken.
  */
 struct rcuwait {
-	struct task_struct *task;
+	struct task_struct __rcu *task;
 };
 
 #define __RCUWAIT_INITIALIZER(name)		\
#9 lore raw

[tip:sched/core] rcuwait: Annotate task_struct with __rcu

In reply to Joel Fernandes (Google)
rcuwait: Annotate task_struct with __rcu
Commit-ID:  03f4b48edae7d936c5bf23488c1ce3fbe7fc2733
Gitweb:     https://git.kernel.org/tip/03f4b48edae7d936c5bf23488c1ce3fbe7fc2733
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:25 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 12:34:31 +0200

rcuwait: Annotate task_struct with __rcu

This suppresses sparse error generated due to the recently added rcu_assign_pointer sparse check.

percpu-rwsem.c:162:9: sparse: error: incompatible types in comparison expression exit.c:316:16: sparse: error: incompatible types in comparison expression

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/rcuwait.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rcuwait.h +1 -1
index 90bfa3279a01..563290fc194f 100644
@@ -18,7 +18,7 @@
  * awoken.
  */
 struct rcuwait {
-	struct task_struct *task;
+	struct task_struct __rcu *task;
 };
 
 #define __RCUWAIT_INITIALIZER(name)		\
#10 lore raw

PATCH v2 4/4 sched: Annotate perf_domain pointer with __rcu

In reply to Joel Fernandes (Google)

This fixes the following sparse errors in sched/fair.c:

fair.c:6506:14: error: incompatible types in comparison expression fair.c:8642:21: error: incompatible types in comparison expression

Using __rcu will also help sparse catch any future bugs.

---
 kernel/sched/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index 2b452d68ab2e..b52ed1ada0be 100644
@@ -780,7 +780,7 @@ struct root_domain {
 	 * NULL-terminated list of performance domains intersecting with the
 	 * CPUs of the rd. Protected by RCU.
 	 */
-	struct perf_domain	*pd;
+	struct perf_domain __rcu *pd;
 };
 
 extern struct root_domain def_root_domain;
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#11 lore raw

[tip:sched/core] sched/core: Annotate perf_domain pointer with __rcu

sched/core: Annotate perf_domain pointer with __rcu
Commit-ID:  2e7d58babd2a6073d1afb38519e246dd4a423da5
Gitweb:     https://git.kernel.org/tip/2e7d58babd2a6073d1afb38519e246dd4a423da5
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:26 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 09:51:04 +0200

sched/core: Annotate perf_domain pointer with __rcu

This fixes the following sparse errors in sched/fair.c:

fair.c:6506:14: error: incompatible types in comparison expression fair.c:8642:21: error: incompatible types in comparison expression

Using __rcu will also help sparse catch any future bugs.

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/sched/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index 2b452d68ab2e..b52ed1ada0be 100644
@@ -780,7 +780,7 @@ struct root_domain {
 	 * NULL-terminated list of performance domains intersecting with the
 	 * CPUs of the rd. Protected by RCU.
 	 */
-	struct perf_domain	*pd;
+	struct perf_domain __rcu *pd;
 };
 
 extern struct root_domain def_root_domain;
#12 lore raw

[tip:sched/core] sched/core: Annotate perf_domain pointer with __rcu

In reply to Joel Fernandes (Google)
sched/core: Annotate perf_domain pointer with __rcu
Commit-ID:  7ba7319f9e3898101bff5d63cbae5a6cc174c8c9
Gitweb:     https://git.kernel.org/tip/7ba7319f9e3898101bff5d63cbae5a6cc174c8c9
Author:     Joel Fernandes (Google) <[email protected]>
AuthorDate: Wed, 20 Mar 2019 20:34:26 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 3 Apr 2019 12:34:31 +0200

sched/core: Annotate perf_domain pointer with __rcu

This fixes the following sparse errors in sched/fair.c:

fair.c:6506:14: error: incompatible types in comparison expression fair.c:8642:21: error: incompatible types in comparison expression

Using __rcu will also help sparse catch any future bugs.

[ From an RCU perspective. ]
Cc Josh Triplett <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Morten Rasmussen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/sched/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index 2b452d68ab2e..b52ed1ada0be 100644
@@ -780,7 +780,7 @@ struct root_domain {
 	 * NULL-terminated list of performance domains intersecting with the
 	 * CPUs of the rd. Protected by RCU.
 	 */
-	struct perf_domain	*pd;
+	struct perf_domain __rcu *pd;
 };
 
 extern struct root_domain def_root_domain;
maintainer
#13 lore raw
In reply to Joel Fernandes (Google)
Quoted 17 lines · Joel Fernandes (Google)

This is just a resend with scheduler patches split from the driver fixes and Paul's Reviewed-by(s) added.

These patches fix various sparse errors ccaused as a result of the recent check to add rcu_check_sparse() to rcu_assign_pointer(). The errors are due to missing annotations. The annotations added in the series can also help avoid future incorrect usages and bugs so it is a good idea to do in any case.

RFC v1 -> Patch v2:
Made changes based on Peter Zijlstra review.

Joel Fernandes (Google) (4):
sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu
sched_domain: Annotate RCU pointers properly
rcuwait: Annotate task_struct with __rcu
sched: Annotate perf_domain pointer with __rcu

Quoted 6 lines
include/linux/rcuwait.h        |  2 +-
include/linux/sched/topology.h |  4 ++--
kernel/sched/cpufreq.c         |  2 +-
kernel/sched/sched.h           | 18 +++++++++---------
kernel/sched/topology.c        | 10 +++++-----
5 files changed, 18 insertions(+), 18 deletions(-)

Thanks Joel

#14 lore raw
In reply to Joel Fernandes (Google)
Quoted 17 lines · Joel Fernandes (Google)

This is just a resend with scheduler patches split from the driver fixes and Paul's Reviewed-by(s) added.

These patches fix various sparse errors ccaused as a result of the recent check to add rcu_check_sparse() to rcu_assign_pointer(). The errors are due to missing annotations. The annotations added in the series can also help avoid future incorrect usages and bugs so it is a good idea to do in any case.

RFC v1 -> Patch v2:
Made changes based on Peter Zijlstra review.

Joel Fernandes (Google) (4):
sched/cpufreq: Annotate cpufreq_update_util_data pointer with __rcu
sched_domain: Annotate RCU pointers properly
rcuwait: Annotate task_struct with __rcu
sched: Annotate perf_domain pointer with __rcu

Quoted 6 lines
include/linux/rcuwait.h        |  2 +-
include/linux/sched/topology.h |  4 ++--
kernel/sched/cpufreq.c         |  2 +-
kernel/sched/sched.h           | 18 +++++++++---------
kernel/sched/topology.c        | 10 +++++-----
5 files changed, 18 insertions(+), 18 deletions(-)

Looks good to me.

-- Luc