net: macb: Relocate mog_init_rings() callback from macb_mac_link_up() to macb_open()
Subsystems (4)
PATCH v2 1/1 net: macb: Relocate mog_init_rings() callback from macb_mac_link_up() to macb_open()
In the non-RT kernel, local_bh_disable() merely disables preemption, whereas it maps to an actual spin lock in the RT kernel. Consequently, when attempting to refill RX buffers via netdev_alloc_skb() in macb_mac_link_up(), a deadlock scenario arises as follows:
Chain caused by macb_mac_link_up():
&bp->lock --> (softirq_ctrl.lock)
Chain caused by macb_start_xmit():
(softirq_ctrl.lock) --> _xmit_ETHER#2 --> &bp->lock
Notably, invoking the mog_init_rings() callback upon link establishment is unnecessary. Instead, we can exclusively call mog_init_rings() within the ndo_open() callback. This adjustment resolves the deadlock issue. Given that mog_init_rings() is only applicable to non-MACB_CAPS_MACB_IS_EMAC cases, we can simply move it to macb_open() and simultaneously eliminate the MACB_CAPS_MACB_IS_EMAC check.
---
V1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
V2: Update the correct lock dependency chain and add the Fix tag.
drivers/net/ethernet/cadence/macb_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +2 -1
@@ -744,7 +744,6 @@ static void macb_mac_link_up(struct phylink_config *config,/* Initialize rings & buffers as clearing MACB_BIT(TE) in link down * cleared the pipeline and control registers. */ - bp->macbgem_ops.mog_init_rings (bp);macb_init_buffers (bp);for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue)
@@ -2991,6 +2990,8 @@ static int macb_open(struct net_device *dev) goto pm_exit; } + bp->macbgem_ops.mog_init_rings (bp); +for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) {napi_enable (&queue->napi_rx);napi_enable (&queue->napi_tx);
Signature · 1 line
2.43.0
Paolo Abeni
maintainerQuoted 9 lines · Xiaolei Wang
In the non-RT kernel,
local_bh_disable()merely disables preemption, whereas it maps to an actual spin lock in the RT kernel. Consequently, when attempting to refill RX buffers vianetdev_alloc_skb()inmacb_mac_link_up(), a deadlock scenario arises as follows:
Chain caused bymacb_mac_link_up():&bp->lock --> (softirq_ctrl.lock) Chain caused by macb_start_xmit(): (softirq_ctrl.lock) --> _xmit_ETHER#2 --> &bp->lock
Including the whole lockdep splat instead of the above would be clearer; in fact, I had to fetch the relevant info from there.
Quoted 6 lines
Notably, invoking the
mog_init_rings()callback upon link establishment is unnecessary. Instead, we can exclusively callmog_init_rings()within thendo_open()callback. This adjustment resolves the deadlock issue. Given thatmog_init_rings()is only applicable to non-MACB_CAPS_MACB_IS_EMAC cases, we can simply move it tomacb_open()and simultaneously eliminate theMACB_CAPS_MACB_IS_EMACcheck.
This part is not clear to me: AFAICS the new code now does such init step unconditionally, which looks confusing. I think such step should still be under the relevant conditional (or you need to include a better/more verbose explanation describing why such check is not really needed).
Quoted 4 lines
Fixes 633e98a711ac ("net: macb: use resolved link config in mac_link_up()")Suggested-by Kevin Hao <[email protected]>Signed-off-by Xiaolei Wang <[email protected]>
Side note: you still need to include the 'net' tag into the subj prefix.
/P
Quoted 11 lines · Paolo Abeni
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 7 lines · Xiaolei Wang
In the non-RT kernel,
local_bh_disable()merely disables preemption, whereas it maps to an actual spin lock in the RT kernel. Consequently, when attempting to refill RX buffers vianetdev_alloc_skb()inmacb_mac_link_up(), a deadlock scenario arises as follows:
Chain caused bymacb_mac_link_up():&bp->lock --> (softirq_ctrl.lock)
Quoted 4 lines
Quoted 2 lines
Chain caused by
macb_start_xmit():
(softirq_ctrl.lock) --> _xmit_ETHER#2 -->&bp->lockIncluding the whole lockdep splat instead of the above would be clearer; in fact, I had to fetch the relevant info from there.
OK, I will add all the logs.
Quoted 7 lines
Quoted 7 lines
Notably, invoking the
mog_init_rings()callback upon link establishment is unnecessary. Instead, we can exclusively callmog_init_rings()within thendo_open()callback. This adjustment resolves the deadlock issue. Given thatmog_init_rings()is only applicable to non-MACB_CAPS_MACB_IS_EMAC cases, we can simply move it tomacb_open()and simultaneously eliminate theMACB_CAPS_MACB_IS_EMACcheck.
Quoted 5 lines
This part is not clear to me: AFAICS the new code now does such init step unconditionally, which looks confusing. I think such step should still be under the relevant conditional (or you need to include a better/more verbose explanation describing why such check is not really needed).
I noticed that the initialization function in 'emac_config' is 'at91ether_init()',
and 'netdev_ops' is 'at91ether_netdev_ops'. It doesn't use 'macb_open()',
so after moving 'mog_init_rings()' to 'macb_open', we no longer need to add this check.
Quoted 6 lines
Quoted 5 lines
Fixes 633e98a711ac ("net: macb: use resolved link config in mac_link_up()")Suggested-by Kevin Hao <[email protected]>Signed-off-by Xiaolei Wang <[email protected]>Side note: you still need to include the 'net' tag into the subj prefix.
OK, I will add "net" to the subject in the next version.
thanks
xiaolei
Quoted 3 lines
/P