From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>,
Ashok Raj <ashok.raj@intel.com>,
Aditya Srivastava <yashsri421@gmail.com>,
Randy Dunlap <rdunlap@infradead.org>,
YueHaibing <yuehaibing@huawei.com>,
"Gustavo A . R . Silva" <gustavoars@kernel.org>,
iommu@lists.linux-foundation.org,
Colin Ian King <colin.king@canonical.com>,
Will Deacon <will@kernel.org>
Subject: [PATCH 10/23] iommu/vt-d: Allocate/register iopf queue for sva devices
Date: Thu, 10 Jun 2021 10:01:02 +0800 [thread overview]
Message-ID: <20210610020115.1637656-11-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20210610020115.1637656-1-baolu.lu@linux.intel.com>
This allocates and registers the iopf queue infrastructure for devices
which want to support IO page fault for SVA.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210520031531.712333-1-baolu.lu@linux.intel.com
---
include/linux/intel-iommu.h | 2 ++
drivers/iommu/intel/iommu.c | 66 ++++++++++++++++++++++++++-----------
drivers/iommu/intel/svm.c | 37 +++++++++++++++++----
3 files changed, 79 insertions(+), 26 deletions(-)
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 4e8bb186daa7..222520d149c1 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -606,6 +606,8 @@ struct intel_iommu {
struct completion prq_complete;
struct ioasid_allocator_ops pasid_allocator; /* Custom allocator for PASIDs */
#endif
+ struct iopf_queue *iopf_queue;
+ unsigned char iopfq_name[16];
struct q_inval *qi; /* Queued invalidation info */
u32 *iommu_state; /* Store iommu states between suspend and resume.*/
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 0ca7f8a2f38e..e78773d46d7d 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -46,6 +46,7 @@
#include <asm/iommu.h>
#include "../irq_remapping.h"
+#include "../iommu-sva-lib.h"
#include "pasid.h"
#include "cap_audit.h"
@@ -5338,6 +5339,34 @@ static int intel_iommu_disable_auxd(struct device *dev)
return 0;
}
+static int intel_iommu_enable_sva(struct device *dev)
+{
+ struct device_domain_info *info = get_domain_info(dev);
+ struct intel_iommu *iommu = info->iommu;
+
+ if (!info || !iommu || dmar_disabled)
+ return -EINVAL;
+
+ if (!(iommu->flags & VTD_FLAG_SVM_CAPABLE))
+ return -ENODEV;
+
+ if (intel_iommu_enable_pasid(iommu, dev))
+ return -ENODEV;
+
+ if (!info->pasid_enabled || !info->pri_enabled || !info->ats_enabled)
+ return -EINVAL;
+
+ return iopf_queue_add_device(iommu->iopf_queue, dev);
+}
+
+static int intel_iommu_disable_sva(struct device *dev)
+{
+ struct device_domain_info *info = get_domain_info(dev);
+ struct intel_iommu *iommu = info->iommu;
+
+ return iopf_queue_remove_device(iommu->iopf_queue, dev);
+}
+
/*
* A PCI express designated vendor specific extended capability is defined
* in the section 3.7 of Intel scalable I/O virtualization technical spec
@@ -5399,38 +5428,37 @@ intel_iommu_dev_has_feat(struct device *dev, enum iommu_dev_features feat)
static int
intel_iommu_dev_enable_feat(struct device *dev, enum iommu_dev_features feat)
{
- if (feat == IOMMU_DEV_FEAT_AUX)
+ switch (feat) {
+ case IOMMU_DEV_FEAT_AUX:
return intel_iommu_enable_auxd(dev);
- if (feat == IOMMU_DEV_FEAT_IOPF)
+ case IOMMU_DEV_FEAT_IOPF:
return intel_iommu_dev_has_feat(dev, feat) ? 0 : -ENODEV;
- if (feat == IOMMU_DEV_FEAT_SVA) {
- struct device_domain_info *info = get_domain_info(dev);
-
- if (!info)
- return -EINVAL;
-
- if (intel_iommu_enable_pasid(info->iommu, dev))
- return -ENODEV;
+ case IOMMU_DEV_FEAT_SVA:
+ return intel_iommu_enable_sva(dev);
- if (!info->pasid_enabled || !info->pri_enabled || !info->ats_enabled)
- return -EINVAL;
-
- if (info->iommu->flags & VTD_FLAG_SVM_CAPABLE)
- return 0;
+ default:
+ return -ENODEV;
}
-
- return -ENODEV;
}
static int
intel_iommu_dev_disable_feat(struct device *dev, enum iommu_dev_features feat)
{
- if (feat == IOMMU_DEV_FEAT_AUX)
+ switch (feat) {
+ case IOMMU_DEV_FEAT_AUX:
return intel_iommu_disable_auxd(dev);
- return -ENODEV;
+ case IOMMU_DEV_FEAT_IOPF:
+ return 0;
+
+ case IOMMU_DEV_FEAT_SVA:
+ return intel_iommu_disable_sva(dev);
+
+ default:
+ return -ENODEV;
+ }
}
static bool
diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
index d51ddece4259..4dc3ab36e9ae 100644
--- a/drivers/iommu/intel/svm.c
+++ b/drivers/iommu/intel/svm.c
@@ -84,6 +84,7 @@ svm_lookup_device_by_dev(struct intel_svm *svm, struct device *dev)
int intel_svm_enable_prq(struct intel_iommu *iommu)
{
+ struct iopf_queue *iopfq;
struct page *pages;
int irq, ret;
@@ -100,13 +101,20 @@ int intel_svm_enable_prq(struct intel_iommu *iommu)
pr_err("IOMMU: %s: Failed to create IRQ vector for page request queue\n",
iommu->name);
ret = -EINVAL;
- err:
- free_pages((unsigned long)iommu->prq, PRQ_ORDER);
- iommu->prq = NULL;
- return ret;
+ goto free_prq;
}
iommu->pr_irq = irq;
+ snprintf(iommu->iopfq_name, sizeof(iommu->iopfq_name),
+ "dmar%d-iopfq", iommu->seq_id);
+ iopfq = iopf_queue_alloc(iommu->iopfq_name);
+ if (!iopfq) {
+ pr_err("IOMMU: %s: Failed to allocate iopf queue\n", iommu->name);
+ ret = -ENOMEM;
+ goto free_hwirq;
+ }
+ iommu->iopf_queue = iopfq;
+
snprintf(iommu->prq_name, sizeof(iommu->prq_name), "dmar%d-prq", iommu->seq_id);
ret = request_threaded_irq(irq, NULL, prq_event_thread, IRQF_ONESHOT,
@@ -114,9 +122,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu)
if (ret) {
pr_err("IOMMU: %s: Failed to request IRQ for page request queue\n",
iommu->name);
- dmar_free_hwirq(irq);
- iommu->pr_irq = 0;
- goto err;
+ goto free_iopfq;
}
dmar_writeq(iommu->reg + DMAR_PQH_REG, 0ULL);
dmar_writeq(iommu->reg + DMAR_PQT_REG, 0ULL);
@@ -125,6 +131,18 @@ int intel_svm_enable_prq(struct intel_iommu *iommu)
init_completion(&iommu->prq_complete);
return 0;
+
+free_iopfq:
+ iopf_queue_free(iommu->iopf_queue);
+ iommu->iopf_queue = NULL;
+free_hwirq:
+ dmar_free_hwirq(irq);
+ iommu->pr_irq = 0;
+free_prq:
+ free_pages((unsigned long)iommu->prq, PRQ_ORDER);
+ iommu->prq = NULL;
+
+ return ret;
}
int intel_svm_finish_prq(struct intel_iommu *iommu)
@@ -139,6 +157,11 @@ int intel_svm_finish_prq(struct intel_iommu *iommu)
iommu->pr_irq = 0;
}
+ if (iommu->iopf_queue) {
+ iopf_queue_free(iommu->iopf_queue);
+ iommu->iopf_queue = NULL;
+ }
+
free_pages((unsigned long)iommu->prq, PRQ_ORDER);
iommu->prq = NULL;
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2021-06-10 2:03 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-10 2:00 [PATCH 00/23] [PULL REQUEST] Intel IOMMU Updates for Linux v5.14 Lu Baolu
2021-06-10 2:00 ` [PATCH 01/23] iommu/vt-d: Remove redundant assignment to variable agaw Lu Baolu
2021-06-10 2:00 ` [PATCH 02/23] iommu/vt-d: Fix kernel-doc syntax in file header Lu Baolu
2021-06-10 2:00 ` [PATCH 03/23] iommu/vt-d: Tweak the description of a DMA fault Lu Baolu
2021-06-10 2:00 ` [PATCH 04/23] iommu/vt-d: Select PCI_ATS explicitly Lu Baolu
2021-06-10 2:00 ` [PATCH 05/23] iommu/vt-d: Support asynchronous IOMMU nested capabilities Lu Baolu
2021-06-10 2:00 ` [PATCH 06/23] iommu/vt-d: Add pasid private data helpers Lu Baolu
2021-06-10 2:00 ` [PATCH 07/23] iommu/vt-d: Use iommu_sva_alloc(free)_pasid() helpers Lu Baolu
2021-06-10 2:01 ` [PATCH 08/23] iommu/vt-d: Use common helper to lookup svm devices Lu Baolu
2021-06-10 2:01 ` [PATCH 09/23] iommu/vt-d: Refactor prq_event_thread() Lu Baolu
2021-06-10 2:01 ` Lu Baolu [this message]
2021-06-10 2:01 ` [PATCH 11/23] iommu/vt-d: Report prq to io-pgfault framework Lu Baolu
2021-06-10 2:01 ` [PATCH 12/23] iommu/vt-d: Add prq_report trace event Lu Baolu
2021-06-10 2:01 ` [PATCH 13/23] iommu/vt-d: Add common code for dmar latency performance monitors Lu Baolu
2021-06-10 2:01 ` [PATCH 14/23] iommu/vt-d: Expose latency monitor data through debugfs Lu Baolu
2021-06-10 2:01 ` [PATCH 15/23] iommu/vt-d: Add cache invalidation latency sampling Lu Baolu
2021-06-10 2:01 ` [PATCH 16/23] iommu/vt-d: Add PRQ handling " Lu Baolu
2021-06-10 2:01 ` [PATCH 17/23] iommu/vt-d: Fix out-bounds-warning in intel/svm.c Lu Baolu
2021-06-10 2:01 ` [PATCH 18/23] iommu/vt-d: Use DEVICE_ATTR_RO macro Lu Baolu
2021-06-10 2:01 ` [PATCH 19/23] iommu/vt-d: Use bitfields for DMAR capabilities Lu Baolu
2021-06-10 2:01 ` [PATCH 20/23] iommu/vt-d: Removed unused iommu_count in dmar domain Lu Baolu
2021-06-10 2:01 ` [PATCH 21/23] iommu/vt-d: Remove unnecessary braces Lu Baolu
2021-06-10 2:01 ` [PATCH 22/23] iommu/vt-d: Define counter explicitly as unsigned int Lu Baolu
2021-06-10 2:01 ` [PATCH 23/23] iommu/vt-d: No need to typecast Lu Baolu
2021-06-10 7:13 ` [PATCH 00/23] [PULL REQUEST] Intel IOMMU Updates for Linux v5.14 Joerg Roedel
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=20210610020115.1637656-11-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=colin.king@canonical.com \
--cc=fenghua.yu@intel.com \
--cc=gustavoars@kernel.org \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=rdunlap@infradead.org \
--cc=will@kernel.org \
--cc=yashsri421@gmail.com \
--cc=yuehaibing@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.