* XDP_REDIRECT with xsks_map and dev_map @ 2020-06-01 7:50 maharishi bhargava 2020-06-02 9:01 ` Toke Høiland-Jørgensen 0 siblings, 1 reply; 15+ messages in thread From: maharishi bhargava @ 2020-06-01 7:50 UTC (permalink / raw) To: xdp-newbies Hi, in my XDP program, I want to redirect some packets using AF_XDP and redirect other packets directly from driver space. Redirection through AF_XDP works fine, but redirection through dev map stops after some packets are processed. What can be the possible issues and solutions? Thanks, Maharishi Bhargava ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-01 7:50 XDP_REDIRECT with xsks_map and dev_map maharishi bhargava @ 2020-06-02 9:01 ` Toke Høiland-Jørgensen 2020-06-02 15:15 ` maharishi bhargava 0 siblings, 1 reply; 15+ messages in thread From: Toke Høiland-Jørgensen @ 2020-06-02 9:01 UTC (permalink / raw) To: maharishi bhargava, xdp-newbies maharishi bhargava <bhargavamaharishi@gmail.com> writes: > Hi, in my XDP program, I want to redirect some packets using AF_XDP > and redirect other packets directly from driver space. > Redirection through AF_XDP works fine, but redirection through dev map > stops after some packets are processed. Do you mean it stops even if you are *only* redirecting to a devmap, or if you are first redirecting a few packets to AF_XDP, then to devmap? Also, which driver(s) are the physical NICs you're redirecting to/from using, and which kernel version are you on? -Toke ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-02 9:01 ` Toke Høiland-Jørgensen @ 2020-06-02 15:15 ` maharishi bhargava 2020-06-02 16:01 ` Toke Høiland-Jørgensen 0 siblings, 1 reply; 15+ messages in thread From: maharishi bhargava @ 2020-06-02 15:15 UTC (permalink / raw) To: Toke Høiland-Jørgensen; +Cc: xdp-newbies On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > > maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > > Hi, in my XDP program, I want to redirect some packets using AF_XDP > > and redirect other packets directly from driver space. > > Redirection through AF_XDP works fine, but redirection through dev map > > stops after some packets are processed. > > Do you mean it stops even if you are *only* redirecting to a devmap, or > if you are first redirecting a few packets to AF_XDP, then to devmap? > > Also, which driver(s) are the physical NICs you're redirecting to/from > using, and which kernel version are you on? > > -Toke Currently, I'm trying to redirect packets only using devmap. But also have code for redirection using AF_XDP(only when a given condition is satisfied). A DPDK program is running in userspace which will receive packets from AF_XDP. Drivers: ixgbe (2x10GbE Intel NIC) Kernel version 5.3 - Maharishi Bhargava ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-02 15:15 ` maharishi bhargava @ 2020-06-02 16:01 ` Toke Høiland-Jørgensen 2020-06-02 18:23 ` maharishi bhargava 0 siblings, 1 reply; 15+ messages in thread From: Toke Høiland-Jørgensen @ 2020-06-02 16:01 UTC (permalink / raw) To: maharishi bhargava; +Cc: xdp-newbies maharishi bhargava <bhargavamaharishi@gmail.com> writes: > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP >> > and redirect other packets directly from driver space. >> > Redirection through AF_XDP works fine, but redirection through dev map >> > stops after some packets are processed. >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or >> if you are first redirecting a few packets to AF_XDP, then to devmap? >> >> Also, which driver(s) are the physical NICs you're redirecting to/from >> using, and which kernel version are you on? >> >> -Toke > > > > Currently, I'm trying to redirect packets only using devmap. But also > have code for redirection using AF_XDP(only when a given condition is > satisfied). A DPDK program is running in userspace which will receive > packets from AF_XDP. Right, so it's just devmap redirect that breaks. What do you mean 'redirection stops', exactly? How are you seeing this? Does xdp_monitor (from samples/bpf) report any exceptions? -Toke ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-02 16:01 ` Toke Høiland-Jørgensen @ 2020-06-02 18:23 ` maharishi bhargava 2020-06-03 10:49 ` Toke Høiland-Jørgensen 0 siblings, 1 reply; 15+ messages in thread From: maharishi bhargava @ 2020-06-02 18:23 UTC (permalink / raw) To: Toke Høiland-Jørgensen; +Cc: xdp-newbies On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > >> > and redirect other packets directly from driver space. > >> > Redirection through AF_XDP works fine, but redirection through dev map > >> > stops after some packets are processed. > >> > >> Do you mean it stops even if you are *only* redirecting to a devmap, or > >> if you are first redirecting a few packets to AF_XDP, then to devmap? > >> > >> Also, which driver(s) are the physical NICs you're redirecting to/from > >> using, and which kernel version are you on? > >> > >> -Toke > > > > > > > > Currently, I'm trying to redirect packets only using devmap. But also > > have code for redirection using AF_XDP(only when a given condition is > > satisfied). A DPDK program is running in userspace which will receive > > packets from AF_XDP. > > Right, so it's just devmap redirect that breaks. What do you mean > 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > (from samples/bpf) report any exceptions? > > -Toke > So, In my setup, there are three systems, Let's Assume A, B, C. System B is acting as a forwarder between A and C. So I can see the number of packets received at system C. To be specific, only 1024 packets are received. If I remove the xsks_map part from the code and don't run DPDK in userspace. This problem does not occur. Also if I forward all the packets using AF_XDP, there is no such issue. - Maharishi ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-02 18:23 ` maharishi bhargava @ 2020-06-03 10:49 ` Toke Høiland-Jørgensen 2020-06-03 10:48 ` Maciej Fijalkowski 0 siblings, 1 reply; 15+ messages in thread From: Toke Høiland-Jørgensen @ 2020-06-03 10:49 UTC (permalink / raw) To: maharishi bhargava; +Cc: xdp-newbies maharishi bhargava <bhargavamaharishi@gmail.com> writes: > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: >> >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP >> >> > and redirect other packets directly from driver space. >> >> > Redirection through AF_XDP works fine, but redirection through dev map >> >> > stops after some packets are processed. >> >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? >> >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from >> >> using, and which kernel version are you on? >> >> >> >> -Toke >> > >> > >> > >> > Currently, I'm trying to redirect packets only using devmap. But also >> > have code for redirection using AF_XDP(only when a given condition is >> > satisfied). A DPDK program is running in userspace which will receive >> > packets from AF_XDP. >> >> Right, so it's just devmap redirect that breaks. What do you mean >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor >> (from samples/bpf) report any exceptions? >> >> -Toke >> > So, In my setup, there are three systems, Let's Assume A, B, C. System > B is acting as a forwarder between A and C. So I can see the number of > packets received at system C. To be specific, only 1024 packets are > received. If I remove the xsks_map part from the code and don't run > DPDK in userspace. This problem does not occur. Also if I forward all > the packets using AF_XDP, there is no such issue. I thought you said you were seeing the problem when only redirecting to a devmap? So why does the xsk_map code impact this? I think you may have to share some code... Also, what does xdp_monitor say? -Toke ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-03 10:49 ` Toke Høiland-Jørgensen @ 2020-06-03 10:48 ` Maciej Fijalkowski 2020-06-03 11:07 ` Toke Høiland-Jørgensen 0 siblings, 1 reply; 15+ messages in thread From: Maciej Fijalkowski @ 2020-06-03 10:48 UTC (permalink / raw) To: Toke Høiland-Jørgensen; +Cc: maharishi bhargava, xdp-newbies On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: > maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > >> >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> >> > >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > >> >> > and redirect other packets directly from driver space. > >> >> > Redirection through AF_XDP works fine, but redirection through dev map > >> >> > stops after some packets are processed. > >> >> > >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or > >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? > >> >> > >> >> Also, which driver(s) are the physical NICs you're redirecting to/from > >> >> using, and which kernel version are you on? > >> >> > >> >> -Toke > >> > > >> > > >> > > >> > Currently, I'm trying to redirect packets only using devmap. But also > >> > have code for redirection using AF_XDP(only when a given condition is > >> > satisfied). A DPDK program is running in userspace which will receive > >> > packets from AF_XDP. > >> > >> Right, so it's just devmap redirect that breaks. What do you mean > >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > >> (from samples/bpf) report any exceptions? > >> > >> -Toke > >> > > So, In my setup, there are three systems, Let's Assume A, B, C. System > > B is acting as a forwarder between A and C. So I can see the number of > > packets received at system C. To be specific, only 1024 packets are > > received. If I remove the xsks_map part from the code and don't run > > DPDK in userspace. This problem does not occur. Also if I forward all > > the packets using AF_XDP, there is no such issue. > > I thought you said you were seeing the problem when only redirecting to > a devmap? So why does the xsk_map code impact this? I think you may have > to share some code... Isn't the case here that either xsk_map or dev_map consumes the frame and therefore the latter doesn't see it? so cloning might be needed here? > > Also, what does xdp_monitor say? > > -Toke > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-03 10:48 ` Maciej Fijalkowski @ 2020-06-03 11:07 ` Toke Høiland-Jørgensen 2020-06-03 11:07 ` Maciej Fijalkowski 0 siblings, 1 reply; 15+ messages in thread From: Toke Høiland-Jørgensen @ 2020-06-03 11:07 UTC (permalink / raw) To: Maciej Fijalkowski; +Cc: maharishi bhargava, xdp-newbies Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: >> >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: >> >> >> >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> >> >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP >> >> >> > and redirect other packets directly from driver space. >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map >> >> >> > stops after some packets are processed. >> >> >> >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? >> >> >> >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from >> >> >> using, and which kernel version are you on? >> >> >> >> >> >> -Toke >> >> > >> >> > >> >> > >> >> > Currently, I'm trying to redirect packets only using devmap. But also >> >> > have code for redirection using AF_XDP(only when a given condition is >> >> > satisfied). A DPDK program is running in userspace which will receive >> >> > packets from AF_XDP. >> >> >> >> Right, so it's just devmap redirect that breaks. What do you mean >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor >> >> (from samples/bpf) report any exceptions? >> >> >> >> -Toke >> >> >> > So, In my setup, there are three systems, Let's Assume A, B, C. System >> > B is acting as a forwarder between A and C. So I can see the number of >> > packets received at system C. To be specific, only 1024 packets are >> > received. If I remove the xsks_map part from the code and don't run >> > DPDK in userspace. This problem does not occur. Also if I forward all >> > the packets using AF_XDP, there is no such issue. >> >> I thought you said you were seeing the problem when only redirecting to >> a devmap? So why does the xsk_map code impact this? I think you may have >> to share some code... > > Isn't the case here that either xsk_map or dev_map consumes the frame and > therefore the latter doesn't see it? so cloning might be needed here? Yeah, certainly you can't redirect *the same packet* to both xsk_map and devmap - but that wasn't what I understood was the use case here? -Toke ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-03 11:07 ` Toke Høiland-Jørgensen @ 2020-06-03 11:07 ` Maciej Fijalkowski 2020-06-03 13:43 ` maharishi bhargava 0 siblings, 1 reply; 15+ messages in thread From: Maciej Fijalkowski @ 2020-06-03 11:07 UTC (permalink / raw) To: Toke Høiland-Jørgensen; +Cc: maharishi bhargava, xdp-newbies On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: > > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > >> >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> >> > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > >> >> >> > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> >> >> > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > >> >> >> > and redirect other packets directly from driver space. > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map > >> >> >> > stops after some packets are processed. > >> >> >> > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? > >> >> >> > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from > >> >> >> using, and which kernel version are you on? > >> >> >> > >> >> >> -Toke > >> >> > > >> >> > > >> >> > > >> >> > Currently, I'm trying to redirect packets only using devmap. But also > >> >> > have code for redirection using AF_XDP(only when a given condition is > >> >> > satisfied). A DPDK program is running in userspace which will receive > >> >> > packets from AF_XDP. > >> >> > >> >> Right, so it's just devmap redirect that breaks. What do you mean > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > >> >> (from samples/bpf) report any exceptions? > >> >> > >> >> -Toke > >> >> > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System > >> > B is acting as a forwarder between A and C. So I can see the number of > >> > packets received at system C. To be specific, only 1024 packets are > >> > received. If I remove the xsks_map part from the code and don't run > >> > DPDK in userspace. This problem does not occur. Also if I forward all > >> > the packets using AF_XDP, there is no such issue. > >> > >> I thought you said you were seeing the problem when only redirecting to > >> a devmap? So why does the xsk_map code impact this? I think you may have > >> to share some code... > > > > Isn't the case here that either xsk_map or dev_map consumes the frame and > > therefore the latter doesn't see it? so cloning might be needed here? > > Yeah, certainly you can't redirect *the same packet* to both xsk_map and > devmap - but that wasn't what I understood was the use case here? Maybe the best would be if Maharishi shared the code as you requested :) > > -Toke > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-03 11:07 ` Maciej Fijalkowski @ 2020-06-03 13:43 ` maharishi bhargava 2020-06-03 15:09 ` Toke Høiland-Jørgensen 0 siblings, 1 reply; 15+ messages in thread From: maharishi bhargava @ 2020-06-03 13:43 UTC (permalink / raw) To: Maciej Fijalkowski; +Cc: Toke Høiland-Jørgensen, xdp-newbies On Wed, Jun 3, 2020 at 4:41 PM Maciej Fijalkowski <maciej.fijalkowski@intel.com> wrote: > > On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: > > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: > > > > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: > > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > >> > > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > >> >> > > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > >> >> > > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > > >> >> >> > > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > >> >> >> > > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > > >> >> >> > and redirect other packets directly from driver space. > > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map > > >> >> >> > stops after some packets are processed. > > >> >> >> > > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or > > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? > > >> >> >> > > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from > > >> >> >> using, and which kernel version are you on? > > >> >> >> > > >> >> >> -Toke > > >> >> > > > >> >> > > > >> >> > > > >> >> > Currently, I'm trying to redirect packets only using devmap. But also > > >> >> > have code for redirection using AF_XDP(only when a given condition is > > >> >> > satisfied). A DPDK program is running in userspace which will receive > > >> >> > packets from AF_XDP. > > >> >> > > >> >> Right, so it's just devmap redirect that breaks. What do you mean > > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > > >> >> (from samples/bpf) report any exceptions? > > >> >> > > >> >> -Toke > > >> >> > > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System > > >> > B is acting as a forwarder between A and C. So I can see the number of > > >> > packets received at system C. To be specific, only 1024 packets are > > >> > received. If I remove the xsks_map part from the code and don't run > > >> > DPDK in userspace. This problem does not occur. Also if I forward all > > >> > the packets using AF_XDP, there is no such issue. > > >> > > >> I thought you said you were seeing the problem when only redirecting to > > >> a devmap? So why does the xsk_map code impact this? I think you may have > > >> to share some code... > > > > > > Isn't the case here that either xsk_map or dev_map consumes the frame and > > > therefore the latter doesn't see it? so cloning might be needed here? > > > > Yeah, certainly you can't redirect *the same packet* to both xsk_map and > > devmap - but that wasn't what I understood was the use case here? > > Maybe the best would be if Maharishi shared the code as you requested :) > > > > > -Toke > > CODE: BPF MAPS: struct bpf_map_def SEC("maps") xsks_map = { .type = BPF_MAP_TYPE_XSKMAP, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 64, /* Assume netdev has no more than 64 queues */ }; struct bpf_map_def SEC("maps") tx_port = { .type = BPF_MAP_TYPE_DEVMAP, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 1024, }; struct Ingress_qos_lts_value{ struct bpf_spin_lock lock; u64 timestamp; }; struct bpf_map_def SEC("maps") Ingress_qos_lts = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(struct Ingress_qos_lts_value), .max_entries = 1025, }; BPF_ANNOTATE_KV_PAIR(Ingress_qos_lts,u32,struct Ingress_qos_lts_value); SEC("prog") int ebpf_filter(struct xdp_md *ctx){ struct xdp_output xout; xout.output_port = 1; void* ebpf_packetStart = ((void*)(long)ctx->data); void* ebpf_packetEnd = ((void*)(long)ctx->data_end); u64 rate = 100;//100 Kbps rate *= 1000*1000*100;//10 Gbps u32 key = 1;//some key u64 packet_length=(ebpf_packetEnd-ebpf_packetStart-42)*8; packet_length *= 1000000000; //packet length * 10^9, to convert rate from second to nanosecond struct Ingress_qos_lts_value* val; val = bpf_map_lookup_elem(&Ingress_qos_lts, &key); u64 now = bpf_ktime_get_ns(); u64 lts; if (val) { bpf_spin_lock(&val->lock); lts = *(&val->timestamp)+(packet_length/rate); if(now>lts){ lts = now; } *(&val->timestamp) = lts; bpf_spin_unlock(&val->lock); // printk("Time : %x %x\n",lts,now); if(lts>now){ return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, 0); } } return bpf_redirect_map(&tx_port,xout.output_port,0); } So, Basically this code redirects the packet to some other interface or sends the packet to userspace based on the incoming packet rate. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-03 13:43 ` maharishi bhargava @ 2020-06-03 15:09 ` Toke Høiland-Jørgensen 2020-06-04 19:52 ` maharishi bhargava 0 siblings, 1 reply; 15+ messages in thread From: Toke Høiland-Jørgensen @ 2020-06-03 15:09 UTC (permalink / raw) To: maharishi bhargava, Maciej Fijalkowski; +Cc: xdp-newbies maharishi bhargava <bhargavamaharishi@gmail.com> writes: > On Wed, Jun 3, 2020 at 4:41 PM Maciej Fijalkowski > <maciej.fijalkowski@intel.com> wrote: >> >> On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: >> > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: >> > >> > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> > >> >> > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: >> > >> >> >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> > >> >> >> > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: >> > >> >> >> >> > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> > >> >> >> >> > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP >> > >> >> >> > and redirect other packets directly from driver space. >> > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map >> > >> >> >> > stops after some packets are processed. >> > >> >> >> >> > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or >> > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? >> > >> >> >> >> > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from >> > >> >> >> using, and which kernel version are you on? >> > >> >> >> >> > >> >> >> -Toke >> > >> >> > >> > >> >> > >> > >> >> > >> > >> >> > Currently, I'm trying to redirect packets only using devmap. But also >> > >> >> > have code for redirection using AF_XDP(only when a given condition is >> > >> >> > satisfied). A DPDK program is running in userspace which will receive >> > >> >> > packets from AF_XDP. >> > >> >> >> > >> >> Right, so it's just devmap redirect that breaks. What do you mean >> > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor >> > >> >> (from samples/bpf) report any exceptions? >> > >> >> >> > >> >> -Toke >> > >> >> >> > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System >> > >> > B is acting as a forwarder between A and C. So I can see the number of >> > >> > packets received at system C. To be specific, only 1024 packets are >> > >> > received. If I remove the xsks_map part from the code and don't run >> > >> > DPDK in userspace. This problem does not occur. Also if I forward all >> > >> > the packets using AF_XDP, there is no such issue. >> > >> >> > >> I thought you said you were seeing the problem when only redirecting to >> > >> a devmap? So why does the xsk_map code impact this? I think you may have >> > >> to share some code... >> > > >> > > Isn't the case here that either xsk_map or dev_map consumes the frame and >> > > therefore the latter doesn't see it? so cloning might be needed here? >> > >> > Yeah, certainly you can't redirect *the same packet* to both xsk_map and >> > devmap - but that wasn't what I understood was the use case here? >> >> Maybe the best would be if Maharishi shared the code as you requested :) >> >> > >> > -Toke >> > > CODE: > BPF MAPS: > > > struct bpf_map_def SEC("maps") xsks_map = { > .type = BPF_MAP_TYPE_XSKMAP, > .key_size = sizeof(int), > .value_size = sizeof(int), > .max_entries = 64, /* Assume netdev has no more than 64 queues */ > }; > > struct bpf_map_def SEC("maps") tx_port = { > .type = BPF_MAP_TYPE_DEVMAP, > .key_size = sizeof(int), > .value_size = sizeof(int), > .max_entries = 1024, > }; > > struct Ingress_qos_lts_value{ > struct bpf_spin_lock lock; > u64 timestamp; > }; > struct bpf_map_def SEC("maps") Ingress_qos_lts = { > .type = BPF_MAP_TYPE_ARRAY, > .key_size = sizeof(u32), > .value_size = sizeof(struct Ingress_qos_lts_value), > .max_entries = 1025, > }; > BPF_ANNOTATE_KV_PAIR(Ingress_qos_lts,u32,struct Ingress_qos_lts_value); > > > SEC("prog") > int ebpf_filter(struct xdp_md *ctx){ > struct xdp_output xout; > xout.output_port = 1; > void* ebpf_packetStart = ((void*)(long)ctx->data); > void* ebpf_packetEnd = ((void*)(long)ctx->data_end); > u64 rate = 100;//100 Kbps > rate *= 1000*1000*100;//10 Gbps > u32 key = 1;//some key > u64 packet_length=(ebpf_packetEnd-ebpf_packetStart-42)*8; > packet_length *= 1000000000; //packet length * 10^9, to convert > rate from second to nanosecond > struct Ingress_qos_lts_value* val; > val = bpf_map_lookup_elem(&Ingress_qos_lts, &key); > u64 now = bpf_ktime_get_ns(); > u64 lts; > if (val) { > bpf_spin_lock(&val->lock); > lts = *(&val->timestamp)+(packet_length/rate); > if(now>lts){ > lts = now; > } > *(&val->timestamp) = lts; > bpf_spin_unlock(&val->lock); > // printk("Time : %x %x\n",lts,now); > if(lts>now){ > return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, 0); > } > } > return bpf_redirect_map(&tx_port,xout.output_port,0); > } > > So, Basically this code redirects the packet to some other interface > or sends the packet to userspace based on the incoming packet rate. Well, if you say it goes away when you remove the xsk code, the obvious explanation would be that the packets are being redirected to userspace instead? What does xdp_monitor say? -Toke ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-03 15:09 ` Toke Høiland-Jørgensen @ 2020-06-04 19:52 ` maharishi bhargava 2020-06-04 22:56 ` Toke Høiland-Jørgensen 2020-06-05 11:31 ` Magnus Karlsson 0 siblings, 2 replies; 15+ messages in thread From: maharishi bhargava @ 2020-06-04 19:52 UTC (permalink / raw) To: Toke Høiland-Jørgensen; +Cc: Maciej Fijalkowski, xdp-newbies On Wed, Jun 3, 2020 at 8:39 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > > On Wed, Jun 3, 2020 at 4:41 PM Maciej Fijalkowski > > <maciej.fijalkowski@intel.com> wrote: > >> > >> On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: > >> > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: > >> > > >> > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: > >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> > >> > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > >> > >> >> > >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> >> > >> > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > >> > >> >> >> > >> > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> >> >> > >> > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > >> > >> >> >> > and redirect other packets directly from driver space. > >> > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map > >> > >> >> >> > stops after some packets are processed. > >> > >> >> >> > >> > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or > >> > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? > >> > >> >> >> > >> > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from > >> > >> >> >> using, and which kernel version are you on? > >> > >> >> >> > >> > >> >> >> -Toke > >> > >> >> > > >> > >> >> > > >> > >> >> > > >> > >> >> > Currently, I'm trying to redirect packets only using devmap. But also > >> > >> >> > have code for redirection using AF_XDP(only when a given condition is > >> > >> >> > satisfied). A DPDK program is running in userspace which will receive > >> > >> >> > packets from AF_XDP. > >> > >> >> > >> > >> >> Right, so it's just devmap redirect that breaks. What do you mean > >> > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > >> > >> >> (from samples/bpf) report any exceptions? > >> > >> >> > >> > >> >> -Toke > >> > >> >> > >> > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System > >> > >> > B is acting as a forwarder between A and C. So I can see the number of > >> > >> > packets received at system C. To be specific, only 1024 packets are > >> > >> > received. If I remove the xsks_map part from the code and don't run > >> > >> > DPDK in userspace. This problem does not occur. Also if I forward all > >> > >> > the packets using AF_XDP, there is no such issue. > >> > >> > >> > >> I thought you said you were seeing the problem when only redirecting to > >> > >> a devmap? So why does the xsk_map code impact this? I think you may have > >> > >> to share some code... > >> > > > >> > > Isn't the case here that either xsk_map or dev_map consumes the frame and > >> > > therefore the latter doesn't see it? so cloning might be needed here? > >> > > >> > Yeah, certainly you can't redirect *the same packet* to both xsk_map and > >> > devmap - but that wasn't what I understood was the use case here? > >> > >> Maybe the best would be if Maharishi shared the code as you requested :) > >> > >> > > >> > -Toke > >> > > > CODE: > > BPF MAPS: > > > > > > struct bpf_map_def SEC("maps") xsks_map = { > > .type = BPF_MAP_TYPE_XSKMAP, > > .key_size = sizeof(int), > > .value_size = sizeof(int), > > .max_entries = 64, /* Assume netdev has no more than 64 queues */ > > }; > > > > struct bpf_map_def SEC("maps") tx_port = { > > .type = BPF_MAP_TYPE_DEVMAP, > > .key_size = sizeof(int), > > .value_size = sizeof(int), > > .max_entries = 1024, > > }; > > > > struct Ingress_qos_lts_value{ > > struct bpf_spin_lock lock; > > u64 timestamp; > > }; > > struct bpf_map_def SEC("maps") Ingress_qos_lts = { > > .type = BPF_MAP_TYPE_ARRAY, > > .key_size = sizeof(u32), > > .value_size = sizeof(struct Ingress_qos_lts_value), > > .max_entries = 1025, > > }; > > BPF_ANNOTATE_KV_PAIR(Ingress_qos_lts,u32,struct Ingress_qos_lts_value); > > > > > > SEC("prog") > > int ebpf_filter(struct xdp_md *ctx){ > > struct xdp_output xout; > > xout.output_port = 1; > > void* ebpf_packetStart = ((void*)(long)ctx->data); > > void* ebpf_packetEnd = ((void*)(long)ctx->data_end); > > u64 rate = 100;//100 Kbps > > rate *= 1000*1000*100;//10 Gbps > > u32 key = 1;//some key > > u64 packet_length=(ebpf_packetEnd-ebpf_packetStart-42)*8; > > packet_length *= 1000000000; //packet length * 10^9, to convert > > rate from second to nanosecond > > struct Ingress_qos_lts_value* val; > > val = bpf_map_lookup_elem(&Ingress_qos_lts, &key); > > u64 now = bpf_ktime_get_ns(); > > u64 lts; > > if (val) { > > bpf_spin_lock(&val->lock); > > lts = *(&val->timestamp)+(packet_length/rate); > > if(now>lts){ > > lts = now; > > } > > *(&val->timestamp) = lts; > > bpf_spin_unlock(&val->lock); > > // printk("Time : %x %x\n",lts,now); > > if(lts>now){ > > return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, 0); > > } > > } > > return bpf_redirect_map(&tx_port,xout.output_port,0); > > } > > > > So, Basically this code redirects the packet to some other interface > > or sends the packet to userspace based on the incoming packet rate. > > Well, if you say it goes away when you remove the xsk code, the obvious > explanation would be that the packets are being redirected to userspace > instead? What does xdp_monitor say? > > -Toke > No packets are not going to userspace. NIC stops processing any more packets after 1024 redirected packets. I'll post the results of xdp_monitor asap. Also, one piece of information that might be helpful. In DPDK's default code for creating xsk_socket, the value of bind_flags was 0. When I changed it to XDP_COPY(1 << 1), everything started working correctly. So, is it something like, the socket was getting created in zero-copy mode and as far as I know, kernel version 5.3 does not support zero-copy mode. Due to this xdp_redirect using DEVMAP was not working as expected. - Maharishi ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-04 19:52 ` maharishi bhargava @ 2020-06-04 22:56 ` Toke Høiland-Jørgensen 2020-06-05 11:35 ` Magnus Karlsson 2020-06-05 11:31 ` Magnus Karlsson 1 sibling, 1 reply; 15+ messages in thread From: Toke Høiland-Jørgensen @ 2020-06-04 22:56 UTC (permalink / raw) To: maharishi bhargava; +Cc: Maciej Fijalkowski, xdp-newbies, Magnus Karlsson maharishi bhargava <bhargavamaharishi@gmail.com> writes: > On Wed, Jun 3, 2020 at 8:39 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > On Wed, Jun 3, 2020 at 4:41 PM Maciej Fijalkowski >> > <maciej.fijalkowski@intel.com> wrote: >> >> >> >> On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: >> >> > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: >> >> > >> >> > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: >> >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > >> >> >> > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: >> >> > >> >> >> >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > >> >> >> >> > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: >> >> > >> >> >> >> >> > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: >> >> > >> >> >> >> >> > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP >> >> > >> >> >> > and redirect other packets directly from driver space. >> >> > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map >> >> > >> >> >> > stops after some packets are processed. >> >> > >> >> >> >> >> > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or >> >> > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? >> >> > >> >> >> >> >> > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from >> >> > >> >> >> using, and which kernel version are you on? >> >> > >> >> >> >> >> > >> >> >> -Toke >> >> > >> >> > >> >> > >> >> > >> >> > >> >> > >> >> > >> >> > Currently, I'm trying to redirect packets only using devmap. But also >> >> > >> >> > have code for redirection using AF_XDP(only when a given condition is >> >> > >> >> > satisfied). A DPDK program is running in userspace which will receive >> >> > >> >> > packets from AF_XDP. >> >> > >> >> >> >> > >> >> Right, so it's just devmap redirect that breaks. What do you mean >> >> > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor >> >> > >> >> (from samples/bpf) report any exceptions? >> >> > >> >> >> >> > >> >> -Toke >> >> > >> >> >> >> > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System >> >> > >> > B is acting as a forwarder between A and C. So I can see the number of >> >> > >> > packets received at system C. To be specific, only 1024 packets are >> >> > >> > received. If I remove the xsks_map part from the code and don't run >> >> > >> > DPDK in userspace. This problem does not occur. Also if I forward all >> >> > >> > the packets using AF_XDP, there is no such issue. >> >> > >> >> >> > >> I thought you said you were seeing the problem when only redirecting to >> >> > >> a devmap? So why does the xsk_map code impact this? I think you may have >> >> > >> to share some code... >> >> > > >> >> > > Isn't the case here that either xsk_map or dev_map consumes the frame and >> >> > > therefore the latter doesn't see it? so cloning might be needed here? >> >> > >> >> > Yeah, certainly you can't redirect *the same packet* to both xsk_map and >> >> > devmap - but that wasn't what I understood was the use case here? >> >> >> >> Maybe the best would be if Maharishi shared the code as you requested :) >> >> >> >> > >> >> > -Toke >> >> > >> > CODE: >> > BPF MAPS: >> > >> > >> > struct bpf_map_def SEC("maps") xsks_map = { >> > .type = BPF_MAP_TYPE_XSKMAP, >> > .key_size = sizeof(int), >> > .value_size = sizeof(int), >> > .max_entries = 64, /* Assume netdev has no more than 64 queues */ >> > }; >> > >> > struct bpf_map_def SEC("maps") tx_port = { >> > .type = BPF_MAP_TYPE_DEVMAP, >> > .key_size = sizeof(int), >> > .value_size = sizeof(int), >> > .max_entries = 1024, >> > }; >> > >> > struct Ingress_qos_lts_value{ >> > struct bpf_spin_lock lock; >> > u64 timestamp; >> > }; >> > struct bpf_map_def SEC("maps") Ingress_qos_lts = { >> > .type = BPF_MAP_TYPE_ARRAY, >> > .key_size = sizeof(u32), >> > .value_size = sizeof(struct Ingress_qos_lts_value), >> > .max_entries = 1025, >> > }; >> > BPF_ANNOTATE_KV_PAIR(Ingress_qos_lts,u32,struct Ingress_qos_lts_value); >> > >> > >> > SEC("prog") >> > int ebpf_filter(struct xdp_md *ctx){ >> > struct xdp_output xout; >> > xout.output_port = 1; >> > void* ebpf_packetStart = ((void*)(long)ctx->data); >> > void* ebpf_packetEnd = ((void*)(long)ctx->data_end); >> > u64 rate = 100;//100 Kbps >> > rate *= 1000*1000*100;//10 Gbps >> > u32 key = 1;//some key >> > u64 packet_length=(ebpf_packetEnd-ebpf_packetStart-42)*8; >> > packet_length *= 1000000000; //packet length * 10^9, to convert >> > rate from second to nanosecond >> > struct Ingress_qos_lts_value* val; >> > val = bpf_map_lookup_elem(&Ingress_qos_lts, &key); >> > u64 now = bpf_ktime_get_ns(); >> > u64 lts; >> > if (val) { >> > bpf_spin_lock(&val->lock); >> > lts = *(&val->timestamp)+(packet_length/rate); >> > if(now>lts){ >> > lts = now; >> > } >> > *(&val->timestamp) = lts; >> > bpf_spin_unlock(&val->lock); >> > // printk("Time : %x %x\n",lts,now); >> > if(lts>now){ >> > return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, 0); >> > } >> > } >> > return bpf_redirect_map(&tx_port,xout.output_port,0); >> > } >> > >> > So, Basically this code redirects the packet to some other interface >> > or sends the packet to userspace based on the incoming packet rate. >> >> Well, if you say it goes away when you remove the xsk code, the obvious >> explanation would be that the packets are being redirected to userspace >> instead? What does xdp_monitor say? >> >> -Toke >> > No packets are not going to userspace. NIC stops processing any more > packets after 1024 redirected packets. I'll post the results of > xdp_monitor asap. > > Also, one piece of information that might be helpful. In DPDK's > default code for creating xsk_socket, the value of bind_flags was 0. > When I changed it to XDP_COPY(1 << 1), everything started working > correctly. So, is it something like, the socket was getting created in > zero-copy mode and as far as I know, kernel version 5.3 does not > support zero-copy mode. Due to this xdp_redirect using DEVMAP was not > working as expected. Hmm, in zero-copy mode packets are DMA'ed directly into the userspace-provided buffer (hence zero copies). Pretty sure this is incompatible with forwarding them to the stack, whether or not the kernel supports zero-copy in the first place. Cc Magnus who will know for sure. -Toke ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-04 22:56 ` Toke Høiland-Jørgensen @ 2020-06-05 11:35 ` Magnus Karlsson 0 siblings, 0 replies; 15+ messages in thread From: Magnus Karlsson @ 2020-06-05 11:35 UTC (permalink / raw) To: Toke Høiland-Jørgensen Cc: maharishi bhargava, Maciej Fijalkowski, Xdp, Magnus Karlsson On Fri, Jun 5, 2020 at 12:57 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > > On Wed, Jun 3, 2020 at 8:39 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> > >> > On Wed, Jun 3, 2020 at 4:41 PM Maciej Fijalkowski > >> > <maciej.fijalkowski@intel.com> wrote: > >> >> > >> >> On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: > >> >> > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: > >> >> > > >> >> > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: > >> >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> >> > >> > >> >> > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > >> >> > >> >> > >> >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> >> > >> >> > >> >> > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > >> >> > >> >> >> > >> >> > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > >> >> > >> >> >> > >> >> > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > >> >> > >> >> >> > and redirect other packets directly from driver space. > >> >> > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map > >> >> > >> >> >> > stops after some packets are processed. > >> >> > >> >> >> > >> >> > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or > >> >> > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? > >> >> > >> >> >> > >> >> > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from > >> >> > >> >> >> using, and which kernel version are you on? > >> >> > >> >> >> > >> >> > >> >> >> -Toke > >> >> > >> >> > > >> >> > >> >> > > >> >> > >> >> > > >> >> > >> >> > Currently, I'm trying to redirect packets only using devmap. But also > >> >> > >> >> > have code for redirection using AF_XDP(only when a given condition is > >> >> > >> >> > satisfied). A DPDK program is running in userspace which will receive > >> >> > >> >> > packets from AF_XDP. > >> >> > >> >> > >> >> > >> >> Right, so it's just devmap redirect that breaks. What do you mean > >> >> > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > >> >> > >> >> (from samples/bpf) report any exceptions? > >> >> > >> >> > >> >> > >> >> -Toke > >> >> > >> >> > >> >> > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System > >> >> > >> > B is acting as a forwarder between A and C. So I can see the number of > >> >> > >> > packets received at system C. To be specific, only 1024 packets are > >> >> > >> > received. If I remove the xsks_map part from the code and don't run > >> >> > >> > DPDK in userspace. This problem does not occur. Also if I forward all > >> >> > >> > the packets using AF_XDP, there is no such issue. > >> >> > >> > >> >> > >> I thought you said you were seeing the problem when only redirecting to > >> >> > >> a devmap? So why does the xsk_map code impact this? I think you may have > >> >> > >> to share some code... > >> >> > > > >> >> > > Isn't the case here that either xsk_map or dev_map consumes the frame and > >> >> > > therefore the latter doesn't see it? so cloning might be needed here? > >> >> > > >> >> > Yeah, certainly you can't redirect *the same packet* to both xsk_map and > >> >> > devmap - but that wasn't what I understood was the use case here? > >> >> > >> >> Maybe the best would be if Maharishi shared the code as you requested :) > >> >> > >> >> > > >> >> > -Toke > >> >> > > >> > CODE: > >> > BPF MAPS: > >> > > >> > > >> > struct bpf_map_def SEC("maps") xsks_map = { > >> > .type = BPF_MAP_TYPE_XSKMAP, > >> > .key_size = sizeof(int), > >> > .value_size = sizeof(int), > >> > .max_entries = 64, /* Assume netdev has no more than 64 queues */ > >> > }; > >> > > >> > struct bpf_map_def SEC("maps") tx_port = { > >> > .type = BPF_MAP_TYPE_DEVMAP, > >> > .key_size = sizeof(int), > >> > .value_size = sizeof(int), > >> > .max_entries = 1024, > >> > }; > >> > > >> > struct Ingress_qos_lts_value{ > >> > struct bpf_spin_lock lock; > >> > u64 timestamp; > >> > }; > >> > struct bpf_map_def SEC("maps") Ingress_qos_lts = { > >> > .type = BPF_MAP_TYPE_ARRAY, > >> > .key_size = sizeof(u32), > >> > .value_size = sizeof(struct Ingress_qos_lts_value), > >> > .max_entries = 1025, > >> > }; > >> > BPF_ANNOTATE_KV_PAIR(Ingress_qos_lts,u32,struct Ingress_qos_lts_value); > >> > > >> > > >> > SEC("prog") > >> > int ebpf_filter(struct xdp_md *ctx){ > >> > struct xdp_output xout; > >> > xout.output_port = 1; > >> > void* ebpf_packetStart = ((void*)(long)ctx->data); > >> > void* ebpf_packetEnd = ((void*)(long)ctx->data_end); > >> > u64 rate = 100;//100 Kbps > >> > rate *= 1000*1000*100;//10 Gbps > >> > u32 key = 1;//some key > >> > u64 packet_length=(ebpf_packetEnd-ebpf_packetStart-42)*8; > >> > packet_length *= 1000000000; //packet length * 10^9, to convert > >> > rate from second to nanosecond > >> > struct Ingress_qos_lts_value* val; > >> > val = bpf_map_lookup_elem(&Ingress_qos_lts, &key); > >> > u64 now = bpf_ktime_get_ns(); > >> > u64 lts; > >> > if (val) { > >> > bpf_spin_lock(&val->lock); > >> > lts = *(&val->timestamp)+(packet_length/rate); > >> > if(now>lts){ > >> > lts = now; > >> > } > >> > *(&val->timestamp) = lts; > >> > bpf_spin_unlock(&val->lock); > >> > // printk("Time : %x %x\n",lts,now); > >> > if(lts>now){ > >> > return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, 0); > >> > } > >> > } > >> > return bpf_redirect_map(&tx_port,xout.output_port,0); > >> > } > >> > > >> > So, Basically this code redirects the packet to some other interface > >> > or sends the packet to userspace based on the incoming packet rate. > >> > >> Well, if you say it goes away when you remove the xsk code, the obvious > >> explanation would be that the packets are being redirected to userspace > >> instead? What does xdp_monitor say? > >> > >> -Toke > >> > > No packets are not going to userspace. NIC stops processing any more > > packets after 1024 redirected packets. I'll post the results of > > xdp_monitor asap. > > > > Also, one piece of information that might be helpful. In DPDK's > > default code for creating xsk_socket, the value of bind_flags was 0. > > When I changed it to XDP_COPY(1 << 1), everything started working > > correctly. So, is it something like, the socket was getting created in > > zero-copy mode and as far as I know, kernel version 5.3 does not > > support zero-copy mode. Due to this xdp_redirect using DEVMAP was not > > working as expected. > > Hmm, in zero-copy mode packets are DMA'ed directly into the > userspace-provided buffer (hence zero copies). Pretty sure this is > incompatible with forwarding them to the stack, whether or not the > kernel supports zero-copy in the first place. If you redirect to another netdev or XDP_PASS a packet to the kernel, it will be copied and the copy is sent onwards to the system. As Toke says, whatever you had in that packet will be visible to the process you created/used the zero-copy AF_XDP socket in. But any further modification to the packet will not be visible in the umem area, since the packet was copied to another kernel internal buffer. /Magnus > Cc Magnus who will know for sure. > > -Toke > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: XDP_REDIRECT with xsks_map and dev_map 2020-06-04 19:52 ` maharishi bhargava 2020-06-04 22:56 ` Toke Høiland-Jørgensen @ 2020-06-05 11:31 ` Magnus Karlsson 1 sibling, 0 replies; 15+ messages in thread From: Magnus Karlsson @ 2020-06-05 11:31 UTC (permalink / raw) To: maharishi bhargava Cc: Toke Høiland-Jørgensen, Maciej Fijalkowski, Xdp On Thu, Jun 4, 2020 at 10:15 PM maharishi bhargava <bhargavamaharishi@gmail.com> wrote: > > On Wed, Jun 3, 2020 at 8:39 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > > > maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > > > > On Wed, Jun 3, 2020 at 4:41 PM Maciej Fijalkowski > > > <maciej.fijalkowski@intel.com> wrote: > > >> > > >> On Wed, Jun 03, 2020 at 01:07:05PM +0200, Toke Høiland-Jørgensen wrote: > > >> > Maciej Fijalkowski <maciej.fijalkowski@intel.com> writes: > > >> > > > >> > > On Wed, Jun 03, 2020 at 12:49:25PM +0200, Toke Høiland-Jørgensen wrote: > > >> > >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > >> > >> > > >> > >> > On Tue, Jun 2, 2020 at 9:31 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote: > > >> > >> >> > > >> > >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > >> > >> >> > > >> > >> >> > On Tue 2 Jun, 2020, 14:31 Toke Høiland-Jørgensen, <toke@redhat.com> wrote: > > >> > >> >> >> > > >> > >> >> >> maharishi bhargava <bhargavamaharishi@gmail.com> writes: > > >> > >> >> >> > > >> > >> >> >> > Hi, in my XDP program, I want to redirect some packets using AF_XDP > > >> > >> >> >> > and redirect other packets directly from driver space. > > >> > >> >> >> > Redirection through AF_XDP works fine, but redirection through dev map > > >> > >> >> >> > stops after some packets are processed. > > >> > >> >> >> > > >> > >> >> >> Do you mean it stops even if you are *only* redirecting to a devmap, or > > >> > >> >> >> if you are first redirecting a few packets to AF_XDP, then to devmap? > > >> > >> >> >> > > >> > >> >> >> Also, which driver(s) are the physical NICs you're redirecting to/from > > >> > >> >> >> using, and which kernel version are you on? > > >> > >> >> >> > > >> > >> >> >> -Toke > > >> > >> >> > > > >> > >> >> > > > >> > >> >> > > > >> > >> >> > Currently, I'm trying to redirect packets only using devmap. But also > > >> > >> >> > have code for redirection using AF_XDP(only when a given condition is > > >> > >> >> > satisfied). A DPDK program is running in userspace which will receive > > >> > >> >> > packets from AF_XDP. > > >> > >> >> > > >> > >> >> Right, so it's just devmap redirect that breaks. What do you mean > > >> > >> >> 'redirection stops', exactly? How are you seeing this? Does xdp_monitor > > >> > >> >> (from samples/bpf) report any exceptions? > > >> > >> >> > > >> > >> >> -Toke > > >> > >> >> > > >> > >> > So, In my setup, there are three systems, Let's Assume A, B, C. System > > >> > >> > B is acting as a forwarder between A and C. So I can see the number of > > >> > >> > packets received at system C. To be specific, only 1024 packets are > > >> > >> > received. If I remove the xsks_map part from the code and don't run > > >> > >> > DPDK in userspace. This problem does not occur. Also if I forward all > > >> > >> > the packets using AF_XDP, there is no such issue. > > >> > >> > > >> > >> I thought you said you were seeing the problem when only redirecting to > > >> > >> a devmap? So why does the xsk_map code impact this? I think you may have > > >> > >> to share some code... > > >> > > > > >> > > Isn't the case here that either xsk_map or dev_map consumes the frame and > > >> > > therefore the latter doesn't see it? so cloning might be needed here? > > >> > > > >> > Yeah, certainly you can't redirect *the same packet* to both xsk_map and > > >> > devmap - but that wasn't what I understood was the use case here? > > >> > > >> Maybe the best would be if Maharishi shared the code as you requested :) > > >> > > >> > > > >> > -Toke > > >> > > > > CODE: > > > BPF MAPS: > > > > > > > > > struct bpf_map_def SEC("maps") xsks_map = { > > > .type = BPF_MAP_TYPE_XSKMAP, > > > .key_size = sizeof(int), > > > .value_size = sizeof(int), > > > .max_entries = 64, /* Assume netdev has no more than 64 queues */ > > > }; > > > > > > struct bpf_map_def SEC("maps") tx_port = { > > > .type = BPF_MAP_TYPE_DEVMAP, > > > .key_size = sizeof(int), > > > .value_size = sizeof(int), > > > .max_entries = 1024, > > > }; > > > > > > struct Ingress_qos_lts_value{ > > > struct bpf_spin_lock lock; > > > u64 timestamp; > > > }; > > > struct bpf_map_def SEC("maps") Ingress_qos_lts = { > > > .type = BPF_MAP_TYPE_ARRAY, > > > .key_size = sizeof(u32), > > > .value_size = sizeof(struct Ingress_qos_lts_value), > > > .max_entries = 1025, > > > }; > > > BPF_ANNOTATE_KV_PAIR(Ingress_qos_lts,u32,struct Ingress_qos_lts_value); > > > > > > > > > SEC("prog") > > > int ebpf_filter(struct xdp_md *ctx){ > > > struct xdp_output xout; > > > xout.output_port = 1; > > > void* ebpf_packetStart = ((void*)(long)ctx->data); > > > void* ebpf_packetEnd = ((void*)(long)ctx->data_end); > > > u64 rate = 100;//100 Kbps > > > rate *= 1000*1000*100;//10 Gbps > > > u32 key = 1;//some key > > > u64 packet_length=(ebpf_packetEnd-ebpf_packetStart-42)*8; > > > packet_length *= 1000000000; //packet length * 10^9, to convert > > > rate from second to nanosecond > > > struct Ingress_qos_lts_value* val; > > > val = bpf_map_lookup_elem(&Ingress_qos_lts, &key); > > > u64 now = bpf_ktime_get_ns(); > > > u64 lts; > > > if (val) { > > > bpf_spin_lock(&val->lock); > > > lts = *(&val->timestamp)+(packet_length/rate); > > > if(now>lts){ > > > lts = now; > > > } > > > *(&val->timestamp) = lts; > > > bpf_spin_unlock(&val->lock); > > > // printk("Time : %x %x\n",lts,now); > > > if(lts>now){ > > > return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, 0); > > > } > > > } > > > return bpf_redirect_map(&tx_port,xout.output_port,0); > > > } > > > > > > So, Basically this code redirects the packet to some other interface > > > or sends the packet to userspace based on the incoming packet rate. > > > > Well, if you say it goes away when you remove the xsk code, the obvious > > explanation would be that the packets are being redirected to userspace > > instead? What does xdp_monitor say? > > > > -Toke > > > No packets are not going to userspace. NIC stops processing any more > packets after 1024 redirected packets. I'll post the results of > xdp_monitor asap. > > Also, one piece of information that might be helpful. In DPDK's > default code for creating xsk_socket, the value of bind_flags was 0. > When I changed it to XDP_COPY(1 << 1), everything started working > correctly. So, is it something like, the socket was getting created in > zero-copy mode and as far as I know, kernel version 5.3 does not > support zero-copy mode. Due to this xdp_redirect using DEVMAP was not > working as expected. Yes, for DPDK to work with AF_XDP in zero-copy mode, you need at least Linux 5.4 and DPDK 19.11 or later. /Magnus > - Maharishi ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-06-05 11:36 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-06-01 7:50 XDP_REDIRECT with xsks_map and dev_map maharishi bhargava 2020-06-02 9:01 ` Toke Høiland-Jørgensen 2020-06-02 15:15 ` maharishi bhargava 2020-06-02 16:01 ` Toke Høiland-Jørgensen 2020-06-02 18:23 ` maharishi bhargava 2020-06-03 10:49 ` Toke Høiland-Jørgensen 2020-06-03 10:48 ` Maciej Fijalkowski 2020-06-03 11:07 ` Toke Høiland-Jørgensen 2020-06-03 11:07 ` Maciej Fijalkowski 2020-06-03 13:43 ` maharishi bhargava 2020-06-03 15:09 ` Toke Høiland-Jørgensen 2020-06-04 19:52 ` maharishi bhargava 2020-06-04 22:56 ` Toke Høiland-Jørgensen 2020-06-05 11:35 ` Magnus Karlsson 2020-06-05 11:31 ` Magnus Karlsson
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.