Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp530573lqb; Thu, 29 Feb 2024 07:49:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWnEzdjWA8hEJZ/uTu7UV7cvMcEavrNj7nvUJ3kxOSS8vvNdYgVm+37KP2QY226XVIbsZVZMbL9jme6i9GtEx78ArySwav8CTuoLPxtpw== X-Google-Smtp-Source: AGHT+IHXj+kSjeCmnr4AKPN7d3EgtDhp/FhIvEJto1hNN/D4SsCeeYZwVVzxWT8JONCQTFiT26TG X-Received: by 2002:a05:6a20:bb27:b0:1a0:ce38:34d5 with SMTP id fc39-20020a056a20bb2700b001a0ce3834d5mr2229612pzb.61.1709221775831; Thu, 29 Feb 2024 07:49:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709221775; cv=pass; d=google.com; s=arc-20160816; b=FGRnyM10gdFxWD/M21JqwMsBnwg95bVIUIW5nHQHaR+eEj/ulhHyBZeMxbVZYfhdgB Zr545Ov+lCzAD26rU/3oy1/6TXn8NtsMkmOB/Ic/0WGNdM1h3EdON2tER9K/5LmVv6vS yl07GK4nQOt+Bx3JDnPmYD4+oMkK1+Joq8Nz8SvESNdLYMNiiTpTbHrstrCyu1EZAEkx On6ld9x7OoyaVfwQwMXfgUKHSFLetJvmlqsl8vDcos51RvBGidRvngD3ZmiaJH0sd00S tChLIzG2NPD8Ir5LoaYwo6TmyxQ2ylI4fNgJV39YaEjFR6SmLCi9C62DDLO2z7M3BStE WgWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oUMAcMHkV+lFo7Pd7CPzajMnqGdTsRLPl2hW1DMkl7U=; fh=N2jKcm+f4iSNzS/oF9lJJUN5Hqv7xdEP1RlIS4q746o=; b=udFFS8CwRxcwr6Lp+kyRjIhHFU4e4zAQQEZggiyHlnfqtIeuwwgLPRYWJzjZQEYNsn 8CJzaunYjd3xUJb/lhGZ9x0586mEu1gHinzo9szYaoY60A0OOvoRjNeSCaXl4yLP1kYz GZ7z3+XuOKBMQiCRmFGLKVRrdL5nsEW0GkRjRsbnhgJ9k1HyqFFVwwk0Vn1VliBZHc1B wMqcjGgFcvQ4zqS5de98H4j0+B41Fbg+8fnMW2WCAXcWwju4OY9GzdP6hdWOWr1I+AXy U1XjwlTO0sYotz+uvnTZol6sFAH1k9iHwgjmomIeDZGog6/rLHuZZZYk4JZ6JY0Tkl31 odmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KvyEpUAD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86949-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86949-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z24-20020a634c18000000b005dc87643ccdsi1567574pga.79.2024.02.29.07.49.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 07:49:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86949-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KvyEpUAD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86949-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86949-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6A28CB21640 for ; Thu, 29 Feb 2024 15:49:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE8DF14D43E; Thu, 29 Feb 2024 15:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KvyEpUAD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD39D14AD2B; Thu, 29 Feb 2024 15:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709221735; cv=none; b=HFCu6ic2V/lZAVGIbfWAvmUwprULAjDIqVFCFDG0q/lS1BcRdytCbof6hM9omkg9v41XMjH8vhPHFiEDjS2fgrHZmrpFBzEGmSSI9iQ9yGLuZmuUpJdNWR3/ds18S0YDNwR7sLGmfTfy7YJRvoLk81SNg7dU2yR7Y13VTAac37A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709221735; c=relaxed/simple; bh=G78L1tou1cSU+q6VxHI+foG7pc7rJWJylN4hyYR0c6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q4t3gCIjmn/sNPlLrruV+QngJ8QMburCpiowFT0GqbQYTXShjRPYys1dKl/8/7ot56T5WQZQunItzE/ntmvwhQJHzcq4bV9Y5OPBb5FAeRBtQryRFRj9/jbT+A+r9tco04SPnfyb0F3qJBGFbVPHpkHc0CeMpl8jMTZXJWgueW0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KvyEpUAD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE44BC43394; Thu, 29 Feb 2024 15:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709221735; bh=G78L1tou1cSU+q6VxHI+foG7pc7rJWJylN4hyYR0c6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KvyEpUADWEiU0fo1pk4xzrRuD6JfCCpnxVDuA06gZ5/xne7xNbSE122ppZKrHwvgm y8N5D888RCKGneBmV3z7vLb0+Y42rm+P+p6x+RcgaZFC/ibmTB6cZjxx/abrffG14t ft+GmbdEVR2VdRo3iPo1NSdBy6MCaiNWRPIuAGk7RMDkg7ZXqTosSab4YQ15pF1gky 6FCce7YXDdW0O2GGEa7hVF5BjIS26tMyMIQhEh3eoP8eEyQBI/uqcvq9oYxtSGjCdJ cTzxsT0NtG+YYKhijiKFcHvI5Twrr8m7Ypk1NyjbqIMqRIkNQNEqTgHep2HV0H0rVg tH06k7Ci0F6+g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tomi Valkeinen , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin , dafna@fastmail.com, heiko@sntech.de, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 6.7 02/26] media: rkisp1: Fix IRQ handling due to shared interrupts Date: Thu, 29 Feb 2024 10:48:21 -0500 Message-ID: <20240229154851.2849367-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229154851.2849367-1-sashal@kernel.org> References: <20240229154851.2849367-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7.6 Content-Transfer-Encoding: 8bit From: Tomi Valkeinen [ Upstream commit ffb635bb398fc07cb38f8a7b4a82cbe5f412f08e ] The driver requests the interrupts as IRQF_SHARED, so the interrupt handlers can be called at any time. If such a call happens while the ISP is powered down, the SoC will hang as the driver tries to access the ISP registers. This can be reproduced even without the platform sharing the IRQ line: Enable CONFIG_DEBUG_SHIRQ and unload the driver, and the board will hang. Fix this by adding a new field, 'irqs_enabled', which is used to bail out from the interrupt handler when the ISP is not operational. Link: https://lore.kernel.org/r/20231218-rkisp-shirq-fix-v1-2-173007628248@ideasonboard.com Signed-off-by: Tomi Valkeinen Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- .../platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ .../platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ .../platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ .../platform/rockchip/rkisp1/rkisp1-dev.c | 22 +++++++++++++++++++ .../platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ 5 files changed, 33 insertions(+) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index c6d7e01c89494..3752b702e270b 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -725,6 +725,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) unsigned int i; u32 status; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); if (!status) return IRQ_NONE; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h index 2d7f06281c390..a4e272adc1ad0 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h @@ -449,6 +449,7 @@ struct rkisp1_debug { * @debug: debug params to be exposed on debugfs * @info: version-specific ISP information * @irqs: IRQ line numbers + * @irqs_enabled: the hardware is enabled and can cause interrupts */ struct rkisp1_device { void __iomem *base_addr; @@ -470,6 +471,7 @@ struct rkisp1_device { struct rkisp1_debug debug; const struct rkisp1_info *info; int irqs[RKISP1_NUM_IRQS]; + bool irqs_enabled; }; /* diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c index 702adee83322b..7320c1c72e688 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c @@ -196,6 +196,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); u32 val, status; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); if (!status) return IRQ_NONE; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c index acc559652d6eb..73cf08a740118 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c @@ -305,6 +305,24 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) { struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); + rkisp1->irqs_enabled = false; + /* Make sure the IRQ handler will see the above */ + mb(); + + /* + * Wait until any running IRQ handler has returned. The IRQ handler + * may get called even after this (as it's a shared interrupt line) + * but the 'irqs_enabled' flag will make the handler return immediately. + */ + for (unsigned int il = 0; il < ARRAY_SIZE(rkisp1->irqs); ++il) { + if (rkisp1->irqs[il] == -1) + continue; + + /* Skip if the irq line is the same as previous */ + if (il == 0 || rkisp1->irqs[il - 1] != rkisp1->irqs[il]) + synchronize_irq(rkisp1->irqs[il]); + } + clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); return pinctrl_pm_select_sleep_state(dev); } @@ -321,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) if (ret) return ret; + rkisp1->irqs_enabled = true; + /* Make sure the IRQ handler will see the above */ + mb(); + return 0; } diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c index 5fbc47bda6831..caffea6a46186 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c @@ -971,6 +971,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); u32 status, isp_err; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); if (!status) return IRQ_NONE; -- 2.43.0