History

iommu: Add APIs for multiple domains per device

Sharing a physical PCI device in a finer-granularity way is becoming a consensus in the industry. IOMMU vendors are also engaging efforts to support such sharing as well as possible. Among the efforts, the capability of support finer-granularity DMA isolation is a common requirement due to the security consideration. With finer-granularity DMA isolation, subsets of a PCI function can be isolated from each others by the IOMMU. As a result, there is a request in software to attach multiple domains to a physical PCI device. One example of such use model is the Intel Scalable IOV [1] [2]. The Intel vt-d 3.0 spec [3] introduces the scalable mode which enables PASID granularity DMA isolation. This adds the APIs to support multiple domains per device. In order to ease the discussions, we call it 'a domain in auxiliary mode' or simply 'auxiliary domain' when multiple domains are attached to a physical device. The APIs include: * iommu_dev_has_feature(dev, IOMMU_DEV_FEAT_AUX) - Detect both IOMMU and PCI endpoint devices supporting the feature (aux-domain here) without the host driver dependency. * iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX) - Check the enabling status of the feature (aux-domain here). The aux-domain interfaces are available only if this returns true. * iommu_dev_enable/disable_feature(dev, IOMMU_DEV_FEAT_AUX) - Enable/disable device specific aux-domain feature. * iommu_aux_attach_device(domain, dev) - Attaches @domain to @dev in the auxiliary mode. Multiple domains could be attached to a single device in the auxiliary mode with each domain representing an isolated address space for an assignable subset of the device. * iommu_aux_detach_device(domain, dev) - Detach @domain which has been attached to @dev in the auxiliary mode. * iommu_aux_get_pasid(domain, dev) - Return ID used for finer-granularity DMA translation. For the Intel Scalable IOV usage model, this will be a PASID. The device which supports Scalable IOV needs to write this ID to the device register so that DMA requests could be tagged with a right PASID prefix. This has been updated with the latest proposal from Joerg posted here [5]. Many people involved in discussions of this design. Kevin Tian <kevin.tian@intel.com> Liu Yi L <yi.l.liu@intel.com> Ashok Raj <ashok.raj@intel.com> Sanjay Kumar <sanjay.k.kumar@intel.com> Jacob Pan <jacob.jun.pan@linux.intel.com> Alex Williamson <alex.williamson@redhat.com> Jean-Philippe Brucker <jean-philippe.brucker@arm.com> Joerg Roedel <joro@8bytes.org> and some discussions can be found here [4] [5]. [1] https://software.intel.com/en-us/download/intel-scalable-io-virtualization-technical-specification [2] https://schd.ws/hosted_files/lc32018/00/LC3-SIOV-final.pdf [3] https://software.intel.com/en-us/download/intel-virtualization-technology-for-directed-io-architecture-specification [4] https://lkml.org/lkml/2018/7/26/4 [5] https://www.spinics.net/lists/iommu/msg31874.html

Lu Baolu committed 7 years ago

Commit a3a19591 parent 15ade5d2 files · +166 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/iommu.h+70−0
@@ -156,6 +156,11 @@ struct iommu_resv_region { · 155 unmodified lines
156156 enum iommu_resv_type type;
157157 };
158158
159+/* Per device IOMMU features */
160+enum iommu_dev_features {
161+ IOMMU_DEV_FEAT_AUX, /* Aux-domain feature */
162+};
163+
159164 #ifdef CONFIG_IOMMU_API
160165
161166 /**
@@ -186,6 +191,11 @@ struct iommu_resv_region { · 24 unmodified lines
186191 * @of_xlate: add OF master IDs to iommu grouping
187192 * @is_attach_deferred: Check if domain attach should be deferred from iommu
188193 * driver init to device driver init (default no)
194+ * @dev_has/enable/disable_feat: per device entries to check/enable/disable
195+ * iommu specific features.
196+ * @dev_feat_enabled: check enabled feature
197+ * @aux_attach/detach_dev: aux-domain specific attach/detach entries.
198+ * @aux_get_pasid: get the pasid given an aux-domain
189199 * @pgsize_bitmap: bitmap of all possible supported page sizes
190200 */
191201 struct iommu_ops {
@@ -230,6 +240,17 @@ struct iommu_ops { · 38 unmodified lines
230240 int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
231241 bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev);
232242
243+ /* Per device IOMMU features */
244+ bool (*dev_has_feat)(struct device *dev, enum iommu_dev_features f);
245+ bool (*dev_feat_enabled)(struct device *dev, enum iommu_dev_features f);
246+ int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f);
247+ int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f);
248+
249+ /* Aux-domain specific attach/detach entries */
250+ int (*aux_attach_dev)(struct iommu_domain *domain, struct device *dev);
251+ void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev);
252+ int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev);
253+
233254 unsigned long pgsize_bitmap;
234255 };
235256
@@ -416,6 +437,14 @@ static inline void dev_iommu_fwspec_set(struct device *dev, · 180 unmodified lines
416437 int iommu_probe_device(struct device *dev);
417438 void iommu_release_device(struct device *dev);
418439
440+bool iommu_dev_has_feature(struct device *dev, enum iommu_dev_features f);
441+int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f);
442+int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f);
443+bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features f);
444+int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev);
445+void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev);
446+int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev);
447+
419448 #else /* CONFIG_IOMMU_API */
420449
421450 struct iommu_ops {};
@@ -700,6 +729,47 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) · 278 unmodified lines
700729 return NULL;
701730 }
702731
732+static inline bool
733+iommu_dev_has_feature(struct device *dev, enum iommu_dev_features feat)
734+{
735+ return false;
736+}
737+
738+static inline bool
739+iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat)
740+{
741+ return false;
742+}
743+
744+static inline int
745+iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat)
746+{
747+ return -ENODEV;
748+}
749+
750+static inline int
751+iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat)
752+{
753+ return -ENODEV;
754+}
755+
756+static inline int
757+iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev)
758+{
759+ return -ENODEV;
760+}
761+
762+static inline void
763+iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev)
764+{
765+}
766+
767+static inline int
768+iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev)
769+{
770+ return -ENODEV;
771+}
772+
703773 #endif /* CONFIG_IOMMU_API */
704774
705775 #ifdef CONFIG_IOMMU_DEBUGFS

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t