public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: madvenka@linux.microsoft.com
Cc: broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org,
	nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com,
	catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org,
	linux-arm-kernel@lists.infradead.org,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 1/5] arm64: Call stack_backtrace() only from within walk_stackframe()
Date: Tue, 30 Nov 2021 15:05:48 +0000	[thread overview]
Message-ID: <YaY9zLNumYZ1lLkc@FVFF77S0Q05N> (raw)
In-Reply-To: <20211123193723.12112-2-madvenka@linux.microsoft.com>

On Tue, Nov 23, 2021 at 01:37:19PM -0600, madvenka@linux.microsoft.com wrote:
> From: "Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>
> 
> Currently, arch_stack_walk() calls start_backtrace() and walk_stackframe()
> separately. There is no need to do that. Instead, call start_backtrace()
> from within walk_stackframe(). In other words, walk_stackframe() is the only
> unwind function a consumer needs to call.
> 
> Currently, the only consumer is arch_stack_walk(). In the future,
> arch_stack_walk_reliable() will be another consumer.
> 
> Currently, there is a check for a NULL task in unwind_frame(). It is not
> needed since all current consumers pass a non-NULL task.

Can you split the NULL check change into a preparatory patch? That change is
fine in isolation (and easier to review/ack), and it's nicer for future
bisection to not group that with unrelated changes.

> Use struct stackframe only within the unwind functions.
> 
> Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
> ---
>  arch/arm64/kernel/stacktrace.c | 41 ++++++++++++++++++----------------
>  1 file changed, 22 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index 0fb58fed54cb..7217c4f63ef7 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c
> @@ -69,9 +69,6 @@ static int notrace unwind_frame(struct task_struct *tsk,
>  	unsigned long fp = frame->fp;
>  	struct stack_info info;
>  
> -	if (!tsk)
> -		tsk = current;
> -
>  	/* Final frame; nothing to unwind */
>  	if (fp == (unsigned long)task_pt_regs(tsk)->stackframe)
>  		return -ENOENT;
> @@ -143,15 +140,19 @@ static int notrace unwind_frame(struct task_struct *tsk,
>  NOKPROBE_SYMBOL(unwind_frame);
>  
>  static void notrace walk_stackframe(struct task_struct *tsk,
> -				    struct stackframe *frame,
> +				    unsigned long fp, unsigned long pc,
>  				    bool (*fn)(void *, unsigned long), void *data)
>  {
> +	struct stackframe frame;
> +
> +	start_backtrace(&frame, fp, pc);
> +
>  	while (1) {
>  		int ret;
>  
> -		if (!fn(data, frame->pc))
> +		if (!fn(data, frame.pc))
>  			break;
> -		ret = unwind_frame(tsk, frame);
> +		ret = unwind_frame(tsk, &frame);
>  		if (ret < 0)
>  			break;
>  	}
> @@ -195,17 +196,19 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry,
>  			      void *cookie, struct task_struct *task,
>  			      struct pt_regs *regs)
>  {
> -	struct stackframe frame;
> -
> -	if (regs)
> -		start_backtrace(&frame, regs->regs[29], regs->pc);
> -	else if (task == current)
> -		start_backtrace(&frame,
> -				(unsigned long)__builtin_frame_address(1),
> -				(unsigned long)__builtin_return_address(0));
> -	else
> -		start_backtrace(&frame, thread_saved_fp(task),
> -				thread_saved_pc(task));
> -
> -	walk_stackframe(task, &frame, consume_entry, cookie);
> +	unsigned long fp, pc;
> +
> +	if (regs) {
> +		fp = regs->regs[29];
> +		pc = regs->pc;
> +	} else if (task == current) {
> +		/* Skip arch_stack_walk() in the stack trace. */
> +		fp = (unsigned long)__builtin_frame_address(1);
> +		pc = (unsigned long)__builtin_return_address(0);
> +	} else {
> +		/* Caller guarantees that the task is not running. */
> +		fp = thread_saved_fp(task);
> +		pc = thread_saved_pc(task);
> +	}
> +	walk_stackframe(task, fp, pc, consume_entry, cookie);

I'd prefer to leave this as-is. The new and old structure are largely
equivalent, so we haven't made this any simpler, but we have added more
arguments to walk_stackframe().

One thing I *would* like to do is move tsk into strcut stackframe, so we only
need to pass that around, which'll make it easier to refactor the core unwind
logic.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-11-30 15:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8b861784d85a21a9bf08598938c11aff1b1249b9>
2021-11-23 19:37 ` [PATCH v11 0/5] arm64: Reorganize the unwinder and implement stack trace reliability checks madvenka
2021-11-23 19:37   ` [PATCH v11 1/5] arm64: Call stack_backtrace() only from within walk_stackframe() madvenka
2021-11-25 13:48     ` Mark Brown
2021-11-30 15:05     ` Mark Rutland [this message]
2021-11-30 17:13       ` Madhavan T. Venkataraman
2021-11-30 18:29         ` Mark Rutland
2021-11-30 20:29           ` Madhavan T. Venkataraman
2021-12-10  4:13             ` Madhavan T. Venkataraman
2021-11-23 19:37   ` [PATCH v11 2/5] arm64: Rename unwinder functions madvenka
2021-11-24 17:10     ` Mark Brown
2021-11-30 15:08     ` Mark Rutland
2021-11-30 17:15       ` Madhavan T. Venkataraman
2021-11-23 19:37   ` [PATCH v11 3/5] arm64: Make the unwind loop in unwind() similar to other architectures madvenka
2021-11-25 14:30     ` Mark Brown
2021-11-23 19:37   ` [PATCH v11 4/5] arm64: Introduce stack trace reliability checks in the unwinder madvenka
2021-11-25 14:56     ` Mark Brown
2021-11-25 16:59       ` Madhavan T. Venkataraman
2021-11-26 13:29         ` Mark Brown
2021-11-26 17:23           ` Madhavan T. Venkataraman
2021-11-23 19:37   ` [PATCH v11 5/5] arm64: Create a list of SYM_CODE functions, check return PC against list madvenka
2021-11-25 15:05     ` Mark Brown

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=YaY9zLNumYZ1lLkc@FVFF77S0Q05N \
    --to=mark.rutland@arm.com \
    --cc=ardb@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=jmorris@namei.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=madvenka@linux.microsoft.com \
    --cc=nobuta.keiya@fujitsu.com \
    --cc=sjitindarsingh@gmail.com \
    --cc=will@kernel.org \
    /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