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 1/4] iommu/vt-d: Modify device_def_domain_type() to use at runtime
Date: Tue, 20 Aug 2019 19:42:09 -0700	[thread overview]
Message-ID: <e11ba804b5e30477fe4219b12912b46af9c7f94a.1566353521.git.sai.praneeth.prakhya@intel.com> (raw)
In-Reply-To: <cover.1566353521.git.sai.praneeth.prakhya@intel.com>

device_def_domain_type() determines the domain type a device could have and
currently it's called only during boot time. Since the function is called
only during boot time, it *always* considers command line arguments like
"intel_iommu=igfx_off" and "iommu=pt" to determine the domain type of a
device. To support changing the domain of an iommu_group through sysfs,
this function has to be called at runtime as well. Hence, modify this
function such that command line arguments are considered to determine the
domain type of a device *only* when the system is booting and ignored if
the system is already up and running.

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>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
---
 drivers/iommu/intel-iommu.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index b7454ca4a87c..27c3c893530a 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2859,15 +2859,14 @@ static bool device_is_rmrr_locked(struct device *dev)
 }
 
 /*
- * Return the required default domain type for a specific device.
+ * Returns the possible default domain types a device could have.
  *
- * @dev: the device in query
- * @startup: true if this is during early boot
+ * @dev: The device in query
  *
  * Returns:
- *  - IOMMU_DOMAIN_DMA: device requires a dynamic mapping domain
- *  - IOMMU_DOMAIN_IDENTITY: device requires an identical mapping domain
- *  - 0: both identity and dynamic domains work for this device
+ *  - IOMMU_DOMAIN_DMA: Device should always be in dynamic mapping domain
+ *  - IOMMU_DOMAIN_IDENTITY: Device should always be in identity mapping domain
+ *  - 0: Device could be in any domain (i.e. identity or dynamic)
  */
 static int device_def_domain_type(struct device *dev)
 {
@@ -2884,11 +2883,22 @@ static int device_def_domain_type(struct device *dev)
 		if (pdev->untrusted)
 			return IOMMU_DOMAIN_DMA;
 
+		/*
+		 * Azalia device should always be in identity domain if
+		 * check_tylersburg_isoch() decides so.
+		 */
 		if ((iommu_identity_mapping & IDENTMAP_AZALIA) && IS_AZALIA(pdev))
 			return IOMMU_DOMAIN_IDENTITY;
 
-		if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev))
-			return IOMMU_DOMAIN_IDENTITY;
+		/*
+		 * intel_iommu=igfx_off should have it's effect only during
+		 * boot.
+		 */
+		if (system_state < SYSTEM_RUNNING) {
+			if ((iommu_identity_mapping & IDENTMAP_GFX) &&
+			    IS_GFX_DEVICE(pdev))
+				return IOMMU_DOMAIN_IDENTITY;
+		}
 
 		/*
 		 * We want to start off with all devices in the 1:1 domain, and
@@ -2919,8 +2929,13 @@ static int device_def_domain_type(struct device *dev)
 			return IOMMU_DOMAIN_DMA;
 	}
 
-	return (iommu_identity_mapping & IDENTMAP_ALL) ?
-			IOMMU_DOMAIN_IDENTITY : 0;
+	/* iommu=pt should have it's effect only during boot */
+	if (system_state < SYSTEM_RUNNING) {
+		if (iommu_identity_mapping & IDENTMAP_ALL)
+			return IOMMU_DOMAIN_IDENTITY;
+	}
+
+	return 0;
 }
 
 static void intel_iommu_init_qi(struct intel_iommu *iommu)
-- 
2.19.1

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

  reply	other threads:[~2019-08-21  2:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21  2:42 [PATCH 0/4] iommu: Add support to change default domain of a group Sai Praneeth Prakhya
2019-08-21  2:42 ` Sai Praneeth Prakhya [this message]
2019-08-21  2:42 ` [PATCH 2/4] iommu: Add device_def_domain_type() call back function to iommu_ops Sai Praneeth Prakhya
2019-08-21  2:42 ` [PATCH 3/4] iommu: Add support to change default domain of an iommu_group Sai Praneeth Prakhya
2019-09-03 12:50   ` Joerg Roedel
2019-09-04  3:09     ` Prakhya, Sai Praneeth
2019-09-04  3:17       ` Lu Baolu
2019-09-04 16:18         ` Prakhya, Sai Praneeth
2019-08-21  2:42 ` [PATCH 4/4] iommu: Document usage of "/sys/kernel/iommu_groups/<grp_id>/type" file Sai Praneeth Prakhya
2019-08-21 14:52   ` John Garry
2019-08-21 17:08     ` Sai Praneeth Prakhya

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=e11ba804b5e30477fe4219b12912b46af9c7f94a.1566353521.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).