From patchwork Sat Jul 8 08:11:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 785821 X-Patchwork-Delegate: openwrt@kresin.me Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x4PNB3Yrsz9s7C for ; Sat, 8 Jul 2017 18:12:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="S4LM87mt"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OrnrANoF"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8cORLt/HvCWG6LvWicIzVC9SUpRoVhgT+ZkGqN9/YJs=; b=S4LM87mthfTUuE rSw8C52C2i6WG/htWjf5QU5U5tmi0ak8Y5QTkLWa685/zaH3HSYwIhEN7fnkd6D0VMf2L5EEIpmsA viGWWBHZaZdqtNutRBL2fa6nHFNcDGqN/EHRvDOzmz7cg1/sFr9/FF1W8l2z983lbs/87cuh2oh4/ oLivkNTILCPD7uH6kEKvsQH3H3GIS3j3C1TpzyQ3roNugMDC31yirpkSzgZ4+HKlHOYuzz3ZcKGtQ Ejn4qSG1GWrZvHsAgvYSxzV1ujLhA9PFH/HRPvXNFVt3a8A6VmX5lKcA0xu8iQudIhk7Kf9POMFde uLgSfc5uVI8Cgc4TFevg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dTkqU-0000gi-Sq; Sat, 08 Jul 2017 08:12:06 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dTkqR-0000fq-PP for lede-dev@lists.infradead.org; Sat, 08 Jul 2017 08:12:05 +0000 Received: by mail-wr0-x243.google.com with SMTP id x23so12464179wrb.0 for ; Sat, 08 Jul 2017 01:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T48Jb9IxIOhCuyZm2KrjEAMJUhOEV/8AX1/L/obCH1k=; b=OrnrANoFFlCkFEXryRGdfYqmDqFkMvhesw7KxhSOoKZjxfnysXItPekXeXTuoh+ZBZ svc0YwMjUXSUT2O9Q7kIIsIY9z++IAOM8uqw9V6mtP0b0xDABezQDp2W6xzU0QlFCna5 0eTm+ZIjEES8JMFtYJp08aJYQGZfAuyM0/Hb7EiJFJlLuHGymzb6zphn32GeFgPi16qb kYdGH0xYVeJsD+3OENSFArqthnizfdZppT7XO2ilT9DvCWZBMkHxcvxY1V8WKrLpUjXl JVeHbo3/W5rrqpyFqhhFcZ98rwcHt9yfNVfj11eUUnOsVKB9zfv8ov9AcK1ATNst5LZk Oq7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T48Jb9IxIOhCuyZm2KrjEAMJUhOEV/8AX1/L/obCH1k=; b=Nj9lnKXOih7GkPxGMPB682tMTVuVb9Q2gxjZr9f/kZpqAj8WbYjfsMd2d7hw+lf/hc XKdTvmMHU0or/sc9BT+mBoHrs+EK2crppYoD6lKX6CydStNuYkgzq4kkP45SpTXBkzkR BUXNirkiGIPCXIhfaO3/S6EoV0RVVjXOIfkPjnSrUDbri6eQiZm2QHANnNZnMcLr9YZ5 X9jaZKgHxAdrMjoI9pF1aQXzPxAbCDaxnKa22tcI+vF0eWQEUCYzKdXVyIw/T51ktosM CcMe7Y5KIf+pPhfRGze6CDcUSm6VZFu7qWsUaZaQxaMSucpZ2IX9i+xLV4WaqC4Lh+aa G5Hw== X-Gm-Message-State: AIVw1130dXpL24ggZ177NoYCvxQy7zWlMZHZKE5p7PArz7yV1//LiJif Sr8UzJbhAO7V/g== X-Received: by 10.28.32.5 with SMTP id g5mr1612829wmg.70.1499501499832; Sat, 08 Jul 2017 01:11:39 -0700 (PDT) Received: from localhost.localdomain ([95.236.121.249]) by smtp.gmail.com with ESMTPSA id w198sm2340796wme.21.2017.07.08.01.11.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Jul 2017 01:11:38 -0700 (PDT) From: Andrea Merello To: john@phrozen.org Date: Sat, 8 Jul 2017 10:11:11 +0200 Message-Id: <1499501471-7398-1-git-send-email-andrea.merello@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <17466737-2781-bacd-7384-64c1835f8b3e@phrozen.org> References: <17466737-2781-bacd-7384-64c1835f8b3e@phrozen.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170708_011204_036395_6764D77C X-CRM114-Status: GOOD ( 16.46 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (andrea.merello[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH] [Lantiq][net]: fix sleep with spinlock held in xrx200 network driver X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: m@kresin.me, Andrea Merello , lede-dev@lists.infradead.org MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In the xrx200_close() function we call napi_disable(), that could sleep, with priv->hw->chan[i].lock held. This could lead to deadlock and causes the kernel to complain. Look at the code I couldn't convince myself about why we need to protect that specific code part with the lock. IMHO there seems no reason to protect the refcount variables, because AFAIK ndo_close() and ndo_open() callbacks are already called with a semaphore held. Neither I could figure out why napi_disable() have to be called with that lock held. The only remaining code part for which I could guess the lock is useful for is ltq_dma_close() function call. This patch reduces the lock to the said function call, avoiding the sleep-with-spinlock-held situation Signed-off-by: Andrea Merello --- .../patches-4.9/0027-NET-lantiq-xrx200-fixes.patch | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 target/linux/lantiq/patches-4.9/0027-NET-lantiq-xrx200-fixes.patch diff --git a/target/linux/lantiq/patches-4.9/0027-NET-lantiq-xrx200-fixes.patch b/target/linux/lantiq/patches-4.9/0027-NET-lantiq-xrx200-fixes.patch new file mode 100644 index 0000000..a7fe6ab --- /dev/null +++ b/target/linux/lantiq/patches-4.9/0027-NET-lantiq-xrx200-fixes.patch @@ -0,0 +1,51 @@ +From a1db9d8df3f2fc627bd80fabd6eaf8ecbb263475 Mon Sep 17 00:00:00 2001 +From: Andrea Merello +Date: Sat, 8 Jul 2017 09:18:11 +0200 +Subject: [PATCH] [Lantiq][net]: fix sleep with spinlock held in xrx200 network + driver + +In the xrx200_close() function we call napi_disable(), that could +sleep, with priv->hw->chan[i].lock held. This could lead to deadlock +and causes the kernel to complain. + +Look at the code I couldn't convince myself about why we +need to protect that specific code part with the lock. IMHO there +seems no reason to protect the refcount variables, because AFAIK +ndo_close() and ndo_open() callbacks are already called with a +semaphore held. Neither I could figure out why napi_disable() have to +be called with that lock held. The only remaining code part for +which I could guess the lock is useful for is ltq_dma_close() +function call. + +This patch reduces the lock to the said function call, avoiding the +sleep-with-spinlock-held situation + +Signed-off-by: Andrea Merello +--- + drivers/net/ethernet/lantiq_xrx200.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c +index 0d2bfe7..b7d9afd 100644 +--- a/drivers/net/ethernet/lantiq_xrx200.c ++++ b/drivers/net/ethernet/lantiq_xrx200.c +@@ -898,14 +898,15 @@ static int xrx200_close(struct net_device *dev) + for (i = 0; i < XRX200_MAX_DMA; i++) { + if (!priv->hw->chan[i].dma.irq) + continue; +- spin_lock_bh(&priv->hw->chan[i].lock); ++ + priv->hw->chan[i].refcount--; + if (!priv->hw->chan[i].refcount) { + if (XRX200_DMA_IS_RX(i)) + napi_disable(&priv->hw->chan[i].napi); ++ spin_lock_bh(&priv->hw->chan[i].lock); + ltq_dma_close(&priv->hw->chan[XRX200_DMA_RX].dma); ++ spin_unlock_bh(&priv->hw->chan[i].lock); + } +- spin_unlock_bh(&priv->hw->chan[i].lock); + } + + return 0; +-- +2.7.4