Skip to content

Commit 42f0cbb

Browse files
committed
Merge branches 'intel/vt-d', 'amd/amd-vi' and 'iommufd/arm-smmuv3-nested' into next
4 parents ae3325f + 980e301 + 18f5a6b + f6681ab commit 42f0cbb

35 files changed

+1470
-1252
lines changed

drivers/acpi/arm64/iort.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,17 @@ static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node)
12181218
return pci_rc->ats_attribute & ACPI_IORT_ATS_SUPPORTED;
12191219
}
12201220

1221+
static bool iort_pci_rc_supports_canwbs(struct acpi_iort_node *node)
1222+
{
1223+
struct acpi_iort_memory_access *memory_access;
1224+
struct acpi_iort_root_complex *pci_rc;
1225+
1226+
pci_rc = (struct acpi_iort_root_complex *)node->node_data;
1227+
memory_access =
1228+
(struct acpi_iort_memory_access *)&pci_rc->memory_properties;
1229+
return memory_access->memory_flags & ACPI_IORT_MF_CANWBS;
1230+
}
1231+
12211232
static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
12221233
u32 streamid)
12231234
{
@@ -1335,6 +1346,8 @@ int iort_iommu_configure_id(struct device *dev, const u32 *id_in)
13351346
fwspec = dev_iommu_fwspec_get(dev);
13361347
if (fwspec && iort_pci_rc_supports_ats(node))
13371348
fwspec->flags |= IOMMU_FWSPEC_PCI_RC_ATS;
1349+
if (fwspec && iort_pci_rc_supports_canwbs(node))
1350+
fwspec->flags |= IOMMU_FWSPEC_PCI_RC_CANWBS;
13381351
} else {
13391352
node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT,
13401353
iort_match_node_callback, dev);

drivers/iommu/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ config ARM_SMMU_V3_SVA
416416
Say Y here if your system supports SVA extensions such as PCIe PASID
417417
and PRI.
418418

419+
config ARM_SMMU_V3_IOMMUFD
420+
bool "Enable IOMMUFD features for ARM SMMUv3 (EXPERIMENTAL)"
421+
depends on IOMMUFD
422+
help
423+
Support for IOMMUFD features intended to support virtual machines
424+
with accelerated virtual IOMMUs.
425+
426+
Say Y here if you are doing development and testing on this feature.
427+
419428
config ARM_SMMU_V3_KUNIT_TEST
420429
tristate "KUnit tests for arm-smmu-v3 driver" if !KUNIT_ALL_TESTS
421430
depends on KUNIT

drivers/iommu/amd/amd_iommu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
5353
struct mm_struct *mm);
5454
void amd_iommu_domain_free(struct iommu_domain *dom);
5555
int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
56-
struct device *dev, ioasid_t pasid);
56+
struct device *dev, ioasid_t pasid,
57+
struct iommu_domain *old);
5758
void amd_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
5859
struct iommu_domain *domain);
5960

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ struct pdom_dev_data {
565565
struct list_head list;
566566
};
567567

568+
/* Keeps track of the IOMMUs attached to protection domain */
569+
struct pdom_iommu_info {
570+
struct amd_iommu *iommu; /* IOMMUs attach to protection domain */
571+
u32 refcnt; /* Count of attached dev/pasid per domain/IOMMU */
572+
};
573+
568574
/*
569575
* This structure contains generic data for IOMMU protection domains
570576
* independent of their use.
@@ -578,8 +584,7 @@ struct protection_domain {
578584
u16 id; /* the domain id written to the device table */
579585
enum protection_domain_mode pd_mode; /* Track page table type */
580586
bool dirty_tracking; /* dirty tracking is enabled in the domain */
581-
unsigned dev_cnt; /* devices assigned to this domain */
582-
unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */
587+
struct xarray iommu_array; /* per-IOMMU reference count */
583588

584589
struct mmu_notifier mn; /* mmu notifier for the SVA domain */
585590
struct list_head dev_data_list; /* List of pdom_dev_data */
@@ -831,7 +836,7 @@ struct devid_map {
831836
*/
832837
struct iommu_dev_data {
833838
/*Protect against attach/detach races */
834-
spinlock_t lock;
839+
struct mutex mutex;
835840

836841
struct list_head list; /* For domain->dev_list */
837842
struct llist_node dev_data_list; /* For global dev_data_list */
@@ -872,12 +877,6 @@ extern struct list_head amd_iommu_pci_seg_list;
872877
*/
873878
extern struct list_head amd_iommu_list;
874879

875-
/*
876-
* Array with pointers to each IOMMU struct
877-
* The indices are referenced in the protection domains
878-
*/
879-
extern struct amd_iommu *amd_iommus[MAX_IOMMUS];
880-
881880
/*
882881
* Structure defining one entry in the device table
883882
*/
@@ -912,14 +911,14 @@ struct unity_map_entry {
912911
/* size of the dma_ops aperture as power of 2 */
913912
extern unsigned amd_iommu_aperture_order;
914913

915-
/* allocation bitmap for domain ids */
916-
extern unsigned long *amd_iommu_pd_alloc_bitmap;
917-
918914
extern bool amd_iommu_force_isolation;
919915

920916
/* Max levels of glxval supported */
921917
extern int amd_iommu_max_glx_val;
922918

919+
/* IDA to track protection domain IDs */
920+
extern struct ida pdom_ids;
921+
923922
/* Global EFR and EFR2 registers */
924923
extern u64 amd_iommu_efr;
925924
extern u64 amd_iommu_efr2;

drivers/iommu/amd/init.c

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ LIST_HEAD(amd_iommu_pci_seg_list); /* list of all PCI segments */
177177
LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the
178178
system */
179179

180-
/* Array to assign indices to IOMMUs*/
181-
struct amd_iommu *amd_iommus[MAX_IOMMUS];
182-
183180
/* Number of IOMMUs present in the system */
184181
static int amd_iommus_present;
185182

@@ -194,12 +191,6 @@ bool amd_iommu_force_isolation __read_mostly;
194191

195192
unsigned long amd_iommu_pgsize_bitmap __ro_after_init = AMD_IOMMU_PGSIZES;
196193

197-
/*
198-
* AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap
199-
* to know which ones are already in use.
200-
*/
201-
unsigned long *amd_iommu_pd_alloc_bitmap;
202-
203194
enum iommu_init_state {
204195
IOMMU_START_STATE,
205196
IOMMU_IVRS_DETECTED,
@@ -1082,7 +1073,12 @@ static bool __copy_device_table(struct amd_iommu *iommu)
10821073
if (dte_v && dom_id) {
10831074
pci_seg->old_dev_tbl_cpy[devid].data[0] = old_devtb[devid].data[0];
10841075
pci_seg->old_dev_tbl_cpy[devid].data[1] = old_devtb[devid].data[1];
1085-
__set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
1076+
/* Reserve the Domain IDs used by previous kernel */
1077+
if (ida_alloc_range(&pdom_ids, dom_id, dom_id, GFP_ATOMIC) != dom_id) {
1078+
pr_err("Failed to reserve domain ID 0x%x\n", dom_id);
1079+
memunmap(old_devtb);
1080+
return false;
1081+
}
10861082
/* If gcr3 table existed, mask it out */
10871083
if (old_devtb[devid].data[0] & DTE_FLAG_GV) {
10881084
tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B;
@@ -1744,9 +1740,6 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h,
17441740
return -ENOSYS;
17451741
}
17461742

1747-
/* Index is fine - add IOMMU to the array */
1748-
amd_iommus[iommu->index] = iommu;
1749-
17501743
/*
17511744
* Copy data from ACPI table entry to the iommu struct
17521745
*/
@@ -2877,11 +2870,6 @@ static void enable_iommus_vapic(void)
28772870
#endif
28782871
}
28792872

2880-
static void enable_iommus(void)
2881-
{
2882-
early_enable_iommus();
2883-
}
2884-
28852873
static void disable_iommus(void)
28862874
{
28872875
struct amd_iommu *iommu;
@@ -2908,7 +2896,8 @@ static void amd_iommu_resume(void)
29082896
iommu_apply_resume_quirks(iommu);
29092897

29102898
/* re-load the hardware */
2911-
enable_iommus();
2899+
for_each_iommu(iommu)
2900+
early_enable_iommu(iommu);
29122901

29132902
amd_iommu_enable_interrupts();
29142903
}
@@ -2989,9 +2978,7 @@ static bool __init check_ioapic_information(void)
29892978

29902979
static void __init free_dma_resources(void)
29912980
{
2992-
iommu_free_pages(amd_iommu_pd_alloc_bitmap,
2993-
get_order(MAX_DOMAIN_ID / 8));
2994-
amd_iommu_pd_alloc_bitmap = NULL;
2981+
ida_destroy(&pdom_ids);
29952982

29962983
free_unity_maps();
29972984
}
@@ -3059,20 +3046,6 @@ static int __init early_amd_iommu_init(void)
30593046
amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base);
30603047
DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type);
30613048

3062-
/* Device table - directly used by all IOMMUs */
3063-
ret = -ENOMEM;
3064-
3065-
amd_iommu_pd_alloc_bitmap = iommu_alloc_pages(GFP_KERNEL,
3066-
get_order(MAX_DOMAIN_ID / 8));
3067-
if (amd_iommu_pd_alloc_bitmap == NULL)
3068-
goto out;
3069-
3070-
/*
3071-
* never allocate domain 0 because its used as the non-allocated and
3072-
* error value placeholder
3073-
*/
3074-
__set_bit(0, amd_iommu_pd_alloc_bitmap);
3075-
30763049
/*
30773050
* now the data structures are allocated and basically initialized
30783051
* start the real acpi table scan

drivers/iommu/amd/io_pgtable.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static void free_sub_pt(u64 *root, int mode, struct list_head *freelist)
118118
*/
119119
static bool increase_address_space(struct amd_io_pgtable *pgtable,
120120
unsigned long address,
121+
unsigned int page_size_level,
121122
gfp_t gfp)
122123
{
123124
struct io_pgtable_cfg *cfg = &pgtable->pgtbl.cfg;
@@ -133,7 +134,8 @@ static bool increase_address_space(struct amd_io_pgtable *pgtable,
133134

134135
spin_lock_irqsave(&domain->lock, flags);
135136

136-
if (address <= PM_LEVEL_SIZE(pgtable->mode))
137+
if (address <= PM_LEVEL_SIZE(pgtable->mode) &&
138+
pgtable->mode - 1 >= page_size_level)
137139
goto out;
138140

139141
ret = false;
@@ -163,18 +165,21 @@ static u64 *alloc_pte(struct amd_io_pgtable *pgtable,
163165
gfp_t gfp,
164166
bool *updated)
165167
{
168+
unsigned long last_addr = address + (page_size - 1);
166169
struct io_pgtable_cfg *cfg = &pgtable->pgtbl.cfg;
167170
int level, end_lvl;
168171
u64 *pte, *page;
169172

170173
BUG_ON(!is_power_of_2(page_size));
171174

172-
while (address > PM_LEVEL_SIZE(pgtable->mode)) {
175+
while (last_addr > PM_LEVEL_SIZE(pgtable->mode) ||
176+
pgtable->mode - 1 < PAGE_SIZE_LEVEL(page_size)) {
173177
/*
174178
* Return an error if there is no memory to update the
175179
* page-table.
176180
*/
177-
if (!increase_address_space(pgtable, address, gfp))
181+
if (!increase_address_space(pgtable, last_addr,
182+
PAGE_SIZE_LEVEL(page_size), gfp))
178183
return NULL;
179184
}
180185

drivers/iommu/amd/io_pgtable_v2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ static int iommu_v2_map_pages(struct io_pgtable_ops *ops, unsigned long iova,
268268
out:
269269
if (updated) {
270270
struct protection_domain *pdom = io_pgtable_ops_to_domain(ops);
271+
unsigned long flags;
271272

273+
spin_lock_irqsave(&pdom->lock, flags);
272274
amd_iommu_domain_flush_pages(pdom, o_iova, size);
275+
spin_unlock_irqrestore(&pdom->lock, flags);
273276
}
274277

275278
if (mapped)

0 commit comments

Comments
 (0)