Linux Perf Users
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/4] perf kvm: Check kvm_need_default_arch_event() early
Date: Tue, 23 Jun 2026 09:49:10 -0700	[thread overview]
Message-ID: <ajq5BhgBMjWpAc2S@google.com> (raw)
In-Reply-To: <20260623071657.7D2E61F00A3A@smtp.kernel.org>

On Tue, Jun 23, 2026 at 07:16:57AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] BUG_ON() unconditionally triggers and crashes `perf kvm record` on architectures where default arch events are not added (e.g., ARM64, RISC-V, s390).
> --
> 
> commit e180ad0afcd0778bb15a60785a0b08bfd2f76a50
> Author: Namhyung Kim <namhyung@kernel.org>
> 
> perf kvm: Check kvm_need_default_arch_event() early
> 
> This commit modifies perf kvm record to check if default options are needed
> before allocating arguments and passing the extra command line, preventing
> the default event from being incorrectly passed to the external command.
> 
> > diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> > index c236093eac473..acc6f2a706b35 100644
> > --- a/tools/perf/builtin-kvm.c
> > +++ b/tools/perf/builtin-kvm.c
> > @@ -1996,13 +1996,14 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)
> >  {
> >  	int rec_argc, i = 0, j, ret;
> >  	const char **rec_argv;
> > +	int need_arch_event = !!kvm_need_default_arch_event(argc, argv);
> >  
> >  	/*
> >  	 * Besides the 2 more options "-o" and "filename",
> >  	 * kvm_add_default_arch_event() may add 2 extra options,
> > -	 * so allocate 4 more items.
> > +	 * so allocate more items conditionally.
> >  	 */
> > -	rec_argc = argc + 2 + 2;
> > +	rec_argc = argc + 2 + (2 * need_arch_event);
> 
> [ ... ]
> 
> > -	if (kvm_need_default_arch_event(argc, argv)) {
> > +	if (need_arch_event) {
> >  		ret = kvm_add_default_arch_event(EM_HOST, &i, rec_argv);
> >  		if (ret)
> >  			goto EXIT;
> >  	}
> >  
> > +	for (j = 1; j < argc; j++, i++)
> > +		rec_argv[i] = STRDUP_FAIL_EXIT(argv[j]);
> > +
> > -	BUG_ON(i + 2 != rec_argc);
> > +	BUG_ON(i != rec_argc);
> 
> [Severity: High]
> Could this BUG_ON() cause a regression for perf kvm record on architectures
> that do not add default events?
> 
> If kvm_need_default_arch_event() returns true, rec_argc is set to argc + 4.
> 
> However, on architectures like ARM64, RISC-V, or s390, it appears
> kvm_add_default_arch_event() can return 0 without actually appending any
> events or incrementing i.
> 
> If that happens, i will only equal argc + 2 after the loop, causing this
> assertion to unconditionally fail and abort the process.

I'll check those arch and make sure they return 0 in
kvm_need_default_arch_event().

Thanks,
Namhyung


  reply	other threads:[~2026-06-23 16:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23  7:03 [PATCH v1 0/4] perf kvm: A small update in default arch event Namhyung Kim
2026-06-23  7:03 ` [PATCH 1/4] perf kvm: Factor out kvm_need_default_arch_event() Namhyung Kim
2026-06-23  7:16   ` sashiko-bot
2026-06-23 16:47     ` Namhyung Kim
2026-06-23  7:03 ` [PATCH 2/4] perf kvm: Check kvm_need_default_arch_event() early Namhyung Kim
2026-06-23  7:16   ` sashiko-bot
2026-06-23 16:49     ` Namhyung Kim [this message]
2026-06-23  7:03 ` [PATCH 3/4] perf kvm: Kill STRDUP_FAIL_EXIT() Namhyung Kim
2026-06-23  7:12   ` sashiko-bot
2026-06-23 16:50     ` Namhyung Kim
2026-06-23  7:03 ` [PATCH 4/4] perf test: Simplify perf kvm record/report tests Namhyung Kim
2026-06-23  7:09   ` sashiko-bot
2026-06-23 16:52     ` Namhyung Kim

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=ajq5BhgBMjWpAc2S@google.com \
    --to=namhyung@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox