netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@mellanox.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	bjorn.topel@intel.com,
	Magnus Karlsson <magnus.karlsson@intel.com>
Cc: "bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Jonathan Lemon <bsd@fb.com>,
	"David S. Miller" <davem@davemloft.net>,
	Maxim Mikityanskiy <maximmi@mellanox.com>,
	Tariq Toukan <tariqt@mellanox.com>,
	Saeed Mahameed <saeedm@mellanox.com>
Subject: [PATCH bpf-next V6 01/16] net/mlx5e: Attach/detach XDP program safely
Date: Wed, 26 Jun 2019 17:35:23 +0300	[thread overview]
Message-ID: <1561559738-4213-2-git-send-email-tariqt@mellanox.com> (raw)
In-Reply-To: <1561559738-4213-1-git-send-email-tariqt@mellanox.com>

From: Maxim Mikityanskiy <maximmi@mellanox.com>

When an XDP program is set, a full reopen of all channels happens in two
cases:

1. When there was no program set, and a new one is being set.

2. When there was a program set, but it's being unset.

The full reopen is necessary, because the channel parameters may change
if XDP is enabled or disabled. However, it's performed in an unsafe way:
if the new channels fail to open, the old ones are already closed, and
the interface goes down. Use the safe way to switch channels instead.
The same way is already used for other configuration changes.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 31 +++++++++++++++--------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 5e40db8f92e6..1b427d7fab42 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -4190,8 +4190,6 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)
 	/* no need for full reset when exchanging programs */
 	reset = (!priv->channels.params.xdp_prog || !prog);
 
-	if (was_opened && reset)
-		mlx5e_close_locked(netdev);
 	if (was_opened && !reset) {
 		/* num_channels is invariant here, so we can take the
 		 * batched reference right upfront.
@@ -4203,20 +4201,31 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)
 		}
 	}
 
-	/* exchange programs, extra prog reference we got from caller
-	 * as long as we don't fail from this point onwards.
-	 */
-	old_prog = xchg(&priv->channels.params.xdp_prog, prog);
+	if (was_opened && reset) {
+		struct mlx5e_channels new_channels = {};
+
+		new_channels.params = priv->channels.params;
+		new_channels.params.xdp_prog = prog;
+		mlx5e_set_rq_type(priv->mdev, &new_channels.params);
+		old_prog = priv->channels.params.xdp_prog;
+
+		err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
+		if (err)
+			goto unlock;
+	} else {
+		/* exchange programs, extra prog reference we got from caller
+		 * as long as we don't fail from this point onwards.
+		 */
+		old_prog = xchg(&priv->channels.params.xdp_prog, prog);
+	}
+
 	if (old_prog)
 		bpf_prog_put(old_prog);
 
-	if (reset) /* change RQ type according to priv->xdp_prog */
+	if (!was_opened && reset) /* change RQ type according to priv->xdp_prog */
 		mlx5e_set_rq_type(priv->mdev, &priv->channels.params);
 
-	if (was_opened && reset)
-		err = mlx5e_open_locked(netdev);
-
-	if (!test_bit(MLX5E_STATE_OPENED, &priv->state) || reset)
+	if (!was_opened || reset)
 		goto unlock;
 
 	/* exchanging programs w/o reset, we update ref counts on behalf
-- 
1.8.3.1


  reply	other threads:[~2019-06-26 14:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26 14:35 [PATCH bpf-next V6 00/16] AF_XDP infrastructure improvements and mlx5e support Tariq Toukan
2019-06-26 14:35 ` Tariq Toukan [this message]
2019-06-26 14:35 ` [PATCH bpf-next V6 02/16] xsk: Add API to check for available entries in FQ Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 03/16] xsk: Add getsockopt XDP_OPTIONS Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 04/16] libbpf: Support " Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 05/16] xsk: Change the default frame size to 4096 and allow controlling it Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 06/16] xsk: Return the whole xdp_desc from xsk_umem_consume_tx Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 07/16] net/mlx5e: Replace deprecated PCI_DMA_TODEVICE Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 08/16] net/mlx5e: Calculate linear RX frag size considering XSK Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 09/16] net/mlx5e: Allow ICO SQ to be used by multiple RQs Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 10/16] net/mlx5e: Refactor struct mlx5e_xdp_info Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 11/16] net/mlx5e: Share the XDP SQ for XDP_TX between RQs Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 12/16] net/mlx5e: XDP_TX from UMEM support Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 13/16] net/mlx5e: Consider XSK in XDP MTU limit calculation Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 14/16] net/mlx5e: Encapsulate open/close queues into a function Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 15/16] net/mlx5e: Move queue param structs to en/params.h Tariq Toukan
2019-06-26 14:35 ` [PATCH bpf-next V6 16/16] net/mlx5e: Add XSK zero-copy support Tariq Toukan
2019-06-26 16:29 ` [PATCH bpf-next V6 00/16] AF_XDP infrastructure improvements and mlx5e support Björn Töpel
2019-06-26 16:46 ` Jonathan Lemon
2019-06-26 20:26 ` Daniel Borkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1561559738-4213-2-git-send-email-tariqt@mellanox.com \
    --to=tariqt@mellanox.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=bsd@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=magnus.karlsson@intel.com \
    --cc=maximmi@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).