BPF List
 help / color / mirror / Atom feed
* PF_PACKET RPS like using bpf
@ 2024-03-14  8:05 Alexandre Cassen
  2024-03-15 17:31 ` Stanislav Fomichev
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Cassen @ 2024-03-14  8:05 UTC (permalink / raw)
  To: bpf

Hello,

While implementing a large scale L2 processing soft, there is a need for 
high perf ingress handling.

In short: using BPF socket_filter prog with a hash func over ethernet 
address to distribute load across multiple PF_PACKET sockets: mainly 
filtering out non related hkey packets. It simplify userland app by 
using multiple PF_PACKET sockets in dedicated pthread.

Longer discussion + quick source code illustration here:

https://github.com/acassen/bpf-pfpacket-rps


My question would be related to sockmap. I tried to figure out how to 
perform the same policing design using sockmap. And cant find my way 
around it :/ If bpf verdict prog can get socket fd from __sk_buff then 
it could drives the same hash/policing decision.

Is it possible to get socket fd from __sk_buff from sockmap verdict prog ?

regs,
Alexandre

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

* Re: PF_PACKET RPS like using bpf
  2024-03-14  8:05 PF_PACKET RPS like using bpf Alexandre Cassen
@ 2024-03-15 17:31 ` Stanislav Fomichev
  2024-03-15 18:06   ` Alexandre Cassen
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislav Fomichev @ 2024-03-15 17:31 UTC (permalink / raw)
  To: Alexandre Cassen; +Cc: bpf

On 03/14, Alexandre Cassen wrote:
> Hello,
> 
> While implementing a large scale L2 processing soft, there is a need for
> high perf ingress handling.
> 
> In short: using BPF socket_filter prog with a hash func over ethernet
> address to distribute load across multiple PF_PACKET sockets: mainly
> filtering out non related hkey packets. It simplify userland app by using
> multiple PF_PACKET sockets in dedicated pthread.
> 
> Longer discussion + quick source code illustration here:
> 
> https://github.com/acassen/bpf-pfpacket-rps
> 
> 
> My question would be related to sockmap. I tried to figure out how to
> perform the same policing design using sockmap. And cant find my way around
> it :/ If bpf verdict prog can get socket fd from __sk_buff then it could
> drives the same hash/policing decision.
> 
> Is it possible to get socket fd from __sk_buff from sockmap verdict prog ?

Don't have an answer about sockmap, but I'd suggest you look at AF_XDP
if you want the best perf out there with raw frames.
IIRC, it just recently got a mode where you can redirect into multiple
sockets (== consumer threads):

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=2863d665ea41

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

* Re: PF_PACKET RPS like using bpf
  2024-03-15 17:31 ` Stanislav Fomichev
@ 2024-03-15 18:06   ` Alexandre Cassen
  2024-03-15 18:30     ` Stanislav Fomichev
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Cassen @ 2024-03-15 18:06 UTC (permalink / raw)
  To: Stanislav Fomichev; +Cc: bpf



On 15/03/2024 18:31, Stanislav Fomichev wrote:
> On 03/14, Alexandre Cassen wrote:
>> Hello,
>>
>> While implementing a large scale L2 processing soft, there is a need for
>> high perf ingress handling.
>>
>> In short: using BPF socket_filter prog with a hash func over ethernet
>> address to distribute load across multiple PF_PACKET sockets: mainly
>> filtering out non related hkey packets. It simplify userland app by using
>> multiple PF_PACKET sockets in dedicated pthread.
>>
>> Longer discussion + quick source code illustration here:
>>
>> https://github.com/acassen/bpf-pfpacket-rps
>>
>>
>> My question would be related to sockmap. I tried to figure out how to
>> perform the same policing design using sockmap. And cant find my way around
>> it :/ If bpf verdict prog can get socket fd from __sk_buff then it could
>> drives the same hash/policing decision.
>>
>> Is it possible to get socket fd from __sk_buff from sockmap verdict prog ?
> 
> Don't have an answer about sockmap, but I'd suggest you look at AF_XDP
> if you want the best perf out there with raw frames.
> IIRC, it just recently got a mode where you can redirect into multiple
> sockets (== consumer threads):
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=2863d665ea41

thanks for replying, __sk_buff bpf mirror doesnt export struct sock as 
present into kernel skbuff, so no options but extending.
AF_XDP is an option. Will extend test code with it later on.

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

* Re: PF_PACKET RPS like using bpf
  2024-03-15 18:06   ` Alexandre Cassen
@ 2024-03-15 18:30     ` Stanislav Fomichev
  2024-03-18 16:40       ` Yonghong Song
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislav Fomichev @ 2024-03-15 18:30 UTC (permalink / raw)
  To: Alexandre Cassen; +Cc: bpf

On 03/15, Alexandre Cassen wrote:
> 
> 
> On 15/03/2024 18:31, Stanislav Fomichev wrote:
> > On 03/14, Alexandre Cassen wrote:
> > > Hello,
> > > 
> > > While implementing a large scale L2 processing soft, there is a need for
> > > high perf ingress handling.
> > > 
> > > In short: using BPF socket_filter prog with a hash func over ethernet
> > > address to distribute load across multiple PF_PACKET sockets: mainly
> > > filtering out non related hkey packets. It simplify userland app by using
> > > multiple PF_PACKET sockets in dedicated pthread.
> > > 
> > > Longer discussion + quick source code illustration here:
> > > 
> > > https://github.com/acassen/bpf-pfpacket-rps
> > > 
> > > 
> > > My question would be related to sockmap. I tried to figure out how to
> > > perform the same policing design using sockmap. And cant find my way around
> > > it :/ If bpf verdict prog can get socket fd from __sk_buff then it could
> > > drives the same hash/policing decision.
> > > 
> > > Is it possible to get socket fd from __sk_buff from sockmap verdict prog ?
> > 
> > Don't have an answer about sockmap, but I'd suggest you look at AF_XDP
> > if you want the best perf out there with raw frames.
> > IIRC, it just recently got a mode where you can redirect into multiple
> > sockets (== consumer threads):
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=2863d665ea41
> 
> thanks for replying, __sk_buff bpf mirror doesnt export struct sock as
> present into kernel skbuff, so no options but extending.
> AF_XDP is an option. Will extend test code with it later on.

We do export bpf_sock in __sk_buff:

	__bpf_md_ptr(struct bpf_sock *, sk);

But it has a very minimal set of 'struct sock' fields exported.

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

* Re: PF_PACKET RPS like using bpf
  2024-03-15 18:30     ` Stanislav Fomichev
@ 2024-03-18 16:40       ` Yonghong Song
  2024-03-18 21:45         ` Alexandre Cassen
  0 siblings, 1 reply; 6+ messages in thread
From: Yonghong Song @ 2024-03-18 16:40 UTC (permalink / raw)
  To: Stanislav Fomichev, Alexandre Cassen; +Cc: bpf


On 3/15/24 11:30 AM, Stanislav Fomichev wrote:
> On 03/15, Alexandre Cassen wrote:
>>
>> On 15/03/2024 18:31, Stanislav Fomichev wrote:
>>> On 03/14, Alexandre Cassen wrote:
>>>> Hello,
>>>>
>>>> While implementing a large scale L2 processing soft, there is a need for
>>>> high perf ingress handling.
>>>>
>>>> In short: using BPF socket_filter prog with a hash func over ethernet
>>>> address to distribute load across multiple PF_PACKET sockets: mainly
>>>> filtering out non related hkey packets. It simplify userland app by using
>>>> multiple PF_PACKET sockets in dedicated pthread.
>>>>
>>>> Longer discussion + quick source code illustration here:
>>>>
>>>> https://github.com/acassen/bpf-pfpacket-rps
>>>>
>>>>
>>>> My question would be related to sockmap. I tried to figure out how to
>>>> perform the same policing design using sockmap. And cant find my way around
>>>> it :/ If bpf verdict prog can get socket fd from __sk_buff then it could
>>>> drives the same hash/policing decision.
>>>>
>>>> Is it possible to get socket fd from __sk_buff from sockmap verdict prog ?
>>> Don't have an answer about sockmap, but I'd suggest you look at AF_XDP
>>> if you want the best perf out there with raw frames.
>>> IIRC, it just recently got a mode where you can redirect into multiple
>>> sockets (== consumer threads):
>>>
>>> https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=2863d665ea41
>> thanks for replying, __sk_buff bpf mirror doesnt export struct sock as
>> present into kernel skbuff, so no options but extending.
>> AF_XDP is an option. Will extend test code with it later on.
> We do export bpf_sock in __sk_buff:
>
> 	__bpf_md_ptr(struct bpf_sock *, sk);
>
> But it has a very minimal set of 'struct sock' fields exported.

You could use bpf_core_cast() in bpf_core_read.h to cast 'struct bpf_sock' to kernel 'struct sock'.

>

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

* Re: PF_PACKET RPS like using bpf
  2024-03-18 16:40       ` Yonghong Song
@ 2024-03-18 21:45         ` Alexandre Cassen
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Cassen @ 2024-03-18 21:45 UTC (permalink / raw)
  To: Yonghong Song, Stanislav Fomichev; +Cc: bpf



On 18/03/2024 17:40, Yonghong Song wrote:
> 
> On 3/15/24 11:30 AM, Stanislav Fomichev wrote:
>> On 03/15, Alexandre Cassen wrote:
>>>
>>> On 15/03/2024 18:31, Stanislav Fomichev wrote:
>>>> On 03/14, Alexandre Cassen wrote:
>>>>> Hello,
>>>>>
>>>>> While implementing a large scale L2 processing soft, there is a 
>>>>> need for
>>>>> high perf ingress handling.
>>>>>
>>>>> In short: using BPF socket_filter prog with a hash func over ethernet
>>>>> address to distribute load across multiple PF_PACKET sockets: mainly
>>>>> filtering out non related hkey packets. It simplify userland app by 
>>>>> using
>>>>> multiple PF_PACKET sockets in dedicated pthread.
>>>>>
>>>>> Longer discussion + quick source code illustration here:
>>>>>
>>>>> https://github.com/acassen/bpf-pfpacket-rps
>>>>>
>>>>>
>>>>> My question would be related to sockmap. I tried to figure out how to
>>>>> perform the same policing design using sockmap. And cant find my 
>>>>> way around
>>>>> it :/ If bpf verdict prog can get socket fd from __sk_buff then it 
>>>>> could
>>>>> drives the same hash/policing decision.
>>>>>
>>>>> Is it possible to get socket fd from __sk_buff from sockmap verdict 
>>>>> prog ?
>>>> Don't have an answer about sockmap, but I'd suggest you look at AF_XDP
>>>> if you want the best perf out there with raw frames.
>>>> IIRC, it just recently got a mode where you can redirect into multiple
>>>> sockets (== consumer threads):
>>>>
>>>> https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=2863d665ea41
>>> thanks for replying, __sk_buff bpf mirror doesnt export struct sock as
>>> present into kernel skbuff, so no options but extending.
>>> AF_XDP is an option. Will extend test code with it later on.
>> We do export bpf_sock in __sk_buff:
>>
>>     __bpf_md_ptr(struct bpf_sock *, sk);
>>
>> But it has a very minimal set of 'struct sock' fields exported.
> 
> You could use bpf_core_cast() in bpf_core_read.h to cast 'struct 
> bpf_sock' to kernel 'struct sock'.


good idea, other option could be to userland set SO_MARK one time and 
get it back from bpf prog via bpf_sock.mark to drive policing decision

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

end of thread, other threads:[~2024-03-18 21:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-14  8:05 PF_PACKET RPS like using bpf Alexandre Cassen
2024-03-15 17:31 ` Stanislav Fomichev
2024-03-15 18:06   ` Alexandre Cassen
2024-03-15 18:30     ` Stanislav Fomichev
2024-03-18 16:40       ` Yonghong Song
2024-03-18 21:45         ` Alexandre Cassen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox