iommu/amd: Don't call the inv_ctx_cb when pasid is not set up
On the error path of amd_iommu_bind_pasid() we call mmu_notifier_unregister() for cleanup. This calls mn_release() which calls the users inv_ctx_cb function if one is available. Since the pasid is not set up yet there is nothing the user can to tear down in this call-back. So don't call inv_ctx_cb on the error path of amd_iommu_unbind_pasid() and make life of the users simpler. Signed-off-by: Joerg Roedel <jroedel@suse.de> Tested-by: Oded Gabbay <Oded.Gabbay@amd.com>
This commit is contained in:
		
					parent
					
						
							
								dba3838d7a
							
						
					
				
			
			
				commit
				
					
						d9e1611e73
					
				
			
		
					 1 changed files with 12 additions and 5 deletions
				
			
		| 
						 | 
					@ -52,7 +52,8 @@ struct pasid_state {
 | 
				
			||||||
	struct pri_queue pri[PRI_QUEUE_SIZE];	/* PRI tag states */
 | 
						struct pri_queue pri[PRI_QUEUE_SIZE];	/* PRI tag states */
 | 
				
			||||||
	struct device_state *device_state;	/* Link to our device_state */
 | 
						struct device_state *device_state;	/* Link to our device_state */
 | 
				
			||||||
	int pasid;				/* PASID index */
 | 
						int pasid;				/* PASID index */
 | 
				
			||||||
	bool invalid;				/* Used during teardown */
 | 
						bool invalid;				/* Used during setup and
 | 
				
			||||||
 | 
											   teardown of the pasid */
 | 
				
			||||||
	spinlock_t lock;			/* Protect pri_queues and
 | 
						spinlock_t lock;			/* Protect pri_queues and
 | 
				
			||||||
						   mmu_notifer_count */
 | 
											   mmu_notifer_count */
 | 
				
			||||||
	wait_queue_head_t wq;			/* To wait for count == 0 */
 | 
						wait_queue_head_t wq;			/* To wait for count == 0 */
 | 
				
			||||||
| 
						 | 
					@ -473,13 +474,15 @@ static void mn_release(struct mmu_notifier *mn, struct mm_struct *mm)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct pasid_state *pasid_state;
 | 
						struct pasid_state *pasid_state;
 | 
				
			||||||
	struct device_state *dev_state;
 | 
						struct device_state *dev_state;
 | 
				
			||||||
 | 
						bool run_inv_ctx_cb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	might_sleep();
 | 
						might_sleep();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pasid_state    = mn_to_state(mn);
 | 
						pasid_state    = mn_to_state(mn);
 | 
				
			||||||
	dev_state      = pasid_state->device_state;
 | 
						dev_state      = pasid_state->device_state;
 | 
				
			||||||
 | 
						run_inv_ctx_cb = !pasid_state->invalid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pasid_state->device_state->inv_ctx_cb)
 | 
						if (run_inv_ctx_cb && pasid_state->device_state->inv_ctx_cb)
 | 
				
			||||||
		dev_state->inv_ctx_cb(dev_state->pdev, pasid_state->pasid);
 | 
							dev_state->inv_ctx_cb(dev_state->pdev, pasid_state->pasid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unbind_pasid(pasid_state);
 | 
						unbind_pasid(pasid_state);
 | 
				
			||||||
| 
						 | 
					@ -674,7 +677,8 @@ int amd_iommu_bind_pasid(struct pci_dev *pdev, int pasid,
 | 
				
			||||||
	pasid_state->mm           = mm;
 | 
						pasid_state->mm           = mm;
 | 
				
			||||||
	pasid_state->device_state = dev_state;
 | 
						pasid_state->device_state = dev_state;
 | 
				
			||||||
	pasid_state->pasid        = pasid;
 | 
						pasid_state->pasid        = pasid;
 | 
				
			||||||
	pasid_state->invalid      = false;
 | 
						pasid_state->invalid      = true; /* Mark as valid only if we are
 | 
				
			||||||
 | 
										     done with setting up the pasid */
 | 
				
			||||||
	pasid_state->mn.ops       = &iommu_mn;
 | 
						pasid_state->mn.ops       = &iommu_mn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pasid_state->mm == NULL)
 | 
						if (pasid_state->mm == NULL)
 | 
				
			||||||
| 
						 | 
					@ -691,6 +695,9 @@ int amd_iommu_bind_pasid(struct pci_dev *pdev, int pasid,
 | 
				
			||||||
	if (ret)
 | 
						if (ret)
 | 
				
			||||||
		goto out_clear_state;
 | 
							goto out_clear_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Now we are ready to handle faults */
 | 
				
			||||||
 | 
						pasid_state->invalid = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Drop the reference to the mm_struct here. We rely on the
 | 
						 * Drop the reference to the mm_struct here. We rely on the
 | 
				
			||||||
	 * mmu_notifier release call-back to inform us when the mm
 | 
						 * mmu_notifier release call-back to inform us when the mm
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue