All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net, michael.chan@broadcom.com
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org,
	pavan.chebbi@broadcom.com, bjorn@kernel.org, joe@dama.to,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 1/7] eth: bnxt_en: order event data before setting the sp_event bit
Date: Thu, 19 Nov 2026 19:52:08 -0800	[thread overview]
Message-ID: <20261120035214.369158-2-kuba@kernel.org> (raw)
In-Reply-To: <20261120035214.369158-1-kuba@kernel.org>

Producers of sp_events may store data for bnxt_sp_task() right before
raising the event, e.g. the IRQ affinity notifier publishes the new
TPH Steering Tag, the async event handler records the FW echo request
data or the FW reset wait limits. set_bit() is not ordered, so on
weakly ordered architectures the event bit may become visible first.
If bnxt_sp_task() is already running it can consume the event and
read the stale data. The queue_work() which follows only re-runs
the task with the event bit already cleared, so the update is lost.

Add a helper which issues smp_mb__before_atomic() before setting
the bit, it pairs with the fully ordered test_and_clear_bit() in
bnxt_sp_task(). Use it for all events, including those which carry
no data, so that new producers don't have to think about it.

Reported by an LLM reviewer while working on subsequent patches.
Very unlikely to matter in practice.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
 - convert the producers which set the bit directly (Björn)
v1: https://lore.kernel.org/20261118023905.3050661-2-kuba@kernel.org
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 33 ++++++++++++++---------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 52606db3f7b4..9ddd75a0fd2f 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -392,9 +392,18 @@ static void __bnxt_queue_sp_work(struct bnxt *bp)
 		schedule_work(&bp->sp_task);
 }
 
+static void bnxt_set_sp_event(struct bnxt *bp, unsigned int event)
+{
+	/* Make the data the event carries visible before the event bit,
+	 * pairs with test_and_clear_bit() in bnxt_sp_task().
+	 */
+	smp_mb__before_atomic();
+	set_bit(event, &bp->sp_event);
+}
+
 static void bnxt_queue_sp_work(struct bnxt *bp, unsigned int event)
 {
-	set_bit(event, &bp->sp_event);
+	bnxt_set_sp_event(bp, event);
 	__bnxt_queue_sp_work(bp);
 }
 
@@ -403,9 +412,9 @@ static void bnxt_sched_reset_rxr(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
 	if (!rxr->bnapi->in_reset) {
 		rxr->bnapi->in_reset = true;
 		if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
-			set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
+			bnxt_set_sp_event(bp, BNXT_RESET_TASK_SP_EVENT);
 		else
-			set_bit(BNXT_RST_RING_SP_EVENT, &bp->sp_event);
+			bnxt_set_sp_event(bp, BNXT_RST_RING_SP_EVENT);
 		__bnxt_queue_sp_work(bp);
 	}
 	rxr->rx_next_cons = 0xffff;
@@ -2751,7 +2760,7 @@ static bool bnxt_event_error_report(struct bnxt *bp, u32 data1, u32 data2)
 			    BNXT_EVENT_THERMAL_THRESHOLD_TEMP(data2));
 		if (notify) {
 			bp->thermal_threshold_type = type;
-			set_bit(BNXT_THERMAL_THRESHOLD_SP_EVENT, &bp->sp_event);
+			bnxt_set_sp_event(bp, BNXT_THERMAL_THRESHOLD_SP_EVENT);
 			return true;
 		}
 		return false;
@@ -2817,18 +2826,18 @@ static int bnxt_async_event_process(struct bnxt *bp,
 				netdev_warn(bp->dev, "Link speed %d no longer supported\n",
 					    speed);
 		}
-		set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_LINK_SPEED_CHNG_SP_EVENT);
 	}
 		fallthrough;
 	case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
 	case ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE:
-		set_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_LINK_CFG_CHANGE_SP_EVENT);
 		fallthrough;
 	case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
-		set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_LINK_CHNG_SP_EVENT);
 		break;
 	case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
-		set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_HWRM_PF_UNLOAD_SP_EVENT);
 		break;
 	case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
 		u16 port_id = BNXT_GET_EVENT_PORT(data1);
@@ -2839,13 +2848,13 @@ static int bnxt_async_event_process(struct bnxt *bp,
 		if (bp->pf.port_id != port_id)
 			break;
 
-		set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_HWRM_PORT_MODULE_SP_EVENT);
 		break;
 	}
 	case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
 		if (BNXT_PF(bp))
 			goto async_event_process_exit;
-		set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_RESET_TASK_SILENT_SP_EVENT);
 		break;
 	case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY: {
 		char *type_str = "Solicited";
@@ -2877,7 +2886,7 @@ static int bnxt_async_event_process(struct bnxt *bp,
 			   type_str, data1, data2,
 			   bp->fw_reset_min_dsecs * 100,
 			   bp->fw_reset_max_dsecs * 100);
-		set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event);
+		bnxt_set_sp_event(bp, BNXT_FW_RESET_NOTIFY_SP_EVENT);
 		break;
 	}
 	case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY: {
@@ -2955,7 +2964,7 @@ static int bnxt_async_event_process(struct bnxt *bp,
 		if (fw_health) {
 			fw_health->echo_req_data1 = data1;
 			fw_health->echo_req_data2 = data2;
-			set_bit(BNXT_FW_ECHO_REQUEST_SP_EVENT, &bp->sp_event);
+			bnxt_set_sp_event(bp, BNXT_FW_ECHO_REQUEST_SP_EVENT);
 			break;
 		}
 		goto async_event_process_exit;
-- 
2.56.1


  reply	other threads:[~2026-11-20  3:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  3:52 [PATCH net-next v2 0/7] eth: bnxt_en: allocate memory on the right NUMA node Jakub Kicinski
2026-11-20  3:52 ` Jakub Kicinski [this message]
2026-11-20  3:52 ` [PATCH net-next v2 2/7] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool Jakub Kicinski
2026-11-20  3:52 ` [PATCH net-next v2 3/7] eth: bnxt_en: allocate per-queue SW state on the queue's NUMA node Jakub Kicinski
2026-11-20  3:52 ` [PATCH net-next v2 4/7] eth: bnxt_en: explicitly keep device-only memory on the device's node Jakub Kicinski
2026-11-20  3:52 ` [PATCH net-next v2 5/7] eth: bnxt_en: allocate fast path DMA rings on the queue's NUMA node Jakub Kicinski
2026-11-20  3:52 ` [PATCH net-next v2 6/7] eth: bnxt_en: add a local bp variable in the IRQ affinity notifier Jakub Kicinski
2026-11-20  3:52 ` [PATCH net-next v2 7/7] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node Jakub Kicinski

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=20261120035214.369158-2-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=bjorn@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=joe@dama.to \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.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 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.