Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] On 32-bit direct-window DMA addresses, the new helpers drop
all Bridge DMA attributes, and nothing provides them another way.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is in
ioc3_init(), the function the patch changes.
--
net: sgi: ioc3-eth: apply the DMA attributes only to 64-bit addresses
This commit changes ioc3_map() so it leaves out the Bridge DMA attributes
when the DMA address has no target widget in bits 63:60, which is the case
for a 32-bit direct window address. It also replaces ERBAR_VAL with
ioc3_erbar(), which returns 0 for such addresses. ioc3_init() now picks
the ERBAR value from the RX ring DMA address. The goal is to prepare for
IP35 support, which will give the IOC3 window addresses.
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/ethernet/sgi/ioc3-eth.c b/drivers/net/ethernet/sgi/ioc3-eth.c
index 009f37105eafd..25139cf5ff62c 100644
--- a/drivers/net/ethernet/sgi/ioc3-eth.c
+++ b/drivers/net/ethernet/sgi/ioc3-eth.c
@@ -152,19 +152,37 @@ static inline int ioc3_alloc_skb(struct ioc3_private *ip, struct sk_buff **skb,
}
#ifdef CONFIG_PCI_XTALK_BRIDGE
+/* A Bridge 64-bit direct-mapped DMA address carries the target widget in
+ * bits 63:60 and the DMA attributes below it. An address in the 32-bit
+ * direct window carries neither, so attributes OR-ed onto one form a
+ * 64-bit address aimed at widget 0.
+ */
static inline unsigned long ioc3_map(dma_addr_t addr, unsigned long attr)
{
+ if (!(addr & PCI64_ATTR_TARG_MASK))
+ return addr;
+
return (addr & ~PCI64_ATTR_BAR) | attr;
}
-#define ERBAR_VAL (ERBAR_BARRIER_BIT << ERBAR_RXBARR_SHIFT)
+/* The RX barrier's upper address bits follow the same form. */
+static inline u32 ioc3_erbar(dma_addr_t addr)
+{
+ if (!(addr & PCI64_ATTR_TARG_MASK))
+ return 0;
+
+ return ERBAR_BARRIER_BIT << ERBAR_RXBARR_SHIFT;
+}
[Severity: Medium]
For a 32-bit direct window address, ioc3_map() now returns the bare
address and ioc3_erbar() returns 0. Where do the dropped attributes come
from in that case?
Three attributes are lost. ioc3_rx() and ioc3_alloc_rx_bufs() lose
PCI64_ATTR_BAR on the RX buffer pointers. ioc3_start() loses
PCI64_ATTR_PREC on the ring bases. ioc3_start_xmit() loses PCI64_ATTR_PREF
on the TX buffer pointers.
For 32-bit direct DMA the Bridge takes these from the per-slot Device(x)
register (BRIDGE_DEV_PREF, BRIDGE_DEV_PRECISE and BRIDGE_DEV_BARRIER in
BRIDGE_DEV_D32_BITS). The only code in the tree that writes
b_device[slot] is bridge_probe(), and it sets only the swap bit:
arch/mips/pci/pci-xtalk-bridge.c:bridge_probe() {
...
bridge_set(bc, b_device[slot].reg, BRIDGE_DEV_SWAP_DIR);
...
}
ERBAR is now 0 as well. What, then, orders the ERXBUF w0 valid-word store
after the payload stores? ioc3_rx() trusts that word before it reads the
frame:
while (w0 & ERXBUF_V) {
err = be32_to_cpu(rxb->err); /* It's valid ... */
Could the CPU see ERXBUF_V before the payload has landed, and pass a stale
or truncated frame up the stack?
There is a separate question about ioc3_init(), which picks the ERBAR
value from the coherent ring address:
writel(ioc3_erbar(ip->rxr_dma), ®s->erbar);
ERBAR applies to the last store into each RX buffer. Those buffers are
separate streaming mappings from ioc3_alloc_skb(). ioc3_map() decides per
address, so suppose the ring gets a 64-bit address and an RX buffer gets a
window address. Wouldn't ERBAR still OR the barrier attribute into the
upper bits of that buffer's last store, which gives the widget 0 address
this patch is meant to avoid? This assumes the IOC3 ORs ERBAR onto the
upper address bits.
None of this can be reached on in-tree platforms. phys_to_dma() returns
bc->baddr + paddr, and baddr has a non-zero target nibble on both IP27 and
IP30. Whether it triggers depends on how the IP35 support maps DMA and
programs Device(x).
The commit message also doesn't say that the RX barrier is turned off for
window addresses, or what replaces it. Could that be added?
#else
static inline unsigned long ioc3_map(dma_addr_t addr, unsigned long attr)
{
[ ... ]
quoted hunk ↗ jump to hunk
@@ -727,7 +745,7 @@ static void ioc3_init(struct net_device *dev)
readl(®s->emcr);
/* Misc registers */
- writel(ERBAR_VAL, ®s->erbar);
+ writel(ioc3_erbar(ip->rxr_dma), ®s->erbar);
[Severity: High]
This isn't a bug introduced by this patch, but ioc3_init() starts with a
synchronous timer delete, and both error-recovery callers hold
ip->ioc3_lock when they call it:
ioc3_init() {
timer_delete_sync(&ip->ioc3_timer); /* Kill if running */
...
}
ioc3_error() runs from the hardirq handler ioc3_interrupt() and does:
spin_lock(&ip->ioc3_lock);
...
ioc3_init(dev);
ioc3_timeout() does the same thing with spin_lock_irq(). The timer
callback takes the same lock:
ioc3_timer()
mii_check_media()
ioc3_setup_duplex()
spin_lock_irq(&ip->ioc3_lock);
Can this deadlock on SMP?
CPU A
ioc3_timer()
ioc3_setup_duplex()
spin_lock_irq(&ip->ioc3_lock) <- spins on the lock CPU B holds
CPU B
ioc3_error() or ioc3_timeout()
spin_lock(&ip->ioc3_lock)
ioc3_init()
timer_delete_sync() <- waits for CPU A's callback
Also, ioc3eth_probe() sets up the timer without TIMER_IRQSAFE:
timer_setup(&ip->ioc3_timer, ioc3_timer, 0);
So won't every hardirq call through ioc3_error() hit this check in
__timer_delete_sync()?
WARN_ON(in_hardirq() && !(timer->flags & TIMER_IRQSAFE));
ioc3_error() runs on EISR_RXOFLO or EISR_RXBUFOFLO, so incoming traffic
that outruns the RX ring is enough to trigger it.
Last, ioc3_error() calls ioc3_mii_init() but not ioc3_mii_start(), unlike
ioc3_timeout(). If the timer is never re-armed, does link and duplex
monitoring stop after an error recovery?
readl(®s->etcdc); /* Clear on read */
writel(15, ®s->ercsr); /* RX low watermark */
writel(0, ®s->ertr); /* Interrupt immediately */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116102115.27574-1-kaloz%40kernel.org