[PATCH V3 2/3] iommu: Take lock before reading iommu_group default domain type

Sai Praneeth Prakhya sai.praneeth.prakhya at intel.com
Thu May 28 19:23:46 UTC 2020

"/sys/kernel/iommu_groups/<grp_id>/type" file could be read to find out the
default domain type of an iommu group. The default domain of an iommu group
doesn't change after booting and hence could be read directly. But,
after addding support to dynamically change iommu group default domain, the
above assumption no longer stays valid.

iommu group default domain type could be changed at any time by writing to
"/sys/kernel/iommu_groups/<grp_id>/type". So, take group mutex before
reading iommu group default domain type so that the user wouldn't see stale
values or iommu_group_show_type() doesn't try to derefernce stale pointers.

Cc: Christoph Hellwig <hch at lst.de>
Cc: Joerg Roedel <joro at 8bytes.org>
Cc: Ashok Raj <ashok.raj at intel.com>
Cc: Will Deacon <will.deacon at arm.com>
Cc: Lu Baolu <baolu.lu at linux.intel.com>
Cc: Sohil Mehta <sohil.mehta at intel.com>
Cc: Robin Murphy <robin.murphy at arm.com>
Cc: Jacob Pan <jacob.jun.pan at linux.intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya at intel.com>
 drivers/iommu/iommu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 2b6cca799055..fae8a4e1c7ab 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -500,6 +500,7 @@ static ssize_t iommu_group_show_type(struct iommu_group *group,
 	char *type = "unknown\n";
+	mutex_lock(&group->mutex);
 	if (group->default_domain) {
 		switch (group->default_domain->type) {
@@ -516,6 +517,7 @@ static ssize_t iommu_group_show_type(struct iommu_group *group,
+	mutex_unlock(&group->mutex);
 	strcpy(buf, type);
 	return strlen(type);

More information about the iommu mailing list