misc cleanups for xdp
Subsystems (6)
cover misc cleanups for xdp
This addresses several of the non-blocking comments left over from the xdp patch set. See individual patches for details.
Brenden Blanco (3):
net/mlx4_en: use READ_ONCE when freeing xdp_prog
rtnl: protect do_setlink from IFLA_XDP_ATTACHED
bpf: make xdp sample variable names more meaningful
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 6 ++++-- net/core/rtnetlink.c | 4 ++++ samples/bpf/xdp1_kern.c | 12 ++++++------ samples/bpf/xdp2_kern.c | 14 +++++++------- 4 files changed, 21 insertions(+), 15 deletions(-)
Signature · 1 line
2.8.2
PATCH 1/3 net/mlx4_en: use READ_ONCE when freeing xdp_prog
For consistency, and in order to hint at the synchronous nature of the xdp_prog field, use READ_ONCE in the destroy path of the ring. All occurrences should now use either READ_ONCE or xchg.
--- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_rx.c +4 -2
@@ -535,9 +535,11 @@ void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv, {struct mlx4_en_dev *mdev = priv->mdev;struct mlx4_en_rx_ring *ring = *pring; +struct bpf_prog *old_prog; -if (ring->xdp_prog) -bpf_prog_put (ring->xdp_prog); + old_prog =READ_ONCE (ring->xdp_prog); +if (old_prog) +bpf_prog_put (old_prog);mlx4_free_hwq_res (mdev->dev, &ring->wqres, size * stride +TXBB_SIZE );vfree (ring->rx_info); ring->rx_info =NULL ;
Signature · 1 line
2.8.2
PATCH 2/3 rtnl: protect do_setlink from IFLA_XDP_ATTACHED
In reply to Brenden BlancoThe IFLA_XDP_ATTACHED nested attribute is meant for read-only, and while do_setlink properly ignores it, it should be more paranoid and reject commands that try to set it.
--- net/core/rtnetlink.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/rtnetlink.c +4 -0
@@ -2109,6 +2109,10 @@ static int do_setlink(const struct sk_buff *skb,if (err <0 ) goto errout; +if (xdp[IFLA_XDP_ATTACHED ]) { + err = -EINVAL ; + goto errout; + }if (xdp[IFLA_XDP_FD ]) { err =dev_change_xdp_fd (dev,nla_get_s32 (xdp[IFLA_XDP_FD ]));
Signature · 1 line
2.8.2
PATCH 3/3 bpf: make xdp sample variable names more meaningful
In reply to Brenden BlancoThe naming choice of index is not terribly descriptive, and dropcnt is in fact incorrect for xdp2. Pick better names for these: ipproto and rxcnt.
--- samples/bpf/xdp1_kern.c | 12 ++++++------ samples/bpf/xdp2_kern.c | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-)
samples/bpf/xdp1_kern.c +6 -6
@@ -14,7 +14,7 @@#include <linux/ipv6.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") dropcnt = { +struct bpf_map_def SEC("maps") rxcnt = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(long),
@@ -49,7 +49,7 @@ int xdp_prog1(struct xdp_md *ctx)long *value;u16 h_proto;u64 nh_off; -u32 index; +u32 ipproto; nh_off =sizeof (*eth);if (data + nh_off > data_end)
@@ -77,13 +77,13 @@ int xdp_prog1(struct xdp_md *ctx) }if (h_proto ==htons (ETH_P_IP )) - index =parse_ipv4 (data, nh_off, data_end); + ipproto =parse_ipv4 (data, nh_off, data_end);else if (h_proto ==htons (ETH_P_IPV6 )) - index =parse_ipv6 (data, nh_off, data_end); + ipproto =parse_ipv6 (data, nh_off, data_end);else - index =0 ; + ipproto =0 ; - value =bpf_map_lookup_elem (&dropcnt, &index); + value =bpf_map_lookup_elem (&rxcnt, &ipproto);if (value) *value +=1 ;
samples/bpf/xdp2_kern.c +7 -7
@@ -14,7 +14,7 @@#include <linux/ipv6.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") dropcnt = { +struct bpf_map_def SEC("maps") rxcnt = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(long),
@@ -65,7 +65,7 @@ int xdp_prog1(struct xdp_md *ctx)long *value;u16 h_proto;u64 nh_off; -u32 index; +u32 ipproto; nh_off =sizeof (*eth);if (data + nh_off > data_end)
@@ -93,17 +93,17 @@ int xdp_prog1(struct xdp_md *ctx) }if (h_proto ==htons (ETH_P_IP )) - index =parse_ipv4 (data, nh_off, data_end); + ipproto =parse_ipv4 (data, nh_off, data_end);else if (h_proto ==htons (ETH_P_IPV6 )) - index =parse_ipv6 (data, nh_off, data_end); + ipproto =parse_ipv6 (data, nh_off, data_end);else - index =0 ; + ipproto =0 ; - value =bpf_map_lookup_elem (&dropcnt, &index); + value =bpf_map_lookup_elem (&rxcnt, &ipproto);if (value) *value +=1 ; -if (index ==17 ) { +if (ipproto ==IPPROTO_UDP ) {swap_src_dst_mac (data); rc =XDP_TX ; }
Signature · 1 line
2.8.2
Re: [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog
In reply to Brenden BlancoQuoted 5 lines · Brenden Blanco
For consistency, and in order to hint at the synchronous nature of the
xdp_progfield, useREAD_ONCEin the destroy path of the ring. All occurrences should now use eitherREAD_ONCEor xchg.Signed-off-by Brenden Blanco <[email protected]>
Re: [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED
In reply to Brenden BlancoQuoted 5 lines · Brenden Blanco
The
IFLA_XDP_ATTACHEDnested attribute is meant for read-only, and whiledo_setlinkproperly ignores it, it should be more paranoid and reject commands that try to set it.Signed-off-by Brenden Blanco <[email protected]>
Re: [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful
In reply to Brenden BlancoQuoted 5 lines · Brenden Blanco
The naming choice of index is not terribly descriptive, and dropcnt is in fact incorrect for xdp2. Pick better names for these: ipproto and rxcnt.
Signed-off-by Brenden Blanco <[email protected]>
Thanks!
David Miller
maintainerFrom: Brenden Blanco <[email protected]>
Date: Wed, 20 Jul 2016 17:22:32 -0700
Quoted 2 lines
This addresses several of the non-blocking comments left over from the xdp patch set. See individual patches for details.
Series applied, thanks.