Skip to content

Commit fa7e9ec

Browse files
rosatomjjoergroedel
authored andcommitted
iommu/s390: Tolerate repeat attach_dev calls
Since commit 0286300 ("iommu: iommu_group_claim_dma_owner() must always assign a domain") s390-iommu will get called to allocate multiple unmanaged iommu domains for a vfio-pci device -- however the current s390-iommu logic tolerates only one. Recognize that multiple domains can be allocated and handle switching between DMA or different iommu domain tables during attach_dev. Signed-off-by: Matthew Rosato <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 0286300 commit fa7e9ec

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/iommu/s390-iommu.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
9999
if (!domain_device)
100100
return -ENOMEM;
101101

102-
if (zdev->dma_table) {
102+
if (zdev->dma_table && !zdev->s390_domain) {
103103
cc = zpci_dma_exit_device(zdev);
104104
if (cc) {
105105
rc = -EIO;
106106
goto out_free;
107107
}
108108
}
109109

110+
if (zdev->s390_domain)
111+
zpci_unregister_ioat(zdev, 0);
112+
110113
zdev->dma_table = s390_domain->dma_table;
111114
cc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
112115
virt_to_phys(zdev->dma_table));
@@ -136,7 +139,13 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
136139
return 0;
137140

138141
out_restore:
139-
zpci_dma_init_device(zdev);
142+
if (!zdev->s390_domain) {
143+
zpci_dma_init_device(zdev);
144+
} else {
145+
zdev->dma_table = zdev->s390_domain->dma_table;
146+
zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
147+
virt_to_phys(zdev->dma_table));
148+
}
140149
out_free:
141150
kfree(domain_device);
142151

@@ -167,7 +176,7 @@ static void s390_iommu_detach_device(struct iommu_domain *domain,
167176
}
168177
spin_unlock_irqrestore(&s390_domain->list_lock, flags);
169178

170-
if (found) {
179+
if (found && (zdev->s390_domain == s390_domain)) {
171180
zdev->s390_domain = NULL;
172181
zpci_unregister_ioat(zdev, 0);
173182
zpci_dma_init_device(zdev);

0 commit comments

Comments
 (0)