All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chen Pei" <cp0613@linux.alibaba.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf riscv: Add perf_regs_load and enable the dwarf unwind test
Date: Mon, 14 Sep 2026 12:58:14 +0000	[thread overview]
Message-ID: <20260914125814.C92251F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914124145.1257-1-cp0613@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Unchecked dereference of `regs` when `perf_sample__user_regs()` fails to allocate.
- [Low] Missing explicit inclusion of <stdlib.h> for standard memory allocation functions, violating musl compatibility guidelines.
--

commit d76f4341bf568ee75224d45323c5c8e122fd3e66
Author: Chen Pei <cp0613@linux.alibaba.com>
Subject: perf riscv: Add perf_regs_load and enable the dwarf unwind test

This commit adds perf_regs_load and an architecture-specific unwind sample
helper for riscv. It also wires riscv into the dwarf unwind test gates so 
that unwinding tests can be executed on riscv architectures.

> diff --git a/tools/perf/arch/riscv/tests/dwarf-unwind.c b/tools/perf/arch/riscv/tests/dwarf-unwind.c
> new file mode 100644
> index 0000000000000..e981b21f918d2
> --- /dev/null
> +++ b/tools/perf/arch/riscv/tests/dwarf-unwind.c
> @@ -0,0 +1,64 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <string.h>
> +#include "perf_regs.h"
> +#include "thread.h"
> +#include "map.h"
> +#include "maps.h"
> +#include "event.h"
> +#include "debug.h"
> +#include "tests/tests.h"
> +
> +#define STACK_SIZE 8192
> +
> +static int sample_ustack(struct perf_sample *sample,
> +		struct thread *thread, u64 *regs)
> +{
> +	struct stack_dump *stack = &sample->user_stack;
> +	struct map *map;
> +	unsigned long sp;
> +	u64 stack_size, *buf;
> +
> +	buf = malloc(STACK_SIZE);

[Severity: Low]
Does this file need to explicitly include <stdlib.h>? Since musl libc
enforces strict POSIX header inclusions, missing the declaration for
malloc could lead to a build failure regression on musl libc systems.

[ ... ]

> +int test__arch_unwind_sample(struct perf_sample *sample,
> +		struct thread *thread)
> +{
> +	struct regs_dump *regs = perf_sample__user_regs(sample);
> +	u64 *buf;
> +
> +	buf = calloc(PERF_REGS_MAX, sizeof(u64));

[Severity: Low]
Similarly, does this calloc require an explicit include of <stdlib.h> to
ensure compatibility with musl libc systems?

> +	if (!buf) {
> +		pr_debug("failed to allocate sample uregs data\n");
> +		return -1;
> +	}
> +
> +	perf_regs_load(buf);
> +	regs->abi  = PERF_SAMPLE_REGS_ABI;

[Severity: Medium]
Can perf_sample__user_regs() return NULL here?

If memory allocation fails within perf_sample__user_regs() (which uses 
zalloc), the returned NULL pointer would be unconditionally dereferenced 
on this line when setting regs->abi.

Could this regression cause a segmentation fault in the perf test tool 
under memory constraints?

> +	regs->regs = buf;
> +	regs->mask = PERF_REGS_MASK;
> +
> +	return sample_ustack(sample, thread, buf);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260914124145.1257-1-cp0613@linux.alibaba.com?part=1

  reply	other threads:[~2026-09-14 12:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 12:41 [PATCH] perf riscv: Add perf_regs_load and enable the dwarf unwind test Chen Pei
2026-09-14 12:41 ` Chen Pei
2026-09-14 12:58 ` sashiko-bot [this message]
2026-09-15  1:54   ` Chen Pei
2026-09-15  1:54     ` Chen Pei
2026-09-15 19:09     ` Ian Rogers
2026-09-15 19:09       ` Ian Rogers
2026-09-22 12:40       ` Arnaldo Carvalho de Melo
2026-09-22 12:40         ` Arnaldo Carvalho de Melo

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=20260914125814.C92251F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cp0613@linux.alibaba.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.