[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200626114522.GI1401039@lianli.shorne-pla.net>
Date: Fri, 26 Jun 2020 20:45:22 +0900
From: Stafford Horne <shorne@...il.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
"Paul E. McKenney" <paulmck@...nel.org>,
Marco Elver <elver@...gle.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Ingo Molnar <mingo@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Mike Rapoport <rppt@...ux.ibm.com>,
Sami Tolvanen <samitolvanen@...gle.com>
Subject: Re: [PATCH] init: Align init_task to avoid conflict with MUTEX_FLAGS
On Fri, Jun 26, 2020 at 01:12:08PM +0200, Peter Zijlstra wrote:
> On Fri, Jun 26, 2020 at 05:44:09AM +0900, Stafford Horne wrote:
> > When booting on 32-bit machines (seen on OpenRISC) I saw this warning
> > with CONFIG_DEBUG_MUTEXES turned on.
>
> > I traced this to kernel/locking/mutex.c storing 3 bits of MUTEX_FLAGS in
> > the task_struct pointer (mutex.owner). There is a comment saying that
> > task_structs are always aligned to L1_CACHE_BYTES. This is not true for
> > the init_task.
> >
> > On 64-bit machines this is not a problem because symbol addresses are
> > naturally aligned to 64-bits providing 3 bits for MUTEX_FLAGS. Howerver,
> > for 32-bit machines the symbol address only has 2 bits available.
> >
> > Fix this by setting init_task alignment to at least L1_CACHE_BYTES.
>
> Whoopsie, sorry about that.
>
> > Cc: Peter Zijlstra <peterz@...radead.org>
> > Signed-off-by: Stafford Horne <shorne@...il.com>
> > ---
> > init/init_task.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/init/init_task.c b/init/init_task.c
> > index 15089d15010a..d2d2af018d0d 100644
> > --- a/init/init_task.c
> > +++ b/init/init_task.c
> > @@ -64,6 +64,8 @@ unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)]
> > struct task_struct init_task
> > #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
> > __init_task_data
> > +#else
> > + __aligned(L1_CACHE_BYTES)
> > #endif
>
> Why make this conditional? task_struct_cachep (in kernel/fork.c) has
> max_t(int, L1_CACHE_BYTES, ARCH_MIN_TASKALIGN) alignment, so this really
> should be aligned on L1_CACHE_BYTES at least.
I think we can make this unconditional. The only reason I used the condition is
because the only architecture that sets CONFIG_ARCH_TASK_STRUCT_ON_STACK is ia64
which already has 64-bit alignment.
I can change it to (not incorporating max_t(ARCH_MIN_TASKALIGN) as not sure how):
diff --git a/init/init_task.c b/init/init_task.c
index 15089d15010a..ab6173f8e6a8 100644
--- a/init/init_task.c
+++ b/init/init_task.c
@@ -65,6 +65,7 @@ struct task_struct init_task
#ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
__init_task_data
#endif
+ __aligned(L1_CACHE_BYTES)
= {
#ifdef CONFIG_THREAD_INFO_IN_TASK
.thread_info = INIT_THREAD_INFO(init_task),
-Stafford
Powered by blists - more mailing lists