aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOded Gabbay <oded.gabbay@amd.com>2014-11-10 03:57:36 -0500
committerOded Gabbay <oded.gabbay@amd.com>2014-11-10 03:57:36 -0500
commita015c1e92639cd65ebb49350abdf5ad15bce4448 (patch)
tree4a21405a0291301bfcc20068dbb86d043d7f5007
parente7cc3dd48c7b0a4b2135a5a2145ad43a8192fa6a (diff)
iommu/amd: fix accounting of device_state
This patch fixes a bug in the accounting of the device_state. In the current code, the device_state was put (decremented) too many times, which sometimes lead to the driver getting stuck permanently in put_device_state_wait(). That happen because the device_state->count would go below zero, which is never supposed to happen. The root cause is that the device_state was decremented in put_pasid_state() and put_pasid_state_wait() but also in all the functions that call those functions. Therefore, the device_state was decremented twice in each of these code paths. The fix is to decouple the device_state accounting from the pasid_state accounting - remove the call to put_device_state() from the put_pasid_state() and the put_pasid_state_wait()) Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
-rw-r--r--drivers/iommu/amd_iommu_v2.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index f724bdc50d25..1e6360e7ae44 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -272,10 +272,8 @@ static void free_pasid_state(struct pasid_state *pasid_state)
272 272
273static void put_pasid_state(struct pasid_state *pasid_state) 273static void put_pasid_state(struct pasid_state *pasid_state)
274{ 274{
275 if (atomic_dec_and_test(&pasid_state->count)) { 275 if (atomic_dec_and_test(&pasid_state->count))
276 put_device_state(pasid_state->device_state);
277 wake_up(&pasid_state->wq); 276 wake_up(&pasid_state->wq);
278 }
279} 277}
280 278
281static void put_pasid_state_wait(struct pasid_state *pasid_state) 279static void put_pasid_state_wait(struct pasid_state *pasid_state)
@@ -284,9 +282,7 @@ static void put_pasid_state_wait(struct pasid_state *pasid_state)
284 282
285 prepare_to_wait(&pasid_state->wq, &wait, TASK_UNINTERRUPTIBLE); 283 prepare_to_wait(&pasid_state->wq, &wait, TASK_UNINTERRUPTIBLE);
286 284
287 if (atomic_dec_and_test(&pasid_state->count)) 285 if (!atomic_dec_and_test(&pasid_state->count))
288 put_device_state(pasid_state->device_state);
289 else
290 schedule(); 286 schedule();
291 287
292 finish_wait(&pasid_state->wq, &wait); 288 finish_wait(&pasid_state->wq, &wait);