Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp868436rdb; Wed, 6 Dec 2023 02:08:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQIxZfxchxGKWxCUwKJdxtd5N/jy64B6mUhsiqoGPTTj/lz1EHCYvGGtxTCsTv/Utqmfl6 X-Received: by 2002:a05:6a21:6d97:b0:18b:9041:5729 with SMTP id wl23-20020a056a216d9700b0018b90415729mr849783pzb.17.1701857317208; Wed, 06 Dec 2023 02:08:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701857317; cv=none; d=google.com; s=arc-20160816; b=OenAuVpmP4FpPFRfmtcrTflNeOXW+qpqrVXQmZIinYgD6l2CssAloa3O8OUNUQZzwJ pPuhQXFPCJ9WjnioLiBrb8XbrCvtQd4AIsVsyn2uf8xReekaiPdEikzVGRP+K8tAJk5Q YeTqHWrb9bQmKiCCLpRshCiYKWgpw0dAfyB5Oh0BmcvZ6lPeF46fwebJ/fGV2xoSxakq V1IFfKNbzmtu+F48AOIkFg2BXRpqJMMRirXKS8D1AZ0IsWUAvom8D3zM4pBLE+JGhco9 2XTXtC2dIrwMvyVQvoWlF4txtnZKna3GhV7jS+rIEY+SGY/8S6Ao+nVGx2posq/7nJVM 4u0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=V46GJsXBP+6HGqwYsnI6bOgK48vwGszpdAfG2rpYpZY=; fh=tme7j8kxe+bl8/nZ+qVhPWeazCvcSJ8NfR7yBtPaJyw=; b=WdPHEnXvZr+O0Us90W73MbRF/gRD1MVJR2aL48NUSIltbfZGWKUAIrjZ198Zv/J+Vs i2U+VZNpJgGbP/CYQYg2QpKtnJoU8BXwWGGji9EegJ/zoq3Q8UsSAePUUqJCyWmYvrJ/ mvu91zG/cKcwkNxSiW8Wr5Kd0Ju4j4s71t3MH3vqiEaK7I4DUSLHQ7dn9hfCeo6czfJk wWvjJFINZP2x81alBEoiB+gym47DVuGqrIzXhXU6i4l8lgCX4rxuXPT1B9qRj+KLEHvv k+DNH8gUvYkMYVV8ZU/ixvfPeGxZLjI1aQHVY9Wgfnds+WTgJCTMdsVAQBuMTXqcEqyC bYwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ejFFmGl7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id k9-20020aa788c9000000b006ce4e7a30casi246471pff.76.2023.12.06.02.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:08:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ejFFmGl7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 04E5B802F688; Wed, 6 Dec 2023 02:08:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377387AbjLFKIG (ORCPT + 99 others); Wed, 6 Dec 2023 05:08:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377385AbjLFKID (ORCPT ); Wed, 6 Dec 2023 05:08:03 -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 8C7D8109; Wed, 6 Dec 2023 02:08:08 -0800 (PST) Received: from [192.168.88.20] (91-158-149-209.elisa-laajakaista.fi [91.158.149.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B964E45; Wed, 6 Dec 2023 11:07:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1701857244; bh=XYVNV7G4X7YzqJ49hmgXShVAk3zY/kjKTxOWrKENMz4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ejFFmGl7bYIEd00VbGSNJVOBmRnVux/HBu5EK8nX1AhVeMCHObhj6efqrWfNm2p1M nES/yTI6Uj951BAPIlUjL95YkOfh4u5iyao+NE+ZU7JqYNvMO75ZX//hXUz27qiMI5 wIRUMKsR7k+FrBvgbhtKuQW7nBPMzjpEU3mIFaeA= Message-ID: Date: Wed, 6 Dec 2023 12:08:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/4] media: rkisp1: Fix IRQ disable race issue Content-Language: en-US To: Laurent Pinchart 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 References: <20231205-rkisp-irq-fix-v1-0-f4045c74ba45@ideasonboard.com> <20231205-rkisp-irq-fix-v1-4-f4045c74ba45@ideasonboard.com> <20231205121355.GE17394@pendragon.ideasonboard.com> From: Tomi Valkeinen Autocrypt: addr=tomi.valkeinen@ideasonboard.com; keydata= xsFNBE6ms0cBEACyizowecZqXfMZtnBniOieTuFdErHA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iXkXSIaQ6YMEs8WjBbpP81h7QxWIfWtp+VnwNGc6nq5IQDESH mvQcsFS7d3eGVI6eyjCFdcAO8eMAEQEAAcLBXwQYAQIACQUCTqazRwIbDAAKCRD6PaqMvJYe 9fA7EACS6exUedsBKmt4pT7nqXBcRsqm6YzT6DeCM8PWMTeaVGHiR4TnNFiT3otD5UpYQI7S suYxoTdHrrrBzdlKe5rUWpzoZkVK6p0s9OIvGzLT0lrb0HC9iNDWT3JgpYDnk4Z2mFi6tTbq xKMtpVFRA6FjviGDRsfkfoURZI51nf2RSAk/A8BEDDZ7lgJHskYoklSpwyrXhkp9FHGMaYII m9EKuUTX9JPDG2FTthCBrdsgWYPdJQvM+zscq09vFMQ9Fykbx5N8z/oFEUy3ACyPqW2oyfvU CH5WDpWBG0s5BALp1gBJPytIAd/pY/5ZdNoi0Cx3+Z7jaBFEyYJdWy1hGddpkgnMjyOfLI7B CFrdecTZbR5upjNSDvQ7RG85SnpYJTIin+SAUazAeA2nS6gTZzumgtdw8XmVXZwdBfF+ICof 92UkbYcYNbzWO/GHgsNT1WnM4sa9lwCSWH8Fw1o/3bX1VVPEsnESOfxkNdu+gAF5S6+I6n3a ueeIlwJl5CpT5l8RpoZXEOVtXYn8zzOJ7oGZYINRV9Pf8qKGLf3Dft7zKBP832I3PQjeok7F yjt+9S+KgSFSHP3Pa4E7lsSdWhSlHYNdG/czhoUkSCN09C0rEK93wxACx3vtxPLjXu6RptBw 3dRq7n+mQChEB1am0BueV1JZaBboIL0AGlSJkm23kw== In-Reply-To: <20231205121355.GE17394@pendragon.ideasonboard.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:08:34 -0800 (PST) On 05/12/2023 14:13, Laurent Pinchart wrote: > 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. I don't think it needs an update, as the irq handling is divided into multiple parts. The handler here may get called due to a MI or ISP interrupt, and vice versa. Tomi > >> + 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 */ >