1 From 02c2586bfbf3302dfdcbdfca4ee840928b64aa47 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 13 Oct 2020 07:31:14 +0200
4 Subject: sched/features: Fix !CONFIG_JUMP_LABEL case
6 From: Juri Lelli <juri.lelli@redhat.com>
8 [ Upstream commit a73f863af4ce9730795eab7097fb2102e6854365 ]
12 765cc3a4b224e ("sched/core: Optimize sched_feat() for !CONFIG_SCHED_DEBUG builds")
14 made sched features static for !CONFIG_SCHED_DEBUG configurations, but
15 overlooked the CONFIG_SCHED_DEBUG=y and !CONFIG_JUMP_LABEL cases.
17 For the latter echoing changes to /sys/kernel/debug/sched_features has
18 the nasty effect of effectively changing what sched_features reports,
19 but without actually changing the scheduler behaviour (since different
20 translation units get different sysctl_sched_features).
22 Fix CONFIG_SCHED_DEBUG=y and !CONFIG_JUMP_LABEL configurations by properly
25 Fixes: 765cc3a4b224e ("sched/core: Optimize sched_feat() for !CONFIG_SCHED_DEBUG builds")
26 Co-developed-by: Daniel Bristot de Oliveira <bristot@redhat.com>
27 Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
28 Signed-off-by: Juri Lelli <juri.lelli@redhat.com>
29 Signed-off-by: Ingo Molnar <mingo@kernel.org>
30 Acked-by: Patrick Bellasi <patrick.bellasi@matbug.net>
31 Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
32 Link: https://lore.kernel.org/r/20201013053114.160628-1-juri.lelli@redhat.com
33 Signed-off-by: Sasha Levin <sashal@kernel.org>
35 kernel/sched/core.c | 2 +-
36 kernel/sched/sched.h | 13 ++++++++++---
37 2 files changed, 11 insertions(+), 4 deletions(-)
39 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
40 index faef74f632620..b166320f7633e 100644
41 --- a/kernel/sched/core.c
42 +++ b/kernel/sched/core.c
45 DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
47 -#if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_JUMP_LABEL)
48 +#ifdef CONFIG_SCHED_DEBUG
50 * Debugging: various feature bits
52 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
53 index 5f0eb4565957f..41b7954be68b7 100644
54 --- a/kernel/sched/sched.h
55 +++ b/kernel/sched/sched.h
56 @@ -1361,7 +1361,7 @@ enum {
60 -#if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_JUMP_LABEL)
61 +#ifdef CONFIG_SCHED_DEBUG
64 * To support run-time toggling of sched features, all the translation units
65 @@ -1369,6 +1369,7 @@ enum {
67 extern const_debug unsigned int sysctl_sched_features;
69 +#ifdef CONFIG_JUMP_LABEL
70 #define SCHED_FEAT(name, enabled) \
71 static __always_inline bool static_branch_##name(struct static_key *key) \
73 @@ -1381,7 +1382,13 @@ static __always_inline bool static_branch_##name(struct static_key *key) \
74 extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
75 #define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
77 -#else /* !(SCHED_DEBUG && CONFIG_JUMP_LABEL) */
78 +#else /* !CONFIG_JUMP_LABEL */
80 +#define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
82 +#endif /* CONFIG_JUMP_LABEL */
84 +#else /* !SCHED_DEBUG */
87 * Each translation unit has its own copy of sysctl_sched_features to allow
88 @@ -1397,7 +1404,7 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =
90 #define sched_feat(x) !!(sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
92 -#endif /* SCHED_DEBUG && CONFIG_JUMP_LABEL */
93 +#endif /* SCHED_DEBUG */
95 extern struct static_key_false sched_numa_balancing;
96 extern struct static_key_false sched_schedstats;