Skip to content

Commit 712d8f2

Browse files
Zhen Leijoergroedel
authored andcommitted
iommu: Enhance IOMMU default DMA mode build options
First, add build options IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the opportunity to set {lazy|strict} mode as default at build time. Then put the two config options in an choice, as they are mutually exclusive. [jpg: Make choice between strict and lazy only (and not passthrough)] Signed-off-by: Zhen Lei <[email protected]> Signed-off-by: John Garry <[email protected]> Reviewed-by: Robin Murphy <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent d8577d2 commit 712d8f2

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2042,9 +2042,10 @@
20422042
throughput at the cost of reduced device isolation.
20432043
Will fall back to strict mode if not supported by
20442044
the relevant IOMMU driver.
2045-
1 - Strict mode (default).
2045+
1 - Strict mode.
20462046
DMA unmap operations invalidate IOMMU hardware TLBs
20472047
synchronously.
2048+
unset - Use value of CONFIG_IOMMU_DEFAULT_{LAZY,STRICT}.
20482049
Note: on x86, the default behaviour depends on the
20492050
equivalent driver-specific parameters, but a strict
20502051
mode explicitly specified by either method takes

drivers/iommu/Kconfig

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,46 @@ 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_STRICT
98+
help
99+
This option allows an IOMMU DMA IOTLB invalidation mode to be
100+
chosen at build time, to override the default mode of each ARCH,
101+
removing the need to pass in kernel parameters through command line.
102+
It is still possible to provide common boot params to override this
103+
config.
104+
105+
If unsure, keep the default.
106+
107+
config IOMMU_DEFAULT_STRICT
108+
bool "strict"
109+
help
110+
For every IOMMU DMA unmap operation, the flush operation of IOTLB and
111+
the free operation of IOVA are guaranteed to be done in the unmap
112+
function.
113+
114+
config IOMMU_DEFAULT_LAZY
115+
bool "lazy"
116+
help
117+
Support lazy mode, where for every IOMMU DMA unmap operation, the
118+
flush operation of IOTLB and the free operation of IOVA are deferred.
119+
They are only guaranteed to be done before the related IOVA will be
120+
reused.
121+
122+
The isolation provided in this mode is not as secure as STRICT mode,
123+
such that a vulnerable time window may be created between the DMA
124+
unmap and the mappings cached in the IOMMU IOTLB or device TLB
125+
finally being invalidated, where the device could still access the
126+
memory which has already been unmapped by the device driver.
127+
However this mode may provide better performance in high throughput
128+
scenarios, and is still considerably more secure than passthrough
129+
mode or no IOMMU.
130+
131+
endchoice
132+
93133
config OF_IOMMU
94134
def_bool y
95135
depends on OF && IOMMU_API

drivers/iommu/iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static struct kset *iommu_group_kset;
3030
static DEFINE_IDA(iommu_group_ida);
3131

3232
static unsigned int iommu_def_domain_type __read_mostly;
33-
static bool iommu_dma_strict __read_mostly = true;
33+
static bool iommu_dma_strict __read_mostly = IS_ENABLED(CONFIG_IOMMU_DEFAULT_STRICT);
3434
static u32 iommu_cmd_line __read_mostly;
3535

3636
struct iommu_group {

0 commit comments

Comments
 (0)