Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1775445ybl; Fri, 13 Dec 2019 23:24:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxoNBdju2U709wXnsJ8oHznhTiGz9aEbJ9M50rwNHhMaJEmc/kHo6gKaeuvocLqY6RKadc2 X-Received: by 2002:a9d:7ccc:: with SMTP id r12mr20225664otn.22.1576308259127; Fri, 13 Dec 2019 23:24:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576308259; cv=none; d=google.com; s=arc-20160816; b=D7fiXn78LELpKfypjctYy1fqFwYN8DcW6Bju7qBoeU5RS5uuIjARihb38GaY8hRsJp MI8H27oqKm3JWcHhNm/PvH+ynDsm4YX1acHhxmRW9kJEmngDITg6vvqJCOVgAkM1JR5U +fNGHz78diJIJEeVvRO2Pkr0v8+NPwmk44uQKGIwM0QRIqu1FHtn18yj7PtrbUipYQpm rgrmYe8FN/34ab9CTx2kmyXANIOw4NDKA5effWzy0euWZGj5tG7e/m0kfmnYlwcYxM0T 4RJ4b+gAHnjXam3Q/xcVqPq4p/Ci2VcV6ohyRxCzaY20QrA/FFsEXTEdn7sAjFWec4nM iP3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=xFr9tovAn4Hpkjwf/6es24RH3ywJr2JaaAx7/DnU9i0=; b=Agp6Lbd0sy7EQX3bBXQu3mSWY6B2TkuA+Nsm8P/FMA5YKiYxN51zImHS8A/YppJaXg cPoIgcH66ZvxeixSHk4jFTwwEOg+V64mAO0GBUWo25IXc6/i1AKni+2grGmDvcIKxb9Y o+rRAmQKF/sKw03B6cxbkP9uAyLn5kWc0Sml7xE4Y4Ob3wj6ezNuNeT+MXBBSqoycLyO RJd0eSOAk3M6JqTyGhrHB3rhjsNQOxrQjJtTAeyUUG8p/w2Hc5TPyfJ4J36jPDNVeMEL H9w/EmDYHDifPxh9wkF8yl2zvkQ7bNblNtp1N2MFDGVcmjG0By3dx8EkeERBTstFJDpx tTIA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h22si6584396otn.279.2019.12.13.23.24.06; Fri, 13 Dec 2019 23:24: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725975AbfLNHXY (ORCPT + 99 others); Sat, 14 Dec 2019 02:23:24 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7689 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725871AbfLNHXY (ORCPT ); Sat, 14 Dec 2019 02:23:24 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 6B77C538BC6A79D7CB3B; Sat, 14 Dec 2019 15:23:20 +0800 (CST) Received: from huawei.com (10.67.189.167) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Sat, 14 Dec 2019 15:23:10 +0800 From: Jiangfeng Xiao To: , , , CC: , , , Subject: [PATCH] net: hisilicon: Fix a BUG trigered by wrong bytes_compl Date: Sat, 14 Dec 2019 15:23:02 +0800 Message-ID: <1576308182-121147-1-git-send-email-xiaojiangfeng@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.167] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The trace is as follow: kernel BUG at lib/dynamic_queue_limits.c:26! Internal error: Oops - BUG: 0 [#1] SMP ARM Modules linked in: hip04_eth CPU: 0 PID: 2003 Comm: tDblStackPcap0 Tainted: G O L 4.4.197 #1 Hardware name: Hisilicon A15 task: c3637668 task.stack: de3bc000 PC is at dql_completed+0x18/0x154 LR is at hip04_tx_reclaim+0x110/0x174 [hip04_eth] pc : [] lr : [] psr: 800f0313 sp : de3bdc2c ip : 00000000 fp : c020fb10 r10: 00000000 r9 : c39b4224 r8 : 00000001 r7 : 00000046 r6 : c39b4000 r5 : 0078f392 r4 : 0078f392 r3 : 00000047 r2 : 00000000 r1 : 00000046 r0 : df5d5c80 Flags: Nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user Control: 32c5387d Table: 1e189b80 DAC: 55555555 Process tDblStackPcap0 (pid: 2003, stack limit = 0xde3bc190) Stack: (0xde3bdc2c to 0xde3be000) [] (dql_completed) from [] (hip04_tx_reclaim+0x110/0x174 [hip04_eth]) [] (hip04_tx_reclaim [hip04_eth]) from [] (hip04_rx_poll+0x20/0x388 [hip04_eth]) [] (hip04_rx_poll [hip04_eth]) from [] (net_rx_action+0x120/0x374) [] (net_rx_action) from [] (__do_softirq+0x218/0x318) [] (__do_softirq) from [] (irq_exit+0x88/0xac) [] (irq_exit) from [] (msa_irq_exit+0x11c/0x1d4) [] (msa_irq_exit) from [] (__handle_domain_irq+0x110/0x148) [] (__handle_domain_irq) from [] (gic_handle_irq+0xd4/0x118) [] (gic_handle_irq) from [] (__irq_svc+0x40/0x58) Exception stack(0xde3bdde0 to 0xde3bde28) dde0: 00000000 00008001 c3637668 00000000 00000000 a00f0213 dd3627a0 c0af6380 de00: c086d380 a00f0213 c0a22a50 de3bde6c 00000002 de3bde30 c0558138 c055813c de20: 600f0213 ffffffff [] (__irq_svc) from [] (_raw_spin_unlock_irqrestore+0x44/0x54) Kernel panic - not syncing: Fatal exception in interrupt Pre-modification code: int hip04_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) { [...] [1] priv->tx_head = TX_NEXT(tx_head); [2] count++; [3] netdev_sent_queue(ndev, skb->len); [...] } An rx interrupt occurs if hip04_mac_start_xmit just executes to the line 2, tx_head has been updated, but corresponding 'skb->len' has not been added to dql_queue. And then hip04_mac_interrupt->__napi_schedule->hip04_rx_poll->hip04_tx_reclaim In hip04_tx_reclaim, because tx_head has been updated, bytes_compl will plus an additional "skb-> len" which has not been added to dql_queue. And then trigger the BUG_ON(bytes_compl > num_queued - dql->num_completed). To solve the problem described above, we put "netdev_sent_queue(ndev, skb->len);" before "priv->tx_head = TX_NEXT(tx_head);" In addition, I adjusted the position of "count++;" to make the code more readable. Signed-off-by: Jiangfeng Xiao --- drivers/net/ethernet/hisilicon/hip04_eth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hip04_eth.c b/drivers/net/ethernet/hisilicon/hip04_eth.c index 3e9b6d5..085476d 100644 --- a/drivers/net/ethernet/hisilicon/hip04_eth.c +++ b/drivers/net/ethernet/hisilicon/hip04_eth.c @@ -543,9 +543,8 @@ static void hip04_start_tx_timer(struct hip04_priv *priv) skb_tx_timestamp(skb); hip04_set_xmit_desc(priv, phys); - priv->tx_head = TX_NEXT(tx_head); - count++; netdev_sent_queue(ndev, skb->len); + priv->tx_head = TX_NEXT(tx_head); stats->tx_bytes += skb->len; stats->tx_packets++; @@ -553,6 +552,7 @@ static void hip04_start_tx_timer(struct hip04_priv *priv) /* Ensure tx_head update visible to tx reclaim */ smp_wmb(); + count++; /* queue is getting full, better start cleaning up now */ if (count >= priv->tx_coalesce_frames) { if (napi_schedule_prep(&priv->napi)) { -- 1.8.5.6