netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@kernel.org>
To: Jesper Dangaard Brouer <hawk@kernel.org>,
	Kohei Enju <enjuk@amazon.com>,
	alexei.starovoitov@gmail.com
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
	daniel@iogearbox.net, davem@davemloft.net, eddyz87@gmail.com,
	haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org,
	kohei.enju@gmail.com, kpsingh@kernel.org, kuba@kernel.org,
	lorenzo@kernel.org, martin.lau@linux.dev, netdev@vger.kernel.org,
	sdf@fomichev.me, shuah@kernel.org, song@kernel.org,
	yonghong.song@linux.dev, kernel-team <kernel-team@cloudflare.com>
Subject: Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem()
Date: Wed, 03 Dec 2025 13:31:29 +0100	[thread overview]
Message-ID: <87jyz39272.fsf@toke.dk> (raw)
In-Reply-To: <7b6b9d1a-c160-4198-8a58-0586424b56e5@kernel.org>

Jesper Dangaard Brouer <hawk@kernel.org> writes:

> On 03/12/2025 11.40, Kohei Enju wrote:
>> On Tue, 2 Dec 2025 17:08:32 -0800, Alexei Starovoitov wrote:
>> 
>>> On Fri, Nov 28, 2025 at 8:05 AM Kohei Enju <enjuk@amazon.com> wrote:
>>>>
>>>> After commit 9216477449f3 ("bpf: cpumap: Add the possibility to attach
>>>> an eBPF program to cpumap"), __cpu_map_entry_alloc() may fail with
>>>> errors other than -ENOMEM, such as -EBADF or -EINVAL.
>>>>
>>>> However, __cpu_map_entry_alloc() returns NULL on all failures, and
>>>> cpu_map_update_elem() unconditionally converts this NULL into -ENOMEM.
>>>> As a result, user space always receives -ENOMEM regardless of the actual
>>>> underlying error.
>>>>
>>>> Examples of unexpected behavior:
>>>>    - Nonexistent fd  : -ENOMEM (should be -EBADF)
>>>>    - Non-BPF fd      : -ENOMEM (should be -EINVAL)
>>>>    - Bad attach type : -ENOMEM (should be -EINVAL)
>>>>
>>>> Change __cpu_map_entry_alloc() to return ERR_PTR(err) instead of NULL
>>>> and have cpu_map_update_elem() propagate this error.
>>>>
>>>> Fixes: 9216477449f3 ("bpf: cpumap: Add the possibility to attach an eBPF program to cpumap")
>>>
>>> The current behavior is what it is. It's not a bug and
>>> this patch is not a fix. It's probably an ok improvement,
>>> but since it changes user visible behavior we have to be careful.
>> 
>> Oops, got it.
>> When I resend, I'll remove the tag and send to bpf-next, not to bpf.
>> 
>> Thank you for taking a look.
>> 
>>>
>>> I'd like Jesper and/or other cpumap experts to confirm that it's ok.
>>>
>> 
>> Sure, I'd like to wait for reactions from cpumap experts.
>
> Skimmed the code changes[1] and they look good to me :-)

We have one example of a use of the cpumap programs in xdp-tools, and
there we just report the error message to the user. I would guess other
apps would follow the same pattern rather than react to a specific error
code; especially since there's only one error code being used here.

So I agree, this should be OK to change.

-Toke

  reply	other threads:[~2025-12-03 12:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-28 16:04 [PATCH bpf v1 0/2] bpf: cpumap: fix error propagation in Kohei Enju
2025-11-28 16:04 ` [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() Kohei Enju
2025-12-03  1:08   ` Alexei Starovoitov
2025-12-03 10:40     ` Kohei Enju
2025-12-03 12:12       ` Jesper Dangaard Brouer
2025-12-03 12:31         ` Toke Høiland-Jørgensen [this message]
2025-12-06  7:29           ` Kohei Enju
2025-12-06 12:00             ` Kohei Enju
2025-12-06 12:06               ` Alexei Starovoitov
2025-12-06 12:14                 ` Kohei Enju
2025-12-06 12:22                   ` Alexei Starovoitov
2025-12-06 12:26                     ` Kohei Enju
2025-11-28 16:04 ` [PATCH bpf v1 2/2] selftests/bpf: add tests for attaching invalid fd Kohei Enju

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=87jyz39272.fsf@toke.dk \
    --to=toke@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=enjuk@amazon.com \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@cloudflare.com \
    --cc=kohei.enju@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).