Skip to content

Commit 06f4b8d

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Remove unnecessary SVA data accesses in page fault path
The existing I/O page fault handling code accesses the per-PASID SVA data structures. This is unnecessary and makes the fault handling code only suitable for SVA scenarios. This removes the SVA data accesses from the I/O page fault reporting and responding code, so that the fault handling code could be generic. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent f76349c commit 06f4b8d

File tree

2 files changed

+8
-54
lines changed

2 files changed

+8
-54
lines changed

drivers/iommu/intel/iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ struct intel_iommu {
586586
#ifdef CONFIG_INTEL_IOMMU_SVM
587587
struct page_req_dsc *prq;
588588
unsigned char prq_name[16]; /* Name for PRQ interrupt */
589+
unsigned long prq_seq_number;
589590
struct completion prq_complete;
590591
struct ioasid_allocator_ops pasid_allocator; /* Custom allocator for PASIDs */
591592
#endif
@@ -761,7 +762,6 @@ struct intel_svm_dev {
761762
struct device *dev;
762763
struct intel_iommu *iommu;
763764
struct iommu_sva sva;
764-
unsigned long prq_seq_number;
765765
u32 pasid;
766766
int users;
767767
u16 did;

drivers/iommu/intel/svm.c

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ static void *pasid_private_find(ioasid_t pasid)
4848
return xa_load(&pasid_private_array, pasid);
4949
}
5050

51-
static struct intel_svm_dev *
52-
svm_lookup_device_by_sid(struct intel_svm *svm, u16 sid)
53-
{
54-
struct intel_svm_dev *sdev = NULL, *t;
55-
56-
rcu_read_lock();
57-
list_for_each_entry_rcu(t, &svm->devs, list) {
58-
if (t->sid == sid) {
59-
sdev = t;
60-
break;
61-
}
62-
}
63-
rcu_read_unlock();
64-
65-
return sdev;
66-
}
67-
6851
static struct intel_svm_dev *
6952
svm_lookup_device_by_dev(struct intel_svm *svm, struct device *dev)
7053
{
@@ -706,11 +689,10 @@ static void handle_bad_prq_event(struct intel_iommu *iommu,
706689

707690
static irqreturn_t prq_event_thread(int irq, void *d)
708691
{
709-
struct intel_svm_dev *sdev = NULL;
710692
struct intel_iommu *iommu = d;
711-
struct intel_svm *svm = NULL;
712693
struct page_req_dsc *req;
713694
int head, tail, handled;
695+
struct pci_dev *pdev;
714696
u64 address;
715697

716698
/*
@@ -730,8 +712,6 @@ static irqreturn_t prq_event_thread(int irq, void *d)
730712
pr_err("IOMMU: %s: Page request without PASID\n",
731713
iommu->name);
732714
bad_req:
733-
svm = NULL;
734-
sdev = NULL;
735715
handle_bad_prq_event(iommu, req, QI_RESP_INVALID);
736716
goto prq_advance;
737717
}
@@ -758,34 +738,19 @@ static irqreturn_t prq_event_thread(int irq, void *d)
758738
if (unlikely(req->lpig && !req->rd_req && !req->wr_req))
759739
goto prq_advance;
760740

761-
if (!svm || svm->pasid != req->pasid) {
762-
/*
763-
* It can't go away, because the driver is not permitted
764-
* to unbind the mm while any page faults are outstanding.
765-
*/
766-
svm = pasid_private_find(req->pasid);
767-
if (IS_ERR_OR_NULL(svm) || (svm->flags & SVM_FLAG_SUPERVISOR_MODE))
768-
goto bad_req;
769-
}
770-
771-
if (!sdev || sdev->sid != req->rid) {
772-
sdev = svm_lookup_device_by_sid(svm, req->rid);
773-
if (!sdev)
774-
goto bad_req;
775-
}
776-
777-
sdev->prq_seq_number++;
778-
741+
pdev = pci_get_domain_bus_and_slot(iommu->segment,
742+
PCI_BUS_NUM(req->rid),
743+
req->rid & 0xff);
779744
/*
780745
* If prq is to be handled outside iommu driver via receiver of
781746
* the fault notifiers, we skip the page response here.
782747
*/
783-
if (intel_svm_prq_report(iommu, sdev->dev, req))
748+
if (!pdev || intel_svm_prq_report(iommu, &pdev->dev, req))
784749
handle_bad_prq_event(iommu, req, QI_RESP_INVALID);
785750

786-
trace_prq_report(iommu, sdev->dev, req->qw_0, req->qw_1,
751+
trace_prq_report(iommu, &pdev->dev, req->qw_0, req->qw_1,
787752
req->priv_data[0], req->priv_data[1],
788-
sdev->prq_seq_number);
753+
iommu->prq_seq_number++);
789754
prq_advance:
790755
head = (head + sizeof(*req)) & PRQ_RING_MASK;
791756
}
@@ -881,8 +846,6 @@ int intel_svm_page_response(struct device *dev,
881846
struct iommu_page_response *msg)
882847
{
883848
struct iommu_fault_page_request *prm;
884-
struct intel_svm_dev *sdev = NULL;
885-
struct intel_svm *svm = NULL;
886849
struct intel_iommu *iommu;
887850
bool private_present;
888851
bool pasid_present;
@@ -901,8 +864,6 @@ int intel_svm_page_response(struct device *dev,
901864
if (!msg || !evt)
902865
return -EINVAL;
903866

904-
mutex_lock(&pasid_mutex);
905-
906867
prm = &evt->fault.prm;
907868
sid = PCI_DEVID(bus, devfn);
908869
pasid_present = prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID;
@@ -919,12 +880,6 @@ int intel_svm_page_response(struct device *dev,
919880
goto out;
920881
}
921882

922-
ret = pasid_to_svm_sdev(dev, prm->pasid, &svm, &sdev);
923-
if (ret || !sdev) {
924-
ret = -ENODEV;
925-
goto out;
926-
}
927-
928883
/*
929884
* Per VT-d spec. v3.0 ch7.7, system software must respond
930885
* with page group response if private data is present (PDP)
@@ -954,6 +909,5 @@ int intel_svm_page_response(struct device *dev,
954909
qi_submit_sync(iommu, &desc, 1, 0);
955910
}
956911
out:
957-
mutex_unlock(&pasid_mutex);
958912
return ret;
959913
}

0 commit comments

Comments
 (0)