Received: by 10.223.176.5 with SMTP id f5csp143501wra; Tue, 6 Feb 2018 19:04:20 -0800 (PST) X-Google-Smtp-Source: AH8x227M2S/MSydG+mZnltyyqpNyrdNTNDZlhtGftkQvPDBRe//y27/stZw9piKzS6otPkm5XDlP X-Received: by 10.101.91.193 with SMTP id o1mr3781170pgr.315.1517972659966; Tue, 06 Feb 2018 19:04:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517972659; cv=none; d=google.com; s=arc-20160816; b=XUYu54m39Db2Vcyd0IxNRVuNj7vivLlmM/BGqW627NOLO6yDvVpKGSMjexlQN04HAo b4vuvccixkzDJWUPjTZ6vwz2OLQQNOo5lGNSQllVubfRl8fYKM4oEKsEKbyFh5whteSr kP2l5dyr1cJqfTVSP8LuPDj3uGxrSa6Yd6fQJnmtqmVgnvT6Km1K59/njp4MWgKjRuQ/ KMtYaxLKU5g7yT2ZSzflakt0a7B0F3nSx5+uyqnq+/fXXBM5VEoAa7cIz66rzWhkMrlE OT9ikSUjFbCmBsDmoZpMsIEzzSHVA0P6DKwyJ5gh19oQNl5dfH5gCTII0WRQx5VxXmT+ Bm4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=Fc+KU228t/YvymuF+NZFRLQxF+QWCD26HIph48osXsA=; b=U2jXv1r6bUou9hKhgFd6jBc3qL4oLPYDFwUXCbcBn4yHmXAjq3p/6OIGnON09kisUX TNKwnrEM0jGqjQ68nWpTmxjftrJ8TDFRFq+WXZYa11DJ/MUJ7VkEwpg1k8Ln4thP9cwM Rl/ftM/e0vMoRpF4dL+dspwh69LRlu/qnLCtQMUOGsH/pW9nQK9sNsWK0f1Zw8I3wo34 fhvVlw7xXIkpLzO5Ge7ad2O9QpEh0T5jaLWLY3IVfpQkiaAZD+vYOTWoxYHgZdS33ujP sml3kBv4/9krM2I2KQ9WlSFwPoIirWHvOhwf6jZBcdRfwqrmruLTVOR+RN+AVPNS2T+2 QPqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kDE+jOsY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r13-v6si373385pls.308.2018.02.06.19.04.05; Tue, 06 Feb 2018 19:04:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kDE+jOsY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752970AbeBGDDZ (ORCPT + 99 others); Tue, 6 Feb 2018 22:03:25 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33305 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752688AbeBGDDX (ORCPT ); Tue, 6 Feb 2018 22:03:23 -0500 Received: by mail-lf0-f65.google.com with SMTP id t139so5741432lff.0 for ; Tue, 06 Feb 2018 19:03:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Fc+KU228t/YvymuF+NZFRLQxF+QWCD26HIph48osXsA=; b=kDE+jOsY8hfeBIM0jpQEHUx96RMBPnsnnNRFgqJTHv131/oexJmZkktpD50QiiPje/ IXXdheuiTW95tO+qNdUuxIF51CsOtKEdHgHVjwsMQd2xDIMVs6V3VYGHaV/3kv8P58P/ Prs8KHJBDwJSbqzG/zqFIP3e8xptMn3T+oIhQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=Fc+KU228t/YvymuF+NZFRLQxF+QWCD26HIph48osXsA=; b=iiQvhlpZb49vvHdwo3kkuj+8M2RVKXJmpD4AY2bUV7tAE0bSqjJrvEd71sW16ISDHG Gh0c61y4MeEv5bu1srGfiBpWVkTxIszL9MbzvZ58xjwRnBwtgGnu7UolU0+IkQ0wjlqv ahrWqehVoDSX+/mGMDvBV60SlDWvuPn6L2BQif/U8jCFkuR8XRhOfCatYYSV4ahRA8qh wYk/sJYptHpBlEx1wVS0axXYgQ3PnycN/g2hUDSy+7Eza6P9ZMDPQakho03mKbwqyZFr F7N8iU+Vs9npQFPegBHZ/Jk/kRxWiMOigC4fKewwIVlig74ronTzdHyRhQO5CVvbsUfY aEng== X-Gm-Message-State: APf1xPBgM9HIRKN47I4YCF8iSD031T9ApDF9KWlYVBJEBb2Kf/U1gJoX QOU1BPKkpixXqh6nvKIg8VN70g== X-Received: by 10.25.160.129 with SMTP id j123mr3122531lfe.136.1517972601727; Tue, 06 Feb 2018 19:03:21 -0800 (PST) Received: from khorivan (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id 77sm66897ljf.81.2018.02.06.19.03.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Feb 2018 19:03:21 -0800 (PST) Date: Wed, 7 Feb 2018 05:03:19 +0200 From: Ivan Khoronzhuk To: Grygorii Strashko Cc: "David S. Miller" , netdev@vger.kernel.org, Sekhar Nori , linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: Re: [PATCH] net: ethernet: ti: cpsw: fix net watchdog timeout Message-ID: <20180207030316.GA7883@khorivan> Mail-Followup-To: Grygorii Strashko , "David S. Miller" , netdev@vger.kernel.org, Sekhar Nori , linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org References: <20180207011706.13393-1-grygorii.strashko@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180207011706.13393-1-grygorii.strashko@ti.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 06, 2018 at 07:17:06PM -0600, Grygorii Strashko wrote: > It was discovered that simple program which indefinitely sends 200b UDP > packets and runs on TI AM574x SoC (SMP) under RT Kernel triggers network > watchdog timeout in TI CPSW driver (<6 hours run). The network watchdog > timeout is triggered due to race between cpsw_ndo_start_xmit() and > cpsw_tx_handler() [NAPI] > > cpsw_ndo_start_xmit() > if (unlikely(!cpdma_check_free_tx_desc(txch))) { > txq = netdev_get_tx_queue(ndev, q_idx); > netif_tx_stop_queue(txq); > > ^^ as per [1] barier has to be used after set_bit() otherwise new value > might not be visible to other cpus > } > > cpsw_tx_handler() > if (unlikely(netif_tx_queue_stopped(txq))) > netif_tx_wake_queue(txq); > > and when it happens ndev TX queue became disabled forever while driver's HW > TX queue is empty. I'm sure it fixes test case somehow but there is some strangeness. (I've thought about this some X months ago): 1. If no free desc, then there is bunch of descs on the queue ready to be sent 2. If one of this desc while this process was missed then next will wake queue, because there is bunch of them on the fly. So, if desc on top of the sent queue missed to enable the queue, then next one more likely will enable it anyway.. then how it could happen? The described race is possible only on last descriptor, yes, packets are small the speed is hight, possibility is very small .....but then next situation is also possible: - packets are sent fast - all packets were sent, but no any descriptors are freed now by sw interrupt (NAPI) - when interrupt had started NAPI, the queue was enabled, all other next interrupts are throttled once NAPI not finished it's work yet. - when new packet submitted, no free descs are present yet (NAPI has not freed any yet), but all packets are sent, so no one can awake tx queue, as interrupt will not arise when NAPI is started to free first descriptor interrupts are disabled.....because h/w queue to be sent is empty... - how it can happen as submitting packet and handling packet operations is under channel lock? Not exactly, a period between handling and freeing the descriptor to the pool is not under channel lock, here: spin_unlock_irqrestore(&chan->lock, flags); if (unlikely(status & CPDMA_DESC_TD_COMPLETE)) cb_status = -ENOSYS; else cb_status = status; __cpdma_chan_free(chan, desc, outlen, cb_status); return status; unlock_ret: spin_unlock_irqrestore(&chan->lock, flags); return status; And: __cpdma_chan_free(chan, desc, outlen, cb_status); -> cpdma_desc_free(pool, desc, 1); As result, queue deadlock as you've described. Just thought, not checked, but theoretically possible. What do you think? > > Fix this, by adding smp_mb__after_atomic() after netif_tx_stop_queue() > calls and double check for free TX descriptors after stopping ndev TX queue > - if there are free TX descriptors wake up ndev TX queue. > > [1] https://www.kernel.org/doc/html/latest/core-api/atomic_ops.html > Signed-off-by: Grygorii Strashko > --- > drivers/net/ethernet/ti/cpsw.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c > index 10d7cbe..3805b13 100644 > --- a/drivers/net/ethernet/ti/cpsw.c > +++ b/drivers/net/ethernet/ti/cpsw.c > @@ -1638,6 +1638,7 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb, > q_idx = q_idx % cpsw->tx_ch_num; > > txch = cpsw->txv[q_idx].ch; > + txq = netdev_get_tx_queue(ndev, q_idx); > ret = cpsw_tx_packet_submit(priv, skb, txch); > if (unlikely(ret != 0)) { > cpsw_err(priv, tx_err, "desc submit failed\n"); > @@ -1648,15 +1649,26 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb, > * tell the kernel to stop sending us tx frames. > */ > if (unlikely(!cpdma_check_free_tx_desc(txch))) { > - txq = netdev_get_tx_queue(ndev, q_idx); > netif_tx_stop_queue(txq); > + > + /* Barrier, so that stop_queue visible to other cpus */ > + smp_mb__after_atomic(); > + > + if (cpdma_check_free_tx_desc(txch)) > + netif_tx_wake_queue(txq); > } > > return NETDEV_TX_OK; > fail: > ndev->stats.tx_dropped++; > - txq = netdev_get_tx_queue(ndev, skb_get_queue_mapping(skb)); > netif_tx_stop_queue(txq); > + > + /* Barrier, so that stop_queue visible to other cpus */ > + smp_mb__after_atomic(); > + > + if (cpdma_check_free_tx_desc(txch)) > + netif_tx_wake_queue(txq); > + > return NETDEV_TX_BUSY; > } > > -- > 2.10.5 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-omap" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Regards, Ivan Khoronzhuk