On 2021/5/11 17:04, Yunsheng Lin wrote:
On 2021/5/11 12:22, Jakub Kicinski wrote:
On Mon, 10 May 2021 09:42:36 +0800 Yunsheng Lin wrote:
The netdev qeueue might be stopped when byte queue limit has reached or tx hw ring is full, net_tx_action() may still be rescheduled endlessly if STATE_MISSED is set, which consumes a lot of cpu without dequeuing and transmiting any skb because the netdev queue is stopped, see qdisc_run_end().
This patch fixes it by checking the netdev queue state before calling qdisc_run() and clearing STATE_MISSED if netdev queue is stopped during qdisc_run(), the net_tx_action() is recheduled again when netdev qeueue is restarted, see netif_tx_wake_queue().
Fixes: 6b3ba9146fe6 ("net: sched: allow qdiscs to handle locking") Reported-by: Michal Kubecek mkubecek@suse.cz Signed-off-by: Yunsheng Lin linyunsheng@huawei.com
Patches 1 and 2 look good to me but this one I'm not 100% sure.
@@ -251,8 +253,10 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate, *validate = true;
if ((q->flags & TCQ_F_ONETXQUEUE) &&
netif_xmit_frozen_or_stopped(txq))
netif_xmit_frozen_or_stopped(txq)) {
return skb;clear_bit(__QDISC_STATE_MISSED, &q->state);
- }
The queues are woken asynchronously without holding any locks via netif_tx_wake_queue(). Theoretically we can have a situation where:
CPU 0 CPU 1 . . dequeue_skb() . netif_xmit_frozen..() # true . . [IRQ] . netif_tx_wake_queue() . <end of IRQ> . netif_tx_action() . set MISSED clear MISSED return NULL ret from qdisc_restart() ret from __qdisc_run() qdisc_run_end() -> MISSED not set
Yes, the above does seems to have the above data race.
As my understanding, there is two ways to fix the above data race:
do not clear the STATE_MISSED for netif_xmit_frozen_or_stopped() case, just check the netif_xmit_frozen_or_stopped() before calling __netif_schedule() at the end of qdisc_run_end(). This seems to only work with qdisc with TCQ_F_ONETXQUEUE flag because it seems we can only check the netif_xmit_frozen_or_stopped() with q->dev_queue, I am not sure q->dev_queue is pointint to which netdev queue when qdisc is not set with TCQ_F_ONETXQUEUE flag.
clearing the STATE_MISSED for netif_xmit_frozen_or_stopped() case as this patch does, and protect the __netif_schedule() with q->seqlock for netif_tx_wake_queue(), which might bring unnecessary overhead for non-stopped queue case
Any better idea?
3. Or check the netif_xmit_frozen_or_stopped() again after clearing STATE_MISSED, like below:
if (netif_xmit_frozen_or_stopped(txq)) { clear_bit(__QDISC_STATE_MISSED, &q->state);
/* Make sure the below netif_xmit_frozen_or_stopped() * checking happens after clearing STATE_MISSED. */ smp_mb__after_atomic();
/* Checking netif_xmit_frozen_or_stopped() again to * make sure __QDISC_STATE_MISSED is set if the * __QDISC_STATE_MISSED set by netif_tx_wake_queue()'s * rescheduling of net_tx_action() is cleared by the * above clear_bit(). */ if (!netif_xmit_frozen_or_stopped(txq)) set_bit(__QDISC_STATE_MISSED, &q->state); }
It is kind of ugly, but it does seem to fix the above data race too. And it seems like a common pattern to deal with the concurrency between xmit and NAPI polling, as below:
https://elixir.bootlin.com/linux/v5.12-rc2/source/drivers/net/ethernet/hisil...
.
Linuxarm mailing list -- linuxarm@openeuler.org To unsubscribe send an email to linuxarm-leave@openeuler.org