public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmaengine: idxd: Only call idxd_enable_system_pasid if succeeded in enabling SVA feature
@ 2022-06-25 22:13 Jerry Snitselaar
  2022-06-26  4:20 ` Fenghua Yu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jerry Snitselaar @ 2022-06-25 22:13 UTC (permalink / raw)
  To: dmaengine; +Cc: Vinod Koul, linux-kernel, Dave Jiang, Fenghua Yu

iommu_sva_bind_device requires that iommu_dev_enable_feature has been
previously called with IOMMU_DEV_FEAT_SVA, and succeeded. Without this
it is possible to run into a situation where you will dereference a
null pointer if the intel_iommu driver is not enabled.

Note: checkpatch didn't like the suggested addition of braces for the
      first arm of the "if (idxd_enable_system_pasid)" block.

Fixes: 42a1b73852c4 ("dmaengine: idxd: Separate user and kernel pasid enabling")
Cc: Vinod Koul <vkoul@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
---
 drivers/dma/idxd/init.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 355fb3ef4cbf..5b49fd5c1e25 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -514,13 +514,14 @@ static int idxd_probe(struct idxd_device *idxd)
 	if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) {
 		if (iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA))
 			dev_warn(dev, "Unable to turn on user SVA feature.\n");
-		else
+		else {
 			set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags);
 
-		if (idxd_enable_system_pasid(idxd))
-			dev_warn(dev, "No in-kernel DMA with PASID.\n");
-		else
-			set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
+			if (idxd_enable_system_pasid(idxd))
+				dev_warn(dev, "No in-kernel DMA with PASID.\n");
+			else
+				set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
+		}
 	} else if (!sva) {
 		dev_warn(dev, "User forced SVA off via module param.\n");
 	}
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-05 13:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-25 22:13 [PATCH] dmaengine: idxd: Only call idxd_enable_system_pasid if succeeded in enabling SVA feature Jerry Snitselaar
2022-06-26  4:20 ` Fenghua Yu
2022-06-26  4:51 ` [PATCH v2] dmaengine: idxd: Only call idxd_enable_system_pasid() " Jerry Snitselaar
2022-06-26  5:06   ` Fenghua Yu
2022-06-26  5:16 ` [PATCH v3] " Jerry Snitselaar
2022-06-26  5:36   ` Fenghua Yu
2022-07-01 17:52     ` Jerry Snitselaar
2022-07-05 13:00   ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox