iommu/vt-d: Support a new DMAR flag
Subsystems (3)
v2 cover iommu/vt-d: Support a new DMAR flag
VT-d spec v5.2 introduces a new DMA_REMAP_OPT_OUT flag in the DMAR table, adding another knob to affect whether the DMA remapping capability should be turned on or off.
While at it, first clean up the existing on/off policy messed with user opts and various force_on conditions in the first 8 patches.
On top of the improved framework, the last patch introduces the support of the new bit.
Some cleanups will be done after this series:
- Cache dmar->flags instead of reading ACPI table multiple times
- Check intel_iommu_enabled at runtime instead of using dmar_policy
- Clean up existing warning messages (e.g. force_on panic message always has the "tboot:" prefix)
v2:
- Rebase to 7.2-rc1
- Policy-oriented renaming to avoid confusion with runtime state (Baolu)
- Warning message/comment improvements (Baolu)
- Always return error for unsupported force_on type
- No need to do platform optin if tboot already forces on (old behavior)
v1:
https://lore.kernel.org/linux-iommu/[email protected]/
Kevin Tian (9):
iommu/vt-d: Fix no_iommu to disable platform optin iommu/vt-d: Force requesting ACS when tboot is enabled iommu/vt-d: Remove dead code when CONFIG_INTEL_IOMMU is not set iommu/vt-d: Consolidate dmar policy management and force_on logic iommu/vt-d: Use dmar_can_force_on() for platform optin iommu/vt-d: Call dmar_can_force_on() for tboot optin iommu/vt-d: Remove the 'force_on' variable
iommu/vt-d: Remove dmar_disabled
iommu/vt-d: Support the new DMA_REMAP_OPT_OUT flag bit
drivers/iommu/intel/dmar.c | 95 +++++++++++++++++++++++++++++++++---- drivers/iommu/intel/iommu.c | 78 +++++++++++++++--------------- drivers/iommu/intel/iommu.h | 64 ++++++++++++++++++++----- drivers/iommu/intel/svm.c | 2 +- include/linux/dmar.h | 1 + 5 files changed, 180 insertions(+), 60 deletions(-)
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
Signature · 1 line
2.43.0
PATCH v2 1/9 iommu/vt-d: Fix no_iommu to disable platform optin
If user explicitly requests to disable iommu (via "iommu=off" or "intel_iommu=off"), there is no reason to force enabling it due to platform optin (for external-facing devices). User should be aware of any security implication of doing so.
"intel_iommu=off" implements this policy by setting no_platform_optin to skip platform optin in platform_optin_force_iommu().
However, "iommu=off" (no_iommu=1) doesn't set no_platform_optin hence is broken in this aspect:
- detect_intel_iommu() doesn't request ACS if no_iommu=1
- platform_optin_force_iommu() forces iommu on if external-facing devices exist and no_platform_optin is not set
This leads to a bad configuration with ACS disabled while DMA remapping is enabled.
Instead of setting no_platform_optin (will soon be removed) for no_iommu=1, directly check no_iommu in platform_optin_force_iommu().
--- drivers/iommu/intel/iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/intel/iommu.c +3 -3
@@ -2482,10 +2482,11 @@ static bool has_external_pci(void)static int __init platform_optin_force_iommu (void ) { -if (!dmar_platform_optin () || no_platform_optin || !has_external_pci ()) +if (no_iommu || !dmar_platform_optin () || no_platform_optin || + !has_external_pci ())return 0 ; -if (no_iommu || dmar_disabled) +if (dmar_disabled)pr_info ("Intel-IOMMU force enabled due to platform opt in\n" );/*
@@ -2496,7 +2497,6 @@ static int __init platform_optin_force_iommu(void)iommu_set_default_passthrough (false); dmar_disabled =0 ; - no_iommu =0 ;return 1 ; }
Signature · 1 line
2.43.0
PATCH v2 2/9 iommu/vt-d: Force requesting ACS when tboot is enabled
In reply to Kevin TianCurrently the conditions of requesting ACS in detect_intel_iommu() don't include tboot, leading to a possible misconfiguration with ACS disabled (e.g. due to user opts) while iommu is later forced on by tboot_force_iommu().
Fix it by checking tboot in detect_intel_iommu().
--- drivers/iommu/intel/dmar.c | 15 +++++++++++++-- drivers/iommu/intel/iommu.c | 2 +- drivers/iommu/intel/iommu.h | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-)
drivers/iommu/intel/dmar.c +13 -2
@@ -915,6 +915,18 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)return 0 ; } +static bool dmar_required (void ) +{ +/* tboot supersedes any user/platform opt */ +if (!intel_iommu_tboot_noforce &&tboot_enabled ()) +return true; + +if (!no_iommu && (!dmar_disabled ||dmar_platform_optin ())) +return true; + +return false; +} +void __init detect_intel_iommu (void ) {int ret;
@@ -928,8 +940,7 @@ void __init detect_intel_iommu(void)if (!ret) ret =dmar_walk_dmar_table ((struct acpi_table_dmar *)dmar_tbl, &validate_drhd_cb); -if (!ret && !no_iommu && !iommu_detected && - (!dmar_disabled ||dmar_platform_optin ())) { +if (!ret && !iommu_detected &&dmar_required ()) { iommu_detected =1 ;/* Make sure ACS will be enabled */ pci_request_acs ();
drivers/iommu/intel/iommu.c +1 -1
@@ -57,7 +57,7 @@ static int rwbf_quirk;* (used when kernel is launched w/ TXT) */ static int force_on =0 ; -static int intel_iommu_tboot_noforce; +int intel_iommu_tboot_noforce;static int no_platform_optin;#define ROOT_ENTRY_NR (VTD_PAGE_SIZE/sizeof(struct root_entry))
drivers/iommu/intel/iommu.h +2 -0
@@ -1354,6 +1354,7 @@ static inline bool ecmd_has_pmu_essential(struct intel_iommu *iommu)extern int dmar_disabled;extern int intel_iommu_enabled; +extern int intel_iommu_tboot_noforce;#else static inline int iommu_calculate_agaw (struct intel_iommu *iommu) {
@@ -1366,6 +1367,7 @@ static inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu)#define dmar_disabled (1)#define intel_iommu_enabled (0)#define intel_iommu_sm (0) +#define intel_iommu_tboot_noforce (0)#endif static inline const char *decode_prq_descriptor(char *str, size_t size,
Signature · 1 line
2.43.0
RE: [PATCH v2 2/9] iommu/vt-d: Force requesting ACS when tboot is enabled
Quoted 5 lines
From: Tian, Kevin <[email protected]>
Sent: Thursday, July 2, 2026 2:12 PMdrivers/iommu/intel/dmar.c +2
-0+static bool dmar_required (void ) +{
drivers/iommu/intel/dmar.c dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg) · line 929
Quoted 10 lines
drivers/iommu/intel/dmar.c +10
-0+/* tboot supersedes any user/platform opt */ +if (!intel_iommu_tboot_noforce &&tboot_enabled ()) +return true; + +if (!no_iommu && (!dmar_disabled ||dmar_platform_optin ())) +return true; + +return false; +} +
Sashiko [1] questions that parse_args() is called after detect_intel_iommu() so above check of intel_iommu_tboot_noforce is always false.
But actually parse_args() is called in start_kernel() way earlier:
parse_early_param();
parse_args("Booting kernel", ...); // where __setup() is parsed
...
mm_core_init();
-> detect_intel_iommu() -> dmar_required()so this comment is invalid.
[1] https://sashiko.dev/#/patchset/20260702061216.388743-1-kevin.tian%40intel.com
PATCH v2 3/9 iommu/vt-d: Remove dead code when CONFIG_INTEL_IOMMU is not set
In reply to Kevin TianThose are leftovers and unreachable now: the entire intel directory is built only when CONFIG_INTEL_IOMMU is set.
--- drivers/iommu/intel/iommu.h | 15 --------------- 1 file changed, 15 deletions(-)
drivers/iommu/intel/iommu.h +0 -15
@@ -1340,7 +1340,6 @@ static inline bool intel_domain_is_ss_paging(struct dmar_domain *domain)return domain->domain.ops == &intel_ss_paging_domain_ops; } -#ifdef CONFIG_INTEL_IOMMU extern int intel_iommu_sm;int iommu_calculate_agaw (struct intel_iommu *iommu);int iommu_calculate_max_sagaw (struct intel_iommu *iommu);
@@ -1355,20 +1354,6 @@ static inline bool ecmd_has_pmu_essential(struct intel_iommu *iommu)extern int dmar_disabled;extern int intel_iommu_enabled;extern int intel_iommu_tboot_noforce; -#else -static inline int iommu_calculate_agaw (struct intel_iommu *iommu) -{ -return 0 ; -} -static inline int iommu_calculate_max_sagaw (struct intel_iommu *iommu) -{ -return 0 ; -} -#define dmar_disabled (1) -#define intel_iommu_enabled (0) -#define intel_iommu_sm (0) -#define intel_iommu_tboot_noforce (0) -#endif static inline const char *decode_prq_descriptor (char *str,size_t size,u64 dw0,u64 dw1,u64 dw2,u64 dw3)
Signature · 1 line
2.43.0
PATCH v2 4/9 iommu/vt-d: Consolidate dmar policy management and force_on logic
In reply to Kevin TianCurrently the dmar on/off is carried by multiple variables (no_iommu, dmar_disabled, no_platform_optin, etc.) with error-prone force_on logic scattered in multiple places.
Unify/centralize the policy/priority management for various force_on scenarios.
No functional impact except one case - "intel_iommu=off" sets no_platform_optin which is checked in platform_optin_force_iommu() but not in detect_intel_iommu(), leading to ACS unnecessarily requested when iommu could not be forced on later. Now with the unified logic this becomes more consistent.
--- drivers/iommu/intel/dmar.c | 58 ++++++++++++++++++++++++++++++++++--- drivers/iommu/intel/iommu.c | 7 +++++ drivers/iommu/intel/iommu.h | 45 ++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 4 deletions(-)
drivers/iommu/intel/dmar.c +54 -4
@@ -915,14 +915,61 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)return 0 ; } +/* +* Centralized helper for deciding the force_on policy +* +* dmar off policies (for DMA Remapping) are defined from stronger +* (more negative values) to weaker (less negative values). +* +* When a force_on type is passed in, it is associated to a reference +* level for comparison. force_on is permitted when dmar is in a +* off policy less negative than the reference level (if the policy is +* on then the check is always true). +* +* For supported force_on types: +* +* - DMAR_FORCEON_TBOOT: tboot strictly requires DMA remapping for secure +* boot hence supersedes any user opts ("iommu=off" or "intel_iommu=off") +* and weaker off policies. +* +* - DMAR_FORCEON_PLATFORM: external-facing devices requires DMA +* remapping to prevent malicious downstream external devices from +* composing DMA attacks. force_on is permitted only if dmar policy is +* off by build configurations (CONFIG_INTEL_IOMMU_DEFAULT_ON=off). +* +* In a nutshell, "trusted boot environment" is considered stronger than +* "user choices", which in turn is stronger than "platform opt-in hint". +*/ +bool dmar_can_force_on (enum dmar_force_on force_on) +{ +int level; + +switch (force_on) { +case DMAR_FORCEON_TBOOT : + level =DMAR_USER_OFF ; +break ; +case DMAR_FORCEON_PLATFORM : + level =DMAR_DEFAULT_OFF ; +break ; +default : + level =INT_MAX ; +pr_warn ("Unsupported force_on type (%d)\n" , force_on); +break ; + } + +return dmar_policy >= level; +} +static bool dmar_required (void ) { -/* tboot supersedes any user/platform opt */ -if (!intel_iommu_tboot_noforce &&tboot_enabled ()) +if (dmar_policy_on ())return true; -if (!no_iommu && (!dmar_disabled ||dmar_platform_optin ())) -return true; +if (!intel_iommu_tboot_noforce &&tboot_enabled ()) +return dmar_can_force_on (DMAR_FORCEON_TBOOT ); + +if (dmar_platform_optin ()) +return dmar_can_force_on (DMAR_FORCEON_PLATFORM );return false; }
@@ -936,6 +983,9 @@ void __init detect_intel_iommu(void) };down_write (&dmar_global_lock); +if (no_iommu) + dmar_policy =DMAR_USER_OFF ; + ret =dmar_table_detect ();if (!ret) ret = dmar_walk_dmar_table((struct acpi_table_dmar *)dmar_tbl,
drivers/iommu/intel/iommu.c +7 -0
@@ -199,6 +199,11 @@ static LIST_HEAD(dmar_satc_units);static void intel_iommu_domain_free (struct iommu_domain *domain); +#ifdef CONFIG_INTEL_IOMMU_DEFAULT_ON +int dmar_policy =DMAR_ON ; +#else +int dmar_policy =DMAR_DEFAULT_OFF ; +#endif int dmar_disabled = !IS_ENABLED (CONFIG_INTEL_IOMMU_DEFAULT_ON );int intel_iommu_sm =IS_ENABLED (CONFIG_INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON );
@@ -240,9 +245,11 @@ static int __init intel_iommu_setup(char *str)while (*str) {if (!strncmp (str,"on" ,2 )) { + dmar_policy =DMAR_ON ; dmar_disabled =0 ;pr_info ("IOMMU enabled\n" ); }else if (!strncmp (str,"off" ,3 )) { + dmar_policy =DMAR_USER_OFF ; dmar_disabled =1 ; no_platform_optin =1 ;pr_info ("IOMMU disabled\n" );
drivers/iommu/intel/iommu.h +45 -0
51 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 5/9 iommu/vt-d: Use dmar_can_force_on() for platform optin
In reply to Kevin TianSo the policy of requesting ACS in detect_intel_iommu() is consistent with that in platform_optin_force_iommu().
While at it, remove no_platform_optin which is unnecessary now.
--- drivers/iommu/intel/iommu.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/iommu/intel/iommu.c +8 -7
@@ -58,7 +58,6 @@ static int rwbf_quirk;*/ static int force_on =0 ;int intel_iommu_tboot_noforce; -static int no_platform_optin;#define ROOT_ENTRY_NR (VTD_PAGE_SIZE/sizeof(struct root_entry))
@@ -251,7 +250,6 @@ static int __init intel_iommu_setup(char *str) }else if (!strncmp (str,"off" ,3 )) { dmar_policy =DMAR_USER_OFF ; dmar_disabled =1 ; - no_platform_optin =1 ;pr_info ("IOMMU disabled\n" ); }else if (!strncmp (str,"igfx_off" ,8 )) { disable_igfx_iommu =1 ;
@@ -2489,20 +2487,23 @@ static bool has_external_pci(void)static int __init platform_optin_force_iommu (void ) { -if (no_iommu || !dmar_platform_optin () || no_platform_optin || - !has_external_pci ()) +if (!dmar_platform_optin () || !dmar_can_force_on (DMAR_FORCEON_PLATFORM ))return 0 ; -if (dmar_disabled) -pr_info ("Intel-IOMMU force enabled due to platform opt in\n" ); +if (!has_external_pci ()) +return 0 ;/* * If Intel-IOMMU is disabled by default, we will apply identity * map for all devices except those marked as being untrusted. */ -if (dmar_disabled) +if (dmar_policy_off ()) { +pr_info ("Intel-IOMMU force enabled due to platform opt in\n" );iommu_set_default_passthrough (false); + } +/* No concurrent access to dmar_policy at this point. */ + dmar_policy =DMAR_FORCE_ON ; dmar_disabled =0 ;return 1 ;
Signature · 1 line
2.43.0
PATCH v2 6/9 iommu/vt-d: Call dmar_can_force_on() for tboot optin
In reply to Kevin TianSo the policy of requesting ACS in detect_intel_iommu() is consistent with that in tboot_force_iommu().
Though tboot is the strongest override so far, dmar_can_force_on() may return false due to future extensions. In this case panic the kernel, as is already done when failing to initialize DMA remapping for tboot.
No functional impact at this point.
--- drivers/iommu/intel/iommu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/iommu/intel/iommu.c +8 -4
@@ -2548,12 +2548,17 @@ static int __init probe_acpi_namespace_devices(void)static __init int tboot_force_iommu (void ) { -if (!tboot_enabled ()) +if (!tboot_enabled () || intel_iommu_tboot_noforce)return 0 ; -if (no_iommu || dmar_disabled) +if (!dmar_can_force_on (DMAR_FORCEON_TBOOT )) +panic ("tboot: Failed to force IOMMU on\n" ); + +if (dmar_policy_off ())pr_warn ("Forcing Intel-IOMMU to enabled\n" ); +/* No concurrent access to dmar_policy at this point. */ + dmar_policy =DMAR_FORCE_ON ; dmar_disabled =0 ; no_iommu =0 ;
@@ -2570,8 +2575,7 @@ int __init intel_iommu_init(void)* Intel IOMMU is required for a TXT/tboot launch or platform * opt in, so enforce that. */ - force_on = (!intel_iommu_tboot_noforce &&tboot_force_iommu ()) || -platform_optin_force_iommu (); + force_on =tboot_force_iommu () ||platform_optin_force_iommu ();down_write (&dmar_global_lock);if (dmar_table_init ()) {
Signature · 1 line
2.43.0
PATCH v2 7/9 iommu/vt-d: Remove the 'force_on' variable
In reply to Kevin TianThe force_on variable is now redundant - same information captured by "dmar_policy == DMAR_FORCE_ON". Replace all force_on checks with dmar_policy_force_on().
--- drivers/iommu/intel/iommu.c | 37 +++++++++++++++++-------------------- drivers/iommu/intel/iommu.h | 5 +++++ 2 files changed, 22 insertions(+), 20 deletions(-)
drivers/iommu/intel/iommu.c +17 -20
@@ -53,10 +53,9 @@ static int rwbf_quirk;#define rwbf_required (iommu) (rwbf_quirk || cap_rwbf((iommu)->cap))/* -* set to 1 to panic kernel if can't successfully enable VT-d -* (used when kernel is launched w/ TXT) +* Skip forcing iommu on and avoid tboot-related kernel panics during +* initialization when set to 1 (via intel_iommu=tboot_noforce). */ -static int force_on =0 ;int intel_iommu_tboot_noforce;#define ROOT_ENTRY_NR (VTD_PAGE_SIZE/sizeof(struct root_entry))
@@ -1711,7 +1710,7 @@ static int __init init_dmars(void)* we always have to disable PMRs or DMA may fail on * this device */ -if (force_on) +if (dmar_policy_force_on ())iommu_disable_protect_mem_regions (iommu);continue ; }
@@ -1803,7 +1802,7 @@ static int init_iommu_hw(void)* we always have to disable PMRs or DMA may fail on * this device */ -if (force_on) +if (dmar_policy_force_on ())iommu_disable_protect_mem_regions (iommu);continue ; }
@@ -1864,7 +1863,7 @@ static void iommu_resume(void *data)unsigned long flag;if (init_iommu_hw ()) { -if (force_on) +if (dmar_policy_force_on ())panic ("tboot: IOMMU setup failed, DMAR can not resume!\n" );else WARN (1 ,"IOMMU setup failed, DMAR can not resume!\n" );
@@ -2132,7 +2131,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)/* * we always have to disable PMRs or DMA may fail on this device */ -if (force_on) +if (dmar_policy_force_on ())iommu_disable_protect_mem_regions (iommu);return 0 ; }
@@ -2485,13 +2484,13 @@ static bool has_external_pci(void)return false; } -static int __init platform_optin_force_iommu (void ) +static void __init platform_optin_force_iommu (void ) {if (!dmar_platform_optin () || !dmar_can_force_on (DMAR_FORCEON_PLATFORM )) -return 0 ; +return ;if (!has_external_pci ()) -return 0 ; +return ;/* * If Intel-IOMMU is disabled by default, we will apply identity
@@ -2505,8 +2504,6 @@ static int __init platform_optin_force_iommu(void)/* No concurrent access to dmar_policy at this point. */ dmar_policy =DMAR_FORCE_ON ; dmar_disabled =0 ; - -return 1 ; }static int __init probe_acpi_namespace_devices (void )
@@ -2546,10 +2543,10 @@ static int __init probe_acpi_namespace_devices(void)return 0 ; } -static __init int tboot_force_iommu (void ) +static __init void tboot_force_iommu (void ) {if (!tboot_enabled () || intel_iommu_tboot_noforce) -return 0 ; +return ;if (!dmar_can_force_on (DMAR_FORCEON_TBOOT ))panic ("tboot: Failed to force IOMMU on\n" );
@@ -2561,8 +2558,6 @@ static __init int tboot_force_iommu(void) dmar_policy =DMAR_FORCE_ON ; dmar_disabled =0 ; no_iommu =0 ; - -return 1 ; }int __init intel_iommu_init (void )
@@ -2575,17 +2570,19 @@ int __init intel_iommu_init(void)* Intel IOMMU is required for a TXT/tboot launch or platform * opt in, so enforce that. */ - force_on =tboot_force_iommu () ||platform_optin_force_iommu (); +tboot_force_iommu (); +if (!dmar_policy_force_on ()) +platform_optin_force_iommu ();down_write (&dmar_global_lock);if (dmar_table_init ()) { -if (force_on) +if (dmar_policy_force_on ())panic ("tboot: Failed to initialize DMAR table\n" ); goto out_free_dmar; }if (dmar_dev_scope_init () <0 ) { -if (force_on) +if (dmar_policy_force_on ())panic ("tboot: Failed to initialize DMAR device scope\n" ); goto out_free_dmar; }
@@ -2639,7 +2636,7 @@ int __init intel_iommu_init(void) ret =init_dmars ();if (ret) { -if (force_on) +if (dmar_policy_force_on ())panic ("tboot: Failed to initialize DMARs\n" );pr_err ("Initialization failed\n" ); goto out_free_dmar;
drivers/iommu/intel/iommu.h +5 -0
@@ -1394,6 +1394,11 @@ static inline bool dmar_policy_off(void)return dmar_policy <0 ; } +static inline bool dmar_policy_force_on (void ) +{ +return dmar_policy ==DMAR_FORCE_ON ; +} +bool dmar_can_force_on (enum dmar_force_on force_on);extern int dmar_disabled;
Signature · 1 line
2.43.0
PATCH v2 8/9 iommu/vt-d: Remove dmar_disabled
In reply to Kevin TianIt's replaced by dmar_policy_off() now, covering both "iommu=off" and "intel_iommu=off". Also remove unnecessary checks on no_iommu, leaving only one exception in intel_iommu_init() which skips debugfs init for "iommu=off" but not "intel_iommu=off". Keep it to avoid surprise for now.
--- drivers/iommu/intel/iommu.c | 9 ++------- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/svm.c | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/iommu/intel/iommu.c +2 -7
@@ -202,7 +202,6 @@ int dmar_policy = DMAR_ON;#else int dmar_policy =DMAR_DEFAULT_OFF ;#endif -int dmar_disabled = !IS_ENABLED (CONFIG_INTEL_IOMMU_DEFAULT_ON );int intel_iommu_sm =IS_ENABLED (CONFIG_INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON );int intel_iommu_enabled =0 ;
@@ -244,11 +243,9 @@ static int __init intel_iommu_setup(char *str)while (*str) {if (!strncmp (str,"on" ,2 )) { dmar_policy =DMAR_ON ; - dmar_disabled =0 ;pr_info ("IOMMU enabled\n" ); }else if (!strncmp (str,"off" ,3 )) { dmar_policy =DMAR_USER_OFF ; - dmar_disabled =1 ;pr_info ("IOMMU disabled\n" ); }else if (!strncmp (str,"igfx_off" ,8 )) { disable_igfx_iommu =1 ;
@@ -2369,7 +2366,7 @@ void intel_iommu_shutdown(void)struct dmar_drhd_unit *drhd;struct intel_iommu *iommu =NULL ; -if (no_iommu || dmar_disabled) +if (dmar_policy_off ())return ;/*
@@ -2503,7 +2500,6 @@ static void __init platform_optin_force_iommu(void)/* No concurrent access to dmar_policy at this point. */ dmar_policy =DMAR_FORCE_ON ; - dmar_disabled =0 ; }static int __init probe_acpi_namespace_devices (void )
@@ -2556,7 +2552,6 @@ static __init void tboot_force_iommu(void)/* No concurrent access to dmar_policy at this point. */ dmar_policy =DMAR_FORCE_ON ; - dmar_disabled =0 ; no_iommu =0 ; }
@@ -2600,7 +2595,7 @@ int __init intel_iommu_init(void)if (!no_iommu)intel_iommu_debugfs_init (); -if (no_iommu || dmar_disabled) { +if (dmar_policy_off ()) {/* * We exit the function here to ensure IOMMU's remapping and * mempool aren't setup, which means that the IOMMU's PMRs
drivers/iommu/intel/iommu.h +0 -1
@@ -1401,7 +1401,6 @@ static inline bool dmar_policy_force_on(void)bool dmar_can_force_on (enum dmar_force_on force_on); -extern int dmar_disabled;extern int intel_iommu_enabled;extern int intel_iommu_tboot_noforce;
drivers/iommu/intel/svm.c +1 -1
@@ -115,7 +115,7 @@ static int intel_iommu_sva_supported(struct device *dev)struct device_domain_info *info =dev_iommu_priv_get (dev);struct intel_iommu *iommu; -if (!info || dmar_disabled) +if (!info ||dmar_policy_off ())return -EINVAL ; iommu = info->iommu;
Signature · 1 line
2.43.0
PATCH v2 9/9 iommu/vt-d: Support the new DMA_REMAP_OPT_OUT flag bit
In reply to Kevin TianSome BIOS already provides config options to expose/hide VT-d units as a whole to/from system software. A new demand is to allow exposing VT-d units but requesting system software to disable DMA remapping while sustaining interrupt remapping. This can be communicated now by setting the new DMA_REMAP_OPT_OUT flag bit in the DMAR table, as introduced in VT-d spec v5.2 (section 8.1, DMA Remapping Reporting Structure).
Introduce a new off policy (DMAR_FW_OFF) for DMA_REMAP_OPT_OUT. As the strongest off policy, it cannot be overridden by user opts or any force_on types. If tboot is enabled in the meantime, kernel will panic. It is user responsibility to configure BIOS properly.
One cleanup is left for future - the DMAR flag is parsed multiple times, in detect_intel_iommu(), dmar_platform_optin() (which can be called at run-time), etc. Caching it is a cleaner way.
--- drivers/iommu/intel/dmar.c | 34 ++++++++++++++++++++++++---------- drivers/iommu/intel/iommu.h | 4 ++++ include/linux/dmar.h | 1 + 3 files changed, 29 insertions(+), 10 deletions(-)
drivers/iommu/intel/dmar.c +24 -10
@@ -930,7 +930,9 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)* * - DMAR_FORCEON_TBOOT: tboot strictly requires DMA remapping for secure * boot hence supersedes any user opts ("iommu=off" or "intel_iommu=off") -* and weaker off policies. +* and weaker off policies. But if firmware forces DMA remapping off (by +* setting DMAR_REMAP_OPT_OUT in the DMAR table), no force_on is allowed. +* Firmware settings must be changed to unblock tboot. * * - DMAR_FORCEON_PLATFORM: external-facing devices requires DMA * remapping to prevent malicious downstream external devices from
@@ -939,6 +941,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)* * In a nutshell, "trusted boot environment" is considered stronger than * "user choices", which in turn is stronger than "platform opt-in hint". +* But they are all meaningless when it's forced off by "firmware". */ bool dmar_can_force_on (enum dmar_force_on force_on) {
@@ -976,31 +979,42 @@ static bool dmar_required(void)void __init detect_intel_iommu (void ) { -int ret;struct dmar_res_callback validate_drhd_cb = { .cb[ACPI_DMAR_TYPE_HARDWARE_UNIT ] = &dmar_validate_one_drhd, .ignore_unhandled = true, }; +struct acpi_table_dmar *dmar; +int ret;down_write (&dmar_global_lock);if (no_iommu) dmar_policy =DMAR_USER_OFF ; ret =dmar_table_detect (); -if (!ret) - ret =dmar_walk_dmar_table ((struct acpi_table_dmar *)dmar_tbl, - &validate_drhd_cb); -if (!ret && !iommu_detected &&dmar_required ()) { +if (!ret) { + dmar = (struct acpi_table_dmar *)dmar_tbl; + ret =dmar_walk_dmar_table (dmar, &validate_drhd_cb); + } + +if (ret) + goto out; + +if (dmar->flags &DMAR_REMAP_OPT_OUT ) { + dmar_policy =DMAR_FW_OFF ; +pr_info ("Firmware forces DMA remapping off\n" ); +pr_info ("Any user opt or tboot/platform force_on will be ignored\n" ); + } + +if (!iommu_detected &&dmar_required ()) { iommu_detected =1 ;/* Make sure ACS will be enabled */ pci_request_acs (); } -if (!ret) { - x86_init.iommu.iommu_init = intel_iommu_init; - x86_platform.iommu_shutdown = intel_iommu_shutdown; - } + x86_init.iommu.iommu_init = intel_iommu_init; + x86_platform.iommu_shutdown = intel_iommu_shutdown; +out:if (dmar_tbl) {acpi_put_table (dmar_tbl); dmar_tbl =NULL ;
drivers/iommu/intel/iommu.h +4 -0
@@ -1375,6 +1375,9 @@ enum dmar_force_on {* - DMAR_USER_OFF * turn off by user opts ("intel_iommu=off" or "iommu=off"). * +* - DMAR_FW_OFF +* turn off due to firmware opt-out (DMAR_REMAP_OPT_OUT) +* * - '0' is invalid, compared to decide the on/off policy * */
@@ -1382,6 +1385,7 @@ enum dmar_force_on {#define DMAR_ON 1#define DMAR_DEFAULT_OFF -1#define DMAR_USER_OFF -2 +#define DMAR_FW_OFF -3extern int dmar_policy;static inline bool dmar_policy_on (void )
include/linux/dmar.h +1 -0
@@ -24,6 +24,7 @@ struct acpi_dmar_header;#define DMAR_INTR_REMAP 0x1#define DMAR_X2APIC_OPT_OUT 0x2#define DMAR_PLATFORM_OPT_IN 0x4 +#define DMAR_REMAP_OPT_OUT 0x8struct intel_iommu ;
Signature · 1 line
2.43.0
Baolu Lu
maintainerQuoted 37 lines · Kevin Tian
VT-d spec v5.2 introduces a new
DMA_REMAP_OPT_OUTflag in the DMAR table, adding another knob to affect whether the DMA remapping capability should be turned on or off.While at it, first clean up the existing on/off policy messed with user opts and various
force_onconditions in the first 8 patches.On top of the improved framework, the last patch introduces the support of the new bit.
Some cleanups will be done after this series:
- Cachedmar->flagsinstead of reading ACPI table multiple times
- Checkintel_iommu_enabledat runtime instead of usingdmar_policy
- Clean up existing warning messages (e.g.force_onpanic message always has the "tboot:" prefix)v2:
- Rebase to 7.2-rc1
- Policy-oriented renaming to avoid confusion with runtime state (Baolu)
- Warning message/comment improvements (Baolu)
- Always return error for unsupportedforce_ontype
- No need to do platform optin if tboot already forces on (old behavior)v1:
https://lore.kernel.org/linux-iommu/20260604051540.592925-1- [email protected]/Kevin Tian (9):
iommu/vt-d: Fixno_iommuto disable platform optin iommu/vt-d: Force requesting ACS when tboot is enabled iommu/vt-d: Remove dead code whenCONFIG_INTEL_IOMMUis not set iommu/vt-d: Consolidate dmar policy management andforce_onlogic iommu/vt-d: Usedmar_can_force_on()for platform optin iommu/vt-d: Calldmar_can_force_on()for tboot optin iommu/vt-d: Remove the 'force_on' variable
iommu/vt-d: Removedmar_disabled
iommu/vt-d: Support the newDMA_REMAP_OPT_OUTflag bit
Quoted 6 lines
drivers/iommu/intel/dmar.c | 95 +++++++++++++++++++++++++++++++++---- drivers/iommu/intel/iommu.c | 78 +++++++++++++++--------------- drivers/iommu/intel/iommu.h | 64 ++++++++++++++++++++----- drivers/iommu/intel/svm.c | 2 +- include/linux/dmar.h | 1 + 5 files changed, 180 insertions(+), 60 deletions(-)
Patch series queued for v7.3-rc1. Thanks a lot, Kevin.