From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756748AbcCRNGZ (ORCPT ); Fri, 18 Mar 2016 09:06:25 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:34404 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754578AbcCRNGW (ORCPT ); Fri, 18 Mar 2016 09:06:22 -0400 Subject: Re: [PATCH v11 1/9] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature To: James Morse References: <1457501543-24197-1-git-send-email-dave.long@linaro.org> <1457501543-24197-2-git-send-email-dave.long@linaro.org> <56E3094E.5010906@arm.com> Cc: Catalin Marinas , Will Deacon , Sandeepa Prabhu , William Cohen , Pratyush Anand , Steve Capper , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , Dave P Martin , Mark Rutland , Robin Murphy , Ard Biesheuvel , Jens Wiklander , Christoffer Dall , =?UTF-8?Q?Alex_Benn=c3=a9e?= , Yang Shi , Greg Kroah-Hartman , Viresh Kumar , "Suzuki K. Poulose" , Kees Cook , Zi Shen Lim , John Blackwood , Feng Kan , Balamurugan Shanmugam , Vladimir Murzin , Mark Salyzyn , Petr Mladek , Andrew Morton , Mark Brown From: David Long Message-ID: <56EBFD3E.5070600@linaro.org> Date: Fri, 18 Mar 2016 09:06:06 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <56E3094E.5010906@arm.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/11/2016 01:07 PM, James Morse wrote: > Hi David, > > On 09/03/16 05:32, David Long wrote: >> From: "David A. Long" >> >> Add HAVE_REGS_AND_STACK_ACCESS_API feature for arm64. >> >> Signed-off-by: David A. Long > >> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c >> index ff7f132..efebf0f 100644 >> --- a/arch/arm64/kernel/ptrace.c >> +++ b/arch/arm64/kernel/ptrace.c > > [ ... SNIP ... ] > >> +/** >> + * regs_within_kernel_stack() - check the address in the stack >> + * @regs: pt_regs which contains kernel stack pointer. >> + * @addr: address which is checked. >> + * >> + * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). >> + * If @addr is within the kernel stack, it returns true. If not, returns false. >> + */ >> +bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) >> +{ >> + return ((addr & ~(THREAD_SIZE - 1)) == >> + (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); > > I'm not sure where this is called from, but if kernel_stack_pointer(regs) could > ever point into an irq_stack you will get the wrong result. > > arch/arm64/include/asm/irq.h has 'on_irq_stack(sp, cpu)' which should help, > although you will need to check the bounds of the irq_stack separately. > > > The horrible details... > > From arch/arm64/kernel/irq.c:20 >> /* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */ >> DEFINE_PER_CPU(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack) >> __aligned(16); > > This was because per-cpu variables can be at-most page aligned. > 6cdf9c7ca687 ("arm64: Store struct thread_info in sp_el0") changed > current_thread_info() to work on these weirdly aligned irq_stacks. > > > Thanks, > > James > > It looks like this is ultimately used (currently) only by the arch-independent kprobes tracing code. But it does seem like this will be recording the wrong data when stack contents are being traced from interrupt routine probes. I will put a fix in for the next spin. Thanks, -dl From mboxrd@z Thu Jan 1 00:00:00 1970 From: dave.long@linaro.org (David Long) Date: Fri, 18 Mar 2016 09:06:06 -0400 Subject: [PATCH v11 1/9] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature In-Reply-To: <56E3094E.5010906@arm.com> References: <1457501543-24197-1-git-send-email-dave.long@linaro.org> <1457501543-24197-2-git-send-email-dave.long@linaro.org> <56E3094E.5010906@arm.com> Message-ID: <56EBFD3E.5070600@linaro.org> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On 03/11/2016 01:07 PM, James Morse wrote: > Hi David, > > On 09/03/16 05:32, David Long wrote: >> From: "David A. Long" >> >> Add HAVE_REGS_AND_STACK_ACCESS_API feature for arm64. >> >> Signed-off-by: David A. Long > >> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c >> index ff7f132..efebf0f 100644 >> --- a/arch/arm64/kernel/ptrace.c >> +++ b/arch/arm64/kernel/ptrace.c > > [ ... SNIP ... ] > >> +/** >> + * regs_within_kernel_stack() - check the address in the stack >> + * @regs: pt_regs which contains kernel stack pointer. >> + * @addr: address which is checked. >> + * >> + * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). >> + * If @addr is within the kernel stack, it returns true. If not, returns false. >> + */ >> +bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) >> +{ >> + return ((addr & ~(THREAD_SIZE - 1)) == >> + (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); > > I'm not sure where this is called from, but if kernel_stack_pointer(regs) could > ever point into an irq_stack you will get the wrong result. > > arch/arm64/include/asm/irq.h has 'on_irq_stack(sp, cpu)' which should help, > although you will need to check the bounds of the irq_stack separately. > > > The horrible details... > > From arch/arm64/kernel/irq.c:20 >> /* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */ >> DEFINE_PER_CPU(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack) >> __aligned(16); > > This was because per-cpu variables can be at-most page aligned. > 6cdf9c7ca687 ("arm64: Store struct thread_info in sp_el0") changed > current_thread_info() to work on these weirdly aligned irq_stacks. > > > Thanks, > > James > > It looks like this is ultimately used (currently) only by the arch-independent kprobes tracing code. But it does seem like this will be recording the wrong data when stack contents are being traced from interrupt routine probes. I will put a fix in for the next spin. Thanks, -dl