From nobody Tue Feb 01 15:24:27 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D1E4A1916794; Tue, 1 Feb 2022 15:24:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jp7yN4hF1z3G02; Tue, 1 Feb 2022 15:24:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643729068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P1jj5PZ88oQ2xIVBAW/pwKU6dF3kiln17n8evnKBxW0=; b=wzvcSripb0FMLZr/OniAQP17En7a9OajoDy+SkfxLVmjJYCOTTm6woQvsZz/kxmdieN7c5 ZM4cXA4B1c9vdH47evHY8P1JpRGBtHWy29NwBf1u2qhLtNGtyIwNXJjL3f1x3tyMdop9OO +D/0onSbolhRlku4K/lGTSzojbM7mCNIMpoZZ6YbxEZX6ffNww3W6DAsgvsWgexC1t5QR/ FuFAce2EPl0iFvT2b1sJfYvqSVirZl3BNrkiP2o1bzCHcvebYcQcjfcQSVluI3yupua1X7 00Mh7m958eMpj67uh5SXzGX+tPPHPG4hty3LGCg5zGq04gNTy0+M3bAsRiiM6A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 189EE133B9; Tue, 1 Feb 2022 15:24:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 211FOSPb051172; Tue, 1 Feb 2022 15:24:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 211FORdU051171; Tue, 1 Feb 2022 15:24:27 GMT (envelope-from git) Date: Tue, 1 Feb 2022 15:24:27 GMT Message-Id: <202202011524.211FORdU051171@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hans Petter Selasky Subject: git: a8e715d21b96 - main - mlx5en: Add race protection for SQ remap List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a8e715d21b963251e449187c98292fff77dc7576 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643729068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P1jj5PZ88oQ2xIVBAW/pwKU6dF3kiln17n8evnKBxW0=; b=diM0XiYwXmT9228NBWlb4GL5Gqfk3Oa9wp2QHiyYxYv5IRW5p2OnjCKCiq+yrzr0vunL7i YkG3t6UafUlNMMrqmK2jgl1VGTTI0Ke4aO+SotN57VUTIVx535mV+vTsqyEuw8FdtB8RRp 9HLQULGxiMKxYxHpw27q8jn3R3sPskrQYWFTin1eDfdM8vqIhnTTXzoa17inLZNi26mXLI lh1Udbq9kLrTvy0Lwl1to/F3dpWzsrtAUWerrYvWJp1eolxx3e7DfoOSCU62liB9EB39Xm xhxZXHMRHTD6y6Ko8+TurqW67MILuNQ8VVGZ8NfQY9BLENBB6p7LpR4w7r49kw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643729068; a=rsa-sha256; cv=none; b=L8u3r7QTvtAYQw+4vQNs8VeFHYumZrPrgqP0N6UM7bH7IcNo5Iwb2wctasaQ6N7UoRY+eN 5915GPcXG2PR0K4tOmRxZUfP0wR3RoPxkTRDvUu9Mv/2JqEXX2Quit80mjNNMLGFkkHtVV YIZnriOnpMBP6LSqti2CLLi5KbM3tlKcz86shCPSSve2qkZGN4UiXviBnIJE1+KKF+MBbC G7zWAuN4h3grOx7Xbw86MceWkF94KanOeV8b2gf+kJa5B6WbA7eiTXhcnP9Wy8w1aD/WrP SDzHfyyJeZXmN5McGW0wIvqaSKByV+M0xWsaEkMde9CzJi3IlKEJoipmLYGQpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=a8e715d21b963251e449187c98292fff77dc7576 commit a8e715d21b963251e449187c98292fff77dc7576 Author: Hans Petter Selasky AuthorDate: 2022-02-01 15:20:12 +0000 Commit: Hans Petter Selasky CommitDate: 2022-02-01 15:21:16 +0000 mlx5en: Add race protection for SQ remap Add a refcount for posted WQEs to avoid a race between post WQE and FW command flows. MFC after: 1 week Sponsored by: NVIDIA Networking --- sys/dev/mlx5/mlx5_en/en_rl.h | 1 + sys/dev/mlx5/mlx5_en/mlx5_en_rl.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sys/dev/mlx5/mlx5_en/en_rl.h b/sys/dev/mlx5/mlx5_en/en_rl.h index 1d7f7afc487d..5d4cb7365f2a 100644 --- a/sys/dev/mlx5/mlx5_en/en_rl.h +++ b/sys/dev/mlx5/mlx5_en/en_rl.h @@ -136,6 +136,7 @@ struct mlx5e_rl_channel { uint64_t new_rate; uint64_t init_rate; uint64_t last_rate; + uint32_t refcount; uint16_t last_burst; uint16_t state; }; diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_rl.c b/sys/dev/mlx5/mlx5_en/mlx5_en_rl.c index 6fe4bd344710..09ff0143e430 100644 --- a/sys/dev/mlx5/mlx5_en/mlx5_en_rl.c +++ b/sys/dev/mlx5/mlx5_en/mlx5_en_rl.c @@ -424,7 +424,8 @@ mlx5e_rl_find_best_rate_locked(struct mlx5e_rl_priv_data *rl, uint64_t user_rate } static int -mlx5e_rl_post_sq_remap_wqe(struct mlx5e_iq *iq, u32 scq_handle, u32 sq_handle) +mlx5e_rl_post_sq_remap_wqe(struct mlx5e_iq *iq, u32 scq_handle, u32 sq_handle, + struct mlx5e_rl_channel *sq_channel) { const u32 ds_cnt = DIV_ROUND_UP(sizeof(struct mlx5e_tx_qos_remap_wqe), MLX5_SEND_WQE_DS); @@ -454,6 +455,8 @@ mlx5e_rl_post_sq_remap_wqe(struct mlx5e_iq *iq, u32 scq_handle, u32 sq_handle) memcpy(iq->doorbell.d32, &wqe->ctrl, sizeof(iq->doorbell.d32)); iq->data[pi].num_wqebbs = DIV_ROUND_UP(ds_cnt, MLX5_SEND_WQEBB_NUM_DS); + iq->data[pi].p_refcount = &sq_channel->refcount; + atomic_add_int(iq->data[pi].p_refcount, 1); iq->pc += iq->data[pi].num_wqebbs; mlx5e_iq_notify_hw(iq); @@ -464,7 +467,8 @@ mlx5e_rl_post_sq_remap_wqe(struct mlx5e_iq *iq, u32 scq_handle, u32 sq_handle) } static int -mlx5e_rl_remap_sq(struct mlx5e_sq *sq, uint16_t index) +mlx5e_rl_remap_sq(struct mlx5e_sq *sq, uint16_t index, + struct mlx5e_rl_channel *sq_channel) { struct mlx5e_channel *iq_channel; u32 scq_handle; @@ -477,10 +481,12 @@ mlx5e_rl_remap_sq(struct mlx5e_sq *sq, uint16_t index) sq_handle = sq->queue_handle; scq_handle = mlx5_rl_get_scq_handle(sq->priv->mdev, index); - if (sq_handle == -1U || scq_handle == -1U) + if (sq_handle == MLX5_INVALID_QUEUE_HANDLE || + scq_handle == MLX5_INVALID_QUEUE_HANDLE) error = -1; else - error = mlx5e_rl_post_sq_remap_wqe(&iq_channel->iq, scq_handle, sq_handle); + error = mlx5e_rl_post_sq_remap_wqe(&iq_channel->iq, scq_handle, + sq_handle, sq_channel); return (error); } @@ -568,7 +574,11 @@ mlx5e_rlw_channel_set_rate_locked(struct mlx5e_rl_worker *rlw, /* set new rate, if SQ is running */ sq = channel->sq; if (sq != NULL && READ_ONCE(sq->running) != 0) { - if (!use_sq_remap || mlx5e_rl_remap_sq(sq, index)) { + if (!use_sq_remap || mlx5e_rl_remap_sq(sq, index, channel)) { + while (atomic_load_int(&channel->refcount) != 0 && + rlw->priv->mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR && + pci_channel_offline(rlw->priv->mdev->pdev) == 0) + pause("W", 1); error = mlx5e_rl_modify_sq(sq, index); if (error != 0) atomic_add_64(&rlw->priv->rl.stats.tx_modify_rate_failure, 1ULL);