mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] sched: fix build with GCC_PLUGIN_RANDSTRUCT
@ 2020-06-28  7:27 Mike Rapoport
  2020-06-28 12:58 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Rapoport @ 2020-06-28  7:27 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Kees Cook, Mike Rapoport, Steven Rostedt, Dietmar Eggemann,
	Ben Segall, Mel Gorman, linux-kernel

From: Mike Rapoport <rppt@linux.ibm.com>

Since the commit a148866489fb ("sched: Replace rq::wake_list")
task_struct and CSD_TYPE_TTWU objects can be on the same queue and this
requires that have layout similar enough.

This assumption is broken when CONFIG_GCC_PLUGIN_RANDSTRUCT is enabled:

  CHK     include/generated/compile.h
  CC      kernel/smp.o
In file included from arch/x86/include/asm/atomic.h:5,
                 from include/linux/atomic.h:7,
                 from include/linux/llist.h:51,
                 from include/linux/irq_work.h:5,
                 from kernel/smp.c:10:
kernel/smp.c: In function ‘smp_init’:
include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_157’ declared with attribute error: BUILD_BUG_ON failed: offsetof(struct task_struct, wake_entry_type) - offsetof(struct task_struct, wake_entry) != offsetof(struct __call_single_data, flags) - offsetof(struct __call_single_data, llist)
  392 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |                                      ^
include/linux/compiler.h:373:4: note: in definition of macro ‘__compiletime_assert’
  373 |    prefix ## suffix();    \
      |    ^~~~~~
include/linux/compiler.h:392:2: note: in expansion of macro ‘_compiletime_assert’
  392 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |  ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
   39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
      |                                     ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
   50 |  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
      |  ^~~~~~~~~~~~~~~~
kernel/smp.c:687:2: note: in expansion of macro ‘BUILD_BUG_ON’
  687 |  BUILD_BUG_ON(offsetof(struct task_struct, wake_entry_type) - offsetof(struct task_struct, wake_entry) !=
      |  ^~~~~~~~~~~~

Wrap 'wake_entry' and 'wake_entry_type' fiels of task_struct in an
anonymous struct to keep their relative layout intact during
randomization.

Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---

v2: use anonymous struct as Steven suggested.

 include/linux/sched.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index b62e6aaf28f0..7e30a09df616 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -654,8 +654,15 @@ struct task_struct {
 	unsigned int			ptrace;
 
 #ifdef CONFIG_SMP
-	struct llist_node		wake_entry;
-	unsigned int			wake_entry_type;
+       /*
+        * The layout of these fields must match the layout of CSD_TYPE_TTWU
+        * so they can be on the same @call_single_queue
+        */
+	struct {
+		struct llist_node		wake_entry;
+		unsigned int			wake_entry_type;
+	};
+
 	int				on_cpu;
 #ifdef CONFIG_THREAD_INFO_IN_TASK
 	/* Current CPU: */
-- 
2.25.4


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

* Re: [PATCH v2] sched: fix build with GCC_PLUGIN_RANDSTRUCT
  2020-06-28  7:27 [PATCH v2] sched: fix build with GCC_PLUGIN_RANDSTRUCT Mike Rapoport
@ 2020-06-28 12:58 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2020-06-28 12:58 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Kees Cook,
	Mike Rapoport, Steven Rostedt, Dietmar Eggemann, Ben Segall,
	Mel Gorman, linux-kernel


There's patches in tip/sched/urgent for this...

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

end of thread, other threads:[~2020-06-28 12:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-28  7:27 [PATCH v2] sched: fix build with GCC_PLUGIN_RANDSTRUCT Mike Rapoport
2020-06-28 12:58 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome