iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
To: iommu@lists.linux-foundation.org
Cc: Ashok Raj <ashok.raj@intel.com>,
	Will Deacon <will.deacon@arm.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Christoph Hellwig <hch@lst.de>
Subject: [PATCH V7 2/3] iommu: Take lock before reading iommu group default domain type
Date: Mon,  7 Sep 2020 20:54:46 -0700	[thread overview]
Message-ID: <1c874d14614921c7283de594fb69d430e3be6cc7.1595619936.git.sai.praneeth.prakhya@intel.com> (raw)
Message-ID: <20200908035446.uP7P3j9uarYL682SlvS2N5V4AY-qCSAJCUyD80RE_tM@z> (raw)
In-Reply-To: <cover.1595619936.git.sai.praneeth.prakhya@intel.com>
In-Reply-To: <cover.1595619936.git.sai.praneeth.prakhya@intel.com>

"/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@lst.de>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Cc: Sohil Mehta <sohil.mehta@intel.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@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 939b37727722..b1607832ede9 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) {
 		case IOMMU_DOMAIN_BLOCKED:
@@ -517,6 +518,7 @@ static ssize_t iommu_group_show_type(struct iommu_group *group,
 			break;
 		}
 	}
+	mutex_unlock(&group->mutex);
 	strcpy(buf, type);
 
 	return strlen(type);
-- 
2.19.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  parent reply	other threads:[~2020-09-06  2:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 19:51 [PATCH V5 0/3] iommu: Add support to change default domain of an iommu group Sai Praneeth Prakhya
2020-07-24 19:51 ` [PATCH V5 1/3] " Sai Praneeth Prakhya
2020-08-24  5:17   ` [PATCH V6 " Sai Praneeth Prakhya
2020-09-04  8:30   ` Joerg Roedel
2020-09-04 19:11     ` Prakhya, Sai Praneeth
2020-09-04 21:42       ` Joerg Roedel
2020-09-04 22:25         ` Prakhya, Sai Praneeth
2020-09-08  3:54   ` [PATCH V7 " Sai Praneeth Prakhya
2020-07-24 19:51 ` Sai Praneeth Prakhya [this message]
2020-08-24  5:17   ` [PATCH V6 2/3] iommu: Take lock before reading iommu group default domain type Sai Praneeth Prakhya
2020-09-08  3:54   ` [PATCH V7 " Sai Praneeth Prakhya
2020-07-24 19:52 ` [PATCH V5 3/3] iommu: Document usage of "/sys/kernel/iommu_groups/<grp_id>/type" file Sai Praneeth Prakhya
2020-08-24  5:17   ` [PATCH V6 " Sai Praneeth Prakhya
2020-09-08  3:54   ` [PATCH V7 " Sai Praneeth Prakhya
2020-07-29 12:37 ` [PATCH V5 0/3] iommu: Add support to change default domain of an iommu group Joerg Roedel
2020-07-29 20:24   ` Prakhya, Sai Praneeth
2020-08-24  5:17 ` [PATCH V6 " Sai Praneeth Prakhya
2020-09-08  3:54 ` [PATCH V7 " Sai Praneeth Prakhya
2020-09-24 17:21 ` Raj, Ashok
2020-09-25  7:34   ` Joerg Roedel
2020-09-25 16:35     ` Raj, Ashok
2020-09-29  5:28     ` Raj, Ashok

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c874d14614921c7283de594fb69d430e3be6cc7.1595619936.git.sai.praneeth.prakhya@intel.com \
    --to=sai.praneeth.prakhya@intel.com \
    --cc=ashok.raj@intel.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=robin.murphy@arm.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).