Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Byrne <daniel1.byrne@intel.com>
To: Dave Jiang <dave.jiang@intel.com>
Cc: Daniel Byrne <daniel1.byrne@intel.com>,
	Vinod Koul <vkoul@kernel.org>, Fenghua Yu <fenghua.yu@intel.com>,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	dmaengine@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] dmaengine: idxd: generation-number transaction status
Date: Mon, 30 Nov 2026 12:02:48 -0800	[thread overview]
Message-ID: <20261130200248.1903384-1-daniel1.byrne@intel.com> (raw)
In-Reply-To: <d7a9311c-f559-485e-b9bc-30d34188d24e@intel.com>

On Mon, 19 Oct 2026 18:53:11 +0000, Dave Jiang wrote:
> LLM suggests possible race:
> 1. Recording the count too early. idxd_dma_tx_submit() saves the reset count into desc->epoch (dma.c:321) before calling idxd_submit_desc(). Until __idxd_submit_desc() checks idxd->state (submit.c:230) and takes wq_active, the submitter holds no lock and no reference.
>
> 2. The halt doesn't wait for this submitter. idxd_halt() (irq.c:509-529) sets HALTED and increments reset_epoch, then calls idxd_wqs_halt_flush(idxd, true). That flush's idxd_wq_kill() waits only for submitters holding wq_active, so it never waits on ours. It then revives wq_active and queues idxd_device_reinit().
>
> 3. Recovery finishes. idxd_device_reinit() (irq.c:32-70) resets, configures and enables the device, which sets ENABLED (device.c:810). It then re-enables the queue (device.c:217). Nothing in this path touches the descriptors or desc->epoch.
>
> 4. The descriptor runs on the new device. The submitter resumes and passes both state checks and the tryget. It then posts the descriptor, which still carries the old count, and the reset device runs it.
>
> 5. The poll frees it early. The first poll after the post sees status 0, and the descriptor matches the cookie. The desc->epoch != reset_epoch branch (dma.c:264-267) then calls idxd_dma_complete_txd(..., true, ...), which frees the slot. It returns DMA_ERROR while the copy is still running.
>
> 6. The late write corrupts the next user. __get_desc() clears the completion record when the slot is reused (submit.c:19). The device then writes its record to the same dener can see a result for a transfer that hasn't run.
>
> LLM suggested fix:
> Move the reset-count read (desc->epoch) out of idxd_dma_tx_submit() and into __idxd_submit_desc(), after the submitter holds wq_active and before the second state check. On the halt side, order the state store before the count store.
>
> --- a/drivers/dma/idxd/dma.c
> +++ b/drivers/dma/idxd/dma.c
> @@ static dma_cookie_t idxd_dma_tx_submit(struct dma_async_tx_descriptor *tx)
>         tx->cookie = cookie;
> -       desc->epoch = READ_ONCE(wq->idxd->reset_epoch);
>
>         rc = idxd_submit_desc(wq, desc);
> --- a/drivers/dma/idxd/submit.c
> +++ b/drivers/dma/idxd/submit.c
> @@ static int __idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc,
>         smp_rmb();
> +       /*
> +        * Stamp under wq_active: a halt that bumps the epoch after this
> +        * read waits in idxd_wq_kill() for the reference, so an old stamp
> +        * proves the post came before that halt's flush. A halt stores its
> +        * state before its bump, so a bumped stamp fails the check below.
> +        */
> +       desc->epoch = READ_ONCE(idxd->reset_epoch);
> +       smp_rmb();
>         if (idxd->state != IDXD_DEV_ENABLED) {
>                 percpu_ref_put(&wq->wq_active);
>                 return -EIO;
>         }
> --- a/drivers/dma/idxd/irq.c
> +++ b/drivers/dma/idxd/irq.c
> @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)
>         if (gensts.state == IDXD_DEVICE_STATE_HALT) {
>                 idxd->state = IDXD_DEV_HALTED;
> +               /* Pairs with the smp_rmb() after the submit's epoch stamp. */
> +               smp_wmb();
>                 /*
>                  * Every descriptor submitted before this point is dead: the

Yes, that race is real in v1. For v2, we use suggested flow: the
epoch is stamped in __idxd_submit_desc() after the wq_active try get
and before the queue-state gate, and idxd_halt() stores the state
before it bumps the epoch, with the smp_wmb()/smp_rmb() pair between
them. idxd_device_fail() bumps the epoch the same way. A halt that
bumps after the stamp waits in idxd_wq_kill() for the reference, so a
descriptor cannot post to a reset device with an old stamp, and a
stamp taken after the bump fails the gate.

I tested with KCSAN (default and STRICT with WEAK_MEMORY),
submitters running while a simulated halt bumps the epoch. No report
on the stamp/bump pair and every parked submitter returned.

Thanks,
Daniel


  reply	other threads:[~2026-11-30 20:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 15:06 [PATCH 0/3] [PATCH 0/3] dmaengine: polled completion status for out-of-order providers Daniel Byrne
2026-10-19 15:06 ` [PATCH 1/3] dmaengine: add dmaengine_async_is_tx_complete() for channel status queries Daniel Byrne
2026-10-19 18:36   ` Frank Li
2026-11-30 20:02     ` Daniel Byrne
2026-10-19 15:06 ` [PATCH 2/3] dmaengine: idxd: generation-number transaction status Daniel Byrne
2026-10-19 18:53   ` Dave Jiang
2026-11-30 20:02     ` Daniel Byrne [this message]
2026-10-19 15:06 ` [PATCH 3/3] dmaengine: drop DMA_COMPLETION_NO_ORDER and DMA_OUT_OF_ORDER Daniel Byrne
2026-10-19 19:02   ` Frank Li
2026-11-30 20:02     ` Daniel Byrne

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=20261130200248.1903384-1-daniel1.byrne@intel.com \
    --to=daniel1.byrne@intel.com \
    --cc=corbet@lwn.net \
    --cc=dave.jiang@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=vinicius.gomes@intel.com \
    --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