Skip to contentSkip to conversation

drm/radeon: fix handling of radeon_vm_bo_rmv v3

PATCH Applied Christian König 3 participants 4 messages Jul 18, 2014

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

PATCH 1/1 drm/radeon: fix handling of radeon_vm_bo_rmv v3

From: Christian König <[email protected]>

v3: completely rewritten. We now just remember which areas
of the PT to clear and do so on the next command submission.

---
 drivers/gpu/drm/radeon/radeon.h    | 13 ++++--
 drivers/gpu/drm/radeon/radeon_cs.c | 22 ++++++++--
 drivers/gpu/drm/radeon/radeon_vm.c | 82 +++++++++++++++++++++++++++-----------
 3 files changed, 86 insertions(+), 31 deletions(-)
drivers/gpu/drm/radeon/radeon.h +9 -4
index 29d9cc0..d07f9e3 100644
@@ -449,6 +449,7 @@ struct radeon_bo_va {
 
 	/* protected by vm mutex */
 	struct list_head		vm_list;
+	struct list_head		vm_status;
 
 	/* constant after initialization */
 	struct radeon_vm		*vm;
@@ -868,6 +869,9 @@ struct radeon_vm {
 	struct list_head		va;
 	unsigned			id;
 
+	/* BOs freed, but not yet updated in the PT */
+	struct list_head		freed;
+
 	/* contains the page directory */
 	struct radeon_bo		*page_directory;
 	uint64_t			pd_gpu_addr;
@@ -2833,9 +2837,10 @@ void radeon_vm_fence(struct radeon_device *rdev,
 uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
 int radeon_vm_update_page_directory(struct radeon_device *rdev,
 				    struct radeon_vm *vm);
+int radeon_vm_clear_freed(struct radeon_device *rdev,
+			  struct radeon_vm *vm);
 int radeon_vm_bo_update(struct radeon_device *rdev,
-			struct radeon_vm *vm,
-			struct radeon_bo *bo,
+			struct radeon_bo_va *bo_va,
 			struct ttm_mem_reg *mem);
 void radeon_vm_bo_invalidate(struct radeon_device *rdev,
 			     struct radeon_bo *bo);
@@ -2848,8 +2853,8 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
 			  struct radeon_bo_va *bo_va,
 			  uint64_t offset,
 			  uint32_t flags);
-int radeon_vm_bo_rmv(struct radeon_device *rdev,
-		     struct radeon_bo_va *bo_va);
+void radeon_vm_bo_rmv(struct radeon_device *rdev,
+		      struct radeon_bo_va *bo_va);
 
 /* audio */
 void r600_audio_update_hdmi(struct work_struct *work);
drivers/gpu/drm/radeon/radeon_cs.c +19 -3
index 71a1434..09fcf4d 100644
@@ -461,14 +461,24 @@ static int radeon_bo_vm_update_pte(struct radeon_cs_parser *p,
 				   struct radeon_vm *vm)
 {
 	struct radeon_device *rdev = p->rdev;
+	struct radeon_bo_va *bo_va;
 	int i, r;
 
 	r = radeon_vm_update_page_directory(rdev, vm);
 	if (r)
 		return r;
 
-	r = radeon_vm_bo_update(rdev, vm, rdev->ring_tmp_bo.bo,
-				&rdev->ring_tmp_bo.bo->tbo.mem);
+	r = radeon_vm_clear_freed(rdev, vm);
+	if (r)
+		return r;
+
+	bo_va = radeon_vm_bo_find(vm, rdev->ring_tmp_bo.bo);
+	if (bo_va == NULL) {
+		DRM_ERROR("Tmp BO not in VM!\n");
+		return -EINVAL;
+	}
+
+	r = radeon_vm_bo_update(rdev, bo_va, &rdev->ring_tmp_bo.bo->tbo.mem);
 	if (r)
 		return r;
 
@@ -480,7 +490,13 @@ static int radeon_bo_vm_update_pte(struct radeon_cs_parser *p,
 			continue;
 
 		bo = p->relocs[i].robj;
-		r = radeon_vm_bo_update(rdev, vm, bo, &bo->tbo.mem);
+		bo_va = radeon_vm_bo_find(vm, bo);
+		if (bo_va == NULL) {
+			dev_err(rdev->dev, "bo %p not in vm %p\n", bo, vm);
+			return -EINVAL;
+		}
+
+		r = radeon_vm_bo_update(rdev, bo_va, &bo->tbo.mem);
 		if (r)
 			return r;
 	}
drivers/gpu/drm/radeon/radeon_vm.c +58 -24

148 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 8 lines · Christian König

From: Christian König <[email protected]>

v3: completely rewritten. We now just remember which areas
of the PT to clear and do so on the next command submission.

[...]

Quoted 5 lines
drivers/gpu/drm/radeon/radeon_vm.c +0 -0
index eecff6b..2726b46 100644

drivers/gpu/drm/radeon/radeon_vm.c int radeon_vm_bo_set_addr(struct radeon_device *rdev, · line 477

Quoted 9 lines
drivers/gpu/drm/radeon/radeon_vm.c +6 -0
@@ -468,6 +469,15 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
 		head = &tmp->vm_list;
 	}
 
+	if (bo_va->soffset) {
+		/* add a clone of the bo_va to clear the old address */
+		tmp = kzalloc(sizeof(struct radeon_bo_va), GFP_KERNEL);
+		tmp->soffset = bo_va->soffset;
+		tmp->eoffset = bo_va->eoffset;
+		tmp->vm = vm;

+ INIT_LIST_HEAD(&tmp->vm_status);

?

Quoted 2 lines
drivers/gpu/drm/radeon/radeon_vm.c +2 -0
+		list_add(&tmp->vm_status, &vm->freed);
+	}

[...]

Quoted 7 lines
drivers/gpu/drm/radeon/radeon_vm.c +3 -3
-int radeon_vm_bo_rmv(struct radeon_device *rdev,
-		     struct radeon_bo_va *bo_va)
+void radeon_vm_bo_rmv(struct radeon_device *rdev,
+		      struct radeon_bo_va *bo_va)
 {
-	int r = 0;
+	struct radeon_vm *vm = bo_va->vm;

drivers/gpu/drm/radeon/radeon_vm.c int radeon_vm_bo_update(struct radeon_device *rdev, · line 937

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_vm.c +2 -5
 
-	mutex_lock(&bo_va->vm->mutex);
-	if (bo_va->soffset)
-		r = radeon_vm_bo_update(rdev, bo_va->vm, bo_va->bo, NULL);
+	list_del(&bo_va->bo_list);
 
+	mutex_lock(&vm->mutex);
 	list_del(&bo_va->vm_list);
-	mutex_unlock(&bo_va->vm->mutex);
-	list_del(&bo_va->bo_list);

Was there any particular reason for moving the list_del(&bo_va->bo_list) outside of the VM mutex? I suspect this might be the cause of the problem below, which I encountered after a few piglit runs.

Other than those two issues, the patch looks good to me, and I haven't seen any piglit GPU lockups with it on my Bonaire yet.

 general protection fault: 0000 [#1] SMP 153
 Modules linked in: bnep bluetooth rfkill snd_hrtimer snd_seq snd_seq_device cpufreq_stats cpufreq_powersave cpufreq_userspace cpufreq_conservative binfmt_misc nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc hid_generic usbhid hid snd_hda_codec_hdmi evdev snd_hda_codec_realtek snd_hda_codec_generic nls_utf8 nls_cp437 vfat fat kvm_amd kvm crc32_pclmul crc32c_intel ghash_clmulni_intel aesni_intel aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd microcode ohci_pci psmouse serio_raw pcspkr edac_mce_amd k10temp edac_core r8169 mii snd_hda_intel snd_hda_controller snd_hda_codec snd_hwdep snd_pcm snd_timer radeon(O) ttm snd sg drm_kms_helper i2c_piix4 ohci_hcd ehci_pci drm ehci_hcd soundcore i2c_algo_bit i2c_core acpi_cpufreq xhci_hcd video usbcore usb_common processor wmi button thermal_sys fuse autofs4 ext4 crc16 mbcache jbd2 dm_mod sd_mod crc_t10dif crct10dif_generic crct10dif_pclmul crct10dif_common ahci libahci libata scsi_mod
 CPU: 2 PID: 14721 Comm: shader_runner Tainted: G           O  3.16.0-rc5+ #143
 Hardware name: System manufacturer System Product Name/A88X-PRO, BIOS 1001 04/01/2014
 task: ffff8800083e4b10 ti: ffff880103bb8000 task.ti: ffff880103bb8000
 RIP: 0010:[<ffffffffc0573672>]  [<ffffffffc0573672>] radeon_vm_bo_find+0x13/0x22 [radeon]
 RSP: 0018:ffff880103bbbbf0  EFLAGS: 00010297
 RAX: dead000000100100 RBX: ffff8800dba24000 RCX: ef7bdef7bdef7bdf
 RDX: 000000000000a7b3 RSI: ffff8802120a9bb8 RDI: ffff8801f1d4f800
 RBP: ffff880103bbbbf0 R08: 0000000000000000 R09: ffffffff00000000
 R10: ffff880103bbba80 R11: ffff8800dba25eb0 R12: ffff880103bbbc18
 R13: ffff8801f1d4f800 R14: ffff8800dba24000 R15: 0000000000000000
 FS:  00007f640e4b7700(0000) GS:ffff88021e200000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00007f35bc858000 CR3: 00000001024a1000 CR4: 00000000000407e0
 Stack:
  ffff880103bbbdc0 ffffffffc04fb879 ffff8801f1d4f848 ffff880103bbbdf0
  ffff8800dba24018 ffff880215228098 ffff8800dba24000 ffff880003207c00
  0000000000000003 ffff8801f9c399c0 ffff8801fa08a120 0000001700000000
 Call Trace:
  [<ffffffffc04fb879>] radeon_cs_ioctl+0x4eb/0x677 [radeon]
  [<ffffffffc042638e>] drm_ioctl+0x366/0x42c [drm]
  [...]
Signature · 6 lines
Earthling Michel Dänzer            |                  http://www.amd.com
Libre software enthusiast          |                Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Am 18.07.2014 11:44, schrieb Michel Dänzer:

Quoted 27 lines · Christian König
Quoted 8 lines

From: Christian König <[email protected]>

v3: completely rewritten. We now just remember which areas
of the PT to clear and do so on the next command submission.

[...]

Quoted 14 lines
drivers/gpu/drm/radeon/radeon_vm.c +6 -0
index eecff6b..2726b46 100644
@@ -468,6 +469,15 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
  		head = &tmp->vm_list;
  	}
 
+	if (bo_va->soffset) {
+		/* add a clone of the bo_va to clear the old address */
+		tmp = kzalloc(sizeof(struct radeon_bo_va), GFP_KERNEL);
+		tmp->soffset = bo_va->soffset;
+		tmp->eoffset = bo_va->eoffset;
+		tmp->vm = vm;
(quoted diff) +1 -0
+		INIT_LIST_HEAD(&tmp->vm_status);
Quoted 1 line

?

Unnecessary, would be overwritten by the following list_add anyway.

Quoted 17 lines
Quoted 2 lines
drivers/gpu/drm/radeon/radeon_vm.c +2 -0
+		list_add(&tmp->vm_status, &vm->freed);
+	}

[...]

Quoted 13 lines
drivers/gpu/drm/radeon/radeon_vm.c +4 -6
-int radeon_vm_bo_rmv(struct radeon_device *rdev,
-		     struct radeon_bo_va *bo_va)
+void radeon_vm_bo_rmv(struct radeon_device *rdev,
+		      struct radeon_bo_va *bo_va)
  {
-	int r = 0;
+	struct radeon_vm *vm = bo_va->vm;
 
-	mutex_lock(&bo_va->vm->mutex);
-	if (bo_va->soffset)
-		r = radeon_vm_bo_update(rdev, bo_va->vm, bo_va->bo, NULL);
+	list_del(&bo_va->bo_list);
Quoted 7 lines

drivers/gpu/drm/radeon/radeon_vm.c int radeon_vm_bo_update(struct radeon_device *rdev, · line 937

Quoted 4 lines
drivers/gpu/drm/radeon/radeon_vm.c +1 -2
+	mutex_lock(&vm->mutex);
  	list_del(&bo_va->vm_list);
-	mutex_unlock(&bo_va->vm->mutex);
-	list_del(&bo_va->bo_list);

Was there any particular reason for moving the list_del(&bo_va->bo_list) outside of the VM mutex? I suspect this might be the cause of the problem below, which I encountered after a few piglit runs.

Ah! Well it's not the root cause of the problem cause we released that lock before as well. But it changed the timing quite a bit and so brought the problem to the surface.

The root cause is that we don't reserve the IB-BO on every command submission, and so a concurrent creating or tear-down of a VM could modify the bo_list without holding a lock.

Thanks for the Info, going to address this in a second patch.

Regards,
Christian.

Quoted 21 lines

Other than those two issues, the patch looks good to me, and I haven't seen any piglit GPU lockups with it on my Bonaire yet.

  general protection fault: 0000 [#1] SMP 153
  Modules linked in: bnep bluetooth rfkill snd_hrtimer snd_seq snd_seq_device cpufreq_stats cpufreq_powersave cpufreq_userspace cpufreq_conservative binfmt_misc nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc hid_generic usbhid hid snd_hda_codec_hdmi evdev snd_hda_codec_realtek snd_hda_codec_generic nls_utf8 nls_cp437 vfat fat kvm_amd kvm crc32_pclmul crc32c_intel ghash_clmulni_intel aesni_intel aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd microcode ohci_pci psmouse serio_raw pcspkr edac_mce_amd k10temp edac_core r8169 mii snd_hda_intel snd_hda_controller snd_hda_codec snd_hwdep snd_pcm snd_timer radeon(O) ttm snd sg drm_kms_helper i2c_piix4 ohci_hcd ehci_pci drm ehci_hcd soundcore i2c_algo_bit i2c_core acpi_cpufreq xhci_hcd video usbcore usb_common processor wmi button thermal_sys fuse autofs4 ext4 crc16 mbcache jbd2 dm_mod sd_mod crc_t10dif crct10dif_generic crct10dif_pclmul crct10dif_common ahci libahci libata scsi_mod
  CPU: 2 PID: 14721 Comm: shader_runner Tainted: G           O  3.16.0-rc5+ #143
  Hardware name: System manufacturer System Product Name/A88X-PRO, BIOS 1001 04/01/2014
  task: ffff8800083e4b10 ti: ffff880103bb8000 task.ti: ffff880103bb8000
  RIP: 0010:[<ffffffffc0573672>]  [<ffffffffc0573672>] radeon_vm_bo_find+0x13/0x22 [radeon]
  RSP: 0018:ffff880103bbbbf0  EFLAGS: 00010297
  RAX: dead000000100100 RBX: ffff8800dba24000 RCX: ef7bdef7bdef7bdf
  RDX: 000000000000a7b3 RSI: ffff8802120a9bb8 RDI: ffff8801f1d4f800
  RBP: ffff880103bbbbf0 R08: 0000000000000000 R09: ffffffff00000000
  R10: ffff880103bbba80 R11: ffff8800dba25eb0 R12: ffff880103bbbc18
  R13: ffff8801f1d4f800 R14: ffff8800dba24000 R15: 0000000000000000
  FS:  00007f640e4b7700(0000) GS:ffff88021e200000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 00007f35bc858000 CR3: 00000001024a1000 CR4: 00000000000407e0
Quoted 10 lines
  Stack:
   ffff880103bbbdc0 ffffffffc04fb879 ffff8801f1d4f848 ffff880103bbbdf0
   ffff8800dba24018 ffff880215228098 ffff8800dba24000 ffff880003207c00
   0000000000000003 ffff8801f9c399c0 ffff8801fa08a120 0000001700000000
  Call Trace:
   [<ffffffffc04fb879>] radeon_cs_ioctl+0x4eb/0x677 [radeon]
   [<ffffffffc042638e>] drm_ioctl+0x366/0x42c [drm]
   [...]

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Applied
#3 lore raw
In reply to Christian König
Quoted 8 lines · Christian König

From: Christian König <[email protected]>

v3: completely rewritten. We now just remember which areas
of the PT to clear and do so on the next command submission.

Applied to my 3.16 tree.

Thanks!

Alex

Quoted 258 lines
---
 drivers/gpu/drm/radeon/radeon.h    | 13 ++++--
 drivers/gpu/drm/radeon/radeon_cs.c | 22 ++++++++--
 drivers/gpu/drm/radeon/radeon_vm.c | 82 +++++++++++++++++++++++++++-----------
 3 files changed, 86 insertions(+), 31 deletions(-)
drivers/gpu/drm/radeon/radeon.h +9 -4
index 29d9cc0..d07f9e3 100644
@@ -449,6 +449,7 @@ struct radeon_bo_va {
 
        /* protected by vm mutex */
        struct list_head                vm_list;
+       struct list_head                vm_status;
 
        /* constant after initialization */
        struct radeon_vm                *vm;
@@ -868,6 +869,9 @@ struct radeon_vm {
        struct list_head                va;
        unsigned                        id;
 
+       /* BOs freed, but not yet updated in the PT */
+       struct list_head                freed;
+
        /* contains the page directory */
        struct radeon_bo                *page_directory;
        uint64_t                        pd_gpu_addr;
@@ -2833,9 +2837,10 @@ void radeon_vm_fence(struct radeon_device *rdev,
 uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
 int radeon_vm_update_page_directory(struct radeon_device *rdev,
                                    struct radeon_vm *vm);
+int radeon_vm_clear_freed(struct radeon_device *rdev,
+                         struct radeon_vm *vm);
 int radeon_vm_bo_update(struct radeon_device *rdev,
-                       struct radeon_vm *vm,
-                       struct radeon_bo *bo,
+                       struct radeon_bo_va *bo_va,
                        struct ttm_mem_reg *mem);
 void radeon_vm_bo_invalidate(struct radeon_device *rdev,
                             struct radeon_bo *bo);
@@ -2848,8 +2853,8 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
                          struct radeon_bo_va *bo_va,
                          uint64_t offset,
                          uint32_t flags);
-int radeon_vm_bo_rmv(struct radeon_device *rdev,
-                    struct radeon_bo_va *bo_va);
+void radeon_vm_bo_rmv(struct radeon_device *rdev,
+                     struct radeon_bo_va *bo_va);
 
 /* audio */
 void r600_audio_update_hdmi(struct work_struct *work);
drivers/gpu/drm/radeon/radeon_cs.c +19 -3
index 71a1434..09fcf4d 100644
@@ -461,14 +461,24 @@ static int radeon_bo_vm_update_pte(struct radeon_cs_parser *p,
                                   struct radeon_vm *vm)
 {
        struct radeon_device *rdev = p->rdev;
+       struct radeon_bo_va *bo_va;
        int i, r;
 
        r = radeon_vm_update_page_directory(rdev, vm);
        if (r)
                return r;
 
-       r = radeon_vm_bo_update(rdev, vm, rdev->ring_tmp_bo.bo,
-                               &rdev->ring_tmp_bo.bo->tbo.mem);
+       r = radeon_vm_clear_freed(rdev, vm);
+       if (r)
+               return r;
+
+       bo_va = radeon_vm_bo_find(vm, rdev->ring_tmp_bo.bo);
+       if (bo_va == NULL) {
+               DRM_ERROR("Tmp BO not in VM!\n");
+               return -EINVAL;
+       }
+
+       r = radeon_vm_bo_update(rdev, bo_va, &rdev->ring_tmp_bo.bo->tbo.mem);
        if (r)
                return r;
 
@@ -480,7 +490,13 @@ static int radeon_bo_vm_update_pte(struct radeon_cs_parser *p,
                        continue;
 
                bo = p->relocs[i].robj;
-               r = radeon_vm_bo_update(rdev, vm, bo, &bo->tbo.mem);
+               bo_va = radeon_vm_bo_find(vm, bo);
+               if (bo_va == NULL) {
+                       dev_err(rdev->dev, "bo %p not in vm %p\n", bo, vm);
+                       return -EINVAL;
+               }
+
+               r = radeon_vm_bo_update(rdev, bo_va, &bo->tbo.mem);
                if (r)
                        return r;
        }
drivers/gpu/drm/radeon/radeon_vm.c +58 -25
index eecff6b..2726b46 100644
@@ -332,6 +332,7 @@ struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
        bo_va->ref_count = 1;
        INIT_LIST_HEAD(&bo_va->bo_list);
        INIT_LIST_HEAD(&bo_va->vm_list);
+       INIT_LIST_HEAD(&bo_va->vm_status);
 
        mutex_lock(&vm->mutex);
        list_add(&bo_va->vm_list, &vm->va);
@@ -468,6 +469,15 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
                head = &tmp->vm_list;
        }
 
+       if (bo_va->soffset) {
+               /* add a clone of the bo_va to clear the old address */
+               tmp = kzalloc(sizeof(struct radeon_bo_va), GFP_KERNEL);
+               tmp->soffset = bo_va->soffset;
+               tmp->eoffset = bo_va->eoffset;
+               tmp->vm = vm;
+               list_add(&tmp->vm_status, &vm->freed);
+       }
+
        bo_va->soffset = soffset;
        bo_va->eoffset = eoffset;
        bo_va->flags = flags;
@@ -823,25 +833,19 @@ static void radeon_vm_update_ptes(struct radeon_device *rdev,
  * Object have to be reserved and mutex must be locked!
  */
 int radeon_vm_bo_update(struct radeon_device *rdev,
-                       struct radeon_vm *vm,
-                       struct radeon_bo *bo,
+                       struct radeon_bo_va *bo_va,
                        struct ttm_mem_reg *mem)
 {
+       struct radeon_vm *vm = bo_va->vm;
        struct radeon_ib ib;
-       struct radeon_bo_va *bo_va;
        unsigned nptes, ndw;
        uint64_t addr;
        int r;
 
-       bo_va = radeon_vm_bo_find(vm, bo);
-       if (bo_va == NULL) {
-               dev_err(rdev->dev, "bo %p not in vm %p\n", bo, vm);
-               return -EINVAL;
-       }
 
        if (!bo_va->soffset) {
                dev_err(rdev->dev, "bo %p don't has a mapping in vm %p\n",
-                       bo, vm);
+                       bo_va->bo, vm);
                return -EINVAL;
        }
 
@@ -868,7 +872,7 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
 
        trace_radeon_vm_bo_update(bo_va);
 
-       nptes = radeon_bo_ngpu_pages(bo);
+       nptes = (bo_va->eoffset - bo_va->soffset) / RADEON_GPU_PAGE_SIZE;
 
        /* padding, etc. */
        ndw = 64;
@@ -911,33 +915,61 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
 }
 
 /**
+ * radeon_vm_clear_freed - clear freed BOs in the PT
+ *
+ * @rdev: radeon_device pointer
+ * @vm: requested vm
+ *
+ * Make sure all freed BOs are cleared in the PT.
+ * Returns 0 for success.
+ *
+ * PTs have to be reserved and mutex must be locked!
+ */
+int radeon_vm_clear_freed(struct radeon_device *rdev,
+                         struct radeon_vm *vm)
+{
+       struct radeon_bo_va *bo_va, *tmp;
+       int r;
+
+       list_for_each_entry_safe(bo_va, tmp, &vm->freed, vm_status) {
+               list_del(&bo_va->vm_status);
+               r = radeon_vm_bo_update(rdev, bo_va, NULL);
+               kfree(bo_va);
+               if (r)
+                       return r;
+       }
+       return 0;
+
+}
+
+/**
  * radeon_vm_bo_rmv - remove a bo to a specific vm
  *
  * @rdev: radeon_device pointer
  * @bo_va: requested bo_va
  *
  * Remove @bo_va->bo from the requested vm (cayman+).
- * Remove @bo_va->bo from the list of bos associated with the bo_va->vm and
- * remove the ptes for @bo_va in the page table.
- * Returns 0 for success.
  *
  * Object have to be reserved!
  */
-int radeon_vm_bo_rmv(struct radeon_device *rdev,
-                    struct radeon_bo_va *bo_va)
+void radeon_vm_bo_rmv(struct radeon_device *rdev,
+                     struct radeon_bo_va *bo_va)
 {
-       int r = 0;
+       struct radeon_vm *vm = bo_va->vm;
 
-       mutex_lock(&bo_va->vm->mutex);
-       if (bo_va->soffset)
-               r = radeon_vm_bo_update(rdev, bo_va->vm, bo_va->bo, NULL);
+       list_del(&bo_va->bo_list);
 
+       mutex_lock(&vm->mutex);
        list_del(&bo_va->vm_list);
-       mutex_unlock(&bo_va->vm->mutex);
-       list_del(&bo_va->bo_list);
 
-       kfree(bo_va);
-       return r;
+       if (bo_va->soffset) {
+               bo_va->bo = NULL;
+               list_add(&bo_va->vm_status, &vm->freed);
+       } else {
+               kfree(bo_va);
+       }
+
+       mutex_unlock(&vm->mutex);
 }
 
 /**
@@ -980,6 +1012,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
        vm->last_id_use = NULL;
        mutex_init(&vm->mutex);
        INIT_LIST_HEAD(&vm->va);
+       INIT_LIST_HEAD(&vm->freed);
 
        pd_size = radeon_vm_directory_size(rdev);
        pd_entries = radeon_vm_num_pdes(rdev);
@@ -1034,7 +1067,8 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm)
                        kfree(bo_va);
                }
        }
-
+       list_for_each_entry_safe(bo_va, tmp, &vm->freed, vm_status)
+               kfree(bo_va);
 
        for (i = 0; i < radeon_vm_num_pdes(rdev); i++)
                radeon_bo_unref(&vm->page_tables[i].bo);
--
Quoted 2 lines

1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel