Skip to content

Commit 0061ffe

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Add static iommu_ops->release_domain
The current device_release callback for individual iommu drivers does the following: 1) Silent IOMMU DMA translation: It detaches any existing domain from the device and puts it into a blocking state (some drivers might use the identity state). 2) Resource release: It releases resources allocated during the device_probe callback and restores the device to its pre-probe state. Step 1 is challenging for individual iommu drivers because each must check if a domain is already attached to the device. Additionally, if a deferred attach never occurred, the device_release should avoid modifying hardware configuration regardless of the reason for its call. To simplify this process, introduce a static release_domain within the iommu_ops structure. It can be either a blocking or identity domain depending on the iommu hardware. The iommu core will decide whether to attach this domain before the device_release callback, eliminating the need for repetitive code in various drivers. Consequently, the device_release callback can focus solely on the opposite operations of device_probe, including releasing all resources allocated during that callback. Co-developed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20240305013305.204605-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 80a9b50 commit 0061ffe

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

drivers/iommu/iommu.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,24 @@ static void iommu_deinit_device(struct device *dev)
463463

464464
/*
465465
* release_device() must stop using any attached domain on the device.
466-
* If there are still other devices in the group they are not effected
466+
* If there are still other devices in the group, they are not affected
467467
* by this callback.
468468
*
469-
* The IOMMU driver must set the device to either an identity or
470-
* blocking translation and stop using any domain pointer, as it is
471-
* going to be freed.
469+
* If the iommu driver provides release_domain, the core code ensures
470+
* that domain is attached prior to calling release_device. Drivers can
471+
* use this to enforce a translation on the idle iommu. Typically, the
472+
* global static blocked_domain is a good choice.
473+
*
474+
* Otherwise, the iommu driver must set the device to either an identity
475+
* or a blocking translation in release_device() and stop using any
476+
* domain pointer, as it is going to be freed.
477+
*
478+
* Regardless, if a delayed attach never occurred, then the release
479+
* should still avoid touching any hardware configuration either.
472480
*/
481+
if (!dev->iommu->attach_deferred && ops->release_domain)
482+
ops->release_domain->ops->attach_dev(ops->release_domain, dev);
483+
473484
if (ops->release_device)
474485
ops->release_device(dev);
475486

include/linux/iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ struct iommu_ops {
487487
struct module *owner;
488488
struct iommu_domain *identity_domain;
489489
struct iommu_domain *blocked_domain;
490+
struct iommu_domain *release_domain;
490491
struct iommu_domain *default_domain;
491492
};
492493

0 commit comments

Comments
 (0)