Merge tag 'iommu-updates-v6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/joro...
[sfrench/cifs-2.6.git] / drivers / iommu / amd / iommu_v2.c
index 2596466cd5a60a346b36c0a0406626bd2a510a30..57c2fb1146e25f113ce7f782e8cdf1e63abd31c9 100644 (file)
@@ -262,8 +262,8 @@ static void put_pasid_state(struct pasid_state *pasid_state)
 
 static void put_pasid_state_wait(struct pasid_state *pasid_state)
 {
-       refcount_dec(&pasid_state->count);
-       wait_event(pasid_state->wq, !refcount_read(&pasid_state->count));
+       if (!refcount_dec_and_test(&pasid_state->count))
+               wait_event(pasid_state->wq, !refcount_read(&pasid_state->count));
        free_pasid_state(pasid_state);
 }
 
@@ -327,6 +327,9 @@ static void free_pasid_states(struct device_state *dev_state)
 
                put_pasid_state(pasid_state);
 
+               /* Clear the pasid state so that the pasid can be re-used */
+               clear_pasid_state(dev_state, pasid_state->pasid);
+
                /*
                 * This will call the mn_release function and
                 * unbind the PASID