mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Fenghua Yu <fenghuay@nvidia.com>,
	Shuai Xue <xueshuai@linux.alibaba.com>
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open()
Date: Mon, 30 Nov 2026 10:13:17 -0700	[thread overview]
Message-ID: <e8066042-e02d-4340-a616-f5f3cd553484@intel.com> (raw)
In-Reply-To: <20261125-wt-idxd-fixes-v2-5-25a4691dfb9e@intel.com>



On 11/25/26 4:49 PM, Vinicius Costa Gomes wrote:
> Three error paths of idxd_cdev_open() are wrong:
> 
> - An ida_alloc() failure jumps to failed_ida without setting rc. The
>   open usually returns 0 after freeing its context, and the release of
>   the file then uses the freed filp->private_data.
> 
> - xa_insert() errors other than -EBUSY are ignored. The open succeeds
>   without the context in the xarray, and the completion records of its
>   page faults are dropped.
> 
> - On a dedicated WQ, the failed_ida path doesn't undo
>   idxd_wq_set_pasid(). The WQ keeps the PASID of an SVA bind that is
>   released right after.
> 
> Set rc on the ida_alloc() failure. Fail the open on xa_insert() errors
> other than -EBUSY, and fix the "exist -> exists" typo in its warning.
> Disable the PASID of a dedicated WQ on the failed_ida path, as
> idxd_file_dev_release() does.
> 
> Fixes: e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened")
> Fixes: b022f59725f0 ("dmaengine: idxd: add idxd_copy_cr() to copy user completion record during page fault handling")
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/dma/idxd/cdev.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
> index f1af7f0d25d3..9343deb2e858 100644
> --- a/drivers/dma/idxd/cdev.c
> +++ b/drivers/dma/idxd/cdev.c
> @@ -264,8 +264,12 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  		mutex_lock(&wq->uc_lock);
>  		rc = xa_insert(&wq->upasid_xa, pasid, ctx, GFP_KERNEL);
>  		mutex_unlock(&wq->uc_lock);
> -		if (rc < 0)
> -			dev_warn(dev, "PASID entry already exist in xarray.\n");
> +		if (rc == -EBUSY) {
> +			/* Another open of this WQ by the same mm added it */
> +			dev_warn(dev, "PASID entry already exists in xarray.\n");
> +		} else if (rc < 0) {
> +			goto failed_get_pasid;
> +		}
>  
>  		if (wq_dedicated(wq)) {
>  			rc = idxd_wq_set_pasid(wq, pasid);
> @@ -279,6 +283,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  	idxd_cdev = wq->idxd_cdev;
>  	ctx->id = ida_alloc(&file_ida, GFP_KERNEL);
>  	if (ctx->id < 0) {
> +		rc = ctx->id;
>  		dev_warn(dev, "ida alloc failure\n");
>  		goto failed_ida;
>  	}
> @@ -311,6 +316,9 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  	put_device(fdev);
>  	return rc;
>  failed_ida:
> +	if (device_user_pasid_enabled(idxd) && wq_dedicated(wq) &&
> +	    idxd_wq_disable_pasid(wq) < 0)
> +		dev_err(dev, "wq disable pasid failed.\n");
>  failed_set_pasid:
>  	if (device_user_pasid_enabled(idxd))
>  		idxd_xa_pasid_remove(ctx);
> 


  reply	other threads:[~2026-11-30 17:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
2026-11-25 23:48 ` [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 2/8] dmaengine: idxd: Fix potential double free on probe error path Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 3/8] dmaengine: idxd: fix duplicate memory frees on initialization " Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 4/8] dmaengine: idxd: Fix the device registration error paths Vinicius Costa Gomes
2026-11-30 17:03   ` Dave Jiang
2026-11-25 23:49 ` [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open() Vinicius Costa Gomes
2026-11-30 17:13   ` Dave Jiang [this message]
2026-11-25 23:49 ` [PATCH v2 6/8] dmaengine: idxd: Initialize the WQ XArray before the WQ can be released Vinicius Costa Gomes
2026-11-30 17:14   ` Dave Jiang
2026-11-25 23:49 ` [PATCH v2 7/8] dmaengine: idxd: Do not release interrupt handles on terminate_all() Vinicius Costa Gomes
2026-11-30 17:15   ` Dave Jiang
2026-11-25 23:49 ` [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors " Vinicius Costa Gomes
2026-11-30 17:18   ` Dave Jiang

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=e8066042-e02d-4340-a616-f5f3cd553484@intel.com \
    --to=dave.jiang@intel.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghuay@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vinicius.gomes@intel.com \
    --cc=vkoul@kernel.org \
    --cc=xueshuai@linux.alibaba.com \
    /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

all inboxes | Powered by JetHome®