From: "Tomasz Moń" <tomasz.mon@camlingroup.com>
To: dmaengine@vger.kernel.org
Cc: "Vinod Koul" <vkoul@kernel.org>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"NXP Linux Team" <linux-imx@nxp.com>,
k.drobinski@camlintechnologies.com,
"Tomasz Moń" <tomasz.mon@camlingroup.com>
Subject: [PATCH 2/2] dmaengine: imx-sdma: fix cyclic buffer race condition
Date: Mon, 17 Jan 2022 10:19:55 +0100 [thread overview]
Message-ID: <20220117091955.1038937-2-tomasz.mon@camlingroup.com> (raw)
In-Reply-To: <20220117091955.1038937-1-tomasz.mon@camlingroup.com>
Assign buffer ownership to SDMA after invoking descriptor callback to
make sure that SDMA does not write to the buffer before it is read by
the CPU.
Signed-off-by: Tomasz Moń <tomasz.mon@camlingroup.com>
---
drivers/dma/imx-sdma.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 330ff41cd614..8cc5103193c3 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -847,7 +847,6 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
*/
desc->chn_real_count = bd->mode.count;
- bd->mode.status |= BD_DONE;
bd->mode.count = desc->period_len;
desc->buf_ptail = desc->buf_tail;
desc->buf_tail = (desc->buf_tail + 1) % desc->num_bd;
@@ -862,6 +861,9 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
dmaengine_desc_get_callback_invoke(&desc->vd.tx, NULL);
spin_lock(&sdmac->vc.lock);
+ /* Assign buffer ownership to SDMA */
+ bd->mode.status |= BD_DONE;
+
if (error)
sdmac->status = old_status;
}
--
2.25.1
next prev parent reply other threads:[~2022-01-17 9:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 9:19 [PATCH 1/2] dmaengine: imx-sdma: restart cyclic channel if needed Tomasz Moń
2022-01-17 9:19 ` Tomasz Moń [this message]
2022-02-15 5:41 ` Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220117091955.1038937-2-tomasz.mon@camlingroup.com \
--to=tomasz.mon@camlingroup.com \
--cc=dmaengine@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=k.drobinski@camlintechnologies.com \
--cc=kernel@pengutronix.de \
--cc=linux-imx@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox