From patchwork Mon Jun 15 08:07:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11604169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 213D3912 for ; Mon, 15 Jun 2020 08:08:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F12E62074D for ; Mon, 15 Jun 2020 08:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592208485; bh=iJfh939iI3h+OWNmaq9Fea8SXgzPZvuVhgPWgf+fAvE=; h=From:To:Cc:Subject:Date:List-ID:From; b=KZ125sukqnAvWsaY0h4WyY0vRjGdHXJ75DjxARl0bCcbik7PuUCGkEJsXUORtZTWj k1kXhfE/IgN+LCRQPKE2qxwOiyLJZbV/GxdcggoGSSdruU8qtCpe442+XWsoh6ojFq iJbVtbMZ8sBqmUoWaGEXA+QxXmyAfM81h8RsIxg0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728860AbgFOIIE (ORCPT ); Mon, 15 Jun 2020 04:08:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:60896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728260AbgFOIIE (ORCPT ); Mon, 15 Jun 2020 04:08:04 -0400 Received: from PC-kkoz.proceq.com (unknown [213.160.61.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 88B67206E2; Mon, 15 Jun 2020 08:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592208483; bh=iJfh939iI3h+OWNmaq9Fea8SXgzPZvuVhgPWgf+fAvE=; h=From:To:Cc:Subject:Date:From; b=GfLNLR/ncBnXRH3pbRa3pVoMgc9chju3+cmZG4U/slQCnrS3TEeQKSHdqzi3ZhJ+7 Py0bopMgmUAXcVy7zU8LXRlUX8X3G7T/otWGEyP/jMjy242fHp65pM/NKhqqbUSHWY i4aqIIdDovs+WifikETKxUnEehfbBTXxdLp/6Oig= From: Krzysztof Kozlowski To: Mark Brown , Thomas Gleixner , Vladimir Oltean , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marc Kleine-Budde , Wolfram Sang , kernel@pengutronix.de, Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v2 1/3] spi: spi-fsl-dspi: Fix external abort on interrupt in exit paths Date: Mon, 15 Jun 2020 10:07:17 +0200 Message-Id: <1592208439-17594-1-git-send-email-krzk@kernel.org> X-Mailer: git-send-email 2.7.4 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org If interrupt comes late, during probe error path or device remove (could be triggered with CONFIG_DEBUG_SHIRQ), the interrupt handler dspi_interrupt() will access registers with the clock being disabled. This leads to external abort on non-linefetch on Toradex Colibri VF50 module (with Vybrid VF5xx): $ echo 4002d000.spi > /sys/devices/platform/soc/40000000.bus/4002d000.spi/driver/unbind Unhandled fault: external abort on non-linefetch (0x1008) at 0x8887f02c Internal error: : 1008 [#1] ARM CPU: 0 PID: 136 Comm: sh Not tainted 5.7.0-next-20200610-00009-g5c913fa0f9c5-dirty #74 Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree) (regmap_mmio_read32le) from [<8061885c>] (regmap_mmio_read+0x48/0x68) (regmap_mmio_read) from [<8060e3b8>] (_regmap_bus_reg_read+0x24/0x28) (_regmap_bus_reg_read) from [<80611c50>] (_regmap_read+0x70/0x1c0) (_regmap_read) from [<80611dec>] (regmap_read+0x4c/0x6c) (regmap_read) from [<80678ca0>] (dspi_interrupt+0x3c/0xa8) (dspi_interrupt) from [<8017acec>] (free_irq+0x26c/0x3cc) (free_irq) from [<8017dcec>] (devm_irq_release+0x1c/0x20) (devm_irq_release) from [<805f98ec>] (release_nodes+0x1e4/0x298) (release_nodes) from [<805f9ac8>] (devres_release_all+0x40/0x60) (devres_release_all) from [<805f5134>] (device_release_driver_internal+0x108/0x1ac) (device_release_driver_internal) from [<805f521c>] (device_driver_detach+0x20/0x24) Fixes: 349ad66c0ab0 ("spi:Add Freescale DSPI driver for Vybrid VF610 platform") Cc: Signed-off-by: Krzysztof Kozlowski --- This is an follow up of my other patch for I2C IMX driver [1]. Let's fix the issues consistently. [1] https://lore.kernel.org/lkml/1592130544-19759-2-git-send-email-krzk@kernel.org/T/#u Changes since v1: 1. Disable the IRQ instead of using non-devm interface. --- drivers/spi/spi-fsl-dspi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 58190c94561f..023e05c53b85 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -1400,7 +1400,7 @@ static int dspi_probe(struct platform_device *pdev) ret = dspi_request_dma(dspi, res->start); if (ret < 0) { dev_err(&pdev->dev, "can't get dma channels\n"); - goto out_clk_put; + goto disable_irq; } } @@ -1415,11 +1415,14 @@ static int dspi_probe(struct platform_device *pdev) ret = spi_register_controller(ctlr); if (ret != 0) { dev_err(&pdev->dev, "Problem registering DSPI ctlr\n"); - goto out_clk_put; + goto disable_irq; } return ret; +disable_irq: + if (dspi->irq > 0) + disable_irq(dspi->irq); out_clk_put: clk_disable_unprepare(dspi->clk); out_ctlr_put: @@ -1435,6 +1438,8 @@ static int dspi_remove(struct platform_device *pdev) /* Disconnect from the SPI framework */ dspi_release_dma(dspi); + if (dspi->irq > 0) + disable_irq(dspi->irq); clk_disable_unprepare(dspi->clk); spi_unregister_controller(dspi->ctlr); From patchwork Mon Jun 15 08:07:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11604171 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B7DD618 for ; Mon, 15 Jun 2020 08:08:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43AA6204EC for ; Mon, 15 Jun 2020 08:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592208490; bh=LUPoJCPiZ/wjm5oTIJ2xHNWoOg9h7BTPPnxEp9CP1Rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZX177yG0wb7hgG1FaRFGrRkIERhz4/KOcfsGr2TdTLu3i9jmN+it9M+5G3Ta5z1Rr XF12lSsXCPA7wDL/6fshy0RE24QXZYH8PfReN4MUaUUEHQryuedVgvDkNSzgzJGInq P7DZwizh0F8Q3QNkcR0u7rF+W3fPaYdWXXuxBdhw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728870AbgFOIIH (ORCPT ); Mon, 15 Jun 2020 04:08:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:60934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728260AbgFOIIG (ORCPT ); Mon, 15 Jun 2020 04:08:06 -0400 Received: from PC-kkoz.proceq.com (unknown [213.160.61.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BCD7E20739; Mon, 15 Jun 2020 08:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592208485; bh=LUPoJCPiZ/wjm5oTIJ2xHNWoOg9h7BTPPnxEp9CP1Rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y/jRKJDCe1kmUUnZACX5iG5uZnbo8a87qS/eLcoyn8WyMxZ8TZqNtsWgAUlDDoQVi r66uEnd1Cs4XmeFA0kJMzcRSXFaeiBJnZCMJLs7b6z4O8bku20AJTaoqMlngop29bs gWdzFS9HnTnB+NDjbSZN+b5DKNdGaWf6c+5Um3Qo= From: Krzysztof Kozlowski To: Mark Brown , Thomas Gleixner , Vladimir Oltean , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marc Kleine-Budde , Wolfram Sang , kernel@pengutronix.de, Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v2 2/3] spi: spi-fsl-dspi: Initialize completion before possible interrupt Date: Mon, 15 Jun 2020 10:07:18 +0200 Message-Id: <1592208439-17594-2-git-send-email-krzk@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592208439-17594-1-git-send-email-krzk@kernel.org> References: <1592208439-17594-1-git-send-email-krzk@kernel.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The interrupt handler calls completion and is IRQ requested before the completion is initialized. Logically it should be the other way. Fixes: 4f5ee75ea171 ("spi: spi-fsl-dspi: Replace interruptible wait queue with a simple completion") Cc: Signed-off-by: Krzysztof Kozlowski --- Changes since v1: 1. Rework the commit msg. --- drivers/spi/spi-fsl-dspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 023e05c53b85..080c5624bd1e 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -1385,6 +1385,8 @@ static int dspi_probe(struct platform_device *pdev) goto poll_mode; } + init_completion(&dspi->xfer_done); + ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, IRQF_SHARED, pdev->name, dspi); if (ret < 0) { @@ -1392,8 +1394,6 @@ static int dspi_probe(struct platform_device *pdev) goto out_clk_put; } - init_completion(&dspi->xfer_done); - poll_mode: if (dspi->devtype_data->trans_mode == DSPI_DMA_MODE) { From patchwork Mon Jun 15 08:07:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11604173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEC07912 for ; Mon, 15 Jun 2020 08:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 964F8206E2 for ; Mon, 15 Jun 2020 08:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592208494; bh=iJjCtGA60IxEMe6LqJFvQCe1OucL9pzPXJCoK6sfAig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iL0dHVG5pYhorVuT8q2Uczb7SeM8NFzXkxXeU0P0CEc92B45KNp/n/2hYRVbMJPXy OPR9S58MtidEsLeUrJFpw8Wnho+fJklFxiPlXJe0WtmzHt3uQshZqZlooUapcfkttI ln+Ei2I+2KkI70kpmSN6g8sujkL4iNrQytLo7zds= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728912AbgFOIIN (ORCPT ); Mon, 15 Jun 2020 04:08:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:32770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728875AbgFOIIH (ORCPT ); Mon, 15 Jun 2020 04:08:07 -0400 Received: from PC-kkoz.proceq.com (unknown [213.160.61.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E0F2520757; Mon, 15 Jun 2020 08:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592208487; bh=iJjCtGA60IxEMe6LqJFvQCe1OucL9pzPXJCoK6sfAig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v7dwvejmsHWlpMyATQrG+75DTVF8FiwOvhgsTE7tJQWKORGU7ymV3YxpI0TXd3HaI eS4YSCU5aHUSjyuEs3ANjls/o8cqQcuILm8bp/1DC74kSNgzqhlLRMb7+600nLnz7g HbCCS5bOwKcSEwP9U8l+vonOPtPCMKSmYxaaLmAQ= From: Krzysztof Kozlowski To: Mark Brown , Thomas Gleixner , Vladimir Oltean , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marc Kleine-Budde , Wolfram Sang , kernel@pengutronix.de, Krzysztof Kozlowski Subject: [PATCH v2 3/3] genirq: Do not test disabled IRQs with DEBUG_SHIRQ Date: Mon, 15 Jun 2020 10:07:19 +0200 Message-Id: <1592208439-17594-3-git-send-email-krzk@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592208439-17594-1-git-send-email-krzk@kernel.org> References: <1592208439-17594-1-git-send-email-krzk@kernel.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Testing events during freeing of disabled shared interrupts (CONFIG_DEBUG_SHIRQ) leads to false positives. The driver disabled interrupts on purpose to be sure that they will not fire during device removal. Signed-off-by: Krzysztof Kozlowski --- Changes since v1: 1. New patch. --- kernel/irq/manage.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 761911168438..f19f0dedc30d 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1775,12 +1775,14 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id) /* * It's a shared IRQ -- the driver ought to be prepared for an IRQ * event to happen even now it's being freed, so let's make sure that - * is so by doing an extra call to the handler .... + * is so by doing an extra call to the handler. + * Although the driver could disable the interrupts just before freeing + * just to avoid such trouble - don't test it then. * * ( We do this after actually deregistering it, to make sure that a * 'real' IRQ doesn't run in parallel with our fake. ) */ - if (action->flags & IRQF_SHARED) { + if (action->flags & IRQF_SHARED && !desc->depth) { local_irq_save(flags); action->handler(irq, dev_id); local_irq_restore(flags);