Skip to contentSkip to conversation

drm/msm: fbdev: Use client buffers

PATCH In review Thomas Zimmermann 3 participants 11 messages Jun 18 – Jul 31

Subsystems (3)

v2 of 3 In review Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/msm: fbdev: Use client buffers

A client buffer holds the DRM framebuffer for an in-kernel DRM client. Until now, msm created an internal ad-hoc framebuffer for its fbdev emulation, while by-passing the regular interfaces used by user-space compositors.

Convert msm's fbdev emulation to use client buffers. Replacing the existing code with a client buffer allows for stream-lining msm code and later also the fbdev helpers. The new framebuffer will be registered against the client's file and will support handles for GEM objects. It is then just another framebuffer within the DRM ecosystem.

Patches 1 and 6 change visibility of msm_framebuffer_init() during the refactoring. It is the easiest way to refactor the fbdev probe helper.

Patch 2 and 3 inline the fb allocation code into the fbdev-probe helper and fix it up a bit.

From there patches 4 and 5 convert fbdev buffer allocation to common DRM helpes and client buffers.

If all fbdev emulation helpers can be converted to client buffers, the emulation's whole framebuffer handling could possibly be moved into shared helpers.

v2:
- clarify on the page alignment of the framebuffer size (Dmitry)

Thomas Zimmermann (6):
drm/msm: Do not declare msm_framebuffer_init() as static drm/msm: fbdev: Inline msm_alloc_stolen_fb()
drm/msm: fbdev: Fix error reporting
drm/msm: fbdev: Calculate buffer geometry with format helpers drm/msm: fbdev: Use a DRM client buffer
drm/msm: Make msm_framebuffer_init() an internal interface again

 drivers/gpu/drm/msm/msm_drv.h   |  9 ---
 drivers/gpu/drm/msm/msm_fb.c    | 98 +++++++++------------------------
 drivers/gpu/drm/msm/msm_fbdev.c | 85 +++++++++++++++++++---------
 3 files changed, 85 insertions(+), 107 deletions(-)

base-commit: fc59f76558703febba8056be87d1c97d14f7485e

Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/6 drm/msm: Do not declare msm_framebuffer_init() as static

Declare msm_framebuffer_init() in msm_drv.h and remove the static qualifier. The function will be required in msm_fbdev.c after inlining msm_alloc_stolen_fb().

Also move msm_framebuffer_init() before msm_framebuffer_create(), so that it can later be made static again. Prepares msm's fbdev emulation for using client buffers.

---
 drivers/gpu/drm/msm/msm_drv.h |  4 ++
 drivers/gpu/drm/msm/msm_fb.c  | 72 +++++++++++++++++------------------
 2 files changed, 39 insertions(+), 37 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +4 -0
index 3787db8770ad..7dccf0713b02 100644
@@ -258,6 +258,10 @@ void msm_framebuffer_cleanup(struct drm_framebuffer *fb, bool needed_dirtyfb);
 uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb, int plane);
 struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
 const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
+struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
+					     const struct drm_format_info *info,
+					     const struct drm_mode_fb_cmd2 *mode_cmd,
+					     struct drm_gem_object **bos);
 struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
 		struct drm_file *file, const struct drm_format_info *info,
 		const struct drm_mode_fb_cmd2 *mode_cmd);
drivers/gpu/drm/msm/msm_fb.c +35 -37

90 lines not on this page · raw message

Signature · 1 line
2.54.0
#2 lore raw

PATCH v2 2/6 drm/msm: fbdev: Inline msm_alloc_stolen_fb()

In reply to Thomas Zimmermann

Inline msm_alloc_stolen_fb() into its only caller. This is necessary for converting fbdev emulation to use client buffers.

There are some minor changes:

- Handle errors for the non-stolen BO in the respective branch.

- Fill mode_cmd right before using it with msm_framebuffer_init(). Both will later be replaced with client-buffer interfaces.

- Set the modifier[0] to DRM_FORMAT_MOD_LINEAR. No functional change.

- Integrate the error handling with the existing clean-up.

---
 drivers/gpu/drm/msm/msm_drv.h   |  2 --
 drivers/gpu/drm/msm/msm_fb.c    | 46 ---------------------------------
 drivers/gpu/drm/msm/msm_fbdev.c | 44 +++++++++++++++++++++++++------
 3 files changed, 36 insertions(+), 56 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +0 -2
index 7dccf0713b02..01a64a32b843 100644
@@ -265,8 +265,6 @@ struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
 struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
 		struct drm_file *file, const struct drm_format_info *info,
 		const struct drm_mode_fb_cmd2 *mode_cmd);
-struct drm_framebuffer * msm_alloc_stolen_fb(struct drm_device *dev,
-		int w, int h, int p, uint32_t format);
 
 #ifdef CONFIG_DRM_MSM_KMS_FBDEV
 int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
drivers/gpu/drm/msm/msm_fb.c +0 -46

55 lines not on this page · raw message

drivers/gpu/drm/msm/msm_fbdev.c +36 -8

90 lines not on this page · raw message

Signature · 1 line
2.54.0
#3 lore raw

PATCH v2 3/6 drm/msm: fbdev: Fix error reporting

In reply to Thomas Zimmermann

Replace deprecated error reporting in msm_fbdev_driver_fbdev_probe(). Use drm_warn() and drm_err() instead.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +4 -4
index a507f1de0c5d..1eb0368a6d07 100644
@@ -114,11 +114,11 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 	DBG("allocating %d bytes for fb %d", size, dev->primary->index);
 	bo = msm_gem_new(dev, size, MSM_BO_SCANOUT | MSM_BO_WC | MSM_BO_STOLEN);
 	if (IS_ERR(bo)) {
-		dev_warn(dev->dev, "could not allocate stolen bo\n");
+		drm_warn(dev, "could not allocate stolen bo\n");
 		/* try regular bo: */
 		bo = msm_gem_new(dev, size, MSM_BO_SCANOUT | MSM_BO_WC);
 		if (IS_ERR(bo)) {
-			DRM_DEV_ERROR(dev->dev, "failed to allocate buffer object\n");
+			drm_err(dev, "failed to allocate buffer object\n");
 			return PTR_ERR(bo);
 		}
 	}
@@ -136,7 +136,7 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 						      mode_cmd.modifier[0]),
 				  &mode_cmd, &bo);
 	if (IS_ERR(fb)) {
-		DRM_DEV_ERROR(dev->dev, "failed to allocate fb\n");
+		drm_err(dev, "failed to allocate fb\n");
 		ret = PTR_ERR(fb);
 		goto err_drm_gem_object_put;
 	}
@@ -148,7 +148,7 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 	 */
 	ret = msm_gem_get_and_pin_iova(bo, priv->kms->vm, &paddr);
 	if (ret) {
-		DRM_DEV_ERROR(dev->dev, "failed to get buffer obj iova: %d\n", ret);
+		drm_err(dev, "failed to get buffer obj iova: %d\n", ret);
 		goto err_drm_framebuffer_remove;
 	}
 
Signature · 1 line
2.54.0
#4 lore raw

PATCH v2 4/6 drm/msm: fbdev: Calculate buffer geometry with format helpers

In reply to Thomas Zimmermann

Replace the geometry and size calculation in msm's fbdev emulation with DRM format helpers. This consists of a 4CC lookup from the fbdev parameters, format lookup, pitch calculation and size calculation. Then allocate the GEM buffer object for the framebuffer memory from the calculated size.

Explicitly align the size of the allocated GEM buffer object to full pages. The contained memory is the framebuffer memory as seen by fbdev. The page alignment is required for mmap.

v2:
- clarify the page alignment of the buffer size (Dmitry)

---
 drivers/gpu/drm/msm/msm_drv.h   |  7 -------
 drivers/gpu/drm/msm/msm_fbdev.c | 26 ++++++++++++--------------
 2 files changed, 12 insertions(+), 21 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +0 -7
index 01a64a32b843..b21f8971dfa1 100644
@@ -505,13 +505,6 @@ void msm_hrtimer_work_init(struct msm_hrtimer_work *work,
 #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
 #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
 
-static inline int align_pitch(int width, int bpp)
-{
-	int bytespp = (bpp + 7) / 8;
-	/* adreno needs pitch aligned to 32 pixels: */
-	return bytespp * ALIGN(width, 32);
-}
-
 /* for the generated headers: */
 #define INVALID_IDX(idx) ({BUG(); 0;})
 #define fui(x)                ({BUG(); 0;})
drivers/gpu/drm/msm/msm_fbdev.c +12 -14
index 1eb0368a6d07..5532c5779f17 100644
@@ -95,23 +95,25 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 	struct fb_info *fbi = helper->info;
 	struct drm_mode_fb_cmd2 mode_cmd = { };
 	struct drm_framebuffer *fb = NULL;
+	const struct drm_format_info *format;
+	u32 fourcc, pitch;
+	u64 size;
 	struct drm_gem_object *bo;
 	uint64_t paddr;
-	uint32_t format;
-	int ret, pitch;
-	int size;
-
-	format = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth);
+	int ret;
 
 	DBG("create fbdev: %dx%d@%d (%dx%d)", sizes->surface_width,
 			sizes->surface_height, sizes->surface_bpp,
 			sizes->fb_width, sizes->fb_height);
 
-	pitch = align_pitch(sizes->surface_width, sizes->surface_bpp);
+	fourcc = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth);
+	format = drm_get_format_info(dev, fourcc, DRM_FORMAT_MOD_LINEAR);
+	/* adreno needs pitch aligned to 32 pixels: */
+	pitch = drm_format_info_min_pitch(format, 0, ALIGN(sizes->surface_width, 32));
+	size = ALIGN(pitch * sizes->surface_height, PAGE_SIZE);
 
 	/* allocate backing bo */
-	size = pitch * sizes->surface_height;
-	DBG("allocating %d bytes for fb %d", size, dev->primary->index);
+	DBG("allocating %llu bytes for fb %d", size, dev->primary->index);
 	bo = msm_gem_new(dev, size, MSM_BO_SCANOUT | MSM_BO_WC | MSM_BO_STOLEN);
 	if (IS_ERR(bo)) {
 		drm_warn(dev, "could not allocate stolen bo\n");
@@ -125,16 +127,12 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 
 	msm_gem_object_set_name(bo, "stolenfb");
 
-	mode_cmd.pixel_format = format;
+	mode_cmd.pixel_format = fourcc;
 	mode_cmd.width = sizes->surface_width;
 	mode_cmd.height = sizes->surface_height;
 	mode_cmd.pitches[0] = pitch;
-	mode_cmd.modifier[0] = DRM_FORMAT_MOD_LINEAR;
 
-	fb = msm_framebuffer_init(dev,
-				  drm_get_format_info(dev, mode_cmd.pixel_format,
-						      mode_cmd.modifier[0]),
-				  &mode_cmd, &bo);
+	fb = msm_framebuffer_init(dev, format, &mode_cmd, &bo);
 	if (IS_ERR(fb)) {
 		drm_err(dev, "failed to allocate fb\n");
 		ret = PTR_ERR(fb);
Signature · 1 line
2.54.0
Reviewed-by on v2 4/6
#5 lore raw

Re: [PATCH v2 4/6] drm/msm: fbdev: Calculate buffer geometry with format helpers

Quoted 10 lines · Thomas Zimmermann

Replace the geometry and size calculation in msm's fbdev emulation with DRM format helpers. This consists of a 4CC lookup from the fbdev parameters, format lookup, pitch calculation and size calculation. Then allocate the GEM buffer object for the framebuffer memory from the calculated size.

Explicitly align the size of the allocated GEM buffer object to full pages. The contained memory is the framebuffer memory as seen by fbdev. The page alignment is required for mmap.

Quoted 9 lines

v2:
- clarify the page alignment of the buffer size (Dmitry)

---
 drivers/gpu/drm/msm/msm_drv.h   |  7 -------
 drivers/gpu/drm/msm/msm_fbdev.c | 26 ++++++++++++--------------
 2 files changed, 12 insertions(+), 21 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#6 lore raw

PATCH v2 5/6 drm/msm: fbdev: Use a DRM client buffer

In reply to Thomas Zimmermann

Replace the internal DRM framebuffer with a DRM client buffer. The client buffer allocates the DRM framebuffer on a file and also uses GEM object handles via the regular ADDFB2 interfaces.

Using client-buffer interfaces unifies framebuffer allocation for DRM clients in user space and msm's internal fbdev emulation. It also simplifies the clean-up side of the fbdev emulation.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 55 +++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 23 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +32 -23
index 5532c5779f17..f14db46aa51e 100644
@@ -41,17 +41,15 @@ static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
 static void msm_fbdev_fb_destroy(struct fb_info *info)
 {
 	struct drm_fb_helper *helper = (struct drm_fb_helper *)info->par;
-	struct drm_framebuffer *fb = helper->fb;
-	struct drm_gem_object *bo = msm_framebuffer_bo(fb, 0);
+	struct drm_gem_object *bo = msm_framebuffer_bo(helper->fb, 0);
 
 	DBG();
 
 	drm_fb_helper_fini(helper);
 
-	/* this will free the backing object */
 	msm_gem_put_vaddr(bo);
-	drm_framebuffer_remove(fb);
 
+	drm_client_buffer_delete(helper->buffer);
 	drm_client_release(&helper->client);
 }
 
@@ -90,15 +88,16 @@ static const struct drm_fb_helper_funcs msm_fbdev_helper_funcs = {
 int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 				 struct drm_fb_helper_surface_size *sizes)
 {
-	struct drm_device *dev = helper->dev;
+	struct drm_client_dev *client = &helper->client;
+	struct drm_device *dev = client->dev;
+	struct drm_file *file = client->file;
 	struct msm_drm_private *priv = dev->dev_private;
 	struct fb_info *fbi = helper->info;
-	struct drm_mode_fb_cmd2 mode_cmd = { };
-	struct drm_framebuffer *fb = NULL;
 	const struct drm_format_info *format;
-	u32 fourcc, pitch;
+	u32 fourcc, pitch, handle;
 	u64 size;
 	struct drm_gem_object *bo;
+	struct drm_client_buffer *buffer;
 	uint64_t paddr;
 	int ret;
 
@@ -127,16 +126,15 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 
 	msm_gem_object_set_name(bo, "stolenfb");
 
-	mode_cmd.pixel_format = fourcc;
-	mode_cmd.width = sizes->surface_width;
-	mode_cmd.height = sizes->surface_height;
-	mode_cmd.pitches[0] = pitch;
-
-	fb = msm_framebuffer_init(dev, format, &mode_cmd, &bo);
-	if (IS_ERR(fb)) {
-		drm_err(dev, "failed to allocate fb\n");
-		ret = PTR_ERR(fb);
+	ret = drm_gem_handle_create(file, bo, &handle);
+	if (ret)
 		goto err_drm_gem_object_put;
+
+	buffer = drm_client_buffer_create(client, sizes->surface_width, sizes->surface_height,
+					  fourcc, handle, pitch);
+	if (IS_ERR(buffer)) {
+		ret = PTR_ERR(buffer);
+		goto err_drm_gem_handle_delete;
 	}
 
 	/*
@@ -147,13 +145,14 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 	ret = msm_gem_get_and_pin_iova(bo, priv->kms->vm, &paddr);
 	if (ret) {
 		drm_err(dev, "failed to get buffer obj iova: %d\n", ret);
-		goto err_drm_framebuffer_remove;
+		goto err_drm_client_buffer_delete;
 	}
 
 	DBG("fbi=%p, dev=%p", fbi, dev);
 
 	helper->funcs = &msm_fbdev_helper_funcs;
-	helper->fb = fb;
+	helper->buffer = buffer;
+	helper->fb = buffer->fb;
 
 	fbi->fbops = &msm_fb_ops;
 
@@ -162,19 +161,29 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 	fbi->screen_buffer = msm_gem_get_vaddr(bo);
 	if (IS_ERR(fbi->screen_buffer)) {
 		ret = PTR_ERR(fbi->screen_buffer);
-		goto err_drm_framebuffer_remove;
+		goto err_msm_gem_put_vaddr;
 	}
 	fbi->screen_size = bo->size;
 	fbi->fix.smem_start = paddr;
 	fbi->fix.smem_len = bo->size;
 
 	DBG("par=%p, %dx%d", fbi->par, fbi->var.xres, fbi->var.yres);
-	DBG("allocated %dx%d fb", fb->width, fb->height);
+	DBG("allocated %dx%d fb", buffer->fb->width, buffer->fb->height);
+
+	/* The handle is only needed for creating the framebuffer. */
+	drm_gem_handle_delete(file, handle);
+
+	/* The framebuffer still holds a reference on the GEM object. */
+	drm_gem_object_put(bo);
 
 	return 0;
 
-err_drm_framebuffer_remove:
-	drm_framebuffer_remove(fb);
+err_msm_gem_put_vaddr:
+	msm_gem_put_vaddr(bo);
+err_drm_client_buffer_delete:
+	drm_client_buffer_delete(buffer);
+err_drm_gem_handle_delete:
+	drm_gem_handle_delete(file, handle);
 err_drm_gem_object_put:
 	drm_gem_object_put(bo);
 	return ret;
Signature · 1 line
2.54.0
#7 lore raw

Re: [PATCH v2 5/6] drm/msm: fbdev: Use a DRM client buffer

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Unbalanced `vmap_count` decrement and kernel warning on probe error path. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unbalanced vmap_count decrement and kernel warning on probe error path. --

commit a68322c2e5e8736f3b039ddfe130065a05ddf719
Author: Thomas Zimmermann <[email protected]>
drm/msm: fbdev: Use a DRM client buffer

This commit replaces the internal DRM framebuffer with a DRM client buffer in msm_fbdev. It unifies framebuffer allocation for DRM clients in user space and the internal fbdev emulation, and simplifies the clean-up side.

Quoted 4 lines
drivers/gpu/drm/msm/msm_fbdev.c +0 -0
index 5532c5779f17c..f14db46aa51e2 100644

[ ... ]

drivers/gpu/drm/msm/msm_fbdev.c int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, · line 164

Quoted 6 lines
drivers/gpu/drm/msm/msm_fbdev.c +1 -1
@@ -162,19 +161,29 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
 	fbi->screen_buffer = msm_gem_get_vaddr(bo);
 	if (IS_ERR(fbi->screen_buffer)) {
 		ret = PTR_ERR(fbi->screen_buffer);
-		goto err_drm_framebuffer_remove;
+		goto err_msm_gem_put_vaddr;

[Severity: Medium]
If msm_gem_get_vaddr() fails and returns an error pointer, the vmap_count is not incremented. Does jumping to err_msm_gem_put_vaddr here cause an unbalanced msm_gem_put_vaddr() call that will underflow vmap_count and trigger a GEM_WARN_ON() kernel warning?

It seems this should instead skip the put_vaddr step and jump straight to err_drm_client_buffer_delete.

Quoted 4 lines
drivers/gpu/drm/msm/msm_fbdev.c +0 -0
 	}
 	fbi->screen_size = bo->size;
 	fbi->fix.smem_start = paddr;
 	fbi->fix.smem_len = bo->size;

[ ... ]

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

Re: [PATCH v2 5/6] drm/msm: fbdev: Use a DRM client buffer

Quoted 11 lines · On Thu, Jun 18, 2026 at 02:26:56PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unbalanced vmap_count decrement and kernel warning on probe error path. --

commit a68322c2e5e8736f3b039ddfe130065a05ddf719
Author: Thomas Zimmermann <[email protected]>
drm/msm: fbdev: Use a DRM client buffer

This commit replaces the internal DRM framebuffer with a DRM client buffer in msm_fbdev. It unifies framebuffer allocation for DRM clients in user space and the internal fbdev emulation, and simplifies the clean-up side.

I'll fix this while applying

Signature · 2 lines
With best wishes
Dmitry
#9 lore raw

PATCH v2 6/6 drm/msm: Make msm_framebuffer_init() an internal interface again

In reply to Thomas Zimmermann

The only caller of msm_framebuffer_init() is msm_framebuffer_create() from the same source file. Declare the former as static.

---
 drivers/gpu/drm/msm/msm_drv.h | 4 ----
 drivers/gpu/drm/msm/msm_fb.c  | 8 ++++----
 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +0 -4
index b21f8971dfa1..2a3ce6afca1c 100644
@@ -258,10 +258,6 @@ void msm_framebuffer_cleanup(struct drm_framebuffer *fb, bool needed_dirtyfb);
 uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb, int plane);
 struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
 const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
-struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
-					     const struct drm_format_info *info,
-					     const struct drm_mode_fb_cmd2 *mode_cmd,
-					     struct drm_gem_object **bos);
 struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
 		struct drm_file *file, const struct drm_format_info *info,
 		const struct drm_mode_fb_cmd2 *mode_cmd);
drivers/gpu/drm/msm/msm_fb.c +4 -4
index dec550e6cf75..60c108d35d2a 100644
@@ -134,10 +134,10 @@ const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb)
 	return msm_fb->format;
 }
 
-struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
-					     const struct drm_format_info *info,
-					     const struct drm_mode_fb_cmd2 *mode_cmd,
-					     struct drm_gem_object **bos)
+static struct drm_framebuffer *
+msm_framebuffer_init(struct drm_device *dev, const struct drm_format_info *info,
+		     const struct drm_mode_fb_cmd2 *mode_cmd,
+		     struct drm_gem_object **bos)
 {
 	struct msm_drm_private *priv = dev->dev_private;
 	struct msm_kms *kms = priv->kms;
Signature · 1 line
2.54.0
#10 lore raw

Re: [PATCH v2 6/6] drm/msm: Make msm_framebuffer_init() an internal interface again

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 cleanup in the error path of msm_framebuffer_prepare() leading to resource leaks and potential hardware faults. --

commit 9c0f26778b6b3f337240eba05217d26a3010e217
Author: Thomas Zimmermann <[email protected]>

drm/msm: Make msm_framebuffer_init() an internal interface again

The patch makes msm_framebuffer_init() a static function since it is only called from msm_framebuffer_create() within the same source file.

[ ... ]

Quoted 6 lines
drivers/gpu/drm/msm/msm_fb.c +0 -0
index dec550e6cf750..60c108d35d2a1 100644
@@ -134,10 +134,10 @@ const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb)
 	return msm_fb->format;

drivers/gpu/drm/msm/msm_fb.c const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb) · line 140

Quoted 10 lines
drivers/gpu/drm/msm/msm_fb.c +4 -4
 }
 
-struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
-					     const struct drm_format_info *info,
-					     const struct drm_mode_fb_cmd2 *mode_cmd,
-					     struct drm_gem_object **bos)
+static struct drm_framebuffer *
+msm_framebuffer_init(struct drm_device *dev, const struct drm_format_info *info,
+		     const struct drm_mode_fb_cmd2 *mode_cmd,
+		     struct drm_gem_object **bos)

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this file, I noticed a missing cleanup in the error path of msm_framebuffer_prepare() that can lead to resource leaks and potential regressions.

When msm_framebuffer_prepare() successfully pins some planes but fails on a subsequent plane, it returns early:

drivers/gpu/drm/msm/msm_fb.c:msm_framebuffer_prepare() {
	...
	for (i = 0; i < n; i++) {
		msm_gem_vma_get(fb->obj[i]);
		ret = msm_gem_get_and_pin_iova(fb->obj[i], vm, &msm_fb->iova[i]);
		drm_dbg_state(fb->dev, "FB[%u]: iova[%d]: %08llx (%d)\n",
			      fb->base.id, i, msm_fb->iova[i], ret);
		if (ret)
			return ret;
	}
	...
}

Does returning immediately here fail to roll back the earlier pinned planes and vma_get references?

Furthermore, DRM core's drm_atomic_helper_prepare_planes() skips calling cleanup_fb() for the plane that failed its prepare_fb(). Since msm_fb->prepare_count is incremented at the start of the function but not decremented on this error path, will a subsequent attempt to use this framebuffer evaluate atomic_inc_return(&msm_fb->prepare_count) > 1 as true?

If it falsely returns success without pinning the remaining planes, could this result in an IOMMU fault or memory corruption during scanout when the hardware attempts to access unmapped addresses?

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