All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/3] bnxt_en: Bug fixes.
@ 2021-09-12 16:34 Michael Chan
  2021-09-12 16:34 ` [PATCH net 1/3] bnxt_en: Fix error recovery regression Michael Chan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michael Chan @ 2021-09-12 16:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, kuba, edwin.peer, gospo

[-- Attachment #1: Type: text/plain, Size: 533 bytes --]

The first patch fixes an error recovery regression just introduced
about a week ago.  The other two patches fix issues related to
freeing rings in the bnxt_close() path under error conditions.

Edwin Peer (1):
  bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem()

Michael Chan (2):
  bnxt_en: Fix error recovery regression
  bnxt_en: Clean up completion ring page arrays completely

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 33 ++++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)

-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

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

* [PATCH net 1/3] bnxt_en: Fix error recovery regression
  2021-09-12 16:34 [PATCH net 0/3] bnxt_en: Bug fixes Michael Chan
@ 2021-09-12 16:34 ` Michael Chan
  2021-09-12 16:34 ` [PATCH net 2/3] bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem() Michael Chan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Chan @ 2021-09-12 16:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, kuba, edwin.peer, gospo

[-- Attachment #1: Type: text/plain, Size: 2286 bytes --]

The recent patch has introduced a regression by not reading the reset
count in the ERROR_RECOVERY async event handler.  We may have just
gone through a reset and the reset count has just incremented.  If
we don't update the reset count in the ERROR_RECOVERY event handler,
the health check timer will see that the reset count has changed and
will initiate an unintended reset.

Restore the unconditional update of the reset count in
bnxt_async_event_process() if error recovery watchdog is enabled.
Also, update the reset count at the end of the reset sequence to
make it even more robust.

Fixes: 1b2b91831983 ("bnxt_en: Fix possible unintended driver initiated error recovery")
Reviewed-by: Edwin Peer <edwin.peer@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 9b86516e59a1..8b0a2ae1367c 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -2213,12 +2213,11 @@ static int bnxt_async_event_process(struct bnxt *bp,
 			DIV_ROUND_UP(fw_health->polling_dsecs * HZ,
 				     bp->current_interval * 10);
 		fw_health->tmr_counter = fw_health->tmr_multiplier;
-		if (!fw_health->enabled) {
+		if (!fw_health->enabled)
 			fw_health->last_fw_heartbeat =
 				bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
-			fw_health->last_fw_reset_cnt =
-				bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
-		}
+		fw_health->last_fw_reset_cnt =
+			bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
 		netif_info(bp, drv, bp->dev,
 			   "Error recovery info: error recovery[1], master[%d], reset count[%u], health status: 0x%x\n",
 			   fw_health->master, fw_health->last_fw_reset_cnt,
@@ -12207,6 +12206,11 @@ static void bnxt_fw_reset_task(struct work_struct *work)
 			return;
 		}
 
+		if ((bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY) &&
+		    bp->fw_health->enabled) {
+			bp->fw_health->last_fw_reset_cnt =
+				bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
+		}
 		bp->fw_reset_state = 0;
 		/* Make sure fw_reset_state is 0 before clearing the flag */
 		smp_mb__before_atomic();
-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

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

* [PATCH net 2/3] bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem()
  2021-09-12 16:34 [PATCH net 0/3] bnxt_en: Bug fixes Michael Chan
  2021-09-12 16:34 ` [PATCH net 1/3] bnxt_en: Fix error recovery regression Michael Chan
@ 2021-09-12 16:34 ` Michael Chan
  2021-09-12 16:34 ` [PATCH net 3/3] bnxt_en: Clean up completion ring page arrays completely Michael Chan
  2021-09-13 11:40 ` [PATCH net 0/3] bnxt_en: Bug fixes patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Chan @ 2021-09-12 16:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, kuba, edwin.peer, gospo

[-- Attachment #1: Type: text/plain, Size: 2389 bytes --]

From: Edwin Peer <edwin.peer@broadcom.com>

The call to bnxt_free_mem(..., false) in the bnxt_half_open_nic() error
path will deallocate ring descriptor memory via bnxt_free_?x_rings(),
but because irq_re_init is false, the ring info itself is not freed.

To simplify error paths, deallocation functions have generally been
written to be safe when called on unallocated memory. It should always
be safe to call dev_close(), which calls bnxt_free_skbs() a second time,
even in this semi- allocated ring state.

Calling bnxt_free_skbs() a second time with the rings already freed will
cause NULL pointer dereference.  Fix it by checking the rings are valid
before proceeding in bnxt_free_tx_skbs() and
bnxt_free_one_rx_ring_skbs().

Fixes: 975bc99a4a39 ("bnxt_en: Refactor bnxt_free_rx_skbs().")
Signed-off-by: Edwin Peer <edwin.peer@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 8b0a2ae1367c..9f9806f1c0fc 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -2729,6 +2729,9 @@ static void bnxt_free_tx_skbs(struct bnxt *bp)
 		struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
 		int j;
 
+		if (!txr->tx_buf_ring)
+			continue;
+
 		for (j = 0; j < max_idx;) {
 			struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
 			struct sk_buff *skb;
@@ -2813,6 +2816,9 @@ static void bnxt_free_one_rx_ring_skbs(struct bnxt *bp, int ring_nr)
 	}
 
 skip_rx_tpa_free:
+	if (!rxr->rx_buf_ring)
+		goto skip_rx_buf_free;
+
 	for (i = 0; i < max_idx; i++) {
 		struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[i];
 		dma_addr_t mapping = rx_buf->mapping;
@@ -2835,6 +2841,11 @@ static void bnxt_free_one_rx_ring_skbs(struct bnxt *bp, int ring_nr)
 			kfree(data);
 		}
 	}
+
+skip_rx_buf_free:
+	if (!rxr->rx_agg_ring)
+		goto skip_rx_agg_free;
+
 	for (i = 0; i < max_agg_idx; i++) {
 		struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
 		struct page *page = rx_agg_buf->page;
@@ -2851,6 +2862,8 @@ static void bnxt_free_one_rx_ring_skbs(struct bnxt *bp, int ring_nr)
 
 		__free_page(page);
 	}
+
+skip_rx_agg_free:
 	if (rxr->rx_page) {
 		__free_page(rxr->rx_page);
 		rxr->rx_page = NULL;
-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

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

* [PATCH net 3/3] bnxt_en: Clean up completion ring page arrays completely
  2021-09-12 16:34 [PATCH net 0/3] bnxt_en: Bug fixes Michael Chan
  2021-09-12 16:34 ` [PATCH net 1/3] bnxt_en: Fix error recovery regression Michael Chan
  2021-09-12 16:34 ` [PATCH net 2/3] bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem() Michael Chan
@ 2021-09-12 16:34 ` Michael Chan
  2021-09-13 11:40 ` [PATCH net 0/3] bnxt_en: Bug fixes patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Chan @ 2021-09-12 16:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, kuba, edwin.peer, gospo

[-- Attachment #1: Type: text/plain, Size: 2022 bytes --]

We recently changed the completion ring page arrays to be dynamically
allocated to better support the expanded range of ring depths.  The
cleanup path for this was not quite complete.  It might cause the
shutdown path to crash if we need to abort before the completion ring
arrays have been allocated and initialized.

Fix it by initializing the ring_mem->pg_arr to NULL after freeing the
completion ring page array.  Add a check in bnxt_free_ring() to skip
referencing the rmem->pg_arr if it is NULL.

Fixes: 03c7448790b8 ("bnxt_en: Don't use static arrays for completion ring pages")
Reviewed-by: Andy Gospodarek <gospo@broadcom.com>
Reviewed-by: Edwin Peer <edwin.peer@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 9f9806f1c0fc..f32431a7e5a6 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -2912,6 +2912,9 @@ static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
 	struct pci_dev *pdev = bp->pdev;
 	int i;
 
+	if (!rmem->pg_arr)
+		goto skip_pages;
+
 	for (i = 0; i < rmem->nr_pages; i++) {
 		if (!rmem->pg_arr[i])
 			continue;
@@ -2921,6 +2924,7 @@ static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
 
 		rmem->pg_arr[i] = NULL;
 	}
+skip_pages:
 	if (rmem->pg_tbl) {
 		size_t pg_tbl_size = rmem->nr_pages * 8;
 
@@ -3240,10 +3244,14 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)
 
 static void bnxt_free_cp_arrays(struct bnxt_cp_ring_info *cpr)
 {
+	struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
+
 	kfree(cpr->cp_desc_ring);
 	cpr->cp_desc_ring = NULL;
+	ring->ring_mem.pg_arr = NULL;
 	kfree(cpr->cp_desc_mapping);
 	cpr->cp_desc_mapping = NULL;
+	ring->ring_mem.dma_arr = NULL;
 }
 
 static int bnxt_alloc_cp_arrays(struct bnxt_cp_ring_info *cpr, int n)
-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

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

* Re: [PATCH net 0/3] bnxt_en: Bug fixes.
  2021-09-12 16:34 [PATCH net 0/3] bnxt_en: Bug fixes Michael Chan
                   ` (2 preceding siblings ...)
  2021-09-12 16:34 ` [PATCH net 3/3] bnxt_en: Clean up completion ring page arrays completely Michael Chan
@ 2021-09-13 11:40 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-09-13 11:40 UTC (permalink / raw)
  To: Michael Chan; +Cc: davem, netdev, kuba, edwin.peer, gospo

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Sun, 12 Sep 2021 12:34:46 -0400 you wrote:
> The first patch fixes an error recovery regression just introduced
> about a week ago.  The other two patches fix issues related to
> freeing rings in the bnxt_close() path under error conditions.
> 
> Edwin Peer (1):
>   bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem()
> 
> [...]

Here is the summary with links:
  - [net,1/3] bnxt_en: Fix error recovery regression
    https://git.kernel.org/netdev/net/c/eca4cf12acda
  - [net,2/3] bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem()
    https://git.kernel.org/netdev/net/c/1affc01fdc60
  - [net,3/3] bnxt_en: Clean up completion ring page arrays completely
    https://git.kernel.org/netdev/net/c/985941e1dd5e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-09-13 11:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12 16:34 [PATCH net 0/3] bnxt_en: Bug fixes Michael Chan
2021-09-12 16:34 ` [PATCH net 1/3] bnxt_en: Fix error recovery regression Michael Chan
2021-09-12 16:34 ` [PATCH net 2/3] bnxt_en: make bnxt_free_skbs() safe to call after bnxt_free_mem() Michael Chan
2021-09-12 16:34 ` [PATCH net 3/3] bnxt_en: Clean up completion ring page arrays completely Michael Chan
2021-09-13 11:40 ` [PATCH net 0/3] bnxt_en: Bug fixes patchwork-bot+netdevbpf

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.