Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2 drm: Fix asynchronous attach logic for...



details:   https://anonhg.NetBSD.org/src/rev/26c0f69a1196
branches:  trunk
changeset: 368553:26c0f69a1196
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jul 18 23:33:53 2022 +0000

description:
drm: Fix asynchronous attach logic for drm framebuffer devices.

The driver-specific sc_scheduled boolean flag was racy.  It is
necessary to use config_pending_incr/decr to hold up console
selection and userland start (and block detach, not that that works
yet) until the drmfb attach has completed.

diffstat:

 sys/external/bsd/drm2/amdgpu/amdgpufb.c       |  22 +++++++---------------
 sys/external/bsd/drm2/i915drm/intelfb.c       |  13 ++-----------
 sys/external/bsd/drm2/nouveau/nouveaufb.c     |  22 +++++++---------------
 sys/external/bsd/drm2/radeon/radeondrmkmsfb.c |  25 +++++++------------------
 sys/external/bsd/drm2/vmwgfx/vmwgfxfb.c       |  24 +++++++-----------------
 5 files changed, 30 insertions(+), 76 deletions(-)

diffs (truncated from 385 to 300 lines):

diff -r 332bf95b6740 -r 26c0f69a1196 sys/external/bsd/drm2/amdgpu/amdgpufb.c
--- a/sys/external/bsd/drm2/amdgpu/amdgpufb.c   Mon Jul 18 13:01:59 2022 +0000
+++ b/sys/external/bsd/drm2/amdgpu/amdgpufb.c   Mon Jul 18 23:33:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpufb.c,v 1.3 2021/12/19 12:21:29 riastradh Exp $   */
+/*     $NetBSD: amdgpufb.c,v 1.4 2022/07/18 23:33:53 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpufb.c,v 1.3 2021/12/19 12:21:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpufb.c,v 1.4 2022/07/18 23:33:53 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/bus.h>
@@ -58,7 +58,6 @@
        device_t                        sc_dev;
        struct amdgpufb_attach_args     sc_afa;
        struct amdgpu_task              sc_attach_task;
-       bool                            sc_scheduled:1;
        bool                            sc_attached:1;
 };
 
@@ -88,7 +87,6 @@
 
        sc->sc_dev = self;
        sc->sc_afa = *afa;
-       sc->sc_scheduled = false;
        sc->sc_attached = false;
 
        aprint_naive("\n");
@@ -99,14 +97,9 @@
        if (error) {
                aprint_error_dev(self, "failed to schedule mode set: %d\n",
                    error);
-               goto fail0;
+               return;
        }
-       sc->sc_scheduled = true;
-
-       /* Success!  */
-       return;
-
-fail0: return;
+       config_pending_incr(self);
 }
 
 static int
@@ -115,9 +108,6 @@
        struct amdgpufb_softc *const sc = device_private(self);
        int error;
 
-       if (sc->sc_scheduled)
-               return EBUSY;
-
        if (sc->sc_attached) {
                pmf_device_deregister(self);
                error = drmfb_detach(&sc->sc_drmfb, flags);
@@ -153,7 +143,7 @@
        if (error) {
                aprint_error_dev(sc->sc_dev, "failed to attach drmfb: %d\n",
                    error);
-               return;
+               goto out;
        }
 
        if (!pmf_device_register1(sc->sc_dev, NULL, NULL, &amdgpufb_shutdown))
@@ -161,6 +151,8 @@
                    "failed to register shutdown handler\n");
 
        sc->sc_attached = true;
+out:
+       config_pending_decr(sc->sc_dev);
 }
 
 static bool
diff -r 332bf95b6740 -r 26c0f69a1196 sys/external/bsd/drm2/i915drm/intelfb.c
--- a/sys/external/bsd/drm2/i915drm/intelfb.c   Mon Jul 18 13:01:59 2022 +0000
+++ b/sys/external/bsd/drm2/i915drm/intelfb.c   Mon Jul 18 23:33:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intelfb.c,v 1.22 2021/12/19 11:49:12 riastradh Exp $   */
+/*     $NetBSD: intelfb.c,v 1.23 2022/07/18 23:33:53 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intelfb.c,v 1.22 2021/12/19 11:49:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intelfb.c,v 1.23 2022/07/18 23:33:53 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/bus.h>
@@ -64,7 +64,6 @@
        struct intelfb_attach_args      sc_ifa;
        bus_space_handle_t              sc_fb_bsh;
        struct i915drmkms_task          sc_attach_task;
-       bool                            sc_scheduled:1;
        bool                            sc_attached:1;
 };
 
@@ -95,7 +94,6 @@
 
        sc->sc_dev = self;
        sc->sc_ifa = *ifa;
-       sc->sc_scheduled = false;
        sc->sc_attached = false;
 
        aprint_naive("\n");
@@ -109,10 +107,6 @@
                return;
        }
        config_pending_incr(self);
-       sc->sc_scheduled = true;
-
-       /* Success!  */
-       return;
 }
 
 static int
@@ -121,9 +115,6 @@
        struct intelfb_softc *const sc = device_private(self);
        int error;
 
-       if (sc->sc_scheduled)
-               return EBUSY;
-
        if (sc->sc_attached) {
                pmf_device_deregister(self);
                error = drmfb_detach(&sc->sc_drmfb, flags);
diff -r 332bf95b6740 -r 26c0f69a1196 sys/external/bsd/drm2/nouveau/nouveaufb.c
--- a/sys/external/bsd/drm2/nouveau/nouveaufb.c Mon Jul 18 13:01:59 2022 +0000
+++ b/sys/external/bsd/drm2/nouveau/nouveaufb.c Mon Jul 18 23:33:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveaufb.c,v 1.7 2021/12/19 10:51:59 riastradh Exp $  */
+/*     $NetBSD: nouveaufb.c,v 1.8 2022/07/18 23:33:53 riastradh Exp $  */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveaufb.c,v 1.7 2021/12/19 10:51:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveaufb.c,v 1.8 2022/07/18 23:33:53 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/bus.h>
@@ -63,7 +63,6 @@
        device_t                        sc_dev;
        struct nouveaufb_attach_args    sc_nfa;
        struct nouveau_pci_task         sc_attach_task;
-       bool                            sc_scheduled:1;
        bool                            sc_attached:1;
 };
 
@@ -93,7 +92,6 @@
 
        sc->sc_dev = self;
        sc->sc_nfa = *nfa;
-       sc->sc_scheduled = false;
        sc->sc_attached = false;
 
        aprint_naive("\n");
@@ -104,14 +102,9 @@
        if (error) {
                aprint_error_dev(self, "failed to schedule mode set: %d\n",
                    error);
-               goto fail0;
+               return;
        }
-       sc->sc_scheduled = true;
-
-       /* Success!  */
-       return;
-
-fail0: return;
+       config_pending_incr(self);
 }
 
 static int
@@ -120,9 +113,6 @@
        struct nouveaufb_softc *const sc = device_private(self);
        int error;
 
-       if (sc->sc_scheduled)
-               return EBUSY;
-
        if (sc->sc_attached) {
                pmf_device_deregister(self);
                error = drmfb_detach(&sc->sc_drmfb, flags);
@@ -158,7 +148,7 @@
        if (error) {
                aprint_error_dev(sc->sc_dev, "failed to attach drmfb: %d\n",
                    error);
-               return;
+               goto out;
        }
 
        if (!pmf_device_register1(sc->sc_dev, NULL, NULL, &nouveaufb_shutdown))
@@ -166,6 +156,8 @@
                    "failed to register shutdown handler\n");
 
        sc->sc_attached = true;
+out:
+       config_pending_decr(sc->sc_dev);
 }
 
 static bool
diff -r 332bf95b6740 -r 26c0f69a1196 sys/external/bsd/drm2/radeon/radeondrmkmsfb.c
--- a/sys/external/bsd/drm2/radeon/radeondrmkmsfb.c     Mon Jul 18 13:01:59 2022 +0000
+++ b/sys/external/bsd/drm2/radeon/radeondrmkmsfb.c     Mon Jul 18 23:33:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: radeondrmkmsfb.c,v 1.15 2021/12/19 10:33:00 riastradh Exp $    */
+/*     $NetBSD: radeondrmkmsfb.c,v 1.16 2022/07/18 23:33:53 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: radeondrmkmsfb.c,v 1.15 2021/12/19 10:33:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeondrmkmsfb.c,v 1.16 2022/07/18 23:33:53 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -50,7 +50,6 @@
        device_t                        sc_dev;
        struct radeonfb_attach_args     sc_rfa;
        struct radeon_task              sc_attach_task;
-       bool                            sc_scheduled:1;
        bool                            sc_attached:1;
 };
 
@@ -89,7 +88,6 @@
 
        sc->sc_dev = self;
        sc->sc_rfa = *rfa;
-       sc->sc_scheduled = false;
        sc->sc_attached = false;
 
        aprint_naive("\n");
@@ -100,14 +98,9 @@
        if (error) {
                aprint_error_dev(self, "failed to schedule mode set: %d\n",
                    error);
-               goto fail0;
+               return;
        }
-       sc->sc_scheduled = true;
-
-       /* Success!  */
-       return;
-
-fail0: return;
+       config_pending_incr(self);
 }
 
 static int
@@ -116,9 +109,6 @@
        struct radeonfb_softc *const sc = device_private(self);
        int error;
 
-       if (sc->sc_scheduled)
-               return EBUSY;
-
        if (sc->sc_attached) {
                pmf_device_deregister(self);
                error = drmfb_detach(&sc->sc_drmfb, flags);
@@ -150,20 +140,19 @@
        };
        int error;
 
-       KASSERT(sc->sc_scheduled);
-
-
        error = drmfb_attach(&sc->sc_drmfb, &da);
        if (error) {
                aprint_error_dev(sc->sc_dev, "failed to attach drmfb: %d\n",
                    error);
-               return;
+               goto out;
        }
        if (!pmf_device_register1(sc->sc_dev, NULL, NULL, &radeonfb_shutdown))
                aprint_error_dev(sc->sc_dev,
                    "failed to register shutdown handler\n");
 
        sc->sc_attached = true;
+out:
+       config_pending_decr(sc->sc_dev);
 }
 
 static bool
diff -r 332bf95b6740 -r 26c0f69a1196 sys/external/bsd/drm2/vmwgfx/vmwgfxfb.c
--- a/sys/external/bsd/drm2/vmwgfx/vmwgfxfb.c   Mon Jul 18 13:01:59 2022 +0000



Home | Main Index | Thread Index | Old Index