sfc: Use acquire/release for irq_soft_enabled
Subsystems (3)
PATCH v2 1/1 sfc: Use acquire/release for irq_soft_enabled
irq_soft_enabled is a lockless gate for interrupt handlers. When it is false, handlers acknowledge interrupts but must not touch channel state.
Channel reallocation disables the gate, swaps and initializes channel pointers, frees old channels, and then enables the gate again. Once a handler observes irq_soft_enabled as true, it can dereference efx->channel[] and other channel state. That observation must therefore be ordered after the channel state was published.
READ_ONCE() does not provide that acquire ordering. The existing smp_wmb() in the soft-enable paths also cannot provide it because it is after the irq_soft_enabled=true store, so it cannot publish prior channel state before the gate becomes visible.
Use a release store only when opening the software IRQ gate, and use acquire loads in interrupt handlers before touching channels. Use WRITE_ONCE() when closing the gate; handlers that observe false do not touch channel state.
Keep the existing smp_wmb() after gate updates. It preserves the previous ordering between the software IRQ gate and subsequent event queue setup, start and stop operations, which is separate from the release/acquire ordering added here.
---
v2:
- Use release ordering only when enabling the software IRQ gate.
- Use WRITE_ONCE() when disabling it.
- Expand the commit message to address review comments from Jakub Kicinski and Edward Cree about the release pairing and the existing smp_wmb().
v1: https://lore.kernel.org/netdev/[email protected]/
--- drivers/net/ethernet/sfc/ef10.c | 4 ++-- drivers/net/ethernet/sfc/ef100_nic.c | 2 +- drivers/net/ethernet/sfc/efx_channels.c | 4 ++-- drivers/net/ethernet/sfc/falcon/efx.c | 4 ++-- drivers/net/ethernet/sfc/falcon/falcon.c | 2 +- drivers/net/ethernet/sfc/falcon/farch.c | 4 ++-- drivers/net/ethernet/sfc/falcon/net_driver.h | 17 +++++++++++++++++ drivers/net/ethernet/sfc/net_driver.h | 17 +++++++++++++++++ drivers/net/ethernet/sfc/siena/efx_channels.c | 4 ++-- drivers/net/ethernet/sfc/siena/farch.c | 4 ++-- drivers/net/ethernet/sfc/siena/net_driver.h | 17 +++++++++++++++++ 11 files changed, 65 insertions(+), 14 deletions(-)
drivers/net/ethernet/sfc/ef10.c +2 -2
@@ -2143,7 +2143,7 @@ static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)netif_vdbg (efx, intr, efx->net_dev,"IRQ %d on CPU %d\n" , irq,raw_smp_processor_id ()); -if (likely (READ_ONCE (efx->irq_soft_enabled))) { +if (likely (efx_irq_soft_enabled (efx))) {/* Note test interrupts */ if (context->index == efx->irq_level) efx->last_irq_cpu =raw_smp_processor_id ();
@@ -2158,7 +2158,7 @@ static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)static irqreturn_t efx_ef10_legacy_interrupt (int irq,void *dev_id) {struct efx_nic *efx = dev_id; -bool soft_enabled =READ_ONCE (efx->irq_soft_enabled); +bool soft_enabled =efx_irq_soft_enabled (efx);struct efx_channel *channel;efx_dword_t reg;u32 queues;
drivers/net/ethernet/sfc/ef100_nic.c +1 -1
@@ -333,7 +333,7 @@ static irqreturn_t ef100_msi_interrupt(int irq, void *dev_id)netif_vdbg (efx, intr, efx->net_dev,"IRQ %d on CPU %d\n" , irq,raw_smp_processor_id ()); -if (likely (READ_ONCE (efx->irq_soft_enabled))) { +if (likely (efx_irq_soft_enabled (efx))) {/* Note test interrupts */ if (context->index == efx->irq_level) efx->last_irq_cpu =raw_smp_processor_id ();
drivers/net/ethernet/sfc/efx_channels.c +2 -2
@@ -972,7 +972,7 @@ int efx_soft_enable_interrupts(struct efx_nic *efx)BUG_ON (efx->state ==STATE_DISABLED ); - efx->irq_soft_enabled = true; +efx_irq_soft_enable (efx);smp_wmb ();efx_for_each_channel (channel, efx) {
@@ -1009,7 +1009,7 @@ void efx_soft_disable_interrupts(struct efx_nic *efx)efx_mcdi_mode_poll (efx); - efx->irq_soft_enabled = false; +efx_irq_soft_disable (efx);smp_wmb ();if (efx->legacy_irq)
drivers/net/ethernet/sfc/falcon/efx.c +2 -2
@@ -1460,7 +1460,7 @@ static int ef4_soft_enable_interrupts(struct ef4_nic *efx)BUG_ON (efx->state ==STATE_DISABLED ); - efx->irq_soft_enabled = true; +ef4_irq_soft_enable (efx);smp_wmb ();ef4_for_each_channel (channel, efx) {
@@ -1493,7 +1493,7 @@ static void ef4_soft_disable_interrupts(struct ef4_nic *efx)if (efx->state ==STATE_DISABLED )return ; - efx->irq_soft_enabled = false; +ef4_irq_soft_disable (efx);smp_wmb ();if (efx->legacy_irq)
drivers/net/ethernet/sfc/falcon/falcon.c +1 -1
@@ -449,7 +449,7 @@ static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)"IRQ %d on CPU %d status " EF4_OWORD_FMT "\n" , irq, raw_smp_processor_id(), EF4_OWORD_VAL(*int_ker)); -if (!likely (READ_ONCE (efx->irq_soft_enabled))) +if (!likely (ef4_irq_soft_enabled (efx)))return IRQ_HANDLED ;/* Check to see if we have a serious error condition */
drivers/net/ethernet/sfc/falcon/farch.c +2 -2
@@ -1500,7 +1500,7 @@ irqreturn_t ef4_farch_fatal_interrupt(struct ef4_nic *efx)irqreturn_t ef4_farch_legacy_interrupt (int irq,void *dev_id) {struct ef4_nic *efx = dev_id; -bool soft_enabled =READ_ONCE (efx->irq_soft_enabled); +bool soft_enabled =ef4_irq_soft_enabled (efx);ef4_oword_t *int_ker = efx->irq_status.addr;irqreturn_t result =IRQ_NONE ;struct ef4_channel *channel;
@@ -1592,7 +1592,7 @@ irqreturn_t ef4_farch_msi_interrupt(int irq, void *dev_id)"IRQ %d on CPU %d status " EF4_OWORD_FMT "\n" , irq, raw_smp_processor_id(), EF4_OWORD_VAL(*int_ker)); -if (!likely (READ_ONCE (efx->irq_soft_enabled))) +if (!likely (ef4_irq_soft_enabled (efx)))return IRQ_HANDLED ;/* Handle non-event-queue sources */
drivers/net/ethernet/sfc/falcon/net_driver.h +17 -0
@@ -1305,6 +1305,23 @@ static inline netdev_features_t ef4_supported_features(const struct ef4_nic *efxreturn net_dev->features | net_dev->hw_features; } +static inline void ef4_irq_soft_enable (struct ef4_nic *efx) +{ +/* Publish channel state before opening the IRQ handler gate. */ +smp_store_release (&efx->irq_soft_enabled, true); +} + +static inline void ef4_irq_soft_disable (struct ef4_nic *efx) +{ +WRITE_ONCE (efx->irq_soft_enabled, false); +} + +static inline bool ef4_irq_soft_enabled (struct ef4_nic *efx) +{ +/* Pair with ef4_irq_soft_enable() before touching channels. */ +return smp_load_acquire (&efx->irq_soft_enabled); +} +/* Get the current TX queue insert index. */ static inline unsigned int ef4_tx_queue_get_insert_index (const struct ef4_tx_queue *tx_queue)
drivers/net/ethernet/sfc/net_driver.h +17 -0
@@ -1731,6 +1731,23 @@ static inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; } +static inline void efx_irq_soft_enable (struct efx_nic *efx) +{ +/* Publish channel state before opening the IRQ handler gate. */ +smp_store_release (&efx->irq_soft_enabled, true); +} + +static inline void efx_irq_soft_disable (struct efx_nic *efx) +{ +WRITE_ONCE (efx->irq_soft_enabled, false); +} + +static inline bool efx_irq_soft_enabled (struct efx_nic *efx) +{ +/* Pair with efx_irq_soft_enable() before touching channels. */ +return smp_load_acquire (&efx->irq_soft_enabled); +} +/* Get the max fill level of the TX queues on this channel */ static inline unsigned int efx_channel_tx_fill_level (struct efx_channel *channel)
drivers/net/ethernet/sfc/siena/efx_channels.c +2 -2
@@ -1004,7 +1004,7 @@ static int efx_soft_enable_interrupts(struct efx_nic *efx)BUG_ON (efx->state ==STATE_DISABLED ); - efx->irq_soft_enabled = true; +efx_irq_soft_enable (efx);smp_wmb ();efx_for_each_channel (channel, efx) {
@@ -1041,7 +1041,7 @@ static void efx_soft_disable_interrupts(struct efx_nic *efx)efx_siena_mcdi_mode_poll (efx); - efx->irq_soft_enabled = false; +efx_irq_soft_disable (efx);smp_wmb ();if (efx->legacy_irq)
drivers/net/ethernet/sfc/siena/farch.c +2 -2
@@ -1514,7 +1514,7 @@ irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx)irqreturn_t efx_farch_legacy_interrupt (int irq,void *dev_id) {struct efx_nic *efx = dev_id; -bool soft_enabled =READ_ONCE (efx->irq_soft_enabled); +bool soft_enabled =efx_irq_soft_enabled (efx);efx_oword_t *int_ker = efx->irq_status.addr;irqreturn_t result =IRQ_NONE ;struct efx_channel *channel;
@@ -1606,7 +1606,7 @@ irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id)"IRQ %d on CPU %d status " EFX_OWORD_FMT "\n" , irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker)); -if (!likely (READ_ONCE (efx->irq_soft_enabled))) +if (!likely (efx_irq_soft_enabled (efx)))return IRQ_HANDLED ;/* Handle non-event-queue sources */
drivers/net/ethernet/sfc/siena/net_driver.h +17 -0
@@ -1624,6 +1624,23 @@ static inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; } +static inline void efx_irq_soft_enable (struct efx_nic *efx) +{ +/* Publish channel state before opening the IRQ handler gate. */ +smp_store_release (&efx->irq_soft_enabled, true); +} + +static inline void efx_irq_soft_disable (struct efx_nic *efx) +{ +WRITE_ONCE (efx->irq_soft_enabled, false); +} + +static inline bool efx_irq_soft_enabled (struct efx_nic *efx) +{ +/* Pair with efx_irq_soft_enable() before touching channels. */ +return smp_load_acquire (&efx->irq_soft_enabled); +} +/* Get the max fill level of the TX queues on this channel */ static inline unsigned int efx_channel_tx_fill_level (struct efx_channel *channel)
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 1 line · On Thu, 18 Jun 2026 17:16:18 +0800 Gui-Dong Han wrote:
Subject: [PATCH net v2] sfc: Use acquire/release for
irq_soft_enabled
Sorry, I'm not applying driver memory barrier ordering changes of this complexity because some static analyzer thinks it's wrong. Please don't repost this unless someone from solarflare asks you to.