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); } From patchwork Mon Nov 11 18:28:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179111 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7037275ilf; Mon, 11 Nov 2019 10:44:06 -0800 (PST) X-Google-Smtp-Source: APXvYqxLc3wjlIzn2AfCoUn9jdqUAG5vK1ptrNixjPNTsXSY2PyfRPZm1tlbZHeLZwWuMJ69siJ5 X-Received: by 2002:a17:906:b2c7:: with SMTP id cf7mr16661030ejb.218.1573497846023; Mon, 11 Nov 2019 10:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573497846; cv=none; d=google.com; s=arc-20160816; b=Nhe1BfUcq21p07BKmMCRV5aM8chhjW8qQZ1+m/Cq6iDxr1WffOJ7PBkoLnDSUETQch YQ8FVKIy4A44ASYRbe7/2aW2AeruuHEq/R0XftEmt+RfLTxNzgtQzjWF7taPOqtFZ3iW LAc8RtHzH1Ko6Y9+PFskY/S4RwLBaq++JLX0xkOKHD5Hgh59hOFB2Fv92L939KySqz78 Uc/14waXuzhStv/RVuhXkrg3l8FGCUsGNDhbaLfcyLtq/rBFFqZy2Cc51l26BJCZNVsW RjP2mFrR6LdFtPMiLg3/bOIwejdbXMlubkc/ya5/IKes1mOc/vrbNhSJghA4UBKwIq/L cmsA== 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=+0+rLiFD4QvbVWJ3wNwc/OVy5xC0qWj6HSQ1CggMqFE=; b=Xf5dSWIjLIOeeOx3nrPcgZAU+8Jfxs4XCr/fltQMBGJ2aoCqhJbT9rF4RY/iRLbT7a xnHx+v7vc9jyRrQByCjIsLMYE8UpC0weLI3qQbVgEmQXkwPCFT4/JcupU+h7TJaBCiS5 YCMw/h9rit4izqSgIQU5Qu0XP8lljoJr0NQHy4x19B94Q40CVq+FfKUJJ4CtPH0txoS8 rlfhVbAddGYyo4IvWbN9cROYkA0PoU5NfY1MgZYNQ1VY/8rMZXyhPusTOUAbhuYaUsru Vf2Zo4gcYNVBXpCLAUA4tamW9W3Ozjo3q5jCCCxcCwGKi5zUAQ572JzjmaID/Tq4jqI9 0UbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sscScEYy; 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 h18si11062593edh.352.2019.11.11.10.44.05; Mon, 11 Nov 2019 10:44:06 -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=sscScEYy; 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 S1728149AbfKKSoE (ORCPT + 14 others); Mon, 11 Nov 2019 13:44:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:35602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728130AbfKKSoD (ORCPT ); Mon, 11 Nov 2019 13:44:03 -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 55BD6204FD; Mon, 11 Nov 2019 18:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497841; bh=dywrqtEgRpBStaOON3XI5ekgKLo9hIVBLPXy10+jWHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sscScEYyhU1DXMlrhNckLb9Z9ehXvUR3UZ/FemxJHkID7jebj3rMTeApHbZVouaaE 4W+BEQb7Xw8bwslitM1q3huFJf+vJVJtc+II+62OuYYMzV+WT8DrMvUzN1AsS3nm7+ d3F3/9OfblZrBQQ2hhWdU0AmCXEPH9QH4zMhTafc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhenfang Wang , Baolin Wang , Vinod Koul , Sasha Levin Subject: [PATCH 4.19 072/125] dmaengine: sprd: Fix the possible memory leak issue Date: Mon, 11 Nov 2019 19:28:31 +0100 Message-Id: <20191111181449.739146488@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: Baolin Wang [ Upstream commit ec1ac309596a7bdf206743b092748205f6cd5720 ] If we terminate the channel to free all descriptors associated with this channel, we will leak the memory of current descriptor if the current descriptor is not completed, since it had been deteled from the desc_issued list and have not been added into the desc_completed list. Thus we should check if current descriptor is completed or not, when freeing the descriptors associated with one channel, if not, we should free it to avoid this issue. Fixes: 9b3b8171f7f4 ("dmaengine: sprd: Add Spreadtrum DMA driver") Reported-by: Zhenfang Wang Tested-by: Zhenfang Wang Signed-off-by: Baolin Wang Link: https://lore.kernel.org/r/170dbbc6d5366b6fa974ce2d366652e23a334251.1570609788.git.baolin.wang@linaro.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/sprd-dma.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 2.20.1 diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index 1ed1c7efa2885..9e8ce56a83d8a 100644 --- a/drivers/dma/sprd-dma.c +++ b/drivers/dma/sprd-dma.c @@ -181,6 +181,7 @@ struct sprd_dma_dev { struct sprd_dma_chn channels[0]; }; +static void sprd_dma_free_desc(struct virt_dma_desc *vd); static bool sprd_dma_filter_fn(struct dma_chan *chan, void *param); static struct of_dma_filter_info sprd_dma_info = { .filter_fn = sprd_dma_filter_fn, @@ -493,12 +494,19 @@ static int sprd_dma_alloc_chan_resources(struct dma_chan *chan) static void sprd_dma_free_chan_resources(struct dma_chan *chan) { struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); + struct virt_dma_desc *cur_vd = NULL; unsigned long flags; spin_lock_irqsave(&schan->vc.lock, flags); + if (schan->cur_desc) + cur_vd = &schan->cur_desc->vd; + sprd_dma_stop(schan); spin_unlock_irqrestore(&schan->vc.lock, flags); + if (cur_vd) + sprd_dma_free_desc(cur_vd); + vchan_free_chan_resources(&schan->vc); pm_runtime_put(chan->device->dev); } @@ -814,15 +822,22 @@ static int sprd_dma_resume(struct dma_chan *chan) static int sprd_dma_terminate_all(struct dma_chan *chan) { struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); + struct virt_dma_desc *cur_vd = NULL; unsigned long flags; LIST_HEAD(head); spin_lock_irqsave(&schan->vc.lock, flags); + if (schan->cur_desc) + cur_vd = &schan->cur_desc->vd; + sprd_dma_stop(schan); vchan_get_all_descriptors(&schan->vc, &head); spin_unlock_irqrestore(&schan->vc.lock, flags); + if (cur_vd) + sprd_dma_free_desc(cur_vd); + vchan_dma_desc_free_list(&schan->vc, &head); return 0; }