dmaengine.vger.kernel.org archive mirror
 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>, Fenghua Yu <fenghua.yu@intel.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/9] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config()
Date: Wed, 6 Aug 2025 10:02:30 -0700	[thread overview]
Message-ID: <b0023322-2605-4189-83f8-d1cba64c6b39@intel.com> (raw)
In-Reply-To: <20250804-idxd-fix-flr-on-kernel-queues-v3-v1-1-4e020fbf52c1@intel.com>



On 8/4/25 6:27 PM, Vinicius Costa Gomes wrote:
> idxd_device_config() should only be called with idxd->dev_lock held.
> Hold the lock to the calls that were missing.
> 
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Patch looks fine. What about doing something like this:

---

diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 5cf419fe6b46..06c182ec3c04 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -1103,11 +1103,15 @@ static int idxd_wqs_setup(struct idxd_device *idxd)
 	return 0;
 }
 
-int idxd_device_config(struct idxd_device *idxd)
+int idxd_device_config_locked(struct idxd_device *idxd)
 {
 	int rc;
 
 	lockdep_assert_held(&idxd->dev_lock);
+
+	if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
+		return -EPERM;
+
 	rc = idxd_wqs_setup(idxd);
 	if (rc < 0)
 		return rc;
@@ -1129,6 +1133,12 @@ int idxd_device_config(struct idxd_device *idxd)
 	return 0;
 }
 
+int idxd_device_config(struct idxd_device *idxd)
+{
+	guard(spinlock)(&idxd->dev_lock);
+	return idxd_device_config_locked(idxd);
+}
+
 static int idxd_wq_load_config(struct idxd_wq *wq)
 {
 	struct idxd_device *idxd = wq->idxd;
@@ -1434,11 +1444,7 @@ int idxd_drv_enable_wq(struct idxd_wq *wq)
 		}
 	}
 
-	rc = 0;
-	spin_lock(&idxd->dev_lock);
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
-		rc = idxd_device_config(idxd);
-	spin_unlock(&idxd->dev_lock);
+	rc = idxd_device_config(idxd);
 	if (rc < 0) {
 		dev_dbg(dev, "Writing wq %d config failed: %d\n", wq->id, rc);
 		goto err;
@@ -1521,7 +1527,7 @@ EXPORT_SYMBOL_NS_GPL(idxd_drv_disable_wq, "IDXD");
 int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
 {
 	struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);
-	int rc = 0;
+	int rc;
 
 	/*
 	 * Device should be in disabled state for the idxd_drv to load. If it's in
@@ -1534,10 +1540,7 @@ int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
 	}
 
 	/* Device configuration */
-	spin_lock(&idxd->dev_lock);
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
-		rc = idxd_device_config(idxd);
-	spin_unlock(&idxd->dev_lock);
+	rc = idxd_device_config(idxd);
 	if (rc < 0)
 		return -ENXIO;
 
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index 74e6695881e6..f15bc2281c6b 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -760,6 +760,7 @@ int idxd_device_disable(struct idxd_device *idxd);
 void idxd_device_reset(struct idxd_device *idxd);
 void idxd_device_clear_state(struct idxd_device *idxd);
 int idxd_device_config(struct idxd_device *idxd);
+int idxd_device_config_locked(struct idxd_device *idxd);
 void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);
 int idxd_device_load_config(struct idxd_device *idxd);
 int idxd_device_request_int_handle(struct idxd_device *idxd, int idx, int *handle,
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 80355d03004d..193b9282e30f 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -1091,12 +1091,10 @@ static void idxd_reset_done(struct pci_dev *pdev)
 	idxd_device_config_restore(idxd, idxd->idxd_saved);
 
 	/* Re-configure IDXD device if allowed. */
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) {
-		rc = idxd_device_config(idxd);
-		if (rc < 0) {
-			dev_err(dev, "HALT: %s config fails\n", idxd_name);
-			goto out;
-		}
+	rc = idxd_device_config(idxd);
+	if (rc < 0) {
+		dev_err(dev, "HALT: %s config fails\n", idxd_name);
+		goto out;
 	}
 
 	/* Bind IDXD device to driver. */


> ---
>  drivers/dma/idxd/init.c | 2 ++
>  drivers/dma/idxd/irq.c  | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
> index 35bdefd3728bb851beb0f235fae7c6d71bd59239..d828d352ab008127e5e442e7072c9d5df0f2c6cf 100644
> --- a/drivers/dma/idxd/init.c
> +++ b/drivers/dma/idxd/init.c
> @@ -1091,7 +1091,9 @@ static void idxd_reset_done(struct pci_dev *pdev)
>  
>  	/* Re-configure IDXD device if allowed. */
>  	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) {
> +		spin_lock(&idxd->dev_lock);
>  		rc = idxd_device_config(idxd);
> +		spin_unlock(&idxd->dev_lock);
>  		if (rc < 0) {
>  			dev_err(dev, "HALT: %s config fails\n", idxd_name);
>  			goto out;
> diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c
> index 1107db3ce0a3a65246bd0d9b1f96e99c9fa3def6..74059fe43fafeb930f58db21d3824f62b095b968 100644
> --- a/drivers/dma/idxd/irq.c
> +++ b/drivers/dma/idxd/irq.c
> @@ -36,7 +36,9 @@ static void idxd_device_reinit(struct work_struct *work)
>  	int rc, i;
>  
>  	idxd_device_reset(idxd);
> +	spin_lock(&idxd->dev_lock);
>  	rc = idxd_device_config(idxd);
> +	spin_unlock(&idxd->dev_lock);
>  	if (rc < 0)
>  		goto out;
>  
> 


  reply	other threads:[~2025-08-06 17:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05  1:27 [PATCH 0/9] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
2025-08-05  1:27 ` [PATCH 1/9] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config() Vinicius Costa Gomes
2025-08-06 17:02   ` Dave Jiang [this message]
2025-08-06 20:25     ` Vinicius Costa Gomes
2025-08-05  1:27 ` [PATCH 2/9] dmaengine: idxd: Fix crash when the event log is disabled Vinicius Costa Gomes
2025-08-06 17:07   ` Dave Jiang
2025-08-05  1:27 ` [PATCH 3/9] dmaengine: idxd: Fix possible invalid memory access after FLR Vinicius Costa Gomes
2025-08-06 17:09   ` Dave Jiang
2025-08-15 19:26   ` Nathan Lynch
2025-08-15 22:45     ` Vinicius Costa Gomes
2025-08-05  1:27 ` [PATCH 4/9] dmaengine: idxd: Flush kernel workqueues on Field Level Reset Vinicius Costa Gomes
2025-08-06 17:12   ` Dave Jiang
2025-08-05  1:27 ` [PATCH 5/9] dmaengine: idxd: Allow DMA clients to empty the pending queue Vinicius Costa Gomes
2025-08-06 17:17   ` Dave Jiang
2025-08-06 20:30     ` Vinicius Costa Gomes
2025-08-05  1:27 ` [PATCH 6/9] dmaengine: idxd: Fix not releasing workqueue on .release() Vinicius Costa Gomes
2025-08-06 17:24   ` Dave Jiang
2025-08-05  1:27 ` [PATCH 7/9] dmaengine: idxd: Fix memory leak when a wq is reset Vinicius Costa Gomes
2025-08-06 17:25   ` Dave Jiang
2025-08-05  1:27 ` [PATCH 8/9] dmaengine: idxd: Fix freeing the allocated ida too late Vinicius Costa Gomes
2025-08-06 17:27   ` Dave Jiang
2025-08-05  1:28 ` [PATCH 9/9] dmaengine: idxd: Fix leaking event log memory Vinicius Costa Gomes
2025-08-06 17:29   ` 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=b0023322-2605-4189-83f8-d1cba64c6b39@intel.com \
    --to=dave.jiang@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).