When user requests kernel to change the default domain type of a group
through sysfs, kernel has to make sure that it's ok to change the domain
type of every device in the group to the requested domain (every device may
not support both the domain types i.e. DMA and identity). Hence, add a call
back function that could be implemented per architecture that performs the
above check.

For intel_iommu, this is already done by device_def_domain_type(), but
every call back function in intel_iommu_ops starts with intel_iommu prefix,
hence modify device_def_domain_type() so that it follows the same
semantics.

Cc: Christoph Hellwig <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Ashok Raj <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Lu Baolu <[email protected]>
Cc: Sohil Mehta <[email protected]>
Cc: Robin Murphy <[email protected]>
Cc: Jacob Pan <[email protected]>
Signed-off-by: Sai Praneeth Prakhya <[email protected]>
---
 drivers/iommu/intel-iommu.c | 9 ++++++---
 include/linux/iommu.h       | 4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 27c3c893530a..3e8655197aad 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2868,7 +2868,7 @@ static bool device_is_rmrr_locked(struct device *dev)
  *  - IOMMU_DOMAIN_IDENTITY: Device should always be in identity mapping domain
  *  - 0: Device could be in any domain (i.e. identity or dynamic)
  */
-static int device_def_domain_type(struct device *dev)
+static int intel_iommu_device_def_domain_type(struct device *dev)
 {
        if (dev_is_pci(dev)) {
                struct pci_dev *pdev = to_pci_dev(dev);
@@ -5297,7 +5297,8 @@ static int intel_iommu_add_device(struct device *dev)
        domain = iommu_get_domain_for_dev(dev);
        dmar_domain = to_dmar_domain(domain);
        if (domain->type == IOMMU_DOMAIN_DMA) {
-               if (device_def_domain_type(dev) == IOMMU_DOMAIN_IDENTITY) {
+               if (intel_iommu_device_def_domain_type(dev) ==
+                   IOMMU_DOMAIN_IDENTITY) {
                        ret = iommu_request_dm_for_dev(dev);
                        if (ret) {
                                dmar_remove_one_dev_info(dev);
@@ -5308,7 +5309,8 @@ static int intel_iommu_add_device(struct device *dev)
                        }
                }
        } else {
-               if (device_def_domain_type(dev) == IOMMU_DOMAIN_DMA) {
+               if (intel_iommu_device_def_domain_type(dev) ==
+                   IOMMU_DOMAIN_DMA) {
                        ret = iommu_request_dma_domain_for_dev(dev);
                        if (ret) {
                                dmar_remove_one_dev_info(dev);
@@ -5652,6 +5654,7 @@ const struct iommu_ops intel_iommu_ops = {
        .dev_enable_feat        = intel_iommu_dev_enable_feat,
        .dev_disable_feat       = intel_iommu_dev_disable_feat,
        .is_attach_deferred     = intel_iommu_is_attach_deferred,
+       .device_def_domain_type = intel_iommu_device_def_domain_type,
        .pgsize_bitmap          = INTEL_IOMMU_PGSIZES,
 };
 
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 64ebaff33455..ae4755ad2937 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -244,6 +244,8 @@ struct iommu_iotlb_gather {
  * @sva_unbind: Unbind process address space from device
  * @sva_get_pasid: Get PASID associated to a SVA handle
  * @page_response: handle page request response
+ * @device_def_domain_type: Return the possible default domain types a device
+ *                         could have.
  * @pgsize_bitmap: bitmap of all possible supported page sizes
  */
 struct iommu_ops {
@@ -307,6 +309,8 @@ struct iommu_ops {
                             struct iommu_fault_event *evt,
                             struct iommu_page_response *msg);
 
+       int (*device_def_domain_type)(struct device *dev);
+
        unsigned long pgsize_bitmap;
 };
 
-- 
2.19.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to