From: Frank Li <Frank.li@oss.nxp.com>
To: Daniel Byrne <daniel1.byrne@intel.com>
Cc: Vinod Koul <vkoul@kernel.org>,
dmaengine@vger.kernel.org,
Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Dave Jiang <dave.jiang@intel.com>, Frank Li <Frank.Li@kernel.org>,
Fenghua Yu <fenghuay@nvidia.com>, Dan Williams <djbw@kernel.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 02/10] dmaengine: idxd: detach the user fault workqueue under the event log lock
Date: Thu, 3 Dec 2026 11:47:28 -0600 [thread overview]
Message-ID: <axGrMOtQhmLe7BXZ@SMW015318> (raw)
In-Reply-To: <20261130194721.1900266-3-daniel1.byrne@intel.com>
On Mon, Nov 30, 2026 at 11:47:13AM -0800, Daniel Byrne wrote:
> The event log walk tests wq->wq and queues fault work on it, and the
> drain of a closing context's PASID tests it and drains it, both under
> evl->lock. The user driver's remove destroyed the workqueue without that
> lock, so a walk could queue on a workqueue being destroyed. The probe's
> error path destroyed it without clearing the pointer, so a later drain
> found a dangling one. That happens when a context's file stays open
> across an unbind, a rebind's probe fails after it created the workqueue,
> and the file then closes.
>
> Detach and destroy the workqueue under evl->lock, in one helper that the
> remove and the probe error path share, and clear the pointer in both. A
> walk or a drain that finds it gone knows that the fault work it would
> have waited for has run.
>
> The probe attaches the workqueue and sets the type under the same lock,
> so that a walk sees them together.
>
> Fixes: c40bd7d9737b ("dmaengine: idxd: process user page faults for completion record")
> Cc: stable@vger.kernel.org # 6.4+
> Signed-off-by: Daniel Byrne <daniel1.byrne@intel.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> v2: idxd_user_drv_probe() creates the workqueue into a local and stores
> wq->wq and the IDXD_WQT_USER type together under evl->lock, the lock
> they are detached under, so that a walk sees the two together; the
> message gives the sequence that leaves a drain with the dangling pointer
> (a file kept open across an unbind, a rebind whose probe fails after it
> created the workqueue, then the close) and no longer says that a walk
> finds it; Fixes and Cc: stable tags added.
>
> drivers/dma/idxd/cdev.c | 42 ++++++++++++++++++++++++++++++++++-------
> drivers/dma/idxd/irq.c | 5 ++++-
> 2 files changed, 39 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
> index 82b07cf942ef..50cd2e3f342d 100644
> --- a/drivers/dma/idxd/cdev.c
> +++ b/drivers/dma/idxd/cdev.c
> @@ -592,11 +592,33 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
> put_device(cdev_dev(idxd_cdev));
> }
>
> +/*
> + * The event log walk tests the fault workqueue and queues on it, and the
> + * drain of a closing context's PASID tests it and drains it, both under
> + * the log's lock, which neither the probe nor the remove otherwise takes.
> + * The workqueue is therefore detached and destroyed under that lock. A
> + * walk or a drain that finds it gone knows that its work has run.
> + */
> +static void idxd_user_wq_destroy_fault_wq(struct idxd_wq *wq)
> +{
> + struct idxd_evl *evl = wq->idxd->evl;
> +
> + if (evl)
> + mutex_lock(&evl->lock);
> + wq->type = IDXD_WQT_NONE;
> + destroy_workqueue(wq->wq);
> + wq->wq = NULL;
> + if (evl)
> + mutex_unlock(&evl->lock);
> +}
> +
> static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
> {
> struct device *dev = &idxd_dev->conf_dev;
> struct idxd_wq *wq = idxd_dev_to_wq(idxd_dev);
> struct idxd_device *idxd = wq->idxd;
> + struct idxd_evl *evl = idxd->evl;
> + struct workqueue_struct *fwq;
> int rc;
>
> if (idxd->state != IDXD_DEV_ENABLED)
> @@ -629,13 +651,22 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
> goto wq_err;
> }
>
> - wq->wq = create_workqueue(dev_name(wq_confdev(wq)));
> - if (!wq->wq) {
> + fwq = create_workqueue(dev_name(wq_confdev(wq)));
> + if (!fwq) {
> rc = -ENOMEM;
> goto wq_err;
> }
>
> + /*
> + * Attached under the lock it is detached under, so that a walk sees
> + * the workqueue and the type together.
> + */
> + if (evl)
> + mutex_lock(&evl->lock);
> + wq->wq = fwq;
> wq->type = IDXD_WQT_USER;
> + if (evl)
> + mutex_unlock(&evl->lock);
> rc = idxd_drv_enable_wq(wq);
> if (rc < 0)
> goto err;
> @@ -653,8 +684,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
> err_cdev:
> idxd_drv_disable_wq(wq);
> err:
> - destroy_workqueue(wq->wq);
> - wq->type = IDXD_WQT_NONE;
> + idxd_user_wq_destroy_fault_wq(wq);
> wq_err:
> mutex_unlock(&wq->wq_lock);
> return rc;
> @@ -667,9 +697,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev)
> mutex_lock(&wq->wq_lock);
> idxd_wq_del_cdev(wq);
> idxd_drv_disable_wq(wq);
> - wq->type = IDXD_WQT_NONE;
> - destroy_workqueue(wq->wq);
> - wq->wq = NULL;
> + idxd_user_wq_destroy_fault_wq(wq);
> mutex_unlock(&wq->wq_lock);
> }
>
> diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c
> index 7ae73bb39548..65f3e389113c 100644
> --- a/drivers/dma/idxd/irq.c
> +++ b/drivers/dma/idxd/irq.c
> @@ -339,7 +339,10 @@ static void process_evl_entry(struct idxd_device *idxd,
> * alone. A kernel WQ, or a user WQ whose cdev driver
> * is not bound, has no cdev workqueue and no user
> * contexts, so queueing could only warn and drop the
> - * record. Note it and move on.
> + * record. Note it and move on. The user driver
> + * detaches the workqueue under evl->lock, which this
> + * walk holds, so the one tested here is the one
> + * queued on.
> */
> if (!is_idxd_wq_user(wq) || !wq->wq) {
> dev_warn_ratelimited(dev,
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-12-03 17:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261130194721.1900266-1-daniel1.byrne@intel.com>
2026-11-30 19:47 ` [PATCH v2 01/10] dmaengine: idxd: don't queue EVL fault work for kernel WQs Daniel Byrne
2026-12-03 17:47 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 02/10] dmaengine: idxd: detach the user fault workqueue under the event log lock Daniel Byrne
2026-12-03 17:47 ` Frank Li [this message]
2026-11-30 19:47 ` [PATCH v2 03/10] dmaengine: idxd: free the event log fault item when no record is copied Daniel Byrne
2026-12-03 17:47 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 04/10] dmaengine: idxd: refuse a memcpy longer than the WQ max transfer size Daniel Byrne
2026-12-03 17:48 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 05/10] dmaengine: idxd: take an mm_users reference for the completion record copy Daniel Byrne
2026-12-03 17:49 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 06/10] dmaengine: idxd: read GENCFG before clearing the event log enable Daniel Byrne
2026-12-03 17:49 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 07/10] dmaengine: idxd: don't sleep for a descriptor in the prep callbacks Daniel Byrne
2026-12-03 17:49 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 08/10] dmaengine: idxd: read the event log size under its lock in the setup Daniel Byrne
2026-12-03 17:50 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 09/10] dmaengine: idxd: free the queue interrupt when the percpu_ref setup fails Daniel Byrne
2026-12-03 17:44 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 10/10] dmaengine: idxd: test a queue under its lock before quiescing it 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=axGrMOtQhmLe7BXZ@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=daniel1.byrne@intel.com \
--cc=dave.jiang@intel.com \
--cc=djbw@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=fenghuay@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--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