: Allow head adjustment in XDP prog
Subsystems (14)
v2 cover : Allow head adjustment in XDP prog
This series adds a helper to allow head adjusting in XDP prog. mlx4 driver has been modified to support this feature. An example is written to encapsulate a packet with an IPv4/v6 header and then XDP_TX it out.
v2:
1. Make a variable name change in bpf_xdp_adjust_head() in patch 1
2. Ensure no less than ETH_HLEN data in bpf_xdp_adjust_head() in patch 1
3. Some clarifications in commit log messages of patch 2 and 3
Thanks,
--Martin
PATCH v2 1/4 bpf: xdp: Allow head adjustment in XDP prog
This patch allows XDP prog to extend/remove the packet data at the head (like adding or removing header). It is done by adding a new XDP helper bpf_xdp_adjust_head().
It also renames bpf_helper_changes_skb_data() to bpf_helper_changes_pkt_data() to better reflect that XDP prog does not work on skb.
--- arch/powerpc/net/bpf_jit_comp64.c | 4 ++-- arch/s390/net/bpf_jit_comp.c | 2 +- arch/x86/net/bpf_jit_comp.c | 2 +- include/linux/filter.h | 2 +- include/uapi/linux/bpf.h | 11 ++++++++++- kernel/bpf/core.c | 2 +- kernel/bpf/verifier.c | 2 +- net/core/filter.c | 34 ++++++++++++++++++++++++++++++++-- 8 files changed, 49 insertions(+), 10 deletions(-)
arch/powerpc/net/bpf_jit_comp64.c +2 -2
@@ -766,7 +766,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, func = (u8 *) __bpf_call_base + imm;/* Save skb pointer if we need to re-cache skb data */ -if (bpf_helper_changes_skb_data (func)) +if (bpf_helper_changes_pkt_data (func))PPC_BPF_STL (3 ,1 ,bpf_jit_stack_local (ctx));bpf_jit_emit_func_call (image, ctx, (u64 )func);
@@ -775,7 +775,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,PPC_MR (b2p[BPF_REG_0 ],3 );/* refresh skb cache */ -if (bpf_helper_changes_skb_data (func)) { +if (bpf_helper_changes_pkt_data (func)) {/* reload skb pointer to r3 */ PPC_BPF_LL (3 ,1 ,bpf_jit_stack_local (ctx));bpf_jit_emit_skb_loads (image, ctx);
arch/s390/net/bpf_jit_comp.c +1 -1
@@ -981,7 +981,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int iEMIT2 (0x0d00 ,REG_14 ,REG_W1 );/* lgr %b0,%r2: load return value into %b0 */ EMIT4 (0xb9040000 ,BPF_REG_0 ,REG_2 ); -if (bpf_helper_changes_skb_data ((void *)func)) { +if (bpf_helper_changes_pkt_data ((void *)func)) { jit->seen |=SEEN_SKB_CHANGE ;/* lg %b1,ST_OFF_SKBP(%r15) */ EMIT6_DISP_LH(0xe3000000, 0x0004, BPF_REG_1, REG_0,
arch/x86/net/bpf_jit_comp.c +1 -1
@@ -853,7 +853,7 @@ xadd: if (is_imm8(insn->off)) func = (u8 *) __bpf_call_base + imm32; jmp_offset = func - (image + addrs[i]);if (seen_ld_abs) { - reload_skb_data =bpf_helper_changes_skb_data (func); + reload_skb_data =bpf_helper_changes_pkt_data (func);if (reload_skb_data) {EMIT1 (0x57 );/* push %rdi */ jmp_offset +=22 ;/* pop, mov, sub, mov */
include/linux/filter.h +1 -1
@@ -590,7 +590,7 @@ void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);u64 __bpf_call_base (u64 r1,u64 r2,u64 r3,u64 r4,u64 r5);struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog); -bool bpf_helper_changes_skb_data (void *func); +bool bpf_helper_changes_pkt_data (void *func);struct bpf_prog *bpf_patch_insn_single (struct bpf_prog *prog,u32 off,const struct bpf_insn *patch,u32 len);
include/uapi/linux/bpf.h +10 -1
@@ -424,6 +424,12 @@ union bpf_attr {* @len: length of header to be pushed in front * @flags: Flags (unused for now) * Return: 0 on success or negative error +* +* int bpf_xdp_adjust_head(xdp_md, delta) +* Adjust the xdp_md.data by delta +* @xdp_md: pointer to xdp_md +* @delta: An positive/negative integer to be added to xdp_md.data +* Return: 0 on success or negative on error */ #define __BPF_FUNC_MAPPER (FN ) \ FN(unspec), \
@@ -469,7 +475,8 @@ union bpf_attr {FN (csum_update), \FN (set_hash_invalid), \FN (get_numa_node_id), \ -FN (skb_change_head), +FN (skb_change_head), \ +FN (xdp_adjust_head),/* integer value in 'imm' field of BPF_CALL instruction selects which helper * function eBPF program intends to call
@@ -576,6 +583,8 @@ struct bpf_sock {__u32 protocol; }; +#define XDP_PACKET_HEADROOM 256 +/* User return codes for XDP prog type. * A valid XDP program must return one of these defined values. All other * return codes are reserved for future use. Unknown return codes will result
kernel/bpf/core.c +1 -1
@@ -1078,7 +1078,7 @@ struct bpf_prog * __weak bpf_int_jit_compile(struct bpf_prog *prog)return prog; } -bool __weak bpf_helper_changes_skb_data (void *func) +bool __weak bpf_helper_changes_pkt_data (void *func) {return false; }
kernel/bpf/verifier.c +1 -1
@@ -1216,7 +1216,7 @@ static int check_call(struct bpf_verifier_env *env, int func_id)return -EINVAL ; } - changes_data =bpf_helper_changes_skb_data (fn->func); + changes_data =bpf_helper_changes_pkt_data (fn->func);memset (&meta,0 ,sizeof (meta)); meta.pkt_access = fn->pkt_access;
net/core/filter.c +32 -2
@@ -2234,7 +2234,34 @@ static const struct bpf_func_proto bpf_skb_change_head_proto = { .arg3_type = ARG_ANYTHING, }; -bool bpf_helper_changes_skb_data (void *func) +BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset) +{ +/* Both mlx4 and mlx5 driver align each packet to PAGE_SIZE when +* XDP prog is set. +* If the above is not true for the other drivers to support +* bpf_xdp_adjust_head, struct xdp_buff can be extended. +*/ +unsigned long addr = (unsigned long )xdp->data &PAGE_MASK ; +void *data_hard_start = (void *)addr; +void *data = xdp->data + offset; + +if (unlikely (data < data_hard_start || data > xdp->data_end -ETH_HLEN )) +return -EINVAL ; + + xdp->data = data; + +return 0 ; +} + +static const struct bpf_func_proto bpf_xdp_adjust_head_proto = { + .func = bpf_xdp_adjust_head, + .gpl_only = false, + .ret_type =RET_INTEGER , + .arg1_type =ARG_PTR_TO_CTX , + .arg2_type =ARG_ANYTHING , +}; + +bool bpf_helper_changes_pkt_data (void *func) { if (func == bpf_skb_vlan_push || func == bpf_skb_vlan_pop ||
@@ -2244,7 +2271,8 @@ bool bpf_helper_changes_skb_data(void *func) func == bpf_skb_change_tail || func == bpf_skb_pull_data || func == bpf_l3_csum_replace || - func == bpf_l4_csum_replace) + func == bpf_l4_csum_replace || + func == bpf_xdp_adjust_head) return true;return false;
@@ -2670,6 +2698,8 @@ xdp_func_proto(enum bpf_func_id func_id)return &bpf_xdp_event_output_proto;case BPF_FUNC_get_smp_processor_id:return &bpf_get_smp_processor_id_proto; +case BPF_FUNC_xdp_adjust_head: +return &bpf_xdp_adjust_head_proto;default :return sk_filter_func_proto (func_id); }
Signature · 1 line
2.5.1
PATCH v2 3/4 mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
In reply to Martin KaFai LauReserve XDP_PACKET_HEADROOM and honor bpf_xdp_adjust_head() when XDP prog is active. This patch only affects the code path when XDP is active.
--- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +15 -2
@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {
@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };
@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; + err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,
@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );
drivers/net/ethernet/mellanox/mlx4/en_rx.c +17 -6
@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {
@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom; + rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;
@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }
@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);
@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data; xdp.data_end = xdp.data + length; act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +switch (act) {case XDP_PASS :break ;
@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;
@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ; buf_size += priv->frag_info[i].frag_size; i++; }
drivers/net/ethernet/mellanox/mlx4/en_tx.c +5 -4
@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };
@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset; tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;
@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2 -1
@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB
Signature · 1 line
2.5.1
PATCH v2 4/4 bpf: xdp: Add XDP example for head adjustment
In reply to Martin KaFai LauThe XDP prog checks if the incoming packet matches any VIP:PORT combination in the BPF hashmap. If it is, it will encapsulate the packet with a IPv4/v6 header as instructed by the value of the BPF hashmap and then XDP_TX it out.
The VIP:PORT -> IP-Encap-Info can be specified by the cmd args of the user prog.
--- samples/bpf/Makefile | 4 + samples/bpf/bpf_helpers.h | 2 + samples/bpf/bpf_load.c | 94 ++++++++++++++ samples/bpf/bpf_load.h | 1 + samples/bpf/xdp1_user.c | 93 -------------- samples/bpf/xdp_tx_iptnl_common.h | 37 ++++++ samples/bpf/xdp_tx_iptnl_kern.c | 232 ++++++++++++++++++++++++++++++++++ samples/bpf/xdp_tx_iptnl_user.c | 253 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 623 insertions(+), 93 deletions(-) create mode 100644 samples/bpf/xdp_tx_iptnl_common.h create mode 100644 samples/bpf/xdp_tx_iptnl_kern.c create mode 100644 samples/bpf/xdp_tx_iptnl_user.c
samples/bpf/Makefile +4 -0
@@ -33,6 +33,7 @@ hostprogs-y += trace_event hostprogs-y += sampleip hostprogs-y += tc_l2_redirect hostprogs-y += lwt_len_hist +hostprogs-y += xdp_tx_iptnl test_lru_dist-objs := test_lru_dist.o libbpf.o sock_example-objs := sock_example.o libbpf.o
@@ -67,6 +68,7 @@ trace_event-objs := bpf_load.o libbpf.o trace_event_user.o sampleip-objs := bpf_load.o libbpf.o sampleip_user.o tc_l2_redirect-objs := bpf_load.o libbpf.o tc_l2_redirect_user.o lwt_len_hist-objs := bpf_load.o libbpf.o lwt_len_hist_user.o +xdp_tx_iptnl-objs := bpf_load.o libbpf.o xdp_tx_iptnl_user.o # Tell kbuild to always build the programs always := $(hostprogs-y)
@@ -99,6 +101,7 @@ always += test_current_task_under_cgroup_kern.o always += trace_event_kern.o always += sampleip_kern.o always += lwt_len_hist_kern.o +always += xdp_tx_iptnl_kern.o HOSTCFLAGS += -I$(objtree)/usr/include HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
@@ -129,6 +132,7 @@ HOSTLOADLIBES_trace_event += -lelf HOSTLOADLIBES_sampleip += -lelf HOSTLOADLIBES_tc_l2_redirect += -l elf HOSTLOADLIBES_lwt_len_hist += -l elf +HOSTLOADLIBES_xdp_tx_iptnl += -lelf # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: # make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
samples/bpf/bpf_helpers.h +2 -0
@@ -57,6 +57,8 @@ static int (*bpf_skb_set_tunnel_opt)(void *ctx, void *md, int size) = (void *) BPF_FUNC_skb_set_tunnel_opt;static unsigned long long (*bpf_get_prandom_u32)(void ) = (void *) BPF_FUNC_get_prandom_u32; +static int (*bpf_xdp_adjust_head)(void *ctx,int offset) = + (void *) BPF_FUNC_xdp_adjust_head;/* llvm builtin functions that eBPF C program may use to * emit BPF_LD_ABS and BPF_LD_IND instructions
samples/bpf/bpf_load.c +94 -0
103 lines not on this page · raw message
samples/bpf/bpf_load.h +1 -0
@@ -31,4 +31,5 @@ struct ksym {int load_kallsyms (void );struct ksym *ksym_search (long key); +int set_link_xdp_fd (int ifindex,int fd);#endif
samples/bpf/xdp1_user.c +0 -93
111 lines not on this page · raw message
samples/bpf/xdp_tx_iptnl_common.h new file +37 -0
@@ -0,0 +1,37 @@ +/* Copyright (c) 2016 Facebook +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +*/ +#ifndef _SAMPLES_BPF_XDP_TX_IPTNL_COMMON_H +#define _SAMPLES_BPF_XDP_TX_IPTNL_COMMON_H + +#include <linux/types.h> + +#define MAX_IPTNL_ENTRIES 256U + +struct vip { +union { +__u32 v6[4 ]; +__u32 v4; + } daddr; +__u16 dport; +__u16 family; +__u8 protocol; +}; + +struct iptnl_info { +union { +__u32 v6[4 ]; +__u32 v4; + } saddr; +union { +__u32 v6[4 ]; +__u32 v4; + } daddr; +__u16 family; +__u8 dmac[6 ]; +}; + +#endif
samples/bpf/xdp_tx_iptnl_kern.c new file +232 -0
232 lines not on this page · raw message
samples/bpf/xdp_tx_iptnl_user.c new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.5.1
PATCH v2 2/4 mlx4: xdp: Allow raising MTU up to one page minus eth and vlan hdrs
In reply to Martin KaFai LauWhen XDP is active in mlx4, mlx4 is using one page/pkt. At the same time (i.e. when XDP is active), it is currently limiting MTU to be FRAG_SZ0 - ETH_HLEN - (2 * VLAN_HLEN) which is 1514 in x86. AFAICT, we can at least raise the MTU limit up to PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) which this patch is doing. It will be useful in the next patch which allows XDP program to extend the packet by adding new header(s).
Note: In the earlier XDP patches, there is already existing guard to ensure the page/pkt scheme only applies when XDP is active in mlx4.
--- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 28 +++++++++++----- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 46 ++++++++++++++------------ 2 files changed, 44 insertions(+), 30 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +20 -8
@@ -51,6 +51,8 @@#include "mlx4_en.h" #include "en_port.h" +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +int mlx4_en_setup_tc (struct net_device *dev,u8 up) {struct mlx4_en_priv *priv =netdev_priv (dev);
@@ -2249,6 +2251,19 @@ void mlx4_en_destroy_netdev(struct net_device *dev)free_netdev (dev); } +static bool mlx4_en_check_xdp_mtu (struct net_device *dev,int mtu) +{ +struct mlx4_en_priv *priv =netdev_priv (dev); + +if (mtu >MLX4_EN_MAX_XDP_MTU ) { +en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , + mtu,MLX4_EN_MAX_XDP_MTU ); +return false; + } + +return true; +} +static int mlx4_en_change_mtu (struct net_device *dev,int new_mtu) {struct mlx4_en_priv *priv =netdev_priv (dev);
@@ -2258,11 +2273,10 @@ static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)en_dbg (DRV , priv,"Change MTU called - current:%d new:%d\n" , dev->mtu, new_mtu); -if (priv->tx_ring_num[TX_XDP ] &&MLX4_EN_EFF_MTU (new_mtu) >FRAG_SZ0 ) { -en_err (priv,"MTU size:%d requires frags but XDP running\n" , - new_mtu); -return -EOPNOTSUPP ; - } +if (priv->tx_ring_num[TX_XDP ] && + !mlx4_en_check_xdp_mtu (dev, new_mtu)) +return -ENOTSUPP ; + dev->mtu = new_mtu;if (netif_running (dev)) {
@@ -2710,10 +2724,8 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)return 0 ; } -if (priv->num_frags >1 ) { -en_err (priv,"Cannot set XDP if MTU requires multiple frags\n" ); +if (!mlx4_en_check_xdp_mtu (dev, dev->mtu))return -EOPNOTSUPP ; - } tmp =kzalloc (sizeof (*tmp),GFP_KERNEL );if (!tmp)
drivers/net/ethernet/mellanox/mlx4/en_rx.c +24 -22
61 lines not on this page · raw message
Signature · 1 line
2.5.1
Re: [PATCH v2 net-next 1/4] bpf: xdp: Allow head adjustment in XDP prog
In reply to Martin KaFai LauQuoted 10 lines · Martin KaFai Lau
This patch allows XDP prog to extend/remove the packet data at the head (like adding or removing header). It is done by adding a new XDP helper
bpf_xdp_adjust_head().It also renames
bpf_helper_changes_skb_data()tobpf_helper_changes_pkt_data()to better reflect that XDP prog does not work on skb.Signed-off-by Martin KaFai Lau <[email protected]>
Yeah, looks good like that:
Should there one day be different requirements wrt min length, we could always pass dev pointer via struct xdp_buff and then use dev->hard_header_len, for example, but not needed right now.
Re: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
In reply to Martin KaFai LauQuoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
Hi Martin, Sorry for the late review, i have some comments below
Quoted 29 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3
-1@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };
drivers/net/ethernet/mellanox/mlx4/en_netdev.c int mlx4_en_start_port(struct net_device *dev) · line 1692
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +4
-0@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; +
Why would the physical MTU care for the headroom you preserve for XDP prog? This is the wire MTU, it shouldn't be changed, please keep it as before, any preservation you make in packets buffers are needed only for FWD case or modify case (HW or wire should not care about them).
Quoted 33 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +8
-1err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {
drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, · line 117
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom;
I don't see any need for headroom on frag_info other that frag0 (which where the packet starts).
What is the meaning of a headroom of a frag in a middle of a packet ?
if you agree with me then, you can use XDP_PACKET_HEADROOM as is where needed (i.e frag0 page offset) and remove "priv->frag_info[i].rx_headroom"
...
After going through the code a little bit i see that this code is shared between XDP and common path, and you didn't want to add boolean conditions.
Ok i see what you did here.
Maybe we can pass headroom as a function parameter and split frag0 handling from the rest ?
If it is too much then i am ok with the code as it is,
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +8
-4+ rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data;
drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud · line 913
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +6
-0xdp.data_end = xdp.data + length; act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +
is this needed only for XDP FWD case ?
is this the only way to detect that the user modified the packet headers (comparing pointers, before and after) ?
if the answer is yes, it should be faster to unconditionally reset packet offset and lenght on XDP_FWD :
case XDP_FWD:
length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr;
Quoted 12 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0switch (act) {case XDP_PASS :break;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;
drivers/net/ethernet/mellanox/mlx4/en_rx.c void mlx4_en_calc_rx_buf(struct net_device *dev) · line 1207
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ;
IMHO, redundant. as you see here frag0 and other frags handling are separated, maybe we can do the same in mlx4_en_alloc_frags.
Quoted 17 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0buf_size += priv->frag_info[i].frag_size; i++; }drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };
drivers/net/ethernet/mellanox/mlx4/en_tx.c netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, · line 1135
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset;
Didn't you already take care of lenght by the following code:
if (xdp.data != orig_data) {
length = xdp.data_end - xdp.data;
frags[0].page_offset = xdp.data - pg_addr;
}and here frame->page_offset is not really page offset, it can only be XDP_PACKET_HEADROOM.
Quoted 33 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +3
-2tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2
-2@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB --2.5.1
Re: [PATCH v2 net-next 1/4] bpf: xdp: Allow head adjustment in XDP prog
In reply to Martin KaFai LauQuoted 11 lines · On Sat, 3 Dec 2016 19:17:23 -0800 Martin KaFai Lau <[email protected]> wrote:
This patch allows XDP prog to extend/remove the packet data at the head (like adding or removing header). It is done by adding a new XDP helper
bpf_xdp_adjust_head().It also renames
bpf_helper_changes_skb_data()tobpf_helper_changes_pkt_data()to better reflect that XDP prog does not work on skb.Signed-off-by Martin KaFai Lau <[email protected]>---
[...]
Quoted 17 lines
net/core/filter.c +8
-1@@ -2234,7 +2234,34 @@ static const struct bpf_func_proto bpf_skb_change_head_proto = { .arg3_type = ARG_ANYTHING, }; -bool bpf_helper_changes_skb_data (void *func) +BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset) +{ +/* Both mlx4 and mlx5 driver align each packet to PAGE_SIZE when +* XDP prog is set. +* If the above is not true for the other drivers to support +* bpf_xdp_adjust_head, struct xdp_buff can be extended. +*/ +unsigned long addr = (unsigned long )xdp->data &PAGE_MASK ;
net/core/filter.c static const struct bpf_func_proto bpf_skb_change_head_proto = { · line 2254
Quoted 10 lines
net/core/filter.c +10
-0+void *data_hard_start = (void *)addr; +void *data = xdp->data + offset; + +if (unlikely (data < data_hard_start || data > xdp->data_end -ETH_HLEN )) +return -EINVAL ; + + xdp->data = data; + +return 0 ; +}
Thanks for adjusting this, I like Daniel's suggestion.
For this patch:
As it still looks like 3/4 need some adjustments based on Saeed's comments.
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 4 lines · Martin KaFai Lau
This series adds a helper to allow head adjusting in XDP prog. mlx4 driver has been modified to support this feature. An example is written to encapsulate a packet with an IPv4/v6 header and then
XDP_TXit out.
Can we just add a feature to one of four drivers which support XDP today and AFAICT leave it completely broken on remaining tree?
I'm not seeing any way for the drivers to inform the stack about their capabilities, would that not be a pre-requisite?
Quoted 11 lines · On Mon, 5 Dec 2016 17:53:02 +0000 Jakub Kicinski <[email protected]> wrote:
Quoted 4 lines · Martin KaFai Lau
This series adds a helper to allow head adjusting in XDP prog. mlx4 driver has been modified to support this feature. An example is written to encapsulate a packet with an IPv4/v6 header and then
XDP_TXit out.Can we just add a feature to one of four drivers which support XDP today and AFAICT leave it completely broken on remaining tree?
I'm not seeing any way for the drivers to inform the stack about their capabilities, would that not be a pre-requisite?
Thank you for bringing this up Jakub, very good point. I do think it must be a pre-requisite that we have a capabilities negotiation interface for XDP ... before adding new features.
As I've also documented here, and below:
https://prototype-kernel.readthedocs.io/en/latest/networking/XDP/design/design.html#ref-prog-negotiation
Capabilities negotiation
========================
.. Warning:: This interface is missing in the implementation
XDP has hooks and feature dependencies in the device drivers. Planning for extendability, not all device drivers will necessarily support all of the future features of XDP, and new feature adoption in device drivers will occur at different development rates.
Thus, there is a need for the device driver to express what XDP capabilities or features it provides.
When attaching/loading an XDP program into the kernel, a feature or capabilities negotiation should be conducted. This implies that an XDP program needs to express what features it wants to use.
If an XDP program being loaded requests features that the given device driver does not support, the program load should simply be rejected.
.. note:: I'm undecided on whether to have an query interface, because
users could just use the regular load-interface to probe for supported options. The downside of probing is the issues SElinux runs into, of false alarms, when glibc tries to probe for capabilities.
Implementation issue
--------------------
The current implementation is missing this interface. Worse, the two actions :ref:XDP_DROP and :ref:XDP_TX should have been expressed as two different capabilities, because XDP_TX requires more changes to the device driver than a simple drop like XDP_DROP.
One can (easily) imagine that an older driver only wants to implement the XDP_DROP facility. The reason is that XDP_TX would require changing too much driver code, which is a concern for an old, stable and time-proven driver.
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Re: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
In reply to Saeed MahameedQuoted 41 lines · Saeed Mahameed
Quoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
Hi Martin, Sorry for the late review, i have some comments below
Quoted 31 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3
-1@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c int mlx4_en_start_port(struct net_device *dev) · line 1692
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +4
-0/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; +Why would the physical MTU care for the headroom you preserve for XDP prog? This is the wire MTU, it shouldn't be changed, please keep it as before, any preservation you make in packets buffers are needed only for FWD case or modify case (HW or wire should not care about them).
Thanks for your feedback!
FWD:
packet received from a port
=> process by a XDP prog
=> XDP_TX out to the same port.
For example, if the received packet has 1500 payload and the XDP prog encapsulates it in an IPv6 header (+40 bytes). After testing, it cannot be sent out due to the HW/wire MTU is 1500.
Even the wire MTU info was passed to the XDP prog, there is not much a XDP prog could do here other than dropping it.
Hence, this patch gives guarantee to the XDP prog such that it can always send out what it has received + XDP_PACKET_HEADROOM.
Quoted 54 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +8
-1err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, · line 117
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom;I don't see any need for headroom on
frag_infoother that frag0 (which where the packet starts).
What is the meaning of a headroom of a frag in a middle of a packet ?if you agree with me then, you can use
XDP_PACKET_HEADROOMas is where needed (i.e frag0 page offset) and remove "priv->frag_info[i].rx_headroom"...
After going through the code a little bit i see that this code is shared between XDP and common path, and you didn't want to add boolean conditions.
Quoted 5 lines
Ok i see what you did here.
Maybe we can pass headroom as a function parameter and split frag0 handling from the rest ?
If it is too much then i am ok with the code as it is,
Right, this patch does the boolean check (XDP active or not) early on in mlx4_en_calc_rx_buf() (i.e. out of the fast path) and store the result in priv->frag_info[0].rx_headroom.
Just want to ensure I understand your comment correctly.
You prefer not to store the boolean test result in frag_info[0].rx_headroom since it is redundant to !!priv->tx_ring_num[TX_XDP] and rx_headroom is also confusing for frag[1-3].
Instead, do the XDP [in]active test before calling mlx4_en_alloc_frags() and then only adjust frags[0].page_offset by +XDP_PACKET_HEADROOM if is needed. It could be done either by passing an extra argument to mlx4_en_alloc_frags() or completely separate mlx4_en_alloc_frags(). I am fine with this also.
Quoted 37 lines
Quoted 37 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +8
-4+ rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data; xdp.data_end = xdp.data + length;
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +6
-0act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +is this needed only for XDP FWD case ?
No. It is also for PASS.
Quoted 2 lines
is this the only way to detect that the user modified the packet headers (comparing pointers, before and after) ?
Yes
Quoted 52 lines
if the answer is yes, it should be faster to unconditionally reset packet offset and lenght on
XDP_FWD:
caseXDP_FWD:length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr;Quoted 12 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0switch (act) {case XDP_PASS :break;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;drivers/net/ethernet/mellanox/mlx4/en_rx.c void mlx4_en_calc_rx_buf(struct net_device *dev) · line 1207
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ;IMHO, redundant. as you see here frag0 and other frags handling are separated, maybe we can do the same in
mlx4_en_alloc_frags.Quoted 17 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0buf_size += priv->frag_info[i].frag_size; i++; }drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };drivers/net/ethernet/mellanox/mlx4/en_tx.c netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, · line 1135
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset;Didn't you already take care of lenght by the following code:
Quoted 5 lines
if (xdp.data != orig_data) {
length = xdp.data_end - xdp.data;
frags[0].page_offset = xdp.data - pg_addr;
}Before this patch, length always assumes the data starts at the beginning of the page and dma is the start of the page. Hence, adding framg->page_offset back to the length here.
However, if I read the codes correctly, I think the map0_byte_count (before or after this patch) does not matter since it is only used in dma_unmap_page() and PAGE_SIZE is always used in dma_unmap_page() for this code patch. Hence, I think we can just set map0_byte_count to PAGE_SIZE here.
Quoted 2 lines
and here
frame->page_offsetis not really page offset, it can only beXDP_PACKET_HEADROOM.
Note that the XDP prog can call bpf_xdp_adjust_head() to add a header. The XDP prog can extend up to XDP_PACKET_HEADROOM (256) bytes but it can also (and usually) only add 40 bytes IPv6 header and then XDP_TX it out.
Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +3
-2tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2
-2@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB --2.5.1
Re: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
Quoted 53 lines · Martin KaFai Lau
Quoted 41 lines · Saeed Mahameed
Quoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
Hi Martin, Sorry for the late review, i have some comments below
Quoted 31 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3
-1@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c int mlx4_en_start_port(struct net_device *dev) · line 1692
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +4
-0/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; +Why would the physical MTU care for the headroom you preserve for XDP prog? This is the wire MTU, it shouldn't be changed, please keep it as before, any preservation you make in packets buffers are needed only for FWD case or modify case (HW or wire should not care about them).
Quoted 1 line
Thanks for your feedback!
Just doing my job :))
Quoted 10 lines
FWD:
packet received from a port
=> process by a XDP prog
=>XDP_TXout to the same port.For example, if the received packet has 1500 payload and the XDP prog encapsulates it in an IPv6 header (+40 bytes). After testing, it cannot be sent out due to the HW/wire MTU is 1500.
Quoted 6 lines
Even the wire MTU info was passed to the XDP prog, there is not much a XDP prog could do here other than dropping it.
Hence, this patch gives guarantee to the XDP prog such that it can always send out what it has received +
XDP_PACKET_HEADROOM.
Still i am not convinced ! this is against common sense, this means that the XDP prog can send packets larger than the MTU seen on netdev!
anyway if a packet with the size (MTU + XDP_PACKET_HEADROOM) was sent from XDP ring and HW allowed it to exit somehow (with the code you provided :)), most likely it will be dropped
at the other end.
I still think XDP prog should not be allowed to FW packets larger than the MTU seen on the netdev and you shouldn't modify the wire MTU just for this case.
Quoted 68 lines
Quoted 54 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +8
-1err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, · line 117
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom;I don't see any need for headroom on
frag_infoother that frag0 (which where the packet starts).
What is the meaning of a headroom of a frag in a middle of a packet ?if you agree with me then, you can use
XDP_PACKET_HEADROOMas is where needed (i.e frag0 page offset) and remove "priv->frag_info[i].rx_headroom"...
After going through the code a little bit i see that this code is shared between XDP and common path, and you didn't want to add boolean conditions.
Quoted 5 lines
Ok i see what you did here.
Maybe we can pass headroom as a function parameter and split frag0 handling from the rest ?
If it is too much then i am ok with the code as it is,Right, this patch does the boolean check (XDP active or not) early on in
mlx4_en_calc_rx_buf()(i.e. out of the fast path) and store the result in priv->frag_info[0].rx_headroom.Just want to ensure I understand your comment correctly.
You prefer not to store the boolean test result in frag_info[0].rx_headroom since it is redundant to !!priv->tx_ring_num[TX_XDP] andrx_headroomis also confusing for frag[1-3].
Quoted 5 lines
Instead, do the XDP [in]active test before calling
mlx4_en_alloc_frags()and then only adjust frags[0].page_offset by +XDP_PACKET_HEADROOM if is needed. It could be done either by passing an extra argument tomlx4_en_alloc_frags()or completely separatemlx4_en_alloc_frags(). I am fine with this also.
Correct, but if this change will add extra checks to the data path then I am ok with the current code.
Quoted 48 lines
Quoted 38 lines
Quoted 38 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +8
-4+ rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data; xdp.data_end = xdp.data + length;Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +6
-0act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +is this needed only for XDP FWD case ?
Quoted 2 lines
No. It is also for PASS.
I see.
Quoted 61 lines
Quoted 2 lines
is this the only way to detect that the user modified the packet headers (comparing pointers, before and after) ?
Yes
Quoted 52 lines
if the answer is yes, it should be faster to unconditionally reset packet offset and lenght on
XDP_FWD:
caseXDP_FWD:length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr;Quoted 12 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0switch (act) {case XDP_PASS :break;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;drivers/net/ethernet/mellanox/mlx4/en_rx.c void mlx4_en_calc_rx_buf(struct net_device *dev) · line 1207
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ;IMHO, redundant. as you see here frag0 and other frags handling are separated, maybe we can do the same in
mlx4_en_alloc_frags.Quoted 17 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0buf_size += priv->frag_info[i].frag_size; i++; }drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };drivers/net/ethernet/mellanox/mlx4/en_tx.c netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, · line 1135
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset;Didn't you already take care of lenght by the following code:
Quoted 5 lines
if (xdp.data != orig_data) { length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr; }
Quoted 9 lines
Before this patch, length always assumes the data starts at the beginning of the page and dma is the start of the page. Hence, adding
framg->page_offsetback to the length here.However, if I read the codes correctly, I think the
map0_byte_count(before or after this patch) does not matter since it is only used indma_unmap_page()andPAGE_SIZEis always used indma_unmap_page()for this code patch. Hence, I think we can just setmap0_byte_counttoPAGE_SIZEhere.
Right, in mlx4_alloc_pages we always map with PAGE_SIZE << order
dma = dma_map_page(priv->ddev, page, 0, PAGE_SIZE << order,
frag_info->dma_dir);
for XDP order is always 0, so you can safely set it to PAGE_SIZE.
Quoted 6 lines
Quoted 2 lines
and here
frame->page_offsetis not really page offset, it can only beXDP_PACKET_HEADROOM.Note that the XDP prog can call
bpf_xdp_adjust_head()to add a header. The XDP prog can extend up toXDP_PACKET_HEADROOM(256) bytes but it can also (and usually) only add 40 bytes IPv6 header and thenXDP_TXit out.
I see.
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +3
-2tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2
-2@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB --2.5.1
John Fastabend
maintainerRe: [PATCH v2 net-next 1/4] bpf: xdp: Allow head adjustment in XDP prog
In reply to Martin KaFai LauQuoted 11 lines · Martin KaFai Lau
This patch allows XDP prog to extend/remove the packet data at the head (like adding or removing header). It is done by adding a new XDP helper
bpf_xdp_adjust_head().It also renames
bpf_helper_changes_skb_data()tobpf_helper_changes_pkt_data()to better reflect that XDP prog does not work on skb.Signed-off-by Martin KaFai Lau <[email protected]>---
[...]
Quoted 11 lines
net/core/filter.c +9
-1-bool bpf_helper_changes_skb_data (void *func) +BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset) +{ +/* Both mlx4 and mlx5 driver align each packet to PAGE_SIZE when +* XDP prog is set. +* If the above is not true for the other drivers to support +* bpf_xdp_adjust_head, struct xdp_buff can be extended. +*/ +unsigned long addr = (unsigned long )xdp->data &PAGE_MASK ; +void *data_hard_start = (void *)addr;
net/core/filter.c static const struct bpf_func_proto bpf_skb_change_head_proto = { · line 2255
Quoted 10 lines
net/core/filter.c +10
-0+void *data = xdp->data + offset; + +if (unlikely (data < data_hard_start || data > xdp->data_end -ETH_HLEN )) +return -EINVAL ; + + xdp->data = data; + +return 0 ; +} +
Sorry for the delay but I don't like the assumptions being made here with regards to page alignment and free space.
Instead of taking the offset from PAGE_MASK how about adding a pointer to xdp_buff so that we get,
struct xdp_buff {
void *data; void *data_start; void *data_end;
};
This gives the headroom explicitly in the data structure. This way we can handle non-paged aligned usages and also some of the drivers are putting metadata (descriptors) at the front of the page. With this patch we could stomp on that metadata with the above we avoid that problem altogether.
Thanks,
John
John Fastabend
maintainerRe: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
In reply to Saeed MahameedQuoted 10 lines · Saeed Mahameed
Quoted 9 lines · Martin KaFai Lau
Quoted 8 lines · Saeed Mahameed
Quoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
[...]
Quoted 20 lines
Quoted 9 lines
FWD:
packet received from a port
=> process by a XDP prog
=>XDP_TXout to the same port.For example, if the received packet has 1500 payload and the XDP prog encapsulates it in an IPv6 header (+40 bytes). After testing, it cannot be sent out due to the HW/wire MTU is 1500.
Quoted 6 lines
Even the wire MTU info was passed to the XDP prog, there is not much a XDP prog could do here other than dropping it.
Hence, this patch gives guarantee to the XDP prog such that it can always send out what it has received +
XDP_PACKET_HEADROOM.Still i am not convinced ! this is against common sense, this means that the XDP prog can send packets larger than the MTU seen on netdev!
Quoted 8 lines
anyway if a packet with the size (MTU +
XDP_PACKET_HEADROOM) was sent from XDP ring and HW allowed it to exit somehow (with the code you provided :)), most likely it will be dropped
at the other end.I still think XDP prog should not be allowed to FW packets larger than the MTU seen on the netdev and you shouldn't modify the wire MTU just for this case.
I agree here it seems changing the MTU arbitrarily from XDP programs just creates another side effect that can already be handled easily by explicitly setting the MTU. This complicates the code and risks confusing users IMO I would prefer to drop this patch and implement this at the control plane if its really needed. Daniel's iproute xdp tool could set this for example if its useful.
My $.02 at least.
Thanks,
John
Re: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
In reply to Saeed MahameedQuoted 75 lines · Saeed Mahameed
Quoted 53 lines · Martin KaFai Lau
Quoted 41 lines · Saeed Mahameed
Quoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
Hi Martin, Sorry for the late review, i have some comments below
Quoted 31 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3
-1@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c int mlx4_en_start_port(struct net_device *dev) · line 1692
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +4
-0/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; +Why would the physical MTU care for the headroom you preserve for XDP prog? This is the wire MTU, it shouldn't be changed, please keep it as before, any preservation you make in packets buffers are needed only for FWD case or modify case (HW or wire should not care about them).
Quoted 1 line
Thanks for your feedback!
Just doing my job :))
Quoted 10 lines
FWD:
packet received from a port
=> process by a XDP prog
=>XDP_TXout to the same port.For example, if the received packet has 1500 payload and the XDP prog encapsulates it in an IPv6 header (+40 bytes). After testing, it cannot be sent out due to the HW/wire MTU is 1500.
Quoted 6 lines
Even the wire MTU info was passed to the XDP prog, there is not much a XDP prog could do here other than dropping it.
Hence, this patch gives guarantee to the XDP prog such that it can always send out what it has received +
XDP_PACKET_HEADROOM.
Quoted 8 lines
Still i am not convinced ! this is against common sense, this means that the XDP prog can send packets larger than the MTU seen on netdev!
anyway if a packet with the size (MTU +
XDP_PACKET_HEADROOM) was sent from XDP ring and HW allowed it to exit somehow (with the code you provided :)), most likely it will be dropped
at the other end.
The MTU of our receiver side is larger than 1500.
If the otherside could not handle >1500, we could lower the box running XDP prog to 1460.
Just ensure we are on the same page. The rx MTU stays the same (1500) because the rx_desc's byte_count is not raised by XDP_PACKET_HEADROOM.
Quoted 73 lines
I still think XDP prog should not be allowed to FW packets larger than the MTU seen on the netdev and you shouldn't modify the wire MTU just for this case.
Quoted 68 lines
Quoted 54 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +8
-1err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, · line 117
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom;I don't see any need for headroom on
frag_infoother that frag0 (which where the packet starts).
What is the meaning of a headroom of a frag in a middle of a packet ?if you agree with me then, you can use
XDP_PACKET_HEADROOMas is where needed (i.e frag0 page offset) and remove "priv->frag_info[i].rx_headroom"...
After going through the code a little bit i see that this code is shared between XDP and common path, and you didn't want to add boolean conditions.
Quoted 5 lines
Ok i see what you did here.
Maybe we can pass headroom as a function parameter and split frag0 handling from the rest ?
If it is too much then i am ok with the code as it is,Right, this patch does the boolean check (XDP active or not) early on in
mlx4_en_calc_rx_buf()(i.e. out of the fast path) and store the result in priv->frag_info[0].rx_headroom.Just want to ensure I understand your comment correctly.
You prefer not to store the boolean test result in frag_info[0].rx_headroom since it is redundant to !!priv->tx_ring_num[TX_XDP] andrx_headroomis also confusing for frag[1-3].
Quoted 8 lines
Quoted 5 lines
Instead, do the XDP [in]active test before calling
mlx4_en_alloc_frags()and then only adjust frags[0].page_offset by +XDP_PACKET_HEADROOM if is needed. It could be done either by passing an extra argument tomlx4_en_alloc_frags()or completely separatemlx4_en_alloc_frags(). I am fine with this also.Correct, but if this change will add extra checks to the data path then I am ok with the current code.
Right, the check has to be done somewhere in the data path. Lets stay with the current approach then.
Quoted 173 lines
Quoted 49 lines
Quoted 39 lines
Quoted 39 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +8
-4+ rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data; xdp.data_end = xdp.data + length;Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +6
-0act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +is this needed only for XDP FWD case ?
Quoted 2 lines
No. It is also for PASS.
I see.
Quoted 61 lines
Quoted 2 lines
is this the only way to detect that the user modified the packet headers (comparing pointers, before and after) ?
Yes
Quoted 52 lines
if the answer is yes, it should be faster to unconditionally reset packet offset and lenght on
XDP_FWD:
caseXDP_FWD:length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr;Quoted 12 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0switch (act) {case XDP_PASS :break;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;drivers/net/ethernet/mellanox/mlx4/en_rx.c void mlx4_en_calc_rx_buf(struct net_device *dev) · line 1207
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ;IMHO, redundant. as you see here frag0 and other frags handling are separated, maybe we can do the same in
mlx4_en_alloc_frags.Quoted 17 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0buf_size += priv->frag_info[i].frag_size; i++; }drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };drivers/net/ethernet/mellanox/mlx4/en_tx.c netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, · line 1135
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset;Didn't you already take care of lenght by the following code:
Quoted 5 lines
if (xdp.data != orig_data) { length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr; }Quoted 9 lines
Before this patch, length always assumes the data starts at the beginning of the page and dma is the start of the page. Hence, adding
framg->page_offsetback to the length here.However, if I read the codes correctly, I think the
map0_byte_count(before or after this patch) does not matter since it is only used indma_unmap_page()andPAGE_SIZEis always used indma_unmap_page()for this code patch. Hence, I think we can just setmap0_byte_counttoPAGE_SIZEhere.Right, in
mlx4_alloc_pageswe always map withPAGE_SIZE<< order
dma = dma_map_page(priv->ddev, page, 0,PAGE_SIZE<< order,
frag_info->dma_dir);
for XDP order is always 0, so you can safely set it toPAGE_SIZE.Quoted 6 lines
Quoted 2 lines
and here
frame->page_offsetis not really page offset, it can only beXDP_PACKET_HEADROOM.Note that the XDP prog can call
bpf_xdp_adjust_head()to add a header. The XDP prog can extend up toXDP_PACKET_HEADROOM(256) bytes but it can also (and usually) only add 40 bytes IPv6 header and thenXDP_TXit out.I see.
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +3
-2tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2
-2@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB --2.5.1
Re: [PATCH v2 net-next 1/4] bpf: xdp: Allow head adjustment in XDP prog
In reply to John FastabendQuoted 48 lines · John Fastabend
Quoted 11 lines · Martin KaFai Lau
This patch allows XDP prog to extend/remove the packet data at the head (like adding or removing header). It is done by adding a new XDP helper
bpf_xdp_adjust_head().It also renames
bpf_helper_changes_skb_data()tobpf_helper_changes_pkt_data()to better reflect that XDP prog does not work on skb.Signed-off-by Martin KaFai Lau <[email protected]>---
[...]
Quoted 11 lines
net/core/filter.c +9
-1-bool bpf_helper_changes_skb_data (void *func) +BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset) +{ +/* Both mlx4 and mlx5 driver align each packet to PAGE_SIZE when +* XDP prog is set. +* If the above is not true for the other drivers to support +* bpf_xdp_adjust_head, struct xdp_buff can be extended. +*/ +unsigned long addr = (unsigned long )xdp->data &PAGE_MASK ; +void *data_hard_start = (void *)addr;net/core/filter.c static const struct bpf_func_proto bpf_skb_change_head_proto = { · line 2255
Quoted 10 lines
net/core/filter.c +10
-0+void *data = xdp->data + offset; + +if (unlikely (data < data_hard_start || data > xdp->data_end -ETH_HLEN )) +return -EINVAL ; + + xdp->data = data; + +return 0 ; +} +Sorry for the delay but I don't like the assumptions being made here with regards to page alignment and free space.
Instead of taking the offset from
PAGE_MASKhow about adding a pointer toxdp_buffso that we get,struct
xdp_buff{void *data; void *data_end; void *data_start;
Quoted 7 lines
};
This gives the headroom explicitly in the data structure. This way we can handle non-paged aligned usages and also some of the drivers are putting metadata (descriptors) at the front of the page. With this patch we could stomp on that metadata with the above we avoid that problem altogether.
Extending the xdp_buff like this was my first local attempt. And then I realized the assumption that mlx4/5 is making. Since there is no immediate need for this patch series and the xdp_buff can always be extended later if needed without breaking the xdp prog, I dropped the xdp_buff addition for now in this patch.
Sure, it will be done at the next spin.
Re: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
In reply to Martin KaFai LauQuoted 80 lines · Martin KaFai Lau
Quoted 79 lines · Saeed Mahameed
Quoted 53 lines · Martin KaFai Lau
Quoted 41 lines · Saeed Mahameed
Quoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
Hi Martin, Sorry for the late review, i have some comments below
Quoted 31 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3
-1@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c int mlx4_en_start_port(struct net_device *dev) · line 1692
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +4
-0/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; +Why would the physical MTU care for the headroom you preserve for XDP prog? This is the wire MTU, it shouldn't be changed, please keep it as before, any preservation you make in packets buffers are needed only for FWD case or modify case (HW or wire should not care about them).
Quoted 1 line
Thanks for your feedback!
Just doing my job :))
Quoted 10 lines
FWD:
packet received from a port
=> process by a XDP prog
=>XDP_TXout to the same port.For example, if the received packet has 1500 payload and the XDP prog encapsulates it in an IPv6 header (+40 bytes). After testing, it cannot be sent out due to the HW/wire MTU is 1500.
Quoted 6 lines
Even the wire MTU info was passed to the XDP prog, there is not much a XDP prog could do here other than dropping it.
Hence, this patch gives guarantee to the XDP prog such that it can always send out what it has received +
XDP_PACKET_HEADROOM.Still i am not convinced ! this is against common sense, this means that the XDP prog can send packets larger than the MTU seen on netdev!
Quoted 9 lines
Quoted 4 lines
anyway if a packet with the size (MTU +
XDP_PACKET_HEADROOM) was sent from XDP ring and HW allowed it to exit somehow (with the code you provided :)), most likely it will be dropped
at the other end.The MTU of our receiver side is larger than 1500.
If the otherside could not handle >1500, we could lower the box running XDP prog to 1460.
This is exactly the user confusion we are trying to avoid.
Genuinely lowering the other side or dropping packets in XDP program that are not eligible for edit&FWD (packets > MTU - required headroom ) will create the same effect. why don't you use this approach ?
dropping "large" packets in XDP seems the best solution.
Quoted 3 lines
Just ensure we are on the same page. The rx MTU stays the same (1500) because the rx_desc's
byte_countis not raised byXDP_PACKET_HEADROOM.
Yea it is clear,
One more reason not to do this: now packets that were dropped due to "large MTU" HW drop cause, will now pass the HW check but will fail on RX error (RX buffers are smaller than the wire MTU sized packet) this counts as an error in both mlx5/4 which is not acceptable.
Quoted 257 lines
Quoted 73 lines
I still think XDP prog should not be allowed to FW packets larger than the MTU seen on the netdev and you shouldn't modify the wire MTU just for this case.
Quoted 68 lines
Quoted 54 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +8
-1err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, · line 117
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom;I don't see any need for headroom on
frag_infoother that frag0 (which where the packet starts).
What is the meaning of a headroom of a frag in a middle of a packet ?if you agree with me then, you can use
XDP_PACKET_HEADROOMas is where needed (i.e frag0 page offset) and remove "priv->frag_info[i].rx_headroom"...
After going through the code a little bit i see that this code is shared between XDP and common path, and you didn't want to add boolean conditions.
Quoted 5 lines
Ok i see what you did here.
Maybe we can pass headroom as a function parameter and split frag0 handling from the rest ?
If it is too much then i am ok with the code as it is,Right, this patch does the boolean check (XDP active or not) early on in
mlx4_en_calc_rx_buf()(i.e. out of the fast path) and store the result in priv->frag_info[0].rx_headroom.Just want to ensure I understand your comment correctly.
You prefer not to store the boolean test result in frag_info[0].rx_headroom since it is redundant to !!priv->tx_ring_num[TX_XDP] andrx_headroomis also confusing for frag[1-3].Quoted 8 lines
Quoted 5 lines
Instead, do the XDP [in]active test before calling
mlx4_en_alloc_frags()and then only adjust frags[0].page_offset by +XDP_PACKET_HEADROOM if is needed. It could be done either by passing an extra argument tomlx4_en_alloc_frags()or completely separatemlx4_en_alloc_frags(). I am fine with this also.Correct, but if this change will add extra checks to the data path then I am ok with the current code.
Right, the check has to be done somewhere in the data path. Lets stay with the current approach then.
Quoted 173 lines
Quoted 49 lines
Quoted 39 lines
Quoted 39 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +8
-4+ rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data; xdp.data_end = xdp.data + length;Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +6
-0act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +is this needed only for XDP FWD case ?
Quoted 2 lines
No. It is also for PASS.
I see.
Quoted 61 lines
Quoted 2 lines
is this the only way to detect that the user modified the packet headers (comparing pointers, before and after) ?
Yes
Quoted 52 lines
if the answer is yes, it should be faster to unconditionally reset packet offset and lenght on
XDP_FWD:
caseXDP_FWD:length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr;Quoted 12 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0switch (act) {case XDP_PASS :break;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;drivers/net/ethernet/mellanox/mlx4/en_rx.c void mlx4_en_calc_rx_buf(struct net_device *dev) · line 1207
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ;IMHO, redundant. as you see here frag0 and other frags handling are separated, maybe we can do the same in
mlx4_en_alloc_frags.Quoted 17 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0buf_size += priv->frag_info[i].frag_size; i++; }drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };drivers/net/ethernet/mellanox/mlx4/en_tx.c netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, · line 1135
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset;Didn't you already take care of lenght by the following code:
Quoted 5 lines
if (xdp.data != orig_data) { length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr; }Quoted 9 lines
Before this patch, length always assumes the data starts at the beginning of the page and dma is the start of the page. Hence, adding
framg->page_offsetback to the length here.However, if I read the codes correctly, I think the
map0_byte_count(before or after this patch) does not matter since it is only used indma_unmap_page()andPAGE_SIZEis always used indma_unmap_page()for this code patch. Hence, I think we can just setmap0_byte_counttoPAGE_SIZEhere.Right, in
mlx4_alloc_pageswe always map withPAGE_SIZE<< order
dma = dma_map_page(priv->ddev, page, 0,PAGE_SIZE<< order,
frag_info->dma_dir);
for XDP order is always 0, so you can safely set it toPAGE_SIZE.Quoted 6 lines
Quoted 2 lines
and here
frame->page_offsetis not really page offset, it can only beXDP_PACKET_HEADROOM.Note that the XDP prog can call
bpf_xdp_adjust_head()to add a header. The XDP prog can extend up toXDP_PACKET_HEADROOM(256) bytes but it can also (and usually) only add 40 bytes IPv6 header and thenXDP_TXit out.I see.
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +3
-2tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2
-2@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB --2.5.1
Re: [PATCH v2 net-next 3/4] mlx4: xdp: Reserve headroom for receiving packet when XDP prog is active
Quoted 91 lines · Saeed Mahameed
Quoted 80 lines · Martin KaFai Lau
Quoted 79 lines · Saeed Mahameed
Quoted 53 lines · Martin KaFai Lau
Quoted 41 lines · Saeed Mahameed
Quoted 6 lines · Martin KaFai Lau
Reserve
XDP_PACKET_HEADROOMand honorbpf_xdp_adjust_head()when XDP prog is active. This patch only affects the code path when XDP is active.Signed-off-by Martin KaFai Lau <[email protected]>---
Hi Martin, Sorry for the late review, i have some comments below
Quoted 31 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 17 +++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 23 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++---- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-)drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3
-1@@ -51,7 +51,8 @@#include "mlx4_en.h" #include "en_port.h" -#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN))) +#define MLX4_EN_MAX_XDP_MTU ((int)(PAGE_SIZE - ETH_HLEN - (2 * VLAN_HLEN) - \ + XDP_PACKET_HEADROOM))int mlx4_en_setup_tc (struct net_device *dev,u8 up) {@@ -1551,6 +1552,7 @@ int mlx4_en_start_port(struct net_device *dev)struct mlx4_en_tx_ring *tx_ring;int rx_index =0 ;int err =0 ; +int mtu;int i, t;int j;u8 mc_list[16 ] = {0 };@@ -1684,8 +1686,12 @@ int mlx4_en_start_port(struct net_device *dev) }Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c int mlx4_en_start_port(struct net_device *dev) · line 1692
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +4
-0/* Configure port */ + mtu = priv->rx_skb_size +ETH_FCS_LEN ; +if (priv->tx_ring_num[TX_XDP ]) + mtu +=XDP_PACKET_HEADROOM ; +Why would the physical MTU care for the headroom you preserve for XDP prog? This is the wire MTU, it shouldn't be changed, please keep it as before, any preservation you make in packets buffers are needed only for FWD case or modify case (HW or wire should not care about them).
Quoted 1 line
Thanks for your feedback!
Just doing my job :))
Quoted 10 lines
FWD:
packet received from a port
=> process by a XDP prog
=>XDP_TXout to the same port.For example, if the received packet has 1500 payload and the XDP prog encapsulates it in an IPv6 header (+40 bytes). After testing, it cannot be sent out due to the HW/wire MTU is 1500.
Quoted 6 lines
Even the wire MTU info was passed to the XDP prog, there is not much a XDP prog could do here other than dropping it.
Hence, this patch gives guarantee to the XDP prog such that it can always send out what it has received +
XDP_PACKET_HEADROOM.Still i am not convinced ! this is against common sense, this means that the XDP prog can send packets larger than the MTU seen on netdev!
Quoted 9 lines
Quoted 4 lines
anyway if a packet with the size (MTU +
XDP_PACKET_HEADROOM) was sent from XDP ring and HW allowed it to exit somehow (with the code you provided :)), most likely it will be dropped
at the other end.The MTU of our receiver side is larger than 1500.
If the otherside could not handle >1500, we could lower the box running XDP prog to 1460.
Quoted 7 lines
This is exactly the user confusion we are trying to avoid.
Genuinely lowering the other side or dropping packets in XDP program that are not eligible for edit&FWD (packets > MTU - required headroom ) will create the same effect. why don't you use this approach ?
dropping "large" packets in XDP seems the best solution.
Within the DC, yes we have absolute control on what to expect and we can even lower the other end easily if it is needed. However, it may not be the case for machines sitting at some exotic location.
After this thread, I think this bit may require more thoughts/discussions. I will drop it now and revisit later since it is not user ABI related.
For now, lets check and drop at the driver side since the driver has the MTU info.
Quoted 269 lines
Quoted 4 lines
Just ensure we are on the same page. The rx MTU stays the same (1500) because the rx_desc's
byte_countis not raised byXDP_PACKET_HEADROOM.Yea it is clear,
One more reason not to do this: now packets that were dropped due to "large MTU" HW drop cause, will now pass the HW check but will fail on RX error (RX buffers are smaller than the wire MTU sized packet) this counts as an error in both mlx5/4 which is not acceptable.
Quoted 257 lines
Quoted 73 lines
I still think XDP prog should not be allowed to FW packets larger than the MTU seen on the netdev and you shouldn't modify the wire MTU just for this case.
Quoted 68 lines
Quoted 54 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +8
-1err = mlx4_SET_PORT_general(mdev->dev, priv->port, - priv->rx_skb_size + ETH_FCS_LEN, + mtu, priv->prof->tx_pause, priv->prof->tx_ppp, priv->prof->rx_pause,@@ -2255,6 +2261,13 @@ static bool mlx4_en_check_xdp_mtu(struct net_device *dev, int mtu) {struct mlx4_en_priv *priv =netdev_priv (dev); +if (mtu +XDP_PACKET_HEADROOM > priv->max_mtu) { +en_err (priv, +"Device max mtu:%d does not allow %d bytes reserved headroom for XDP prog\n" , + priv->max_mtu,XDP_PACKET_HEADROOM ); +return false; + } +if (mtu >MLX4_EN_MAX_XDP_MTU ) {en_err (priv,"mtu:%d > max:%d when XDP prog is attached\n" , mtu,MLX4_EN_MAX_XDP_MTU );drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -96,7 +96,6 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS ];const struct mlx4_en_frag_info *frag_info;struct page *page; -dma_addr_t dma;int i;for (i =0 ; i < priv->num_frags; i++) {drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, · line 117
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -115,9 +114,10 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,for (i =0 ; i < priv->num_frags; i++) { frags[i] = ring_alloc[i]; - dma = ring_alloc[i].dma + ring_alloc[i].page_offset; + frags[i].page_offset += priv->frag_info[i].rx_headroom;I don't see any need for headroom on
frag_infoother that frag0 (which where the packet starts).
What is the meaning of a headroom of a frag in a middle of a packet ?if you agree with me then, you can use
XDP_PACKET_HEADROOMas is where needed (i.e frag0 page offset) and remove "priv->frag_info[i].rx_headroom"...
After going through the code a little bit i see that this code is shared between XDP and common path, and you didn't want to add boolean conditions.
Quoted 5 lines
Ok i see what you did here.
Maybe we can pass headroom as a function parameter and split frag0 handling from the rest ?
If it is too much then i am ok with the code as it is,Right, this patch does the boolean check (XDP active or not) early on in
mlx4_en_calc_rx_buf()(i.e. out of the fast path) and store the result in priv->frag_info[0].rx_headroom.Just want to ensure I understand your comment correctly.
You prefer not to store the boolean test result in frag_info[0].rx_headroom since it is redundant to !!priv->tx_ring_num[TX_XDP] andrx_headroomis also confusing for frag[1-3].Quoted 8 lines
Quoted 5 lines
Instead, do the XDP [in]active test before calling
mlx4_en_alloc_frags()and then only adjust frags[0].page_offset by +XDP_PACKET_HEADROOM if is needed. It could be done either by passing an extra argument tomlx4_en_alloc_frags()or completely separatemlx4_en_alloc_frags(). I am fine with this also.Correct, but if this change will add extra checks to the data path then I am ok with the current code.
Right, the check has to be done somewhere in the data path. Lets stay with the current approach then.
Quoted 173 lines
Quoted 49 lines
Quoted 39 lines
Quoted 39 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +8
-4+ rx_desc->data[i].addr =cpu_to_be64 (frags[i].dma + + frags[i].page_offset); ring_alloc[i] = page_alloc[i]; - rx_desc->data[i].addr =cpu_to_be64 (dma); }return 0 ;@@ -250,7 +250,8 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,if (ring->page_cache.index >0 ) { frags[0 ] = ring->page_cache.buf[--ring->page_cache.index]; - rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma); + rx_desc->data[0 ].addr =cpu_to_be64 (frags[0 ].dma + + frags[0 ].page_offset);return 0 ; }@@ -889,6 +890,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (xdp_prog) {struct xdp_buff xdp;dma_addr_t dma; +void *pg_addr, *orig_data;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);@@ -896,11 +898,18 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud priv->frag_info[0 ].frag_size, DMA_FROM_DEVICE); - xdp.data =page_address (frags[0 ].page) + - frags[0 ].page_offset; + pg_addr =page_address (frags[0 ].page); + orig_data = pg_addr + frags[0 ].page_offset; + xdp.data = orig_data; xdp.data_end = xdp.data + length;Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +6
-0act =bpf_prog_run_xdp (xdp_prog, &xdp); + +if (xdp.data != orig_data) { + length = xdp.data_end - xdp.data; + frags[0 ].page_offset = xdp.data - pg_addr; + } +is this needed only for XDP FWD case ?
Quoted 2 lines
No. It is also for PASS.
I see.
Quoted 61 lines
Quoted 2 lines
is this the only way to detect that the user modified the packet headers (comparing pointers, before and after) ?
Yes
Quoted 52 lines
if the answer is yes, it should be faster to unconditionally reset packet offset and lenght on
XDP_FWD:
caseXDP_FWD:length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr;Quoted 12 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0switch (act) {case XDP_PASS :break;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1180,6 +1189,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)*/ priv->frag_info[0 ].frag_stride =PAGE_SIZE ; priv->frag_info[0 ].dma_dir =PCI_DMA_BIDIRECTIONAL ; + priv->frag_info[0 ].rx_headroom =XDP_PACKET_HEADROOM ; i =1 ; }else {int buf_size =0 ;drivers/net/ethernet/mellanox/mlx4/en_rx.c void mlx4_en_calc_rx_buf(struct net_device *dev) · line 1207
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-0@@ -1194,6 +1204,7 @@ void mlx4_en_calc_rx_buf(struct net_device *dev)ALIGN (priv->frag_info[i].frag_size,SMP_CACHE_BYTES ); priv->frag_info[i].dma_dir =PCI_DMA_FROMDEVICE ; + priv->frag_info[i].rx_headroom =0 ;IMHO, redundant. as you see here frag0 and other frags handling are separated, maybe we can do the same in
mlx4_en_alloc_frags.Quoted 17 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-0buf_size += priv->frag_info[i].frag_size; i++; }drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct mlx4_en_rx_alloc frame = { .page = tx_info->page, .dma = tx_info->map0_dma, - .page_offset =0 , + .page_offset =XDP_PACKET_HEADROOM , .page_size =PAGE_SIZE , };drivers/net/ethernet/mellanox/mlx4/en_tx.c netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, · line 1135
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1
-1@@ -1132,7 +1132,7 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->page = frame->page; frame->page =NULL ; tx_info->map0_dma = dma; - tx_info->map0_byte_count = length; + tx_info->map0_byte_count = length + frame->page_offset;Didn't you already take care of lenght by the following code:
Quoted 5 lines
if (xdp.data != orig_data) { length = xdp.data_end - xdp.data; frags[0].page_offset = xdp.data - pg_addr; }Quoted 9 lines
Before this patch, length always assumes the data starts at the beginning of the page and dma is the start of the page. Hence, adding
framg->page_offsetback to the length here.However, if I read the codes correctly, I think the
map0_byte_count(before or after this patch) does not matter since it is only used indma_unmap_page()andPAGE_SIZEis always used indma_unmap_page()for this code patch. Hence, I think we can just setmap0_byte_counttoPAGE_SIZEhere.Right, in
mlx4_alloc_pageswe always map withPAGE_SIZE<< order
dma = dma_map_page(priv->ddev, page, 0,PAGE_SIZE<< order,
frag_info->dma_dir);
for XDP order is always 0, so you can safely set it toPAGE_SIZE.Quoted 6 lines
Quoted 2 lines
and here
frame->page_offsetis not really page offset, it can only beXDP_PACKET_HEADROOM.Note that the XDP prog can call
bpf_xdp_adjust_head()to add a header. The XDP prog can extend up toXDP_PACKET_HEADROOM(256) bytes but it can also (and usually) only add 40 bytes IPv6 header and thenXDP_TXit out.I see.
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/mellanox/mlx4/en_tx.c +3
-2tx_info->nr_txbb = nr_txbb; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN); tx_info->data_offset = (void *)data - (void *)tx_desc;@@ -1141,9 +1141,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_info->linear =1 ; tx_info->inl =0 ; -dma_sync_single_for_device (priv->ddev, dma, length,PCI_DMA_TODEVICE ); +dma_sync_single_range_for_device (priv->ddev, dma, frame->page_offset, + length,PCI_DMA_TODEVICE ); - data->addr =cpu_to_be64 (dma); + data->addr =cpu_to_be64 (dma + frame->page_offset); data->lkey = ring->mr_key;dma_wmb (); data->byte_count =cpu_to_be32 (length);drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2
-2@@ -475,7 +475,8 @@ struct mlx4_en_frag_info {u16 frag_prefix_size;u32 frag_stride;enum dma_data_direction dma_dir; -int order; +u16 order; +u16 rx_headroom; };#ifdef CONFIG_MLX4_EN_DCB --2.5.1