From patchwork Mon Nov 11 18:27:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179110 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7033784ilf; Mon, 11 Nov 2019 10:40:48 -0800 (PST) X-Google-Smtp-Source: APXvYqx9A8s8FHCBapLe2xr7rtQVTfYlW8yzyPDlQLEPPanBxvY6wJkmreJN7q0P1Hc2a9Nl2ZRK X-Received: by 2002:a17:906:85c8:: with SMTP id i8mr24228444ejy.46.1573497648125; Mon, 11 Nov 2019 10:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573497648; cv=none; d=google.com; s=arc-20160816; b=unggclFD/NCQDMWwKWxqY0Ksu5ssCUxBV7waqiFlh8YLMzU1JgOEoYqa8Z4Cxq/8rf 6WyxPqQszUAIVUtDiJSZCrtJ2WX3PFJ5k4weLkiXtRMpppxmH6Neue76IW4gXAoB6crR Jq+aIQiciwH9Sql8cUP5vTufNO9Efpd5cpPTKs32Of235VGz+kMiz7YO9V1CqZVIvoB4 h8FVt21DXiwQ8DpbgwQ9huigfdMPHM1XowFWFBTec5S5UXtYXdBN8aDFqMzgu2uMlJr4 iPFMsTQUGUORueYVgcZHdB3ZvpwGQiJxnxkYFnWA5/MqGR6RXjn4YRzNEbs6hJvP2Oth pK8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Cw33AmoY6NOWXHwayD019ahxORWruUp9fWA/9NQYVGg=; b=WVTNbltuhrY6S27Pqvx5YLVwX4ODhfIM0xS8qf3VAs7f7KixW91YYkXziA/M0VyRRI VYQ4urz11IYoq31eGKwtLGOLiEAXseWulqejpSnkFfPGKEkD9ukaK+lBkJ28IRmeYRN7 9KtTRC9qRn2nfkH323gyDYAM4XGl4TCAIB27D7RRrgkj4OjZ6hkv8vyxIciyyyvKVSAe FzqhADEbbUMIZCdEE71GHQRA7nXed4o3ZTUlfVRfm39D0frA+mac3yLuF64xllukK0ED zlEpfTQykFZrLL6jadiCLzLLg5xOnHtbjbjRfiik4NImuU6iL0TjOGYCudaDC8R56MN+ 775w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h33zMjtL; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 o1si9502143eje.298.2019.11.11.10.40.47; Mon, 11 Nov 2019 10:40:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@kernel.org header.s=default header.b=h33zMjtL; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728454AbfKKSkn (ORCPT + 14 others); Mon, 11 Nov 2019 13:40:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:59870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728468AbfKKSkm (ORCPT ); Mon, 11 Nov 2019 13:40:42 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1887B20659; Mon, 11 Nov 2019 18:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497641; bh=kUBUtkFGhTWmRy3K6qas81XFSNfOybMzFRFT3CAK3ck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h33zMjtLYXOVdPewq3impcZsRfpUO2g0hHu9fYFkttZ97+oK5iu+ERfGuZWcB1/VS LMrEgpIObdwWr+CRSMpPYXdFdzo+L632bBWIojfWWtAkSgvLYh3PpBdoTff4AZ3oJC V5NxyI9qhfynmCyyvYZ3/wGbY6Vnm5nO7OjAqNqE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, lipeng , Yisen Zhuang , Eric Dumazet , "David S. Miller" , Marc Zyngier , Salil Mehta Subject: [PATCH 4.19 015/125] net: hns: Fix the stray netpoll locks causing deadlock in NAPI path Date: Mon, 11 Nov 2019 19:27:34 +0100 Message-Id: <20191111181441.661895796@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Salil Mehta [ Upstream commit bf5a6b4c474c589244dc25ee1af2c3c829228ef8 ] This patch fixes the problem of the spin locks, originally meant for the netpoll path of hns driver, causing deadlock in the normal NAPI poll path. The issue happened due to the presence of the stray leftover spin lock code related to the netpoll, whose support was earlier removed from the HNS[1], got activated due to enabling of NET_POLL_CONTROLLER switch. Earlier background: The netpoll handling code originally had this bug(as identified by Marc Zyngier[2]) of wrong spin lock API being used which did not disable the interrupts and hence could cause locking issues. i.e. if the lock were first acquired in context to thread like 'ip' util and this lock if ever got later acquired again in context to the interrupt context like TX/RX (Interrupts could always pre-empt the lock holding task and acquire the lock again) and hence could cause deadlock. Proposed Solution: 1. If the netpoll was enabled in the HNS driver, which is not right now, we could have simply used spin_[un]lock_irqsave() 2. But as netpoll is disabled, therefore, it is best to get rid of the existing locks and stray code for now. This should solve the problem reported by Marc. [1] https://git.kernel.org/torvalds/c/4bd2c03be7 [2] https://patchwork.ozlabs.org/patch/1189139/ Fixes: 4bd2c03be707 ("net: hns: remove ndo_poll_controller") Cc: lipeng Cc: Yisen Zhuang Cc: Eric Dumazet Cc: David S. Miller Reported-by: Marc Zyngier Acked-by: Marc Zyngier Tested-by: Marc Zyngier Signed-off-by: Salil Mehta Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/hisilicon/hns/hnae.c | 1 - drivers/net/ethernet/hisilicon/hns/hnae.h | 3 --- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 22 +--------------------- 3 files changed, 1 insertion(+), 25 deletions(-) --- a/drivers/net/ethernet/hisilicon/hns/hnae.c +++ b/drivers/net/ethernet/hisilicon/hns/hnae.c @@ -203,7 +203,6 @@ hnae_init_ring(struct hnae_queue *q, str ring->q = q; ring->flags = flags; - spin_lock_init(&ring->lock); ring->coal_param = q->handle->coal_param; assert(!ring->desc && !ring->desc_cb && !ring->desc_dma_addr); --- a/drivers/net/ethernet/hisilicon/hns/hnae.h +++ b/drivers/net/ethernet/hisilicon/hns/hnae.h @@ -278,9 +278,6 @@ struct hnae_ring { /* statistic */ struct ring_stats stats; - /* ring lock for poll one */ - spinlock_t lock; - dma_addr_t desc_dma_addr; u32 buf_size; /* size for hnae_desc->addr, preset by AE */ u16 desc_num; /* total number of desc */ --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -947,15 +947,6 @@ static int is_valid_clean_head(struct hn return u > c ? (h > c && h <= u) : (h > c || h <= u); } -/* netif_tx_lock will turn down the performance, set only when necessary */ -#ifdef CONFIG_NET_POLL_CONTROLLER -#define NETIF_TX_LOCK(ring) spin_lock(&(ring)->lock) -#define NETIF_TX_UNLOCK(ring) spin_unlock(&(ring)->lock) -#else -#define NETIF_TX_LOCK(ring) -#define NETIF_TX_UNLOCK(ring) -#endif - /* reclaim all desc in one budget * return error or number of desc left */ @@ -969,21 +960,16 @@ static int hns_nic_tx_poll_one(struct hn int head; int bytes, pkts; - NETIF_TX_LOCK(ring); - head = readl_relaxed(ring->io_base + RCB_REG_HEAD); rmb(); /* make sure head is ready before touch any data */ - if (is_ring_empty(ring) || head == ring->next_to_clean) { - NETIF_TX_UNLOCK(ring); + if (is_ring_empty(ring) || head == ring->next_to_clean) return 0; /* no data to poll */ - } if (!is_valid_clean_head(ring, head)) { netdev_err(ndev, "wrong head (%d, %d-%d)\n", head, ring->next_to_use, ring->next_to_clean); ring->stats.io_err_cnt++; - NETIF_TX_UNLOCK(ring); return -EIO; } @@ -998,8 +984,6 @@ static int hns_nic_tx_poll_one(struct hn ring->stats.tx_pkts += pkts; ring->stats.tx_bytes += bytes; - NETIF_TX_UNLOCK(ring); - dev_queue = netdev_get_tx_queue(ndev, ring_data->queue_index); netdev_tx_completed_queue(dev_queue, pkts, bytes); @@ -1059,16 +1043,12 @@ static void hns_nic_tx_clr_all_bufs(stru int head; int bytes, pkts; - NETIF_TX_LOCK(ring); - head = ring->next_to_use; /* ntu :soft setted ring position*/ bytes = 0; pkts = 0; while (head != ring->next_to_clean) hns_nic_reclaim_one_desc(ring, &bytes, &pkts); - NETIF_TX_UNLOCK(ring); - dev_queue = netdev_get_tx_queue(ndev, ring_data->queue_index); netdev_tx_reset_queue(dev_queue); }