From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 19/19] iommu/vt-d: Drain PRQs when domain removed from RID
Date: Mon, 4 Nov 2024 09:40:39 +0800 [thread overview]
Message-ID: <20241104014040.106100-20-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20241104014040.106100-1-baolu.lu@linux.intel.com>
As this iommu driver now supports page faults for requests without
PASID, page requests should be drained when a domain is removed from
the RID2PASID entry.
This results in the intel_iommu_drain_pasid_prq() call being moved to
intel_pasid_tear_down_entry(). This indicates that when a translation
is removed from any PASID entry and the PRI has been enabled on the
device, page requests are drained in the domain detachment path.
The intel_iommu_drain_pasid_prq() helper has been modified to support
sending device TLB invalidation requests for both PASID and non-PASID
cases.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
Link: https://lore.kernel.org/r/20241101045543.70086-1-baolu.lu@linux.intel.com
---
drivers/iommu/intel/iommu.c | 1 -
drivers/iommu/intel/pasid.c | 1 +
drivers/iommu/intel/prq.c | 26 +++++++++-----------------
3 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 87a3563dfe54..3878f35be09d 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4069,7 +4069,6 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
intel_iommu_debugfs_remove_dev_pasid(dev_pasid);
kfree(dev_pasid);
intel_pasid_tear_down_entry(iommu, dev, pasid, false);
- intel_iommu_drain_pasid_prq(dev, pasid);
}
static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index 7e76062a7ad2..31665fb62e1c 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -265,6 +265,7 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
iommu->flush.flush_iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH);
devtlb_invalidation_with_pasid(iommu, dev, pasid);
+ intel_iommu_drain_pasid_prq(dev, pasid);
}
/*
diff --git a/drivers/iommu/intel/prq.c b/drivers/iommu/intel/prq.c
index 621cd26504b3..c2d792db52c3 100644
--- a/drivers/iommu/intel/prq.c
+++ b/drivers/iommu/intel/prq.c
@@ -63,26 +63,18 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)
struct dmar_domain *domain;
struct intel_iommu *iommu;
struct qi_desc desc[3];
- struct pci_dev *pdev;
int head, tail;
u16 sid, did;
- int qdep;
info = dev_iommu_priv_get(dev);
- if (WARN_ON(!info || !dev_is_pci(dev)))
- return;
-
if (!info->pri_enabled)
return;
iommu = info->iommu;
domain = info->domain;
- pdev = to_pci_dev(dev);
sid = PCI_DEVID(info->bus, info->devfn);
did = domain ? domain_id_iommu(domain, iommu) : FLPT_DEFAULT_DID;
- qdep = pci_ats_queue_depth(pdev);
-
/*
* Check and wait until all pending page requests in the queue are
* handled by the prq handling thread.
@@ -114,15 +106,15 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)
desc[0].qw0 = QI_IWD_STATUS_DATA(QI_DONE) |
QI_IWD_FENCE |
QI_IWD_TYPE;
- desc[1].qw0 = QI_EIOTLB_PASID(pasid) |
- QI_EIOTLB_DID(did) |
- QI_EIOTLB_GRAN(QI_GRAN_NONG_PASID) |
- QI_EIOTLB_TYPE;
- desc[2].qw0 = QI_DEV_EIOTLB_PASID(pasid) |
- QI_DEV_EIOTLB_SID(sid) |
- QI_DEV_EIOTLB_QDEP(qdep) |
- QI_DEIOTLB_TYPE |
- QI_DEV_IOTLB_PFSID(info->pfsid);
+ if (pasid == IOMMU_NO_PASID) {
+ qi_desc_iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH, &desc[1]);
+ qi_desc_dev_iotlb(sid, info->pfsid, info->ats_qdep, 0,
+ MAX_AGAW_PFN_WIDTH, &desc[2]);
+ } else {
+ qi_desc_piotlb(did, pasid, 0, -1, 0, &desc[1]);
+ qi_desc_dev_iotlb_pasid(sid, info->pfsid, pasid, info->ats_qdep,
+ 0, MAX_AGAW_PFN_WIDTH, &desc[2]);
+ }
qi_retry:
reinit_completion(&iommu->prq_complete);
qi_submit_sync(iommu, desc, 3, QI_OPT_WAIT_DRAIN);
--
2.43.0
next prev parent reply other threads:[~2024-11-04 1:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-04 1:40 [PATCH 00/19] [PULL REQUEST] Intel IOMMU updates for v6.13 Lu Baolu
2024-11-04 1:40 ` [PATCH 01/19] iommu/vt-d: Add domain_alloc_paging support Lu Baolu
2024-11-04 1:40 ` [PATCH 02/19] iommu/vt-d: Remove unused domain_alloc callback Lu Baolu
2024-11-04 1:40 ` [PATCH 03/19] iommu/vt-d: Enhance compatibility check for paging domain attach Lu Baolu
2024-11-04 1:40 ` [PATCH 04/19] iommu/vt-d: Remove domain_update_iommu_cap() Lu Baolu
2024-11-04 1:40 ` [PATCH 05/19] iommu/vt-d: Remove domain_update_iommu_superpage() Lu Baolu
2024-11-04 1:40 ` [PATCH 06/19] iommu/vt-d: Refactor first_level_by_default() Lu Baolu
2024-11-04 1:40 ` [PATCH 07/19] iommu/vt-d: Refine intel_iommu_domain_alloc_user() Lu Baolu
2024-11-04 1:40 ` [PATCH 08/19] iommu/vt-d: Use PCI_DEVID() macro Lu Baolu
2024-11-04 1:40 ` [PATCH 09/19] iommu/vt-d: Increase buffer size for device name Lu Baolu
2024-11-04 1:40 ` [PATCH 10/19] iommu/vt-d: Remove unused dmar_msi_read Lu Baolu
2024-11-04 1:40 ` [PATCH 11/19] iommu/vt-d: Drop s1_pgtbl from dmar_domain Lu Baolu
2024-11-04 1:40 ` [PATCH 12/19] iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes() Lu Baolu
2024-11-04 1:40 ` [PATCH 13/19] iommu/vt-d: Fix checks and print in pgtable_walk() Lu Baolu
2024-11-04 1:40 ` [PATCH 14/19] iommu/vt-d: Separate page request queue from SVM Lu Baolu
2024-11-04 1:40 ` [PATCH 15/19] iommu/vt-d: Remove the pasid present check in prq_event_thread Lu Baolu
2024-11-04 1:40 ` [PATCH 16/19] iommu/vt-d: Move IOMMU_IOPF into INTEL_IOMMU Lu Baolu
2024-11-04 1:40 ` [PATCH 17/19] iommufd: Enable PRI when doing the iommufd_hwpt_alloc Lu Baolu
2024-11-04 1:40 ` [PATCH 18/19] iommu/vt-d: Drop pasid requirement for prq initialization Lu Baolu
2024-11-04 1:40 ` Lu Baolu [this message]
2024-11-05 12:33 ` [PATCH 00/19] [PULL REQUEST] Intel IOMMU updates for v6.13 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=20241104014040.106100-20-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.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