From patchwork Wed Sep 25 20:20:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812404 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B731A14884C for ; Wed, 25 Sep 2024 20:20:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295619; cv=none; b=O+evS5KoaRDgNZqQGTn2JbtIYM9uMRnwexB7Encz9NuNJsnzLj1AXXzPYhjEt2JKj3ANF+OFAABS8EFUr3j6OwhGJO9k/8YvnLnBlXsh9SxI0bYMtAaaJWUzo8MyASnvz8Oj7R5ELu17QQzH6nA/zPJ7YVtTo5nUd33Y/HF/EYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295619; c=relaxed/simple; bh=6vIrgKwlwWw0JozlQZEvOhq5Fo8aBIbsGcWrnYZk45s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vExqiDzGLmj9mVdCGbwbBCyxuFN6X9LLI/nDEZzZ4rIScIU30h22WpTD4McCFhFgJBkBrSTH/xFNnH27dzMcR+m/IXIRVeLW0frtt+Fkf/VfeI1BTSKzUADF5I7fU4dTPfmp/mHOX/w6REJpEacVu3wQ5s1gemhL6nIshnKPjNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o4ElnPfv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o4ElnPfv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F07EC4CEC9; Wed, 25 Sep 2024 20:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295619; bh=6vIrgKwlwWw0JozlQZEvOhq5Fo8aBIbsGcWrnYZk45s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o4ElnPfvcOzNdnZjkgmigO+vPJyfr1eLtSDn/S/0Hf1x57NYuyL/M9p9F5O/5L++v 3RrkLt81+QlK3VYn0RRx7dt3kDCqnHJsWDdQniMEi6h1eAQW5eNSr42QHXTlVKIUx8 KyoNbzBczistzNYtzz8HT5pj/QwAwsfJ+AAThX9lP4BOcrOQo4iiLAO7clKHSajJYo nrHM8yX1qoPmCX3mGj8E7oYu+h2F11GLkhUoTTSrf63rtEgOp+izdJF0+yvwPCEQUX STwSUkZE8xslivFolzfNDZxb8yPiwK68+BF7U2pEVHFGVkx13Cd0DfhE3aFQgOsccM /S2xdGL6vWZOg== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Gerd Bayer , Zhu Yanjun , Maxim Mikityanskiy Subject: [net 1/8] net/mlx5: Fix error path in multi-packet WQE transmit Date: Wed, 25 Sep 2024 13:20:06 -0700 Message-ID: <20240925202013.45374-2-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Gerd Bayer Remove the erroneous unmap in case no DMA mapping was established The multi-packet WQE transmit code attempts to obtain a DMA mapping for the skb. This could fail, e.g. under memory pressure, when the IOMMU driver just can't allocate more memory for page tables. While the code tries to handle this in the path below the err_unmap label it erroneously unmaps one entry from the sq's FIFO list of active mappings. Since the current map attempt failed this unmap is removing some random DMA mapping that might still be required. If the PCI function now presents that IOVA, the IOMMU may assumes a rogue DMA access and e.g. on s390 puts the PCI function in error state. The erroneous behavior was seen in a stress-test environment that created memory pressure. Fixes: 5af75c747e2a ("net/mlx5e: Enhanced TX MPWQE for SKBs") Signed-off-by: Gerd Bayer Reviewed-by: Zhu Yanjun Acked-by: Maxim Mikityanskiy Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/en_tx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c index b09e9abd39f3..f8c7912abe0e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c @@ -642,7 +642,6 @@ mlx5e_sq_xmit_mpwqe(struct mlx5e_txqsq *sq, struct sk_buff *skb, return; err_unmap: - mlx5e_dma_unmap_wqe_err(sq, 1); sq->stats->dropped++; dev_kfree_skb_any(skb); mlx5e_tx_flush(sq); From patchwork Wed Sep 25 20:20:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812405 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E92D14A0BC for ; Wed, 25 Sep 2024 20:20:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295620; cv=none; b=G7GLEzee3cgxBNjXLi8hQ5fU2TgqIDmQrA/1rF306i4yWfVMGNBZSB5YqJb7HbKFA/TMLJQzSbwgYa8W/LbgiKxw0SOIs1vnYJa0alfpGuxf5ivVl01NEAAnGK9xexY7tEObJGfZY2+xD6Q8G7libbBUjyQEtx0APcFP/RSM70g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295620; c=relaxed/simple; bh=CefgCdjM7a3qSpg7kE6psuz7c5Kcep0bN8QmOjPzfsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rKxvg/9O5disTrJQQHtc+iyeNinsp7i+CarePzzXNBZp6tOgMHfBDTtB9fyA3EVmIyXF9Jsn2U2hhObvLTWp4xAS7OTCHWYr5kEttJ7o/h4tzF9VhwpRAuxAzEG7LEi4Y44Z51jz4WuzOm0kAEOc1wyn09Du2XyN03ST7cRmoWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uutJ+4zK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uutJ+4zK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A2D9C4CEC9; Wed, 25 Sep 2024 20:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295620; bh=CefgCdjM7a3qSpg7kE6psuz7c5Kcep0bN8QmOjPzfsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uutJ+4zKCp76bbxPjCQV+u0T7cx0G4lwyBk1iImhoMXC/cMNbLEa2JuyaSsCRfN90 DhbkXMYRRiRzwg6oZmtobyHmnXvVXV8kPydz+3QBB2Dup0pJ7iPH+JnlVqBPC4iaVo /zfgotMvfWILURy9cnUBUbQXRN+TLQNczgcvtVVd5gpM9huPtPddIK110aP0mAplhJ JgDu9T/Lhvlw8t9G4d00SqBEGpgDPs2FiXnW75JghmvVdS7EC9v546ksHVqO0UJShP +PVuiDu9JbhsX90NqfSeTGL6ZeJIPnPk1GEBmtLblgUAL4jo86WwZfC2Q2IoqbFjVL /Nac/iuk+Jvsw== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Mohamed Khalfella , Yuanyuan Zhong , Moshe Shemesh Subject: [net 2/8] net/mlx5: Added cond_resched() to crdump collection Date: Wed, 25 Sep 2024 13:20:07 -0700 Message-ID: <20240925202013.45374-3-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Mohamed Khalfella Collecting crdump involves reading vsc registers from pci config space of mlx device, which can take long time to complete. This might result in starving other threads waiting to run on the cpu. Numbers I got from testing ConnectX-5 Ex MCX516A-CDAT in the lab: - mlx5_vsc_gw_read_block_fast() was called with length = 1310716. - mlx5_vsc_gw_read_fast() reads 4 bytes at a time. It was not used to read the entire 1310716 bytes. It was called 53813 times because there are jumps in read_addr. - On average mlx5_vsc_gw_read_fast() took 35284.4ns. - In total mlx5_vsc_wait_on_flag() called vsc_read() 54707 times. The average time for each call was 17548.3ns. In some instances vsc_read() was called more than one time when the flag was not set. As expected the thread released the cpu after 16 iterations in mlx5_vsc_wait_on_flag(). - Total time to read crdump was 35284.4ns * 53813 ~= 1.898s. It was seen in the field that crdump can take more than 5 seconds to complete. During that time mlx5_vsc_wait_on_flag() did not release the cpu because it did not complete 16 iterations. It is believed that pci config reads were slow. Adding cond_resched() every 128 register read improves the situation. In the common case the, crdump takes ~1.8989s, the thread yields the cpu every ~4.51ms. If crdump takes ~5s, the thread yields the cpu every ~18.0ms. Fixes: 8b9d8baae1de ("net/mlx5: Add Crdump support") Reviewed-by: Yuanyuan Zhong Signed-off-by: Mohamed Khalfella Reviewed-by: Moshe Shemesh Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c index d0b595ba6110..432c98f2626d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c @@ -24,6 +24,11 @@ pci_write_config_dword((dev)->pdev, (dev)->vsc_addr + (offset), (val)) #define VSC_MAX_RETRIES 2048 +/* Reading VSC registers can take relatively long time. + * Yield the cpu every 128 registers read. + */ +#define VSC_GW_READ_BLOCK_COUNT 128 + enum { VSC_CTRL_OFFSET = 0x4, VSC_COUNTER_OFFSET = 0x8, @@ -273,6 +278,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, { unsigned int next_read_addr = 0; unsigned int read_addr = 0; + unsigned int count = 0; while (read_addr < length) { if (mlx5_vsc_gw_read_fast(dev, read_addr, &next_read_addr, @@ -280,6 +286,10 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, return read_addr; read_addr = next_read_addr; + if (++count == VSC_GW_READ_BLOCK_COUNT) { + cond_resched(); + count = 0; + } } return length; } From patchwork Wed Sep 25 20:20:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812406 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 692EA14B94C for ; Wed, 25 Sep 2024 20:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295621; cv=none; b=TTwtXfdMYHLbL/MINGJyCgsvZOSLJq+uL9VuR5It3IEY7APVRIVmbDDRlNQvOqGMhrTeV7kD0KPT3Yhy93H5u4gc2jFxsiyHJjTd4MCiXr5d0W0EHhkv0cydjhadRF/+6iOgKw/vsQA88vXFsAuqaOyIzu2I7IqbmvUBn+S5QCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295621; c=relaxed/simple; bh=q9heOA759Feg+gsc4h6gwRpTD5AW/fy0qmc4G7wb5s0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TmtTejWR1lwb8oGf3RWtP5qVKmQRhOS7to1mejfSCImzPC37h5CgrqrlEsXQO338+zPmpERy/Zum4JDSwZFhECZ7BCFWZB5F4U+cXucoOEUEAZawfD2QZkPJIOuXuIbLmckDnOQmWX/EqKXPuz4OlDlmu1O3qzVU2SeokIvlZcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qyMQP7Vb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qyMQP7Vb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB831C4CECD; Wed, 25 Sep 2024 20:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295621; bh=q9heOA759Feg+gsc4h6gwRpTD5AW/fy0qmc4G7wb5s0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qyMQP7VbiB1FbzKySGeDnh8Ii+/99MFSu4htj0baSZnpVfgwXQbpesPWeCx/ap10p ARuwz4S5o9p9rsdXihXw7KUg8hl8sGHYefp2daj62vRucK2zu/H0RYB/aTulCRFWOL iGsRhOq2rfIlLZYF8N9iZdoP9tLwbdvb/+TT68t7T4E3N/h3akkuzBkubehT2zUf8D Rwn2ViXatp4EeIfi9a8LWqZdFcJJC2X2u5a2nAU6kMN1pd5hCc5jaC2WxxwYSKpxO6 GjoOfzNHOn68wq6b55nnZQU1vtsW6MYmT4kvHbP1mTu5drMTMNDTdk2H3jV8ulmZ3V LCeqpJeQMnaHA== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Elena Salomatkina , Simon Horman , Kalesh AP Subject: [net 3/8] net/mlx5e: Fix NULL deref in mlx5e_tir_builder_alloc() Date: Wed, 25 Sep 2024 13:20:08 -0700 Message-ID: <20240925202013.45374-4-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Elena Salomatkina In mlx5e_tir_builder_alloc() kvzalloc() may return NULL which is dereferenced on the next line in a reference to the modify field. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a6696735d694 ("net/mlx5e: Convert TIR to a dedicated object") Signed-off-by: Elena Salomatkina Reviewed-by: Simon Horman Reviewed-by: Kalesh AP Reviewed-by: Tariq Toukan Reviewed-by: Gal Pressman Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/en/tir.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c index d4239e3b3c88..11f724ad90db 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c @@ -23,6 +23,9 @@ struct mlx5e_tir_builder *mlx5e_tir_builder_alloc(bool modify) struct mlx5e_tir_builder *builder; builder = kvzalloc(sizeof(*builder), GFP_KERNEL); + if (!builder) + return NULL; + builder->modify = modify; return builder; From patchwork Wed Sep 25 20:20:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812407 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAAE514D2B8 for ; Wed, 25 Sep 2024 20:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295622; cv=none; b=D04m47nyT0MJMT2cpb4UaRfBMENdceUovnKISyXQu/lVOk3OnPJKass5bNzRHJHuGAtDxk9+lQUZRXHUk63m2aEGhWh3tQg6y0MYBJ2TYoJ8LPW79kmQlX7Xeh3nSgMycFjMsIInor+otnE4YR2hZ7gLuZskr3sKN1dpbMMBc2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295622; c=relaxed/simple; bh=UmeLeVjpGuVXJaYH9oHbxtBmYZZ2mIjnmjnppDiBmD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tictvVFq9EVGeO4SpeuUisavgA9QN2B126NKcbSUdgDATBfGR/PcAUBGl6bbt5WTDAaoT7sQloboiA52O6gPszFVN6dN8PmY/QjZTrPq0dX1QwT7aXSkOLLZJDrOqRdND90aZAgZ4QvJ9e+5BoSXsyiN5L6i92yx4pK+vSDlw58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sggBqvOG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sggBqvOG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFE5BC4CEC3; Wed, 25 Sep 2024 20:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295621; bh=UmeLeVjpGuVXJaYH9oHbxtBmYZZ2mIjnmjnppDiBmD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sggBqvOG54v6Rlzyx0vyHJKGMc2oo+ybPt98Dak+PiRYzVBoohfqQb/ssrIC59Gvb nasXFrYi7pEuIr4dwsf4dCbPQU8rz5+Gs8US3YROCoDMr3pyDNakh+qI9FT8kzT9kH hQGMYaIiM3ptlCMTeHiPGhLCAYIeSL379v50Tg0yL4pvLVHqBvSSb7p7NOnb1EfJTb OptY3qRyYaLbTgHrI0e/M7GPk1ZHQgpl5eIkbFjvaJaj8eRBRJvIL/JtB/6bnF7Gdq 7m4GPXwXJUh2MItkkL4L8b3QbivHZkd6lfn9yN/KdB1eytEHgClOCaGjzJXZLIWeSi r4WTVL/FaIvVA== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Yevgeny Kliteynik Subject: [net 4/8] net/mlx5: Fix wrong reserved field in hca_cap_2 in mlx5_ifc Date: Wed, 25 Sep 2024 13:20:09 -0700 Message-ID: <20240925202013.45374-5-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Yevgeny Kliteynik Fixing the wrong size of a field in hca_cap_2. The bug was introduced by adding new fields for HWS and not fixing the reserved field size. Fixes: 34c626c3004a ("net/mlx5: Added missing mlx5_ifc definition for HW Steering") Signed-off-by: Yevgeny Kliteynik Reviewed-by: Tariq Toukan Signed-off-by: Saeed Mahameed --- include/linux/mlx5/mlx5_ifc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 620a5c305123..04df1610736e 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -2115,7 +2115,7 @@ struct mlx5_ifc_cmd_hca_cap_2_bits { u8 ts_cqe_metadata_size2wqe_counter[0x5]; u8 reserved_at_250[0x10]; - u8 reserved_at_260[0x120]; + u8 reserved_at_260[0x20]; u8 format_select_dw_gtpu_dw_0[0x8]; u8 format_select_dw_gtpu_dw_1[0x8]; From patchwork Wed Sep 25 20:20:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812408 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD8FE14F9FD for ; Wed, 25 Sep 2024 20:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295622; cv=none; b=tJ3LKtl90TASDtFJrIFeU8mEGTTIbV9rAiHer5Na5mAAzksWpP/UitTgEPlgd9rwTuROVxVsEO8gsGuc3SrY5ZOPky0kyETkHaC4dqzTSK0vxUTbtEExANqH6eBqnsSi4H1LNzKU0Gncg8os+ImUJKZIaqNzPa0a0jDkw2cVN4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295622; c=relaxed/simple; bh=F6JInSZ1B3JBx2nLMqz1WtCE2ayxMuc0K4E/bM7+xH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XoiK68Gbutvjy5ZRGTyxZNyOkm4w4bOsGCQrXkwSbYPWTdVnylnD1n+9QetIoc2wvzrX3zok6yGu+rkl2KBBoLl3flyZiNebzTS106arfNguw8qidVaXaFlbKNSCp1EdCTF3OzMP/AmclMkkdCcn7/IvpCifWnatLgn9pr+4n1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SIHKIe5c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SIHKIe5c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93DEFC4CEC3; Wed, 25 Sep 2024 20:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295622; bh=F6JInSZ1B3JBx2nLMqz1WtCE2ayxMuc0K4E/bM7+xH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SIHKIe5cpkIdlucNaZy6wi/qMlhFw8anczlJ/VTFQWD+Y+NC8dMcoIBIlCSRC3LWM YwWPl7BuwPS73YI4eorfyNsf76sDGvR6QykEVheXNmJMNRyPR09v8lS8qEn9ihFzg+ ftLRtGM+Lr3Dl1DTqShBk7KR4sPUvFm9aARaOwXcNZKlkpwmrEFOsGXP/K/gWzvlcL orpkxxp0aLBUhR80ecbSa230AniiJ7J9m4fSAhvuqX7lzEcqSkcfx9DuvVgTgLtfIc UC1+K8bI+AHE4x7eTb/HVDKUcYXqxmF7X8byrgnK1ptv4EB56Gt/ol0uxoE6ct98x8 eIfBreKXwjaOg== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Yevgeny Kliteynik , Dan Carpenter Subject: [net 5/8] net/mlx5: HWS, fixed double-free in error flow of creating SQ Date: Wed, 25 Sep 2024 13:20:10 -0700 Message-ID: <20240925202013.45374-6-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Yevgeny Kliteynik When SQ creation fails, call the appropriate mlx5_core destroy function. This fixes the following smatch warnings: divers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c:739 hws_send_ring_open_sq() warn: 'sq->dep_wqe' double freed hws_send_ring_open_sq() warn: 'sq->wq_ctrl.buf.frags' double freed hws_send_ring_open_sq() warn: 'sq->wr_priv' double freed Fixes: 2ca62599aa0b ("net/mlx5: HWS, added send engine and context handling") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/e4ebc227-4b25-49bf-9e4c-14b7ea5c6a07@stanley.mountain/ Signed-off-by: Yevgeny Kliteynik Signed-off-by: Saeed Mahameed --- .../mellanox/mlx5/core/steering/hws/mlx5hws_send.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c index a1adbb48735c..0c7989184c30 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_send.c @@ -653,6 +653,12 @@ static int hws_send_ring_create_sq(struct mlx5_core_dev *mdev, u32 pdn, return err; } +static void hws_send_ring_destroy_sq(struct mlx5_core_dev *mdev, + struct mlx5hws_send_ring_sq *sq) +{ + mlx5_core_destroy_sq(mdev, sq->sqn); +} + static int hws_send_ring_set_sq_rdy(struct mlx5_core_dev *mdev, u32 sqn) { void *in, *sqc; @@ -696,7 +702,7 @@ static int hws_send_ring_create_sq_rdy(struct mlx5_core_dev *mdev, u32 pdn, err = hws_send_ring_set_sq_rdy(mdev, sq->sqn); if (err) - hws_send_ring_close_sq(sq); + hws_send_ring_destroy_sq(mdev, sq); return err; } From patchwork Wed Sep 25 20:20:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812409 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FF2F154420 for ; Wed, 25 Sep 2024 20:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295624; cv=none; b=EPPRhl15SqV5pBJGtpDH5p21orOVQcHMjAx0l+fKnvNkU5SlY4VRZy5oH8oJLpxPJ8GZOPihkMxGMG+JxoJI3F3NPUZiX5V7E4P5K4gb92H1eqZ0oPuZGcc12zTuRSMJTCVciVzhIoXYwfsdrydV6CpTxnjoKpAWY3q5ou5lTbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295624; c=relaxed/simple; bh=h5RN0PGYou2v5vLsubKxgEXrp0aHqNkuR7lcYqYnEyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A2CAVz8M43w2isb4Of4z5jwUHwxQkHdcI0Ix2FYyBGkr3K5CVE+t2f/vyKhmhXf4wwIeiyZVrmOzzk2FicDn7YksYVca0wrFOhjKDLE0NIj+XMICqNWtGlDeszIw/RjZXRtgQ/FBN6vqWBRxxSwk5I8HKvpClomEj1YPkI60UP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jbS72fY2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jbS72fY2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70FF8C4CEC3; Wed, 25 Sep 2024 20:20:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295623; bh=h5RN0PGYou2v5vLsubKxgEXrp0aHqNkuR7lcYqYnEyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbS72fY2fws6WeZqM9FnREJrxebrx2CrBuW8/vyUcL+AVs+SqnEPEZjWmMMZuP5jc rhFMCIkGd7/vk1tUEpZFJpLxpAc9FxmPAFUjc+1X1dEopVX1kjqx2bkqNWjsnfq1ti 1bxj14RxeGdCLIhC2VCzlNaf561kg0zuWNzVjhmCUs1In5c0mBTG62J8ONw9wcTEqz brwg4IrmwDmhIBOwZyjvUqM5TG19uzveVDfin9mV8ktcDqYBXCbqG6aavI+oj/BnQ+ miUBKr6tu57kqKrov93RzwASC81LUYwmOGW2zCAuFq1kwzvoV3aMAwV6mNXA6oCt/A BFnb/inHBVYkg== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Yevgeny Kliteynik , Dan Carpenter Subject: [net 6/8] net/mlx5: HWS, changed E2BIG error to a negative return code Date: Wed, 25 Sep 2024 13:20:11 -0700 Message-ID: <20240925202013.45374-7-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Yevgeny Kliteynik Fixed all the 'E2BIG' returns in error flow of functions to the negative '-E2BIG' as we are using negative error codes everywhere in HWS code. This also fixes the following smatch warnings: "warn: was negative '-E2BIG' intended?" Fixes: 74a778b4a63f ("net/mlx5: HWS, added definers handling") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/f8c77688-7d83-4937-baba-ac844dfe2e0b@stanley.mountain/ Signed-off-by: Yevgeny Kliteynik Signed-off-by: Saeed Mahameed --- .../mellanox/mlx5/core/steering/hws/mlx5hws_bwc_complex.c | 2 +- .../mellanox/mlx5/core/steering/hws/mlx5hws_definer.c | 4 ++-- .../mellanox/mlx5/core/steering/hws/mlx5hws_matcher.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc_complex.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc_complex.c index bb563f50ef09..601fad5fc54a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc_complex.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc_complex.c @@ -33,7 +33,7 @@ bool mlx5hws_bwc_match_params_is_complex(struct mlx5hws_context *ctx, * and let the usual match creation path handle it, * both for good and bad flows. */ - if (ret == E2BIG) { + if (ret == -E2BIG) { is_complex = true; mlx5hws_dbg(ctx, "Matcher definer layout: need complex matcher\n"); } else { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_definer.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_definer.c index 3bdb5c90efff..d566d2ddf424 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_definer.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_definer.c @@ -1845,7 +1845,7 @@ hws_definer_find_best_match_fit(struct mlx5hws_context *ctx, return 0; } - return E2BIG; + return -E2BIG; } static void @@ -1931,7 +1931,7 @@ mlx5hws_definer_calc_layout(struct mlx5hws_context *ctx, /* Find the match definer layout for header layout match union */ ret = hws_definer_find_best_match_fit(ctx, match_definer, match_hl); if (ret) { - if (ret == E2BIG) + if (ret == -E2BIG) mlx5hws_dbg(ctx, "Failed to create match definer from header layout - E2BIG\n"); else diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_matcher.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_matcher.c index 33d2b31e4b46..61a1155d4b4f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_matcher.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_matcher.c @@ -675,7 +675,7 @@ static int hws_matcher_bind_mt(struct mlx5hws_matcher *matcher) if (!(matcher->flags & MLX5HWS_MATCHER_FLAGS_COLLISION)) { ret = mlx5hws_definer_mt_init(ctx, matcher->mt); if (ret) { - if (ret == E2BIG) + if (ret == -E2BIG) mlx5hws_err(ctx, "Failed to set matcher templates with match definers\n"); return ret; } From patchwork Wed Sep 25 20:20:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812410 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD3D2154BEC for ; Wed, 25 Sep 2024 20:20:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295624; cv=none; b=EltkjjSbctCdWaWUln+BAVNHSyWNrkLtxmqn+VRuzdHZxG1KEteDge/pYqpcPur7Vq/J+vjoSLXNQwTlKlNva5p23ZC7tBMmj2eDXstjvBf7Fb/4bcpawJIX2od2eAaJYbWs7/lPBls+5b1TbEUpELYha199m3tnE9u5dAQ6kMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295624; c=relaxed/simple; bh=pFm1GC8xrAkDojzTiDVHxvRLgkWjSFRFm/I+GSFhVUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AyOLrmkJANk2jraoCv4ZH1ngfHZEvXk8qNhU9dWRN4MEuzB0nxd2TFdbJGQJwZ8VtOdauJc4gXlGv7VCNgS3yu/ig/0PfwqskDIoywnoF2qxAGjbxDLtwJinQapQ9HUDQA4vmCZ0XJiJGD8WBwlYXDZ7ck9WV+2P5cPTPTIzK/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kSs/0tlX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kSs/0tlX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E5E3C4CEC3; Wed, 25 Sep 2024 20:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295624; bh=pFm1GC8xrAkDojzTiDVHxvRLgkWjSFRFm/I+GSFhVUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kSs/0tlX2SXubmnGioF1S43Q21vFPY8YASCzWQzA+FACrAkpBaT7QXGQnhRARqI+h pxoYNDwJJZfVoQGuVOBRBRMAiKJhabvvSvk+jiP4+7Vgm1CrN94XfRM4MAC3hECQne av4GEXTjPJHoJNZFQNuPetmv5pugE+Du0TTzNcNJc0r6aWqI8d5bvlmMJM1A+YwR0e NPASh0ljyApmUjYNueuNlgxuharkztdIOV6/1hcceR2IxW7/rgRMGcApjaK341H+ca 6LOXShCRclsyW4QJ7vWz/rkTvxwqHimfHk/+XqQ1gnsvbLhSjwwXxTNWuwvr+VOa72 xVI9GDBbGO3BQ== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Dragos Tatulea Subject: [net 7/8] net/mlx5e: SHAMPO, Fix overflow of hd_per_wq Date: Wed, 25 Sep 2024 13:20:12 -0700 Message-ID: <20240925202013.45374-8-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Dragos Tatulea When having larger RQ sizes and small MTUs sizes, the hd_per_wq variable can overflow. Like in the following case: $> ethtool --set-ring eth1 rx 8192 $> ip link set dev eth1 mtu 144 $> ethtool --features eth1 rx-gro-hw on ... yields in dmesg: mlx5_core 0000:08:00.1: mlx5_cmd_out_err:808:(pid 194797): CREATE_MKEY(0x200) op_mod(0x0) failed, status bad parameter(0x3), syndrome (0x3bf6f), err(-22) because hd_per_wq is 64K which overflows to 0 and makes the command fail. This patch increases the variable size to 32 bit. Fixes: 99be56171fa9 ("net/mlx5e: SHAMPO, Re-enable HW-GRO") Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index da0a1c65ec4a..57b7298a0e79 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -627,7 +627,7 @@ struct mlx5e_shampo_hd { struct mlx5e_dma_info *info; struct mlx5e_frag_page *pages; u16 curr_page_index; - u16 hd_per_wq; + u32 hd_per_wq; u16 hd_per_wqe; unsigned long *bitmap; u16 pi; From patchwork Wed Sep 25 20:20:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13812411 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B87B5146A79 for ; Wed, 25 Sep 2024 20:20:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295625; cv=none; b=YySpl5ufMumoXVum82hCHEmPnfnhG064JZh3tkA/1u2JxTPxA5tuOvPsUV0rUR1kmHyOIxYpJ8TgkrMNeUeJhf27x9pr31Slpy9OlMzeP2HvvQYsThWf1A9kbOCzrThTwXc46cz7OgBX/nl11k3Qs+ucvpwAazf2wLPA9ZQvE/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727295625; c=relaxed/simple; bh=+x1hjVJ+TQq+Bm6v7O9rXkc0EbAf4umfKnCq0Rq3xA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K8O43Ke42yjyRh8etEi/eunHU329+pLG9+soIJgolYNqYuq56dgQG9I58qi3tCl8ZwiSc7suAcrJasZYGZR+6DDRvXq+uhf3I5Hu24WbdD97iKUe8TVdfWmY/yp1col68ly7IrgaK0HhyQ4wQkBqShQU7GZZzvGmDLmLBx4oyg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jooyhELy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jooyhELy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4135EC4CECF; Wed, 25 Sep 2024 20:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727295625; bh=+x1hjVJ+TQq+Bm6v7O9rXkc0EbAf4umfKnCq0Rq3xA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jooyhELyf+F42sNKV/wnXqjrU2k7HlDWC2jXH2Kb9jkC48dXdnZUjtBF+X/nxdAK2 0sT+nvniXZt2sTBPucVwTcpoeONEgdbkVpxJ+wJ6kdg8FsL+G5jWtnP1k6mxZlPVqE cZBZCi2lfaLo3xdjGYqXyH35IP/eWiGLrn6efj7VZ4e1t/hEghJqqTkF5TEcdlMKV4 RGr4Y4gNlF6yAi1cvZIiyFfktPkilEeOmVQepFZFWzNOBVzjB0xA1/g+v/yclZiRvV m2mhgFqsAysxJsm2Lgj3REIBjZfomhR+vH8mT24gcF4he9p0+XZf0vOesRP7hNytR1 XG8l/6p3ol/Eg== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Gal Pressman , Leon Romanovsky , Jianbo Liu Subject: [net 8/8] net/mlx5e: Fix crash caused by calling __xfrm_state_delete() twice Date: Wed, 25 Sep 2024 13:20:13 -0700 Message-ID: <20240925202013.45374-9-saeed@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925202013.45374-1-saeed@kernel.org> References: <20240925202013.45374-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jianbo Liu The km.state is not checked in driver's delayed work. When xfrm_state_check_expire() is called, the state can be reset to XFRM_STATE_EXPIRED, even if it is XFRM_STATE_DEAD already. This happens when xfrm state is deleted, but not freed yet. As __xfrm_state_delete() is called again in xfrm timer, the following crash occurs. To fix this issue, skip xfrm_state_check_expire() if km.state is not XFRM_STATE_VALID. Oops: general protection fault, probably for non-canonical address 0xdead000000000108: 0000 [#1] SMP CPU: 5 UID: 0 PID: 7448 Comm: kworker/u102:2 Not tainted 6.11.0-rc2+ #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Workqueue: mlx5e_ipsec: eth%d mlx5e_ipsec_handle_sw_limits [mlx5_core] RIP: 0010:__xfrm_state_delete+0x3d/0x1b0 Code: 0f 84 8b 01 00 00 48 89 fd c6 87 c8 00 00 00 05 48 8d bb 40 10 00 00 e8 11 04 1a 00 48 8b 95 b8 00 00 00 48 8b 85 c0 00 00 00 <48> 89 42 08 48 89 10 48 8b 55 10 48 b8 00 01 00 00 00 00 ad de 48 RSP: 0018:ffff88885f945ec8 EFLAGS: 00010246 RAX: dead000000000122 RBX: ffffffff82afa940 RCX: 0000000000000036 RDX: dead000000000100 RSI: 0000000000000000 RDI: ffffffff82afb980 RBP: ffff888109a20340 R08: ffff88885f945ea0 R09: 0000000000000000 R10: 0000000000000000 R11: ffff88885f945ff8 R12: 0000000000000246 R13: ffff888109a20340 R14: ffff88885f95f420 R15: ffff88885f95f400 FS: 0000000000000000(0000) GS:ffff88885f940000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2163102430 CR3: 00000001128d6001 CR4: 0000000000370eb0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: ? die_addr+0x33/0x90 ? exc_general_protection+0x1a2/0x390 ? asm_exc_general_protection+0x22/0x30 ? __xfrm_state_delete+0x3d/0x1b0 ? __xfrm_state_delete+0x2f/0x1b0 xfrm_timer_handler+0x174/0x350 ? __xfrm_state_delete+0x1b0/0x1b0 __hrtimer_run_queues+0x121/0x270 hrtimer_run_softirq+0x88/0xd0 handle_softirqs+0xcc/0x270 do_softirq+0x3c/0x50 __local_bh_enable_ip+0x47/0x50 mlx5e_ipsec_handle_sw_limits+0x7d/0x90 [mlx5_core] process_one_work+0x137/0x2d0 worker_thread+0x28d/0x3a0 ? rescuer_thread+0x480/0x480 kthread+0xb8/0xe0 ? kthread_park+0x80/0x80 ret_from_fork+0x2d/0x50 ? kthread_park+0x80/0x80 ret_from_fork_asm+0x11/0x20 Fixes: b2f7b01d36a9 ("net/mlx5e: Simulate missing IPsec TX limits hardware functionality") Signed-off-by: Jianbo Liu Reviewed-by: Leon Romanovsky Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c index 3d274599015b..ca92e518be76 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c @@ -67,7 +67,6 @@ static void mlx5e_ipsec_handle_sw_limits(struct work_struct *_work) return; spin_lock_bh(&x->lock); - xfrm_state_check_expire(x); if (x->km.state == XFRM_STATE_EXPIRED) { sa_entry->attrs.drop = true; spin_unlock_bh(&x->lock); @@ -75,6 +74,13 @@ static void mlx5e_ipsec_handle_sw_limits(struct work_struct *_work) mlx5e_accel_ipsec_fs_modify(sa_entry); return; } + + if (x->km.state != XFRM_STATE_VALID) { + spin_unlock_bh(&x->lock); + return; + } + + xfrm_state_check_expire(x); spin_unlock_bh(&x->lock); queue_delayed_work(sa_entry->ipsec->wq, &dwork->dwork,