Skip to contentSkip to conversation

drm/amdgpu: skip force complete fences when ring is uninitialized

PATCH Superseded Bob Zhou 3 participants 4 messages May 31, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH 1/1 drm/amdgpu: skip force complete fences when ring is uninitialized

uvd ring in uvd_v7_0_sw_init only initializes ring in bare metal case, so when executing amdgpu_uvd_resume to restore fence seq in SRIOV, a null pointer dereference will occur. This patch correct this.

Fixes 043f2271e2d0a ("drm/amdgpu: mark force completed fences with -ECANCELED")
BUG: kernel NULL pointer dereference, address: 0000000000000000
Oops: 0000 [#1] PREEMPT SMP PTI
RIP: 0010:amdgpu_fence_driver_set_error+0x3f/0xc0 [amdgpu]
Call Trace:
 <TASK>
 amdgpu_fence_driver_force_completion+0x18/0x50 [amdgpu]
 amdgpu_uvd_resume+0x1b2/0x380 [amdgpu]
 ? amdgpu_ring_init+0x73c/0x820 [amdgpu]
 uvd_v7_0_sw_init+0x358/0x450 [amdgpu]
 amdgpu_device_init.cold+0x198c/0x1fdf [amdgpu]
 ? pci_bus_read_config_byte+0x40/0x80
 ? pci_read_config_byte+0x27/0x50
 amdgpu_driver_load_kms+0x1a/0x160 [amdgpu]
 amdgpu_pci_probe+0x186/0x3c0 [amdgpu]
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -0
index c694b41f6461..d2c5484309a6 100644
@@ -723,6 +723,8 @@ void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error)
  */
 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
 {
+	if (ring->fence_drv.irq_src)
+		return;
 	amdgpu_fence_driver_set_error(ring, -ECANCELED);
 	amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
 	amdgpu_fence_process(ring);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

[Public]

Regards,
Guchun

Quoted 52 lines

-----Original Message-----
From: Bob Zhou <[email protected]>
Sent: Wednesday, May 31, 2023 12:48 PM
To: [email protected]; Min, Frank <[email protected]>; Koenig, Christian <[email protected]>
Cc: Chen, Guchun <[email protected]>; Zhou, Bob <[email protected]>
Subject: [PATCH] drm/amdgpu: skip force complete fences when ring is uninitialized

uvd ring in uvd_v7_0_sw_init only initializes ring in bare metal case, so when executing amdgpu_uvd_resume to restore fence seq in SRIOV, a null pointer dereference will occur. This patch correct this.

Fixes 043f2271e2d0a ("drm/amdgpu: mark force completed fences with -

ECANCELED")

BUG: kernel NULL pointer dereference, address: 0000000000000000
Oops: 0000 [#1] PREEMPT SMP PTI
RIP: 0010:amdgpu_fence_driver_set_error+0x3f/0xc0 [amdgpu] Call Trace:
 <TASK>
 amdgpu_fence_driver_force_completion+0x18/0x50 [amdgpu]
 amdgpu_uvd_resume+0x1b2/0x380 [amdgpu]
 ? amdgpu_ring_init+0x73c/0x820 [amdgpu]
 uvd_v7_0_sw_init+0x358/0x450 [amdgpu]
 amdgpu_device_init.cold+0x198c/0x1fdf [amdgpu]  ?
pci_bus_read_config_byte+0x40/0x80
 ? pci_read_config_byte+0x27/0x50
 amdgpu_driver_load_kms+0x1a/0x160 [amdgpu]
 amdgpu_pci_probe+0x186/0x3c0 [amdgpu]
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -1
index c694b41f6461..d2c5484309a6 100644
@@ -723,6 +723,8 @@ void amdgpu_fence_driver_set_error(struct
 amdgpu_ring *ring, int error)
  */
 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)  {
+     if (ring->fence_drv.irq_src)
+             return;
      amdgpu_fence_driver_set_error(ring, -ECANCELED);
      amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
      amdgpu_fence_process(ring);
--

2.34.1

maintainer
#2 lore raw
In reply to Bob Zhou

Am 31.05.23 um 06:48 schrieb Bob Zhou:

Quoted 3 lines

uvd ring in uvd_v7_0_sw_init only initializes ring in bare metal case, so when executing amdgpu_uvd_resume to restore fence seq in SRIOV, a null pointer dereference will occur. This patch correct this.

Ah! I was already wondering how this bug reports came to be.

In this case please fix the UVD code to not call amdgpu_fence_driver_force_completion() in the first place instead of hacking around that in the fence code.

Regards,
Christian.

Quoted 36 lines
Fixes 043f2271e2d0a ("drm/amdgpu: mark force completed fences with -ECANCELED")
BUG: kernel NULL pointer dereference, address: 0000000000000000
Oops: 0000 [#1] PREEMPT SMP PTI
RIP: 0010:amdgpu_fence_driver_set_error+0x3f/0xc0 [amdgpu]
Call Trace:
  <TASK>
  amdgpu_fence_driver_force_completion+0x18/0x50 [amdgpu]
  amdgpu_uvd_resume+0x1b2/0x380 [amdgpu]
  ? amdgpu_ring_init+0x73c/0x820 [amdgpu]
  uvd_v7_0_sw_init+0x358/0x450 [amdgpu]
  amdgpu_device_init.cold+0x198c/0x1fdf [amdgpu]
  ? pci_bus_read_config_byte+0x40/0x80
  ? pci_read_config_byte+0x27/0x50
  amdgpu_driver_load_kms+0x1a/0x160 [amdgpu]
  amdgpu_pci_probe+0x186/0x3c0 [amdgpu]
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -0
index c694b41f6461..d2c5484309a6 100644
@@ -723,6 +723,8 @@ void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error)
   */
  void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
  {
+	if (ring->fence_drv.irq_src)
+		return;
  	amdgpu_fence_driver_set_error(ring, -ECANCELED);
  	amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
  	amdgpu_fence_process(ring);
author
#3 lore raw

[AMD Official Use Only - General]

Hi Christian,

Thanks for your suggestion. I will apply it and send out the v2 patch for review.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, May 31, 2023 4:33 PM
To: Zhou, Bob <[email protected]>; [email protected]; Min, Frank <[email protected]>
Cc: Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: skip force complete fences when ring is uninitialized

Am 31.05.23 um 06:48 schrieb Bob Zhou:

Quoted 3 lines

uvd ring in uvd_v7_0_sw_init only initializes ring in bare metal case, so when executing amdgpu_uvd_resume to restore fence seq in SRIOV, a null pointer dereference will occur. This patch correct this.

Ah! I was already wondering how this bug reports came to be.

In this case please fix the UVD code to not call
amdgpu_fence_driver_force_completion() in the first place instead of hacking around that in the fence code.

Regards,
Christian.

Quoted 37 lines
Fixes 043f2271e2d0a ("drm/amdgpu: mark force completed fences with

-ECANCELED")

BUG: kernel NULL pointer dereference, address: 0000000000000000
Oops: 0000 [#1] PREEMPT SMP PTI
RIP: 0010:amdgpu_fence_driver_set_error+0x3f/0xc0 [amdgpu] Call Trace:
  <TASK>
  amdgpu_fence_driver_force_completion+0x18/0x50 [amdgpu]
  amdgpu_uvd_resume+0x1b2/0x380 [amdgpu]
  ? amdgpu_ring_init+0x73c/0x820 [amdgpu]
  uvd_v7_0_sw_init+0x358/0x450 [amdgpu]
  amdgpu_device_init.cold+0x198c/0x1fdf [amdgpu]
  ? pci_bus_read_config_byte+0x40/0x80
  ? pci_read_config_byte+0x27/0x50
  amdgpu_driver_load_kms+0x1a/0x160 [amdgpu]
  amdgpu_pci_probe+0x186/0x3c0 [amdgpu]
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -0
index c694b41f6461..d2c5484309a6 100644
@@ -723,6 +723,8 @@ void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error)
   */
  void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
  {
+     if (ring->fence_drv.irq_src)
+             return;
      amdgpu_fence_driver_set_error(ring, -ECANCELED);
      amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
      amdgpu_fence_process(ring);