From: John Garry via iommu <iommu@lists.linux-foundation.org>
To: <joro@8bytes.org>, <will@kernel.org>, <robin.murphy@arm.com>
Cc: jean-philippe@linaro.org, jasowang@redhat.com, mst@redhat.com,
linuxarm@huawei.com, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
iommu@lists.linux-foundation.org
Subject: [PATCH RESEND v5 3/5] iommu: Allow iommu_change_dev_def_domain() realloc same default domain type
Date: Mon, 4 Apr 2022 19:27:12 +0800 [thread overview]
Message-ID: <1649071634-188535-4-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1649071634-188535-1-git-send-email-john.garry@huawei.com>
Allow iommu_change_dev_def_domain() to create a new default domain, keeping
the same as current.
Also remove comment about the function purpose, which will become stale.
Signed-off-by: John Garry <john.garry@huawei.com>
---
drivers/iommu/iommu.c | 49 ++++++++++++++++++++++---------------------
include/linux/iommu.h | 1 +
2 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0dd766030baf..10bb10c2a210 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2863,6 +2863,7 @@ u32 iommu_sva_get_pasid(struct iommu_sva *handle)
}
EXPORT_SYMBOL_GPL(iommu_sva_get_pasid);
+
/*
* Changes the default domain of an iommu group that has *only* one device
*
@@ -2873,10 +2874,6 @@ EXPORT_SYMBOL_GPL(iommu_sva_get_pasid);
*
* Returns 0 on success and error code on failure
*
- * Note:
- * 1. Presently, this function is called only when user requests to change the
- * group's default domain type through /sys/kernel/iommu_groups/<grp_id>/type
- * Please take a closer look if intended to use for other purposes.
*/
static int iommu_change_dev_def_domain(struct iommu_group *group,
struct device *prev_dev, int type)
@@ -2929,28 +2926,32 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
goto out;
}
- dev_def_dom = iommu_get_def_domain_type(dev);
- if (!type) {
+ if (type == __IOMMU_DOMAIN_SAME) {
+ type = prev_dom->type;
+ } else {
+ dev_def_dom = iommu_get_def_domain_type(dev);
+ if (!type) {
+ /*
+ * If the user hasn't requested any specific type of domain and
+ * if the device supports both the domains, then default to the
+ * domain the device was booted with
+ */
+ type = dev_def_dom ? : iommu_def_domain_type;
+ } else if (dev_def_dom && type != dev_def_dom) {
+ dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n",
+ iommu_domain_type_str(type));
+ ret = -EINVAL;
+ goto out;
+ }
+
/*
- * If the user hasn't requested any specific type of domain and
- * if the device supports both the domains, then default to the
- * domain the device was booted with
+ * Switch to a new domain only if the requested domain type is different
+ * from the existing default domain type
*/
- type = dev_def_dom ? : iommu_def_domain_type;
- } else if (dev_def_dom && type != dev_def_dom) {
- dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n",
- iommu_domain_type_str(type));
- ret = -EINVAL;
- goto out;
- }
-
- /*
- * Switch to a new domain only if the requested domain type is different
- * from the existing default domain type
- */
- if (prev_dom->type == type) {
- ret = 0;
- goto out;
+ if (prev_dom->type == type) {
+ ret = 0;
+ goto out;
+ }
}
/* We can bring up a flush queue without tearing down the domain */
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 9208eca4b0d1..b141cf71c7af 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -63,6 +63,7 @@ struct iommu_domain_geometry {
implementation */
#define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */
#define __IOMMU_DOMAIN_DMA_FQ (1U << 3) /* DMA-API uses flush queue */
+#define __IOMMU_DOMAIN_SAME (1U << 4) /* Keep same type (internal) */
/*
* This are the possible domain-types
--
2.26.2
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2022-04-04 11:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 11:27 [PATCH RESEND v5 0/5] iommu: Allow IOVA rcache range be configured John Garry via iommu
2022-04-04 11:27 ` [PATCH RESEND v5 1/5] iommu: Refactor iommu_group_store_type() John Garry via iommu
2022-04-07 7:40 ` Leizhen (ThunderTown) via iommu
2022-07-06 12:00 ` Will Deacon
2022-07-06 12:03 ` John Garry via iommu
2022-07-06 12:12 ` Will Deacon
2022-04-04 11:27 ` [PATCH RESEND v5 2/5] iova: Allow rcache range upper limit to be flexible John Garry via iommu
2022-04-07 7:52 ` Leizhen (ThunderTown) via iommu
2022-07-06 12:11 ` Will Deacon
2022-07-06 12:10 ` Will Deacon
2022-04-04 11:27 ` John Garry via iommu [this message]
2022-04-04 11:27 ` [PATCH RESEND v5 4/5] iommu: Allow max opt DMA len be set for a group via sysfs John Garry via iommu
2022-04-07 8:21 ` Leizhen (ThunderTown) via iommu
2022-04-07 14:00 ` John Garry via iommu
2022-04-04 11:27 ` [PATCH RESEND v5 5/5] iova: Add iova_len argument to iova_domain_init_rcaches() John Garry via iommu
2022-04-07 8:27 ` Leizhen (ThunderTown) via iommu
2022-04-07 13:52 ` John Garry via iommu
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=1649071634-188535-4-git-send-email-john.garry@huawei.com \
--to=iommu@lists.linux-foundation.org \
--cc=jasowang@redhat.com \
--cc=jean-philippe@linaro.org \
--cc=john.garry@huawei.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mst@redhat.com \
--cc=robin.murphy@arm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=will@kernel.org \
/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