Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 3e11909

Browse files
committed
Merge remote-tracking branch 'intel-iommu/iommu/fixes' into gvt-staging
2 parents 3ad0415 + 8cc6331 commit 3e11909

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2074
-630
lines changed

Documentation/ABI/testing/sysfs-kernel-iommu_groups

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ Description: /sys/kernel/iommu_groups/<grp_id>/type shows the type of default
4242
======== ======================================================
4343
DMA All the DMA transactions from the device in this group
4444
are translated by the iommu.
45+
DMA-FQ As above, but using batched invalidation to lazily
46+
remove translations after use. This may offer reduced
47+
overhead at the cost of reduced memory protection.
4548
identity All the DMA transactions from the device in this group
46-
are not translated by the iommu.
49+
are not translated by the iommu. Maximum performance
50+
but zero protection.
4751
auto Change to the type the device was booted with.
4852
======== ======================================================
4953

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 12 additions & 17 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,18 +1941,17 @@
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
19531948
not be supported.
1954-
sm_on [Default Off]
1955-
By default, scalable mode will be disabled even if the
1956-
hardware advertises that it has support for the scalable
1957-
mode translation. With this option set, scalable mode
1958-
will be used on hardware which claims to support it.
1949+
sm_on
1950+
Enable the Intel IOMMU scalable mode if the hardware
1951+
advertises that it has support for the scalable mode
1952+
translation.
1953+
sm_off
1954+
Disallow use of the Intel IOMMU scalable mode.
19591955
tboot_noforce [Default Off]
19601956
Do not force the Intel IOMMU enabled under tboot.
19611957
By default, tboot will force Intel IOMMU on, which
@@ -2047,13 +2043,12 @@
20472043
throughput at the cost of reduced device isolation.
20482044
Will fall back to strict mode if not supported by
20492045
the relevant IOMMU driver.
2050-
1 - Strict mode (default).
2046+
1 - Strict mode.
20512047
DMA unmap operations invalidate IOMMU hardware TLBs
20522048
synchronously.
2053-
Note: on x86, the default behaviour depends on the
2054-
equivalent driver-specific parameters, but a strict
2055-
mode explicitly specified by either method takes
2056-
precedence.
2049+
unset - Use value of CONFIG_IOMMU_DEFAULT_DMA_{LAZY,STRICT}.
2050+
Note: on x86, strict mode specified via one of the
2051+
legacy driver-specific options takes precedence.
20572052

20582053
iommu.passthrough=
20592054
[ARM64, X86] Configure DMA to bypass the IOMMU by default.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/iommu/apple,dart.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Apple DART IOMMU
8+
9+
maintainers:
10+
- Sven Peter <[email protected]>
11+
12+
description: |+
13+
Apple SoCs may contain an implementation of their Device Address
14+
Resolution Table which provides a mandatory layer of address
15+
translations for various masters.
16+
17+
Each DART instance is capable of handling up to 16 different streams
18+
with individual pagetables and page-level read/write protection flags.
19+
20+
This DART IOMMU also raises interrupts in response to various
21+
fault conditions.
22+
23+
properties:
24+
compatible:
25+
const: apple,t8103-dart
26+
27+
reg:
28+
maxItems: 1
29+
30+
interrupts:
31+
maxItems: 1
32+
33+
clocks:
34+
description:
35+
Reference to the gate clock phandle if required for this IOMMU.
36+
Optional since not all IOMMUs are attached to a clock gate.
37+
38+
'#iommu-cells':
39+
const: 1
40+
description:
41+
Has to be one. The single cell describes the stream id emitted by
42+
a master to the IOMMU.
43+
44+
required:
45+
- compatible
46+
- reg
47+
- '#iommu-cells'
48+
- interrupts
49+
50+
additionalProperties: false
51+
52+
examples:
53+
- |+
54+
dart1: iommu@82f80000 {
55+
compatible = "apple,t8103-dart";
56+
reg = <0x82f80000 0x4000>;
57+
interrupts = <1 781 4>;
58+
#iommu-cells = <1>;
59+
};
60+
61+
master1 {
62+
iommus = <&dart1 0>;
63+
};
64+
65+
- |+
66+
dart2a: iommu@82f00000 {
67+
compatible = "apple,t8103-dart";
68+
reg = <0x82f00000 0x4000>;
69+
interrupts = <1 781 4>;
70+
#iommu-cells = <1>;
71+
};
72+
dart2b: iommu@82f80000 {
73+
compatible = "apple,t8103-dart";
74+
reg = <0x82f80000 0x4000>;
75+
interrupts = <1 781 4>;
76+
#iommu-cells = <1>;
77+
};
78+
79+
master2 {
80+
iommus = <&dart2a 0>, <&dart2b 1>;
81+
};

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,13 @@ L: [email protected]
12621262
S: Odd fixes
12631263
F: drivers/input/mouse/bcm5974.c
12641264

1265+
APPLE DART IOMMU DRIVER
1266+
M: Sven Peter <[email protected]>
1267+
1268+
S: Maintained
1269+
F: Documentation/devicetree/bindings/iommu/apple,dart.yaml
1270+
F: drivers/iommu/apple-dart.c
1271+
12651272
APPLE SMC DRIVER
12661273
M: Henrik Rydberg <[email protected]>
12671274

drivers/iommu/Kconfig

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,57 @@ config IOMMU_DEBUGFS
7979
debug/iommu directory, and then populate a subdirectory with
8080
entries as required.
8181

82-
config IOMMU_DEFAULT_PASSTHROUGH
83-
bool "IOMMU passthrough by default"
82+
choice
83+
prompt "IOMMU default domain type"
8484
depends on IOMMU_API
85+
default IOMMU_DEFAULT_DMA_LAZY if X86 || IA64
86+
default IOMMU_DEFAULT_DMA_STRICT
8587
help
86-
Enable passthrough by default, removing the need to pass in
87-
iommu.passthrough=on or iommu=pt through command line. If this
88-
is enabled, you can still disable with iommu.passthrough=off
89-
or iommu=nopt depending on the architecture.
88+
Choose the type of IOMMU domain used to manage DMA API usage by
89+
device drivers. The options here typically represent different
90+
levels of tradeoff between robustness/security and performance,
91+
depending on the IOMMU driver. Not all IOMMUs support all options.
92+
This choice can be overridden at boot via the command line, and for
93+
some devices also at runtime via sysfs.
9094

91-
If unsure, say N here.
95+
If unsure, keep the default.
96+
97+
config IOMMU_DEFAULT_DMA_STRICT
98+
bool "Translated - Strict"
99+
help
100+
Trusted devices use translation to restrict their access to only
101+
DMA-mapped pages, with strict TLB invalidation on unmap. Equivalent
102+
to passing "iommu.passthrough=0 iommu.strict=1" on the command line.
103+
104+
Untrusted devices always use this mode, with an additional layer of
105+
bounce-buffering such that they cannot gain access to any unrelated
106+
data within a mapped page.
107+
108+
config IOMMU_DEFAULT_DMA_LAZY
109+
bool "Translated - Lazy"
110+
help
111+
Trusted devices use translation to restrict their access to only
112+
DMA-mapped pages, but with "lazy" batched TLB invalidation. This
113+
mode allows higher performance with some IOMMUs due to reduced TLB
114+
flushing, but at the cost of reduced isolation since devices may be
115+
able to access memory for some time after it has been unmapped.
116+
Equivalent to passing "iommu.passthrough=0 iommu.strict=0" on the
117+
command line.
118+
119+
If this mode is not supported by the IOMMU driver, the effective
120+
runtime default will fall back to IOMMU_DEFAULT_DMA_STRICT.
121+
122+
config IOMMU_DEFAULT_PASSTHROUGH
123+
bool "Passthrough"
124+
help
125+
Trusted devices are identity-mapped, giving them unrestricted access
126+
to memory with minimal performance overhead. Equivalent to passing
127+
"iommu.passthrough=1" (historically "iommu=pt") on the command line.
128+
129+
If this mode is not supported by the IOMMU driver, the effective
130+
runtime default will fall back to IOMMU_DEFAULT_DMA_STRICT.
131+
132+
endchoice
92133

93134
config OF_IOMMU
94135
def_bool y
@@ -249,6 +290,20 @@ config SPAPR_TCE_IOMMU
249290
Enables bits of IOMMU API required by VFIO. The iommu_ops
250291
is not implemented as it is not necessary for VFIO.
251292

293+
config APPLE_DART
294+
tristate "Apple DART IOMMU Support"
295+
depends on ARCH_APPLE || (COMPILE_TEST && !GENERIC_ATOMIC64)
296+
select IOMMU_API
297+
select IOMMU_IO_PGTABLE_LPAE
298+
default ARCH_APPLE
299+
help
300+
Support for Apple DART (Device Address Resolution Table) IOMMUs
301+
found in Apple ARM SoCs like the M1.
302+
This IOMMU is required for most peripherals using DMA to access
303+
the main memory.
304+
305+
Say Y here if you are using an Apple SoC.
306+
252307
# ARM IOMMU support
253308
config ARM_SMMU
254309
tristate "ARM Ltd. System MMU (SMMU) Support"

drivers/iommu/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ obj-$(CONFIG_HYPERV_IOMMU) += hyperv-iommu.o
2929
obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o
3030
obj-$(CONFIG_IOMMU_SVA_LIB) += iommu-sva-lib.o io-pgfault.o
3131
obj-$(CONFIG_SPRD_IOMMU) += sprd-iommu.o
32+
obj-$(CONFIG_APPLE_DART) += apple-dart.o

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: 36 additions & 24 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 */
@@ -298,6 +297,22 @@ int amd_iommu_get_num_iommus(void)
298297
return amd_iommus_present;
299298
}
300299

300+
#ifdef CONFIG_IRQ_REMAP
301+
static bool check_feature_on_all_iommus(u64 mask)
302+
{
303+
bool ret = false;
304+
struct amd_iommu *iommu;
305+
306+
for_each_iommu(iommu) {
307+
ret = iommu_feature(iommu, mask);
308+
if (!ret)
309+
return false;
310+
}
311+
312+
return true;
313+
}
314+
#endif
315+
301316
/*
302317
* For IVHD type 0x11/0x40, EFR is also available via IVHD.
303318
* Default to IVHD EFR since it is available sooner
@@ -814,9 +829,9 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
814829
return 0;
815830
}
816831

817-
#ifdef CONFIG_IRQ_REMAP
818832
static int iommu_init_ga_log(struct amd_iommu *iommu)
819833
{
834+
#ifdef CONFIG_IRQ_REMAP
820835
u64 entry;
821836

822837
if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
@@ -846,25 +861,9 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)
846861
err_out:
847862
free_ga_log(iommu);
848863
return -EINVAL;
849-
}
850-
#endif /* CONFIG_IRQ_REMAP */
851-
852-
static int iommu_init_ga(struct amd_iommu *iommu)
853-
{
854-
int ret = 0;
855-
856-
#ifdef CONFIG_IRQ_REMAP
857-
/* Note: We have already checked GASup from IVRS table.
858-
* Now, we need to make sure that GAMSup is set.
859-
*/
860-
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) &&
861-
!iommu_feature(iommu, FEATURE_GAM_VAPIC))
862-
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
863-
864-
ret = iommu_init_ga_log(iommu);
864+
#else
865+
return 0;
865866
#endif /* CONFIG_IRQ_REMAP */
866-
867-
return ret;
868867
}
869868

870869
static int __init alloc_cwwb_sem(struct amd_iommu *iommu)
@@ -1846,12 +1845,15 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
18461845
if (iommu_feature(iommu, FEATURE_PPR) && alloc_ppr_log(iommu))
18471846
return -ENOMEM;
18481847

1849-
ret = iommu_init_ga(iommu);
1848+
ret = iommu_init_ga_log(iommu);
18501849
if (ret)
18511850
return ret;
18521851

1853-
if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE))
1852+
if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) {
1853+
pr_info("Using strict mode due to virtualization\n");
1854+
iommu_set_dma_strict();
18541855
amd_iommu_np_cache = true;
1856+
}
18551857

18561858
init_iommu_perf_ctr(iommu);
18571859

@@ -2477,6 +2479,14 @@ static void early_enable_iommus(void)
24772479
}
24782480

24792481
#ifdef CONFIG_IRQ_REMAP
2482+
/*
2483+
* Note: We have already checked GASup from IVRS table.
2484+
* Now, we need to make sure that GAMSup is set.
2485+
*/
2486+
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) &&
2487+
!check_feature_on_all_iommus(FEATURE_GAM_VAPIC))
2488+
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
2489+
24802490
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
24812491
amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP);
24822492
#endif
@@ -3098,8 +3108,10 @@ static int __init parse_amd_iommu_intr(char *str)
30983108
static int __init parse_amd_iommu_options(char *str)
30993109
{
31003110
for (; *str; ++str) {
3101-
if (strncmp(str, "fullflush", 9) == 0)
3102-
amd_iommu_unmap_flush = true;
3111+
if (strncmp(str, "fullflush", 9) == 0) {
3112+
pr_warn("amd_iommu=fullflush deprecated; use iommu.strict=1 instead\n");
3113+
iommu_set_dma_strict();
3114+
}
31033115
if (strncmp(str, "force_enable", 12) == 0)
31043116
amd_iommu_force_enable = true;
31053117
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))

0 commit comments

Comments
 (0)