Skip to content

Commit 47e231c

Browse files
committed
Merge tag 'iommu-fixes-v7.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux
Pull iommu fixes from Joerg Roedel: "Intel VT-d: - Abort all pending requests on dev_tlb_inv timeout to avoid hardlockup - Limit IOPF handling to PRI-capable device to avoid SVA attach failure AMD-Vi: - Make sure identity domain is not used when SNP is active Core fixes: - Handle mapping IOVA 0x0 correctly - Fix crash in SVA code - Kernel-doc fix in IO-PGTable code" * tag 'iommu-fixes-v7.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux: iommu/amd: Block identity domain when SNP enabled iommu/sva: Fix crash in iommu_sva_unbind_device() iommu/io-pgtable: fix all kernel-doc warnings in io-pgtable.h iommu: Fix mapping check for 0x0 to avoid re-mapping it iommu/vt-d: Only handle IOPF for SVA when PRI is supported iommu/vt-d: Fix intel iommu iotlb sync hardlockup and retry
2 parents 1651602 + ba17de9 commit 47e231c

6 files changed

Lines changed: 42 additions & 16 deletions

File tree

drivers/iommu/amd/iommu.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2909,8 +2909,21 @@ static struct iommu_domain blocked_domain = {
29092909

29102910
static struct protection_domain identity_domain;
29112911

2912+
static int amd_iommu_identity_attach(struct iommu_domain *dom, struct device *dev,
2913+
struct iommu_domain *old)
2914+
{
2915+
/*
2916+
* Don't allow attaching a device to the identity domain if SNP is
2917+
* enabled.
2918+
*/
2919+
if (amd_iommu_snp_en)
2920+
return -EINVAL;
2921+
2922+
return amd_iommu_attach_device(dom, dev, old);
2923+
}
2924+
29122925
static const struct iommu_domain_ops identity_domain_ops = {
2913-
.attach_dev = amd_iommu_attach_device,
2926+
.attach_dev = amd_iommu_identity_attach,
29142927
};
29152928

29162929
void amd_iommu_init_identity_domain(void)

drivers/iommu/intel/dmar.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,6 @@ static int qi_check_fault(struct intel_iommu *iommu, int index, int wait_index)
13141314
if (fault & DMA_FSTS_ITE) {
13151315
head = readl(iommu->reg + DMAR_IQH_REG);
13161316
head = ((head >> shift) - 1 + QI_LENGTH) % QI_LENGTH;
1317-
head |= 1;
13181317
tail = readl(iommu->reg + DMAR_IQT_REG);
13191318
tail = ((tail >> shift) - 1 + QI_LENGTH) % QI_LENGTH;
13201319

@@ -1331,7 +1330,7 @@ static int qi_check_fault(struct intel_iommu *iommu, int index, int wait_index)
13311330
do {
13321331
if (qi->desc_status[head] == QI_IN_USE)
13331332
qi->desc_status[head] = QI_ABORT;
1334-
head = (head - 2 + QI_LENGTH) % QI_LENGTH;
1333+
head = (head - 1 + QI_LENGTH) % QI_LENGTH;
13351334
} while (head != tail);
13361335

13371336
/*

drivers/iommu/intel/svm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain,
164164
if (IS_ERR(dev_pasid))
165165
return PTR_ERR(dev_pasid);
166166

167-
ret = iopf_for_domain_replace(domain, old, dev);
168-
if (ret)
169-
goto out_remove_dev_pasid;
167+
/* SVA with non-IOMMU/PRI IOPF handling is allowed. */
168+
if (info->pri_supported) {
169+
ret = iopf_for_domain_replace(domain, old, dev);
170+
if (ret)
171+
goto out_remove_dev_pasid;
172+
}
170173

171174
/* Setup the pasid table: */
172175
sflags = cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0;
@@ -181,7 +184,8 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain,
181184

182185
return 0;
183186
out_unwind_iopf:
184-
iopf_for_domain_replace(old, domain, dev);
187+
if (info->pri_supported)
188+
iopf_for_domain_replace(old, domain, dev);
185189
out_remove_dev_pasid:
186190
domain_remove_dev_pasid(domain, dev, pasid);
187191
return ret;

drivers/iommu/iommu-sva.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
182182
iommu_detach_device_pasid(domain, dev, iommu_mm->pasid);
183183
if (--domain->users == 0) {
184184
list_del(&domain->next);
185-
iommu_domain_free(domain);
186-
}
185+
if (list_empty(&iommu_mm->sva_domains)) {
186+
list_del(&iommu_mm->mm_list_elm);
187+
if (list_empty(&iommu_sva_mms))
188+
iommu_sva_present = false;
189+
}
187190

188-
if (list_empty(&iommu_mm->sva_domains)) {
189-
list_del(&iommu_mm->mm_list_elm);
190-
if (list_empty(&iommu_sva_mms))
191-
iommu_sva_present = false;
191+
iommu_domain_free(domain);
192192
}
193193

194194
mutex_unlock(&iommu_sva_lock);

drivers/iommu/iommu.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,11 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain,
12131213
if (addr == end)
12141214
goto map_end;
12151215

1216-
phys_addr = iommu_iova_to_phys(domain, addr);
1216+
/*
1217+
* Return address by iommu_iova_to_phys for 0 is
1218+
* ambiguous. Offset to address 1 if addr is 0.
1219+
*/
1220+
phys_addr = iommu_iova_to_phys(domain, addr ? addr : 1);
12171221
if (!phys_addr) {
12181222
map_size += pg_size;
12191223
continue;

include/linux/io-pgtable.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct iommu_flush_ops {
5353
* tables.
5454
* @ias: Input address (iova) size, in bits.
5555
* @oas: Output address (paddr) size, in bits.
56-
* @coherent_walk A flag to indicate whether or not page table walks made
56+
* @coherent_walk: A flag to indicate whether or not page table walks made
5757
* by the IOMMU are coherent with the CPU caches.
5858
* @tlb: TLB management callbacks for this set of tables.
5959
* @iommu_dev: The device representing the DMA configuration for the
@@ -136,6 +136,7 @@ struct io_pgtable_cfg {
136136
void (*free)(void *cookie, void *pages, size_t size);
137137

138138
/* Low-level data specific to the table format */
139+
/* private: */
139140
union {
140141
struct {
141142
u64 ttbr;
@@ -203,6 +204,9 @@ struct arm_lpae_io_pgtable_walk_data {
203204
* @unmap_pages: Unmap a range of virtually contiguous pages of the same size.
204205
* @iova_to_phys: Translate iova to physical address.
205206
* @pgtable_walk: (optional) Perform a page table walk for a given iova.
207+
* @read_and_clear_dirty: Record dirty info per IOVA. If an IOVA is dirty,
208+
* clear its dirty state from the PTE unless the
209+
* IOMMU_DIRTY_NO_CLEAR flag is passed in.
206210
*
207211
* These functions map directly onto the iommu_ops member functions with
208212
* the same names.
@@ -231,7 +235,9 @@ struct io_pgtable_ops {
231235
* the configuration actually provided by the allocator (e.g. the
232236
* pgsize_bitmap may be restricted).
233237
* @cookie: An opaque token provided by the IOMMU driver and passed back to
234-
* the callback routines in cfg->tlb.
238+
* the callback routines.
239+
*
240+
* Returns: Pointer to the &struct io_pgtable_ops for this set of page tables.
235241
*/
236242
struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
237243
struct io_pgtable_cfg *cfg,

0 commit comments

Comments
 (0)