Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp277856rdb; Thu, 22 Feb 2024 03:33:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpu+EKqGYFJ0KE7F3mhGeUuJ3B7KyZ4fPXBPV4Ui/tIEBT7j62lDwEq/fgbA/41Ppwr2xqR8tEosqJeUeItz/IY8Hx7NSQoGVR/cjYQg== X-Google-Smtp-Source: AGHT+IEL3seJXI61ttr/QKGfPYfyJ1K59daQtTJS7ZRr4a1rQ1N20wziFRFHxXNZ83t+qTcd8NPn X-Received: by 2002:a1f:d447:0:b0:4c8:90e5:6792 with SMTP id l68-20020a1fd447000000b004c890e56792mr12678317vkg.7.1708601637147; Thu, 22 Feb 2024 03:33:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708601637; cv=pass; d=google.com; s=arc-20160816; b=0zqYKYqf9MP3R27iaLoMLSD32sphgcMoX99CQ9Zky0bgf5WsRFHg75jhSUQszOF9MW /AKTuGse7G3dcR1BFE7WFBRYnp30FSnBbtiZcXcQPhBbhgOhYAsbeEdUxFvbDreVIbOi JUNcollm7l1N22DO5KEb9kXO8wA1YKUoD0CztSETi9IuLvys4lXgecaqf4513TMhdjRs fbqpOzcylU1nkarStnLG46ihUwOQaafggdFNQb0LLps+hB99+WXLSphqo2+BTnco+wah 6J+2Z5GAedGgkNWMrklBdUG+DCVNNEb+uqFLyGKWAmeXY7x2RhKZvOPZ+7lfxMjYlUzu 51Ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=unATImeiTgCx2h83hV/vvpZDGrNkG9tQmTwgLhrnhvI=; fh=7Ze5xPQXuwRxFNHD2ILqwMPZ5wjg3PcSuREjIh8VhDo=; b=0EHe59Zkroqb3AhhsTujZ4YeTfIjX9tDfr0h3mBzHj+GuHn2GXSxlR45U97iTL1HqC 6nm8dUo7b2zhA3tDoI+40Vgp9iwzXICtSQeKdJ8T/Udobb4m2io9/3n870RZvdI1L/DE Y4fSA3969WocDALX39n85zR4layr2CmHB/5eLrVawlvxicNMl9OVueTIA91b5S/8fYjJ h21sZmjjfK2oEAxQLV/7nmapVIGMqw6LE69DW7SXFo6SqN0RBhKhYA15rMfrgpEjt9re tk5RwWX8s70QLT7VTBhSk2NOdYmzsctu3pxQ5t4sKsLMQdAF99rmxYbEeczPyNQYmJhB my6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=rVeJYGXd; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-76416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id if9-20020a0562141c4900b0068f5c3cb247si10156105qvb.191.2024.02.22.03.33.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:33:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=rVeJYGXd; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-76416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com 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 E2AC21C22E3C for ; Thu, 22 Feb 2024 11:33:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 909DC47779; Thu, 22 Feb 2024 11:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="rVeJYGXd" Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 9CDF7381A1; Thu, 22 Feb 2024 11:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708601607; cv=none; b=LyWEGs0/m9BL5VLRyxKgWnEi0cc8wcBMFbJxyrEHMXS7KuS0kj2A6W3sFl41VhC7m6u7yizUm7gxpe26BBWGh+MKjQfYnInCYhu64wFRNqzFOo0RO20/GB968R6oO6oYja3HCV4sLuJFtU38c1ydJbRlOPWzooqgF4GUt9soSso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708601607; c=relaxed/simple; bh=RGZevRFsIBvLsB1s0og8plkNvtCkfORtLILdFlyUzw0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=fp5C4e2uJGdKQmVpuFdiwsxAyomKseQhxVGOiMCups42qgWeRL4TQ3coJsOyswYtLO4IfsjzeI8CeIzawgaz0D2BNYXN5r9ABvzKX8qBux0t3nzWMsDWfbTg1TOPkIQajjXdARk9cUB8APDTroCfa8uStlh72rm/yNhFrIUd5qo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=rVeJYGXd; arc=none smtp.client-ip=198.47.19.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 41MBX7O6059121; Thu, 22 Feb 2024 05:33:07 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1708601587; bh=unATImeiTgCx2h83hV/vvpZDGrNkG9tQmTwgLhrnhvI=; h=From:Date:Subject:References:In-Reply-To:To:CC; b=rVeJYGXdT7Ymnf2W3KyFM42kDH/batnZnLLyh2+TyVQiP/CSD3IFOLukhWUeaWN0X oqjXbTnCOzloDPiHKZNvVcL0jOdCOypZNvv9ySWUTH7vSaWBO8wDQL9UD1cpCXN8Ff TvooYNuJos6qSxv4qPQglQ/tS7xreZdjB5qNv6g0= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 41MBX7VF056960 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 22 Feb 2024 05:33:07 -0600 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Thu, 22 Feb 2024 05:33:06 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Thu, 22 Feb 2024 05:33:06 -0600 Received: from localhost (jluthra.dhcp.ti.com [172.24.227.217]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 41MBX5bj090878; Thu, 22 Feb 2024 05:33:06 -0600 From: Jai Luthra Date: Thu, 22 Feb 2024 17:01:17 +0530 Subject: [PATCH RFC 01/21] media: ti: j721e-csi2rx: Fix races while restarting DMA Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20240222-multistream-v1-1-1837ed916eeb@ti.com> References: <20240222-multistream-v1-0-1837ed916eeb@ti.com> In-Reply-To: <20240222-multistream-v1-0-1837ed916eeb@ti.com> To: Tomi Valkeinen , Mauro Carvalho Chehab , Sakari Ailus , Hans Verkuil , Vaishnav Achath , Maxime Ripard , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: , , , Vignesh Raghavendra , Aradhya Bhatia , Devarsh Thakkar , Changhuang Liang , Jack Zhu , Julien Massot , Jayshri Pawar , Jai Luthra X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1532; i=j-luthra@ti.com; h=from:subject:message-id; bh=RGZevRFsIBvLsB1s0og8plkNvtCkfORtLILdFlyUzw0=; b=owEBbQKS/ZANAwAIAUPekfkkmnFFAcsmYgBl1zDaW9QfFKtaA48EMnvlA0N0UPpud5MN0AiqU qz3gSThwtSJAjMEAAEIAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCZdcw2gAKCRBD3pH5JJpx RZpWD/9TrlLiXZwWyOpm0PdGXZeBKB+af2zmPStZLGcfOE2aiYqIvQXZasnffBaD+rtu0LF9vKc LSuRyNTfIbaKkideXMz5oYsyu46z9AeJ6+MLj2D3iEYabvJZknCGVOK5Xx1xyKGhBnAcd9XucDl zEPeX3tcpyBN8fwIaJ27pMs+HCW/9AEyZA+/DwVLrtz2UTYNmSHOz5cgaAXy2U2URgP66oi3VLU sEym4xvzKCa4uwid9Ns+O+bfgaFgyJMuHmGWwPig2nmVpTF4m5IiTsaOl5+h+a8XvYDDLoCyMcV 8dorGmBTMb0WhPzeJ5GA7Dkw8lN+gbinoHomqJlf/B0gw5v1Ln6PQuWlY//NPyeWNL12lbCnHE2 blYQ3L6zQE7eRI49fuN891rkdnHy3mnvzXySDNvx62kNG50yt7N1xthBjYH9FnutwaXcPzUe4MU lex+cUEG8cEBn7iT8ZkoNO2jUdQvk06e/+mOPv3KqzGzFFsNRhYhQpMAw6BYVPav+0x/4mtEcuD HSVaMyIRajwZ2Jpa//Fc5g9TPDaIR27LMer1l4X5D/Iz2PzLnmfrZ2xxma8fU6wqR3ABHdwBF8+ 2dJ8GlCphRINgnAea64x8tbbhCsvt3J/69JwpD/e/PBQdYGeFjPQPfbsiw3gDyKPUewiXs0rdow Bxk05JYwsUwjIBQ== X-Developer-Key: i=j-luthra@ti.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 After the frame is submitted to DMA, it may happen that the submitted list is not updated soon enough, and the DMA callback is triggered before that. This can lead to kernel crashes, so move everything in a single lock/unlock section to prevent such races. Fixes: b4a3d877dc92 ("media: ti: Add CSI2RX support for J721E") Signed-off-by: Jai Luthra --- drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c index be47a4a24f97..e2cac8d73d78 100644 --- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c @@ -810,15 +810,14 @@ static void ti_csi2rx_buffer_queue(struct vb2_buffer *vb) dev_warn(csi->dev, "Failed to drain DMA. Next frame might be bogus\n"); + spin_lock_irqsave(&dma->lock, flags); ret = ti_csi2rx_start_dma(csi, buf); if (ret) { - dev_err(csi->dev, "Failed to start DMA: %d\n", ret); - spin_lock_irqsave(&dma->lock, flags); vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); dma->state = TI_CSI2RX_DMA_IDLE; spin_unlock_irqrestore(&dma->lock, flags); + dev_err(csi->dev, "Failed to start DMA: %d\n", ret); } else { - spin_lock_irqsave(&dma->lock, flags); list_add_tail(&buf->list, &dma->submitted); spin_unlock_irqrestore(&dma->lock, flags); } -- 2.43.0