Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1522696

[RFC v3 07/10] iommu: Implement reserved_regions iommu-group sysfs file

From Eric Auger <eric.auger@redhat.com>
Newsgroups linux.kernel
Subject [RFC v3 07/10] iommu: Implement reserved_regions iommu-group sysfs file
Date 2016-11-15 14:20 +0100
Message-ID <sDLOz-5pg-45@gated-at.bofh.it> (permalink)
References <sDLER-5lG-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


A new iommu-group sysfs attribute file is introduced. It contains
the list of reserved regions for the iommu-group. Each reserved
region is described on a separate line:
- first field is the start IOVA address,
- second is the end IOVA address,

Signed-off-by: Eric Auger <eric.auger@redhat.com>

---

The file layout is inspired of /sys/bus/pci/devices/BDF/resource.
I also read Documentation/filesystems/sysfs.txt so I expect this
to be frowned upon.
---
 drivers/iommu/iommu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index e0fbcc5..ce9a465 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -32,6 +32,7 @@
 #include <linux/pci.h>
 #include <linux/bitops.h>
 #include <linux/property.h>
+#include <linux/list_sort.h>
 #include <trace/events/iommu.h>
 
 static struct kset *iommu_group_kset;
@@ -186,8 +187,47 @@ int iommu_get_group_resv_regions(struct iommu_group *group,
 }
 EXPORT_SYMBOL_GPL(iommu_get_group_resv_regions);
 
+static int iommu_resv_region_cmp(void *priv, struct list_head *a,
+			       struct list_head *b)
+{
+	struct iommu_resv_region *rega, *regb;
+
+	rega = container_of(a, struct iommu_resv_region, list);
+	regb = container_of(b, struct iommu_resv_region, list);
+
+	if (rega->start + rega->length - 1 < regb->start)
+		return -1;
+	if (regb->start + regb->length - 1 < rega->start)
+		return 1;
+	else
+		return 0;
+}
+
+static ssize_t iommu_group_show_resv_regions(struct iommu_group *group,
+					     char *buf)
+{
+	struct iommu_resv_region *region, *next;
+	struct list_head group_resv_regions;
+	char *str = buf;
+
+	INIT_LIST_HEAD(&group_resv_regions);
+	iommu_get_group_resv_regions(group, &group_resv_regions);
+	list_sort(NULL, &group_resv_regions, iommu_resv_region_cmp);
+
+	list_for_each_entry_safe(region, next, &group_resv_regions, list) {
+		str += sprintf(str, "0x%016llx 0x%016llx\n", region->start,
+			       region->start + region->length - 1);
+		kfree(region);
+	}
+
+	return (str - buf);
+}
+
 static IOMMU_GROUP_ATTR(name, S_IRUGO, iommu_group_show_name, NULL);
 
+static IOMMU_GROUP_ATTR(reserved_regions, S_IRUGO,
+			iommu_group_show_resv_regions, NULL);
+
 static void iommu_group_release(struct kobject *kobj)
 {
 	struct iommu_group *group = to_iommu_group(kobj);
@@ -202,6 +242,8 @@ static void iommu_group_release(struct kobject *kobj)
 	if (group->default_domain)
 		iommu_domain_free(group->default_domain);
 
+	iommu_group_remove_file(group, &iommu_group_attr_reserved_regions);
+
 	kfree(group->name);
 	kfree(group);
 }
@@ -265,6 +307,11 @@ struct iommu_group *iommu_group_alloc(void)
 	 */
 	kobject_put(&group->kobj);
 
+	ret = iommu_group_create_file(group,
+				      &iommu_group_attr_reserved_regions);
+	if (ret)
+		return ERR_PTR(ret);
+
 	pr_debug("Allocated group %d\n", group->id);
 
 	return group;
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC v3 00/10] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:10 +0100
  [RFC v3 02/10] iommu: Rename iommu_dm_regions into iommu_resv_regions Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:10 +0100
  [RFC v3 01/10] iommu/dma: Allow MSI-only cookies Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:10 +0100
  [RFC v3 05/10] iommu: Do not map reserved regions Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 08/10] iommu/vt-d: Implement reserved region get/put callbacks Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 10/10] vfio/type1: Get MSI cookie Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 09/10] iommu/arm-smmu: Implement reserved region get/put callbacks Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 03/10] iommu: Add new reserved IOMMU attributes Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 06/10] iommu: iommu_get_group_resv_regions Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 07/10] iommu: Implement reserved_regions iommu-group sysfs file Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  [RFC v3 04/10] iommu: iommu_alloc_resv_region Eric Auger <eric.auger@redhat.com> - 2016-11-15 14:20 +0100
  Re: [RFC v3 00/10] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA  reserved regions Auger Eric <eric.auger@redhat.com> - 2016-11-18 09:40 +0100
  RE: [RFC v3 00/10] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA         reserved regions Bharat Bhushan <bharat.bhushan@nxp.com> - 2016-11-18 11:10 +0100

csiph-web