Message ID | 1464803536-19929-1-git-send-email-catalin.marinas@arm.com (mailing list archive) |
---|---|
State | Accepted, archived |
Delegated to: | Rafael Wysocki |
Headers | show |
On Wednesday, June 01, 2016 06:52:16 PM Catalin Marinas wrote: > The cpuidle_devices per-CPU variable is only defined when CPU_IDLE is > enabled. Commit c8cc7d4de7a4 ("sched/idle: Reorganize the idle loop") > removed the #ifdef CONFIG_CPU_IDLE around cpuidle_idle_call() with the > compiler optimising away __this_cpu_read(cpuidle_devices). However, with > CONFIG_UBSAN && !CONFIG_CPU_IDLE, this optimisation no longer happens > and the kernel fails to link since cpuidle_devices is not defined. > > This patch introduces an accessor function for the current CPU cpuidle > device (returning NULL when !CONFIG_CPU_IDLE) and uses it in > cpuidle_idle_call(). > > Cc: Rafael J. Wysocki <rjw@rjwysocki.net> > Cc: Daniel Lezcano <daniel.lezcano@linaro.org> > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> OK Is this needed in -stable? > --- > > This fixes a build failure on arm64 with UBSAN && !CPU_IDLE and gcc > 5.3.1 (probably other compiler versions would behave in the same way). > > I tried to keep close to the existing coding style in cpuidle.h. > > include/linux/cpuidle.h | 3 +++ > kernel/sched/idle.c | 2 +- > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h > index 786ad32631a6..07b83d32f66c 100644 > --- a/include/linux/cpuidle.h > +++ b/include/linux/cpuidle.h > @@ -152,6 +152,8 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev); > extern int cpuidle_play_dead(void); > > extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev); > +static inline struct cpuidle_device *cpuidle_get_device(void) > +{return __this_cpu_read(cpuidle_devices); } > #else > static inline void disable_cpuidle(void) { } > static inline bool cpuidle_not_available(struct cpuidle_driver *drv, > @@ -187,6 +189,7 @@ static inline void cpuidle_disable_device(struct cpuidle_device *dev) { } > static inline int cpuidle_play_dead(void) {return -ENODEV; } > static inline struct cpuidle_driver *cpuidle_get_cpu_driver( > struct cpuidle_device *dev) {return NULL; } > +static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; } > #endif > > #if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND) > diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c > index bd12c6c714ec..c5aeedf4e93a 100644 > --- a/kernel/sched/idle.c > +++ b/kernel/sched/idle.c > @@ -127,7 +127,7 @@ static int call_cpuidle(struct cpuidle_driver *drv, struct cpuidle_device *dev, > */ > static void cpuidle_idle_call(void) > { > - struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); > + struct cpuidle_device *dev = cpuidle_get_device(); > struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); > int next_state, entered_state; > -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jun 01, 2016 at 10:20:03PM +0200, Rafael J. Wysocki wrote: > On Wednesday, June 01, 2016 06:52:16 PM Catalin Marinas wrote: > > The cpuidle_devices per-CPU variable is only defined when CPU_IDLE is > > enabled. Commit c8cc7d4de7a4 ("sched/idle: Reorganize the idle loop") > > removed the #ifdef CONFIG_CPU_IDLE around cpuidle_idle_call() with the > > compiler optimising away __this_cpu_read(cpuidle_devices). However, with > > CONFIG_UBSAN && !CONFIG_CPU_IDLE, this optimisation no longer happens > > and the kernel fails to link since cpuidle_devices is not defined. > > > > This patch introduces an accessor function for the current CPU cpuidle > > device (returning NULL when !CONFIG_CPU_IDLE) and uses it in > > cpuidle_idle_call(). > > > > Cc: Rafael J. Wysocki <rjw@rjwysocki.net> > > Cc: Daniel Lezcano <daniel.lezcano@linaro.org> > > Cc: Ingo Molnar <mingo@redhat.com> > > Cc: Peter Zijlstra <peterz@infradead.org> > > Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> > > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> > > OK > > Is this needed in -stable? Not sure how common this config combination is (I was just testing different options and came across it). Even though it's not a fix for UBSAN, we could add it up to 4.5 since that's when UBSAN was merged: Cc: <stable@vger.kernel.org> # 4.5+
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 786ad32631a6..07b83d32f66c 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -152,6 +152,8 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev); extern int cpuidle_play_dead(void); extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev); +static inline struct cpuidle_device *cpuidle_get_device(void) +{return __this_cpu_read(cpuidle_devices); } #else static inline void disable_cpuidle(void) { } static inline bool cpuidle_not_available(struct cpuidle_driver *drv, @@ -187,6 +189,7 @@ static inline void cpuidle_disable_device(struct cpuidle_device *dev) { } static inline int cpuidle_play_dead(void) {return -ENODEV; } static inline struct cpuidle_driver *cpuidle_get_cpu_driver( struct cpuidle_device *dev) {return NULL; } +static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; } #endif #if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index bd12c6c714ec..c5aeedf4e93a 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -127,7 +127,7 @@ static int call_cpuidle(struct cpuidle_driver *drv, struct cpuidle_device *dev, */ static void cpuidle_idle_call(void) { - struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); + struct cpuidle_device *dev = cpuidle_get_device(); struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); int next_state, entered_state;
The cpuidle_devices per-CPU variable is only defined when CPU_IDLE is enabled. Commit c8cc7d4de7a4 ("sched/idle: Reorganize the idle loop") removed the #ifdef CONFIG_CPU_IDLE around cpuidle_idle_call() with the compiler optimising away __this_cpu_read(cpuidle_devices). However, with CONFIG_UBSAN && !CONFIG_CPU_IDLE, this optimisation no longer happens and the kernel fails to link since cpuidle_devices is not defined. This patch introduces an accessor function for the current CPU cpuidle device (returning NULL when !CONFIG_CPU_IDLE) and uses it in cpuidle_idle_call(). Cc: Rafael J. Wysocki <rjw@rjwysocki.net> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> --- This fixes a build failure on arm64 with UBSAN && !CPU_IDLE and gcc 5.3.1 (probably other compiler versions would behave in the same way). I tried to keep close to the existing coding style in cpuidle.h. include/linux/cpuidle.h | 3 +++ kernel/sched/idle.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html