Increase reference count of FB assigned to drmmode_crtc->flip_pending
PATCH 1/2 Increase reference count of FB assigned to drmmode_crtc->flip_pending
From: Michel Dänzer <[email protected]>
Otherwise, it could happen that we destroy the FB before the flip completes, resulting in use-after-free and most likely a crash.
(Ported from amdgpu commit af7221e1c4d2dbdfd488eb0976a835584ea8441c)
--- src/drmmode_display.c | 8 ++++++-- src/radeon_kms.c | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
src/drmmode_display.c +6 -2
@@ -2369,8 +2369,11 @@ void drmmode_clear_pending_flip(xf86CrtcPtr crtc) {drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; +ScrnInfoPtr scrn = crtc->scrn; +RADEONEntPtr pRADEONEnt =RADEONEntPriv (scrn); - drmmode_crtc->flip_pending =NULL ; +drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->flip_pending, +NULL ); if (!crtc->enabled || (drmmode_crtc->pending_dpms_mode != DPMSModeOn &&
@@ -3030,7 +3033,8 @@ Bool radeon_do_pageflip(ScrnInfoPtr scrn, ClientPtr client, goto flip_error; } - drmmode_crtc->flip_pending = fb; +drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->flip_pending, + fb); drm_queue_seq =0 ; }
src/radeon_kms.c +4 -4
@@ -815,8 +815,8 @@ radeon_prime_scanout_flip(PixmapDirtyUpdatePtr ent)return ; } - drmmode_crtc->flip_pending = -radeon_pixmap_get_fb (drmmode_crtc->scanout[scanout_id].pixmap); +drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->flip_pending, +radeon_pixmap_get_fb (drmmode_crtc->scanout[scanout_id].pixmap));if (!drmmode_crtc->flip_pending) {xf86DrvMsg (scrn->scrnIndex,X_WARNING ,"Failed to get FB for PRIME flip.\n" );
@@ -1110,8 +1110,8 @@ radeon_scanout_flip(ScreenPtr pScreen, RADEONInfoPtr info,return ; } - drmmode_crtc->flip_pending = -radeon_pixmap_get_fb (drmmode_crtc->scanout[scanout_id].pixmap); +drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->flip_pending, +radeon_pixmap_get_fb (drmmode_crtc->scanout[scanout_id].pixmap));if (!drmmode_crtc->flip_pending) {xf86DrvMsg (scrn->scrnIndex,X_WARNING ,"Failed to get FB for scanout flip.\n" );
Signature · 6 lines
2.13.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20170627093850.26318-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org
PATCH 2/2 Improve drmmode_fb_reference debugging code
From: Michel Dänzer <[email protected]>
If a reference count is <= 0, call FatalError with the call location (in case it doesn't get resolved in the backtrace printed by FatalError).
(Ported from amdgpu commit 1b6ff5fd9933c00ec1ec90dfc62e0b531927749b)
--- src/drmmode_display.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
src/drmmode_display.h +18 -11
@@ -141,29 +141,36 @@ enum drmmode_flip_sync {static inline void -drmmode_fb_reference (int drm_fd,struct drmmode_fb **old,struct drmmode_fb *new) +drmmode_fb_reference_loc (int drm_fd,struct drmmode_fb **old,struct drmmode_fb *new, +const char *caller,unsigned line) {if (new) { -if (new->refcnt <=0 ) -ErrorF ("New FB's refcnt was %d in %s\n" , new->refcnt, __func__); -else - new->refcnt++; +if (new->refcnt <=0 ) { +FatalError ("New FB's refcnt was %d at %s:%u" , + new->refcnt, caller, line); + } + + new->refcnt++; }if (*old) {if ((*old)->refcnt <=0 ) { -ErrorF ("Old FB's refcnt was %d in %s\n" , (*old)->refcnt, __func__); - }else { -if (--(*old)->refcnt ==0 ) { -drmModeRmFB (drm_fd, (*old)->handle); -free (*old); - } +FatalError ("Old FB's refcnt was %d at %s:%u" , + (*old)->refcnt, caller, line); + } + +if (--(*old)->refcnt ==0 ) { +drmModeRmFB (drm_fd, (*old)->handle); +free (*old); } } *old = new; } +#define drmmode_fb_reference (fd, old, new) \ + drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) + extern int drmmode_page_flip_target_absolute(RADEONEntPtr pRADEONEnt, drmmode_crtc_private_ptr drmmode_crtc,
Signature · 6 lines
2.13.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20170627093850.26318-2-michel-otUistvHUpPR7s880joybQ@public.gmane.org
Alex Deucher
Reviewed-byRe: [PATCH xf86-video-ati 2/2] Improve drmmode_fb_reference debugging code
Quoted 9 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
If a reference count is <= 0, call FatalError with the call location (in case it doesn't get resolved in the backtrace printed by FatalError).
(Ported from amdgpu commit
1b6ff5fd9933c00ec1ec90dfc62e0b531927749b)Signed-off-by Michel Dänzer <[email protected]>
Series is:
Quoted 59 lines
--- src/drmmode_display.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)src/drmmode_display.h +18
-12@@ -141,29 +141,36 @@ enum drmmode_flip_sync {static inline void -drmmode_fb_reference (int drm_fd,struct drmmode_fb **old,struct drmmode_fb *new) +drmmode_fb_reference_loc (int drm_fd,struct drmmode_fb **old,struct drmmode_fb *new, +const char *caller,unsigned line) {if (new) { -if (new->refcnt <=0 ) -ErrorF ("New FB's refcnt was %d in %s\n" , new->refcnt, __func__); -else - new->refcnt++; +if (new->refcnt <=0 ) { +FatalError ("New FB's refcnt was %d at %s:%u" , + new->refcnt, caller, line); + } + + new->refcnt++; }if (*old) {if ((*old)->refcnt <=0 ) { -ErrorF ("Old FB's refcnt was %d in %s\n" , (*old)->refcnt, __func__); - }else { -if (--(*old)->refcnt ==0 ) { -drmModeRmFB (drm_fd, (*old)->handle); -free (*old); - } +FatalError ("Old FB's refcnt was %d at %s:%u" , + (*old)->refcnt, caller, line); + } + +if (--(*old)->refcnt ==0 ) { +drmModeRmFB (drm_fd, (*old)->handle); +free (*old); } } *old = new; } +#define drmmode_fb_reference (fd, old, new) \ + drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) + extern int drmmode_page_flip_target_absolute(RADEONEntPtr pRADEONEnt, drmmode_crtc_private_ptr drmmode_crtc, --2.13.1
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx