* [PATCH bpf v1 0/2] bpf: cpumap: fix error propagation in @ 2025-11-28 16:04 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-11-28 16:04 ` [PATCH bpf v1 2/2] selftests/bpf: add tests for attaching invalid fd Kohei Enju 0 siblings, 2 replies; 13+ messages in thread From: Kohei Enju @ 2025-11-28 16:04 UTC (permalink / raw) To: netdev, bpf Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Lorenzo Bianconi, Shuah Khan, kohei.enju, Kohei Enju This series fixes incorrect error propagation in cpumap and adds selftests that cover the failure cases. Currently, failures returned from __cpu_map_entry_alloc() are ignored and always converted to -ENOMEM by cpu_map_update_elem(). This series ensures the correct error propagation and adds selftests. Kohei Enju (2): bpf: cpumap: propagate underlying error in cpu_map_update_elem() selftests/bpf: add tests for attaching invalid fd kernel/bpf/cpumap.c | 21 ++++++++++++------- .../bpf/prog_tests/xdp_cpumap_attach.c | 19 +++++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) -- 2.51.0 ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-11-28 16:04 [PATCH bpf v1 0/2] bpf: cpumap: fix error propagation in Kohei Enju @ 2025-11-28 16:04 ` Kohei Enju 2025-12-03 1:08 ` Alexei Starovoitov 2025-11-28 16:04 ` [PATCH bpf v1 2/2] selftests/bpf: add tests for attaching invalid fd Kohei Enju 1 sibling, 1 reply; 13+ messages in thread From: Kohei Enju @ 2025-11-28 16:04 UTC (permalink / raw) To: netdev, bpf Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Lorenzo Bianconi, Shuah Khan, kohei.enju, Kohei Enju 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") Signed-off-by: Kohei Enju <enjuk@amazon.com> --- kernel/bpf/cpumap.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index 703e5df1f4ef..04171fbc39cb 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -430,7 +430,7 @@ static struct bpf_cpu_map_entry * __cpu_map_entry_alloc(struct bpf_map *map, struct bpf_cpumap_val *value, u32 cpu) { - int numa, err, i, fd = value->bpf_prog.fd; + int numa, err = -ENOMEM, i, fd = value->bpf_prog.fd; gfp_t gfp = GFP_KERNEL | __GFP_NOWARN; struct bpf_cpu_map_entry *rcpu; struct xdp_bulk_queue *bq; @@ -440,7 +440,7 @@ __cpu_map_entry_alloc(struct bpf_map *map, struct bpf_cpumap_val *value, rcpu = bpf_map_kmalloc_node(map, sizeof(*rcpu), gfp | __GFP_ZERO, numa); if (!rcpu) - return NULL; + return ERR_PTR(err); /* Alloc percpu bulkq */ rcpu->bulkq = bpf_map_alloc_percpu(map, sizeof(*rcpu->bulkq), @@ -468,16 +468,21 @@ __cpu_map_entry_alloc(struct bpf_map *map, struct bpf_cpumap_val *value, rcpu->value.qsize = value->qsize; gro_init(&rcpu->gro); - if (fd > 0 && __cpu_map_load_bpf_program(rcpu, map, fd)) - goto free_ptr_ring; + if (fd > 0) { + err = __cpu_map_load_bpf_program(rcpu, map, fd); + if (err) + goto free_ptr_ring; + } /* Setup kthread */ init_completion(&rcpu->kthread_running); rcpu->kthread = kthread_create_on_node(cpu_map_kthread_run, rcpu, numa, "cpumap/%d/map:%d", cpu, map->id); - if (IS_ERR(rcpu->kthread)) + if (IS_ERR(rcpu->kthread)) { + err = PTR_ERR(rcpu->kthread); goto free_prog; + } /* Make sure kthread runs on a single CPU */ kthread_bind(rcpu->kthread, cpu); @@ -503,7 +508,7 @@ __cpu_map_entry_alloc(struct bpf_map *map, struct bpf_cpumap_val *value, free_percpu(rcpu->bulkq); free_rcu: kfree(rcpu); - return NULL; + return ERR_PTR(err); } static void __cpu_map_entry_free(struct work_struct *work) @@ -596,8 +601,8 @@ static long cpu_map_update_elem(struct bpf_map *map, void *key, void *value, } else { /* Updating qsize cause re-allocation of bpf_cpu_map_entry */ rcpu = __cpu_map_entry_alloc(map, &cpumap_value, key_cpu); - if (!rcpu) - return -ENOMEM; + if (IS_ERR(rcpu)) + return PTR_ERR(rcpu); } rcu_read_lock(); __cpu_map_entry_replace(cmap, key_cpu, rcpu); -- 2.51.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 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 0 siblings, 1 reply; 13+ messages in thread From: Alexei Starovoitov @ 2025-12-03 1:08 UTC (permalink / raw) To: Kohei Enju Cc: Network Development, bpf, Alexei Starovoitov, Daniel Borkmann, David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Lorenzo Bianconi, Shuah Khan, kohei.enju 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. I'd like Jesper and/or other cpumap experts to confirm that it's ok. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-03 1:08 ` Alexei Starovoitov @ 2025-12-03 10:40 ` Kohei Enju 2025-12-03 12:12 ` Jesper Dangaard Brouer 0 siblings, 1 reply; 13+ messages in thread From: Kohei Enju @ 2025-12-03 10:40 UTC (permalink / raw) To: alexei.starovoitov Cc: andrii, ast, bpf, daniel, davem, eddyz87, enjuk, haoluo, hawk, john.fastabend, jolsa, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, yonghong.song 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. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 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 0 siblings, 1 reply; 13+ messages in thread From: Jesper Dangaard Brouer @ 2025-12-03 12:12 UTC (permalink / raw) To: Kohei Enju, alexei.starovoitov Cc: andrii, ast, bpf, daniel, davem, eddyz87, haoluo, john.fastabend, jolsa, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, yonghong.song, kernel-team 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 :-) Bcc'ed some Cloudflare people that use cpumap, so add link to change: [1] https://lore.kernel.org/all/20251128160504.57844-2-enjuk@amazon.com/ ... if they want to object --Jesper ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-03 12:12 ` Jesper Dangaard Brouer @ 2025-12-03 12:31 ` Toke Høiland-Jørgensen 2025-12-06 7:29 ` Kohei Enju 0 siblings, 1 reply; 13+ messages in thread From: Toke Høiland-Jørgensen @ 2025-12-03 12:31 UTC (permalink / raw) To: Jesper Dangaard Brouer, Kohei Enju, alexei.starovoitov Cc: andrii, ast, bpf, daniel, davem, eddyz87, haoluo, john.fastabend, jolsa, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, yonghong.song, kernel-team 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-03 12:31 ` Toke Høiland-Jørgensen @ 2025-12-06 7:29 ` Kohei Enju 2025-12-06 12:00 ` Kohei Enju 0 siblings, 1 reply; 13+ messages in thread From: Kohei Enju @ 2025-12-06 7:29 UTC (permalink / raw) To: toke Cc: alexei.starovoitov, andrii, ast, bpf, daniel, davem, eddyz87, enjuk, haoluo, hawk, john.fastabend, jolsa, kernel-team, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, yonghong.song On Wed, 03 Dec 2025 13:31:29 +0100, Toke Høiland-Jørgensen wrote: >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 Thank you for the clarification, Toke and Jesper. Since I see no objections so far, I'll work on v2 and resend next week. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-06 7:29 ` Kohei Enju @ 2025-12-06 12:00 ` Kohei Enju 2025-12-06 12:06 ` Alexei Starovoitov 0 siblings, 1 reply; 13+ messages in thread From: Kohei Enju @ 2025-12-06 12:00 UTC (permalink / raw) To: enjuk Cc: alexei.starovoitov, andrii, ast, bpf, daniel, davem, eddyz87, haoluo, hawk, john.fastabend, jolsa, kernel-team, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, toke, yonghong.song On Sat, 6 Dec 2025 16:29:44 +0900, Kohei Enju wrote: >On Wed, 03 Dec 2025 13:31:29 +0100, Toke H�iland-J�rgensen wrote: > >>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\u202fAM 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 > >Thank you for the clarification, Toke and Jesper. >Since I see no objections so far, I'll work on v2 and resend next week. Ah, I forgot that bpf-next is closed until Jan 2nd due to the merge window. I'll resend v2 after Jan 2nd :) ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-06 12:00 ` Kohei Enju @ 2025-12-06 12:06 ` Alexei Starovoitov 2025-12-06 12:14 ` Kohei Enju 0 siblings, 1 reply; 13+ messages in thread From: Alexei Starovoitov @ 2025-12-06 12:06 UTC (permalink / raw) To: Kohei Enju Cc: Andrii Nakryiko, Alexei Starovoitov, bpf, Daniel Borkmann, David S. Miller, Eduard, Hao Luo, Jesper Dangaard Brouer, John Fastabend, Jiri Olsa, kernel-team, kohei.enju, KP Singh, Jakub Kicinski, Lorenzo Bianconi, Martin KaFai Lau, Network Development, Stanislav Fomichev, Shuah Khan, Song Liu, Toke Høiland-Jørgensen, Yonghong Song On Sat, Dec 6, 2025 at 9:01 PM Kohei Enju <enjuk@amazon.com> wrote: > > Ah, I forgot that bpf-next is closed until Jan 2nd due to the merge window. > I'll resend v2 after Jan 2nd :) ?! It's not closed. net-next is. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-06 12:06 ` Alexei Starovoitov @ 2025-12-06 12:14 ` Kohei Enju 2025-12-06 12:22 ` Alexei Starovoitov 0 siblings, 1 reply; 13+ messages in thread From: Kohei Enju @ 2025-12-06 12:14 UTC (permalink / raw) To: alexei.starovoitov Cc: andrii, ast, bpf, daniel, davem, eddyz87, enjuk, haoluo, hawk, john.fastabend, jolsa, kernel-team, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, toke, yonghong.song On Sat, 6 Dec 2025 04:06:38 -0800, Alexei Starovoitov wrote: >On Sat, Dec 6, 2025 at 9:01 PM Kohei Enju <enjuk@amazon.com> wrote: >> >> Ah, I forgot that bpf-next is closed until Jan 2nd due to the merge window. >> I'll resend v2 after Jan 2nd :) > >?! It's not closed. net-next is. Oh, really? Hmm, I've read the documentation[1], but I may misunderstand something. Perhaps that documentation is outdated? [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/bpf/bpf_devel_QA.rst#n232 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-06 12:14 ` Kohei Enju @ 2025-12-06 12:22 ` Alexei Starovoitov 2025-12-06 12:26 ` Kohei Enju 0 siblings, 1 reply; 13+ messages in thread From: Alexei Starovoitov @ 2025-12-06 12:22 UTC (permalink / raw) To: Kohei Enju Cc: Andrii Nakryiko, Alexei Starovoitov, bpf, Daniel Borkmann, David S. Miller, Eduard, Hao Luo, Jesper Dangaard Brouer, John Fastabend, Jiri Olsa, kernel-team, kohei.enju, KP Singh, Jakub Kicinski, Lorenzo Bianconi, Martin KaFai Lau, Network Development, Stanislav Fomichev, Shuah Khan, Song Liu, Toke Høiland-Jørgensen, Yonghong Song On Sat, Dec 6, 2025 at 9:14 PM Kohei Enju <enjuk@amazon.com> wrote: > > On Sat, 6 Dec 2025 04:06:38 -0800, Alexei Starovoitov wrote: > > >On Sat, Dec 6, 2025 at 9:01 PM Kohei Enju <enjuk@amazon.com> wrote: > >> > >> Ah, I forgot that bpf-next is closed until Jan 2nd due to the merge window. > >> I'll resend v2 after Jan 2nd :) > > > >?! It's not closed. net-next is. > > Oh, really? > Hmm, I've read the documentation[1], but I may misunderstand something. Perhaps that documentation is outdated? > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/bpf/bpf_devel_QA.rst#n232 yes. It's seriously outdated. bpf-next was never closed. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH bpf v1 1/2] bpf: cpumap: propagate underlying error in cpu_map_update_elem() 2025-12-06 12:22 ` Alexei Starovoitov @ 2025-12-06 12:26 ` Kohei Enju 0 siblings, 0 replies; 13+ messages in thread From: Kohei Enju @ 2025-12-06 12:26 UTC (permalink / raw) To: alexei.starovoitov Cc: andrii, ast, bpf, daniel, davem, eddyz87, enjuk, haoluo, hawk, john.fastabend, jolsa, kernel-team, kohei.enju, kpsingh, kuba, lorenzo, martin.lau, netdev, sdf, shuah, song, toke, yonghong.song On Sat, 6 Dec 2025 04:22:02 -0800, Alexei Starovoitov wrote: >On Sat, Dec 6, 2025 at 9:14 PM Kohei Enju <enjuk@amazon.com> wrote: >> >> On Sat, 6 Dec 2025 04:06:38 -0800, Alexei Starovoitov wrote: >> >> >On Sat, Dec 6, 2025 at 9:01 PM Kohei Enju <enjuk@amazon.com> wrote: >> >> >> >> Ah, I forgot that bpf-next is closed until Jan 2nd due to the merge window. >> >> I'll resend v2 after Jan 2nd :) >> > >> >?! It's not closed. net-next is. >> >> Oh, really? >> Hmm, I've read the documentation[1], but I may misunderstand something. Perhaps that documentation is outdated? >> >> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/bpf/bpf_devel_QA.rst#n232 > >yes. It's seriously outdated. bpf-next was never closed. Today I learned! Thank you for the clarification. As originally planned, I will work on v2 next week :) ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH bpf v1 2/2] selftests/bpf: add tests for attaching invalid fd 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-11-28 16:04 ` Kohei Enju 1 sibling, 0 replies; 13+ messages in thread From: Kohei Enju @ 2025-11-28 16:04 UTC (permalink / raw) To: netdev, bpf Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Lorenzo Bianconi, Shuah Khan, kohei.enju, Kohei Enju Add test cases for situations where adding the following types of file descriptors to a cpumap entry should fail: - Non-BPF file descriptor (expect -EINVAL) - Nonexistent file descriptor (expect -EBADF) Also tighten the assertion for the expected error when adding a non-BPF_XDP_CPUMAP program to a cpumap entry. Signed-off-by: Kohei Enju <enjuk@amazon.com> --- .../bpf/prog_tests/xdp_cpumap_attach.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c index df27535995af..ad56e4370ce3 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c @@ -18,7 +18,7 @@ static void test_xdp_with_cpumap_helpers(void) struct bpf_cpumap_val val = { .qsize = 192, }; - int err, prog_fd, prog_redir_fd, map_fd; + int err, prog_fd, prog_redir_fd, map_fd, bad_fd; struct nstoken *nstoken = NULL; __u32 idx = 0; @@ -79,7 +79,22 @@ static void test_xdp_with_cpumap_helpers(void) val.qsize = 192; val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog); err = bpf_map_update_elem(map_fd, &idx, &val, 0); - ASSERT_NEQ(err, 0, "Add non-BPF_XDP_CPUMAP program to cpumap entry"); + ASSERT_EQ(err, -EINVAL, "Add non-BPF_XDP_CPUMAP program to cpumap entry"); + + /* Try to attach non-BPF file descriptor */ + bad_fd = open("/dev/null", O_RDONLY); + ASSERT_GE(bad_fd, 0, "Open /dev/null for non-BPF fd"); + + val.bpf_prog.fd = bad_fd; + err = bpf_map_update_elem(map_fd, &idx, &val, 0); + ASSERT_EQ(err, -EINVAL, "Add non-BPF fd to cpumap entry"); + + /* Try to attach nonexistent file descriptor */ + err = close(bad_fd); + ASSERT_EQ(err, 0, "Close non-BPF fd for nonexistent fd"); + + err = bpf_map_update_elem(map_fd, &idx, &val, 0); + ASSERT_EQ(err, -EBADF, "Add nonexistent fd to cpumap entry"); /* Try to attach BPF_XDP program with frags to cpumap when we have * already loaded a BPF_XDP program on the map -- 2.51.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-12-06 12:27 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).