All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hang Zhengyang" <hang.zhengyang1010@gmail.com>
Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH] perf bpf_counter: Say why the perf_event_attr map can't be used
Date: Fri, 20 Nov 2026 07:02:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-224590@kernel.org> (raw)
In-Reply-To: <20261120-bperf-attr-map-err-v1-1-b12b6b550273@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf bpf_counter: -Werror=sign-compare in bperf_pin_hint() on
  32-bit glibc
- [Low] perf bpf_counter: missing errno.h include for errno in
  bperf_lock_attr_map()
--

commit ef2748ac810907c5c84a28e7a31cf730bd68ad09
Author: Hang Zhengyang <hang.zhengyang1010@gmail.com>

perf bpf_counter: Say why the perf_event_attr map can't be used

This commit reports specific errors and a bpffs mount hint when
creating, pinning, opening, checking, or locking the bperf
perf_event_attr map fails.

Link: https://lore.kernel.org/all/YFneUHDiAt8Rg0cc@kernel.org/

> diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c
> index 9362e45e17ceb..9a463eb9d51d9 100644
> --- a/tools/perf/util/bpf_counter.c
> +++ b/tools/perf/util/bpf_counter.c
> @@ -3,11 +3,13 @@
>  /* Copyright (c) 2019 Facebook */
>  
>  #include <assert.h>
> +#include <libgen.h>
>  #include <limits.h>
>  #include <unistd.h>
>  #include <sys/file.h>
>  #include <sys/resource.h>
>  #include <sys/time.h>
> +#include <sys/vfs.h>
>  #include <linux/err.h>
>  #include <linux/list.h>
>  #include <linux/zalloc.h>
> @@ -32,6 +34,10 @@
>  #include "bpf_skel/bperf_leader.skel.h"
>  #include "bpf_skel/bperf_follower.skel.h"
>  
> +#ifndef BPF_FS_MAGIC
> +#define BPF_FS_MAGIC 0xcafe4a11
> +#endif
> +
>  struct bpf_counter {
>  	void *skel;
>  	struct list_head list;
> @@ -376,6 +382,24 @@ static bool bperf_attr_map_compatible(int attr_map_fd)
>  		(map_info.value_size == sizeof(struct perf_event_attr_map_entry));
>  }
>  
> +/* bpf_obj_pin() only works on bpffs: say so if that is why it failed. */
> +static void bperf_pin_hint(struct target *target, const char *path)
> +{
> +	char buf[PATH_MAX];
> +	struct statfs st;
> +	const char *dir;
> +
> +	scnprintf(buf, sizeof(buf), "%s", path);
> +	dir = dirname(buf);
> +	if (statfs(dir, &st) || st.f_type == BPF_FS_MAGIC)
> +		return;

[Severity: Medium]
Does comparing st.f_type against BPF_FS_MAGIC without a cast fail to
build with -Werror=sign-compare on 32-bit glibc?

0xcafe4a11 exceeds INT_MAX, so BPF_FS_MAGIC has type unsigned int, while
struct statfs f_type (__fsword_t) is a 32-bit signed integer on 32-bit
glibc targets.  Casting st.f_type to unsigned long, as is_bpffs() in
tools/bpf/bpftool/common.c does, avoids the warning.

> +	if (target->attr_map)
> +		pr_err("--bpf-attr-map: %s is not on bpffs\n", dir);
> +	else
> +		pr_err("bpffs is not mounted at %s, try 'mount -t bpf bpf %s' or use --bpf-attr-map\n",
> +		       dir, dir);
> +}
> +
>  static int bperf_lock_attr_map(struct target *target)
>  {
>  	char path[PATH_MAX];
> @@ -393,30 +417,41 @@ static int bperf_lock_attr_map(struct target *target)
>  					sizeof(struct perf_event_attr),
>  					sizeof(struct perf_event_attr_map_entry),
>  					ATTR_MAP_SIZE, NULL);
> -		if (map_fd < 0)
> +		if (map_fd < 0) {
> +			pr_err("Failed to create perf_event_attr map: %m\n");
>  			return -1;
> +		}
>  
>  		err = bpf_obj_pin(map_fd, path);
>  		if (err) {
>  			/* someone pinned the map in parallel? */
>  			close(map_fd);
>  			map_fd = bpf_obj_get(path);
> -			if (map_fd < 0)
> +			if (map_fd < 0) {
> +				/* report the pin error, not the bpf_obj_get() one */
> +				errno = -err;

[Severity: Low]
This isn't a bug right now because the generated BPF skeleton headers
pull it in transitively, but tools/perf/util/bpf_counter.c should
explicitly include <errno.h> at the top of the file for errno.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-bperf-attr-map-err-v1-1-b12b6b550273@gmail.com?part=1

      reply	other threads:[~2026-11-20  7:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:49 [PATCH] perf bpf_counter: Say why the perf_event_attr map can't be used Hang Zhengyang
2026-11-20  6:49 ` Hang Zhengyang via B4 Relay
2026-11-20  7:02 ` sashiko-bot [this message]

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=sashiko-outbox-224590@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hang.zhengyang1010@gmail.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.