From: bugzilla-daemon@freedesktop.org Subject: [Bug 111588] Framebuffer corruption when a fb which is not being scanned out gets removed Date: Sun, 08 Sep 2019 12:37:39 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2087299110==" Return-path: Received: from culpepper.freedesktop.org (culpepper.freedesktop.org [IPv6:2610:10:20:722:a800:ff:fe98:4b55]) by gabe.freedesktop.org (Postfix) with ESMTP id 23F41898C4 for ; Sun, 8 Sep 2019 12:37:39 +0000 (UTC) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============2087299110== Content-Type: multipart/alternative; boundary="15679462580.F8DFE.7972" Content-Transfer-Encoding: 7bit --15679462580.F8DFE.7972 Date: Sun, 8 Sep 2019 12:37:38 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://bugs.freedesktop.org/ Auto-Submitted: auto-generated https://bugs.freedesktop.org/show_bug.cgi?id=3D111588 --- Comment #1 from Hans de Goede --- I just realized I left out one bit of info which might be useful, to debug = this I added the following change to the kernel: diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 57564318ceea..4712bfb9ae05 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -464,6 +464,7 @@ int drm_mode_rmfb(struct drm_device *dev, u32 fb_id, if (drm_framebuffer_read_refcount(fb) > 1) { struct drm_mode_rmfb_work arg; + pr_err("drm_modr_rmfb calling drm_framebuffer_remove\n"); INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn); INIT_LIST_HEAD(&arg.fbs); list_add_tail(&fb->filp_head, &arg.fbs); @@ -471,8 +472,10 @@ int drm_mode_rmfb(struct drm_device *dev, u32 fb_id, schedule_work(&arg.work); flush_work(&arg.work); destroy_work_on_stack(&arg.work); - } else + } else { + pr_err("drm_modr_rmfb calling drm_framebuffer_put\n"); drm_framebuffer_put(fb); + } return 0; @@ -669,11 +672,13 @@ void drm_fb_release(struct drm_file *priv) */ list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { if (drm_framebuffer_read_refcount(fb) > 1) { + pr_err("drm_fb_release calling drm_framebuffer_remove\n"); list_move_tail(&fb->filp_head, &arg.fbs); } else { list_del_init(&fb->filp_head); /* This drops the fpriv->fbs reference. */ + pr_err("drm_fb_release calling drm_framebuffer_put\= n"); drm_framebuffer_put(fb); } } @@ -863,6 +868,8 @@ static int atomic_remove_fb(struct drm_framebuffer *fb) if (plane->state->fb !=3D fb) continue; + pr_err("atomic_remove_fb found plane still using fb\n"); + plane_state =3D drm_atomic_get_plane_state(state, plane); if (IS_ERR(plane_state)) { ret =3D PTR_ERR(plane_state); In the working case, so where we let the kernel do the fb cleanup itself, I see: Plymouth removes fb it creates to test for 32bpp support: kernel: drm_modr_rmfb calling drm_framebuffer_put gdm starts, does page-flipping, resulting in a number of: kernel: drm_modr_rmfb calling drm_framebuffer_put kernel: drm_modr_rmfb calling drm_framebuffer_put ... lines And then plymouth exits without any cleanup, so we get: kernel: drm_fb_release calling drm_framebuffer_put Followed by more: kernel: drm_modr_rmfb calling drm_framebuffer_put kernel: drm_modr_rmfb calling drm_framebuffer_put ... >From gdm. In the broken case, where ply_renderer_buffer_free() gets called on plymouth-quit, I only see: kernel: drm_modr_rmfb calling drm_framebuffer_put kernel: drm_modr_rmfb calling drm_framebuffer_put ... lines, wihch is expected as the fb is rmfb-ed before the fd is closed. Note that we never hit: @@ -863,6 +868,8 @@ static int atomic_remove_fb(struct drm_framebuffer *fb) if (plane->state->fb !=3D fb) continue; + pr_err("atomic_remove_fb found plane still using fb\n"); + plane_state =3D drm_atomic_get_plane_state(state, plane); if (IS_ERR(plane_state)) { ret =3D PTR_ERR(plane_state); So AFAICT userspace is doing everything correctly even in the broken case. --=20 You are receiving this mail because: You are the assignee for the bug.= --15679462580.F8DFE.7972 Date: Sun, 8 Sep 2019 12:37:38 +0000 MIME-Version: 1.0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://bugs.freedesktop.org/ Auto-Submitted: auto-generated

Commen= t # 1 on bug 11158= 8 from Hans de Goede
I just realized I left out one bit of info which might be usef=
ul, to debug this
I added the following change to the kernel:

diff --git a/drivers/gpu/drm/drm_framebuffer.c
b/drivers/gpu/drm/drm_framebuffer.c
index 57564318ceea..4712bfb9ae05 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -464,6 +464,7 @@ int drm_mode_rmfb(struct drm_device *de=
v, u32 fb_id,
        if (drm_framebuffer_read_refcount(fb) > 1) {
                struct drm_mode_rmfb_work arg;

+               pr_err("drm_modr_rmfb calling drm_framebuffer_remove\n=
");
                INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
                INIT_LIST_HEAD(&arg.fbs);
                list_add_tail(&fb->filp_head, &arg.fbs);
@@ -471,8 +472,10 @@ int drm_mode_rmfb(struct drm_device *d=
ev, u32 fb_id,
                schedule_work(&arg.work);
                flush_work(&arg.work);
                destroy_work_on_stack(&arg.work);
-       } else
+       } else {
+               pr_err("drm_modr_rmfb calling drm_framebuffer_put\n&qu=
ot;);
                drm_framebuffer_put(fb);
+       }

        return 0;

@@ -669,11 +672,13 @@ void drm_fb_release(struct drm_file *=
priv)
         */
        list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
                if (drm_framebuffer_read_refcount(fb) > 1) {
+                       pr_err("drm_fb_release calling
drm_framebuffer_remove\n");
                        list_move_tail(&fb->filp_head, &arg.fbs);
                } else {
                        list_del_init(&fb->filp_head);

                        /* This drops the fpriv->fbs reference. */
+                       pr_err("drm_fb_release calling drm_framebuffer=
_put\n");
                        drm_framebuffer_put(fb);
                }
        }
@@ -863,6 +868,8 @@ static int atomic_remove_fb(struct drm_=
framebuffer *fb)
                if (plane->state->fb !=3D fb)
                        continue;

+               pr_err("atomic_remove_fb found plane still using fb\n&=
quot;);
+
                plane_state =3D drm_atomic_get_plane_state(state, plane);
                if (IS_ERR(plane_state)) {
                        ret =3D PTR_ERR(plane_state);


In the working case, so where we let the kernel do the fb cleanup itself, I
see:

Plymouth removes fb it creates to test for 32bpp support:
kernel: drm_modr_rmfb calling drm_framebuffer_put

gdm starts, does page-flipping, resulting in a number of:

kernel: drm_modr_rmfb calling drm_framebuffer_put
kernel: drm_modr_rmfb calling drm_framebuffer_put
...

lines

And then plymouth exits without any cleanup, so we get:
kernel: drm_fb_release calling drm_framebuffer_put

Followed by more:

kernel: drm_modr_rmfb calling drm_framebuffer_put
kernel: drm_modr_rmfb calling drm_framebuffer_put
...

>From gdm.

In the broken case, where ply_renderer_buffer_free() gets called on
plymouth-quit, I only see:

kernel: drm_modr_rmfb calling drm_framebuffer_put
kernel: drm_modr_rmfb calling drm_framebuffer_put
...

lines, wihch is expected as the fb is rmfb-ed before the fd is closed.

Note that we never hit:

@@ -863,6 +868,8 @@ static int atomic_remove_fb(struct drm_=
framebuffer *fb)
                if (plane->state->fb !=3D fb)
                        continue;

+               pr_err("atomic_remove_fb found plane still using fb\n&=
quot;);
+
                plane_state =3D drm_atomic_get_plane_state(state, plane);
                if (IS_ERR(plane_state)) {
                        ret =3D PTR_ERR(plane_state);


So AFAICT userspace is doing everything correctly even in the broken case.<=
/pre>
        


You are receiving this mail because:
  • You are the assignee for the bug.
= --15679462580.F8DFE.7972-- --===============2087299110== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVs --===============2087299110==--