Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1286125rdb; Wed, 6 Dec 2023 14:13:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1pWkCuJSkaYfa/H0nlslrQ7TPXfE2k57HoZIHXa44Xtuha93njYKP+ChTW462G3Ga/NB3 X-Received: by 2002:a17:90a:e293:b0:286:6cc0:8854 with SMTP id d19-20020a17090ae29300b002866cc08854mr1394120pjz.65.1701900801647; Wed, 06 Dec 2023 14:13:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701900801; cv=none; d=google.com; s=arc-20160816; b=Qth7M0Y/6xcyiG5OSfVtN1mWizK7DAIpzA5n589qeBUyAQ/vWqpH5Z+y8B/yi2OplS W6pZku3UgS/1486pcJpX1bdK7+WVCckTwBpvNHCR0ZLE3qO+ZvU4QJDL/TEkAt/QFoXP TL5qtGPe9OweoVSLBJzONyS9IW7L4y/ilxVNYCU8kSyX4J1Nh6Vq3l6ULSSmMEBZgZUt oplDpgTmoa+UuLe1AUtyC502E3ofD1JTNo1RqiHGxbQYVRpt41cnVNj3TTiRrTgLdaKm +HxRnNeCe+71vvKsCiAS9Nl9dki+j7DVjEoLkbFMztxGsDeVk9v99qbBRzk8+BXXz3Y1 TOog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5egu1g9Tru7SArf6/+VY+BgDZ6yNjJGDV99QT7Y6Q+A=; fh=R21zpjKbl9YWrtu/YTsLnY0FeiDryfrWDIu5g6GjEVY=; b=wAbvIrT3rs9PcYCLYovXJbfo29a3GV0kwvdlL8eL1eXEinxKZAKVWCW1Nga6f/a4Hw mKquejuaVKNhtuB8o7gqy4O4oYOlOz+L7Q5YcczFtbrsYt+69F2H222x/8w5vAesEOCr vymp6hK0ZhpJ2Oklg5ZZB4zDeEjngWf21y5jM5Mt6f57CbLdaVW/+mPVM0p+c6rrTqAy V1q9pNzzmHa+EjJNVnAkZByxb37F4DHblhq4Hnojm3l8oISf37+XFf9RpkV2uYBnPG6Z XQ1vFHrww1JXHIG0PF7iaagb/Quan/O4V7wJfCm0OgsmLFypiUvQuiLQoxrAGla0/gvo P6qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=mMp2vAP7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id z15-20020a1709027e8f00b001cfc048af27si423610pla.584.2023.12.06.14.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 14:13:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=mMp2vAP7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 1ABCD82E2976; Wed, 6 Dec 2023 14:13:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbjLFWNA (ORCPT + 99 others); Wed, 6 Dec 2023 17:13:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjLFWM7 (ORCPT ); Wed, 6 Dec 2023 17:12:59 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0107DDE; Wed, 6 Dec 2023 14:13:04 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F1441556; Wed, 6 Dec 2023 23:12:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1701900742; bh=MyiZ0c9R7mhTEt9Q8JKoeIvrzUNTttSdhrpWfhqCogE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mMp2vAP7F/Z8TOEz4aQAFWxGxRVpyCWPin+FZNaj8aiBvsICy14SbeuqEFb3c2LrR aZettZBcgw6+h7/serhV0khPIeOsV21Xg0EICis0YA7YuKnsvNHW5ZgH1UhQ3q71h5 gK9A8sBWNSjy5ZXtE833/BI3GLT+3AiwdOhSSc6w= Date: Thu, 7 Dec 2023 00:13:09 +0200 From: Laurent Pinchart To: Tomi Valkeinen Cc: Dafna Hirschfeld , Mauro Carvalho Chehab , Heiko Stuebner , Paul Elder , Alexander Stein , kieran.bingham@ideasonboard.com, umang.jain@ideasonboard.com, aford173@gmail.com, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/4] media: rkisp1: Fix IRQ disable race issue Message-ID: <20231206221309.GD29417@pendragon.ideasonboard.com> References: <20231206-rkisp-irq-fix-v2-0-6ba4185eeb1f@ideasonboard.com> <20231206-rkisp-irq-fix-v2-4-6ba4185eeb1f@ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231206-rkisp-irq-fix-v2-4-6ba4185eeb1f@ideasonboard.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 14:13:19 -0800 (PST) Hi Tomi, Thank you for the patch. On Wed, Dec 06, 2023 at 12:12:31PM +0200, Tomi Valkeinen wrote: > In rkisp1_isp_stop() and rkisp1_csi_disable() the driver masks the > interrupts and then apparently assumes that the interrupt handler won't > be running, and proceeds in the stop procedure. This is not the case, as > the interrupt handler can already be running, which would lead to the > ISP being disabled while the interrupt handler handling a captured > frame. > > This brings up two issues: 1) the ISP could be powered off while the > interrupt handler is still running and accessing registers, leading to > board lockup, and 2) the interrupt handler code and the code that > disables the streaming might do things that conflict. > > It is not clear to me if 2) causes a real issue, but 1) can be seen with > a suitable delay (or printk in my case) in the interrupt handler, > leading to board lockup. > > Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart > --- > drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 14 +++++++++++++- > drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 20 +++++++++++++++++--- > 2 files changed, 30 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > index 47f4353a1784..0bab3303f2e4 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c > @@ -125,8 +125,20 @@ static void rkisp1_csi_disable(struct rkisp1_csi *csi) > struct rkisp1_device *rkisp1 = csi->rkisp1; > u32 val; > > - /* Mask and clear interrupts. */ > + /* Mask MIPI interrupts. */ > rkisp1_write(rkisp1, RKISP1_CIF_MIPI_IMSC, 0); > + > + /* Flush posted writes */ > + rkisp1_read(rkisp1, RKISP1_CIF_MIPI_IMSC); > + > + /* > + * Wait until the IRQ handler has ended. The IRQ handler may get called > + * even after this, but it will return immediately as the MIPI > + * interrupts have been masked. > + */ > + synchronize_irq(rkisp1->irqs[RKISP1_IRQ_MIPI]); > + > + /* Clear MIPI interrupt status */ > rkisp1_write(rkisp1, RKISP1_CIF_MIPI_ICR, ~0); > > val = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_CTRL); > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > index dafbfd230542..33b5a714d117 100644 > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c > @@ -364,11 +364,25 @@ static void rkisp1_isp_stop(struct rkisp1_isp *isp) > * ISP(mi) stop in mi frame end -> Stop ISP(mipi) -> > * Stop ISP(isp) ->wait for ISP isp off > */ > - /* stop and clear MI and ISP interrupts */ > - rkisp1_write(rkisp1, RKISP1_CIF_ISP_IMSC, 0); > - rkisp1_write(rkisp1, RKISP1_CIF_ISP_ICR, ~0); > > + /* Mask MI and ISP interrupts */ > + rkisp1_write(rkisp1, RKISP1_CIF_ISP_IMSC, 0); > rkisp1_write(rkisp1, RKISP1_CIF_MI_IMSC, 0); > + > + /* Flush posted writes */ > + rkisp1_read(rkisp1, RKISP1_CIF_MI_IMSC); > + > + /* > + * Wait until the IRQ handler has ended. The IRQ handler may get called > + * even after this, but it will return immediately as the MI and ISP > + * interrupts have been masked. > + */ > + synchronize_irq(rkisp1->irqs[RKISP1_IRQ_ISP]); > + if (rkisp1->irqs[RKISP1_IRQ_ISP] != rkisp1->irqs[RKISP1_IRQ_MI]) > + synchronize_irq(rkisp1->irqs[RKISP1_IRQ_MI]); > + > + /* Clear MI and ISP interrupt status */ > + rkisp1_write(rkisp1, RKISP1_CIF_ISP_ICR, ~0); > rkisp1_write(rkisp1, RKISP1_CIF_MI_ICR, ~0); > > /* stop ISP */ -- Regards, Laurent Pinchart