All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: return -EINVAL from bpf_ringbuf_query for unknown flags
@ 2026-07-10  3:55 Jianlin Shi
  2026-07-10  4:06 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jianlin Shi @ 2026-07-10  3:55 UTC (permalink / raw)
  To: bpf; +Cc: andrii, ast, daniel

bpf_ringbuf_query() returns 0 for unrecognized flags, which is
indistinguishable from a successful BPF_RB_AVAIL_DATA query on an empty
ring buffer. Return -EINVAL instead so invalid flags are reported
explicitly.

Update the helper documentation accordingly and document
BPF_RB_OVERWRITE_POS, which was missing from the description list.

Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
---
 include/uapi/linux/bpf.h | 3 ++-
 kernel/bpf/ringbuf.c     | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index c8d400b76..b18d5810d 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -4664,13 +4664,14 @@ union bpf_attr {
  *		* **BPF_RB_RING_SIZE**: The size of ring buffer.
  *		* **BPF_RB_CONS_POS**: Consumer position (can wrap around).
  *		* **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
+ *		* **BPF_RB_OVERWRITE_POS**: Overwrite position (can wrap around).
  *
  *		Data returned is just a momentary snapshot of actual values
  *		and could be inaccurate, so this facility should be used to
  *		power heuristics and for reporting, not to make 100% correct
  *		calculation.
  *	Return
- *		Requested value, or 0, if *flags* are not recognized.
+ *		Requested value on success. **-EINVAL** if *flags* are not recognized.
  *
  * long bpf_csum_level(struct sk_buff *skb, u64 level)
  * 	Description
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index 35ae64ade..e549acdc6 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -656,7 +656,7 @@ BPF_CALL_2(bpf_ringbuf_query, struct bpf_map *, map, u64, flags)
 	case BPF_RB_OVERWRITE_POS:
 		return smp_load_acquire(&rb->overwrite_pos);
 	default:
-		return 0;
+		return -EINVAL;
 	}
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread
[parent not found: <20260710035555.3725522-1-shijianlin11@foxmail.com>]

end of thread, other threads:[~2026-07-13  1:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10  3:55 [PATCH] bpf: return -EINVAL from bpf_ringbuf_query for unknown flags Jianlin Shi
2026-07-10  4:06 ` sashiko-bot
2026-07-10  4:43 ` bot+bpf-ci
2026-07-10 22:11 ` Andrii Nakryiko
     [not found] <20260710035555.3725522-1-shijianlin11@foxmail.com>
2026-07-13  1:31 ` Jianlin Shi
2026-07-13  1:44 ` Jianlin Shi

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.