mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Eduard Zateev <hackerowskiy@gmail.com>, bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next] libbpf: Prefer mounted tracefs over debugfs
Date: Tue, 20 Oct 2026 10:35:06 -0700	[thread overview]
Message-ID: <20ac0187-cae1-4c8c-9949-8e8501aff2fc@linux.dev> (raw)
In-Reply-To: <20261018092629.585046-1-hackerowskiy@gmail.com>

On 10/18/26 2:26 AM, Eduard Zateev wrote:
> The tracefs path helpers look up /sys/kernel/debug/tracing first, even
> when tracefs is already mounted at /sys/kernel/tracing. This can trigger
> an unnecessary legacy tracefs mount and selects a path beneath debugfs,
> which is commonly restricted.

This doesn't describe the actual problem. If debugfs is restricted or
not mounted, the existing faccessat() check already fails and libbpf
falls back to tracefs.

It looks like the actual trivial improvement is in avoiding the
debugfs/tracing automount causing:

  NOTICE: Automounting of tracing to debugfs is deprecated and will be removed in 2030

in the kernel logs whenever debugfs/tracing gets automounted.
libbpf triggers that on legacy kprobe/uprobe/tracepoint attach when
debugfs is mounted.

See commit 9ba817fb7c6a ("tracing: Deprecate auto-mounting tracefs in
debugfs") and CONFIG_TRACEFS_AUTOMOUNT_DEPRECATED.

> 
> Prefer the direct tracefs mount when statfs() reports TRACEFS_MAGIC.
> Checking the filesystem type avoids selecting an existing but unmounted
> sysfs mountpoint. Preserve the existing debugfs fallback and the default
> tracefs path when neither location is available.
> 
> Fixes: a1ac9fd6c650 ("libbpf: fallback to tracefs mount point if debugfs is not mounted")
> Closes: https://github.com/libbpf/libbpf/issues/966
> Assisted-by: LLM
> Signed-off-by: Eduard Zateev <hackerowskiy@gmail.com>

Please update the commit message to show the actual consequence of the
change. And drop both fixes and assisted-by tags. This is not a bug,
and assited-by has been recently deprecated.

The diff looks ok to me, but tbh I don't see much value in it.
Any particular reason you decided to fix this?

pw-bot: cr


> ---
> 
> Validation on Fedora 44 (aarch64):
> - Built static and shared libbpf with the default warning settings.
> - Exercised all five path helpers using wrapped syscalls for both mounts,
>   tracefs only, debugfs only, an unmounted tracefs directory, and neither
>   path available. The original code fails the both-mounts scenario.
> - Confirmed the direct tracefs paths on the host's mounted tracefs.
> Privileged BPF attach/mount tests were not run.
> 
>  tools/lib/bpf/libbpf.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index cb09ded90..9db0a8bde 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -59,6 +59,10 @@
>  #define BPF_FS_MAGIC		0xcafe4a11
>  #endif
>  
> +#ifndef TRACEFS_MAGIC
> +#define TRACEFS_MAGIC		0x74726163
> +#endif
> +
>  #define MAX_EVENT_NAME_LEN	64
>  
>  #define BPF_FS_DEFAULT_PATH "/sys/fs/bpf"
> @@ -12713,12 +12717,17 @@ static int append_to_file(const char *file, const char *fmt, ...)
>  
>  static bool use_debugfs(void)
>  {
> -	static int has_debugfs = -1;
> +	static int needs_debugfs = -1;
> +	struct statfs st_fs;
>  
> -	if (has_debugfs < 0)
> -		has_debugfs = faccessat(AT_FDCWD, DEBUGFS, F_OK, AT_EACCESS) == 0;
> +	if (needs_debugfs < 0) {
> +		if (statfs(TRACEFS, &st_fs) == 0 && st_fs.f_type == TRACEFS_MAGIC)
> +			needs_debugfs = 0;
> +		else
> +			needs_debugfs = faccessat(AT_FDCWD, DEBUGFS, F_OK, AT_EACCESS) == 0;
> +	}
>  
> -	return has_debugfs == 1;
> +	return needs_debugfs == 1;
>  }
>  
>  static const char *tracefs_path(void)
> 
> base-commit: a6303535c2ad9d49598d52556183911f02287791


      reply	other threads:[~2026-10-20 17:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18  9:26 Eduard Zateev
2026-10-20 17:35 ` Ihor Solodrai [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=20ac0187-cae1-4c8c-9949-8e8501aff2fc@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hackerowskiy@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@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

all inboxes | Powered by JetHome®