From patchwork Fri Nov 15 22:33:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 179542 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp13127245ilf; Fri, 15 Nov 2019 14:35:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyvpb2iY0BS3tAc51pzT/cZ02TdVCNhcfX/wEMgxpaljCzgN/ZMBRHzbXYXxaS6gcU9ZHQZ X-Received: by 2002:a17:906:25c5:: with SMTP id n5mr4346376ejb.126.1573857300642; Fri, 15 Nov 2019 14:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573857300; cv=none; d=google.com; s=arc-20160816; b=h1n09Gci2du7rJa2z/jL/lVK8gtX1voBT6BqZEka7gRnPxBa4z/K3b5so2her58n5p S9IoUZigciX53d9qYzvBHD7MoIUCdEXd7SeS4YEoRF2xcgV5HAMjqTx+AWtefKHqPZe2 qaivw1GV7v78s6p3KTk15/6xnK5tI/XzZkWLuTZBdtg2feNEESRQplF2tD2biYkMZsoX exx3lpx0Gh+1TYubCftVgrMX6LFRbEWnfSEszcMhvxDEmlmxrdvr8o9kiI0kwxJlue5i uxYelj43a3Rash3aSafZLVKXmu9c2EZ4djEq42nJRYQTz+ixNF0KHvzLWvR6400MwzOr aqlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CfdEn/VOoyCYVCEhBtRjG/LrGez0kXMzdfAuimisWqo=; b=iSYaXdO3+N5ENZ2QEequD3c3+czMOTq8FfivR2Df8cnJO8n+O5hfMual2j2QOqqRre RA+F21gbinUYs/44N9Q/vEtk0zr8guI6fUgVhBxvUd9PfJ3P2yawQQLKVd0bi3pLjUIS ahwZ8OnMevAjdYIvdz24s67Hq6B1FimH97VPxx/GtPgPG/tdkNk1LUDBM2QSk326dnCN 85+8NJ6IyeU4UMa/7NeMg3obPXtPU43xIsUWfdSvfjeEMMBlL9FZIYnBHU7CFu1w/Pco BprFKxpD/dTOs7A2CgA1G3EElWw2XGCAgmw968vbt8hJOMuttesmXUvRzf7WDNwc5OkE AxPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BmJCSnph; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l24si6701150edw.352.2019.11.15.14.35.00; Fri, 15 Nov 2019 14:35:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BmJCSnph; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfKOWeG (ORCPT + 15 others); Fri, 15 Nov 2019 17:34:06 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39456 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727199AbfKOWeC (ORCPT ); Fri, 15 Nov 2019 17:34:02 -0500 Received: by mail-pl1-f196.google.com with SMTP id o9so5624457plk.6 for ; Fri, 15 Nov 2019 14:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CfdEn/VOoyCYVCEhBtRjG/LrGez0kXMzdfAuimisWqo=; b=BmJCSnphEJxB/SJaEZ55rWx8UacuDIrgu3GGuKP9hxL0m0pDhN7q9J+QXmeNHU3a9S KcLpI35v0bQ7VN2vpFI89zIEmufoawp/UX+aj0AEhPZY1Ca6qiVHFhjEj/1Q6qpfeLYh gjoYQxSbf630RaEl3OM/6BIGdyMcJhAgPgaITE7CHkkMSKWyVALpX3aHE/rIyZ+534CU kKKAtB/FXySeSR4aPKIGgqnJPLZz5ZmoX7PLhvXCyZfRhjY/WwB2qknR22z51CDufEry KwJioKJ8hKDwJTr64gk0X3402S8pXsOhEqAEl6DeZUZcNxfDi9jgwWcFrfWjMc4Hltu1 UKjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CfdEn/VOoyCYVCEhBtRjG/LrGez0kXMzdfAuimisWqo=; b=ch/mVw/pO7JVp0RXzY5dhL4Ozr2cgirrraeWGKvNxIJzbQ6HJeRJq35M1WDChzNR3M ys64hwZVl+sAQkZbav6Zb5fFbkQM/urWEVYofWBexAcmgOG1+xez+55Dh+MMVkEpFERB EKyv8iQ3HCKoaKNlg8SJ98GtULaRW/dcLab8RpI30VSIm8E9TbMya5NsHzNpxSAYGP55 Hr9i51ZWmRGVZWxpZjuA+eNvDvvNGVcTSmXhpegqhm2JII9UK9OsNC9oiOppu9ppJHvo jWd/f6aWSenvRr7JRsrdi1ne/GeEPIpOCzHCEOR5p3K5C0HQLEE87+6TYSf3xQyd0Xgq i98w== X-Gm-Message-State: APjAAAUqAKAD5u0DUKehqw47sH4yZZDpB+4CGnhFDc0NXS9OLNhLDaMK YeivSlznKfsGexedZv9Sj6qgRWGqyrQ= X-Received: by 2002:a17:90a:ca04:: with SMTP id x4mr23087371pjt.103.1573857241601; Fri, 15 Nov 2019 14:34:01 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m15sm11699724pfh.19.2019.11.15.14.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 14:34:01 -0800 (PST) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [stable 4.19+][PATCH 05/20] media: stm32-dcmi: fix DMA corruption when stopping streaming Date: Fri, 15 Nov 2019 15:33:41 -0700 Message-Id: <20191115223356.27675-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191115223356.27675-1-mathieu.poirier@linaro.org> References: <20191115223356.27675-1-mathieu.poirier@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hugues Fruchet commit b3ce6f6ff3c260ee53b0f2236e5fd950d46957da upstream Avoid call of dmaengine_terminate_all() between dmaengine_prep_slave_single() and dmaengine_submit() by locking the whole DMA submission sequence. Signed-off-by: Hugues Fruchet Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Cc: stable # 4.19+ Signed-off-by: Mathieu Poirier --- drivers/media/platform/stm32/stm32-dcmi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.17.1 diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c index 1d9c028e52cb..d86944109cbf 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -164,6 +164,9 @@ struct stm32_dcmi { int errors_count; int overrun_count; int buffers_count; + + /* Ensure DMA operations atomicity */ + struct mutex dma_lock; }; static inline struct stm32_dcmi *notifier_to_dcmi(struct v4l2_async_notifier *n) @@ -314,6 +317,13 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi, return ret; } + /* + * Avoid call of dmaengine_terminate_all() between + * dmaengine_prep_slave_single() and dmaengine_submit() + * by locking the whole DMA submission sequence + */ + mutex_lock(&dcmi->dma_lock); + /* Prepare a DMA transaction */ desc = dmaengine_prep_slave_single(dcmi->dma_chan, buf->paddr, buf->size, @@ -322,6 +332,7 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi, if (!desc) { dev_err(dcmi->dev, "%s: DMA dmaengine_prep_slave_single failed for buffer phy=%pad size=%zu\n", __func__, &buf->paddr, buf->size); + mutex_unlock(&dcmi->dma_lock); return -EINVAL; } @@ -333,9 +344,12 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi, dcmi->dma_cookie = dmaengine_submit(desc); if (dma_submit_error(dcmi->dma_cookie)) { dev_err(dcmi->dev, "%s: DMA submission failed\n", __func__); + mutex_unlock(&dcmi->dma_lock); return -ENXIO; } + mutex_unlock(&dcmi->dma_lock); + dma_async_issue_pending(dcmi->dma_chan); return 0; @@ -717,7 +731,9 @@ static void dcmi_stop_streaming(struct vb2_queue *vq) spin_unlock_irq(&dcmi->irqlock); /* Stop all pending DMA operations */ + mutex_lock(&dcmi->dma_lock); dmaengine_terminate_all(dcmi->dma_chan); + mutex_unlock(&dcmi->dma_lock); pm_runtime_put(dcmi->dev); @@ -1719,6 +1735,7 @@ static int dcmi_probe(struct platform_device *pdev) spin_lock_init(&dcmi->irqlock); mutex_init(&dcmi->lock); + mutex_init(&dcmi->dma_lock); init_completion(&dcmi->complete); INIT_LIST_HEAD(&dcmi->buffers);