From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752099AbbCYJNL (ORCPT ); Wed, 25 Mar 2015 05:13:11 -0400 Received: from terminus.zytor.com ([198.137.202.10]:37396 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752390AbbCYJNG (ORCPT ); Wed, 25 Mar 2015 05:13:06 -0400 Date: Wed, 25 Mar 2015 02:12:27 -0700 From: tip-bot for Ingo Molnar Message-ID: Cc: luto@kernel.org, oleg@redhat.com, dvlasenk@redhat.com, rostedt@goodmis.org, torvalds@linux-foundation.org, ast@plumgrid.com, wad@chromium.org, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, bp@suse.de, bp@alien8.de, mingo@kernel.org, luto@amacapital.net, keescook@chromium.org, fweisbec@gmail.com Reply-To: linux-kernel@vger.kernel.org, hpa@zytor.com, ast@plumgrid.com, tglx@linutronix.de, wad@chromium.org, rostedt@goodmis.org, oleg@redhat.com, dvlasenk@redhat.com, torvalds@linux-foundation.org, luto@kernel.org, mingo@kernel.org, luto@amacapital.net, bp@alien8.de, keescook@chromium.org, fweisbec@gmail.com, bp@suse.de In-Reply-To: <20150324184311.GA14760@gmail.com> References: <20150324184311.GA14760@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/asm/entry/64: Improve the THREAD_INFO() macro explanation Git-Commit-ID: 1ddc6f3c60d75a7577dd33bc441e309febe2fc76 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 1ddc6f3c60d75a7577dd33bc441e309febe2fc76 Gitweb: http://git.kernel.org/tip/1ddc6f3c60d75a7577dd33bc441e309febe2fc76 Author: Ingo Molnar AuthorDate: Tue, 24 Mar 2015 19:43:11 +0100 Committer: Ingo Molnar CommitDate: Tue, 24 Mar 2015 20:57:30 +0100 x86/asm/entry/64: Improve the THREAD_INFO() macro explanation Explain the background, and add a real example. Acked-by: Denys Vlasenko Acked-by: Andy Lutomirski Acked-by: Borislav Petkov Cc: Alexei Starovoitov Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Frederic Weisbecker Cc: H. Peter Anvin Cc: Kees Cook Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Steven Rostedt Cc: Will Drewry Link: http://lkml.kernel.org/r/20150324184311.GA14760@gmail.com 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 ad0ee34..813dfbb 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)