Skip to contentSkip to conversation

FAILED: patch "[PATCH] iommu/sva: Set handle->dev before the SVA handle is visible" failed to apply to 6.6-stable tree

PATCH New [email protected] 2 participants 2 messages Sep 3 – Sep 9

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 530f8f9c3546cb3ebee1b135375aaee08a073ebb
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090353-deck-monument-5171@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 530f8f9c3546cb3ebee1b135375aaee08a073ebb Mon Sep 17 00:00:00 2001
From: Shuai Xue <[email protected]>
Date: Sun, 26 Jul 2026 15:43:29 +0800
Subject: [PATCH] iommu/sva: Set handle->dev before the SVA handle is visible

iommu_attach_device_pasid() installs the new SVA attach handle in the group PASID lookup before iommu_sva_bind_device() returns. A concurrent bind can therefore find and reuse the same handle after iommu_sva_lock is dropped.

handle->dev was initialized after dropping iommu_sva_lock. This leaves a window where a racing bind can return a handle whose dev pointer is still NULL. A subsequent iommu_sva_unbind_device() can then dereference it via handle->dev->iommu_group.

Initialize handle->dev before releasing iommu_sva_lock so any visible SVA handle is fully initialized.

Fixes be51b1d6bbff ("iommu/sva: Refactoring iommu_sva_bind/unbind_device()")
Assisted-by Qoder:Qwen-3.8-MAX-Preview
drivers/iommu/iommu-sva.c +1 -1
index bc7c7232a43e..9742cb593577 100644
@@ -145,8 +145,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 	list_add(&domain->next, &iommu_mm->sva_domains);
 out:
 	refcount_set(&handle->users, 1);
-	mutex_unlock(&iommu_sva_lock);
 	handle->dev = dev;
+	mutex_unlock(&iommu_sva_lock);
 	return handle;
 
 out_free_domain:
maintainer
#1 lore raw

PATCH 1/1 iommu/sva: Set handle->dev before the SVA handle is visible

From: Shuai Xue <[email protected]>

[ Upstream commit 530f8f9c3546cb3ebee1b135375aaee08a073ebb ]

iommu_attach_device_pasid() installs the new SVA attach handle in the group PASID lookup before iommu_sva_bind_device() returns. A concurrent bind can therefore find and reuse the same handle after iommu_sva_lock is dropped.

handle->dev was initialized after dropping iommu_sva_lock. This leaves a window where a racing bind can return a handle whose dev pointer is still NULL. A subsequent iommu_sva_unbind_device() can then dereference it via handle->dev->iommu_group.

Initialize handle->dev before releasing iommu_sva_lock so any visible SVA handle is fully initialized.

Fixes be51b1d6bbff ("iommu/sva: Refactoring iommu_sva_bind/unbind_device()")
Assisted-by Qoder:Qwen-3.8-MAX-Preview
[ Adjusted context for per-bind SVA handles lacking handle->users reference counting. ]
---
 drivers/iommu/iommu-sva.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iommu-sva.c +1 -1
index a340b805b82b7..4605304410be1 100644
@@ -100,8 +100,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
 		goto out_free_domain;
 	domain->users = 1;
 out:
-	mutex_unlock(&iommu_sva_lock);
 	handle->dev = dev;
+	mutex_unlock(&iommu_sva_lock);
 	handle->domain = domain;
 
 	return handle;
Signature · 1 line
2.53.0