Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp236375rdb; Tue, 5 Dec 2023 04:14:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFsqvgFUL9mDOrUqYmcPTYKv/YQZJ6BFBIkFMqf4gr3zyijwsDXj3fVKx8sGNS7OvXWLry X-Received: by 2002:a05:6a20:938b:b0:18f:97c:8241 with SMTP id x11-20020a056a20938b00b0018f097c8241mr3700042pzh.75.1701778452369; Tue, 05 Dec 2023 04:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701778452; cv=none; d=google.com; s=arc-20160816; b=JxqjwMPkGXVr/JA1DUe/pLD3oEKVToVxYUPWNcTQFTZhGY9WTLeRumUczjkMEoWxQm sSpXsjiBB8ViJMXeshvA+yXjE2YPP47xfnxGqPHJEYN1Dy2Dt8WXoZ74XM4HKk9gMP3N 9AgD6O2SylckZMUVQOELztqe5tL4jv40Rm0s/5VRmZfLOzXPvnAD7DDRgVFVpLLIWLvd /asqvqM9MOhPMdmlXuhlC8IVS43qD1ie6SvfJgI2HkaqhxBdclqV82dP1XzlTxVXS/Gg zMzjTDzv0w4w+DeiDoL2yd52X8+sBPAv7CbEuK4v0u/qm1adUbgDXABg1IpHZ2hGr/w4 7llQ== 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=TrTmgOUw07vBZ4rQfXPl8iIewFgFEwN8gioUE9qiz94=; fh=R21zpjKbl9YWrtu/YTsLnY0FeiDryfrWDIu5g6GjEVY=; b=sMazBTzEbWUGPIl9HofeLnuwvQ9+GPmSdXPDdAT625dabJGSwyIVWQcxBDsNKDpcb/ i5o+NLysh2UljWBN2JGxFg7bCjBNcEu35H5CoEJFA2w+ns++w1MCC2+7wz8n8anBVcz5 p+109LYAq8NIX2SE/Wek6tn4QyJNG7r0m7D0+r9x+GLW0uFvBUBtWMvpp2iO9bjzjkcD 5+WVGjlMqE8tLwKklXEmOgdfTdH0McOTqSkLQlFPkqVHz+/jPtV1eYiY4GHDyFG2EtQp 5qe8vxuRBieHdcFyUhPO6BVBeIbqB7okh9MV/nIicfUMXLLhUL282DbRHlRfDUcYegux tXwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Q6OEmb5m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b15-20020a056a000a8f00b006cb93f13d52si9657198pfl.120.2023.12.05.04.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 04:14:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Q6OEmb5m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id C1ED78075B07; Tue, 5 Dec 2023 04:14:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbjLEMNr (ORCPT + 99 others); Tue, 5 Dec 2023 07:13:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235123AbjLEMNp (ORCPT ); Tue, 5 Dec 2023 07:13:45 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 718D4D7; Tue, 5 Dec 2023 04:13:50 -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 619B6844; Tue, 5 Dec 2023 13:13:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1701778388; bh=0ZLr3kFQ/SRckdRD/WtVOMYCg8x0SdcGPUxWJlxbTSQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q6OEmb5m+LGJD4zSLWKgY92Ie7m6mdi0BK0wkagE6rqjc15tEFpTp2Alyi8NZdMc/ IVN84yY+f6rc2thMg75CK6Mh5IXgqRxFn6emZA2ubX4vWZgu70mWDQw38aBHKcntxp mgTMuGzaeP9wD78HMIR1Zzmf8dhnZ2LhI6sYITNI= Date: Tue, 5 Dec 2023 14:13:55 +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 4/4] media: rkisp1: Fix IRQ disable race issue Message-ID: <20231205121355.GE17394@pendragon.ideasonboard.com> References: <20231205-rkisp-irq-fix-v1-0-f4045c74ba45@ideasonboard.com> <20231205-rkisp-irq-fix-v1-4-f4045c74ba45@ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231205-rkisp-irq-fix-v1-4-f4045c74ba45@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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 05 Dec 2023 04:14:09 -0800 (PST) Hi Tomi, Thank you for the patch. On Tue, Dec 05, 2023 at 10:09:35AM +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. > > It is not clear to me if this problem causes a real issue, but shutting > down the ISP while an interrupt handler is running sounds rather bad. Agreed. > Signed-off-by: Tomi Valkeinen > --- > 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 f6b54654b435..f0cef766fc0c 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. > + */ This comment will need to be updated if patch 3/4 gets replaced by a patch that drops IRQF_SHARED. > + 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 d6b8786661ad..a6dd497c884c 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. > + */ Same here. > + 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]); It would be nice if we could avoid the double synchronize_irq() for platforms where RKISP1_IRQ_MIPI and RKISP1_IRQ_ISP are identical, but I understand that would be difficult. > + > + /* 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