mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Mike Rapoport <rppt@linux.ibm.com>,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v14 05/12] powerpc: prep stack walkers for THREAD_INFO_IN_TASK
Date: Thu, 24 Jan 2019 17:04:09 +0000	[thread overview]
Message-ID: <20190124170409.GC5531@lakrids.cambridge.arm.com> (raw)
In-Reply-To: <685ac94ceb1dfac43fbd2ee11a987cbaca63ab0b.1548346225.git.christophe.leroy@c-s.fr>

On Thu, Jan 24, 2019 at 04:19:39PM +0000, Christophe Leroy wrote:
> [text copied from commit 9bbd4c56b0b6
> ("arm64: prep stack walkers for THREAD_INFO_IN_TASK")]
> 
> When CONFIG_THREAD_INFO_IN_TASK is selected, task stacks may be freed
> before a task is destroyed. To account for this, the stacks are
> refcounted, and when manipulating the stack of another task, it is
> necessary to get/put the stack to ensure it isn't freed and/or re-used
> while we do so.
> 
> This patch reworks the powerpc stack walking code to account for this.
> When CONFIG_THREAD_INFO_IN_TASK is not selected these perform no
> refcounting, and this should only be a structural change that does not
> affect behaviour.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

I'm not familiar with the powerpc code, but AFAICT this is analagous to
the arm64 code, and I'm not aware of any special caveats. FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

> ---
>  arch/powerpc/kernel/process.c    | 23 +++++++++++++++++++++--
>  arch/powerpc/kernel/stacktrace.c | 29 ++++++++++++++++++++++++++---
>  2 files changed, 47 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index ce393df243aa..4ffbb677c9f5 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -2027,7 +2027,7 @@ int validate_sp(unsigned long sp, struct task_struct *p,
>  
>  EXPORT_SYMBOL(validate_sp);
>  
> -unsigned long get_wchan(struct task_struct *p)
> +static unsigned long __get_wchan(struct task_struct *p)
>  {
>  	unsigned long ip, sp;
>  	int count = 0;
> @@ -2053,6 +2053,20 @@ unsigned long get_wchan(struct task_struct *p)
>  	return 0;
>  }
>  
> +unsigned long get_wchan(struct task_struct *p)
> +{
> +	unsigned long ret;
> +
> +	if (!try_get_task_stack(p))
> +		return 0;
> +
> +	ret = __get_wchan(p);
> +
> +	put_task_stack(p);
> +
> +	return ret;
> +}
> +
>  static int kstack_depth_to_print = CONFIG_PRINT_STACK_DEPTH;
>  
>  void show_stack(struct task_struct *tsk, unsigned long *stack)
> @@ -2067,6 +2081,9 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
>  	int curr_frame = 0;
>  #endif
>  
> +	if (!try_get_task_stack(tsk))
> +		return;
> +
>  	sp = (unsigned long) stack;
>  	if (tsk == NULL)
>  		tsk = current;
> @@ -2081,7 +2098,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
>  	printk("Call Trace:\n");
>  	do {
>  		if (!validate_sp(sp, tsk, STACK_FRAME_OVERHEAD))
> -			return;
> +			break;
>  
>  		stack = (unsigned long *) sp;
>  		newsp = stack[0];
> @@ -2121,6 +2138,8 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
>  
>  		sp = newsp;
>  	} while (count++ < kstack_depth_to_print);
> +
> +	put_task_stack(tsk);
>  }
>  
>  #ifdef CONFIG_PPC64
> diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
> index e2c50b55138f..a5745571e06e 100644
> --- a/arch/powerpc/kernel/stacktrace.c
> +++ b/arch/powerpc/kernel/stacktrace.c
> @@ -67,12 +67,17 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
>  {
>  	unsigned long sp;
>  
> +	if (!try_get_task_stack(tsk))
> +		return;
> +
>  	if (tsk == current)
>  		sp = current_stack_pointer();
>  	else
>  		sp = tsk->thread.ksp;
>  
>  	save_context_stack(trace, sp, tsk, 0);
> +
> +	put_task_stack(tsk);
>  }
>  EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
>  
> @@ -84,9 +89,8 @@ save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
>  EXPORT_SYMBOL_GPL(save_stack_trace_regs);
>  
>  #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE
> -int
> -save_stack_trace_tsk_reliable(struct task_struct *tsk,
> -				struct stack_trace *trace)
> +static int __save_stack_trace_tsk_reliable(struct task_struct *tsk,
> +					   struct stack_trace *trace)
>  {
>  	unsigned long sp;
>  	unsigned long stack_page = (unsigned long)task_stack_page(tsk);
> @@ -193,6 +197,25 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
>  	}
>  	return 0;
>  }
> +
> +int save_stack_trace_tsk_reliable(struct task_struct *tsk,
> +				  struct stack_trace *trace)
> +{
> +	int ret;
> +
> +	/*
> +	 * If the task doesn't have a stack (e.g., a zombie), the stack is
> +	 * "reliably" empty.
> +	 */
> +	if (!try_get_task_stack(tsk))
> +		return 0;
> +
> +	ret = __save_stack_trace_tsk_reliable(trace, tsk);
> +
> +	put_task_stack(tsk);
> +
> +	return ret;
> +}
>  EXPORT_SYMBOL_GPL(save_stack_trace_tsk_reliable);
>  #endif /* CONFIG_HAVE_RELIABLE_STACKTRACE */
>  
> -- 
> 2.13.3
> 

  reply	other threads:[~2019-01-24 17:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 16:19 [PATCH v14 00/12] powerpc: Switch to CONFIG_THREAD_INFO_IN_TASK Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 01/12] powerpc/32: Fix CONFIG_VIRT_CPU_ACCOUNTING_NATIVE for 40x/booke Christophe Leroy
2019-01-30  8:08   ` Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 02/12] powerpc/irq: use memblock functions returning virtual address Christophe Leroy
2019-01-24 16:51   ` Mark Rutland
2019-01-24 17:25     ` Mike Rapoport
2019-01-24 17:28       ` Mark Rutland
2019-01-24 16:19 ` [PATCH v14 03/12] book3s/64: avoid circular header inclusion in mmu-hash.h Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 04/12] powerpc: Only use task_struct 'cpu' field on SMP Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 05/12] powerpc: prep stack walkers for THREAD_INFO_IN_TASK Christophe Leroy
2019-01-24 17:04   ` Mark Rutland [this message]
2019-01-24 16:19 ` [PATCH v14 06/12] powerpc: Prepare for moving thread_info into task_struct Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 07/12] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK Christophe Leroy
2019-01-24 17:18   ` Mark Rutland
2019-01-24 16:19 ` [PATCH v14 08/12] powerpc: regain entire stack space Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 09/12] powerpc: 'current_set' is now a table of task_struct pointers Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 10/12] powerpc/32: Remove CURRENT_THREAD_INFO and rename TI_CPU Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 11/12] powerpc/64: Remove CURRENT_THREAD_INFO Christophe Leroy
2019-01-24 16:19 ` [PATCH v14 12/12] powerpc: clean stack pointers naming Christophe Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190124170409.GC5531@lakrids.cambridge.arm.com \
    --to=mark.rutland@arm.com \
    --cc=benh@kernel.crashing.org \
    --cc=christophe.leroy@c-s.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=paulus@samba.org \
    --cc=rppt@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®