Skip to contentSkip to conversation

drm/amdgpu: fix locking in vega10_ih_prescreen_iv

PATCH In review Christian König 2 participants 4 messages Jan 24, 2018 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: fix locking in vega10_ih_prescreen_iv

The vm pointer can become invalid as soon as the lock is released.

---
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +3 -1
index 926c2d305c33..9589e0a2f14a 100644
@@ -278,9 +278,9 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev)
 	/* Track retry faults in per-VM fault FIFO. */
 	spin_lock(&adev->vm_manager.pasid_lock);
 	vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
-	spin_unlock(&adev->vm_manager.pasid_lock);
 	if (WARN_ON_ONCE(!vm)) {
 		/* VM not found, process it normally */
+		spin_unlock(&adev->vm_manager.pasid_lock);
 		amdgpu_ih_clear_fault(adev, key);
 		return true;
 	}
@@ -288,9 +288,11 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev)
 	r = kfifo_put(&vm->faults, key);
 	if (!r) {
 		/* FIFO is full. Ignore it until there is space */
+		spin_unlock(&adev->vm_manager.pasid_lock);
 		amdgpu_ih_clear_fault(adev, key);
 		goto ignore_iv;
 	}
+	spin_unlock(&adev->vm_manager.pasid_lock);
 
 	/* It's the first fault for this address, process it normally */
 	return true;
Signature · 6 lines
2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20180124123938.4792-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: remove WARN_ON when VM isn't found

It can easily be that the VM is already destroyed when this runs.

---
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +1 -1
index 9589e0a2f14a..ee7e16d576c0 100644
@@ -278,7 +278,7 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev)
 	/* Track retry faults in per-VM fault FIFO. */
 	spin_lock(&adev->vm_manager.pasid_lock);
 	vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
-	if (WARN_ON_ONCE(!vm)) {
+	if (vm) {
 		/* VM not found, process it normally */
 		spin_unlock(&adev->vm_manager.pasid_lock);
 		amdgpu_ih_clear_fault(adev, key);
Signature · 6 lines
2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20180124123938.4792-2-christian.koenig-5C7GfCeVMHo@public.gmane.org

Acked-by
#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: remove WARN_ON when VM isn't found

Quoted 12 lines · Christian König

It can easily be that the VM is already destroyed when this runs.

---
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +0 -0
index 9589e0a2f14a..ee7e16d576c0 100644

drivers/gpu/drm/amd/amdgpu/vega10_ih.c static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev) · line 281

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +1 -1
@@ -278,7 +278,7 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev)
        /* Track retry faults in per-VM fault FIFO. */
        spin_lock(&adev->vm_manager.pasid_lock);
        vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
-       if (WARN_ON_ONCE(!vm)) {
+       if (vm) {

Should be !vm. With that fixed:

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +0 -1
                /* VM not found, process it normally */
                spin_unlock(&adev->vm_manager.pasid_lock);
                amdgpu_ih_clear_fault(adev, key);
--

2.14.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Acked-by
#5 lore raw
In reply to a message not in the archive
Quoted 3 lines · Christian König

The vm pointer can become invalid as soon as the lock is released.

Quoted 34 lines
---
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vega10_ih.c +3 -2
index 926c2d305c33..9589e0a2f14a 100644
@@ -278,9 +278,9 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev)
        /* Track retry faults in per-VM fault FIFO. */
        spin_lock(&adev->vm_manager.pasid_lock);
        vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
-       spin_unlock(&adev->vm_manager.pasid_lock);
        if (WARN_ON_ONCE(!vm)) {
                /* VM not found, process it normally */
+               spin_unlock(&adev->vm_manager.pasid_lock);
                amdgpu_ih_clear_fault(adev, key);
                return true;
        }
@@ -288,9 +288,11 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device *adev)
        r = kfifo_put(&vm->faults, key);
        if (!r) {
                /* FIFO is full. Ignore it until there is space */
+               spin_unlock(&adev->vm_manager.pasid_lock);
                amdgpu_ih_clear_fault(adev, key);
                goto ignore_iv;
        }
+       spin_unlock(&adev->vm_manager.pasid_lock);
 
        /* It's the first fault for this address, process it normally */
        return true;
--

2.14.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx