Skip to contentSkip to conversation

dri: print error message if drmModeRmFB fails

PATCH In review Imre Deak 2 participants 3 messages Aug 31, 2012 – Sep 5, 2012

lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/2 dri: print error message if drmModeRmFB fails

This can fail at least if the caller is not in DRM master mode and leak the corresponding FB object. So it's better to be verbose about it.

---
 src/intel_display.c |   25 ++++++++++++++++++-------
 src/sna/sna_video.c |   15 +++++++++++++--
 2 files changed, 31 insertions(+), 9 deletions(-)
src/intel_display.c +18 -7
index 6dfc8e6..6dd4556 100644
@@ -630,6 +630,16 @@ intel_crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
 	return rotate_pixmap;
 }
 
+static void remove_drm_fb(int scrnIndex, int drm_fd, int fb_id)
+{
+	int err;
+
+	err = drmModeRmFB(drm_fd, fb_id);
+	if (err)
+		xf86DrvMsg(scrnIndex, X_ERROR,
+			   "Couldn't remove DRM framebuffer (%d)\n", err);
+}
+
 static void
 intel_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 {
@@ -646,7 +656,8 @@ intel_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 	if (data) {
 		/* Be sure to sync acceleration before the memory gets
 		 * unbound. */
-		drmModeRmFB(mode->fd, intel_crtc->rotate_fb_id);
+		remove_drm_fb(scrn->scrnIndex, mode->fd,
+			      intel_crtc->rotate_fb_id);
 		intel_crtc->rotate_fb_id = 0;
 
 		dri_bo_unreference(intel_crtc->rotate_bo);
@@ -1464,7 +1475,7 @@ intel_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
 	intel_uxa_create_screen_resources(scrn->pScreen);
 
 	if (old_fb_id)
-		drmModeRmFB(mode->fd, old_fb_id);
+		remove_drm_fb(scrn->scrnIndex, mode->fd, old_fb_id);
 	if (old_front)
 		drm_intel_bo_unreference(old_front);
 
@@ -1478,7 +1489,7 @@ fail:
 	scrn->virtualY = old_height;
 	scrn->displayWidth = old_pitch;
 	if (old_fb_id != mode->fb_id)
-		drmModeRmFB(mode->fd, mode->fb_id);
+		remove_drm_fb(scrn->scrnIndex, mode->fd, mode->fb_id);
 	mode->fb_id = old_fb_id;
 
 	return FALSE;
@@ -1559,7 +1570,7 @@ intel_do_pageflip(intel_screen_private *intel,
 	return TRUE;
 
 error_undo:
-	drmModeRmFB(mode->fd, mode->fb_id);
+	remove_drm_fb(scrn->scrnIndex, mode->fd, mode->fb_id);
 	mode->fb_id = old_fb_id;
 
 error_out:
@@ -1601,7 +1612,7 @@ intel_page_flip_handler(int fd, unsigned int frame, unsigned int tv_sec,
 		return;
 
 	/* Release framebuffer */
-	drmModeRmFB(mode->fd, mode->old_fb_id);
+	remove_drm_fb(0, mode->fd, mode->old_fb_id);
 
 	if (mode->flip_info == NULL)
 		return;
@@ -1704,7 +1715,7 @@ intel_mode_remove_fb(intel_screen_private *intel)
 	struct intel_mode *mode = intel->modes;
 
 	if (mode->fb_id) {
-		drmModeRmFB(mode->fd, mode->fb_id);
+		remove_drm_fb(intel->scrn->scrnIndex, mode->fd, mode->fb_id);
 		mode->fb_id = 0;
 	}
 }
@@ -1727,7 +1738,7 @@ intel_mode_fini(intel_screen_private *intel)
 	}
 
 	if (mode->fb_id)
-		drmModeRmFB(mode->fd, mode->fb_id);
+		remove_drm_fb(intel->scrn->scrnIndex, mode->fd, mode->fb_id);
 
 	/* mode->rotate_fb_id should have been destroyed already */
 
src/sna/sna_video.c +13 -2
index b8690ec..8f3f662 100644
@@ -74,6 +74,16 @@ static inline bool sna_video_xvmc_setup(struct sna *sna,
 }
 #endif
 
+static void remove_drm_fb(int scrnIndex, int drm_fd, int fb_id)
+{
+	int err;
+
+	err = drmModeRmFB(drm_fd, fb_id);
+	if (err)
+		xf86DrvMsg(scrnIndex, X_ERROR,
+			   "Couldn't remove DRM framebuffer (%d)\n", err);
+}
+
 void sna_video_free_buffers(struct sna *sna, struct sna_video *video)
 {
 	unsigned int i;
@@ -81,7 +91,7 @@ void sna_video_free_buffers(struct sna *sna, struct sna_video *video)
 	for (i = 0; i < ARRAY_SIZE(video->old_buf); i++) {
 		if (video->old_buf[i]) {
 			if (video->old_buf[i]->unique_id)
-				drmModeRmFB(sna->kgem.fd,
+				remove_drm_fb(sna->scrn->scrnIndex, sna->kgem.fd,
 						video->old_buf[i]->unique_id);
 			kgem_bo_destroy(&sna->kgem, video->old_buf[i]);
 			video->old_buf[i] = NULL;
@@ -90,7 +100,8 @@ void sna_video_free_buffers(struct sna *sna, struct sna_video *video)
 
 	if (video->buf) {
 		if (video->buf->unique_id)
-			drmModeRmFB(sna->kgem.fd, video->buf->unique_id);
+			remove_drm_fb(sna->scrn->scrnIndex, sna->kgem.fd,
+				      video->buf->unique_id);
 		kgem_bo_destroy(&sna->kgem, video->buf);
 		video->buf = NULL;
 	}
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/2 dri: fix leakage of FB when closing the screen

Calling drmModeRmFB is only allowed in DRM master mode. Since leaving the VT also drops master mode we need to remove the FB before calling I830LeaveVT.

This is only a real leak in case of a server reset, otherwise the server process will exit anyway and the kernel will clean up the FB.

---
 src/intel_driver.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/intel_driver.c +4 -4
index c5be679..ca8e530 100644
@@ -1049,10 +1049,6 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 	I830UeventFini(scrn);
 #endif
 
-	if (scrn->vtSema == TRUE) {
-		I830LeaveVT(VT_FUNC_ARGS(0));
-	}
-
 	DeleteCallback(&FlushCallback, intel_flush_callback, scrn);
 
 	intel_glamor_close_screen(screen);
@@ -1082,6 +1078,10 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 		intel->front_buffer = NULL;
 	}
 
+	if (scrn->vtSema == TRUE) {
+		I830LeaveVT(VT_FUNC_ARGS(0));
+	}
+
 	intel_batch_teardown(scrn);
 
 	if (INTEL_INFO(intel)->gen >= 40)
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH xf86-video 2/2] dri: fix leakage of FB when closing the screen

Quoted 6 lines · Imre Deak

Calling drmModeRmFB is only allowed in DRM master mode. Since leaving the VT also drops master mode we need to remove the FB before calling I830LeaveVT.

This is only a real leak in case of a server reset, otherwise the server process will exit anyway and the kernel will clean up the FB.

Your reasoning is sound and the new location of leave_vt did not scare me...

Thanks, pushed. I'm not too concerned over simply warning about an unfixable leak along the anomalous path, though the debug spew in the kernel for this error is not as obvious as I'd like. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre