All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-ide@vger.kernel.org
Cc: Damien Le Moal <dlemoal@kernel.org>,
	Niklas Cassel <cassel@kernel.org>,
	Grant Likely <grant.likely@secretlab.ca>,
	Tim Yamin <plasm@roo.me.uk>, Julia Lawall <Julia.Lawall@lip6.fr>,
	Jeff Garzik <jgarzik@redhat.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCHv3 2/6] ata: pata_mpc52xx: synchronize with task IRQ before resetting DMA state
Date: Fri, 12 Jun 2026 11:32:23 -0700	[thread overview]
Message-ID: <20260612183227.20446-3-rosenp@gmail.com> (raw)
In-Reply-To: <20260612183227.20446-1-rosenp@gmail.com>

mpc52xx_bmdma_stop() calls bcom_disable() to stop the BestComm task,
but an already-pending task completion IRQ can still fire and execute
mpc52xx_ata_task_irq() concurrently. The handler iterates the BD ring
via bcom_buffer_done()/bcom_retrieve_buffer() and writes to
priv->waiting_for_dma, while bmdma_stop resets the BD ring with
bcom_ata_reset_bd() and clears waiting_for_dma -- all without
synchronization.

Add a task_irq field to priv, store it during probe, and call
synchronize_irq() after bcom_disable() and before bcom_ata_reset_bd()
to ensure the handler has completed and cannot race with the BD ring
reset or the waiting_for_dma clear.

Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/ata/pata_mpc52xx.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index fe445d6aaff6..72a2b677bc90 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -58,6 +58,7 @@ struct mpc52xx_ata_priv {
 
 	/* DMA */
 	struct bcom_task		*dmatsk;
+	int				task_irq;
 	const struct udmaspec		*udmaspec;
 	const struct mdmaspec		*mdmaspec;
 	int 				mpc52xx_ata_dma_last_write;
@@ -571,6 +572,7 @@ mpc52xx_bmdma_stop(struct ata_queued_cmd *qc)
 	struct mpc52xx_ata_priv *priv = ap->host->private_data;
 
 	bcom_disable(priv->dmatsk);
+	synchronize_irq(priv->task_irq);
 	bcom_ata_reset_bd(priv->dmatsk);
 	priv->waiting_for_dma = 0;
 
@@ -769,6 +771,7 @@ static int mpc52xx_ata_probe(struct platform_device *op)
 	priv->dmatsk = dmatsk;
 
 	task_irq = bcom_get_task_irq(dmatsk);
+	priv->task_irq = task_irq;
 	rv = devm_request_irq(&op->dev, task_irq, &mpc52xx_ata_task_irq, 0,
 				"ATA task", priv);
 	if (rv) {
-- 
2.54.0


  parent reply	other threads:[~2026-06-12 18:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 18:32 [PATCHv3 0/6] ata: pata_mpc52xx: fix cleanup ordering and modernize Rosen Penev
2026-06-12 18:32 ` [PATCHv3 1/6] ata: pata_mpc52xx: fix NULL pointer dereference in IRQ handler Rosen Penev
2026-06-12 18:46   ` sashiko-bot
2026-06-12 18:32 ` Rosen Penev [this message]
2026-06-12 18:32 ` [PATCHv3 3/6] ata: pata_mpc52xx: reset cached DMA direction on resume Rosen Penev
2026-06-12 18:32 ` [PATCHv3 4/6] ata: pata_mpc52xx: remove redundant irq_dispose_mapping calls Rosen Penev
2026-06-12 18:45   ` sashiko-bot
2026-06-12 18:32 ` [PATCHv3 5/6] ata: pata_mpc52xx: convert to platform_get_irq() Rosen Penev
2026-06-12 18:32 ` [PATCHv3 6/6] ata: pata_mpc52xx: convert to full devm resource management Rosen Penev

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=20260612183227.20446-3-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=Julia.Lawall@lip6.fr \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=grant.likely@secretlab.ca \
    --cc=jgarzik@redhat.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=plasm@roo.me.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.