In rtw_sdio_handle_interrupt(), the HISR status register is cleared using Write-1-to-Clear (W1C) semantics. However, the driver masks out the REG_SDIO_HISR_RX_REQUEST bit in the local 'hisr' variable before writing it back, causing a 0 to be written to that bit. This prevents the RX request interrupt from being acknowledged and cleared in hardware, trapping the CPU core in an infinite interrupt storm loop (starving the RCU preempt kthread and locking up the system). Masking out the bit in software was originally intended to allow budget-limited polling without losing interrupts. However, because the status register was never acknowledged, the hardware interrupt line remained asserted continuously. Resolve this by adopting the standard interrupt masking pattern: 1. Mask interrupts via rtw_sdio_disable_interrupt(rtwdev) upon entry. 2. Acknowledge pending status bits via rtw_write32(rtwdev, REG_SDIO_HISR, hisr) without clearing REG_SDIO_HISR_RX_REQUEST from the writeback mask. 3. Service the pending interrupt events (rtw_sdio_rx_isr). 4. Re-enable interrupts via rtw_sdio_enable_interrupt(rtwdev). Any packet arriving over the air while interrupts are masked latches REG_SDIO_HISR_RX_REQUEST in hardware. Unmasking HIMR restores the interrupt mask and immediately re-asserts the SDIO interrupt line (DAT[1]), causing ksdioirqd to run another pass and drain the new packets. Fixes: 65371a3f14e7 ("wifi: rtw88: sdio: Add HCI implementation for SDIO based chipsets") Cc: stable@vger.kernel.org Signed-off-by: Alastair D'Silva --- v2: - Drop the complex drain-and-recheck inside rtw_sdio_rx_isr() and budget bypass logic from v1. - Implement clean HIMR masking (rtw_sdio_disable_interrupt() on entry, rtw_sdio_enable_interrupt() on exit), matching the PCI driver model as suggested by Ping-Ke Shih and the Realtek internal team. - Verified on physical RTL8821CS hardware (Allwinner H618 / Mellow Fly-C5). Empirical Testbed & Timing Measurements: ---------------------------------------- To address concerns regarding bus overhead and packet loss during the masked window, rtw_sdio_handle_interrupt() was instrumented with nanosecond ktime timestamps on an Allwinner H618 board with RTL8821CS SDIO Wi-Fi under continuous saturation traffic (38.0 Mbps TCP / 34.4 Mbps UDP with 0% loss): 1. Bus Overhead (average over 18,660 interrupts): - Disable HIMR: 13.88 us (min: 10.00 us, max: 74.83 us) - Acknowledge HISR: 13.69 us (min: 8.91 us, max: 39.33 us) - RX ISR work: 204.78 us (min: 48.66 us, max: 5.07 ms) - Enable HIMR: 14.46 us (min: 9.54 us, max: 52.79 us) - Total ISR time: 280.32 us Toggling HIMR accounts for ~28.35 us (~10% of total ISR duration) and is negligible compared to payload data transfers over SDIO. 2. Hardware Latching & No FIFO Stall: - In 1,251 out of 18,660 interrupts (6.7%), new packets arrived over the air while interrupts were masked during FIFO drainage. - Reading REG_SDIO_HISR immediately prior to unmasking confirmed that REG_SDIO_HISR_RX_REQUEST was latched in hardware in every instance. - Unmasking HIMR immediately re-asserted DAT[1], causing ksdioirqd to service the newly arrived packets. Zero packets were left stuck in FIFO. - Injecting artificial delays up to 2000 us before unmasking increased masked arrivals to 16.4% while maintaining 0% extra packet loss and zero stalls. drivers/net/wireless/realtek/rtw88/sdio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index 5b40d74b16ee..ff707f207a83 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -1087,16 +1087,21 @@ static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func) rtwsdio->irq_thread = current; hisr = rtw_read32(rtwdev, REG_SDIO_HISR); + if (!hisr) + goto out; + + rtw_sdio_disable_interrupt(rtwdev); + rtw_write32(rtwdev, REG_SDIO_HISR, hisr); if (hisr & REG_SDIO_HISR_TXERR) rtw_sdio_tx_err_isr(rtwdev); - if (hisr & REG_SDIO_HISR_RX_REQUEST) { - hisr &= ~REG_SDIO_HISR_RX_REQUEST; + if (hisr & REG_SDIO_HISR_RX_REQUEST) rtw_sdio_rx_isr(rtwdev); - } - rtw_write32(rtwdev, REG_SDIO_HISR, hisr); + /* Unmasking HIMR re-asserts the IRQ line if new packets arrived */ + rtw_sdio_enable_interrupt(rtwdev); +out: rtwsdio->irq_thread = NULL; } -- 2.53.0