All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] misc cleanups for xdp
@ 2016-07-21  0:22 Brenden Blanco
  2016-07-21  0:22 ` [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog Brenden Blanco
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Brenden Blanco @ 2016-07-21  0:22 UTC (permalink / raw)
  To: davem, netdev
  Cc: Brenden Blanco, Daniel Borkmann, Alexei Starovoitov, Tariq Toukan

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

-- 
2.8.2

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

* [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog
  2016-07-21  0:22 [PATCH net-next 0/3] misc cleanups for xdp Brenden Blanco
@ 2016-07-21  0:22 ` Brenden Blanco
  2016-07-21  1:20   ` Alexei Starovoitov
  2016-07-21  0:22 ` [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED Brenden Blanco
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Brenden Blanco @ 2016-07-21  0:22 UTC (permalink / raw)
  To: davem, netdev
  Cc: Brenden Blanco, Daniel Borkmann, Alexei Starovoitov, Tariq Toukan

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.

Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 11d88c8..a02dec6 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -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;
-- 
2.8.2

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

* [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED
  2016-07-21  0:22 [PATCH net-next 0/3] misc cleanups for xdp Brenden Blanco
  2016-07-21  0:22 ` [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog Brenden Blanco
@ 2016-07-21  0:22 ` Brenden Blanco
  2016-07-21  1:21   ` Alexei Starovoitov
  2016-07-21  0:22 ` [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful Brenden Blanco
  2016-07-21  5:07 ` [PATCH net-next 0/3] misc cleanups for xdp David Miller
  3 siblings, 1 reply; 8+ messages in thread
From: Brenden Blanco @ 2016-07-21  0:22 UTC (permalink / raw)
  To: davem, netdev
  Cc: Brenden Blanco, Daniel Borkmann, Alexei Starovoitov, Tariq Toukan

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

Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
---
 net/core/rtnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index eba2b82..189cc78 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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]));
-- 
2.8.2

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

* [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful
  2016-07-21  0:22 [PATCH net-next 0/3] misc cleanups for xdp Brenden Blanco
  2016-07-21  0:22 ` [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog Brenden Blanco
  2016-07-21  0:22 ` [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED Brenden Blanco
@ 2016-07-21  0:22 ` Brenden Blanco
  2016-07-21  1:22   ` Alexei Starovoitov
  2016-07-21  5:07 ` [PATCH net-next 0/3] misc cleanups for xdp David Miller
  3 siblings, 1 reply; 8+ messages in thread
From: Brenden Blanco @ 2016-07-21  0:22 UTC (permalink / raw)
  To: davem, netdev
  Cc: Brenden Blanco, Daniel Borkmann, Alexei Starovoitov, Tariq Toukan

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 <bblanco@plumgrid.com>
---
 samples/bpf/xdp1_kern.c | 12 ++++++------
 samples/bpf/xdp2_kern.c | 14 +++++++-------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
index e7dd8ac..2197421 100644
--- a/samples/bpf/xdp1_kern.c
+++ b/samples/bpf/xdp1_kern.c
@@ -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;
 
diff --git a/samples/bpf/xdp2_kern.c b/samples/bpf/xdp2_kern.c
index 38fe7e1..e012888 100644
--- a/samples/bpf/xdp2_kern.c
+++ b/samples/bpf/xdp2_kern.c
@@ -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;
 	}
-- 
2.8.2

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

* Re: [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog
  2016-07-21  0:22 ` [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog Brenden Blanco
@ 2016-07-21  1:20   ` Alexei Starovoitov
  0 siblings, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2016-07-21  1:20 UTC (permalink / raw)
  To: Brenden Blanco; +Cc: davem, netdev, Daniel Borkmann, Tariq Toukan

On Wed, Jul 20, 2016 at 05:22:33PM -0700, Brenden Blanco wrote:
> 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.
> 
> Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>

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

* Re: [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED
  2016-07-21  0:22 ` [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED Brenden Blanco
@ 2016-07-21  1:21   ` Alexei Starovoitov
  0 siblings, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2016-07-21  1:21 UTC (permalink / raw)
  To: Brenden Blanco; +Cc: davem, netdev, Daniel Borkmann, Tariq Toukan

On Wed, Jul 20, 2016 at 05:22:34PM -0700, Brenden Blanco wrote:
> The 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.
> 
> Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>

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

* Re: [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful
  2016-07-21  0:22 ` [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful Brenden Blanco
@ 2016-07-21  1:22   ` Alexei Starovoitov
  0 siblings, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2016-07-21  1:22 UTC (permalink / raw)
  To: Brenden Blanco; +Cc: davem, netdev, Daniel Borkmann, Tariq Toukan

On Wed, Jul 20, 2016 at 05:22:35PM -0700, Brenden Blanco wrote:
> 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 <bblanco@plumgrid.com>

Thanks!
Acked-by: Alexei Starovoitov <ast@kernel.org>

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

* Re: [PATCH net-next 0/3] misc cleanups for xdp
  2016-07-21  0:22 [PATCH net-next 0/3] misc cleanups for xdp Brenden Blanco
                   ` (2 preceding siblings ...)
  2016-07-21  0:22 ` [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful Brenden Blanco
@ 2016-07-21  5:07 ` David Miller
  3 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2016-07-21  5:07 UTC (permalink / raw)
  To: bblanco; +Cc: netdev, daniel, alexei.starovoitov, ttoukan.linux

From: Brenden Blanco <bblanco@plumgrid.com>
Date: Wed, 20 Jul 2016 17:22:32 -0700

> This addresses several of the non-blocking comments left over from the
> xdp patch set. See individual patches for details.

Series applied, thanks.

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

end of thread, other threads:[~2016-07-21  5:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-21  0:22 [PATCH net-next 0/3] misc cleanups for xdp Brenden Blanco
2016-07-21  0:22 ` [PATCH net-next 1/3] net/mlx4_en: use READ_ONCE when freeing xdp_prog Brenden Blanco
2016-07-21  1:20   ` Alexei Starovoitov
2016-07-21  0:22 ` [PATCH net-next 2/3] rtnl: protect do_setlink from IFLA_XDP_ATTACHED Brenden Blanco
2016-07-21  1:21   ` Alexei Starovoitov
2016-07-21  0:22 ` [PATCH net-next 3/3] bpf: make xdp sample variable names more meaningful Brenden Blanco
2016-07-21  1:22   ` Alexei Starovoitov
2016-07-21  5:07 ` [PATCH net-next 0/3] misc cleanups for xdp David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.