Skip to content

Commit 5d7856e

Browse files
kolyshkinkondors1995
authored andcommitted
sched/headers: Move 'struct sched_param' out of uapi, to work around glibc/musl breakage
Both glibc and musl define 'struct sched_param' in sched.h, while kernel has it in uapi/linux/sched/types.h, making it cumbersome to use sched_getattr(2) or sched_setattr(2) from userspace. For example, something like this: #include <sched.h> #include <linux/sched/types.h> struct sched_attr sa; will result in "error: redefinition of ‘struct sched_param’" (note the code doesn't need sched_param at all -- it needs struct sched_attr plus some stuff from sched.h). The situation is, glibc is not going to provide a wrapper for sched_{get,set}attr, thus the need to include linux/sched_types.h directly, which leads to the above problem. Thus, the userspace is left with a few sub-par choices when it wants to use e.g. sched_setattr(2), such as maintaining a copy of struct sched_attr definition, or using some other ugly tricks. OTOH, 'struct sched_param' is well known, defined in POSIX, and it won't be ever changed (as that would break backward compatibility). So, while 'struct sched_param' is indeed part of the kernel uapi, exposing it the way it's done now creates an issue, and hiding it (like this patch does) fixes that issue, hopefully without creating another one: common userspace software rely on libc headers, and as for "special" software (like libc), it looks like glibc and musl do not rely on kernel headers for 'struct sched_param' definition (but let's Cc their mailing lists in case it's otherwise). The alternative to this patch would be to move struct sched_attr to, say, linux/sched.h, or linux/sched/attr.h (the new file). Oh, and here is the previous attempt to fix the issue: https://lore.kernel.org/all/20200528135552.GA87103@google.com/ While I support Linus arguments, the issue is still here and needs to be fixed. [ mingo: Linus is right, this shouldn't be needed - but on the other hand I agree that this header is not really helpful to user-space as-is. So let's pretend that <uapi/linux/sched/types.h> is only about sched_attr, and call this commit a workaround for user-space breakage that it in reality is ... Also, remove the Fixes tag. ] Change-Id: I3943f8f4a11a9007ccc392de3ece9e62841e8fcb Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20230808030357.1213829-1-kolyshkin@gmail.com
1 parent 983e60f commit 5d7856e

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

include/linux/sched.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct rcu_node;
4848
struct reclaim_state;
4949
struct robust_list_head;
5050
struct sched_attr;
51-
struct sched_param;
5251
struct seq_file;
5352
struct sighand_struct;
5453
struct signal_struct;
@@ -341,6 +340,10 @@ enum uclamp_id {
341340
UCLAMP_CNT
342341
};
343342

343+
struct sched_param {
344+
int sched_priority;
345+
};
346+
344347
struct sched_info {
345348
#ifdef CONFIG_SCHED_INFO
346349
/* Cumulative counters: */

include/uapi/linux/sched/types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
#include <linux/types.h>
66

7-
struct sched_param {
8-
int sched_priority;
9-
};
10-
117
#define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */
128
#define SCHED_ATTR_SIZE_VER1 56 /* add: util_{min,max} */
139

0 commit comments

Comments
 (0)