Skip to contentSkip to conversation

drm/amdgpu: deduplicate JPEG v5.0 interrupt routine

PATCH RESEND Superseded Andre Luiz Batista Bueno 3 participants 6 messages May 10 – Jun 24

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 drm/amdgpu: deduplicate JPEG v5.0 interrupt routine

Both jpeg_v5_0_1.c and jpeg_v5_0_2.c implement identical interrupt processing routines. To avoid code duplication, extract this implementation into a shared common function in new jpeg_v5_0_interrupt.c and .h files.

---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  1 +
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c      | 57 +----------------
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c      | 57 +----------------
 .../gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.c  | 64 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.h  | 12 ++++
 5 files changed, 83 insertions(+), 108 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.h
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
index db66c6372199..69e5e55e1a2b 100644
@@ -229,6 +229,7 @@ amdgpu-y += \
 	jpeg_v5_0_0.o \
 	jpeg_v5_0_1.o \
 	jpeg_v5_0_2.o \
+	jpeg_v5_0_interrupt.o \
 	jpeg_v5_3_0.o
 
 # add VPE block
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +3 -54

69 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +3 -54

69 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.c new file +64 -0

64 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.h new file +12 -0
new file mode 100644
index 000000000000..046bcb4a3906
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+
+#ifndef __JPEG_V5_0_INTERRUPT_H__
+#define __JPEG_V5_0_INTERRUPT_H__
+
+struct amdgpu_device;
+struct amdgpu_iv_entry;
+
+int jpeg_v5_0_process_interrupt_common(struct amdgpu_device *adev,
+				       struct amdgpu_iv_entry *entry);
+
+#endif /* __JPEG_V5_0_INTERRUPT_H__ */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · Andre Luiz Batista Bueno

Both jpeg_v5_0_1.c and jpeg_v5_0_2.c implement identical interrupt processing routines. To avoid code duplication, extract this implementation into a shared common function in new jpeg_v5_0_interrupt.c and .h files.

Quoted 9 lines
---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  1 +
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c      | 57 +----------------
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c      | 57 +----------------
 .../gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.c  | 64 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.h  | 12 ++++
 5 files changed, 83 insertions(+), 108 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.h

This is not common to jpeg v5. jpeg_v5_0_0.c has a different interrupt handler, although it could probably be shared with that as well. I think the additional fields in the IH should be 0s so it should work correctly, but we'd need to verify. If you do want to share this, I would just make the implementation in jpeg_v5_0_1.c non-static and then just use it directly in jpeg_v5_0_2.c.

Alex

Quoted 254 lines
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
index db66c6372199..69e5e55e1a2b 100644
@@ -229,6 +229,7 @@ amdgpu-y += \
        jpeg_v5_0_0.o \
        jpeg_v5_0_1.o \
        jpeg_v5_0_2.o \
+       jpeg_v5_0_interrupt.o \
        jpeg_v5_3_0.o
 
 # add VPE block
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +3 -54
index edecbfe66c79..6e5611921eda 100644
@@ -34,6 +34,8 @@
 #include "vcn/vcn_5_0_0_sh_mask.h"
 #include "ivsrcid/vcn/irqsrcs_vcn_5_0.h"
 
+#include "jpeg_v5_0_interrupt.h"
+
 static int jpeg_v5_0_1_start_sriov(struct amdgpu_device *adev);
 static void jpeg_v5_0_1_set_dec_ring_funcs(struct amdgpu_device *adev);
 static void jpeg_v5_0_1_set_irq_funcs(struct amdgpu_device *adev);
@@ -759,60 +761,7 @@ static int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
                                         struct amdgpu_irq_src *source,
                                         struct amdgpu_iv_entry *entry)
 {
-       u32 i, inst;
-
-       i = node_id_to_phys_map[entry->node_id];
-       DRM_DEV_DEBUG(adev->dev, "IH: JPEG TRAP\n");
-
-       for (inst = 0; inst < adev->jpeg.num_jpeg_inst; ++inst)
-               if (adev->jpeg.inst[inst].aid_id == i)
-                       break;
-
-       if (inst >= adev->jpeg.num_jpeg_inst) {
-               dev_WARN_ONCE(adev->dev, 1,
-                             "Interrupt received for unknown JPEG instance %d",
-                             entry->node_id);
-               return 0;
-       }
-
-       switch (entry->src_id) {
-       case VCN_5_0__SRCID__JPEG_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[0]);
-               break;
-       case VCN_5_0__SRCID__JPEG1_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[1]);
-               break;
-       case VCN_5_0__SRCID__JPEG2_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[2]);
-               break;
-       case VCN_5_0__SRCID__JPEG3_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[3]);
-               break;
-       case VCN_5_0__SRCID__JPEG4_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[4]);
-               break;
-       case VCN_5_0__SRCID__JPEG5_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[5]);
-               break;
-       case VCN_5_0__SRCID__JPEG6_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[6]);
-               break;
-       case VCN_5_0__SRCID__JPEG7_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[7]);
-               break;
-       case VCN_5_0__SRCID__JPEG8_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[8]);
-               break;
-       case VCN_5_0__SRCID__JPEG9_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[9]);
-               break;
-       default:
-               DRM_DEV_ERROR(adev->dev, "Unhandled interrupt: %d %d\n",
-                             entry->src_id, entry->src_data[0]);
-               break;
-       }
-
-       return 0;
+       return jpeg_v5_0_process_interrupt_common(adev, entry);
 }
 
 static void jpeg_v5_0_1_core_stall_reset(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +3 -54
index 285c459379c4..daea95907639 100644
@@ -34,6 +34,8 @@
 #include "vcn/vcn_5_0_0_sh_mask.h"
 #include "ivsrcid/vcn/irqsrcs_vcn_5_0.h"
 
+#include "jpeg_v5_0_interrupt.h"
+
 static void jpeg_v5_0_2_set_dec_ring_funcs(struct amdgpu_device *adev);
 static void jpeg_v5_0_2_set_irq_funcs(struct amdgpu_device *adev);
 static int jpeg_v5_0_2_set_powergating_state(struct amdgpu_ip_block *ip_block,
@@ -587,60 +589,7 @@ static int jpeg_v5_0_2_process_interrupt(struct amdgpu_device *adev,
                                         struct amdgpu_irq_src *source,
                                         struct amdgpu_iv_entry *entry)
 {
-       u32 i, inst;
-
-       i = node_id_to_phys_map[entry->node_id];
-       DRM_DEV_DEBUG(adev->dev, "IH: JPEG TRAP\n");
-
-       for (inst = 0; inst < adev->jpeg.num_jpeg_inst; ++inst)
-               if (adev->jpeg.inst[inst].aid_id == i)
-                       break;
-
-       if (inst >= adev->jpeg.num_jpeg_inst) {
-               dev_WARN_ONCE(adev->dev, 1,
-                             "Interrupt received for unknown JPEG instance %d",
-                             entry->node_id);
-               return 0;
-       }
-
-       switch (entry->src_id) {
-       case VCN_5_0__SRCID__JPEG_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[0]);
-               break;
-       case VCN_5_0__SRCID__JPEG1_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[1]);
-               break;
-       case VCN_5_0__SRCID__JPEG2_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[2]);
-               break;
-       case VCN_5_0__SRCID__JPEG3_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[3]);
-               break;
-       case VCN_5_0__SRCID__JPEG4_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[4]);
-               break;
-       case VCN_5_0__SRCID__JPEG5_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[5]);
-               break;
-       case VCN_5_0__SRCID__JPEG6_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[6]);
-               break;
-       case VCN_5_0__SRCID__JPEG7_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[7]);
-               break;
-       case VCN_5_0__SRCID__JPEG8_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[8]);
-               break;
-       case VCN_5_0__SRCID__JPEG9_DECODE:
-               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[9]);
-               break;
-       default:
-               DRM_DEV_ERROR(adev->dev, "Unhandled interrupt: %d %d\n",
-                             entry->src_id, entry->src_data[0]);
-               break;
-       }
-
-       return 0;
+       return jpeg_v5_0_process_interrupt_common(adev, entry);
 }
 
 static void jpeg_v5_0_2_core_stall_reset(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.c new file +64 -0
new file mode 100644
index 000000000000..a76ee6586b63
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+
+#include "amdgpu.h"
+#include "ivsrcid/vcn/irqsrcs_vcn_5_0.h"
+#include "jpeg_v5_0_interrupt.h"
+
+int jpeg_v5_0_process_interrupt_common(struct amdgpu_device *adev,
+                                      struct amdgpu_iv_entry *entry)
+{
+       u32 i, inst;
+
+       i = node_id_to_phys_map[entry->node_id];
+       DRM_DEV_DEBUG(adev->dev, "IH: JPEG TRAP\n");
+
+       for (inst = 0; inst < adev->jpeg.num_jpeg_inst; ++inst)
+               if (adev->jpeg.inst[inst].aid_id == i)
+                       break;
+
+       if (inst >= adev->jpeg.num_jpeg_inst) {
+               dev_WARN_ONCE(adev->dev, 1,
+                             "Interrupt received for unknown JPEG instance %d",
+                             entry->node_id);
+               return 0;
+       }
+
+       switch (entry->src_id) {
+       case VCN_5_0__SRCID__JPEG_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[0]);
+               break;
+       case VCN_5_0__SRCID__JPEG1_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[1]);
+               break;
+       case VCN_5_0__SRCID__JPEG2_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[2]);
+               break;
+       case VCN_5_0__SRCID__JPEG3_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[3]);
+               break;
+       case VCN_5_0__SRCID__JPEG4_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[4]);
+               break;
+       case VCN_5_0__SRCID__JPEG5_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[5]);
+               break;
+       case VCN_5_0__SRCID__JPEG6_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[6]);
+               break;
+       case VCN_5_0__SRCID__JPEG7_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[7]);
+               break;
+       case VCN_5_0__SRCID__JPEG8_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[8]);
+               break;
+       case VCN_5_0__SRCID__JPEG9_DECODE:
+               amdgpu_fence_process(&adev->jpeg.inst[inst].ring_dec[9]);
+               break;
+       default:
+               DRM_DEV_ERROR(adev->dev, "Unhandled interrupt: %d %d\n",
+                             entry->src_id, entry->src_data[0]);
+               break;
+       }
+
+       return 0;
+}
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_interrupt.h new file +12 -1
new file mode 100644
index 000000000000..046bcb4a3906
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+
+#ifndef __JPEG_V5_0_INTERRUPT_H__
+#define __JPEG_V5_0_INTERRUPT_H__
+
+struct amdgpu_device;
+struct amdgpu_iv_entry;
+
+int jpeg_v5_0_process_interrupt_common(struct amdgpu_device *adev,
+                                      struct amdgpu_iv_entry *entry);
+
+#endif /* __JPEG_V5_0_INTERRUPT_H__ */
--

2.43.0

#2 lore raw

PATCH v2 1/1 drm/amdgpu: deduplicate JPEG v5.0 interrupt routine

Both jpeg_v5_0_1.c and jpeg_v5_0_2.c implement identical interrupt processing routines. To avoid code duplication, make the implementation in jpeg_v5_0_1.c non-static and call it directly from jpeg_v5_0_2.c.

---

v2:
- Dropped the new jpeg_v5_0_interrupt.c/h files and Makefile changes.
- Kept the interrupt routine in jpeg_v5_0_1.c but removed the 'static' modifier.
- Declared the function prototype in jpeg_v5_0_1.h and included it in jpeg_v5_0_2.c to call it directly, as suggested by Alex Deucher.

 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.h |  8 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c | 63 ++----------------------
 3 files changed, 12 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1 -1
index edecbfe66c79..46bcbecd89e8 100644
@@ -755,7 +755,7 @@ static int jpeg_v5_0_1_set_ras_interrupt_state(struct amdgpu_device *adev,
 
 
 
-static int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
+int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
 					 struct amdgpu_irq_src *source,
 					 struct amdgpu_iv_entry *entry)
 {
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.h +8 -0
index a7e58d5fb246..67346faecb47 100644
@@ -108,4 +108,12 @@ enum amdgpu_jpeg_v5_0_1_sub_block {
 	AMDGPU_JPEG_V5_0_1_MAX_SUB_BLOCK,
 };
 
+struct amdgpu_irq_src;
+struct amdgpu_iv_entry;
+struct amdgpu_device;
+
+int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
+					struct amdgpu_irq_src *source,
+					struct amdgpu_iv_entry *entry);
+
 #endif /* __JPEG_V5_0_1_H__ */
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +3 -60

81 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing bounds check on entry->node_id before array indexing on node_id_to_phys_map can lead to an out-of-bounds memory read. --

commit 18102389ca6554c76ab0eea5128ed6304f9d3003
Author: Andre Luiz Batista Bueno <[email protected]>

drm/amdgpu: deduplicate JPEG v5.0 interrupt routine

Both jpeg_v5_0_1.c and jpeg_v5_0_2.c implement identical interrupt processing routines. To avoid code duplication, make the implementation in jpeg_v5_0_1.c non-static and call it directly from jpeg_v5_0_2.c.

drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c static int jpeg_v5_0_1_set_ras_interrupt_state(struct amdgpu_device *adev, · line 761

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1 -1
index 250316704dfac..2b8d8f4ca30d2 100644
@@ -755,7 +755,7 @@ static int jpeg_v5_0_1_set_ras_interrupt_state(struct amdgpu_device *adev,
 
 
 
-static int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
+int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
 					 struct amdgpu_irq_src *source,
 					 struct amdgpu_iv_entry *entry)
 {

[Severity: High]
This is a pre-existing issue, but since this function is being exported to be shared by other JPEG v5.0 blocks, could an out-of-bounds array access occur here?

Looking at the beginning of jpeg_v5_0_1_process_interrupt():

	u32 i, inst;

	i = node_id_to_phys_map[entry->node_id];

The entry->node_id is extracted from the GPU's Interrupt Ring buffer using an 8-bit mask, allowing values up to 255. However, node_id_to_phys_map is defined globally with a fixed size of NODEID_MAX (15 elements).

Without a bounds check verifying entry->node_id < NODEID_MAX before indexing the array, could a malformed hardware interrupt payload cause the driver to read out-of-bounds memory?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

PATCH RESEND v2 1/1 drm/amdgpu: deduplicate JPEG v5.0 interrupt routine

In reply to Alex Deucher

Both jpeg_v5_0_1.c and jpeg_v5_0_2.c implement identical interrupt processing routines. To avoid code duplication, make the implementation in jpeg_v5_0_1.c non-static and call it directly from jpeg_v5_0_2.c.

---

v2:
- Dropped the new jpeg_v5_0_interrupt.c/h files and Makefile changes.
- Kept the interrupt routine in jpeg_v5_0_1.c but removed the 'static' modifier.
- Declared the function prototype in jpeg_v5_0_1.h and included it in jpeg_v5_0_2.c to call it directly, as suggested by Alex Deucher.

 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.h |  8 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c | 63 ++----------------------
 3 files changed, 12 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1 -1
index edecbfe66c79..46bcbecd89e8 100644
@@ -755,7 +755,7 @@ static int jpeg_v5_0_1_set_ras_interrupt_state(struct amdgpu_device *adev,
 
 
 
-static int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
+int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
 					 struct amdgpu_irq_src *source,
 					 struct amdgpu_iv_entry *entry)
 {
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.h +8 -0
index a7e58d5fb246..67346faecb47 100644
@@ -108,4 +108,12 @@ enum amdgpu_jpeg_v5_0_1_sub_block {
 	AMDGPU_JPEG_V5_0_1_MAX_SUB_BLOCK,
 };
 
+struct amdgpu_irq_src;
+struct amdgpu_iv_entry;
+struct amdgpu_device;
+
+int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
+					struct amdgpu_irq_src *source,
+					struct amdgpu_iv_entry *entry);
+
 #endif /* __JPEG_V5_0_1_H__ */
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +3 -60

81 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Potential out-of-bounds array access when indexing node_id_to_phys_map with unvalidated entry->node_id. --

commit 9ee6645118b792b4fedbe83c62cc09cc3bce36b1
Author: Andre Luiz Batista Bueno <[email protected]>

drm/amdgpu: deduplicate JPEG v5.0 interrupt routine

This commit deduplicates identical interrupt processing routines in jpeg_v5_0_1.c and jpeg_v5_0_2.c. It updates jpeg_v5_0_1_process_interrupt() to be non-static and calls it directly from the jpeg_v5_0_2 interrupt handlers to avoid code duplication.

drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c static int jpeg_v5_0_1_set_ras_interrupt_state(struct amdgpu_device *adev, · line 761

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1 -1
index 250316704dfac..2b8d8f4ca30d2 100644
@@ -755,7 +755,7 @@ static int jpeg_v5_0_1_set_ras_interrupt_state(struct amdgpu_device *adev,
 
 
 
-static int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
+int jpeg_v5_0_1_process_interrupt(struct amdgpu_device *adev,
 					 struct amdgpu_irq_src *source,
 					 struct amdgpu_iv_entry *entry)
 {

[Severity: High]
This is a pre-existing issue, but does this function lack bounds checking on entry->node_id before using it as an array index?

When the interrupt vector is read from the hardware-writeable IH ring, entry->node_id can be an 8-bit value (0-255). Looking at how this is handled inside jpeg_v5_0_1_process_interrupt():

int jpeg_v5_0_1_process_interrupt(...)

{
	u32 i, inst;

	i = node_id_to_phys_map[entry->node_id];
        ...
}

Could a malicious or malfunctioning PCIe device supply an interrupt vector with a node_id >= NODEID_MAX (15), leading to an out-of-bounds read of up to 1020 bytes past the end of the node_id_to_phys_map array and a potential kernel panic?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1