Skip to content

Commit 1d65b90

Browse files
committed
Merge remote-tracking branch 'korg/core' into x86/amd
2 parents a270be1 + 75cc101 commit 1d65b90

File tree

14 files changed

+437
-239
lines changed

14 files changed

+437
-239
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,7 @@
290290
amd_iommu= [HW,X86-64]
291291
Pass parameters to the AMD IOMMU driver in the system.
292292
Possible values are:
293-
fullflush - enable flushing of IO/TLB entries when
294-
they are unmapped. Otherwise they are
295-
flushed before they will be reused, which
296-
is a lot of faster
293+
fullflush - Deprecated, equivalent to iommu.strict=1
297294
off - do not initialize any AMD IOMMU found in
298295
the system
299296
force_isolation - Force device isolation for all
@@ -1944,9 +1941,7 @@
19441941
this case, gfx device will use physical address for
19451942
DMA.
19461943
strict [Default Off]
1947-
With this option on every unmap_single operation will
1948-
result in a hardware IOTLB flush operation as opposed
1949-
to batching them for performance.
1944+
Deprecated, equivalent to iommu.strict=1.
19501945
sp_off [Default Off]
19511946
By default, super page will be supported if Intel IOMMU
19521947
has the capability. With this option, super page will
@@ -2047,9 +2042,10 @@
20472042
throughput at the cost of reduced device isolation.
20482043
Will fall back to strict mode if not supported by
20492044
the relevant IOMMU driver.
2050-
1 - Strict mode (default).
2045+
1 - Strict mode.
20512046
DMA unmap operations invalidate IOMMU hardware TLBs
20522047
synchronously.
2048+
unset - Use value of CONFIG_IOMMU_DEFAULT_{LAZY,STRICT}.
20532049
Note: on x86, the default behaviour depends on the
20542050
equivalent driver-specific parameters, but a strict
20552051
mode explicitly specified by either method takes

drivers/iommu/Kconfig

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,47 @@ config IOMMU_DEFAULT_PASSTHROUGH
9090

9191
If unsure, say N here.
9292

93+
choice
94+
prompt "IOMMU default DMA IOTLB invalidation mode"
95+
depends on IOMMU_DMA
96+
97+
default IOMMU_DEFAULT_LAZY if (AMD_IOMMU || INTEL_IOMMU)
98+
default IOMMU_DEFAULT_STRICT
99+
help
100+
This option allows an IOMMU DMA IOTLB invalidation mode to be
101+
chosen at build time, to override the default mode of each ARCH,
102+
removing the need to pass in kernel parameters through command line.
103+
It is still possible to provide common boot params to override this
104+
config.
105+
106+
If unsure, keep the default.
107+
108+
config IOMMU_DEFAULT_STRICT
109+
bool "strict"
110+
help
111+
For every IOMMU DMA unmap operation, the flush operation of IOTLB and
112+
the free operation of IOVA are guaranteed to be done in the unmap
113+
function.
114+
115+
config IOMMU_DEFAULT_LAZY
116+
bool "lazy"
117+
help
118+
Support lazy mode, where for every IOMMU DMA unmap operation, the
119+
flush operation of IOTLB and the free operation of IOVA are deferred.
120+
They are only guaranteed to be done before the related IOVA will be
121+
reused.
122+
123+
The isolation provided in this mode is not as secure as STRICT mode,
124+
such that a vulnerable time window may be created between the DMA
125+
unmap and the mappings cached in the IOMMU IOTLB or device TLB
126+
finally being invalidated, where the device could still access the
127+
memory which has already been unmapped by the device driver.
128+
However this mode may provide better performance in high throughput
129+
scenarios, and is still considerably more secure than passthrough
130+
mode or no IOMMU.
131+
132+
endchoice
133+
93134
config OF_IOMMU
94135
def_bool y
95136
depends on OF && IOMMU_API

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,6 @@ extern u16 amd_iommu_last_bdf;
779779
/* allocation bitmap for domain ids */
780780
extern unsigned long *amd_iommu_pd_alloc_bitmap;
781781

782-
/*
783-
* If true, the addresses will be flushed on unmap time, not when
784-
* they are reused
785-
*/
786-
extern bool amd_iommu_unmap_flush;
787-
788782
/* Smallest max PASID supported by any IOMMU in the system */
789783
extern u32 amd_iommu_max_pasid;
790784

drivers/iommu/amd/init.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ u16 amd_iommu_last_bdf; /* largest PCI device id we have
161161
to handle */
162162
LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings
163163
we find in ACPI */
164-
bool amd_iommu_unmap_flush; /* if true, flush on every unmap */
165164

166165
LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the
167166
system */
@@ -3103,8 +3102,10 @@ static int __init parse_amd_iommu_intr(char *str)
31033102
static int __init parse_amd_iommu_options(char *str)
31043103
{
31053104
for (; *str; ++str) {
3106-
if (strncmp(str, "fullflush", 9) == 0)
3107-
amd_iommu_unmap_flush = true;
3105+
if (strncmp(str, "fullflush", 9) == 0) {
3106+
pr_warn("amd_iommu=fullflush deprecated; use iommu.strict=1 instead\n");
3107+
iommu_set_dma_strict();
3108+
}
31083109
if (strncmp(str, "force_enable", 12) == 0)
31093110
amd_iommu_force_enable = true;
31103111
if (strncmp(str, "off", 3) == 0)

drivers/iommu/amd/io_pgtable.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,6 @@ static phys_addr_t iommu_v1_iova_to_phys(struct io_pgtable_ops *ops, unsigned lo
493493
unsigned long offset_mask, pte_pgsize;
494494
u64 *pte, __pte;
495495

496-
if (pgtable->mode == PAGE_MODE_NONE)
497-
return iova;
498-
499496
pte = fetch_pte(pgtable, iova, &pte_pgsize);
500497

501498
if (!pte || !IOMMU_PTE_PRESENT(*pte))

drivers/iommu/amd/iommu.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,12 +1818,6 @@ void amd_iommu_domain_update(struct protection_domain *domain)
18181818
static void __init amd_iommu_init_dma_ops(void)
18191819
{
18201820
swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
1821-
1822-
if (amd_iommu_unmap_flush)
1823-
pr_info("IO/TLB flush on unmap enabled\n");
1824-
else
1825-
pr_info("Lazy IO/TLB flushing enabled\n");
1826-
iommu_set_dma_strict(amd_iommu_unmap_flush);
18271821
}
18281822

18291823
int __init amd_iommu_init_api(void)

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,9 +2488,6 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
24882488
{
24892489
struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops;
24902490

2491-
if (domain->type == IOMMU_DOMAIN_IDENTITY)
2492-
return iova;
2493-
24942491
if (!ops)
24952492
return 0;
24962493

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,9 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11981198
return ret;
11991199
}
12001200

1201-
static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
1202-
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
1201+
static int arm_smmu_map_pages(struct iommu_domain *domain, unsigned long iova,
1202+
phys_addr_t paddr, size_t pgsize, size_t pgcount,
1203+
int prot, gfp_t gfp, size_t *mapped)
12031204
{
12041205
struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops;
12051206
struct arm_smmu_device *smmu = to_smmu_domain(domain)->smmu;
@@ -1209,14 +1210,15 @@ static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
12091210
return -ENODEV;
12101211

12111212
arm_smmu_rpm_get(smmu);
1212-
ret = ops->map(ops, iova, paddr, size, prot, gfp);
1213+
ret = ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, gfp, mapped);
12131214
arm_smmu_rpm_put(smmu);
12141215

12151216
return ret;
12161217
}
12171218

1218-
static size_t arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
1219-
size_t size, struct iommu_iotlb_gather *gather)
1219+
static size_t arm_smmu_unmap_pages(struct iommu_domain *domain, unsigned long iova,
1220+
size_t pgsize, size_t pgcount,
1221+
struct iommu_iotlb_gather *iotlb_gather)
12201222
{
12211223
struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops;
12221224
struct arm_smmu_device *smmu = to_smmu_domain(domain)->smmu;
@@ -1226,7 +1228,7 @@ static size_t arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
12261228
return 0;
12271229

12281230
arm_smmu_rpm_get(smmu);
1229-
ret = ops->unmap(ops, iova, size, gather);
1231+
ret = ops->unmap_pages(ops, iova, pgsize, pgcount, iotlb_gather);
12301232
arm_smmu_rpm_put(smmu);
12311233

12321234
return ret;
@@ -1320,9 +1322,6 @@ static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
13201322
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
13211323
struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
13221324

1323-
if (domain->type == IOMMU_DOMAIN_IDENTITY)
1324-
return iova;
1325-
13261325
if (!ops)
13271326
return 0;
13281327

@@ -1582,8 +1581,8 @@ static struct iommu_ops arm_smmu_ops = {
15821581
.domain_alloc = arm_smmu_domain_alloc,
15831582
.domain_free = arm_smmu_domain_free,
15841583
.attach_dev = arm_smmu_attach_dev,
1585-
.map = arm_smmu_map,
1586-
.unmap = arm_smmu_unmap,
1584+
.map_pages = arm_smmu_map_pages,
1585+
.unmap_pages = arm_smmu_unmap_pages,
15871586
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
15881587
.iotlb_sync = arm_smmu_iotlb_sync,
15891588
.iova_to_phys = arm_smmu_iova_to_phys,

0 commit comments

Comments
 (0)