From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753649AbbCXSvb (ORCPT ); Tue, 24 Mar 2015 14:51:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47328 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753229AbbCXSvZ (ORCPT ); Tue, 24 Mar 2015 14:51:25 -0400 Message-ID: <5511B213.9030806@redhat.com> Date: Tue, 24 Mar 2015 19:50:59 +0100 From: Denys Vlasenko User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Ingo Molnar CC: Andy Lutomirski , Linus Torvalds , Steven Rostedt , Borislav Petkov , "H. Peter Anvin" , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/asm/entry/64: Improve the THREAD_INFO() macro explanation References: <1426785469-15125-1-git-send-email-dvlasenk@redhat.com> <20150324184311.GA14760@gmail.com> In-Reply-To: <20150324184311.GA14760@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/24/2015 07:43 PM, Ingo Molnar wrote: > From 0229a184997a7d4ad4398ee3ac2f5ae78c1c1a03 Mon Sep 17 00:00:00 2001 > From: Ingo Molnar > Date: Tue, 24 Mar 2015 18:57:13 +0100 > Subject: [PATCH] x86/asm/entry/64: Improve the THREAD_INFO() macro explanation > > Explain the background, and add a real example. > > Cc: Alexei Starovoitov > Cc: Andy Lutomirski > Cc: Andy Lutomirski > Cc: Borislav Petkov > Cc: Borislav Petkov > Cc: Denys Vlasenko > Cc: Frederic Weisbecker > Cc: H. Peter Anvin > Cc: Kees Cook > Cc: Linus Torvalds > Cc: Oleg Nesterov > Cc: Steven Rostedt > Cc: Will Drewry > Signed-off-by: Ingo Molnar > --- > arch/x86/include/asm/thread_info.h | 27 +++++++++++++++++++++++---- > 1 file changed, 23 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h > index ad0ee3423da5..813dfbb867a7 100644 > --- a/arch/x86/include/asm/thread_info.h > +++ b/arch/x86/include/asm/thread_info.h > @@ -206,10 +206,29 @@ static inline unsigned long current_stack_pointer(void) > _ASM_SUB $(THREAD_SIZE),reg ; > > /* > - * ASM operand which evaluates to thread_info address > - * if it is known that "reg" is exactly "off" bytes below stack top. > - * Example (fetch thread_info->fieldname): > - * mov TI_fieldname+THREAD_INFO(reg, off),%eax > + * ASM operand which evaluates to a 'thread_info' address of > + * the current task, if it is known that "reg" is exactly "off" > + * bytes below the top of the stack currently. > + * > + * ( The kernel stack's size is known at build time, it is usually > + * 2 or 4 pages, and the bottom of the kernel stack contains > + * the thread_info structure. So to access the thread_info very > + * quickly from assembly code we can calculate down from the > + * top of the kernel stack to the bottom, using constant, > + * build-time calculations only. ) > + * > + * For example, to fetch the current thread_info->flags value into %eax > + * on x86-64 defconfig kernels, in syscall entry code where RSP is > + * currently at exactly SIZEOF_PTREGS bytes away from the top of the > + * stack: > + * > + * mov TI_flags+THREAD_INFO(%rsp, SIZEOF_PTREGS), %eax > + * > + * will translate to: > + * > + * 8b 84 24 b8 c0 ff ff mov -0x3f48(%rsp), %eax > + * > + * which is below the current RSP by almost 16K. > */ > #define THREAD_INFO(reg, off) ((off)-THREAD_SIZE)(reg) Acked-by: Denys Vlasenko