Skip to contentSkip to conversation

drm/amd/amdgpu: Fix wave mask in amdgpu_debugfs_wave_read()

PATCH In review Tom St Denis 2 participants 5 messages Nov 10, 2017 – Nov 13, 2017 4 messages not in the archive

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

PATCH 1/1 drm/amd/amdgpu: Fix wave mask in amdgpu_debugfs_wave_read()

The bottom two bits of the simd value were being put into the upper bits of the wave value which was likely working due to the bits being ignored (or aliased).

Eitherway, now we mask it correctly.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index c1f1b8f15395..cc59020d5874 100644
@@ -3766,7 +3766,7 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
 	se = ((*pos >> 7) & 0xFF);
 	sh = ((*pos >> 15) & 0xFF);
 	cu = ((*pos >> 23) & 0xFF);
-	wave = ((*pos >> 31) & 0xFF);
+	wave = ((*pos >> 31) & 0x3F);
 	simd = ((*pos >> 37) & 0xFF);
 
 	/* switch to the specific se/sh/cu */
Signature · 6 lines
2.12.0

_______________________________________________
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): [email protected]

#2 lore raw

Am 10.11.2017 um 19:03 schrieb Tom St Denis:

Quoted 16 lines

The bottom two bits of the simd value were being put into the upper bits of the wave value which was likely working due to the bits being ignored (or aliased).

Eitherway, now we mask it correctly.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index c1f1b8f15395..cc59020d5874 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf, · line 3770

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -3766,7 +3766,7 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
  	se = ((*pos >> 7) & 0xFF);
  	sh = ((*pos >> 15) & 0xFF);
  	cu = ((*pos >> 23) & 0xFF);
-	wave = ((*pos >> 31) & 0xFF);
+	wave = ((*pos >> 31) & 0x3F);
  	simd = ((*pos >> 37) & 0xFF);

Have you considered using GENMASK_ULL instead of fiddling with the hex masks manually?

E.g. that would look like this

se = (*pos & GENMASK_ULL(14, 7)) >> 7; sh = (*pos & GENMASK_ULL(22, 15)) >> 15; cu = (*pos & GENMASK_ULL(30, 23)) >> 23; wave = (*pos & GENMASK_ULL(36, 31)) >> 31; simd = (*pos & GENMASK_ULL(44, 37)) >> 37;

if you ask me makes it totally obvious what is happening here and avoids such typos.

Might be that we even have some GENMASK_ULL + shift macro somewhere in the kernel, but I don't know of anything of hand.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf, · line 3772

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  	/* switch to the specific se/sh/cu */

_______________________________________________
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): c9e0f18f-3b94-b6c2-11b1-aa33ec1ab526-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw
Quoted 35 lines · Christian König

Am 10.11.2017 um 19:03 schrieb Tom St Denis:

Quoted 16 lines

The bottom two bits of the simd value were being put into the upper bits of the wave value which was likely working due to the bits being ignored (or aliased).

Eitherway, now we mask it correctly.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index c1f1b8f15395..cc59020d5874 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static ssize_t amdgpu_debugfs_wave_read(struct · line 3771

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -3766,7 +3766,7 @@ static ssize_t amdgpu_debugfs_wave_read(struct 
 file *f, char __user *buf,
       se = ((*pos >> 7) & 0xFF);
       sh = ((*pos >> 15) & 0xFF);
       cu = ((*pos >> 23) & 0xFF);
-    wave = ((*pos >> 31) & 0xFF);
+    wave = ((*pos >> 31) & 0x3F);
       simd = ((*pos >> 37) & 0xFF);

Have you considered using GENMASK_ULL instead of fiddling with the hex masks manually?

E.g. that would look like this

se = (*pos & GENMASK_ULL(14, 7)) >> 7; sh = (*pos & GENMASK_ULL(22, 15)) >> 15; cu = (*pos & GENMASK_ULL(30, 23)) >> 23; wave = (*pos & GENMASK_ULL(36, 31)) >> 31; simd = (*pos & GENMASK_ULL(44, 37)) >> 37;

Quoted 5 lines

if you ask me makes it totally obvious what is happening here and avoids such typos.

Might be that we even have some GENMASK_ULL + shift macro somewhere in the kernel, but I don't know of anything of hand.

Christian.

I'll take a gander it's a good suggestion. Though this could apply to 3 other functions in the debugfs side. Maybe do a fix patch first and then another patch to switch all 4 functions over to a cleaner approach (using GENMASK_ULL/etc)?

Tom
_______________________________________________
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): 4bc09ec7-d6f2-5a51-9652-bafd9385eb53-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Am 10.11.2017 um 19:29 schrieb Tom St Denis:

Quoted 36 lines · Christian König
Quoted 35 lines

Am 10.11.2017 um 19:03 schrieb Tom St Denis:

Quoted 16 lines

The bottom two bits of the simd value were being put into the upper bits of the wave value which was likely working due to the bits being ignored (or aliased).

Eitherway, now we mask it correctly.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index c1f1b8f15395..cc59020d5874 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static ssize_t amdgpu_debugfs_wave_read(struct · line 3771

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -3766,7 +3766,7 @@ static ssize_t amdgpu_debugfs_wave_read(struct 
 file *f, char __user *buf,
       se = ((*pos >> 7) & 0xFF);
       sh = ((*pos >> 15) & 0xFF);
       cu = ((*pos >> 23) & 0xFF);
-    wave = ((*pos >> 31) & 0xFF);
+    wave = ((*pos >> 31) & 0x3F);
       simd = ((*pos >> 37) & 0xFF);

Have you considered using GENMASK_ULL instead of fiddling with the hex masks manually?

E.g. that would look like this

se = (*pos & GENMASK_ULL(14, 7)) >> 7; sh = (*pos & GENMASK_ULL(22, 15)) >> 15; cu = (*pos & GENMASK_ULL(30, 23)) >> 23; wave = (*pos & GENMASK_ULL(36, 31)) >> 31; simd = (*pos & GENMASK_ULL(44, 37)) >> 37;

Quoted 8 lines
Quoted 5 lines

if you ask me makes it totally obvious what is happening here and avoids such typos.

Might be that we even have some GENMASK_ULL + shift macro somewhere in the kernel, but I don't know of anything of hand.

Christian.

I'll take a gander it's a good suggestion.  Though this could apply to 3 other functions in the debugfs side.  Maybe do a fix patch first and then another patch to switch all 4 functions over to a cleaner approach (using GENMASK_ULL/etc)?

For kernel work I would usually prefer a patch which fixes the original issue and then another one to clean up the coding and move to GENMASK_ULL, but it is such a minor issue that I probably don't care much.

Christian.

Quoted 6 lines

Tom
_______________________________________________
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

A message that is not in the archive (sent off-list or not yet received): 46c57bbf-c795-21dd-19ef-34e334801374-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#8 lore raw
Quoted 39 lines · Christian König

Am 10.11.2017 um 19:29 schrieb Tom St Denis:

Quoted 38 lines · Christian König
Quoted 37 lines

Am 10.11.2017 um 19:03 schrieb Tom St Denis:

Quoted 16 lines

The bottom two bits of the simd value were being put into the upper bits of the wave value which was likely working due to the bits being ignored (or aliased).

Eitherway, now we mask it correctly.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index c1f1b8f15395..cc59020d5874 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static ssize_t amdgpu_debugfs_wave_read(struct · line 3771

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -3766,7 +3766,7 @@ static ssize_t amdgpu_debugfs_wave_read(struct 
 file *f, char __user *buf,
       se = ((*pos >> 7) & 0xFF);
       sh = ((*pos >> 15) & 0xFF);
       cu = ((*pos >> 23) & 0xFF);
-    wave = ((*pos >> 31) & 0xFF);
+    wave = ((*pos >> 31) & 0x3F);
       simd = ((*pos >> 37) & 0xFF);

Have you considered using GENMASK_ULL instead of fiddling with the hex masks manually?

E.g. that would look like this

se = (*pos & GENMASK_ULL(14, 7)) >> 7; sh = (*pos & GENMASK_ULL(22, 15)) >> 15; cu = (*pos & GENMASK_ULL(30, 23)) >> 23; wave = (*pos & GENMASK_ULL(36, 31)) >> 31; simd = (*pos & GENMASK_ULL(44, 37)) >> 37;

if you ask me makes it totally obvious what is happening here and avoids such typos.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Might be that we even have some GENMASK_ULL + shift macro somewhere in the kernel, but I don't know of anything of hand.

Christian.

I'll take a gander it's a good suggestion.  Though this could apply to 3 other functions in the debugfs side.  Maybe do a fix patch first and then another patch to switch all 4 functions over to a cleaner approach (using GENMASK_ULL/etc)?

For kernel work I would usually prefer a patch which fixes the original issue and then another one to clean up the coding and move to GENMASK_ULL, but it is such a minor issue that I probably don't care much.

Hi Christian,

Cool because I had sent a v2 to the list on Friday later in the day :-).
Could use an R-b.

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