aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2014-07-08 09:01:43 -0400
committerJoerg Roedel <jroedel@suse.de>2014-07-10 09:36:46 -0400
commit53d340ef4a19ccade5305fc38808cac04861b322 (patch)
treeb1051d9a4fc7cb1898500eff2fc2c00ed9546e4e /drivers/iommu
parentdc88db7ee9f9a0a850dcee5738031f888ba124b7 (diff)
iommu/amd: Add pasid_state->invalid flag
This is used to signal the ppr_notifer function that no more faults should be processes on this pasid_state. This way we can keep the pasid_state safely in the state-table so that it can be freed in the amd_iommu_unbind_pasid() function. This allows us to not hold a reference to the mm_struct during the whole pasid-binding-time. Signed-off-by: Joerg Roedel <jroedel@suse.de> Tested-by: Oded Gabbay <Oded.Gabbay@amd.com>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/amd_iommu_v2.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index 6ba707b998ff..69a46f1e963f 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -53,6 +53,7 @@ struct pasid_state {
53 struct pri_queue pri[PRI_QUEUE_SIZE]; /* PRI tag states */ 53 struct pri_queue pri[PRI_QUEUE_SIZE]; /* PRI tag states */
54 struct device_state *device_state; /* Link to our device_state */ 54 struct device_state *device_state; /* Link to our device_state */
55 int pasid; /* PASID index */ 55 int pasid; /* PASID index */
56 bool invalid; /* Used during teardown */
56 spinlock_t lock; /* Protect pri_queues and 57 spinlock_t lock; /* Protect pri_queues and
57 mmu_notifer_count */ 58 mmu_notifer_count */
58 wait_queue_head_t wq; /* To wait for count == 0 */ 59 wait_queue_head_t wq; /* To wait for count == 0 */
@@ -306,8 +307,17 @@ static void unbind_pasid(struct pasid_state *pasid_state)
306 307
307 domain = pasid_state->device_state->domain; 308 domain = pasid_state->device_state->domain;
308 309
310 /*
311 * Mark pasid_state as invalid, no more faults will we added to the
312 * work queue after this is visible everywhere.
313 */
314 pasid_state->invalid = true;
315
316 /* Make sure this is visible */
317 smp_wmb();
318
319 /* After this the device/pasid can't access the mm anymore */
309 amd_iommu_domain_clear_gcr3(domain, pasid_state->pasid); 320 amd_iommu_domain_clear_gcr3(domain, pasid_state->pasid);
310 clear_pasid_state(pasid_state->device_state, pasid_state->pasid);
311 321
312 /* Make sure no more pending faults are in the queue */ 322 /* Make sure no more pending faults are in the queue */
313 flush_workqueue(iommu_wq); 323 flush_workqueue(iommu_wq);
@@ -573,7 +583,7 @@ static int ppr_notifier(struct notifier_block *nb, unsigned long e, void *data)
573 goto out; 583 goto out;
574 584
575 pasid_state = get_pasid_state(dev_state, iommu_fault->pasid); 585 pasid_state = get_pasid_state(dev_state, iommu_fault->pasid);
576 if (pasid_state == NULL) { 586 if (pasid_state == NULL || pasid_state->invalid) {
577 /* We know the device but not the PASID -> send INVALID */ 587 /* We know the device but not the PASID -> send INVALID */
578 amd_iommu_complete_ppr(dev_state->pdev, iommu_fault->pasid, 588 amd_iommu_complete_ppr(dev_state->pdev, iommu_fault->pasid,
579 PPR_INVALID, tag); 589 PPR_INVALID, tag);
@@ -657,6 +667,7 @@ int amd_iommu_bind_pasid(struct pci_dev *pdev, int pasid,
657 pasid_state->mm = get_task_mm(task); 667 pasid_state->mm = get_task_mm(task);
658 pasid_state->device_state = dev_state; 668 pasid_state->device_state = dev_state;
659 pasid_state->pasid = pasid; 669 pasid_state->pasid = pasid;
670 pasid_state->invalid = false;
660 pasid_state->mn.ops = &iommu_mn; 671 pasid_state->mn.ops = &iommu_mn;
661 672
662 if (pasid_state->mm == NULL) 673 if (pasid_state->mm == NULL)
@@ -720,6 +731,9 @@ void amd_iommu_unbind_pasid(struct pci_dev *pdev, int pasid)
720 */ 731 */
721 put_pasid_state(pasid_state); 732 put_pasid_state(pasid_state);
722 733
734 /* Clear the pasid state so that the pasid can be re-used */
735 clear_pasid_state(dev_state, pasid_state->pasid);
736
723 /* This will call the mn_release function and unbind the PASID */ 737 /* This will call the mn_release function and unbind the PASID */
724 mmu_notifier_unregister(&pasid_state->mn, pasid_state->mm); 738 mmu_notifier_unregister(&pasid_state->mn, pasid_state->mm);
725 739