Subject: [PATCH v12 01/10] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature

From: [email-masked] (David Long)
Date: Fri, 20 May 2016 00:18:03 -0400

On 05/17/2016 05:14 AM, Huang Shijie wrote:
> On Wed, Apr 27, 2016 at 02:52:56PM -0400, David Long wrote:
>> From: "David A. Long" <[email-masked]>
>> +/**
>> + * 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))) ||
>> +		on_irq_stack(addr, raw_smp_processor_id());
>> +}
>> +
>> +/**
>> + * regs_get_kernel_stack_nth() - get Nth entry of the stack
>> + * @regs:	pt_regs which contains kernel stack pointer.
>> + * @n:		stack entry number.
>> + *
>> + * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
>> + * is specified by @regs. If the @n th entry is NOT in the kernel stack,
>> + * this returns 0.
>> + */_
>> +unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
>> +{
>> +	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
>> +
>> +	addr += n;
>> +	if (regs_within_kernel_stack(regs, (unsigned long)addr))
> If the @addr fall in the interrupt stack, the regs_within_kernel_stack()
> will return true. But Is it what we want?
>

Yes, I think it is.  The function is used in regs_get_kernel_stack_nth() 
to make sure the data being asked for (based on the pt_regs saved stack 
pointer) is actually on the stack, whether it's "kernel" stack or "irq" 
stack.

Thanks,
-dl