From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753319AbcFOI0D (ORCPT ); Wed, 15 Jun 2016 04:26:03 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33188 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753138AbcFOIZ7 (ORCPT ); Wed, 15 Jun 2016 04:25:59 -0400 Date: Wed, 15 Jun 2016 10:25:54 +0200 From: Ingo Molnar To: WANG Chao Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched: unlikely corrupted stack end Message-ID: <20160615082554.GA18748@gmail.com> References: <20160614064306.48035-1-wcwxyz@gmail.com> <20160614082423.6068-1-wcwxyz@gmail.com> <20160614085613.GC9974@gmail.com> <20160614102638.GB13439@gmail.com> <71E4B9CB-BF33-4319-941B-85EC6640E339@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <71E4B9CB-BF33-4319-941B-85EC6640E339@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * WANG Chao wrote: > > > 在 2016年6月14日,下午6:26,Ingo Molnar 写道: > > > > > > * WANG Chao wrote: > > > >> > >>> 在 2016年6月14日,下午4:56,Ingo Molnar 写道: > >>> > >>> > >>> * WANG Chao wrote: > >>> > >>>> unlikely() was dropped in commit ce03e4137bb2 ("sched/core: Drop > >>>> unlikely behind BUG_ON()"), but commit 29d6455178a0 ("sched: panic on > >>>> corrupted stack end") dropped BUG_ON() and called panic directly. > >>>> > >>>> Now we should bring unlikely() back for branch prediction. While we're > >>>> at it, it's better and cleaner to turn task_stack_end_corrupted() into > >>>> inline function. > >>>> > >>>> Signed-off-by: WANG Chao > >>>> --- > >>>> include/linux/sched.h | 7 +++++-- > >>>> 1 file changed, 5 insertions(+), 2 deletions(-) > >>>> > >>>> diff --git a/include/linux/sched.h b/include/linux/sched.h > >>>> index 6e42ada26345..797ca1975431 100644 > >>>> --- a/include/linux/sched.h > >>>> +++ b/include/linux/sched.h > >>>> @@ -2997,8 +2997,11 @@ static inline unsigned long *end_of_stack(struct task_struct *p) > >>>> } > >>>> > >>>> #endif > >>>> -#define task_stack_end_corrupted(task) \ > >>>> - (*(end_of_stack(task)) != STACK_END_MAGIC) > >>>> + > >>>> +static inline int task_stack_end_corrupted(struct task_struct *p) > >>>> +{ > >>>> + return unlikely(*(end_of_stack(p)) != STACK_END_MAGIC); > >>>> +} > >>> > >>> The passed in pointer should be const, and the extra parentheses around the > >>> end_of_stack() call are not needed anymore (since it's now proper C code now). > >> > >> end_of_stack() will discard const and cause an compiler warning. > >> Should I add const to end_of_stack()? > > > > Yes. Also make sure ia64 still builds and such. > > It seems convert task_stack_end_corrupted() into inline isn’t trivial. > > In ia64, end_of_stack() is expanded to: > > (unsigned long *)((void *)(p) + ((IA64_TASK_SIZE + IA64_THREAD_INFO_SIZE + 31) & ~31)) > > IA64_TASK_SIZE and IA64_THREAD_INFO_SIZE is defined in arch/ia64/kernel/asm-offsets.c, > which needs to include linux/sched.h. > > So the problem is task_stack_end_corrupted() doesn’t compile before asm-offsets.c is compiled. > asm-offsets.c also needs to include linux/sched.h to compile. I think maybe that’s why > task_stack_end_corrupted() is introduced as marco, not inline. > > Any idea? Oh well ... I guess we'll have to add the unlikely() to the macro itself. Thanks, Ingo