Skip to content

Commit 93fa6cf

Browse files
committed
Merge branch 'iommu/guest-msi' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into arm/core
2 parents 566cf87 + 5018c8d commit 93fa6cf

File tree

14 files changed

+590
-93
lines changed

14 files changed

+590
-93
lines changed

Documentation/ABI/testing/sysfs-kernel-iommu_groups

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ Description: /sys/kernel/iommu_groups/ contains a number of sub-
1212
file if the IOMMU driver has chosen to register a more
1313
common name for the group.
1414
Users:
15+
16+
What: /sys/kernel/iommu_groups/reserved_regions
17+
Date: January 2017
18+
KernelVersion: v4.11
19+
Contact: Eric Auger <[email protected]>
20+
Description: /sys/kernel/iommu_groups/reserved_regions list IOVA
21+
regions that are reserved. Not necessarily all
22+
reserved regions are listed. This is typically used to
23+
output direct-mapped, MSI, non mappable regions. Each
24+
region is described on a single line: the 1st field is
25+
the base IOVA, the second is the end IOVA and the third
26+
field describes the type of the region.

drivers/iommu/amd_iommu.c

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,9 +3161,10 @@ static bool amd_iommu_capable(enum iommu_cap cap)
31613161
return false;
31623162
}
31633163

3164-
static void amd_iommu_get_dm_regions(struct device *dev,
3165-
struct list_head *head)
3164+
static void amd_iommu_get_resv_regions(struct device *dev,
3165+
struct list_head *head)
31663166
{
3167+
struct iommu_resv_region *region;
31673168
struct unity_map_entry *entry;
31683169
int devid;
31693170

@@ -3172,41 +3173,56 @@ static void amd_iommu_get_dm_regions(struct device *dev,
31723173
return;
31733174

31743175
list_for_each_entry(entry, &amd_iommu_unity_map, list) {
3175-
struct iommu_dm_region *region;
3176+
size_t length;
3177+
int prot = 0;
31763178

31773179
if (devid < entry->devid_start || devid > entry->devid_end)
31783180
continue;
31793181

3180-
region = kzalloc(sizeof(*region), GFP_KERNEL);
3182+
length = entry->address_end - entry->address_start;
3183+
if (entry->prot & IOMMU_PROT_IR)
3184+
prot |= IOMMU_READ;
3185+
if (entry->prot & IOMMU_PROT_IW)
3186+
prot |= IOMMU_WRITE;
3187+
3188+
region = iommu_alloc_resv_region(entry->address_start,
3189+
length, prot,
3190+
IOMMU_RESV_DIRECT);
31813191
if (!region) {
31823192
pr_err("Out of memory allocating dm-regions for %s\n",
31833193
dev_name(dev));
31843194
return;
31853195
}
3186-
3187-
region->start = entry->address_start;
3188-
region->length = entry->address_end - entry->address_start;
3189-
if (entry->prot & IOMMU_PROT_IR)
3190-
region->prot |= IOMMU_READ;
3191-
if (entry->prot & IOMMU_PROT_IW)
3192-
region->prot |= IOMMU_WRITE;
3193-
31943196
list_add_tail(&region->list, head);
31953197
}
3198+
3199+
region = iommu_alloc_resv_region(MSI_RANGE_START,
3200+
MSI_RANGE_END - MSI_RANGE_START + 1,
3201+
0, IOMMU_RESV_RESERVED);
3202+
if (!region)
3203+
return;
3204+
list_add_tail(&region->list, head);
3205+
3206+
region = iommu_alloc_resv_region(HT_RANGE_START,
3207+
HT_RANGE_END - HT_RANGE_START + 1,
3208+
0, IOMMU_RESV_RESERVED);
3209+
if (!region)
3210+
return;
3211+
list_add_tail(&region->list, head);
31963212
}
31973213

3198-
static void amd_iommu_put_dm_regions(struct device *dev,
3214+
static void amd_iommu_put_resv_regions(struct device *dev,
31993215
struct list_head *head)
32003216
{
3201-
struct iommu_dm_region *entry, *next;
3217+
struct iommu_resv_region *entry, *next;
32023218

32033219
list_for_each_entry_safe(entry, next, head, list)
32043220
kfree(entry);
32053221
}
32063222

3207-
static void amd_iommu_apply_dm_region(struct device *dev,
3223+
static void amd_iommu_apply_resv_region(struct device *dev,
32083224
struct iommu_domain *domain,
3209-
struct iommu_dm_region *region)
3225+
struct iommu_resv_region *region)
32103226
{
32113227
struct dma_ops_domain *dma_dom = to_dma_ops_domain(to_pdomain(domain));
32123228
unsigned long start, end;
@@ -3230,9 +3246,9 @@ static const struct iommu_ops amd_iommu_ops = {
32303246
.add_device = amd_iommu_add_device,
32313247
.remove_device = amd_iommu_remove_device,
32323248
.device_group = amd_iommu_device_group,
3233-
.get_dm_regions = amd_iommu_get_dm_regions,
3234-
.put_dm_regions = amd_iommu_put_dm_regions,
3235-
.apply_dm_region = amd_iommu_apply_dm_region,
3249+
.get_resv_regions = amd_iommu_get_resv_regions,
3250+
.put_resv_regions = amd_iommu_put_resv_regions,
3251+
.apply_resv_region = amd_iommu_apply_resv_region,
32363252
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
32373253
};
32383254

drivers/iommu/arm-smmu-v3.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@
412412
/* High-level queue structures */
413413
#define ARM_SMMU_POLL_TIMEOUT_US 100
414414

415+
#define MSI_IOVA_BASE 0x8000000
416+
#define MSI_IOVA_LENGTH 0x100000
417+
415418
static bool disable_bypass;
416419
module_param_named(disable_bypass, disable_bypass, bool, S_IRUGO);
417420
MODULE_PARM_DESC(disable_bypass,
@@ -1372,8 +1375,6 @@ static bool arm_smmu_capable(enum iommu_cap cap)
13721375
switch (cap) {
13731376
case IOMMU_CAP_CACHE_COHERENCY:
13741377
return true;
1375-
case IOMMU_CAP_INTR_REMAP:
1376-
return true; /* MSIs are just memory writes */
13771378
case IOMMU_CAP_NOEXEC:
13781379
return true;
13791380
default:
@@ -1883,6 +1884,29 @@ static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args)
18831884
return iommu_fwspec_add_ids(dev, args->args, 1);
18841885
}
18851886

1887+
static void arm_smmu_get_resv_regions(struct device *dev,
1888+
struct list_head *head)
1889+
{
1890+
struct iommu_resv_region *region;
1891+
int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
1892+
1893+
region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
1894+
prot, IOMMU_RESV_MSI);
1895+
if (!region)
1896+
return;
1897+
1898+
list_add_tail(&region->list, head);
1899+
}
1900+
1901+
static void arm_smmu_put_resv_regions(struct device *dev,
1902+
struct list_head *head)
1903+
{
1904+
struct iommu_resv_region *entry, *next;
1905+
1906+
list_for_each_entry_safe(entry, next, head, list)
1907+
kfree(entry);
1908+
}
1909+
18861910
static struct iommu_ops arm_smmu_ops = {
18871911
.capable = arm_smmu_capable,
18881912
.domain_alloc = arm_smmu_domain_alloc,
@@ -1898,6 +1922,8 @@ static struct iommu_ops arm_smmu_ops = {
18981922
.domain_get_attr = arm_smmu_domain_get_attr,
18991923
.domain_set_attr = arm_smmu_domain_set_attr,
19001924
.of_xlate = arm_smmu_of_xlate,
1925+
.get_resv_regions = arm_smmu_get_resv_regions,
1926+
.put_resv_regions = arm_smmu_put_resv_regions,
19011927
.pgsize_bitmap = -1UL, /* Restricted during device attach */
19021928
};
19031929

drivers/iommu/arm-smmu.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ enum arm_smmu_s2cr_privcfg {
281281

282282
#define FSYNR0_WNR (1 << 4)
283283

284+
#define MSI_IOVA_BASE 0x8000000
285+
#define MSI_IOVA_LENGTH 0x100000
286+
284287
static int force_stage;
285288
module_param(force_stage, int, S_IRUGO);
286289
MODULE_PARM_DESC(force_stage,
@@ -1371,8 +1374,6 @@ static bool arm_smmu_capable(enum iommu_cap cap)
13711374
* requests.
13721375
*/
13731376
return true;
1374-
case IOMMU_CAP_INTR_REMAP:
1375-
return true; /* MSIs are just memory writes */
13761377
case IOMMU_CAP_NOEXEC:
13771378
return true;
13781379
default:
@@ -1549,6 +1550,29 @@ static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args)
15491550
return iommu_fwspec_add_ids(dev, &fwid, 1);
15501551
}
15511552

1553+
static void arm_smmu_get_resv_regions(struct device *dev,
1554+
struct list_head *head)
1555+
{
1556+
struct iommu_resv_region *region;
1557+
int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
1558+
1559+
region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
1560+
prot, IOMMU_RESV_MSI);
1561+
if (!region)
1562+
return;
1563+
1564+
list_add_tail(&region->list, head);
1565+
}
1566+
1567+
static void arm_smmu_put_resv_regions(struct device *dev,
1568+
struct list_head *head)
1569+
{
1570+
struct iommu_resv_region *entry, *next;
1571+
1572+
list_for_each_entry_safe(entry, next, head, list)
1573+
kfree(entry);
1574+
}
1575+
15521576
static struct iommu_ops arm_smmu_ops = {
15531577
.capable = arm_smmu_capable,
15541578
.domain_alloc = arm_smmu_domain_alloc,
@@ -1564,6 +1588,8 @@ static struct iommu_ops arm_smmu_ops = {
15641588
.domain_get_attr = arm_smmu_domain_get_attr,
15651589
.domain_set_attr = arm_smmu_domain_set_attr,
15661590
.of_xlate = arm_smmu_of_xlate,
1591+
.get_resv_regions = arm_smmu_get_resv_regions,
1592+
.put_resv_regions = arm_smmu_put_resv_regions,
15671593
.pgsize_bitmap = -1UL, /* Restricted during device attach */
15681594
};
15691595

0 commit comments

Comments
 (0)