public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: [bug report] perf lock: Print the number of lost entries for BPF
Date: Fri, 9 Aug 2024 15:29:20 +0300	[thread overview]
Message-ID: <909abbc8-efca-40df-9876-8c36b6942a83@stanley.mountain> (raw)

Hello Namhyung Kim,

Commit 6d499a6b3d90 ("perf lock: Print the number of lost entries for
BPF") from Aug 2, 2022 (linux-next), leads to the following Smatch
static checker warning:

	./tools/perf/util/bpf_skel/lock_contention.bpf.c:379 contention_begin()
	warn: unsigned 'pelem->stack_id' is never less than zero.

./tools/perf/util/bpf_skel/lock_contention.bpf.c
    360 SEC("tp_btf/contention_begin")
    361 int contention_begin(u64 *ctx)
    362 {
    363         struct tstamp_data *pelem;
    364 
    365         if (!enabled || !can_record(ctx))
    366                 return 0;
    367 
    368         pelem = get_tstamp_elem(ctx[1]);
    369         if (pelem == NULL)
    370                 return 0;
    371 
    372         pelem->timestamp = bpf_ktime_get_ns();
    373         pelem->lock = (__u64)ctx[0];
    374         pelem->flags = (__u32)ctx[1];
    375 
    376         if (needs_callstack) {
    377                 pelem->stack_id = bpf_get_stackid(ctx, &stacks,
    378                                                   BPF_F_FAST_STACK_CMP | stack_skip);
--> 379                 if (pelem->stack_id < 0)

->stack_id is a u32 so it can't be less than zero

    380                         __sync_fetch_and_add(&stack_fail, 1);
    381         } else if (aggr_mode == LOCK_AGGR_TASK) {
    382                 struct task_struct *task;
    383 
    384                 if (lock_owner) {
    385                         task = get_lock_owner(pelem->lock, pelem->flags);
    386 
    387                         /* The flags is not used anymore.  Pass the owner pid. */
    388                         if (task)
    389                                 pelem->flags = BPF_CORE_READ(task, pid);

regards,
dan carpenter

             reply	other threads:[~2024-08-09 12:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09 12:29 Dan Carpenter [this message]
2024-08-10 19:17 ` [PATCH] perf lock contention: Change stack_id type to s32 Namhyung Kim
2024-08-12 14:52   ` kernel test robot
2024-08-12 16:09   ` Arnaldo Carvalho de Melo
2024-08-12 16:52     ` Arnaldo Carvalho de Melo
2024-08-12 16:57       ` Namhyung Kim
2024-08-12 17:05         ` 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=909abbc8-efca-40df-9876-8c36b6942a83@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@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