Skip to content

Commit 0bf476f

Browse files
robhancockseddavem330
authored andcommitted
net: macb: Fix lost RX packet wakeup race in NAPI receive
There is an oddity in the way the RSR register flags propagate to the ISR register (and the actual interrupt output) on this hardware: it appears that RSR register bits only result in ISR being asserted if the interrupt was actually enabled at the time, so enabling interrupts with RSR bits already set doesn't trigger an interrupt to be raised. There was already a partial fix for this race in the macb_poll function where it checked for RSR bits being set and re-triggered NAPI receive. However, there was a still a race window between checking RSR and actually enabling interrupts, where a lost wakeup could happen. It's necessary to check again after enabling interrupts to see if RSR was set just prior to the interrupt being enabled, and re-trigger receive in that case. This issue was noticed in a point-to-point UDP request-response protocol which periodically saw timeouts or abnormally high response times due to received packets not being processed in a timely fashion. In many applications, more packets arriving, including TCP retransmissions, would cause the original packet to be processed, thus masking the issue. Fixes: 02f7a34 ("net: macb: Re-enable RX interrupt only when RX is done") Cc: [email protected] Co-developed-by: Scott McNutt <[email protected]> Signed-off-by: Scott McNutt <[email protected]> Signed-off-by: Robert Hancock <[email protected]> Tested-by: Claudiu Beznea <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9f3956d commit 0bf476f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,14 +1573,37 @@ static int macb_poll(struct napi_struct *napi, int budget)
15731573
if (work_done < budget) {
15741574
napi_complete_done(napi, work_done);
15751575

1576-
/* Packets received while interrupts were disabled */
1576+
/* RSR bits only seem to propagate to raise interrupts when
1577+
* interrupts are enabled at the time, so if bits are already
1578+
* set due to packets received while interrupts were disabled,
1579+
* they will not cause another interrupt to be generated when
1580+
* interrupts are re-enabled.
1581+
* Check for this case here. This has been seen to happen
1582+
* around 30% of the time under heavy network load.
1583+
*/
15771584
status = macb_readl(bp, RSR);
15781585
if (status) {
15791586
if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
15801587
queue_writel(queue, ISR, MACB_BIT(RCOMP));
15811588
napi_reschedule(napi);
15821589
} else {
15831590
queue_writel(queue, IER, bp->rx_intr_mask);
1591+
1592+
/* In rare cases, packets could have been received in
1593+
* the window between the check above and re-enabling
1594+
* interrupts. Therefore, a double-check is required
1595+
* to avoid losing a wakeup. This can potentially race
1596+
* with the interrupt handler doing the same actions
1597+
* if an interrupt is raised just after enabling them,
1598+
* but this should be harmless.
1599+
*/
1600+
status = macb_readl(bp, RSR);
1601+
if (unlikely(status)) {
1602+
queue_writel(queue, IDR, bp->rx_intr_mask);
1603+
if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
1604+
queue_writel(queue, ISR, MACB_BIT(RCOMP));
1605+
napi_schedule(napi);
1606+
}
15841607
}
15851608
}
15861609

0 commit comments

Comments
 (0)