* [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3
@ 2014-07-18 6:56 Christian König
2014-07-18 9:44 ` Michel Dänzer
2014-07-18 16:41 ` Alex Deucher
0 siblings, 2 replies; 4+ messages in thread
From: Christian König @ 2014-07-18 6:56 UTC (permalink / raw)
To: dri-devel
From: Christian König <christian.koenig@amd.com>
v3: completely rewritten. We now just remember which areas
of the PT to clear and do so on the next command submission.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=79980
Signed-off-by: Christian König <christian.koenig@amd.com>
---
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(-)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 29d9cc0..d07f9e3 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -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);
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 71a1434..09fcf4d 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -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;
}
diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
index eecff6b..2726b46 100644
--- a/drivers/gpu/drm/radeon/radeon_vm.c
+++ b/drivers/gpu/drm/radeon/radeon_vm.c
@@ -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);
--
1.9.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3
2014-07-18 6:56 [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3 Christian König
@ 2014-07-18 9:44 ` Michel Dänzer
2014-07-18 10:59 ` Christian König
2014-07-18 16:41 ` Alex Deucher
1 sibling, 1 reply; 4+ messages in thread
From: Michel Dänzer @ 2014-07-18 9:44 UTC (permalink / raw)
To: Christian König; +Cc: dri-devel
On 18.07.2014 15:56, Christian König wrote:
> From: Christian König <christian.koenig@amd.com>
>
> v3: completely rewritten. We now just remember which areas
> of the PT to clear and do so on the next command submission.
>
> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=79980
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
[...]
> diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
> index eecff6b..2726b46 100644
> --- a/drivers/gpu/drm/radeon/radeon_vm.c
> +++ b/drivers/gpu/drm/radeon/radeon_vm.c
> @@ -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);
?
> + list_add(&tmp->vm_status, &vm->freed);
> + }
[...]
> -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);
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]
[...]
--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3
2014-07-18 9:44 ` Michel Dänzer
@ 2014-07-18 10:59 ` Christian König
0 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2014-07-18 10:59 UTC (permalink / raw)
To: Michel Dänzer; +Cc: dri-devel
Am 18.07.2014 11:44, schrieb Michel Dänzer:
> On 18.07.2014 15:56, Christian König wrote:
>> From: Christian König <christian.koenig@amd.com>
>>
>> v3: completely rewritten. We now just remember which areas
>> of the PT to clear and do so on the next command submission.
>>
>> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=79980
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
> [...]
>
>> diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
>> index eecff6b..2726b46 100644
>> --- a/drivers/gpu/drm/radeon/radeon_vm.c
>> +++ b/drivers/gpu/drm/radeon/radeon_vm.c
>> @@ -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);
>
> ?
Unnecessary, would be overwritten by the following list_add anyway.
>> + list_add(&tmp->vm_status, &vm->freed);
>> + }
> [...]
>
>> -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);
> 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.
>
>
> 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]
> [...]
>
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3
2014-07-18 6:56 [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3 Christian König
2014-07-18 9:44 ` Michel Dänzer
@ 2014-07-18 16:41 ` Alex Deucher
1 sibling, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2014-07-18 16:41 UTC (permalink / raw)
To: Christian König; +Cc: Maling list - DRI developers
On Fri, Jul 18, 2014 at 2:56 AM, Christian König
<deathsimple@vodafone.de> wrote:
> From: Christian König <christian.koenig@amd.com>
>
> v3: completely rewritten. We now just remember which areas
> of the PT to clear and do so on the next command submission.
>
> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=79980
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
Applied to my 3.16 tree.
Thanks!
Alex
> ---
> 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(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> index 29d9cc0..d07f9e3 100644
> --- a/drivers/gpu/drm/radeon/radeon.h
> +++ b/drivers/gpu/drm/radeon/radeon.h
> @@ -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);
> diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
> index 71a1434..09fcf4d 100644
> --- a/drivers/gpu/drm/radeon/radeon_cs.c
> +++ b/drivers/gpu/drm/radeon/radeon_cs.c
> @@ -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;
> }
> diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
> index eecff6b..2726b46 100644
> --- a/drivers/gpu/drm/radeon/radeon_vm.c
> +++ b/drivers/gpu/drm/radeon/radeon_vm.c
> @@ -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);
> --
> 1.9.1
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-18 16:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-18 6:56 [PATCH] drm/radeon: fix handling of radeon_vm_bo_rmv v3 Christian König
2014-07-18 9:44 ` Michel Dänzer
2014-07-18 10:59 ` Christian König
2014-07-18 16:41 ` Alex Deucher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.