Re: [PATCH] nouveau/uvmm: fix addr/range calcs for remap operations

2024-03-28 Thread Danilo Krummrich

On 3/28/24 03:43, Dave Airlie wrote:

From: Dave Airlie 

dEQP-VK.sparse_resources.image_rebind.2d_array.r64i.128_128_8
was causing a remap operation like the below.

op_remap: prev: 003fffed 000f a5abd18a 

op_remap: next:
op_remap: unmap: 003fffed 0010 0
op_map: map: 003c 0001 5b1ba33c 000e

This was resulting in an unmap operation from 0x3fffed+0xf, 0x10
which was corrupting the pagetables and oopsing the kernel.


Good catch, thanks for looking into that.



Fixes the prev + unmap range calcs to use start/end and map back to addr/range.


I like how using start/end instead fixes the issue and keeps it simple.



Signed-off-by: Dave Airlie 
Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")
Cc: Danilo Krummrich 


Applied the patch to drm-misc-fixes.


---
  drivers/gpu/drm/nouveau/nouveau_uvmm.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c 
b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
index 9675ef25b16d..87bce1a9d073 100644
--- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
@@ -813,15 +813,15 @@ op_remap(struct drm_gpuva_op_remap *r,
struct drm_gpuva_op_unmap *u = r->unmap;
struct nouveau_uvma *uvma = uvma_from_va(u->va);
u64 addr = uvma->va.va.addr;
-   u64 range = uvma->va.va.range;
+   u64 end = uvma->va.va.addr + uvma->va.va.range;
  
  	if (r->prev)

addr = r->prev->va.addr + r->prev->va.range;
  
  	if (r->next)

-   range = r->next->va.addr - addr;
+   end = r->next->va.addr;
  
-	op_unmap_range(u, addr, range);

+   op_unmap_range(u, addr, end - addr);
  }
  
  static int




[PATCH] nouveau/uvmm: fix addr/range calcs for remap operations

2024-03-27 Thread Dave Airlie
From: Dave Airlie 

dEQP-VK.sparse_resources.image_rebind.2d_array.r64i.128_128_8
was causing a remap operation like the below.

op_remap: prev: 003fffed 000f a5abd18a 

op_remap: next:
op_remap: unmap: 003fffed 0010 0
op_map: map: 003c 0001 5b1ba33c 000e

This was resulting in an unmap operation from 0x3fffed+0xf, 0x10
which was corrupting the pagetables and oopsing the kernel.

Fixes the prev + unmap range calcs to use start/end and map back to addr/range.

Signed-off-by: Dave Airlie 
Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")
Cc: Danilo Krummrich 
---
 drivers/gpu/drm/nouveau/nouveau_uvmm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c 
b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
index 9675ef25b16d..87bce1a9d073 100644
--- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c
@@ -813,15 +813,15 @@ op_remap(struct drm_gpuva_op_remap *r,
struct drm_gpuva_op_unmap *u = r->unmap;
struct nouveau_uvma *uvma = uvma_from_va(u->va);
u64 addr = uvma->va.va.addr;
-   u64 range = uvma->va.va.range;
+   u64 end = uvma->va.va.addr + uvma->va.va.range;
 
if (r->prev)
addr = r->prev->va.addr + r->prev->va.range;
 
if (r->next)
-   range = r->next->va.addr - addr;
+   end = r->next->va.addr;
 
-   op_unmap_range(u, addr, range);
+   op_unmap_range(u, addr, end - addr);
 }
 
 static int
-- 
2.43.2