Audit Capability and Extended Capability among IOMMUs
Subsystems (2)
v5 cover Audit Capability and Extended Capability among IOMMUs
Modern platforms have more than one IOMMU. Each IOMMU has its own feature set. Some of these features must be consistent among IOMMUs. Otherwise, these differences can lead to improper behavior in the system. On the other hand, for some features, each IOMMU can have different capacity values. So, different actions are required to deal with the inconsistencies depending on the IOMMU features.
Currently, some inconsistencies are ignored by the IOMMU driver. This patchset checks IOMMU capabilities and extended capabilities centralizedly during boot and take different actions according to the impacts caused by the mismatches.
For example:
1. Use common capacity values (normally the lowest capacity value) for all IOMMUs.
2. Report feature mismatches.
Detailed information on the IOMMU Capability / Extended Capability can be found in Intel VT-d Specification.
ChangeLog:
- Change from v4 to v5:
1. Drop the SVM coherency policy from this patchset.
- Change from v3 to v4:
1. fix the build error for when only enabled irq remapping.
- Change from v2 to v3:
1. fix the wrong macro names and rebase to v5.10.
- Change from v1 to v2:
1. Add missing cap/ecaps for audit.
2. Refactor function/macros overal suggested by Lu, Baolu.
2. Skip audit for gfx dedicated IOMMU.
3. Change commit message.
Kyung Min Park (2):
iommu/vt-d: Audit IOMMU Capabilities and add helper functions iommu/vt-d: Move capability check code to cap_audit files
drivers/iommu/intel/Makefile | 4 +- drivers/iommu/intel/cap_audit.c | 205 ++++++++++++++++++++++++++++ drivers/iommu/intel/cap_audit.h | 130 ++++++++++++++++++ drivers/iommu/intel/iommu.c | 85 ++---------- drivers/iommu/intel/irq_remapping.c | 8 ++ include/linux/intel-iommu.h | 39 +++--- 6 files changed, 377 insertions(+), 94 deletions(-) create mode 100644 drivers/iommu/intel/cap_audit.c create mode 100644 drivers/iommu/intel/cap_audit.h
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v5 1/2 iommu/vt-d: Audit IOMMU Capabilities and add helper functions
Audit IOMMU Capability/Extended Capability and check if the IOMMUs have the consistent value for features. Report out or scale to the lowest supported when IOMMU features have incompatibility among IOMMUs.
Report out features when below features are mismatched:
- First Level 5 Level Paging Support (FL5LP)
- First Level 1 GByte Page Support (FL1GP)
- Read Draining (DRD)
- Write Draining (DWD)
- Page Selective Invalidation (PSI)
- Zero Length Read (ZLR)
- Caching Mode (CM)
- Protected High/Low-Memory Region (PHMR/PLMR)
- Required Write-Buffer Flushing (RWBF)
- Advanced Fault Logging (AFL)
- RID-PASID Support (RPS)
- Scalable Mode Page Walk Coherency (SMPWC)
- First Level Translation Support (FLTS)
- Second Level Translation Support (SLTS)
- No Write Flag Support (NWFS)
- Second Level Accessed/Dirty Support (SLADS)
- Virtual Command Support (VCS)
- Scalable Mode Translation Support (SMTS)
- Device TLB Invalidation Throttle (DIT)
- Page Drain Support (PDS)
- Process Address Space ID Support (PASID)
- Extended Accessed Flag Support (EAFS)
- Supervisor Request Support (SRS)
- Execute Request Support (ERS)
- Page Request Support (PRS)
- Nested Translation Support (NEST)
- Snoop Control (SC)
- Pass Through (PT)
- Device TLB Support (DT)
- Queued Invalidation (QI)
- Page walk Coherency (C)
Set capability to the lowest supported when below features are mismatched:
- Maximum Address Mask Value (MAMV)
- Number of Fault Recording Registers (NFR)
- Second Level Large Page Support (SLLPS)
- Fault Recording Offset (FRO)
- Maximum Guest Address Width (MGAW)
- Supported Adjusted Guest Address Width (SAGAW)
- Number of Domains supported (NDOMS)
- Pasid Size Supported (PSS)
- Maximum Handle Mask Value (MHMV)
- IOTLB Register Offset (IRO)
--- drivers/iommu/intel/Makefile | 4 +- drivers/iommu/intel/cap_audit.c | 185 ++++++++++++++++++++++++++++ drivers/iommu/intel/cap_audit.h | 110 +++++++++++++++++ drivers/iommu/intel/iommu.c | 9 ++ drivers/iommu/intel/irq_remapping.c | 8 ++ include/linux/intel-iommu.h | 39 +++--- 6 files changed, 335 insertions(+), 20 deletions(-) create mode 100644 drivers/iommu/intel/cap_audit.c create mode 100644 drivers/iommu/intel/cap_audit.h
drivers/iommu/intel/Makefile +2 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DMAR_TABLE) += dmar.o obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o -obj-$(CONFIG_INTEL_IOMMU) += trace.o +obj-$(CONFIG_INTEL_IOMMU) += trace.o cap_audit.o obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o obj-$(CONFIG_INTEL_IOMMU_SVM) += svm.o -obj-$(CONFIG_IRQ_REMAP) += irq_remapping.o +obj-$(CONFIG_IRQ_REMAP) += irq_remapping.o cap_audit.o
drivers/iommu/intel/cap_audit.c new file +185 -0
185 lines not on this page · raw message
drivers/iommu/intel/cap_audit.h new file +110 -0
110 lines not on this page · raw message
drivers/iommu/intel/iommu.c +9 -0
@@ -48,6 +48,7 @@#include "../irq_remapping.h" #include "pasid.h" +#include "cap_audit.h" #define ROOT_SIZE VTD_PAGE_SIZE#define CONTEXT_SIZE VTD_PAGE_SIZE
@@ -3197,6 +3198,10 @@ static int __init init_dmars(void) goto error; } + ret =intel_cap_audit (CAP_AUDIT_STATIC_DMAR ,NULL ); +if (ret) + goto free_iommu; +for_each_iommu (iommu, drhd) {if (drhd->ignored) {iommu_disable_translation (iommu);
@@ -3748,6 +3753,10 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)if (g_iommus[iommu->seq_id])return 0 ; + ret =intel_cap_audit (CAP_AUDIT_HOTPLUG_DMAR , iommu); +if (ret) + goto out; +if (hw_pass_through && !ecap_pass_through (iommu->ecap)) {pr_warn ("%s: Doesn't support hardware pass through.\n" , iommu->name);
drivers/iommu/intel/irq_remapping.c +8 -0
@@ -22,6 +22,7 @@#include <asm/pci-direct.h> #include "../irq_remapping.h" +#include "cap_audit.h" enum irq_mode {IRQ_REMAPPING ,
@@ -734,6 +735,9 @@ static int __init intel_prepare_irq_remapping(void)if (dmar_table_init () <0 )return -ENODEV ; +if (intel_cap_audit (CAP_AUDIT_STATIC_IRQR ,NULL )) + goto error; +if (!dmar_ir_support ())return -ENODEV ;
@@ -1439,6 +1443,10 @@ static int dmar_ir_add(struct dmar_drhd_unit *dmaru, struct intel_iommu *iommu)int ret;int eim =x2apic_enabled (); + ret =intel_cap_audit (CAP_AUDIT_HOTPLUG_IRQR , iommu); +if (ret) +return ret; +if (eim && !ecap_eim_support (iommu->ecap)) {pr_info ("DRHD %Lx: EIM not supported by DRHD, ecap %Lx\n" , iommu->reg_phys, iommu->ecap);
include/linux/intel-iommu.h +21 -18
@@ -168,34 +168,37 @@* Extended Capability Register */ +#define ecap_rps (e) (((e) >> 49) & 0x1)#define ecap_smpwc (e) (((e) >> 48) & 0x1)#define ecap_flts (e) (((e) >> 47) & 0x1)#define ecap_slts (e) (((e) >> 46) & 0x1) +#define ecap_slads (e) (((e) >> 45) & 0x1)#define ecap_vcs (e) (((e) >> 44) & 0x1)#define ecap_smts (e) (((e) >> 43) & 0x1) -#define ecap_dit (e) ((e >> 41) & 0x1) -#define ecap_pasid (e) ((e >> 40) & 0x1) -#define ecap_pss (e) ((e >> 35) & 0x1f) -#define ecap_eafs (e) ((e >> 34) & 0x1) -#define ecap_nwfs (e) ((e >> 33) & 0x1) -#define ecap_srs (e) ((e >> 31) & 0x1) -#define ecap_ers (e) ((e >> 30) & 0x1) -#define ecap_prs (e) ((e >> 29) & 0x1) -#define ecap_broken_pasid (e) ((e >> 28) & 0x1) -#define ecap_dis (e) ((e >> 27) & 0x1) -#define ecap_nest (e) ((e >> 26) & 0x1) -#define ecap_mts (e) ((e >> 25) & 0x1) -#define ecap_ecs (e) ((e >> 24) & 0x1) +#define ecap_dit (e) (((e) >> 41) & 0x1) +#define ecap_pds (e) (((e) >> 42) & 0x1) +#define ecap_pasid (e) (((e) >> 40) & 0x1) +#define ecap_pss (e) (((e) >> 35) & 0x1f) +#define ecap_eafs (e) (((e) >> 34) & 0x1) +#define ecap_nwfs (e) (((e) >> 33) & 0x1) +#define ecap_srs (e) (((e) >> 31) & 0x1) +#define ecap_ers (e) (((e) >> 30) & 0x1) +#define ecap_prs (e) (((e) >> 29) & 0x1) +#define ecap_broken_pasid (e) (((e) >> 28) & 0x1) +#define ecap_dis (e) (((e) >> 27) & 0x1) +#define ecap_nest (e) (((e) >> 26) & 0x1) +#define ecap_mts (e) (((e) >> 25) & 0x1) +#define ecap_ecs (e) (((e) >> 24) & 0x1)#define ecap_iotlb_offset (e) ((((e) >> 8) & 0x3ff) * 16)#define ecap_max_iotlb_offset (e) (ecap_iotlb_offset(e) + 16)#define ecap_coherent (e) ((e) & 0x1)#define ecap_qis (e) ((e) & 0x2) -#define ecap_pass_through (e) ((e >> 6) & 0x1) -#define ecap_eim_support (e) ((e >> 4) & 0x1) -#define ecap_ir_support (e) ((e >> 3) & 0x1) +#define ecap_pass_through (e) (((e) >> 6) & 0x1) +#define ecap_eim_support (e) (((e) >> 4) & 0x1) +#define ecap_ir_support (e) (((e) >> 3) & 0x1)#define ecap_dev_iotlb_support (e) (((e) >> 2) & 0x1) -#define ecap_max_handle_mask (e) ((e >> 20) & 0xf) -#define ecap_sc_support (e) ((e >> 7) & 0x1)/* Snooping Control */ +#define ecap_max_handle_mask (e) (((e) >> 20) & 0xf) +#define ecap_sc_support (e) (((e) >> 7) & 0x1)/* Snooping Control */ /* Virtual command interface capability */ #define vccap_pasid (v) (((v) & DMA_VCS_PAS))/* PASID allocation */
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v5 2/2 iommu/vt-d: Move capability check code to cap_audit files
In reply to Kyung Min ParkMove IOMMU capability check and sanity check code to cap_audit files. Also implement some helper functions for sanity checks.
--- drivers/iommu/intel/cap_audit.c | 20 +++++++++ drivers/iommu/intel/cap_audit.h | 20 +++++++++ drivers/iommu/intel/iommu.c | 76 +-------------------------------- 3 files changed, 42 insertions(+), 74 deletions(-)
drivers/iommu/intel/cap_audit.c +20 -0
@@ -183,3 +183,23 @@ int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu)return -EFAULT ; } + +bool intel_cap_smts_sanity (void ) +{ +return ecap_smts (intel_iommu_ecap_sanity); +} + +bool intel_cap_pasid_sanity (void ) +{ +return ecap_pasid (intel_iommu_ecap_sanity); +} + +bool intel_cap_nest_sanity (void ) +{ +return ecap_nest (intel_iommu_ecap_sanity); +} + +bool intel_cap_flts_sanity (void ) +{ +return ecap_flts (intel_iommu_ecap_sanity); +}
drivers/iommu/intel/cap_audit.h +20 -0
@@ -107,4 +107,24 @@ enum cap_audit_type { CAP_AUDIT_HOTPLUG_IRQR, }; +bool intel_cap_smts_sanity (void ); +bool intel_cap_pasid_sanity (void ); +bool intel_cap_nest_sanity (void ); +bool intel_cap_flts_sanity (void ); + +static inline bool scalable_mode_support (void ) +{ +return (intel_iommu_sm &&intel_cap_smts_sanity ()); +} + +static inline bool pasid_mode_support (void ) +{ +return scalable_mode_support () &&intel_cap_pasid_sanity (); +} + +static inline bool nested_mode_support (void ) +{ +return scalable_mode_support () &&intel_cap_nest_sanity (); +} +int intel_cap_audit (enum cap_audit_type type,struct intel_iommu *iommu);
drivers/iommu/intel/iommu.c +2 -74
94 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu