[lkml]   [2020]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v9 3/4] iommu: Take lock before reading iommu group default domain type
From: Sai Praneeth Prakhya <>

"/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 <>
Cc: Joerg Roedel <>
Cc: Ashok Raj <>
Cc: Will Deacon <>
Cc: Sohil Mehta <>
Cc: Robin Murphy <>
Cc: Jacob Pan <>
Signed-off-by: Sai Praneeth Prakhya <>
Signed-off-by: Lu Baolu <>
drivers/iommu/iommu.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 716bd602b0ed..aad465c38067 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -501,6 +501,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) {
@@ -517,6 +518,7 @@ static ssize_t iommu_group_show_type(struct iommu_group *group,
+ mutex_unlock(&group->mutex);
strcpy(buf, type);

return strlen(type);
 \ /
  Last update: 2020-11-21 15:05    [W:0.070 / U:0.716 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site