Skip to contentSkip to conversation

drm/amd/display: increase MAX_SURFACES in line with planes and streams

PATCH In review Melissa Wen 2 participants 8 messages Sep 25, 2024 – Oct 23, 2024

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

cover drm/amd/display: increase MAX_SURFACES in line with planes and streams

Hi!

AFAIU, the driver is defining two different max number of surfaces:
MAX_SURFACES (dc.h) and MAX_SURFACE_NUM (dc_types.h) Many years ago, MAX_SURFACES was set 3 just to prevent a stack size warning as in 091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3")[1]. But according to commit 3cfd03b79425 ("update max streams per surface")[2], from 2023, six is the real max number of surfaces supported by any asics and the warning that motivated [1] seems not valid anymore.

This mismatch looks a bit problematic per se, and I wonder if we should start using only one definition (MAX_SURFACES or MAX_SURFACE_NUM) in the whole driver.

Also, with MAX_PLANES and MAX_STREAMS both set as 6, there are some driver with max_slave_planes = 2 and so the maximum of 3 surfaces can cause an array-index-out-of-bonds, as reported by [3] and pointed out in the second patch of this series (MAX_SURFACES < plane_count).

I suppose that this blew up after 1d0c9ded4519 ("Introduce overlay cursor mode") [4], since it uses one more DCN plane for cursor overlay mode.

So, the first patch just update MAX_SURFACES to 6 and the second add some debug prints to warn when changes on these values might cause array-index-out-of-bounds.

Let me know your thoughts.

Thanks,

Melissa

[1] https://gitlab.freedesktop.org/agd5f/linux/-/commit/091a97e542cf
[2] https://gitlab.freedesktop.org/agd5f/linux/-/commit/3cfd03b79425
[3] https://gitlab.freedesktop.org/drm/amd/-/issues/3594
[4] https://lore.kernel.org/amd-gfx/[email protected]/

Melissa Wen (2):
drm/amd/display: increase max surfaces in line with planes and streams drm/amd/display: add warnings for MAX_SURFACES mismatch

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 20 +++++++++++++++++++
 drivers/gpu/drm/amd/display/dc/dc.h           |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 drm/amd/display: increase max surfaces in line with planes and streams

091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3") reduced the max number of surfaces since, at that time, there was no use for more. However, HW and driver evolves and there are now driver versions that allow two overlay planes (max_slave_planes). Moreover, commit 3cfd03b79425 ("drm/amd/display: update max streams per surface") states 6 is the max surfaces supported asics can have. Therefore, update MAX_SURFACES to match MAX_SURFACE_NUM, MAX_PLANES and MAX_STREAMS.

It also addresses array-index-out-of-bounds reported in the link.

---
 drivers/gpu/drm/amd/display/dc/dc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -1
index 3992ad73165b..08b00b263533 100644
@@ -57,7 +57,7 @@ struct dmub_notification;
 
 #define DC_VER "3.2.301"
 
-#define MAX_SURFACES 3
+#define MAX_SURFACES 6
 #define MAX_PLANES 6
 #define MAX_STREAMS 6
 #define MIN_VIEWPORT_SIZE 12
Signature · 1 line
2.45.2
#2 lore raw

RE: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Melissa,

MAX_SURFACE_NUM and MAX_PLANES both represent the upper bound of planes that are supported by HW. It is best to replace MAX_SURFACE_NUM with MAX_PLANES to remove redundancy. MAX_SURFACES is used to represent the upper bound of surfaces that can be piped to a single CRTC. Keep MAX_SURFACES as is to keep stack size down, and replace MAX_SURFACE_NUM with MAX_PLANES.

Thanks,
Zaeem

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Melissa Wen
Sent: Wednesday, September 25, 2024 11:37 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3") reduced the max number of surfaces since, at that time, there was no use for more. However, HW and driver evolves and there are now driver versions that allow two overlay planes (max_slave_planes). Moreover, commit 3cfd03b79425 ("drm/amd/display: update max streams per surface") states 6 is the max surfaces supported asics can have. Therefore, update MAX_SURFACES to match MAX_SURFACE_NUM, MAX_PLANES and MAX_STREAMS.

It also addresses array-index-out-of-bounds reported in the link.

---
 drivers/gpu/drm/amd/display/dc/dc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -1
index 3992ad73165b..08b00b263533 100644
@@ -57,7 +57,7 @@ struct dmub_notification;
 
 #define DC_VER "3.2.301"
 
-#define MAX_SURFACES 3
+#define MAX_SURFACES 6
 #define MAX_PLANES 6
 #define MAX_STREAMS 6
 #define MIN_VIEWPORT_SIZE 12

--
2.45.2

#3 lore raw

Re: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

Hi Zaeem,

Thanks for explaining their relationship.

So IIUC, current DM implementation for dc_surface_updates array is wrong, since it's taking MAX_SURFACES (=3) for allocation but MAX_PLANES (=6) as the upper bound of size of the dc_surface_updates array, as you can see in this allocation and after an iteration from 0 to plane_count:

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#L9861

Another question to understand what would be the right fix for the implementation above-mentioned: with the cursor overlay mode, it means we are using one of the overlay planes for this cursor overlay mode (one from the "max_slave_planes") or this cursor plane is an extra plane, which means, for some drivers, one primary plane + two overlay planes + one plane for cursor overlay mode (max 4 planes) ?

BR,

Melissa

Quoted 43 lines · Zaeem

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Melissa,

MAX_SURFACE_NUM and MAX_PLANES both represent the upper bound of planes that are supported by HW. It is best to replace MAX_SURFACE_NUM with MAX_PLANES to remove redundancy. MAX_SURFACES is used to represent the upper bound of surfaces that can be piped to a single CRTC. Keep MAX_SURFACES as is to keep stack size down, and replace MAX_SURFACE_NUM with MAX_PLANES.

Thanks,
Zaeem

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Melissa Wen
Sent: Wednesday, September 25, 2024 11:37 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3") reduced the max number of surfaces since, at that time, there was no use for more. However, HW and driver evolves and there are now driver versions that allow two overlay planes (max_slave_planes). Moreover, commit 3cfd03b79425 ("drm/amd/display: update max streams per surface") states 6 is the max surfaces supported asics can have. Therefore, update MAX_SURFACES to match MAX_SURFACE_NUM, MAX_PLANES and MAX_STREAMS.

It also addresses array-index-out-of-bounds reported in the link.

---
  drivers/gpu/drm/amd/display/dc/dc.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -2
index 3992ad73165b..08b00b263533 100644
@@ -57,7 +57,7 @@ struct dmub_notification;
 
  #define DC_VER "3.2.301"
 
-#define MAX_SURFACES 3
+#define MAX_SURFACES 6
  #define MAX_PLANES 6
  #define MAX_STREAMS 6
  #define MIN_VIEWPORT_SIZE 12
--

2.45.2

#4 lore raw

Re: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

Hi,

Gentle ping to land the fix for the kernel crash.
If faster, I can send a new version increasing max surfaces to 4 as previously discussed.

There are now two bug reports for the same issue:
- https://gitlab.freedesktop.org/drm/amd/-/issues/3693
- https://gitlab.freedesktop.org/drm/amd/-/issues/3594

Best Regards,

Melissa

Quoted 60 lines · Melissa Wen

Hi Zaeem,

Thanks for explaining their relationship.

So IIUC, current DM implementation for dc_surface_updates array is wrong, since it's taking MAX_SURFACES (=3) for allocation but MAX_PLANES (=6) as the upper bound of size of the dc_surface_updates array, as you can see in this allocation and after an iteration from 0 to plane_count:

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#L9861

Another question to understand what would be the right fix for the implementation above-mentioned: with the cursor overlay mode, it means we are using one of the overlay planes for this cursor overlay mode (one from the "max_slave_planes") or this cursor plane is an extra plane, which means, for some drivers, one primary plane + two overlay planes + one plane for cursor overlay mode (max 4 planes) ?

BR,

Melissa

Quoted 43 lines · Zaeem

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Melissa,

MAX_SURFACE_NUM and MAX_PLANES both represent the upper bound of planes that are supported by HW. It is best to replace MAX_SURFACE_NUM with MAX_PLANES to remove redundancy. MAX_SURFACES is used to represent the upper bound of surfaces that can be piped to a single CRTC. Keep MAX_SURFACES as is to keep stack size down, and replace MAX_SURFACE_NUM with MAX_PLANES.

Thanks,
Zaeem

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Melissa Wen
Sent: Wednesday, September 25, 2024 11:37 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3") reduced the max number of surfaces since, at that time, there was no use for more. However, HW and driver evolves and there are now driver versions that allow two overlay planes (max_slave_planes). Moreover, commit 3cfd03b79425 ("drm/amd/display: update max streams per surface") states 6 is the max surfaces supported asics can have. Therefore, update MAX_SURFACES to match MAX_SURFACE_NUM, MAX_PLANES and MAX_STREAMS.

It also addresses array-index-out-of-bounds reported in the link.

---
  drivers/gpu/drm/amd/display/dc/dc.h | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -1
index 3992ad73165b..08b00b263533 100644
@@ -57,7 +57,7 @@ struct dmub_notification;
 
   #define DC_VER "3.2.301"
 
-#define MAX_SURFACES 3
+#define MAX_SURFACES 6
   #define MAX_PLANES 6
   #define MAX_STREAMS 6
   #define MIN_VIEWPORT_SIZE 12
Signature · 1 line
2.45.2
#5 lore raw

RE: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

[AMD Official Use Only - AMD Internal Distribution Only]

Hi,

A patch addressing this will be sent out soon.

Thanks,
Zaeem

-----Original Message-----
From: Melissa Wen <[email protected]>
Sent: Tuesday, October 22, 2024 11:58 AM
To: Mohamed, Zaeem <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Siqueira, Rodrigo <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

Hi,

Gentle ping to land the fix for the kernel crash.
If faster, I can send a new version increasing max surfaces to 4 as previously discussed.

There are now two bug reports for the same issue:
- https://gitlab.freedesktop.org/drm/amd/-/issues/3693
- https://gitlab.freedesktop.org/drm/amd/-/issues/3594

Best Regards,

Melissa

Quoted 88 lines · Melissa Wen

Hi Zaeem,

Thanks for explaining their relationship.

So IIUC, current DM implementation for dc_surface_updates array is wrong, since it's taking MAX_SURFACES (=3) for allocation but MAX_PLANES (=6) as the upper bound of size of the dc_surface_updates array, as you can see in this allocation and after an iteration from 0 to plane_count:

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/disp
lay/amdgpu_dm/amdgpu_dm.c#L9861

Another question to understand what would be the right fix for the implementation above-mentioned: with the cursor overlay mode, it means we are using one of the overlay planes for this cursor overlay mode (one from the "max_slave_planes") or this cursor plane is an extra plane, which means, for some drivers, one primary plane + two overlay planes + one plane for cursor overlay mode (max 4 planes) ?

BR,

Melissa

Quoted 61 lines · Zaeem

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Melissa,

MAX_SURFACE_NUM and MAX_PLANES both represent the upper bound of planes that are supported by HW. It is best to replace MAX_SURFACE_NUM with MAX_PLANES to remove redundancy. MAX_SURFACES is used to represent the upper bound of surfaces that can be piped to a single CRTC. Keep MAX_SURFACES as is to keep stack size down, and replace MAX_SURFACE_NUM with MAX_PLANES.

Thanks,
Zaeem

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Melissa Wen
Sent: Wednesday, September 25, 2024 11:37 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3") reduced the max number of surfaces since, at that time, there was no use for more. However, HW and driver evolves and there are now driver versions that allow two overlay planes (max_slave_planes). Moreover, commit 3cfd03b79425 ("drm/amd/display: update max streams per surface") states 6 is the max surfaces supported asics can have. Therefore, update MAX_SURFACES to match MAX_SURFACE_NUM, MAX_PLANES and MAX_STREAMS.

It also addresses array-index-out-of-bounds reported in the link.

---
  drivers/gpu/drm/amd/display/dc/dc.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -2
index 3992ad73165b..08b00b263533 100644
@@ -57,7 +57,7 @@ struct dmub_notification;
 
  #define DC_VER "3.2.301"
 
-#define MAX_SURFACES 3
+#define MAX_SURFACES 6
  #define MAX_PLANES 6
  #define MAX_STREAMS 6
  #define MIN_VIEWPORT_SIZE 12
--

2.45.2

#6 lore raw

Re: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

Quoted 5 lines · Zaeem

[AMD Official Use Only - AMD Internal Distribution Only]

Hi,

A patch addressing this will be sent out soon.

Great! Thanks for the heads up!

Melissa

Quoted 113 lines

Thanks,
Zaeem

-----Original Message-----
From: Melissa Wen <[email protected]>
Sent: Tuesday, October 22, 2024 11:58 AM
To: Mohamed, Zaeem <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Siqueira, Rodrigo <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

Hi,

Gentle ping to land the fix for the kernel crash.
If faster, I can send a new version increasing max surfaces to 4 as previously discussed.

There are now two bug reports for the same issue:
- https://gitlab.freedesktop.org/drm/amd/-/issues/3693
- https://gitlab.freedesktop.org/drm/amd/-/issues/3594

Best Regards,

Melissa

Quoted 87 lines · Melissa Wen

Hi Zaeem,

Thanks for explaining their relationship.

So IIUC, current DM implementation for dc_surface_updates array is wrong, since it's taking MAX_SURFACES (=3) for allocation but MAX_PLANES (=6) as the upper bound of size of the dc_surface_updates array, as you can see in this allocation and after an iteration from 0 to plane_count:

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/disp
lay/amdgpu_dm/amdgpu_dm.c#L9861

Another question to understand what would be the right fix for the implementation above-mentioned: with the cursor overlay mode, it means we are using one of the overlay planes for this cursor overlay mode (one from the "max_slave_planes") or this cursor plane is an extra plane, which means, for some drivers, one primary plane + two overlay planes + one plane for cursor overlay mode (max 4 planes) ?

BR,

Melissa

Quoted 61 lines · Zaeem

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Melissa,

MAX_SURFACE_NUM and MAX_PLANES both represent the upper bound of planes that are supported by HW. It is best to replace MAX_SURFACE_NUM with MAX_PLANES to remove redundancy. MAX_SURFACES is used to represent the upper bound of surfaces that can be piped to a single CRTC. Keep MAX_SURFACES as is to keep stack size down, and replace MAX_SURFACE_NUM with MAX_PLANES.

Thanks,
Zaeem

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Melissa Wen
Sent: Wednesday, September 25, 2024 11:37 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/2] drm/amd/display: increase max surfaces in line with planes and streams

091a97e542cf ("drm/amd/display: Fix warning. Set MAX_SURFACES to 3") reduced the max number of surfaces since, at that time, there was no use for more. However, HW and driver evolves and there are now driver versions that allow two overlay planes (max_slave_planes). Moreover, commit 3cfd03b79425 ("drm/amd/display: update max streams per surface") states 6 is the max surfaces supported asics can have. Therefore, update MAX_SURFACES to match MAX_SURFACE_NUM, MAX_PLANES and MAX_STREAMS.

It also addresses array-index-out-of-bounds reported in the link.

---
   drivers/gpu/drm/amd/display/dc/dc.h | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -2
index 3992ad73165b..08b00b263533 100644
@@ -57,7 +57,7 @@ struct dmub_notification;
 
   #define DC_VER "3.2.301"
 
-#define MAX_SURFACES 3
+#define MAX_SURFACES 6
   #define MAX_PLANES 6
   #define MAX_STREAMS 6
   #define MIN_VIEWPORT_SIZE 12
--

2.45.2

#7 lore raw

PATCH 2/2 drm/amd/display: add warnings for MAX_SURFACES mismatch

In reply to Melissa Wen

So that, in the future, when the max number of planes and streams increases, they might be synced with the number of surfaces to prevent array-index-out-of-bounds issues.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +20 -0
index 6d12def3e8b3..95db2b1cc91a 100644
@@ -3098,6 +3098,13 @@ static void dm_gpureset_commit_state(struct dc_state *dc_state,
 	for (k = 0; k < dc_state->stream_count; k++) {
 		bundle->stream_update.stream = dc_state->streams[k];
 
+		if (MAX_SURFACES < dc_state->stream_status->plane_count) {
+			drm_warn(dm->ddev, "Not enough dc_surface_update for the "
+					   "number of planes. Please increase "
+					   "MAX_SURFACES inline to MAX_PLANES.\n");
+			continue;
+		}
+
 		for (m = 0; m < dc_state->stream_status->plane_count; m++) {
 			bundle->surface_updates[m].surface =
 				dc_state->stream_status->plane_states[m];
@@ -8923,6 +8930,13 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 		if (!dc_plane)
 			continue;
 
+		if (MAX_SURFACES < planes_count) {
+			drm_warn(dev, "Not enough dc_surface_update for the "
+				      "number of planes. Please increase "
+				      "MAX_SURFACES inline to MAX_PLANES.\n");
+			continue;
+		}
+
 		bundle->surface_updates[planes_count].surface = dc_plane;
 		if (new_pcrtc_state->color_mgmt_changed) {
 			bundle->surface_updates[planes_count].gamma = &dc_plane->gamma_correction;
@@ -9874,6 +9888,12 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 
 		WARN_ON(!status->plane_count);
 
+		if (MAX_SURFACES < status->plane_count) {
+			drm_warn(dev, "Not enough dc_surface_update for the "
+				      "number of planes. Please increase "
+				      "MAX_SURFACES inline to MAX_PLANES.\n");
+			continue;
+		}
 		/*
 		 * TODO: DC refuses to perform stream updates without a dc_surface_update.
 		 * Here we create an empty update on each plane.
Signature · 1 line
2.45.2