iommu: Make default_domain's mandatory
Subsystems (19)
Jason Gunthorpe
maintainerv8 cover iommu: Make default_domain's mandatory
It has been a long time coming, this series completes the default_domain transition and makes it so that the core IOMMU code will always have a non-NULL default_domain for every driver on every
platform. set_platform_dma_ops() turned out to be a bad idea, and so completely remove it.
This is achieved by changing each driver to either:
1 - Convert the existing (or deleted) ops->detach_dev() into an
op->attach_dev() of an IDENTITY domain.
This is based on the theory that the ARM32 HW is able to function when the iommu is turned off and so the turned off state is an IDENTITY translation.
2 - Use a new PLATFORM domain type. This is a hack to accommodate drivers
that we don't really know WTF they do. S390 is legitimately using this to switch to it's platform dma_ops implementation, which is where the name comes from.
3 - Do #1 and force the default domain to be IDENTITY, this corrects
the tegra-smmu case where even an ARM64 system would have a NULL default_domain.
Using this we can apply the rules:
a) ARM_DMA_USE_IOMMU mode always uses either the driver's ops->default_domain, ops->def_domain_type(), or an IDENTITY domain. All ARM32 drivers provide one of these three options.
b) dma-iommu.c mode uses either the driver's ops->default_domain, ops->def_domain_type or the usual DMA API policy logic based on the command line/etc to pick IDENTITY/DMA domain types
c) All other arch's (PPC/S390) use ops->default_domain always.
See the patch "Require a default_domain for all iommu drivers" for a per-driver breakdown.
The conversion broadly teaches a bunch of ARM32 drivers that they can do IDENTITY domains. There is some educated guessing involved that these are actual IDENTITY domains. If this turns out to be wrong the driver can be trivially changed to use a BLOCKING domain type instead. Further, the domain type only matters for drivers using ARM64's dma-iommu.c mode as it will select IDENTITY based on the command line and expect IDENTITY to work. For ARM32 and other arch cases it is purely documentation.
Finally, based on all the analysis in this series, we can purge IOMMU_DOMAIN_UNMANAGED/DMA constants from most of the drivers. This greatly simplifies understanding the driver contract to the core code. IOMMU drivers should not be involved in policy for how the DMA API works, that should be a core core decision.
The main gain from this work is to remove alot of ARM_DMA_USE_IOMMU specific code and behaviors from drivers. All that remains in iommu drivers after this series is the calls to arm_iommu_create_mapping().
This is a step toward removing ARM_DMA_USE_IOMMU.
The IDENTITY domains added to the ARM64 supporting drivers can be tested by booting in ARM64 mode and enabling CONFIG_IOMMU_DEFAULT_PASSTHROUGH. If the system still boots then most likely the implementation is an IDENTITY domain. If not we can trivially change it to BLOCKING or at worst PLATFORM if there is no detail what is going on in the HW.
I think this is pretty safe for the ARM32 drivers as they don't really change, the code that was in detach_dev continues to be called in the same places it was called before.
This is on github: https://github.com/jgunthorpe/linux/commits/iommu_all_defdom
v8:
- Rebase on v6.6-rc1
- Adjust comments for ops.default_domain
v7:
- Rebase on v6.5-rc6/Joerg's tree/iommufd
- Most of patch "iommufd/selftest: Make the mock iommu driver into a real driver" is now in the iommufd tree, diffuse the remaining bits to
"iommu: Add iommu_ops->identity_domain" and
"iommu: Add IOMMU_DOMAIN_PLATFORM"
- Move the check for domain->ops->free to patch 1 as the rockchip conversion relies on it
- Add IOMMU_DOMAIN_PLATFORM to iommu_domain_type_str
- Rewrite "iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()" to be clearer and more robust
- Remove left over .default_domain in tegra-smmu.c
- Use group_iommu_ops() in all appropriate places
- Typo s/paging/dev/ in sun50i
v6: https://lore.kernel.org/r/[email protected]
- Rebase on v6.5-rc1/Joerg's tree
- Fix the iommufd self test missing the iommu_device_sysfs_add()
- Update typo in msm commit message
v5: https://lore.kernel.org/r/[email protected]
- Rebase on v6.5-rc1/Joerg's tree
- Fix Dan's remark about 'gdev uninitialized' in patch 9
v4: https://lore.kernel.org/r/[email protected]
- Fix rebasing typo missing ops->alloc_domain_paging check
- Rebase on latest Joerg tree
v3: https://lore.kernel.org/r/[email protected]
- FSL is back to a PLATFORM domain, with some fixing so it attach only
does something when leaving an UNMANAGED domain like it always was
- Rebase on Joerg's tree, adjust for "alloc_type" change
- Change the ARM32 untrusted check to a WARN_ON since no ARM32 system
can currently set trusted
v2: https://lore.kernel.org/r/[email protected]
- FSL is an IDENTITY domain
- Delete terga-gart instead of trying to carry it
- Use the policy determination from iommu_get_default_domain_type() to drive the arm_iommu mode
- Reorganize and introduce new patches to do the above:
* Split the ops->identity_domain to an independent earlier patch
* Remove the UNMANAGED return from def_domain_type in mtk_v1 earlier
so the new iommu_get_default_domain_type() can work
* Make the driver's def_domain_type have higher policy priority than untrusted
* Merge the set_platfom_dma_ops hunk from mtk_v1 along with rockchip into the patch that forced IDENTITY on ARM32
- Revise sun50i to be cleaner and have a non-NULL internal domain
- Reword logging in exynos
- Remove the gdev from the group alloc path, instead add a new
function __iommu_group_domain_alloc() that takes in the group
and uses the first device. Split this to its own patch
- New patch to make iommufd's mock selftest into a real driver
- New patch to fix power's partial iommu driver
v1: https://lore.kernel.org/r/[email protected]
Jason Gunthorpe (24):
iommu: Add iommu_ops->identity_domain
iommu: Add IOMMU_DOMAIN_PLATFORM
powerpc/iommu: Setup a default domain and remove set_platform_dma_ops
iommu: Add IOMMU_DOMAIN_PLATFORM for S390
iommu/fsl_pamu: Implement a PLATFORM domain iommu/tegra-gart: Remove tegra-gart
iommu/mtk_iommu_v1: Implement an IDENTITY domain
iommu: Reorganize iommu_get_default_domain_type() to respect
def_domain_type()
iommu: Allow an IDENTITY domain as the default_domain in ARM32 iommu/exynos: Implement an IDENTITY domain iommu/tegra-smmu: Implement an IDENTITY domain iommu/tegra-smmu: Support DMA domains in tegra
iommu/omap: Implement an IDENTITY domain
iommu/msm: Implement an IDENTITY domain
iommu: Remove ops->set_platform_dma_ops() iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN
iommu: Require a default_domain for all iommu drivers
iommu: Add __iommu_group_domain_alloc()
iommu: Add ops->domain_alloc_paging()
iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()
iommu: Convert remaining simple drivers to domain_alloc_paging()
arch/arm/configs/multi_v7_defconfig | 1 - arch/arm/configs/tegra_defconfig | 1 - arch/powerpc/kernel/iommu.c | 38 ++- drivers/iommu/Kconfig | 11 - drivers/iommu/Makefile | 1 - drivers/iommu/arm/arm-smmu/qcom_iommu.c | 45 ++- drivers/iommu/exynos-iommu.c | 73 +++-- drivers/iommu/fsl_pamu_domain.c | 41 ++- drivers/iommu/iommu.c | 259 ++++++++++------- drivers/iommu/iommufd/selftest.c | 19 +- drivers/iommu/ipmmu-vmsa.c | 50 +++- drivers/iommu/msm_iommu.c | 30 +- drivers/iommu/mtk_iommu.c | 30 +- drivers/iommu/mtk_iommu_v1.c | 28 +- drivers/iommu/omap-iommu.c | 28 +- drivers/iommu/rockchip-iommu.c | 26 +- drivers/iommu/s390-iommu.c | 28 +- drivers/iommu/sprd-iommu.c | 7 +- drivers/iommu/sun50i-iommu.c | 35 ++- drivers/iommu/tegra-gart.c | 371 ------------------------ drivers/iommu/tegra-smmu.c | 44 ++- drivers/memory/tegra/mc.c | 34 --- drivers/memory/tegra/tegra20.c | 28 -- include/linux/iommu.h | 18 +- include/soc/tegra/mc.h | 26 -- 25 files changed, 516 insertions(+), 756 deletions(-) delete mode 100644 drivers/iommu/tegra-gart.c
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 1/24 iommu: Add iommu_ops->identity_domain
This allows a driver to set a global static to an IDENTITY domain and the core code will automatically use it whenever an IDENTITY domain is requested.
By making it always available it means the IDENTITY can be used in error handling paths to force the iommu driver into a known state. Devices implementing global static identity domains should avoid failing their attach_dev ops.
To make global static domains simpler allow drivers to omit their free function and update the iommufd selftest.
Convert rockchip to use the new mechanism.
--- drivers/iommu/iommu.c | 6 +++++- drivers/iommu/iommufd/selftest.c | 5 ----- drivers/iommu/rockchip-iommu.c | 9 +-------- include/linux/iommu.h | 3 +++ 4 files changed, 9 insertions(+), 14 deletions(-)
drivers/iommu/iommu.c +5 -1
@@ -1978,6 +1978,9 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,if (bus ==NULL || bus->iommu_ops ==NULL )return NULL ; +if (alloc_type ==IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain) +return bus->iommu_ops->identity_domain; + domain = bus->iommu_ops->domain_alloc (alloc_type);if (!domain)return NULL ;
@@ -2011,7 +2014,8 @@ void iommu_domain_free(struct iommu_domain *domain)if (domain->type ==IOMMU_DOMAIN_SVA )mmdrop (domain->mm);iommu_put_dma_cookie (domain); - domain->ops->free (domain); +if (domain->ops->free) + domain->ops->free (domain); }EXPORT_SYMBOL_GPL (iommu_domain_free);
drivers/iommu/iommufd/selftest.c +0 -5
@@ -111,10 +111,6 @@ struct selftest_obj { }; }; -static void mock_domain_blocking_free (struct iommu_domain *domain) -{ -} -static int mock_domain_nop_attach (struct iommu_domain *domain,struct device *dev) {
@@ -122,7 +118,6 @@ static int mock_domain_nop_attach(struct iommu_domain *domain, }static const struct iommu_domain_ops mock_blocking_ops = { - .free = mock_domain_blocking_free, .attach_dev = mock_domain_nop_attach, };
drivers/iommu/rockchip-iommu.c +1 -8
@@ -989,13 +989,8 @@ static int rk_iommu_identity_attach(struct iommu_domain *identity_domain,return 0 ; } -static void rk_iommu_identity_free (struct iommu_domain *domain) -{ -} -static struct iommu_domain_ops rk_identity_ops = { .attach_dev = rk_iommu_identity_attach, - .free = rk_iommu_identity_free, };static struct iommu_domain rk_identity_domain = {
@@ -1059,9 +1054,6 @@ static struct iommu_domain *rk_iommu_domain_alloc(unsigned type) {struct rk_iommu_domain *rk_domain; -if (type ==IOMMU_DOMAIN_IDENTITY ) -return &rk_identity_domain; -if (type !=IOMMU_DOMAIN_UNMANAGED && type !=IOMMU_DOMAIN_DMA )return NULL ;
@@ -1186,6 +1178,7 @@ static int rk_iommu_of_xlate(struct device *dev, }static const struct iommu_ops rk_iommu_ops = { + .identity_domain = &rk_identity_domain, .domain_alloc = rk_iommu_domain_alloc, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device,
include/linux/iommu.h +3 -0
@@ -260,6 +260,8 @@ struct iommu_iotlb_gather {* will be blocked by the hardware. * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops +* @identity_domain: An always available, always attachable identity +* translation. */ struct iommu_ops {bool (*capable)(struct device *dev,enum iommu_cap );
@@ -294,6 +296,7 @@ struct iommu_ops {const struct iommu_domain_ops *default_domain_ops;unsigned long pgsize_bitmap;struct module *owner; +struct iommu_domain *identity_domain; };/**
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 2/24 iommu: Add IOMMU_DOMAIN_PLATFORM
In reply to Jason GunthorpeThis is used when the iommu driver is taking control of the dma_ops, currently only on S390 and power spapr. It is designed to preserve the original ops->detach_dev() semantic that these S390 was built around.
Provide an opaque domain type and a 'default_domain' ops value that allows the driver to trivially force any single domain as the default domain.
Update iommufd selftest to use this instead of set_platform_dma_ops
--- drivers/iommu/iommu.c | 13 +++++++++++++ drivers/iommu/iommufd/selftest.c | 14 +++++--------- include/linux/iommu.h | 8 ++++++++ 3 files changed, 26 insertions(+), 9 deletions(-)
drivers/iommu/iommu.c +13 -0
@@ -184,6 +184,8 @@ static const char *iommu_domain_type_str(unsigned int t)case IOMMU_DOMAIN_DMA :case IOMMU_DOMAIN_DMA_FQ :return "Translated" ; +case IOMMU_DOMAIN_PLATFORM : +return "Platform" ;default :return "Unknown" ; }
@@ -1752,6 +1754,17 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)lockdep_assert_held (&group->mutex); +/* +* Allow legacy drivers to specify the domain that will be the default +* domain. This should always be either an IDENTITY/BLOCKED/PLATFORM +* domain. Do not use in new drivers. +*/ +if (bus->iommu_ops->default_domain) { +if (req_type) +return ERR_PTR (-EINVAL ); +return bus->iommu_ops->default_domain; + } +if (req_type)return __iommu_group_alloc_default_domain (bus, group, req_type);
drivers/iommu/iommufd/selftest.c +5 -9
@@ -281,14 +281,6 @@ static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)return cap ==IOMMU_CAP_CACHE_COHERENCY ; } -static void mock_domain_set_plaform_dma_ops (struct device *dev) -{ -/* -* mock doesn't setup default domains because we can't hook into the -* normal probe path -*/ -} -static struct iommu_device mock_iommu_device = { };
@@ -298,12 +290,16 @@ static struct iommu_device *mock_probe_device(struct device *dev) }static const struct iommu_ops mock_ops = { +/* +* IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() +* because it is zero. +*/ + .default_domain = &mock_blocking_domain, .owner =THIS_MODULE , .pgsize_bitmap =MOCK_IO_PAGE_SIZE , .hw_info = mock_domain_hw_info, .domain_alloc = mock_domain_alloc, .capable = mock_domain_capable, - .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, .device_group = generic_device_group, .probe_device = mock_probe_device, .default_domain_ops =
include/linux/iommu.h +8 -0
@@ -64,6 +64,7 @@ struct iommu_domain_geometry {#define __IOMMU_DOMAIN_DMA_FQ (1U << 3)/* DMA-API uses flush queue */ #define __IOMMU_DOMAIN_SVA (1U << 4)/* Shared process address space */ +#define __IOMMU_DOMAIN_PLATFORM (1U << 5)#define IOMMU_DOMAIN_ALLOC_FLAGS ~__IOMMU_DOMAIN_DMA_FQ/*
@@ -81,6 +82,8 @@ struct iommu_domain_geometry {* invalidation. * IOMMU_DOMAIN_SVA - DMA addresses are shared process addresses * represented by mm_struct's. +* IOMMU_DOMAIN_PLATFORM - Legacy domain for drivers that do their own +* dma_api stuff. Do not use in new drivers. */ #define IOMMU_DOMAIN_BLOCKED (0U)#define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT)
@@ -91,6 +94,7 @@ struct iommu_domain_geometry { __IOMMU_DOMAIN_DMA_API | \ __IOMMU_DOMAIN_DMA_FQ)#define IOMMU_DOMAIN_SVA (__IOMMU_DOMAIN_SVA) +#define IOMMU_DOMAIN_PLATFORM (__IOMMU_DOMAIN_PLATFORM)struct iommu_domain {unsigned type;
@@ -262,6 +266,9 @@ struct iommu_iotlb_gather {* @owner: Driver module providing these ops * @identity_domain: An always available, always attachable identity * translation. +* @default_domain: If not NULL this will always be set as the default domain. +* This should be an IDENTITY/BLOCKED/PLATFORM domain. +* Do not use in new drivers. */ struct iommu_ops {bool (*capable)(struct device *dev,enum iommu_cap );
@@ -297,6 +304,7 @@ struct iommu_ops {unsigned long pgsize_bitmap;struct module *owner;struct iommu_domain *identity_domain; +struct iommu_domain *default_domain; };/**
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 3/24 powerpc/iommu: Setup a default domain and remove set_platform_dma_ops
In reply to Jason GunthorpePOWER is using the set_platform_dma_ops() callback to hook up its private dma_ops, but this is buired under some indirection and is weirdly happening for a BLOCKED domain as well.
For better documentation create a PLATFORM domain to manage the dma_ops, since that is what it is for, and make the BLOCKED domain an alias for it. BLOCKED is required for VFIO.
Also removes the leaky allocation of the BLOCKED domain by using a global static.
--- arch/powerpc/kernel/iommu.c | 38 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
arch/powerpc/kernel/iommu.c +17 -21
@@ -1280,7 +1280,7 @@ struct iommu_table_group_ops spapr_tce_table_group_ops = {/* * A simple iommu_ops to allow less cruft in generic VFIO code. */ -static int spapr_tce_blocking_iommu_attach_dev (struct iommu_domain *dom, +static int spapr_tce_platform_iommu_attach_dev (struct iommu_domain *dom,struct device *dev) {struct iommu_group *grp =iommu_group_get (dev);
@@ -1297,17 +1297,22 @@ static int spapr_tce_blocking_iommu_attach_dev(struct iommu_domain *dom,return ret; } -static void spapr_tce_blocking_iommu_set_platform_dma (struct device *dev) -{ -struct iommu_group *grp =iommu_group_get (dev); -struct iommu_table_group *table_group; +static const struct iommu_domain_ops spapr_tce_platform_domain_ops = { + .attach_dev = spapr_tce_platform_iommu_attach_dev, +}; - table_group =iommu_group_get_iommudata (grp); - table_group->ops->release_ownership (table_group); -} +static struct iommu_domain spapr_tce_platform_domain = { + .type =IOMMU_DOMAIN_PLATFORM , + .ops = &spapr_tce_platform_domain_ops, +}; -static const struct iommu_domain_ops spapr_tce_blocking_domain_ops = { - .attach_dev = spapr_tce_blocking_iommu_attach_dev, +static struct iommu_domain spapr_tce_blocked_domain = { + .type =IOMMU_DOMAIN_BLOCKED , +/* +* FIXME: SPAPR mixes blocked and platform behaviors, the blocked domain +* also sets the dma_api ops +*/ + .ops = &spapr_tce_platform_domain_ops, };static bool spapr_tce_iommu_capable (struct device *dev,enum iommu_cap cap)
@@ -1324,18 +1329,9 @@ static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap)static struct iommu_domain *spapr_tce_iommu_domain_alloc (unsigned int type) { -struct iommu_domain *dom; -if (type !=IOMMU_DOMAIN_BLOCKED )return NULL ; - - dom =kzalloc (sizeof (*dom),GFP_KERNEL ); -if (!dom) -return NULL ; - - dom->ops = &spapr_tce_blocking_domain_ops; - -return dom; +return &spapr_tce_blocked_domain; }static struct iommu_device *spapr_tce_iommu_probe_device (struct device *dev)
@@ -1371,12 +1367,12 @@ static struct iommu_group *spapr_tce_iommu_device_group(struct device *dev) }static const struct iommu_ops spapr_tce_iommu_ops = { + .default_domain = &spapr_tce_platform_domain, .capable = spapr_tce_iommu_capable, .domain_alloc = spapr_tce_iommu_domain_alloc, .probe_device = spapr_tce_iommu_probe_device, .release_device = spapr_tce_iommu_release_device, .device_group = spapr_tce_iommu_device_group, - .set_platform_dma_ops = spapr_tce_blocking_iommu_set_platform_dma, };static struct attribute *spapr_tce_iommu_attrs[] = {
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 4/24 iommu: Add IOMMU_DOMAIN_PLATFORM for S390
In reply to Jason GunthorpeThe PLATFORM domain will be set as the default domain and attached as normal during probe. The driver will ignore the initial attach from a NULL domain to the PLATFORM domain.
After this, the PLATFORM domain's attach_dev will be called whenever we detach from an UNMANAGED domain (eg for VFIO). This is the same time the original design would have called op->detach_dev().
This is temporary until the S390 dma-iommu.c conversion is merged.
--- drivers/iommu/s390-iommu.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iommu/s390-iommu.c +19 -2
@@ -142,14 +142,31 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,return 0 ; } -static void s390_iommu_set_platform_dma (struct device *dev) +/* +* Switch control over the IOMMU to S390's internal dma_api ops +*/ +static int s390_iommu_platform_attach (struct iommu_domain *platform_domain, +struct device *dev) {struct zpci_dev *zdev =to_zpci_dev (dev); +if (!zdev->s390_domain) +return 0 ; +__s390_iommu_detach_device (zdev);zpci_dma_init_device (zdev); +return 0 ; } +static struct iommu_domain_ops s390_iommu_platform_ops = { + .attach_dev = s390_iommu_platform_attach, +}; + +static struct iommu_domain s390_iommu_platform_domain = { + .type =IOMMU_DOMAIN_PLATFORM , + .ops = &s390_iommu_platform_ops, +}; +static void s390_iommu_get_resv_regions (struct device *dev,struct list_head *list) {
@@ -428,12 +445,12 @@ void zpci_destroy_iommu(struct zpci_dev *zdev) }static const struct iommu_ops s390_iommu_ops = { + .default_domain = &s390_iommu_platform_domain, .capable = s390_iommu_capable, .domain_alloc = s390_domain_alloc, .probe_device = s390_iommu_probe_device, .release_device = s390_iommu_release_device, .device_group = generic_device_group, - .set_platform_dma_ops = s390_iommu_set_platform_dma, .pgsize_bitmap =SZ_4K , .get_resv_regions = s390_iommu_get_resv_regions, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 5/24 iommu/fsl_pamu: Implement a PLATFORM domain
In reply to Jason GunthorpeThis driver is nonsensical. To not block migrating the core API away from NULL default_domains give it a hacky of a PLATFORM domain that keeps it working exactly as it always did.
Leave some comments around to warn away any future people looking at this.
--- drivers/iommu/fsl_pamu_domain.c | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-)
drivers/iommu/fsl_pamu_domain.c +38 -3
@@ -196,6 +196,13 @@ static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type) {struct fsl_dma_domain *dma_domain; +/* +* FIXME: This isn't creating an unmanaged domain since the +* default_domain_ops do not have any map/unmap function it doesn't meet +* the requirements for __IOMMU_DOMAIN_PAGING. The only purpose seems to +* allow drivers/soc/fsl/qbman/qman_portal.c to do +* fsl_pamu_configure_l1_stash() +*/ if (type !=IOMMU_DOMAIN_UNMANAGED )return NULL ;
@@ -283,15 +290,33 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,return ret; } -static void fsl_pamu_set_platform_dma (struct device *dev) +/* +* FIXME: fsl/pamu is completely broken in terms of how it works with the iommu +* API. Immediately after probe the HW is left in an IDENTITY translation and +* the driver provides a non-working UNMANAGED domain that it can switch over +* to. However it cannot switch back to an IDENTITY translation, instead it +* switches to what looks like BLOCKING. +*/ +static int fsl_pamu_platform_attach (struct iommu_domain *platform_domain, +struct device *dev) {struct iommu_domain *domain =iommu_get_domain_for_dev (dev); -struct fsl_dma_domain *dma_domain =to_fsl_dma_domain (domain); +struct fsl_dma_domain *dma_domain;const u32 *prop;int len;struct pci_dev *pdev =NULL ;struct pci_controller *pci_ctl; +/* +* Hack to keep things working as they always have, only leaving an +* UNMANAGED domain makes it BLOCKING. +*/ +if (domain == platform_domain || !domain || + domain->type !=IOMMU_DOMAIN_UNMANAGED ) +return 0 ; + + dma_domain =to_fsl_dma_domain (domain); +/* * Use LIODN of the PCI controller while detaching a * PCI device.
@@ -312,8 +337,18 @@ static void fsl_pamu_set_platform_dma(struct device *dev)detach_device (dev, dma_domain); else pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node); +return 0 ; } +static struct iommu_domain_ops fsl_pamu_platform_ops = { + .attach_dev = fsl_pamu_platform_attach, +}; + +static struct iommu_domain fsl_pamu_platform_domain = { + .type =IOMMU_DOMAIN_PLATFORM , + .ops = &fsl_pamu_platform_ops, +}; +/* Set the domain stash attribute */ int fsl_pamu_configure_l1_stash (struct iommu_domain *domain,u32 cpu) {
@@ -395,11 +430,11 @@ static struct iommu_device *fsl_pamu_probe_device(struct device *dev) }static const struct iommu_ops fsl_pamu_ops = { + .default_domain = &fsl_pamu_platform_domain, .capable = fsl_pamu_capable, .domain_alloc = fsl_pamu_domain_alloc, .probe_device = fsl_pamu_probe_device, .device_group = fsl_pamu_device_group, - .set_platform_dma_ops = fsl_pamu_set_platform_dma, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = fsl_pamu_attach_device, .iova_to_phys = fsl_pamu_iova_to_phys,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 6/24 iommu/tegra-gart: Remove tegra-gart
In reply to Jason GunthorpeThierry says this is not used anymore, and doesn't think it makes sense as an iommu driver. The HW it supports is about 10 years old now and newer HW uses different IOMMU drivers.
As this is the only driver with a GART approach, and it doesn't really meet the driver expectations from the IOMMU core, let's just remove it so we don't have to think about how to make it fit in.
It has a number of identified problems:
- The assignment of iommu_groups doesn't match the HW behavior
- It claims to have an UNMANAGED domain but it is really an IDENTITY domain with a translation aperture. This is inconsistent with the core expectation for security sensitive operations
- It doesn't implement a SW page table under struct iommu_domain so
* It can't accept a map until the domain is attached
* It forgets about all maps after the domain is detached
* It doesn't clear the HW of maps once the domain is detached (made worse by having the wrong groups)
--- arch/arm/configs/multi_v7_defconfig | 1 - arch/arm/configs/tegra_defconfig | 1 - drivers/iommu/Kconfig | 11 - drivers/iommu/Makefile | 1 - drivers/iommu/tegra-gart.c | 371 ---------------------------- drivers/memory/tegra/mc.c | 34 --- drivers/memory/tegra/tegra20.c | 28 --- include/soc/tegra/mc.h | 26 -- 8 files changed, 473 deletions(-) delete mode 100644 drivers/iommu/tegra-gart.c
arch/arm/configs/multi_v7_defconfig +0 -1
@@ -1073,7 +1073,6 @@ CONFIG_QCOM_IPCC=y CONFIG_OMAP_IOMMU=y CONFIG_OMAP_IOMMU_DEBUG=y CONFIG_ROCKCHIP_IOMMU=y -CONFIG_TEGRA_IOMMU_GART=y CONFIG_TEGRA_IOMMU_SMMU=y CONFIG_EXYNOS_IOMMU=y CONFIG_QCOM_IOMMU=y
arch/arm/configs/tegra_defconfig +0 -1
@@ -292,7 +292,6 @@ CONFIG_CHROME_PLATFORMS=y CONFIG_CROS_EC=y CONFIG_CROS_EC_I2C=m CONFIG_CROS_EC_SPI=m -CONFIG_TEGRA_IOMMU_GART=y CONFIG_TEGRA_IOMMU_SMMU=y CONFIG_ARCH_TEGRA_2x_SOC=y CONFIG_ARCH_TEGRA_3x_SOC=y
drivers/iommu/Kconfig +0 -11
@@ -236,17 +236,6 @@ config SUN50I_IOMMU help Support for the IOMMU introduced in the Allwinner H6 SoCs. -config TEGRA_IOMMU_GART - bool "Tegra GART IOMMU Support" - depends on ARCH_TEGRA_2x_SOC - depends on TEGRA_MC - select IOMMU_API - help - Enables support for remapping discontiguous physical memory - shared with the operating system into contiguous I/O virtual - space through the GART (Graphics Address Relocation Table) - hardware included on Tegra SoCs. - config TEGRA_IOMMU_SMMU bool "NVIDIA Tegra SMMU Support" depends on ARCH_TEGRA
drivers/iommu/Makefile +0 -1
@@ -20,7 +20,6 @@ obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o obj-$(CONFIG_ROCKCHIP_IOMMU) += rockchip-iommu.o obj-$(CONFIG_SUN50I_IOMMU) += sun50i-iommu.o -obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o obj-$(CONFIG_FSL_PAMU) += fsl_pamu.o fsl_pamu_domain.o
drivers/iommu/tegra-gart.c deleted +0 -371
371 lines not on this page · raw message
drivers/memory/tegra/mc.c +0 -34
@@ -979,35 +979,6 @@ static int tegra_mc_probe(struct platform_device *pdev) } } -if (IS_ENABLED (CONFIG_TEGRA_IOMMU_GART ) && !mc->soc->smmu) { - mc->gart =tegra_gart_probe (&pdev->dev, mc); -if (IS_ERR (mc->gart)) { -dev_err (&pdev->dev,"failed to probe GART: %ld\n" , -PTR_ERR (mc->gart)); - mc->gart =NULL ; - } - } - -return 0 ; -} - -static int __maybe_unused tegra_mc_suspend (struct device *dev) -{ -struct tegra_mc *mc =dev_get_drvdata (dev); - -if (mc->soc->ops && mc->soc->ops->suspend) -return mc->soc->ops->suspend (mc); - -return 0 ; -} - -static int __maybe_unused tegra_mc_resume (struct device *dev) -{ -struct tegra_mc *mc =dev_get_drvdata (dev); - -if (mc->soc->ops && mc->soc->ops->resume) -return mc->soc->ops->resume (mc); -return 0 ; }
@@ -1020,15 +991,10 @@ static void tegra_mc_sync_state(struct device *dev)icc_sync_state (dev); } -static const struct dev_pm_ops tegra_mc_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (tegra_mc_suspend, tegra_mc_resume) -}; -static struct platform_driver tegra_mc_driver = { .driver = { .name ="tegra-mc" , .of_match_table = tegra_mc_of_match, - .pm = &tegra_mc_pm_ops, .suppress_bind_attrs = true, .sync_state = tegra_mc_sync_state, },
drivers/memory/tegra/tegra20.c +0 -28
@@ -688,32 +688,6 @@ static int tegra20_mc_probe(struct tegra_mc *mc)return 0 ; } -static int tegra20_mc_suspend (struct tegra_mc *mc) -{ -int err; - -if (IS_ENABLED (CONFIG_TEGRA_IOMMU_GART ) && mc->gart) { - err =tegra_gart_suspend (mc->gart); -if (err <0 ) -return err; - } - -return 0 ; -} - -static int tegra20_mc_resume (struct tegra_mc *mc) -{ -int err; - -if (IS_ENABLED (CONFIG_TEGRA_IOMMU_GART ) && mc->gart) { - err =tegra_gart_resume (mc->gart); -if (err <0 ) -return err; - } - -return 0 ; -} -static irqreturn_t tegra20_mc_handle_irq (int irq,void *data) {struct tegra_mc *mc = data;
@@ -789,8 +763,6 @@ static irqreturn_t tegra20_mc_handle_irq(int irq, void *data)static const struct tegra_mc_ops tegra20_mc_ops = { .probe = tegra20_mc_probe, - .suspend = tegra20_mc_suspend, - .resume = tegra20_mc_resume, .handle_irq = tegra20_mc_handle_irq, };
include/soc/tegra/mc.h +0 -26
@@ -96,7 +96,6 @@ struct tegra_smmu_soc {struct tegra_mc ;struct tegra_smmu ; -struct gart_device ;#ifdef CONFIG_TEGRA_IOMMU_SMMU struct tegra_smmu *tegra_smmu_probe(struct device *dev,
@@ -116,28 +115,6 @@ static inline void tegra_smmu_remove(struct tegra_smmu *smmu) }#endif -#ifdef CONFIG_TEGRA_IOMMU_GART -struct gart_device *tegra_gart_probe (struct device *dev,struct tegra_mc *mc); -int tegra_gart_suspend (struct gart_device *gart); -int tegra_gart_resume (struct gart_device *gart); -#else -static inline struct gart_device * -tegra_gart_probe (struct device *dev,struct tegra_mc *mc) -{ -return ERR_PTR (-ENODEV ); -} - -static inline int tegra_gart_suspend (struct gart_device *gart) -{ -return -ENODEV ; -} - -static inline int tegra_gart_resume (struct gart_device *gart) -{ -return -ENODEV ; -} -#endif -struct tegra_mc_reset {const char *name;unsigned long id;
@@ -185,8 +162,6 @@ struct tegra_mc_ops {*/ int (*probe)(struct tegra_mc *mc);void (*remove)(struct tegra_mc *mc); -int (*suspend)(struct tegra_mc *mc); -int (*resume)(struct tegra_mc *mc);irqreturn_t (*handle_irq)(int irq,void *data);int (*probe_device)(struct tegra_mc *mc,struct device *dev); };
@@ -225,7 +200,6 @@ struct tegra_mc {struct tegra_bpmp *bpmp;struct device *dev;struct tegra_smmu *smmu; -struct gart_device *gart;void __iomem *regs;void __iomem *bcast_ch_regs;void __iomem **ch_regs;
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 7/24 iommu/mtk_iommu_v1: Implement an IDENTITY domain
In reply to Jason GunthorpeWhat mtk does during mtk_iommu_v1_set_platform_dma() is actually putting the iommu into identity mode. Make this available as a proper IDENTITY domain.
The mtk_iommu_v1_def_domain_type() from
commit 8bbe13f52cb7 ("iommu/mediatek-v1: Add def_domain_type") explains this was needed to allow probe_finalize() to be called, but now the IDENTITY domain will do the same job so change the returned def_domain_type.
mkt_v1 is the only driver that returns IOMMU_DOMAIN_UNMANAGED from def_domain_type(). This allows the next patch to enforce an IDENTITY domain policy for this driver.
--- drivers/iommu/mtk_iommu_v1.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iommu/mtk_iommu_v1.c +19 -2
@@ -319,11 +319,27 @@ static int mtk_iommu_v1_attach_device(struct iommu_domain *domain, struct devicereturn 0 ; } -static void mtk_iommu_v1_set_platform_dma (struct device *dev) +static int mtk_iommu_v1_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) {struct mtk_iommu_v1_data *data =dev_iommu_priv_get (dev);mtk_iommu_v1_config (data, dev, false); +return 0 ; +} + +static struct iommu_domain_ops mtk_iommu_v1_identity_ops = { + .attach_dev = mtk_iommu_v1_identity_attach, +}; + +static struct iommu_domain mtk_iommu_v1_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &mtk_iommu_v1_identity_ops, +}; + +static void mtk_iommu_v1_set_platform_dma (struct device *dev) +{ +mtk_iommu_v1_identity_attach (&mtk_iommu_v1_identity_domain, dev); } static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova,
@@ -443,7 +459,7 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_argstatic int mtk_iommu_v1_def_domain_type (struct device *dev) { -return IOMMU_DOMAIN_UNMANAGED ; +return IOMMU_DOMAIN_IDENTITY ; }static struct iommu_device *mtk_iommu_v1_probe_device (struct device *dev)
@@ -578,6 +594,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data) }static const struct iommu_ops mtk_iommu_v1_ops = { + .identity_domain = &mtk_iommu_v1_identity_domain, .domain_alloc = mtk_iommu_v1_domain_alloc, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 8/24 iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()
In reply to Jason GunthorpeExcept for dart (which forces IOMMU_DOMAIN_DMA) every driver returns 0 or IDENTITY from ops->def_domain_type().
The drivers that return IDENTITY have some kind of good reason, typically that quirky hardware really can't support anything other than IDENTITY.
Arrange things so that if the driver says it needs IDENTITY then iommu_get_default_domain_type() either fails or returns IDENTITY. It will not ignore the driver's override to IDENTITY.
Split the function into two steps, reducing the group device list to the driver's def_domain_type() and the untrusted flag.
Then compute the result based on those two reduced variables. Fully reject combining untrusted with IDENTITY.
Remove the debugging print on the iommu_group_store_type() failure path, userspace should not be able to trigger kernel prints.
This makes the next patch cleaner that wants to force IDENTITY always for ARM_IOMMU because there is no support for DMA.
--- drivers/iommu/iommu.c | 117 ++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 38 deletions(-)
drivers/iommu/iommu.c +79 -38
@@ -1718,19 +1718,6 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) }EXPORT_SYMBOL_GPL (fsl_mc_device_group); -static int iommu_get_def_domain_type (struct device *dev) -{ -const struct iommu_ops *ops =dev_iommu_ops (dev); - -if (dev_is_pci (dev) &&to_pci_dev (dev)->untrusted) -return IOMMU_DOMAIN_DMA ; - -if (ops->def_domain_type) -return ops->def_domain_type (dev); - -return 0 ; -} -static struct iommu_domain *__iommu_group_alloc_default_domain (const struct bus_type *bus,struct iommu_group *group,int req_type)
@@ -1740,6 +1727,23 @@ __iommu_group_alloc_default_domain(const struct bus_type *bus,return __iommu_domain_alloc (bus, req_type); } +/* +* Returns the iommu_ops for the devices in an iommu group. +* +* It is assumed that all devices in an iommu group are managed by a single +* IOMMU unit. Therefore, this returns the dev_iommu_ops of the first device +* in the group. +*/ +static const struct iommu_ops *group_iommu_ops (struct iommu_group *group) +{ +struct group_device *device = + list_first_entry(&group->devices, struct group_device, list); + +lockdep_assert_held (&group->mutex); + +return dev_iommu_ops (device->dev); +} +/* * req_type of 0 means "auto" which means to select a domain based on * iommu_def_domain_type or what the driver actually supports.
@@ -1820,40 +1824,77 @@ static int iommu_bus_notifier(struct notifier_block *nb,return 0 ; } -/* A target_type of 0 will select the best domain type and cannot fail */ +/* +* Combine the driver's chosen def_domain_type across all the devices in a +* group. Drivers must give a consistent result. +*/ +static int iommu_get_def_domain_type (struct iommu_group *group, +struct device *dev,int cur_type) +{ +const struct iommu_ops *ops =group_iommu_ops (group); +int type; + +if (!ops->def_domain_type) +return cur_type; + + type = ops->def_domain_type (dev); +if (!type || cur_type == type) +return cur_type; +if (!cur_type) +return type; + +dev_err_ratelimited ( + dev, +"IOMMU driver error, requesting conflicting def_domain_type, %s and %s, for devices in group %u.\n" , +iommu_domain_type_str (cur_type),iommu_domain_type_str (type), + group->id); + +/* +* Try to recover, drivers are allowed to force IDENITY or DMA, IDENTITY +* takes precedence. +*/ +if (type ==IOMMU_DOMAIN_IDENTITY ) +return type; +return cur_type; +} + +/* +* A target_type of 0 will select the best domain type. 0 can be returned in +* this case meaning the global default should be used. +*/ static int iommu_get_default_domain_type (struct iommu_group *group,int target_type) { -int best_type = target_type; +struct device *untrusted =NULL ;struct group_device *gdev; -struct device *last_dev; +int driver_type =0 ;lockdep_assert_held (&group->mutex); -for_each_group_device (group, gdev) { -unsigned int type =iommu_get_def_domain_type (gdev->dev); + driver_type =iommu_get_def_domain_type (group, gdev->dev, + driver_type); -if (best_type && type && best_type != type) { -if (target_type) { -dev_err_ratelimited ( - gdev->dev, -"Device cannot be in %s domain\n" , -iommu_domain_type_str (target_type)); -return -1 ; - } - -dev_warn ( - gdev->dev, -"Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n" , -iommu_domain_type_str (type),dev_name (last_dev), -iommu_domain_type_str (best_type)); -return 0 ; - } -if (!best_type) - best_type = type; - last_dev = gdev->dev; +if (dev_is_pci (gdev->dev) &&to_pci_dev (gdev->dev)->untrusted) + untrusted = gdev->dev; } -return best_type; + +if (untrusted) { +if (driver_type && driver_type !=IOMMU_DOMAIN_DMA ) { +dev_err_ratelimited ( + untrusted, +"Device is not trusted, but driver is overriding group %u to %s, refusing to probe.\n" , + group->id,iommu_domain_type_str (driver_type)); +return -1 ; + } + driver_type =IOMMU_DOMAIN_DMA ; + } + +if (target_type) { +if (driver_type && target_type != driver_type) +return -1 ; +return target_type; + } +return driver_type; }static void iommu_group_do_probe_finalize (struct device *dev)
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 9/24 iommu: Allow an IDENTITY domain as the default_domain in ARM32
In reply to Jason GunthorpeEven though dma-iommu.c and CONFIG_ARM_DMA_USE_IOMMU do approximately the same stuff, the way they relate to the IOMMU core is quiet different.
dma-iommu.c expects the core code to setup an UNMANAGED domain (of type IOMMU_DOMAIN_DMA) and then configures itself to use that domain. This becomes the default_domain for the group.
ARM_DMA_USE_IOMMU does not use the default_domain, instead it directly allocates an UNMANAGED domain and operates it just like an external driver. In this case group->default_domain is NULL.
If the driver provides a global static identity_domain then automatically use it as the default_domain when in ARM_DMA_USE_IOMMU mode.
This allows drivers that implemented default_domain == NULL as an IDENTITY translation to trivially get a properly labeled non-NULL default_domain on ARM32 configs.
With this arrangment when ARM_DMA_USE_IOMMU wants to disconnect from the device the normal detach_domain flow will restore the IDENTITY domain as the default domain. Overall this makes attach_dev() of the IDENTITY domain called in the same places as detach_dev().
This effectively migrates these drivers to default_domain mode. For drivers that support ARM64 they will gain support for the IDENTITY translation mode for the dma_api and behave in a uniform way.
Drivers use this by setting ops->identity_domain to a static singleton iommu_domain that implements the identity attach. If the core detects ARM_DMA_USE_IOMMU mode then it automatically attaches the IDENTITY domain during probe.
Drivers can continue to prevent the use of DMA translation by returning IOMMU_DOMAIN_IDENTITY from def_domain_type, this will completely prevent IOMMU_DMA from running but will not impact ARM_DMA_USE_IOMMU.
This allows removing the set_platform_dma_ops() from every remaining driver.
Remove the set_platform_dma_ops from rockchip and mkt_v1 as all it does is set an existing global static identity domain. mkt_v1 does not support IOMMU_DOMAIN_DMA and it does not compile on ARM64 so this transformation is safe.
--- drivers/iommu/iommu.c | 21 ++++++++++++++++++++- drivers/iommu/mtk_iommu_v1.c | 12 ------------ drivers/iommu/rockchip-iommu.c | 10 ---------- 3 files changed, 20 insertions(+), 23 deletions(-)
drivers/iommu/iommu.c +20 -1
@@ -1865,17 +1865,36 @@ static int iommu_get_def_domain_type(struct iommu_group *group,static int iommu_get_default_domain_type (struct iommu_group *group,int target_type) { +const struct iommu_ops *ops =group_iommu_ops (group);struct device *untrusted =NULL ;struct group_device *gdev;int driver_type =0 ;lockdep_assert_held (&group->mutex); + +/* +* ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an +* identity_domain and it will automatically become their default +* domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. +* Override the selection to IDENTITY if we are sure the driver supports +* it. +*/ +if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) && ops->identity_domain) + driver_type =IOMMU_DOMAIN_IDENTITY ; +for_each_group_device (group, gdev) { driver_type =iommu_get_def_domain_type (group, gdev->dev, driver_type); -if (dev_is_pci (gdev->dev) &&to_pci_dev (gdev->dev)->untrusted) +if (dev_is_pci (gdev->dev) &&to_pci_dev (gdev->dev)->untrusted) { +/* +* No ARM32 using systems will set untrusted, it cannot +* work. +*/ +if (WARN_ON (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ))) +return -1 ; untrusted = gdev->dev; + } }if (untrusted) {
drivers/iommu/mtk_iommu_v1.c +0 -12
@@ -337,11 +337,6 @@ static struct iommu_domain mtk_iommu_v1_identity_domain = { .ops = &mtk_iommu_v1_identity_ops, }; -static void mtk_iommu_v1_set_platform_dma (struct device *dev) -{ -mtk_iommu_v1_identity_attach (&mtk_iommu_v1_identity_domain, dev); -} -static int mtk_iommu_v1_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -457,11 +452,6 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_argreturn 0 ; } -static int mtk_iommu_v1_def_domain_type (struct device *dev) -{ -return IOMMU_DOMAIN_IDENTITY ; -} -static struct iommu_device *mtk_iommu_v1_probe_device (struct device *dev) {struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev);
@@ -599,10 +589,8 @@ static const struct iommu_ops mtk_iommu_v1_ops = { .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, .release_device = mtk_iommu_v1_release_device, - .def_domain_type = mtk_iommu_v1_def_domain_type, .device_group = generic_device_group, .pgsize_bitmap = MT2701_IOMMU_PAGE_SIZE, - .set_platform_dma_ops = mtk_iommu_v1_set_platform_dma, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = mtk_iommu_v1_attach_device,
drivers/iommu/rockchip-iommu.c +0 -10
@@ -998,13 +998,6 @@ static struct iommu_domain rk_identity_domain = { .ops = &rk_identity_ops, }; -#ifdef CONFIG_ARM -static void rk_iommu_set_platform_dma (struct device *dev) -{ -WARN_ON (rk_iommu_identity_attach (&rk_identity_domain, dev)); -} -#endif -static int rk_iommu_attach_device (struct iommu_domain *domain,struct device *dev) {
@@ -1183,9 +1176,6 @@ static const struct iommu_ops rk_iommu_ops = { .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, .device_group = rk_iommu_device_group, -#ifdef CONFIG_ARM - .set_platform_dma_ops = rk_iommu_set_platform_dma, -#endif .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, .of_xlate = rk_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 10/24 iommu/exynos: Implement an IDENTITY domain
In reply to Jason GunthorpeWhat exynos calls exynos_iommu_detach_device is actually putting the iommu into identity mode.
Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain.
--- drivers/iommu/exynos-iommu.c | 66 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-)
drivers/iommu/exynos-iommu.c +32 -34
@@ -24,6 +24,7 @@typedef u32 sysmmu_iova_t ;typedef u32 sysmmu_pte_t ; +static struct iommu_domain exynos_identity_domain;/* We do not consider super section mapping (16MB) */ #define SECT_ORDER 20
@@ -829,7 +830,7 @@ static int __maybe_unused exynos_sysmmu_suspend(struct device *dev)struct exynos_iommu_owner *owner =dev_iommu_priv_get (master);mutex_lock (&owner->rpm_lock); -if (data->domain) { +if (&data->domain->domain != &exynos_identity_domain) {dev_dbg (data->sysmmu,"saving state\n" );__sysmmu_disable (data); }
@@ -847,7 +848,7 @@ static int __maybe_unused exynos_sysmmu_resume(struct device *dev)struct exynos_iommu_owner *owner =dev_iommu_priv_get (master);mutex_lock (&owner->rpm_lock); -if (data->domain) { +if (&data->domain->domain != &exynos_identity_domain) {dev_dbg (data->sysmmu,"restoring state\n" );__sysmmu_enable (data); }
@@ -980,17 +981,20 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain)kfree (domain); } -static void exynos_iommu_detach_device (struct iommu_domain *iommu_domain, -struct device *dev) +static int exynos_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) { -struct exynos_iommu_domain *domain =to_exynos_domain (iommu_domain);struct exynos_iommu_owner *owner =dev_iommu_priv_get (dev); -phys_addr_t pagetable =virt_to_phys (domain->pgtable); +struct exynos_iommu_domain *domain; +phys_addr_t pagetable;struct sysmmu_drvdata *data, *next;unsigned long flags; -if (!has_sysmmu (dev) || owner->domain != iommu_domain) -return ; +if (owner->domain == identity_domain) +return 0 ; + + domain =to_exynos_domain (owner->domain); + pagetable =virt_to_phys (domain->pgtable);mutex_lock (&owner->rpm_lock);
@@ -1009,15 +1013,25 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,list_del_init (&data->domain_node);spin_unlock (&data->lock); } - owner->domain =NULL ; + owner->domain = identity_domain;spin_unlock_irqrestore (&domain->lock, flags);mutex_unlock (&owner->rpm_lock); -dev_dbg (dev,"%s: Detached IOMMU with pgtable %pa\n" , __func__, - &pagetable); +dev_dbg (dev,"%s: Restored IOMMU to IDENTITY from pgtable %pa\n" , + __func__, &pagetable); +return 0 ; } +static struct iommu_domain_ops exynos_identity_ops = { + .attach_dev = exynos_iommu_identity_attach, +}; + +static struct iommu_domain exynos_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &exynos_identity_ops, +}; +static int exynos_iommu_attach_device (struct iommu_domain *iommu_domain,struct device *dev) {
@@ -1026,12 +1040,11 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,struct sysmmu_drvdata *data;phys_addr_t pagetable =virt_to_phys (domain->pgtable);unsigned long flags; +int err; -if (!has_sysmmu (dev)) -return -ENODEV ; - -if (owner->domain) -exynos_iommu_detach_device (owner->domain, dev); + err =exynos_iommu_identity_attach (&exynos_identity_domain, dev); +if (err) +return err;mutex_lock (&owner->rpm_lock);
@@ -1407,26 +1420,12 @@ static struct iommu_device *exynos_iommu_probe_device(struct device *dev)return &data->iommu; } -static void exynos_iommu_set_platform_dma (struct device *dev) -{ -struct exynos_iommu_owner *owner =dev_iommu_priv_get (dev); - -if (owner->domain) { -struct iommu_group *group =iommu_group_get (dev); - -if (group) { -exynos_iommu_detach_device (owner->domain, dev); -iommu_group_put (group); - } - } -} -static void exynos_iommu_release_device (struct device *dev) {struct exynos_iommu_owner *owner =dev_iommu_priv_get (dev);struct sysmmu_drvdata *data; -exynos_iommu_set_platform_dma (dev); +WARN_ON (exynos_iommu_identity_attach (&exynos_identity_domain, dev));list_for_each_entry (data, &owner->controllers, owner_node)device_link_del (data->link);
@@ -1457,6 +1456,7 @@ static int exynos_iommu_of_xlate(struct device *dev,INIT_LIST_HEAD (&owner->controllers);mutex_init (&owner->rpm_lock); + owner->domain = &exynos_identity_domain;dev_iommu_priv_set (dev, owner); }
@@ -1471,11 +1471,9 @@ static int exynos_iommu_of_xlate(struct device *dev, }static const struct iommu_ops exynos_iommu_ops = { + .identity_domain = &exynos_identity_domain, .domain_alloc = exynos_iommu_domain_alloc, .device_group = generic_device_group, -#ifdef CONFIG_ARM - .set_platform_dma_ops = exynos_iommu_set_platform_dma, -#endif .probe_device = exynos_iommu_probe_device, .release_device = exynos_iommu_release_device, .pgsize_bitmap =SECT_SIZE |LPAGE_SIZE |SPAGE_SIZE ,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 11/24 iommu/tegra-smmu: Implement an IDENTITY domain
In reply to Jason GunthorpeWhat tegra-smmu does during tegra_smmu_set_platform_dma() is actually putting the iommu into identity mode.
Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain.
--- drivers/iommu/tegra-smmu.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)
drivers/iommu/tegra-smmu.c +32 -5
@@ -511,23 +511,39 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain,return err; } -static void tegra_smmu_set_platform_dma (struct device *dev) +static int tegra_smmu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) {struct iommu_domain *domain =iommu_get_domain_for_dev (dev);struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev); -struct tegra_smmu_as *as =to_smmu_as (domain); -struct tegra_smmu *smmu = as->smmu; +struct tegra_smmu_as *as; +struct tegra_smmu *smmu;unsigned int index;if (!fwspec) -return ; +return -ENODEV ; +if (domain == identity_domain || !domain) +return 0 ; + + as =to_smmu_as (domain); + smmu = as->smmu;for (index =0 ; index < fwspec->num_ids; index++) {tegra_smmu_disable (smmu, fwspec->ids[index], as->id);tegra_smmu_as_unprepare (smmu, as); } +return 0 ; } +static struct iommu_domain_ops tegra_smmu_identity_ops = { + .attach_dev = tegra_smmu_identity_attach, +}; + +static struct iommu_domain tegra_smmu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &tegra_smmu_identity_ops, +}; +static void tegra_smmu_set_pde (struct tegra_smmu_as *as,unsigned long iova,u32 value) {
@@ -962,11 +978,22 @@ static int tegra_smmu_of_xlate(struct device *dev,return iommu_fwspec_add_ids (dev, &id,1 ); } +static int tegra_smmu_def_domain_type (struct device *dev) +{ +/* +* FIXME: For now we want to run all translation in IDENTITY mode, due +* to some device quirks. Better would be to just quirk the troubled +* devices. +*/ +return IOMMU_DOMAIN_IDENTITY ; +} +static const struct iommu_ops tegra_smmu_ops = { + .identity_domain = &tegra_smmu_identity_domain, + .def_domain_type = &tegra_smmu_def_domain_type, .domain_alloc = tegra_smmu_domain_alloc, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, - .set_platform_dma_ops = tegra_smmu_set_platform_dma, .of_xlate = tegra_smmu_of_xlate, .pgsize_bitmap =SZ_4K , .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 12/24 iommu/tegra-smmu: Support DMA domains in tegra
In reply to Jason GunthorpeAll ARM64 iommu drivers should support IOMMU_DOMAIN_DMA to enable dma-iommu.c.
tegra is blocking dma-iommu usage, and also default_domain's, because it wants an identity translation. This is needed for some device quirk. The correct way to do this is to support IDENTITY domains and use ops->def_domain_type() to return IOMMU_DOMAIN_IDENTITY for only the quirky devices.
Add support for IOMMU_DOMAIN_DMA and force IOMMU_DOMAIN_IDENTITY mode for everything so no behavior changes.
--- drivers/iommu/tegra-smmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/tegra-smmu.c +1 -1
@@ -276,7 +276,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) {struct tegra_smmu_as *as; -if (type !=IOMMU_DOMAIN_UNMANAGED ) +if (type !=IOMMU_DOMAIN_UNMANAGED && type !=IOMMU_DOMAIN_DMA )return NULL ; as =kzalloc (sizeof (*as),GFP_KERNEL );
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 13/24 iommu/omap: Implement an IDENTITY domain
In reply to Jason GunthorpeWhat omap does during omap_iommu_set_platform_dma() is actually putting the iommu into identity mode.
Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain.
This driver does not support IOMMU_DOMAIN_DMA, however it cannot be compiled on ARM64 either. Most likely it is fine to support dma-iommu.c
--- drivers/iommu/omap-iommu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/iommu/omap-iommu.c +18 -3
@@ -1555,16 +1555,31 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain, omap_domain->dev =NULL ; } -static void omap_iommu_set_platform_dma (struct device *dev) +static int omap_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) {struct iommu_domain *domain =iommu_get_domain_for_dev (dev); -struct omap_iommu_domain *omap_domain =to_omap_domain (domain); +struct omap_iommu_domain *omap_domain; +if (domain == identity_domain || !domain) +return 0 ; + + omap_domain =to_omap_domain (domain);spin_lock (&omap_domain->lock);_omap_iommu_detach_dev (omap_domain, dev);spin_unlock (&omap_domain->lock); +return 0 ; } +static struct iommu_domain_ops omap_iommu_identity_ops = { + .attach_dev = omap_iommu_identity_attach, +}; + +static struct iommu_domain omap_iommu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &omap_iommu_identity_ops, +}; +static struct iommu_domain *omap_iommu_domain_alloc (unsigned type) {struct omap_iommu_domain *omap_domain;
@@ -1732,11 +1747,11 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev) }static const struct iommu_ops omap_iommu_ops = { + .identity_domain = &omap_iommu_identity_domain, .domain_alloc = omap_iommu_domain_alloc, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, - .set_platform_dma_ops = omap_iommu_set_platform_dma, .pgsize_bitmap =OMAP_IOMMU_PGSIZES , .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = omap_iommu_attach_dev,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 14/24 iommu/msm: Implement an IDENTITY domain
In reply to Jason GunthorpeWhat msm does during msm_iommu_set_platform_dma() is actually putting the iommu into identity mode.
Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain.
This driver does not support IOMMU_DOMAIN_DMA, however it cannot be compiled on ARM64 either. Most likely it is fine to support dma-iommu.c
--- drivers/iommu/msm_iommu.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/iommu/msm_iommu.c +19 -4
@@ -443,15 +443,20 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)return ret; } -static void msm_iommu_set_platform_dma (struct device *dev) +static int msm_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) {struct iommu_domain *domain =iommu_get_domain_for_dev (dev); -struct msm_priv *priv =to_msm_priv (domain); +struct msm_priv *priv;unsigned long flags;struct msm_iommu_dev *iommu;struct msm_iommu_ctx_dev *master; -int ret; +int ret =0 ; +if (domain == identity_domain || !domain) +return 0 ; + + priv =to_msm_priv (domain);free_io_pgtable_ops (priv->iop);spin_lock_irqsave (&msm_iommu_lock, flags);
@@ -468,8 +473,18 @@ static void msm_iommu_set_platform_dma(struct device *dev) } fail:spin_unlock_irqrestore (&msm_iommu_lock, flags); +return ret; } +static struct iommu_domain_ops msm_iommu_identity_ops = { + .attach_dev = msm_iommu_identity_attach, +}; + +static struct iommu_domain msm_iommu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &msm_iommu_identity_ops, +}; +static int msm_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t pa,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -675,10 +690,10 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id) }static struct iommu_ops msm_iommu_ops = { + .identity_domain = &msm_iommu_identity_domain, .domain_alloc = msm_iommu_domain_alloc, .probe_device = msm_iommu_probe_device, .device_group = generic_device_group, - .set_platform_dma_ops = msm_iommu_set_platform_dma, .pgsize_bitmap =MSM_IOMMU_PGSIZES , .of_xlate = qcom_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 15/24 iommu: Remove ops->set_platform_dma_ops()
In reply to Jason GunthorpeAll drivers are now using IDENTITY or PLATFORM domains for what this did, we can remove it now. It is no longer possible to attach to a NULL domain.
--- drivers/iommu/iommu.c | 30 +++++------------------------- include/linux/iommu.h | 4 ---- 2 files changed, 5 insertions(+), 29 deletions(-)
drivers/iommu/iommu.c +5 -25
@@ -2351,21 +2351,8 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group,if (group->domain == new_domain)return 0 ; -/* -* New drivers should support default domains, so set_platform_dma() -* op will never be called. Otherwise the NULL domain represents some -* platform specific behavior. -*/ -if (!new_domain) { -for_each_group_device (group, gdev) { -const struct iommu_ops *ops =dev_iommu_ops (gdev->dev); - -if (!WARN_ON (!ops->set_platform_dma_ops)) - ops->set_platform_dma_ops (gdev->dev); - } - group->domain =NULL ; -return 0 ; - } +if (WARN_ON (!new_domain)) +return -EINVAL ;/* * Changing the domain is done by calling attach_dev() on the new
@@ -2401,19 +2388,15 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group,*/ last_gdev = gdev;for_each_group_device (group, gdev) { -const struct iommu_ops *ops =dev_iommu_ops (gdev->dev); -/* -* If set_platform_dma_ops is not present a NULL domain can -* happen only for first probe, in which case we leave -* group->domain as NULL and let release clean everything up. +* A NULL domain can happen only for first probe, in which case +* we leave group->domain as NULL and let release clean +* everything up. */ if (group->domain)WARN_ON (__iommu_device_set_domain ( group, gdev->dev, group->domain,IOMMU_SET_DOMAIN_MUST_SUCCEED )); -else if (ops->set_platform_dma_ops) - ops->set_platform_dma_ops (gdev->dev);if (gdev == last_gdev)break ; }
@@ -3036,9 +3019,6 @@ static int iommu_setup_default_domain(struct iommu_group *group,/* * There are still some drivers which don't support default domains, so * we ignore the failure and leave group->default_domain NULL. -* -* We assume that the iommu driver starts up the device in -* 'set_platform_dma_ops' mode if it does not support default domains. */ dom =iommu_group_alloc_default_domain (group, req_type);if (!dom) {
include/linux/iommu.h +0 -4
@@ -243,9 +243,6 @@ struct iommu_iotlb_gather {* @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU * group and attached to the groups domain -* @set_platform_dma_ops: Returning control back to the platform DMA ops. This op -* is to support old IOMMU drivers, new drivers should use -* default domains, and the common IOMMU DMA ops. * @device_group: find iommu group for a particular device * @get_resv_regions: Request list of reserved regions for a device * @of_xlate: add OF master IDs to iommu grouping
@@ -280,7 +277,6 @@ struct iommu_ops {struct iommu_device *(*probe_device)(struct device *dev);void (*release_device)(struct device *dev);void (*probe_finalize)(struct device *dev); -void (*set_platform_dma_ops)(struct device *dev);struct iommu_group *(*device_group)(struct device *dev);/* Request/Free a list of reserved regions for a device */
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 16/24 iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN
In reply to Jason GunthorpeThis brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain.
--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +39 -0
@@ -400,6 +400,44 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *devreturn 0 ; } +static int qcom_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); +struct qcom_iommu_domain *qcom_domain; +struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev); +struct qcom_iommu_dev *qcom_iommu =to_iommu (dev); +unsigned int i; + +if (domain == identity_domain || !domain) +return 0 ; + + qcom_domain =to_qcom_iommu_domain (domain); +if (WARN_ON (!qcom_domain->iommu)) +return -EINVAL ; + +pm_runtime_get_sync (qcom_iommu->dev); +for (i =0 ; i < fwspec->num_ids; i++) { +struct qcom_iommu_ctx *ctx =to_ctx (qcom_domain, fwspec->ids[i]); + +/* Disable the context bank: */ +iommu_writel (ctx,ARM_SMMU_CB_SCTLR ,0 ); + + ctx->domain =NULL ; + } +pm_runtime_put_sync (qcom_iommu->dev); +return 0 ; +} + +static struct iommu_domain_ops qcom_iommu_identity_ops = { + .attach_dev = qcom_iommu_identity_attach, +}; + +static struct iommu_domain qcom_iommu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &qcom_iommu_identity_ops, +}; +static int qcom_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -565,6 +603,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) }static const struct iommu_ops qcom_iommu_ops = { + .identity_domain = &qcom_iommu_identity_domain, .capable = qcom_iommu_capable, .domain_alloc = qcom_iommu_domain_alloc, .probe_device = qcom_iommu_probe_device,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 17/24 iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN
In reply to Jason GunthorpeThis brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain.
Also reverts commit 584d334b1393 ("iommu/ipmmu-vmsa: Remove ipmmu_utlb_disable()")
--- drivers/iommu/ipmmu-vmsa.c | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
drivers/iommu/ipmmu-vmsa.c +43 -0
@@ -295,6 +295,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, mmu->utlb_ctx[utlb] = domain->context_id; } +/* +* Disable MMU translation for the microTLB. +*/ +static void ipmmu_utlb_disable (struct ipmmu_vmsa_domain *domain, +unsigned int utlb) +{ +struct ipmmu_vmsa_device *mmu = domain->mmu; + +ipmmu_imuctr_write (mmu, utlb,0 ); + mmu->utlb_ctx[utlb] =IPMMU_CTX_INVALID ; +} +static void ipmmu_tlb_flush_all (void *cookie) {struct ipmmu_vmsa_domain *domain = cookie;
@@ -627,6 +639,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,return 0 ; } +static int ipmmu_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) +{ +struct iommu_domain *io_domain =iommu_get_domain_for_dev (dev); +struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev); +struct ipmmu_vmsa_domain *domain; +unsigned int i; + +if (io_domain == identity_domain || !io_domain) +return 0 ; + + domain =to_vmsa_domain (io_domain); +for (i =0 ; i < fwspec->num_ids; ++i) +ipmmu_utlb_disable (domain, fwspec->ids[i]); + +/* +* TODO: Optimize by disabling the context when no device is attached. +*/ +return 0 ; +} + +static struct iommu_domain_ops ipmmu_iommu_identity_ops = { + .attach_dev = ipmmu_iommu_identity_attach, +}; + +static struct iommu_domain ipmmu_iommu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &ipmmu_iommu_identity_ops, +}; +static int ipmmu_map (struct iommu_domain *io_domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -849,6 +891,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev) }static const struct iommu_ops ipmmu_ops = { + .identity_domain = &ipmmu_iommu_identity_domain, .domain_alloc = ipmmu_domain_alloc, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 18/24 iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN
In reply to Jason GunthorpeThis brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain.
--- drivers/iommu/mtk_iommu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/iommu/mtk_iommu.c +23 -0
@@ -777,6 +777,28 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,return ret; } +static int mtk_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); +struct mtk_iommu_data *data =dev_iommu_priv_get (dev); + +if (domain == identity_domain || !domain) +return 0 ; + +mtk_iommu_config (data, dev, false,0 ); +return 0 ; +} + +static struct iommu_domain_ops mtk_iommu_identity_ops = { + .attach_dev = mtk_iommu_identity_attach, +}; + +static struct iommu_domain mtk_iommu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &mtk_iommu_identity_ops, +}; +static int mtk_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -996,6 +1018,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, }static const struct iommu_ops mtk_iommu_ops = { + .identity_domain = &mtk_iommu_identity_domain, .domain_alloc = mtk_iommu_domain_alloc, .probe_device = mtk_iommu_probe_device, .release_device = mtk_iommu_release_device,
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 19/24 iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN
In reply to Jason GunthorpePrior to commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") the sun50i_iommu_detach_device() function was being called by ops->detach_dev().
This is an IDENTITY domain so convert sun50i_iommu_detach_device() into sun50i_iommu_identity_attach() and a full IDENTITY domain and thus hook it back up the same was as the old ops->detach_dev().
--- drivers/iommu/sun50i-iommu.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/iommu/sun50i-iommu.c +19 -7
@@ -757,21 +757,32 @@ static void sun50i_iommu_detach_domain(struct sun50i_iommu *iommu, iommu->domain =NULL ; } -static void sun50i_iommu_detach_device (struct iommu_domain *domain, -struct device *dev) +static int sun50i_iommu_identity_attach (struct iommu_domain *identity_domain, +struct device *dev) { -struct sun50i_iommu_domain *sun50i_domain =to_sun50i_domain (domain);struct sun50i_iommu *iommu =dev_iommu_priv_get (dev); +struct sun50i_iommu_domain *sun50i_domain;dev_dbg (dev,"Detaching from IOMMU domain\n" ); -if (iommu->domain != domain) -return ; +if (iommu->domain == identity_domain) +return 0 ; + sun50i_domain =to_sun50i_domain (iommu->domain);if (refcount_dec_and_test (&sun50i_domain->refcnt))sun50i_iommu_detach_domain (iommu, sun50i_domain); +return 0 ; } +static struct iommu_domain_ops sun50i_iommu_identity_ops = { + .attach_dev = sun50i_iommu_identity_attach, +}; + +static struct iommu_domain sun50i_iommu_identity_domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &sun50i_iommu_identity_ops, +}; +static int sun50i_iommu_attach_device (struct iommu_domain *domain,struct device *dev) {
@@ -789,8 +800,7 @@ static int sun50i_iommu_attach_device(struct iommu_domain *domain,if (iommu->domain == domain)return 0 ; -if (iommu->domain) -sun50i_iommu_detach_device (iommu->domain, dev); +sun50i_iommu_identity_attach (&sun50i_iommu_identity_domain, dev);sun50i_iommu_attach_domain (iommu, sun50i_domain);
@@ -827,6 +837,7 @@ static int sun50i_iommu_of_xlate(struct device *dev, }static const struct iommu_ops sun50i_iommu_ops = { + .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap =SZ_4K , .device_group = sun50i_iommu_device_group, .domain_alloc = sun50i_iommu_domain_alloc,
@@ -985,6 +996,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev)if (!iommu)return -ENOMEM ;spin_lock_init (&iommu->iommu_lock); + iommu->domain = &sun50i_iommu_identity_domain;platform_set_drvdata (pdev, iommu); iommu->dev = &pdev->dev;
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 20/24 iommu: Require a default_domain for all iommu drivers
In reply to Jason GunthorpeAt this point every iommu driver will cause a default_domain to be selected, so we can finally remove this gap from the core code.
The following table explains what each driver supports and what the resulting default_domain will be:
ops->defaut_domain
IDENTITY DMA PLATFORM v ARM32 dma-iommu ARCH
amd/iommu.c Y Y N/A either apple-dart.c Y Y N/A either arm-smmu.c Y Y IDENTITY either qcom_iommu.c G Y IDENTITY either arm-smmu-v3.c Y Y N/A either exynos-iommu.c G Y IDENTITY either fsl_pamu_domain.c Y Y N/A N/A PLATFORM intel/iommu.c Y Y N/A either ipmmu-vmsa.c G Y IDENTITY either msm_iommu.c G IDENTITY N/A mtk_iommu.c G Y IDENTITY either mtk_iommu_v1.c G IDENTITY N/A omap-iommu.c G IDENTITY N/A rockchip-iommu.c G Y IDENTITY either s390-iommu.c Y Y N/A N/A PLATFORM sprd-iommu.c Y N/A DMA sun50i-iommu.c G Y IDENTITY either tegra-smmu.c G Y IDENTITY IDENTITY virtio-iommu.c Y Y N/A either spapr Y Y N/A N/A PLATFORM
* G means ops->identity_domain is used
* N/A means the driver will not compile in this configuration
ARM32 drivers select an IDENTITY default domain through either the ops->identity_domain or directly requesting an IDENTIY domain through alloc_domain().
In ARM64 mode tegra-smmu will still block the use of dma-iommu.c and forces an IDENTITY domain.
S390 uses a PLATFORM domain to represent when the dma_ops are set to the s390 iommu code.
fsl_pamu uses an PLATFORM domain.
POWER SPAPR uses PLATFORM and blocking to enable its weird VFIO mode.
The x86 drivers continue unchanged.
After this patch group->default_domain is only NULL for a short period during bus iommu probing while all the groups are constituted. Otherwise it is always !NULL.
This completes changing the iommu subsystem driver contract to a system where the current iommu_domain always represents some form of translation and the driver is continuously asserting a definable translation mode.
It resolves the confusion that the original ops->detach_dev() caused around what translation, exactly, is the IOMMU performing after detach. There were at least three different answers to that question in the tree, they are all now clearly named with domain types.
--- drivers/iommu/iommu.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/iommu/iommu.c +7 -15
@@ -1865,7 +1865,6 @@ static int iommu_get_def_domain_type(struct iommu_group *group,static int iommu_get_default_domain_type (struct iommu_group *group,int target_type) { -const struct iommu_ops *ops =group_iommu_ops (group);struct device *untrusted =NULL ;struct group_device *gdev;int driver_type =0 ;
@@ -1876,11 +1875,13 @@ static int iommu_get_default_domain_type(struct iommu_group *group,* ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an * identity_domain and it will automatically become their default * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. -* Override the selection to IDENTITY if we are sure the driver supports -* it. +* Override the selection to IDENTITY. */ -if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) && ops->identity_domain) +if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU )) { +static_assert (!(IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) && +IS_ENABLED (CONFIG_IOMMU_DMA ))); driver_type =IOMMU_DOMAIN_IDENTITY ; + }for_each_group_device (group, gdev) { driver_type = iommu_get_def_domain_type(group, gdev->dev,
@@ -3016,18 +3017,9 @@ static int iommu_setup_default_domain(struct iommu_group *group,if (req_type <0 )return -EINVAL ; -/* -* There are still some drivers which don't support default domains, so -* we ignore the failure and leave group->default_domain NULL. -*/ dom =iommu_group_alloc_default_domain (group, req_type); -if (!dom) { -/* Once in default_domain mode we never leave */ -if (group->default_domain) -return -ENODEV ; - group->default_domain =NULL ; -return 0 ; - } +if (!dom) +return -ENODEV ;if (group->default_domain == dom)return 0 ;
Signature · 1 line
2.42.0
Re: [PATCH v8 20/24] iommu: Require a default_domain for all iommu drivers
Quoted 9 lines · Jason Gunthorpe
At this point every iommu driver will cause a
default_domainto be selected, so we can finally remove this gap from the core code.The following table explains what each driver supports and what the resulting
default_domainwill be:
ops->defaut_domain
IDENTITY DMA PLATFORM v ARM32 dma-iommu ARCH
Quoted 10 lines
amd/iommu.c Y Y N/A either apple-dart.c Y Y N/A either arm-smmu.c Y Y IDENTITY either qcom_iommu.c G Y IDENTITY either arm-smmu-v3.c Y Y N/A either exynos-iommu.c G Y IDENTITY either fsl_pamu_domain.c Y Y N/A N/A PLATFORM intel/iommu.c Y Y N/A either ipmmu-vmsa.c G Y IDENTITY either msm_iommu.c G IDENTITY N/A
Unfortunately this patch breaks msm_iommu platforms. This driver doesn't select ARM_DMA_USE_IOMMU, so iommu_get_default_domain_type() returns 0, bus_iommu_probe() fails with -ENODEV.
If I make MSM_IOMMU select ARM_DMA_USE_IOMMU, then GPU probing fails with -EBUSY.
Quoted 107 lines
mtk_iommu.c G Y IDENTITY either mtk_iommu_v1.c G IDENTITY N/A omap-iommu.c G IDENTITY N/A rockchip-iommu.c G Y IDENTITY either s390-iommu.c Y Y N/A N/A PLATFORM sprd-iommu.c Y N/A DMA sun50i-iommu.c G Y IDENTITY either tegra-smmu.c G Y IDENTITY IDENTITY virtio-iommu.c Y Y N/A either spapr Y Y N/A N/A PLATFORM* G means
ops->identity_domainis used
* N/A means the driver will not compile in this configurationARM32 drivers select an IDENTITY default domain through either the
ops->identity_domainor directly requesting an IDENTIY domain throughalloc_domain().In ARM64 mode tegra-smmu will still block the use of
dma-iommu.cand forces an IDENTITY domain.S390 uses a PLATFORM domain to represent when the
dma_opsare set to the s390 iommu code.
fsl_pamuuses an PLATFORM domain.POWER SPAPR uses PLATFORM and blocking to enable its weird VFIO mode.
The x86 drivers continue unchanged.
After this patch
group->default_domainis only NULL for a short period during bus iommu probing while all the groups are constituted. Otherwise it is always !NULL.This completes changing the iommu subsystem driver contract to a system where the current
iommu_domainalways represents some form of translation and the driver is continuously asserting a definable translation mode.It resolves the confusion that the original
ops->detach_dev()caused around what translation, exactly, is the IOMMU performing after detach. There were at least three different answers to that question in the tree, they are all now clearly named with domain types.Tested-by Heiko Stuebner <[email protected]>Tested-by Niklas Schnelle <[email protected]>Tested-by Steven Price <[email protected]>Tested-by Marek Szyprowski <[email protected]>Tested-by Nicolin Chen <[email protected]>Reviewed-by Lu Baolu <[email protected]>Reviewed-by Jerry Snitselaar <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>--- drivers/iommu/iommu.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)drivers/iommu/iommu.c +7
-16@@ -1865,7 +1865,6 @@ static int iommu_get_def_domain_type(struct iommu_group *group,static int iommu_get_default_domain_type (struct iommu_group *group,int target_type) { -const struct iommu_ops *ops =group_iommu_ops (group);struct device *untrusted =NULL ;struct group_device *gdev;int driver_type =0 ;@@ -1876,11 +1875,13 @@ static int iommu_get_default_domain_type(struct iommu_group *group,* ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an * identity_domain and it will automatically become their default * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. -* Override the selection to IDENTITY if we are sure the driver supports -* it. +* Override the selection to IDENTITY. */ -if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) && ops->identity_domain) +if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU )) { +static_assert (!(IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) && +IS_ENABLED (CONFIG_IOMMU_DMA ))); driver_type =IOMMU_DOMAIN_IDENTITY ; + }for_each_group_device (group, gdev) { driver_type = iommu_get_def_domain_type(group, gdev->dev,@@ -3016,18 +3017,9 @@ static int iommu_setup_default_domain(struct iommu_group *group,if (req_type <0 )return -EINVAL ; -/* -* There are still some drivers which don't support default domains, so -* we ignore the failure and leave group->default_domain NULL. -*/ dom =iommu_group_alloc_default_domain (group, req_type); -if (!dom) { -/* Once in default_domain mode we never leave */ -if (group->default_domain) -return -ENODEV ; - group->default_domain =NULL ; -return 0 ; - } +if (!dom) +return -ENODEV ;if (group->default_domain == dom)return 0 ; --2.42.0
Signature · 2 lines
With best wishes Dmitry
Jason Gunthorpe
maintainerRe: [PATCH v8 20/24] iommu: Require a default_domain for all iommu drivers
Quoted 21 lines · Dmitry Baryshkov
Quoted 9 lines · Jason Gunthorpe
At this point every iommu driver will cause a
default_domainto be selected, so we can finally remove this gap from the core code.The following table explains what each driver supports and what the resulting
default_domainwill be:
ops->defaut_domain
IDENTITY DMA PLATFORM v ARM32 dma-iommu ARCHQuoted 10 lines
amd/iommu.c Y Y N/A either apple-dart.c Y Y N/A either arm-smmu.c Y Y IDENTITY either qcom_iommu.c G Y IDENTITY either arm-smmu-v3.c Y Y N/A either exynos-iommu.c G Y IDENTITY either fsl_pamu_domain.c Y Y N/A N/A PLATFORM intel/iommu.c Y Y N/A either ipmmu-vmsa.c G Y IDENTITY either msm_iommu.c G IDENTITY N/A
Quoted 5 lines
Unfortunately this patch breaks
msm_iommuplatforms. This driver doesn't selectARM_DMA_USE_IOMMU, soiommu_get_default_domain_type()returns 0,bus_iommu_probe()fails with-ENODEV.
If I makeMSM_IOMMUselectARM_DMA_USE_IOMMU, then GPU probing fails with-EBUSY.
Oh, OK.
Does this fix it?
drivers/iommu/msm_iommu.c +6 -0
@@ -685,10 +685,16 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)return 0 ; } +static int msm_iommu_def_domain_type (struct device *dev) +{ +return IOMMU_DOMAIN_IDENTITY ; +} +static struct iommu_ops msm_iommu_ops = { .identity_domain = &msm_iommu_identity_domain, .domain_alloc_paging = msm_iommu_domain_alloc_paging, .probe_device = msm_iommu_probe_device, + .def_domain_type = msm_iommu_def_domain_type, .device_group = generic_device_group, .pgsize_bitmap =MSM_IOMMU_PGSIZES , .of_xlate = qcom_iommu_of_xlate,
Dmitry Baryshkov
Tested-byRe: [PATCH v8 20/24] iommu: Require a default_domain for all iommu drivers
Quoted 29 lines · Jason Gunthorpe
Quoted 21 lines · Dmitry Baryshkov
Quoted 9 lines · Jason Gunthorpe
At this point every iommu driver will cause a
default_domainto be selected, so we can finally remove this gap from the core code.The following table explains what each driver supports and what the resulting
default_domainwill be:
ops->defaut_domain
IDENTITY DMA PLATFORM v ARM32 dma-iommu ARCHQuoted 10 lines
amd/iommu.c Y Y N/A either apple-dart.c Y Y N/A either arm-smmu.c Y Y IDENTITY either qcom_iommu.c G Y IDENTITY either arm-smmu-v3.c Y Y N/A either exynos-iommu.c G Y IDENTITY either fsl_pamu_domain.c Y Y N/A N/A PLATFORM intel/iommu.c Y Y N/A either ipmmu-vmsa.c G Y IDENTITY either msm_iommu.c G IDENTITY N/AQuoted 5 lines
Unfortunately this patch breaks
msm_iommuplatforms. This driver doesn't selectARM_DMA_USE_IOMMU, soiommu_get_default_domain_type()returns 0,bus_iommu_probe()fails with-ENODEV.
If I makeMSM_IOMMUselectARM_DMA_USE_IOMMU, then GPU probing fails with-EBUSY.
Quoted 3 lines
Oh, OK.
Does this fix it?
It indeed fixes the issue, so could you please post it, adding:
Quoted 21 lines
drivers/iommu/msm_iommu.c +6
-0@@ -685,10 +685,16 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)return 0 ; } +static int msm_iommu_def_domain_type (struct device *dev) +{ +return IOMMU_DOMAIN_IDENTITY ; +} +static struct iommu_ops msm_iommu_ops = { .identity_domain = &msm_iommu_identity_domain, .domain_alloc_paging = msm_iommu_domain_alloc_paging, .probe_device = msm_iommu_probe_device, + .def_domain_type = msm_iommu_def_domain_type, .device_group = generic_device_group, .pgsize_bitmap =MSM_IOMMU_PGSIZES , .of_xlate = qcom_iommu_of_xlate,
Signature · 2 lines
With best wishes Dmitry
Jason Gunthorpe
maintainerPATCH v8 21/24 iommu: Add __iommu_group_domain_alloc()
In reply to Jason GunthorpeAllocate a domain from a group. Automatically obtains the iommu_ops to use from the device list of the group. Convert the internal callers to use it.
--- drivers/iommu/iommu.c | 59 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 30 deletions(-)
drivers/iommu/iommu.c +29 -30
@@ -96,8 +96,8 @@ static const char * const iommu_group_resv_type_string[] = {static int iommu_bus_notifier (struct notifier_block *nb,unsigned long action,void *data);static void iommu_release_device (struct device *dev); -static struct iommu_domain *__iommu_domain_alloc (const struct bus_type *bus, -unsigned type); +static struct iommu_domain * +__iommu_group_domain_alloc (struct iommu_group *group,unsigned int type);static int __iommu_attach_device (struct iommu_domain *domain,struct device *dev); static int __iommu_attach_group(struct iommu_domain *domain,
@@ -1719,12 +1719,11 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)EXPORT_SYMBOL_GPL (fsl_mc_device_group);static struct iommu_domain * -__iommu_group_alloc_default_domain (const struct bus_type *bus, -struct iommu_group *group,int req_type) +__iommu_group_alloc_default_domain (struct iommu_group *group,int req_type) {if (group->default_domain && group->default_domain->type == req_type)return group->default_domain; -return __iommu_domain_alloc (bus, req_type); +return __iommu_group_domain_alloc (group, req_type); }/*
@@ -1751,9 +1750,7 @@ static const struct iommu_ops *group_iommu_ops(struct iommu_group *group)static struct iommu_domain *iommu_group_alloc_default_domain (struct iommu_group *group,int req_type) { -const struct bus_type *bus = - list_first_entry(&group->devices, struct group_device, list) - ->dev->bus; +const struct iommu_ops *ops =group_iommu_ops (group);struct iommu_domain *dom;lockdep_assert_held (&group->mutex);
@@ -1763,24 +1760,24 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)* domain. This should always be either an IDENTITY/BLOCKED/PLATFORM * domain. Do not use in new drivers. */ -if (bus->iommu_ops->default_domain) { +if (ops->default_domain) {if (req_type)return ERR_PTR (-EINVAL ); -return bus->iommu_ops->default_domain; +return ops->default_domain; }if (req_type) -return __iommu_group_alloc_default_domain (bus, group, req_type); +return __iommu_group_alloc_default_domain (group, req_type);/* The driver gave no guidance on what type to use, try the default */ - dom =__iommu_group_alloc_default_domain (bus, group, iommu_def_domain_type); + dom =__iommu_group_alloc_default_domain (group, iommu_def_domain_type);if (dom)return dom;/* Otherwise IDENTITY and DMA_FQ defaults will try DMA */ if (iommu_def_domain_type ==IOMMU_DOMAIN_DMA )return NULL ; - dom =__iommu_group_alloc_default_domain (bus, group,IOMMU_DOMAIN_DMA ); + dom =__iommu_group_alloc_default_domain (group,IOMMU_DOMAIN_DMA );if (!dom)return NULL ;
@@ -2043,19 +2040,16 @@ void iommu_set_fault_handler(struct iommu_domain *domain, }EXPORT_SYMBOL_GPL (iommu_set_fault_handler); -static struct iommu_domain *__iommu_domain_alloc (const struct bus_type *bus, -unsigned type) +static struct iommu_domain *__iommu_domain_alloc (const struct iommu_ops *ops, +unsigned int type) {struct iommu_domain *domain;unsigned int alloc_type = type &IOMMU_DOMAIN_ALLOC_FLAGS ; -if (bus ==NULL || bus->iommu_ops ==NULL ) -return NULL ; +if (alloc_type ==IOMMU_DOMAIN_IDENTITY && ops->identity_domain) +return ops->identity_domain; -if (alloc_type ==IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain) -return bus->iommu_ops->identity_domain; - - domain = bus->iommu_ops->domain_alloc (alloc_type); + domain = ops->domain_alloc (alloc_type);if (!domain)return NULL ;
@@ -2065,10 +2059,10 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,* may override this later */ if (!domain->pgsize_bitmap) - domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; + domain->pgsize_bitmap = ops->pgsize_bitmap;if (!domain->ops) - domain->ops = bus->iommu_ops->default_domain_ops; + domain->ops = ops->default_domain_ops;if (iommu_is_dma_domain (domain) &&iommu_get_dma_cookie (domain)) {iommu_domain_free (domain);
@@ -2077,9 +2071,17 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,return domain; } +static struct iommu_domain * +__iommu_group_domain_alloc (struct iommu_group *group,unsigned int type) +{ +return __iommu_domain_alloc (group_iommu_ops (group), type); +} +struct iommu_domain *iommu_domain_alloc (const struct bus_type *bus) { -return __iommu_domain_alloc (bus,IOMMU_DOMAIN_UNMANAGED ); +if (bus ==NULL || bus->iommu_ops ==NULL ) +return NULL ; +return __iommu_domain_alloc (bus->iommu_ops,IOMMU_DOMAIN_UNMANAGED ); }EXPORT_SYMBOL_GPL (iommu_domain_alloc);
@@ -3239,21 +3241,18 @@ void iommu_device_unuse_default_domain(struct device *dev)static int __iommu_group_alloc_blocking_domain (struct iommu_group *group) { -struct group_device *dev = - list_first_entry(&group->devices, struct group_device, list); -if (group->blocking_domain)return 0 ; group->blocking_domain = -__iommu_domain_alloc (dev->dev->bus,IOMMU_DOMAIN_BLOCKED ); +__iommu_group_domain_alloc (group,IOMMU_DOMAIN_BLOCKED );if (!group->blocking_domain) {/* * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED * create an empty domain instead. */ - group->blocking_domain =__iommu_domain_alloc ( - dev->dev->bus,IOMMU_DOMAIN_UNMANAGED ); + group->blocking_domain =__iommu_group_domain_alloc ( + group,IOMMU_DOMAIN_UNMANAGED );if (!group->blocking_domain)return -EINVAL ; }
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 22/24 iommu: Add ops->domain_alloc_paging()
In reply to Jason GunthorpeThis callback requests the driver to create only a __IOMMU_DOMAIN_PAGING domain, so it saves a few lines in a lot of drivers needlessly checking the type.
More critically, this allows us to sweep out all the IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA checks from a lot of the drivers, simplifying what is going on in the code and ultimately removing the now-unused special cases in drivers where they did not support IOMMU_DOMAIN_DMA.
domain_alloc_paging() should return a struct iommu_domain that is functionally compatible with ARM_DMA_USE_IOMMU, dma-iommu.c and iommufd.
Be forwards looking and pass in a 'struct device *' argument. We can provide this when allocating the default_domain. No drivers will look at this.
--- drivers/iommu/iommu.c | 17 ++++++++++++++--- include/linux/iommu.h | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/iommu/iommu.c +14 -3
@@ -2041,6 +2041,7 @@ void iommu_set_fault_handler(struct iommu_domain *domain,EXPORT_SYMBOL_GPL (iommu_set_fault_handler);static struct iommu_domain *__iommu_domain_alloc (const struct iommu_ops *ops, +struct device *dev,unsigned int type) {struct iommu_domain *domain;
@@ -2048,8 +2049,13 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,if (alloc_type ==IOMMU_DOMAIN_IDENTITY && ops->identity_domain)return ops->identity_domain; +else if (type & __IOMMU_DOMAIN_PAGING && ops->domain_alloc_paging) + domain = ops->domain_alloc_paging (dev); +else if (ops->domain_alloc) + domain = ops->domain_alloc (alloc_type); +else +return NULL ; - domain = ops->domain_alloc (alloc_type);if (!domain)return NULL ;
@@ -2074,14 +2080,19 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,static struct iommu_domain *__iommu_group_domain_alloc (struct iommu_group *group,unsigned int type) { -return __iommu_domain_alloc (group_iommu_ops (group), type); +struct device *dev = + list_first_entry(&group->devices, struct group_device, list) + ->dev; + +return __iommu_domain_alloc (group_iommu_ops (group), dev, type); }struct iommu_domain *iommu_domain_alloc (const struct bus_type *bus) {if (bus ==NULL || bus->iommu_ops ==NULL )return NULL ; -return __iommu_domain_alloc (bus->iommu_ops,IOMMU_DOMAIN_UNMANAGED ); +return __iommu_domain_alloc (bus->iommu_ops,NULL , +IOMMU_DOMAIN_UNMANAGED ); }EXPORT_SYMBOL_GPL (iommu_domain_alloc);
include/linux/iommu.h +3 -0
@@ -239,6 +239,8 @@ struct iommu_iotlb_gather {* use. The information type is one of enum iommu_hw_info_type defined * in include/uapi/linux/iommufd.h. * @domain_alloc: allocate iommu domain +* @domain_alloc_paging: Allocate an iommu_domain that can be used for +* UNMANAGED, DMA, and DMA_FQ domain types. * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -273,6 +275,7 @@ struct iommu_ops {/* Domain allocation and freeing by the iommu driver */ struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); +struct iommu_domain *(*domain_alloc_paging)(struct device *dev);struct iommu_device *(*probe_device)(struct device *dev);void (*release_device)(struct device *dev);
Signature · 1 line
2.42.0
Jason Gunthorpe
maintainerPATCH v8 23/24 iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()
In reply to Jason GunthorpeThese drivers are all trivially converted since the function is only called if the domain type is going to be IOMMU_DOMAIN_UNMANAGED/DMA.
--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 6 ++---- drivers/iommu/exynos-iommu.c | 7 ++----- drivers/iommu/ipmmu-vmsa.c | 7 ++----- drivers/iommu/mtk_iommu.c | 7 ++----- drivers/iommu/rockchip-iommu.c | 7 ++----- drivers/iommu/sprd-iommu.c | 7 ++----- drivers/iommu/sun50i-iommu.c | 9 +++------ drivers/iommu/tegra-smmu.c | 7 ++----- 8 files changed, 17 insertions(+), 40 deletions(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +2 -4
@@ -332,12 +332,10 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,return ret; } -static struct iommu_domain *qcom_iommu_domain_alloc (unsigned type) +static struct iommu_domain *qcom_iommu_domain_alloc_paging (struct device *dev) {struct qcom_iommu_domain *qcom_domain; -if (type !=IOMMU_DOMAIN_UNMANAGED && type !=IOMMU_DOMAIN_DMA ) -return NULL ;/* * Allocate the domain and initialise some of its data structures. * We can't really do anything meaningful until we've added a
@@ -605,7 +603,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)static const struct iommu_ops qcom_iommu_ops = { .identity_domain = &qcom_iommu_identity_domain, .capable = qcom_iommu_capable, - .domain_alloc = qcom_iommu_domain_alloc, + .domain_alloc_paging = qcom_iommu_domain_alloc_paging, .probe_device = qcom_iommu_probe_device, .device_group = generic_device_group, .of_xlate = qcom_iommu_of_xlate,
drivers/iommu/exynos-iommu.c +2 -5
@@ -887,7 +887,7 @@ static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val) DMA_TO_DEVICE); } -static struct iommu_domain *exynos_iommu_domain_alloc (unsigned type) +static struct iommu_domain *exynos_iommu_domain_alloc_paging (struct device *dev) {struct exynos_iommu_domain *domain;dma_addr_t handle;
@@ -896,9 +896,6 @@ static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type)/* Check if correct PTE offsets are initialized */ BUG_ON (PG_ENT_SHIFT <0 || !dma_dev); -if (type !=IOMMU_DOMAIN_DMA && type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - domain =kzalloc (sizeof (*domain),GFP_KERNEL );if (!domain)return NULL ;
@@ -1472,7 +1469,7 @@ static int exynos_iommu_of_xlate(struct device *dev,static const struct iommu_ops exynos_iommu_ops = { .identity_domain = &exynos_identity_domain, - .domain_alloc = exynos_iommu_domain_alloc, + .domain_alloc_paging = exynos_iommu_domain_alloc_paging, .device_group = generic_device_group, .probe_device = exynos_iommu_probe_device, .release_device = exynos_iommu_release_device,
drivers/iommu/ipmmu-vmsa.c +2 -5
@@ -563,13 +563,10 @@ static irqreturn_t ipmmu_irq(int irq, void *dev)* IOMMU Operations */ -static struct iommu_domain *ipmmu_domain_alloc (unsigned type) +static struct iommu_domain *ipmmu_domain_alloc_paging (struct device *dev) {struct ipmmu_vmsa_domain *domain; -if (type !=IOMMU_DOMAIN_UNMANAGED && type !=IOMMU_DOMAIN_DMA ) -return NULL ; - domain =kzalloc (sizeof (*domain),GFP_KERNEL );if (!domain)return NULL ;
@@ -892,7 +889,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev)static const struct iommu_ops ipmmu_ops = { .identity_domain = &ipmmu_iommu_identity_domain, - .domain_alloc = ipmmu_domain_alloc, + .domain_alloc_paging = ipmmu_domain_alloc_paging, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device, .probe_finalize = ipmmu_probe_finalize,
drivers/iommu/mtk_iommu.c +2 -5
@@ -689,13 +689,10 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,return 0 ; } -static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) +static struct iommu_domain *mtk_iommu_domain_alloc_paging (struct device *dev) {struct mtk_iommu_domain *dom; -if (type !=IOMMU_DOMAIN_DMA && type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - dom =kzalloc (sizeof (*dom),GFP_KERNEL );if (!dom)return NULL ;
@@ -1019,7 +1016,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,static const struct iommu_ops mtk_iommu_ops = { .identity_domain = &mtk_iommu_identity_domain, - .domain_alloc = mtk_iommu_domain_alloc, + .domain_alloc_paging = mtk_iommu_domain_alloc_paging, .probe_device = mtk_iommu_probe_device, .release_device = mtk_iommu_release_device, .device_group = mtk_iommu_device_group,
drivers/iommu/rockchip-iommu.c +2 -5
@@ -1043,13 +1043,10 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,return ret; } -static struct iommu_domain *rk_iommu_domain_alloc (unsigned type) +static struct iommu_domain *rk_iommu_domain_alloc_paging (struct device *dev) {struct rk_iommu_domain *rk_domain; -if (type !=IOMMU_DOMAIN_UNMANAGED && type !=IOMMU_DOMAIN_DMA ) -return NULL ; -if (!dma_dev)return NULL ;
@@ -1172,7 +1169,7 @@ static int rk_iommu_of_xlate(struct device *dev,static const struct iommu_ops rk_iommu_ops = { .identity_domain = &rk_identity_domain, - .domain_alloc = rk_iommu_domain_alloc, + .domain_alloc_paging = rk_iommu_domain_alloc_paging, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, .device_group = rk_iommu_device_group,
drivers/iommu/sprd-iommu.c +2 -5
@@ -134,13 +134,10 @@ sprd_iommu_pgt_size(struct iommu_domain *domain) SPRD_IOMMU_PAGE_SHIFT) * sizeof(u32); } -static struct iommu_domain *sprd_iommu_domain_alloc (unsigned int domain_type) +static struct iommu_domain *sprd_iommu_domain_alloc_paging (struct device *dev) {struct sprd_iommu_domain *dom; -if (domain_type !=IOMMU_DOMAIN_DMA && domain_type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - dom =kzalloc (sizeof (*dom),GFP_KERNEL );if (!dom)return NULL ;
@@ -421,7 +418,7 @@ static int sprd_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)static const struct iommu_ops sprd_iommu_ops = { - .domain_alloc = sprd_iommu_domain_alloc, + .domain_alloc_paging = sprd_iommu_domain_alloc_paging, .probe_device = sprd_iommu_probe_device, .device_group = sprd_iommu_device_group, .of_xlate = sprd_iommu_of_xlate,
drivers/iommu/sun50i-iommu.c +3 -6
@@ -667,14 +667,11 @@ static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain *domain,sun50i_iova_get_page_offset (iova); } -static struct iommu_domain *sun50i_iommu_domain_alloc (unsigned type) +static struct iommu_domain * +sun50i_iommu_domain_alloc_paging (struct device *dev) {struct sun50i_iommu_domain *sun50i_domain; -if (type !=IOMMU_DOMAIN_DMA && - type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - sun50i_domain =kzalloc (sizeof (*sun50i_domain),GFP_KERNEL );if (!sun50i_domain)return NULL ;
@@ -840,7 +837,7 @@ static const struct iommu_ops sun50i_iommu_ops = { .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap = SZ_4K, .device_group = sun50i_iommu_device_group, - .domain_alloc = sun50i_iommu_domain_alloc, + .domain_alloc_paging = sun50i_iommu_domain_alloc_paging, .of_xlate = sun50i_iommu_of_xlate, .probe_device = sun50i_iommu_probe_device, .default_domain_ops = &(const struct iommu_domain_ops ) {
drivers/iommu/tegra-smmu.c +2 -5
@@ -272,13 +272,10 @@ static void tegra_smmu_free_asid(struct tegra_smmu *smmu, unsigned int id)clear_bit (id, smmu->asids); } -static struct iommu_domain *tegra_smmu_domain_alloc (unsigned type) +static struct iommu_domain *tegra_smmu_domain_alloc_paging (struct device *dev) {struct tegra_smmu_as *as; -if (type !=IOMMU_DOMAIN_UNMANAGED && type !=IOMMU_DOMAIN_DMA ) -return NULL ; - as =kzalloc (sizeof (*as),GFP_KERNEL );if (!as)return NULL ;
@@ -991,7 +988,7 @@ static int tegra_smmu_def_domain_type(struct device *dev)static const struct iommu_ops tegra_smmu_ops = { .identity_domain = &tegra_smmu_identity_domain, .def_domain_type = &tegra_smmu_def_domain_type, - .domain_alloc = tegra_smmu_domain_alloc, + .domain_alloc_paging = tegra_smmu_domain_alloc_paging, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, .of_xlate = tegra_smmu_of_xlate,
Signature · 1 line
2.42.0
Re: [PATCH v8 23/24] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()
Quoted 14 lines · Jason Gunthorpe
External email : Please do not click links or open attachments until you have verified the sender or the content.
These drivers are all trivially converted since the function is only
called if the domain type is going to be IOMMU_DOMAIN_UNMANAGED/DMA.Tested-by Heiko Stuebner <[email protected]>Tested-by Steven Price <[email protected]>Tested-by Marek Szyprowski <[email protected]>Tested-by Nicolin Chen <[email protected]>Reviewed-by Lu Baolu <[email protected]>Reviewed-by Jerry Snitselaar <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>
Quoted 11 lines
--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 6 ++---- drivers/iommu/exynos-iommu.c | 7 ++----- drivers/iommu/ipmmu-vmsa.c | 7 ++----- drivers/iommu/mtk_iommu.c | 7 ++----- drivers/iommu/rockchip-iommu.c | 7 ++----- drivers/iommu/sprd-iommu.c | 7 ++----- drivers/iommu/sun50i-iommu.c | 9 +++------ drivers/iommu/tegra-smmu.c | 7 ++----- 8 files changed, 17 insertions(+), 40 deletions(-)
Thanks.
Jason Gunthorpe
maintainerPATCH v8 24/24 iommu: Convert remaining simple drivers to domain_alloc_paging()
In reply to Jason GunthorpeThese drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively allows them to support that mode.
The prior work to require default_domains makes this safe because every one of these drivers is either compilation incompatible with dma-iommu.c, or already establishing a default_domain. In both cases alloc_domain() will never be called with IOMMU_DOMAIN_DMA for these drivers so it is safe to drop the test.
Removing these tests clarifies that the domain allocation path is only about the functionality of a paging domain and has nothing to do with policy of how the paging domain is used for UNMANAGED/DMA/DMA_FQ.
--- drivers/iommu/msm_iommu.c | 7 ++----- drivers/iommu/mtk_iommu_v1.c | 7 ++----- drivers/iommu/omap-iommu.c | 7 ++----- drivers/iommu/s390-iommu.c | 7 ++----- 4 files changed, 8 insertions(+), 20 deletions(-)
drivers/iommu/msm_iommu.c +2 -5
@@ -302,13 +302,10 @@ static void __program_context(void __iomem *base, int ctx,SET_M (base, ctx,1 ); } -static struct iommu_domain *msm_iommu_domain_alloc (unsigned type) +static struct iommu_domain *msm_iommu_domain_alloc_paging (struct device *dev) {struct msm_priv *priv; -if (type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - priv =kzalloc (sizeof (*priv),GFP_KERNEL );if (!priv) goto fail_nomem;
@@ -691,7 +688,7 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)static struct iommu_ops msm_iommu_ops = { .identity_domain = &msm_iommu_identity_domain, - .domain_alloc = msm_iommu_domain_alloc, + .domain_alloc_paging = msm_iommu_domain_alloc_paging, .probe_device = msm_iommu_probe_device, .device_group = generic_device_group, .pgsize_bitmap =MSM_IOMMU_PGSIZES ,
drivers/iommu/mtk_iommu_v1.c +2 -5
@@ -270,13 +270,10 @@ static int mtk_iommu_v1_domain_finalise(struct mtk_iommu_v1_data *data)return 0 ; } -static struct iommu_domain *mtk_iommu_v1_domain_alloc (unsigned type) +static struct iommu_domain *mtk_iommu_v1_domain_alloc_paging (struct device *dev) {struct mtk_iommu_v1_domain *dom; -if (type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - dom =kzalloc (sizeof (*dom),GFP_KERNEL );if (!dom)return NULL ;
@@ -585,7 +582,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data)static const struct iommu_ops mtk_iommu_v1_ops = { .identity_domain = &mtk_iommu_v1_identity_domain, - .domain_alloc = mtk_iommu_v1_domain_alloc, + .domain_alloc_paging = mtk_iommu_v1_domain_alloc_paging, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, .release_device = mtk_iommu_v1_release_device,
drivers/iommu/omap-iommu.c +2 -5
@@ -1580,13 +1580,10 @@ static struct iommu_domain omap_iommu_identity_domain = { .ops = &omap_iommu_identity_ops, }; -static struct iommu_domain *omap_iommu_domain_alloc (unsigned type) +static struct iommu_domain *omap_iommu_domain_alloc_paging (struct device *dev) {struct omap_iommu_domain *omap_domain; -if (type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - omap_domain =kzalloc (sizeof (*omap_domain),GFP_KERNEL );if (!omap_domain)return NULL ;
@@ -1748,7 +1745,7 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev)static const struct iommu_ops omap_iommu_ops = { .identity_domain = &omap_iommu_identity_domain, - .domain_alloc = omap_iommu_domain_alloc, + .domain_alloc_paging = omap_iommu_domain_alloc_paging, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group,
drivers/iommu/s390-iommu.c +2 -5
@@ -39,13 +39,10 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *s390_domain_alloc (unsigned domain_type) +static struct iommu_domain *s390_domain_alloc_paging (struct device *dev) {struct s390_domain *s390_domain; -if (domain_type !=IOMMU_DOMAIN_UNMANAGED ) -return NULL ; - s390_domain =kzalloc (sizeof (*s390_domain),GFP_KERNEL );if (!s390_domain)return NULL ;
@@ -447,7 +444,7 @@ void zpci_destroy_iommu(struct zpci_dev *zdev)static const struct iommu_ops s390_iommu_ops = { .default_domain = &s390_iommu_platform_domain, .capable = s390_iommu_capable, - .domain_alloc = s390_domain_alloc, + .domain_alloc_paging = s390_domain_alloc_paging, .probe_device = s390_iommu_probe_device, .release_device = s390_iommu_release_device, .device_group = generic_device_group,
Signature · 1 line
2.42.0
Quoted 18 lines · Jason Gunthorpe
Jason Gunthorpe (24):
iommu: Addiommu_ops->identity_domain
iommu: AddIOMMU_DOMAIN_PLATFORM
powerpc/iommu: Setup a default domain and removeset_platform_dma_ops
iommu: AddIOMMU_DOMAIN_PLATFORMfor S390
iommu/fsl_pamu: Implement a PLATFORM domain iommu/tegra-gart: Remove tegra-gart
iommu/mtk_iommu_v1: Implement an IDENTITY domain
iommu: Reorganizeiommu_get_default_domain_type()to respect
def_domain_type()
iommu: Allow an IDENTITY domain as thedefault_domainin ARM32 iommu/exynos: Implement an IDENTITY domain iommu/tegra-smmu: Implement an IDENTITY domain iommu/tegra-smmu: Support DMA domains in tegra
iommu/omap: Implement an IDENTITY domain
iommu/msm: Implement an IDENTITY domain
iommu: Removeops->set_platform_dma_ops()iommu/qcom_iommu: Add anIOMMU_IDENTITIY_DOMAIN
Quoted 8 lines
iommu/ipmmu: Add an
IOMMU_IDENTITIY_DOMAINiommu/mtk_iommu: Add anIOMMU_IDENTITIY_DOMAINiommu/sun50i: Add anIOMMU_IDENTITIY_DOMAIN
iommu: Require adefault_domainfor all iommu drivers
iommu: Add__iommu_group_domain_alloc()
iommu: Addops->domain_alloc_paging()
iommu: Convert simple drivers withDOMAIN_DMAtodomain_alloc_paging()
iommu: Convert remaining simple drivers todomain_alloc_paging()
Applied, thanks.