From: bot+bpf-ci@kernel.org
To: tasos.papagiannnis@gmail.com,bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,linux-mm@kvack.org,akpm@linux-foundation.org,david@kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,kpsingh@kernel.org,matt@bobrowski.net,song@kernel.org,tasos.papagiannnis@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next 2/5] bpf: Add user memory access kfuncs for mm_struct
Date: Tue, 11 Aug 2026 12:40:12 +0000 (UTC) [thread overview]
Message-ID: <5c189189e30671eaac05435772319bfeec1c1bf5d8a21a4f7e4aa95f0e88910a@mail.kernel.org> (raw)
In-Reply-To: <20260811112154.94053-3-tasos.papagiannnis@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3382 bytes --]
> Register both kfuncs with the common BPF_EVENTS kfunc set and mark them
This isn't a bug, but could the changelog be more precise here? The
kfuncs go into common_btf_ids, which is registered for
BPF_PROG_TYPE_UNSPEC, so they are reachable from any sleepable program
rather than from a tracing-specific set.
Relatedly, was gating them on CONFIG_BPF_EVENTS intentional? Nothing in
either function depends on tracing, and the analogous
bpf_copy_from_user_task*() kfuncs in kernel/bpf/helpers.c are available
unconditionally.
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 6388b6b23e490..9ba3362832cd0 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -4931,6 +4931,8 @@ BTF_ID_FLAGS(func, bpf_iter_kmem_cache_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)
> BTF_ID_FLAGS(func, bpf_local_irq_save)
> BTF_ID_FLAGS(func, bpf_local_irq_restore)
> #ifdef CONFIG_BPF_EVENTS
> +BTF_ID_FLAGS(func, bpf_copy_from_user_mm, KF_SLEEPABLE)
> +BTF_ID_FLAGS(func, bpf_copy_from_user_mm_str, KF_SLEEPABLE)
> BTF_ID_FLAGS(func, bpf_probe_read_user_dynptr)
> BTF_ID_FLAGS(func, bpf_probe_read_kernel_dynptr)
> BTF_ID_FLAGS(func, bpf_probe_read_user_str_dynptr)
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 891897f8a1b35..8931b3b2fc9d7 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -24,6 +24,7 @@
> #include <linux/key.h>
> #include <linux/namei.h>
> #include <linux/file.h>
> +#include <linux/mm.h>
>
> #include <net/bpf_sk_storage.h>
>
[ ... ]
> +__bpf_kfunc int bpf_copy_from_user_mm(void *dst, u32 dst__sz,
> + const void __user *unsafe_ptr__ign,
> + struct mm_struct *mm, u64 flags)
> +{
> + int ret;
> +
> + if (unlikely(flags))
> + return -EINVAL;
> +
> + if (unlikely(!dst__sz))
> + return 0;
> +
> + ret = access_remote_vm(mm, (unsigned long)unsafe_ptr__ign,
> + dst, dst__sz, 0);
> + if (ret == dst__sz)
> + return 0;
> +
> + memset(dst, 0, dst__sz);
> + return ret < 0 ? ret : -EFAULT;
> +}
[ ... ]
> +__bpf_kfunc int bpf_copy_from_user_mm_str(void *dst, u32 dst__sz,
> + const void __user *unsafe_ptr__ign,
> + struct mm_struct *mm, u64 flags)
> +{
> + int ret;
> +
> + if (unlikely(flags & ~BPF_F_PAD_ZEROS))
> + return -EINVAL;
> +
> + if (unlikely(!dst__sz))
> + return 0;
> +
> + ret = copy_remote_mm_str(mm, (unsigned long)unsafe_ptr__ign,
> + dst, dst__sz, 0);
> + if (ret < 0)
> + goto err;
> +
> + if (flags & BPF_F_PAD_ZEROS)
> + memset(dst + ret, 0, dst__sz - ret);
> +
> + return ret + 1;
> +
> +err:
> + if (flags & BPF_F_PAD_ZEROS)
> + memset(dst, 0, dst__sz);
> + return ret;
> +}
This isn't a bug, but since copy_remote_vm_str() in mm/memory.c is
already just a get_task_mm()/mmput() wrapper around copy_remote_mm_str(),
would it be cleaner to have bpf_copy_from_user_task_str() delegate to the
new mm-based kfunc (or share a static helper) rather than keeping two
near-identical copies of the flag/PAD_ZEROS/return-value logic in
different files?
The new copy also uses a 'goto err' where the existing one inlines the
error path, so the two now diverge in style too.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31488001112
next prev parent reply other threads:[~2026-08-11 12:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 11:21 [PATCH bpf-next 0/5] " Anastasios Papagiannis
2026-08-11 11:21 ` [PATCH bpf-next 1/5] mm: Add copy_remote_mm_str() Anastasios Papagiannis
2026-08-11 12:40 ` bot+bpf-ci
2026-08-11 11:21 ` [PATCH bpf-next 2/5] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-08-11 12:40 ` bot+bpf-ci [this message]
2026-08-11 11:21 ` [PATCH bpf-next 3/5] bpf: Mark linux_binprm->mm as trusted-or-null Anastasios Papagiannis
2026-08-11 12:40 ` bot+bpf-ci
2026-08-11 11:21 ` [PATCH bpf-next 4/5] selftests/bpf: Test trusted-or-null linux_binprm->mm Anastasios Papagiannis
2026-08-11 11:21 ` [PATCH bpf-next 5/5] selftests/bpf: Test mm_struct user memory kfuncs with linux_binprm Anastasios Papagiannis
2026-08-11 13:28 ` [PATCH bpf-next 0/5] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
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=5c189189e30671eaac05435772319bfeec1c1bf5d8a21a4f7e4aa95f0e88910a@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=david@kernel.org \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=martin.lau@kernel.org \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=tasos.papagiannnis@gmail.com \
--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®