Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp385815rdb; Mon, 22 Jan 2024 07:15:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFvpDVhSeWEhJLM7S7PHiRdghVXW1ZysOpwuxxi47KLXmUdW40L6bb23cAAadSFOa/ya+h X-Received: by 2002:a05:6808:3994:b0:3bd:4967:f9fb with SMTP id gq20-20020a056808399400b003bd4967f9fbmr6520285oib.45.1705936558533; Mon, 22 Jan 2024 07:15:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705936558; cv=pass; d=google.com; s=arc-20160816; b=w82VFGef/+wSFpZ01Kp4fyI2F0FUbLJ4An9XTERDJRBpboWR+vxWiyOleB+koGElMo 5QbiYy/69O1g7DvcvQIOOFkPh9JGtz0DmPfBZZVswVlt4AiXhG61enUAMwVFb/A6WsNF aqy8Gla/KL61Fect7BiXqNLK/p4d4uFNoX/Hbq7O8iY3fNSXdpQVH8ft5LonWc4B3oRt 9LldBe3+khoYdHfypAzgfEFHHXwAriRm2b0ueYfHbBacjuF1cYWvKYXeKuetEcIaWhwY eq6d2x2FL+uXqltuoGeoJgnZNl34EVgaNuIAKOe16Vyj5VfV6QRvOZ2APfCMMzLSPLVR wZUg== 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=B/uYh0is8GI8rdYX2e8AAbZnxOcs+EoOjFSvx15APQU=; fh=MSL/7hYF60PaScCJvqqoGkUWoZtElvzu/oEB/jqaobA=; b=fP8A9HMleBzXkC0uxVG+D5P9EDMzI8dJMBFf2ARY0bDSMToOwsZLEd0svhdOrfRs9P ohhTH+RcfLn1ztYxwUf1ZsAXw12BozQiwbviYl1Fl2Ov27BOS6rvETHA+NSy0Tozya3D M3s2/I5pi94CvLY5iPCYM+r7zTBAEpvJOi3nEqJ4+vQUTynvL9nkCxhq8z4TUfzeKxI/ Y0llPctWfR1zEmTn+8MikOcxx8o+HRUnybemUOXnlCEf5V3SFafInPVyePGmb3YSTN0+ 1ksrFrEvEWISSyUVju3ozWlsvSOgH2X/VkpmqIm6/9RcB/Dbw31/JcARu4j6eMm/4Kwm COJw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IPmoFAwI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g2-20020a05620a218200b00783468ff932si5513389qka.760.2024.01.22.07.15.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 07:15:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IPmoFAwI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33257-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 01FCB1C22AE5 for ; Mon, 22 Jan 2024 15:15:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AD1B54277; Mon, 22 Jan 2024 14:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IPmoFAwI" 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 A9D7753E17; Mon, 22 Jan 2024 14:58:27 +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=1705935507; cv=none; b=P8yjLpaLFifAvaVmafStlSNKEUxP07iUAHuj+G57Jwnv1Zw/4zh+6fHMsl0fr3ZZTDjwn3tQHJ1s45qgJ9ph87vzSQaLyiFnWEqmB2Q8/JTWsBLg4wuD1oalhSi0GwoRo5Yg3oGa2CdD8FkX2JQZHNZq7ydB/g7jFa1RRvPaZGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705935507; c=relaxed/simple; bh=1rhpbTEV4z8DnN43nGy8wsyD+6mjYsPqciJT7U/+yyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BihrV0dg62vQmqhvuxfsmQmYfFuP0HEOOFSJrCLVbu3P2u/hGHmwArdBaVCl8k4NXAUKS0rDpgDZOesGYE1OY4/eREKgf/hSmS8eHYDg5PtT1SF8X3EkNHb2WW8GM7t2nRMMOZy+l6i2f47YBDYD4iUvRi8e7lODqfR4cy9IwNQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IPmoFAwI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC568C433C7; Mon, 22 Jan 2024 14:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705935507; bh=1rhpbTEV4z8DnN43nGy8wsyD+6mjYsPqciJT7U/+yyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IPmoFAwIGlm+xJUOBPhnjGfudKM8+QzXJ75A/1dakONcnxo2JF6GbYyZhZWjWS7cN xVNzSWcOcC8V4yGTTXALe8wN0LEC6pUtkJ1SNZenTWc6UcjzUD0Izo+loB6z52bwSB 3I2UtE173USEw34eKoKADwiaFbf2H03UCFa63HvRtB3zYwVm5yzdxW/dDcp/vLlmfq j5cWHzL6U+grESAFmZUE+00zD8O49b67+0Ib4mZVaeflllQ1IYj032OO5cm5ikwGbe D1H6MhWU9iqpKZdtp/3pg0jvE/2lCCcbgAkFL+L7RjShXkmKoW60K1Z/Oduep0JAr2 NB2MwXiQKFusg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tomi Valkeinen , Adam Ford , 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 38/88] media: rkisp1: Fix IRQ disable race issue Date: Mon, 22 Jan 2024 09:51:11 -0500 Message-ID: <20240122145608.990137-38-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122145608.990137-1-sashal@kernel.org> References: <20240122145608.990137-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.1 Content-Transfer-Encoding: 8bit From: Tomi Valkeinen [ Upstream commit 870565f063a58576e8a4529f122cac4325c6b395 ] 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. Link: https://lore.kernel.org/r/20231207-rkisp-irq-fix-v3-4-358a2c871a3c@ideasonboard.com Tested-by: Adam Ford #imx8mp-beacon 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-csi.c | 14 ++++++++++++- .../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 6e17b2817e61..702adee83322 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 88ca8b2283b7..61d4816186e7 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c @@ -254,11 +254,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 */ -- 2.43.0