From: Pierre-Louis Dourneau <pl.dourneau@klervi.com>
To: Sam Ravnborg <sam@ravnborg.org>,
Boris Brezillon <bbrezillon@kernel.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
dri-devel@lists.freedesktop.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Manikandan Muralidharan <manikandan.m@microchip.com>
Cc: "Pierre-Louis Dourneau" <pl.dourneau@klervi.com>,
"Benoît Alcaina" <b.alcaina@klervi.com>,
"Arnaud Lahache" <a.lahache@klervi.com>,
"Nicolas Georges" <n.georges@klervi.com>
Subject: [PATCH] drm/atmel-hlcdc: Release CRTC commit when destroying plane state
Date: Wed, 6 Mar 2024 20:49:35 +0100 [thread overview]
Message-ID: <20240306194935.11871-1-pl.dourneau@klervi.com> (raw)
From: Arnaud Lahache <a.lahache@klervi.com>
Fixes a memory leak occurring on each modeset update.
Running a program such as libdrm's modetest[0] with this driver exhausts
all available memory after a few minutes. Enabling kmemleak yields a series
of such leak reports:
unreferenced object 0xc21acf40 (size 64):
comm "modetest", pid 210, jiffies 4294942460 (age 331.240s)
hex dump (first 32 bytes):
00 a0 a1 c1 01 00 00 00 ff ff ff ff 4c cf 1a c2 ............L...
4c cf 1a c2 ff ff ff ff 58 cf 1a c2 58 cf 1a c2 L.......X...X...
backtrace:
[<d68b3e09>] kmalloc_trace+0x18/0x24
[<f858a020>] drm_atomic_helper_setup_commit+0x1e0/0x7e0
[<26e8ab04>] drm_atomic_helper_commit+0x40/0x160
[<49708b0c>] drm_atomic_commit+0xa8/0xf0
[<e58c2942>] drm_mode_obj_set_property_ioctl+0x154/0x3d8
[<5e97e57d>] drm_ioctl+0x200/0x3c4
[<ed514ba1>] sys_ioctl+0x240/0xb48
[<26aab344>] ret_fast_syscall+0x0/0x44
drm_atomic_helper_setup_commit() acquires a reference to a drm_crtc_commit
for each CRTC and associated connectors and planes involved in a modeset.
64-byte leaks map well to the size of a drm_crtc_commit on 32-bit
architectures, and the second 4-byte chunk in the hex dump above awfully
looks like a reference count.
We tracked this missing reference decrement down to the driver's
atmel_hlcdc_plane_atomic_destroy_state() callback. Its CRTC counterpart,
atmel_hlcdc_crtc_destroy_state(), calls into the drm_atomic helpers and
properly releases its references to the commit. Planes didn't. Using the
default helper for that purpose, __drm_atomic_helper_plane_destroy_state(),
fixes the leak and avoids reimplementing the same logic in the driver.
[0]: https://gitlab.freedesktop.org/mesa/drm/-/tree/main/tests/modetest
Invoke with `modetest -M atmel-hlcdc -s 32:#0 -v`, assuming 32 is the
ID of a connector.
Signed-off-by: Arnaud Lahache <a.lahache@klervi.com>
Co-developed-by: Pierre-Louis Dourneau <pl.dourneau@klervi.com>
Signed-off-by: Pierre-Louis Dourneau <pl.dourneau@klervi.com>
Co-developed-by: Benoît Alcaina <b.alcaina@klervi.com>
Signed-off-by: Benoît Alcaina <b.alcaina@klervi.com>
---
As far as our testing goes, we've been running 6 of our production units
with this patch for more than 2 weeks as per the date this patch is sent
out. We can report stable memory usage.
Admittedly, our usage of the DRM uAPI is rather simple: create 2 dumb
buffers, do an initial MODE_SETCRTC, and then MODE_PAGE_FLIP between the
two dumb buffers at the rate of once per second on average. We haven't
evaluated more complex workloads.
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
index daa508504f47..390c4fc62af7 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
@@ -934,8 +934,7 @@ static void atmel_hlcdc_plane_atomic_destroy_state(struct drm_plane *p,
state->dscrs[i]->self);
}
- if (s->fb)
- drm_framebuffer_put(s->fb);
+ __drm_atomic_helper_plane_destroy_state(s);
kfree(state);
}
base-commit: 9dfc46c87cdc8f5a42a71de247a744a6b8188980
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2024-03-06 19:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 19:49 Pierre-Louis Dourneau [this message]
2024-03-08 8:00 ` [PATCH] drm/atmel-hlcdc: Release CRTC commit when destroying plane state Ludovic.Desroches
2024-03-12 8:40 ` Pierre-Louis Dourneau
2024-03-15 12:25 ` Pierre-Louis Dourneau
2024-03-21 6:45 ` Ludovic.Desroches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240306194935.11871-1-pl.dourneau@klervi.com \
--to=pl.dourneau@klervi.com \
--cc=a.lahache@klervi.com \
--cc=airlied@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=b.alcaina@klervi.com \
--cc=bbrezillon@kernel.org \
--cc=claudiu.beznea@tuxon.dev \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=manikandan.m@microchip.com \
--cc=mripard@kernel.org \
--cc=n.georges@klervi.com \
--cc=nicolas.ferre@microchip.com \
--cc=sam@ravnborg.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox