Skip to content

Commit 1a3a7d6

Browse files
niklas88joergroedel
authored andcommitted
iommu/s390: Get rid of s390_domain_device
The struct s390_domain_device serves the sole purpose as list entry for the devices list of a struct s390_domain. As it contains no additional information besides a list_head and a pointer to the struct zpci_dev we can simplify things and just thread the device list through struct zpci_dev directly. This removes the need to allocate during domain attach and gets rid of one level of indirection during mapping operations. Reviewed-by: Matthew Rosato <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent bf8d2dd commit 1a3a7d6

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

arch/s390/include/asm/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct zpci_bus {
117117
struct zpci_dev {
118118
struct zpci_bus *zbus;
119119
struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */
120+
struct list_head iommu_list;
120121
struct kref kref;
121122
struct hotplug_slot hotplug_slot;
122123

drivers/iommu/s390-iommu.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ struct s390_domain {
2929
spinlock_t list_lock;
3030
};
3131

32-
struct s390_domain_device {
33-
struct list_head list;
34-
struct zpci_dev *zdev;
35-
};
36-
3732
static struct s390_domain *to_s390_domain(struct iommu_domain *dom)
3833
{
3934
return container_of(dom, struct s390_domain, domain);
@@ -87,21 +82,13 @@ static void s390_domain_free(struct iommu_domain *domain)
8782
static void __s390_iommu_detach_device(struct zpci_dev *zdev)
8883
{
8984
struct s390_domain *s390_domain = zdev->s390_domain;
90-
struct s390_domain_device *domain_device, *tmp;
9185
unsigned long flags;
9286

9387
if (!s390_domain)
9488
return;
9589

9690
spin_lock_irqsave(&s390_domain->list_lock, flags);
97-
list_for_each_entry_safe(domain_device, tmp, &s390_domain->devices,
98-
list) {
99-
if (domain_device->zdev == zdev) {
100-
list_del(&domain_device->list);
101-
kfree(domain_device);
102-
break;
103-
}
104-
}
91+
list_del_init(&zdev->iommu_list);
10592
spin_unlock_irqrestore(&s390_domain->list_lock, flags);
10693

10794
zpci_unregister_ioat(zdev, 0);
@@ -114,28 +101,21 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
114101
{
115102
struct s390_domain *s390_domain = to_s390_domain(domain);
116103
struct zpci_dev *zdev = to_zpci_dev(dev);
117-
struct s390_domain_device *domain_device;
118104
unsigned long flags;
119105
int cc, rc = 0;
120106

121107
if (!zdev)
122108
return -ENODEV;
123109

124-
domain_device = kzalloc(sizeof(*domain_device), GFP_KERNEL);
125-
if (!domain_device)
126-
return -ENOMEM;
127-
128110
if (zdev->s390_domain)
129111
__s390_iommu_detach_device(zdev);
130112
else if (zdev->dma_table)
131113
zpci_dma_exit_device(zdev);
132114

133115
cc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
134116
virt_to_phys(s390_domain->dma_table));
135-
if (cc) {
136-
rc = -EIO;
137-
goto out_free;
138-
}
117+
if (cc)
118+
return -EIO;
139119
zdev->dma_table = s390_domain->dma_table;
140120

141121
spin_lock_irqsave(&s390_domain->list_lock, flags);
@@ -151,18 +131,15 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
151131
rc = -EINVAL;
152132
goto out_unregister;
153133
}
154-
domain_device->zdev = zdev;
155134
zdev->s390_domain = s390_domain;
156-
list_add(&domain_device->list, &s390_domain->devices);
135+
list_add(&zdev->iommu_list, &s390_domain->devices);
157136
spin_unlock_irqrestore(&s390_domain->list_lock, flags);
158137

159138
return 0;
160139

161140
out_unregister:
162141
zpci_unregister_ioat(zdev, 0);
163142
zdev->dma_table = NULL;
164-
out_free:
165-
kfree(domain_device);
166143

167144
return rc;
168145
}
@@ -206,10 +183,10 @@ static int s390_iommu_update_trans(struct s390_domain *s390_domain,
206183
phys_addr_t pa, dma_addr_t dma_addr,
207184
size_t size, int flags)
208185
{
209-
struct s390_domain_device *domain_device;
210186
phys_addr_t page_addr = pa & PAGE_MASK;
211187
dma_addr_t start_dma_addr = dma_addr;
212188
unsigned long irq_flags, nr_pages, i;
189+
struct zpci_dev *zdev;
213190
unsigned long *entry;
214191
int rc = 0;
215192

@@ -234,8 +211,8 @@ static int s390_iommu_update_trans(struct s390_domain *s390_domain,
234211
}
235212

236213
spin_lock(&s390_domain->list_lock);
237-
list_for_each_entry(domain_device, &s390_domain->devices, list) {
238-
rc = zpci_refresh_trans((u64) domain_device->zdev->fh << 32,
214+
list_for_each_entry(zdev, &s390_domain->devices, iommu_list) {
215+
rc = zpci_refresh_trans((u64)zdev->fh << 32,
239216
start_dma_addr, nr_pages * PAGE_SIZE);
240217
if (rc)
241218
break;

0 commit comments

Comments
 (0)