Skip to content

Commit 4fc2ea6

Browse files
committed
Merge tag 'iommu-updates-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull iommu updates from Joerg Roedel: - Allow compiling the ARM-SMMU drivers as modules. - Fixes and cleanups for the ARM-SMMU drivers and io-pgtable code collected by Will Deacon. The merge-commit (6855d1b) has all the details. - Cleanup of the iommu_put_resv_regions() call-backs in various drivers. - AMD IOMMU driver cleanups. - Update for the x2APIC support in the AMD IOMMU driver. - Preparation patches for Intel VT-d nested mode support. - RMRR and identity domain handling fixes for the Intel VT-d driver. - More small fixes and cleanups. * tag 'iommu-updates-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (87 commits) iommu/amd: Remove the unnecessary assignment iommu/vt-d: Remove unnecessary WARN_ON_ONCE() iommu/vt-d: Unnecessary to handle default identity domain iommu/vt-d: Allow devices with RMRRs to use identity domain iommu/vt-d: Add RMRR base and end addresses sanity check iommu/vt-d: Mark firmware tainted if RMRR fails sanity check iommu/amd: Remove unused struct member iommu/amd: Replace two consecutive readl calls with one readq iommu/vt-d: Don't reject Host Bridge due to scope mismatch PCI/ATS: Add PASID stubs iommu/arm-smmu-v3: Return -EBUSY when trying to re-add a device iommu/arm-smmu-v3: Improve add_device() error handling iommu/arm-smmu-v3: Use WRITE_ONCE() when changing validity of an STE iommu/arm-smmu-v3: Add second level of context descriptor table iommu/arm-smmu-v3: Prepare for handling arm_smmu_write_ctx_desc() failure iommu/arm-smmu-v3: Propagate ssid_bits iommu/arm-smmu-v3: Add support for Substream IDs iommu/arm-smmu-v3: Add context descriptor tables allocators iommu/arm-smmu-v3: Prepare arm_smmu_s1_cfg for SSID support ACPI/IORT: Parse SSID property of named component node ...
2 parents d271ab2 + e3b5ee0 commit 4fc2ea6

36 files changed

+1686
-822
lines changed

Documentation/devicetree/bindings/iommu/iommu.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ have a means to turn off translation. But it is invalid in such cases to
8686
disable the IOMMU's device tree node in the first place because it would
8787
prevent any driver from properly setting up the translations.
8888

89+
Optional properties:
90+
--------------------
91+
- pasid-num-bits: Some masters support multiple address spaces for DMA, by
92+
tagging DMA transactions with an address space identifier. By default,
93+
this is 0, which means that the device only has one address space.
94+
8995

9096
Notes:
9197
======

drivers/acpi/arm64/iort.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define pr_fmt(fmt) "ACPI: IORT: " fmt
1212

1313
#include <linux/acpi_iort.h>
14+
#include <linux/bitfield.h>
1415
#include <linux/iommu.h>
1516
#include <linux/kernel.h>
1617
#include <linux/list.h>
@@ -902,9 +903,9 @@ static inline bool iort_iommu_driver_enabled(u8 type)
902903
{
903904
switch (type) {
904905
case ACPI_IORT_NODE_SMMU_V3:
905-
return IS_BUILTIN(CONFIG_ARM_SMMU_V3);
906+
return IS_ENABLED(CONFIG_ARM_SMMU_V3);
906907
case ACPI_IORT_NODE_SMMU:
907-
return IS_BUILTIN(CONFIG_ARM_SMMU);
908+
return IS_ENABLED(CONFIG_ARM_SMMU);
908909
default:
909910
pr_warn("IORT node type %u does not describe an SMMU\n", type);
910911
return false;
@@ -976,6 +977,20 @@ static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data)
976977
return iort_iommu_xlate(info->dev, parent, streamid);
977978
}
978979

980+
static void iort_named_component_init(struct device *dev,
981+
struct acpi_iort_node *node)
982+
{
983+
struct acpi_iort_named_component *nc;
984+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
985+
986+
if (!fwspec)
987+
return;
988+
989+
nc = (struct acpi_iort_named_component *)node->node_data;
990+
fwspec->num_pasid_bits = FIELD_GET(ACPI_IORT_NC_PASID_BITS,
991+
nc->node_flags);
992+
}
993+
979994
/**
980995
* iort_iommu_configure - Set-up IOMMU configuration for a device.
981996
*
@@ -1030,6 +1045,9 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev)
10301045
if (parent)
10311046
err = iort_iommu_xlate(dev, parent, streamid);
10321047
} while (parent && !err);
1048+
1049+
if (!err)
1050+
iort_named_component_init(dev, node);
10331051
}
10341052

10351053
/*

drivers/iommu/Kconfig

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ config IOMMU_DEBUGFS
8282
config IOMMU_DEFAULT_PASSTHROUGH
8383
bool "IOMMU passthrough by default"
8484
depends on IOMMU_API
85-
help
85+
help
8686
Enable passthrough by default, removing the need to pass in
8787
iommu.passthrough=on or iommu=pt through command line. If this
8888
is enabled, you can still disable with iommu.passthrough=off
@@ -91,8 +91,8 @@ config IOMMU_DEFAULT_PASSTHROUGH
9191
If unsure, say N here.
9292

9393
config OF_IOMMU
94-
def_bool y
95-
depends on OF && IOMMU_API
94+
def_bool y
95+
depends on OF && IOMMU_API
9696

9797
# IOMMU-agnostic DMA-mapping layer
9898
config IOMMU_DMA
@@ -214,6 +214,7 @@ config INTEL_IOMMU_SVM
214214
select PCI_PASID
215215
select PCI_PRI
216216
select MMU_NOTIFIER
217+
select IOASID
217218
help
218219
Shared Virtual Memory (SVM) provides a facility for devices
219220
to access DMA resources through process address space by
@@ -248,6 +249,18 @@ config INTEL_IOMMU_FLOPPY_WA
248249
workaround will setup a 1:1 mapping for the first
249250
16MiB to make floppy (an ISA device) work.
250251

252+
config INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON
253+
bool "Enable Intel IOMMU scalable mode by default"
254+
depends on INTEL_IOMMU
255+
help
256+
Selecting this option will enable by default the scalable mode if
257+
hardware presents the capability. The scalable mode is defined in
258+
VT-d 3.0. The scalable mode capability could be checked by reading
259+
/sys/devices/virtual/iommu/dmar*/intel-iommu/ecap. If this option
260+
is not selected, scalable mode support could also be enabled by
261+
passing intel_iommu=sm_on to the kernel. If not sure, please use
262+
the default value.
263+
251264
config IRQ_REMAP
252265
bool "Support for Interrupt Remapping"
253266
depends on X86_64 && X86_IO_APIC && PCI_MSI && ACPI
@@ -356,7 +369,7 @@ config SPAPR_TCE_IOMMU
356369

357370
# ARM IOMMU support
358371
config ARM_SMMU
359-
bool "ARM Ltd. System MMU (SMMU) Support"
372+
tristate "ARM Ltd. System MMU (SMMU) Support"
360373
depends on (ARM64 || ARM) && MMU
361374
select IOMMU_API
362375
select IOMMU_IO_PGTABLE_LPAE
@@ -368,6 +381,18 @@ config ARM_SMMU
368381
Say Y here if your SoC includes an IOMMU device implementing
369382
the ARM SMMU architecture.
370383

384+
config ARM_SMMU_LEGACY_DT_BINDINGS
385+
bool "Support the legacy \"mmu-masters\" devicetree bindings"
386+
depends on ARM_SMMU=y && OF
387+
help
388+
Support for the badly designed and deprecated "mmu-masters"
389+
devicetree bindings. This allows some DMA masters to attach
390+
to the SMMU but does not provide any support via the DMA API.
391+
If you're lucky, you might be able to get VFIO up and running.
392+
393+
If you say Y here then you'll make me very sad. Instead, say N
394+
and move your firmware to the utopian future that was 2016.
395+
371396
config ARM_SMMU_DISABLE_BYPASS_BY_DEFAULT
372397
bool "Default to disabling bypass on ARM SMMU v1 and v2"
373398
depends on ARM_SMMU
@@ -394,7 +419,7 @@ config ARM_SMMU_DISABLE_BYPASS_BY_DEFAULT
394419
config.
395420

396421
config ARM_SMMU_V3
397-
bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
422+
tristate "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
398423
depends on ARM64
399424
select IOMMU_API
400425
select IOMMU_IO_PGTABLE_LPAE

drivers/iommu/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o
1414
obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o amd_iommu_quirks.o
1515
obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += amd_iommu_debugfs.o
1616
obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o
17-
obj-$(CONFIG_ARM_SMMU) += arm-smmu.o arm-smmu-impl.o arm-smmu-qcom.o
17+
obj-$(CONFIG_ARM_SMMU) += arm-smmu-mod.o
18+
arm-smmu-mod-objs += arm-smmu.o arm-smmu-impl.o arm-smmu-qcom.o
1819
obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o
1920
obj-$(CONFIG_DMAR_TABLE) += dmar.o
2021
obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o intel-pasid.o

drivers/iommu/amd_iommu.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,6 @@ int __init amd_iommu_init_api(void)
22942294
int __init amd_iommu_init_dma_ops(void)
22952295
{
22962296
swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
2297-
iommu_detected = 1;
22982297

22992298
if (amd_iommu_unmap_flush)
23002299
pr_info("IO/TLB flush on unmap enabled\n");
@@ -2638,15 +2637,6 @@ static void amd_iommu_get_resv_regions(struct device *dev,
26382637
list_add_tail(&region->list, head);
26392638
}
26402639

2641-
static void amd_iommu_put_resv_regions(struct device *dev,
2642-
struct list_head *head)
2643-
{
2644-
struct iommu_resv_region *entry, *next;
2645-
2646-
list_for_each_entry_safe(entry, next, head, list)
2647-
kfree(entry);
2648-
}
2649-
26502640
static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
26512641
struct device *dev)
26522642
{
@@ -2685,7 +2675,7 @@ const struct iommu_ops amd_iommu_ops = {
26852675
.device_group = amd_iommu_device_group,
26862676
.domain_get_attr = amd_iommu_domain_get_attr,
26872677
.get_resv_regions = amd_iommu_get_resv_regions,
2688-
.put_resv_regions = amd_iommu_put_resv_regions,
2678+
.put_resv_regions = generic_iommu_put_resv_regions,
26892679
.is_attach_deferred = amd_iommu_is_attach_deferred,
26902680
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
26912681
.flush_iotlb_all = amd_iommu_flush_iotlb_all,

drivers/iommu/amd_iommu_init.c

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#define IVHD_FLAG_ISOC_EN_MASK 0x08
7272

7373
#define IVMD_FLAG_EXCL_RANGE 0x08
74+
#define IVMD_FLAG_IW 0x04
75+
#define IVMD_FLAG_IR 0x02
7476
#define IVMD_FLAG_UNITY_MAP 0x01
7577

7678
#define ACPI_DEVFLAG_INITPASS 0x01
@@ -147,7 +149,7 @@ bool amd_iommu_dump;
147149
bool amd_iommu_irq_remap __read_mostly;
148150

149151
int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC;
150-
static int amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE;
152+
static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
151153

152154
static bool amd_iommu_detected;
153155
static bool __initdata amd_iommu_disabled;
@@ -714,7 +716,7 @@ static void iommu_enable_ppr_log(struct amd_iommu *iommu)
714716
writel(0x00, iommu->mmio_base + MMIO_PPR_HEAD_OFFSET);
715717
writel(0x00, iommu->mmio_base + MMIO_PPR_TAIL_OFFSET);
716718

717-
iommu_feature_enable(iommu, CONTROL_PPFLOG_EN);
719+
iommu_feature_enable(iommu, CONTROL_PPRLOG_EN);
718720
iommu_feature_enable(iommu, CONTROL_PPR_EN);
719721
}
720722

@@ -1116,21 +1118,17 @@ static int __init add_early_maps(void)
11161118
*/
11171119
static void __init set_device_exclusion_range(u16 devid, struct ivmd_header *m)
11181120
{
1119-
struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
1120-
11211121
if (!(m->flags & IVMD_FLAG_EXCL_RANGE))
11221122
return;
11231123

1124-
if (iommu) {
1125-
/*
1126-
* We only can configure exclusion ranges per IOMMU, not
1127-
* per device. But we can enable the exclusion range per
1128-
* device. This is done here
1129-
*/
1130-
set_dev_entry_bit(devid, DEV_ENTRY_EX);
1131-
iommu->exclusion_start = m->range_start;
1132-
iommu->exclusion_length = m->range_length;
1133-
}
1124+
/*
1125+
* Treat per-device exclusion ranges as r/w unity-mapped regions
1126+
* since some buggy BIOSes might lead to the overwritten exclusion
1127+
* range (exclusion_start and exclusion_length members). This
1128+
* happens when there are multiple exclusion ranges (IVMD entries)
1129+
* defined in ACPI table.
1130+
*/
1131+
m->flags = (IVMD_FLAG_IW | IVMD_FLAG_IR | IVMD_FLAG_UNITY_MAP);
11341132
}
11351133

11361134
/*
@@ -1523,8 +1521,6 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
15231521
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
15241522
if (((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) == 0))
15251523
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
1526-
if (((h->efr_attr & (0x1 << IOMMU_FEAT_XTSUP_SHIFT)) == 0))
1527-
amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
15281524
break;
15291525
case 0x11:
15301526
case 0x40:
@@ -1534,8 +1530,15 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
15341530
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
15351531
if (((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0))
15361532
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
1537-
if (((h->efr_reg & (0x1 << IOMMU_EFR_XTSUP_SHIFT)) == 0))
1538-
amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
1533+
/*
1534+
* Note: Since iommu_update_intcapxt() leverages
1535+
* the IOMMU MMIO access to MSI capability block registers
1536+
* for MSI address lo/hi/data, we need to check both
1537+
* EFR[XtSup] and EFR[MsiCapMmioSup] for x2APIC support.
1538+
*/
1539+
if ((h->efr_reg & BIT(IOMMU_EFR_XTSUP_SHIFT)) &&
1540+
(h->efr_reg & BIT(IOMMU_EFR_MSICAPMMIOSUP_SHIFT)))
1541+
amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE;
15391542
break;
15401543
default:
15411544
return -EINVAL;
@@ -1727,7 +1730,6 @@ static const struct attribute_group *amd_iommu_groups[] = {
17271730
static int __init iommu_init_pci(struct amd_iommu *iommu)
17281731
{
17291732
int cap_ptr = iommu->cap_ptr;
1730-
u32 range, misc, low, high;
17311733
int ret;
17321734

17331735
iommu->dev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(iommu->devid),
@@ -1740,19 +1742,12 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
17401742

17411743
pci_read_config_dword(iommu->dev, cap_ptr + MMIO_CAP_HDR_OFFSET,
17421744
&iommu->cap);
1743-
pci_read_config_dword(iommu->dev, cap_ptr + MMIO_RANGE_OFFSET,
1744-
&range);
1745-
pci_read_config_dword(iommu->dev, cap_ptr + MMIO_MISC_OFFSET,
1746-
&misc);
17471745

17481746
if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB)))
17491747
amd_iommu_iotlb_sup = false;
17501748

17511749
/* read extended feature bits */
1752-
low = readl(iommu->mmio_base + MMIO_EXT_FEATURES);
1753-
high = readl(iommu->mmio_base + MMIO_EXT_FEATURES + 4);
1754-
1755-
iommu->features = ((u64)high << 32) | low;
1750+
iommu->features = readq(iommu->mmio_base + MMIO_EXT_FEATURES);
17561751

17571752
if (iommu_feature(iommu, FEATURE_GT)) {
17581753
int glxval;
@@ -1996,8 +1991,8 @@ static int iommu_init_intcapxt(struct amd_iommu *iommu)
19961991
struct irq_affinity_notify *notify = &iommu->intcapxt_notify;
19971992

19981993
/**
1999-
* IntCapXT requires XTSup=1, which can be inferred
2000-
* amd_iommu_xt_mode.
1994+
* IntCapXT requires XTSup=1 and MsiCapMmioSup=1,
1995+
* which can be inferred from amd_iommu_xt_mode.
20011996
*/
20021997
if (amd_iommu_xt_mode != IRQ_REMAP_X2APIC_MODE)
20031998
return 0;
@@ -2044,7 +2039,7 @@ static int iommu_init_msi(struct amd_iommu *iommu)
20442039
iommu_feature_enable(iommu, CONTROL_EVT_INT_EN);
20452040

20462041
if (iommu->ppr_log != NULL)
2047-
iommu_feature_enable(iommu, CONTROL_PPFINT_EN);
2042+
iommu_feature_enable(iommu, CONTROL_PPRINT_EN);
20482043

20492044
iommu_ga_log_enable(iommu);
20502045

drivers/iommu/amd_iommu_types.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
#define CONTROL_COHERENT_EN 0x0aULL
148148
#define CONTROL_ISOC_EN 0x0bULL
149149
#define CONTROL_CMDBUF_EN 0x0cULL
150-
#define CONTROL_PPFLOG_EN 0x0dULL
151-
#define CONTROL_PPFINT_EN 0x0eULL
150+
#define CONTROL_PPRLOG_EN 0x0dULL
151+
#define CONTROL_PPRINT_EN 0x0eULL
152152
#define CONTROL_PPR_EN 0x0fULL
153153
#define CONTROL_GT_EN 0x10ULL
154154
#define CONTROL_GA_EN 0x11ULL
@@ -377,12 +377,12 @@
377377
#define IOMMU_CAP_EFR 27
378378

379379
/* IOMMU Feature Reporting Field (for IVHD type 10h */
380-
#define IOMMU_FEAT_XTSUP_SHIFT 0
381380
#define IOMMU_FEAT_GASUP_SHIFT 6
382381

383382
/* IOMMU Extended Feature Register (EFR) */
384383
#define IOMMU_EFR_XTSUP_SHIFT 2
385384
#define IOMMU_EFR_GASUP_SHIFT 7
385+
#define IOMMU_EFR_MSICAPMMIOSUP_SHIFT 46
386386

387387
#define MAX_DOMAIN_ID 65536
388388

@@ -463,7 +463,6 @@ struct amd_irte_ops;
463463
* independent of their use.
464464
*/
465465
struct protection_domain {
466-
struct list_head list; /* for list of all protection domains */
467466
struct list_head dev_list; /* List of all devices in this domain */
468467
struct iommu_domain domain; /* generic domain handle used by
469468
iommu core code */

drivers/iommu/arm-smmu-impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int arm_mmu500_reset(struct arm_smmu_device *smmu)
119119
* Secure has also cleared SACR.CACHE_LOCK for this to take effect...
120120
*/
121121
reg = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_ID7);
122-
major = FIELD_GET(ID7_MAJOR, reg);
122+
major = FIELD_GET(ARM_SMMU_ID7_MAJOR, reg);
123123
reg = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_sACR);
124124
if (major >= 2)
125125
reg &= ~ARM_MMU500_ACR_CACHE_LOCK;

0 commit comments

Comments
 (0)