linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] man/man7/socket.7: fix documentation for SO_ATTACH_REUSEPORT_EBPF
@ 2025-10-27 13:17 Vincent Bernat
  2025-10-27 13:24 ` Alejandro Colomar
  0 siblings, 1 reply; 4+ messages in thread
From: Vincent Bernat @ 2025-10-27 13:17 UTC (permalink / raw)
  To: Alejandro Colomar, linux-man; +Cc: Vincent Bernat, Craig Gallek

When using eBPF, the program should not return an index, but a
decision (SK_PASS/SK_DROP). The socket should be selected using the
sk_select_reuseport helper.

Cc: Craig Gallek <kraig@google.com>
Signed-off-by: Vincent Bernat <vincent@bernat.ch>
---
 man/man7/socket.7 | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/man/man7/socket.7 b/man/man7/socket.7
index b4d58a23d5da..d85fdd931e42 100644
--- a/man/man7/socket.7
+++ b/man/man7/socket.7
@@ -354,20 +354,25 @@ the sockets in the reuseport group (that is, all sockets which have
 .B SO_REUSEPORT
 set and are using the same local address to receive packets).
 .IP
-The BPF program must return an index between 0 and N\-1 representing
-the socket which should receive the packet
-(where N is the number of sockets in the group).
-If the BPF program returns an invalid index,
-socket selection will fall back to the plain
+The classic BPF program must return an index between 0 and
+N\-1 representing the socket which should receive the packet
+(where N is the number of sockets in the group). If the BPF
+program returns an invalid index, socket selection will fall
+back to the plain
 .B SO_REUSEPORT
 mechanism.
-.IP
 Sockets are numbered in the order in which they are added to the group
 (that is, the order of
 .BR bind (2)
 calls for UDP sockets or the order of
 .BR listen (2)
 calls for TCP sockets).
+.IP
+The extended BPF program must return a decision and the
+.B bpf_sk_select_reuseport
+helper should be used to select the socket which should receive
+the packet.
+.IP
 New sockets added to a reuseport group will inherit the BPF program.
 When a socket is removed from a reuseport group (via
 .BR close (2)),
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] man/man7/socket.7: fix documentation for SO_ATTACH_REUSEPORT_EBPF
  2025-10-27 13:17 [PATCH] man/man7/socket.7: fix documentation for SO_ATTACH_REUSEPORT_EBPF Vincent Bernat
@ 2025-10-27 13:24 ` Alejandro Colomar
  2025-10-27 19:11   ` Vincent Bernat
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2025-10-27 13:24 UTC (permalink / raw)
  To: Vincent Bernat; +Cc: linux-man, Craig Gallek

[-- Attachment #1: Type: text/plain, Size: 2264 bytes --]

Hi Vincent,

On Mon, Oct 27, 2025 at 02:17:00PM +0100, Vincent Bernat wrote:
> When using eBPF, the program should not return an index, but a
> decision (SK_PASS/SK_DROP). The socket should be selected using the
> sk_select_reuseport helper.
> 
> Cc: Craig Gallek <kraig@google.com>
> Signed-off-by: Vincent Bernat <vincent@bernat.ch>

Would you mind adding a Fixes: tag for the commit that introduced the
incorrect text?

Also, do you have a guess of why the wrong text was written?  It would
be useful to have an idea of that.


Have a lovely day!
Alex

> ---
>  man/man7/socket.7 | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/man/man7/socket.7 b/man/man7/socket.7
> index b4d58a23d5da..d85fdd931e42 100644
> --- a/man/man7/socket.7
> +++ b/man/man7/socket.7
> @@ -354,20 +354,25 @@ the sockets in the reuseport group (that is, all sockets which have
>  .B SO_REUSEPORT
>  set and are using the same local address to receive packets).
>  .IP
> -The BPF program must return an index between 0 and N\-1 representing
> -the socket which should receive the packet
> -(where N is the number of sockets in the group).
> -If the BPF program returns an invalid index,
> -socket selection will fall back to the plain
> +The classic BPF program must return an index between 0 and
> +N\-1 representing the socket which should receive the packet
> +(where N is the number of sockets in the group). If the BPF
> +program returns an invalid index, socket selection will fall
> +back to the plain
>  .B SO_REUSEPORT
>  mechanism.
> -.IP
>  Sockets are numbered in the order in which they are added to the group
>  (that is, the order of
>  .BR bind (2)
>  calls for UDP sockets or the order of
>  .BR listen (2)
>  calls for TCP sockets).
> +.IP
> +The extended BPF program must return a decision and the
> +.B bpf_sk_select_reuseport
> +helper should be used to select the socket which should receive
> +the packet.
> +.IP
>  New sockets added to a reuseport group will inherit the BPF program.
>  When a socket is removed from a reuseport group (via
>  .BR close (2)),
> -- 
> 2.51.0
> 

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] man/man7/socket.7: fix documentation for SO_ATTACH_REUSEPORT_EBPF
  2025-10-27 13:24 ` Alejandro Colomar
@ 2025-10-27 19:11   ` Vincent Bernat
       [not found]     ` <CAEfhGiz9OLu=arVoPFJhYTr3h-wB5QR5sOkgNDMzwR+74NUEBw@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Vincent Bernat @ 2025-10-27 19:11 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: linux-man, Craig Gallek

On 2025-10-27 14:24, Alejandro Colomar wrote:

> On Mon, Oct 27, 2025 at 02:17:00PM +0100, Vincent Bernat wrote:
>> When using eBPF, the program should not return an index, but a
>> decision (SK_PASS/SK_DROP). The socket should be selected using the
>> sk_select_reuseport helper.
>>
>> Cc: Craig Gallek <kraig@google.com>
>> Signed-off-by: Vincent Bernat <vincent@bernat.ch>
> 
> Would you mind adding a Fixes: tag for the commit that introduced the
> incorrect text?

This is 1fa871f5378e (2016-03-01; "socket.7: Document some BPF-related 
socket options")
> Also, do you have a guess of why the wrong text was written?  It would
> be useful to have an idea of that.

Not a clue, but maybe let's wait when Craig comes back from vacation so 
he could say if there was a change or not and tell if I am correct.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] man/man7/socket.7: fix documentation for SO_ATTACH_REUSEPORT_EBPF
       [not found]     ` <CAEfhGiz9OLu=arVoPFJhYTr3h-wB5QR5sOkgNDMzwR+74NUEBw@mail.gmail.com>
@ 2025-11-03 20:28       ` Vincent Bernat
  0 siblings, 0 replies; 4+ messages in thread
From: Vincent Bernat @ 2025-11-03 20:28 UTC (permalink / raw)
  To: Craig Gallek; +Cc: Alejandro Colomar, linux-man, Martin KaFai Lau

On 2025-11-03 17:31, Craig Gallek wrote:

>      > On Mon, Oct 27, 2025 at 02:17:00PM +0100, Vincent Bernat wrote:
>      >> When using eBPF, the program should not return an index, but a
>      >> decision (SK_PASS/SK_DROP). The socket should be selected using the
>      >> sk_select_reuseport helper.
>      >>
>      >> Cc: Craig Gallek <kraig@google.com <mailto:kraig@google.com>>
>      >> Signed-off-by: Vincent Bernat <vincent@bernat.ch
>     <mailto:vincent@bernat.ch>>
>      >
>      > Would you mind adding a Fixes: tag for the commit that introduced the
>      > incorrect text?
> 
>     This is 1fa871f5378e (2016-03-01; "socket.7: Document some BPF-related
>     socket options")
>      > Also, do you have a guess of why the wrong text was written?  It
>     would
>      > be useful to have an idea of that.
> 
>     Not a clue, but maybe let's wait when Craig comes back from vacation so
>     he could say if there was a change or not and tell if I am correct.
> 
> 
> It's been a while since I've used this code, but it looks like the 
> sk_select_reuseport helper was added a few years later by Martin KaFai 
> Lau in 2dbb9b9e6df6.  The execution of the bpf program (run_bpf_filter 
> in sock_reuseport.c) still uses the program's 'returned' value in both 
> the cbpf and ebpf cases, but it looks like Martin's change tightened up 
> the 'type' of eBPF program that can be used for this purpose and 
> included this helper function to allow for an explicit validation 
> instead of just having the program return a raw integer value.
> 
> So I think this is just a case of the documentation not keeping up with 
> the code.  I'm less familiar with the PASS/DROP syntax, but I'm guessing 
> that came along after the initial implementation of these reuseport BPF 
> programs as well.
> 
> In any event, my quick read of the code lines up with your proposed 
> documentation change.  It might be worth having Martin verify as well, 
> but this looks good to me.

OK, so, two things are possible and the kernel selects depending on the 
program type (BPF_PROG_TYPE_SOCKET_FILTER or BPF_PROG_TYPE_SK_REUSEPORT).

if (prog->type == BPF_PROG_TYPE_SK_REUSEPORT)
     sk2 = bpf_run_sk_reuseport(reuse, sk, prog, skb, NULL, hash);
else
     sk2 = run_bpf_filter(reuse, socks, prog, skb, hdr_len);

So, I can update the documentation for that, as I have missed it. 
Waiting for Martin feedback in case there is something else.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-03 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 13:17 [PATCH] man/man7/socket.7: fix documentation for SO_ATTACH_REUSEPORT_EBPF Vincent Bernat
2025-10-27 13:24 ` Alejandro Colomar
2025-10-27 19:11   ` Vincent Bernat
     [not found]     ` <CAEfhGiz9OLu=arVoPFJhYTr3h-wB5QR5sOkgNDMzwR+74NUEBw@mail.gmail.com>
2025-11-03 20:28       ` Vincent Bernat

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).