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/dist/drm drm: Fix locking around accur...



details:   https://anonhg.NetBSD.org/src/rev/a07d82d4bb3a
branches:  trunk
changeset: 1029196:a07d82d4bb3a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 26 21:00:14 2021 +0000

description:
drm: Fix locking around accurate vblank counts.

- Make drm_crtc_accurate_vblank_count require the caller to hold the
  event lock, rather than take it internally.

- Fix locking around drm_crtc_accurate_vblank_count and related
  operations in amdgpu and nouveau interrupt handlers.

- Use drm_crtc_vblank_put_locked, not drm_crtc_vblank_put, when we
  already hold the event lock.

PR kern/56557

diffstat:

 sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm.c        |   6 +-
 sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c    |   6 ++-
 sys/external/bsd/drm2/dist/drm/drm_vblank.c                             |  19 ++-------
 sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_disp.c |   6 +-
 4 files changed, 14 insertions(+), 23 deletions(-)

diffs (138 lines):

diff -r 31724aed2cad -r a07d82d4bb3a sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm.c
--- a/sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm.c  Sun Dec 26 18:16:41 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm.c  Sun Dec 26 21:00:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpu_dm.c,v 1.4 2021/12/19 12:31:45 riastradh Exp $  */
+/*     $NetBSD: amdgpu_dm.c,v 1.5 2021/12/26 21:00:14 riastradh Exp $  */
 
 /*
  * Copyright 2015 Advanced Micro Devices, Inc.
@@ -27,7 +27,7 @@
 
 /* The caprices of the preprocessor require that this be declared right here */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_dm.c,v 1.4 2021/12/19 12:31:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_dm.c,v 1.5 2021/12/26 21:00:14 riastradh Exp $");
 
 #define CREATE_TRACE_POINTS
 
@@ -361,7 +361,7 @@
                        drm_crtc_send_vblank_event(&amdgpu_crtc->base, e);
 
                        /* Event sent, so done with vblank for this flip */
-                       drm_crtc_vblank_put(&amdgpu_crtc->base);
+                       drm_crtc_vblank_put_locked(&amdgpu_crtc->base);
                }
        } else if (e) {
                /* VRR active and inside front-porch: vblank count and
diff -r 31724aed2cad -r a07d82d4bb3a sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c
--- a/sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c      Sun Dec 26 18:16:41 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c      Sun Dec 26 21:00:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amdgpu_dm_crc.c,v 1.2 2021/12/18 23:45:00 riastradh Exp $      */
+/*     $NetBSD: amdgpu_dm_crc.c,v 1.3 2021/12/26 21:00:14 riastradh Exp $      */
 
 /*
  * Copyright 2015 Advanced Micro Devices, Inc.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_dm_crc.c,v 1.2 2021/12/18 23:45:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_dm_crc.c,v 1.3 2021/12/26 21:00:14 riastradh Exp $");
 
 #include <drm/drm_crtc.h>
 #include <drm/drm_vblank.h>
@@ -319,7 +319,9 @@
                                       &crcs[0], &crcs[1], &crcs[2]))
                        return;
 
+               spin_lock(&crtc->dev->event_lock);
                drm_crtc_add_crc_entry(crtc, true,
                                       drm_crtc_accurate_vblank_count(crtc), crcs);
+               spin_unlock(&crtc->dev->event_lock);
        }
 }
diff -r 31724aed2cad -r a07d82d4bb3a sys/external/bsd/drm2/dist/drm/drm_vblank.c
--- a/sys/external/bsd/drm2/dist/drm/drm_vblank.c       Sun Dec 26 18:16:41 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_vblank.c       Sun Dec 26 21:00:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_vblank.c,v 1.15 2021/12/19 12:36:31 riastradh Exp $        */
+/*     $NetBSD: drm_vblank.c,v 1.16 2021/12/26 21:00:14 riastradh Exp $        */
 
 /*
  * drm_irq.c IRQ and vblank support
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_vblank.c,v 1.15 2021/12/19 12:36:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_vblank.c,v 1.16 2021/12/26 21:00:14 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/moduleparam.h>
@@ -337,7 +337,7 @@
  * This is mostly useful for hardware that can obtain the scanout position, but
  * doesn't have a hardware frame counter.
  */
-static u64 drm_crtc_accurate_vblank_count_locked(struct drm_crtc *crtc)
+u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
        unsigned int pipe = drm_crtc_index(crtc);
@@ -358,17 +358,6 @@
 
        return vblank;
 }
-
-u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
-{
-       u64 vblank;
-
-       spin_lock(&crtc->dev->event_lock);
-       vblank = drm_crtc_accurate_vblank_count_locked(crtc);
-       spin_unlock(&crtc->dev->event_lock);
-
-       return vblank;
-}
 EXPORT_SYMBOL(drm_crtc_accurate_vblank_count);
 
 static void __disable_vblank(struct drm_device *dev, unsigned int pipe)
@@ -972,7 +961,7 @@
        assert_spin_locked(&dev->event_lock);
 
        e->pipe = pipe;
-       e->sequence = drm_crtc_accurate_vblank_count_locked(crtc) + 1;
+       e->sequence = drm_crtc_accurate_vblank_count(crtc) + 1;
        list_add_tail(&e->base.link, &dev->vblank_event_list);
 }
 EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
diff -r 31724aed2cad -r a07d82d4bb3a sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_disp.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_disp.c   Sun Dec 26 18:16:41 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_disp.c   Sun Dec 26 21:00:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_dispnv50_disp.c,v 1.6 2021/12/19 11:34:44 riastradh Exp $      */
+/*     $NetBSD: nouveau_dispnv50_disp.c,v 1.7 2021/12/26 21:00:14 riastradh Exp $      */
 
 /*
  * Copyright 2011 Red Hat Inc.
@@ -24,7 +24,7 @@
  * Authors: Ben Skeggs
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_dispnv50_disp.c,v 1.6 2021/12/19 11:34:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_dispnv50_disp.c,v 1.7 2021/12/26 21:00:14 riastradh Exp $");
 
 #include "disp.h"
 #include "atom.h"
@@ -2136,9 +2136,9 @@
                if (new_crtc_state->event) {
                        unsigned long flags;
                        /* Get correct count/ts if racing with vblank irq */
+                       spin_lock_irqsave(&crtc->dev->event_lock, flags);
                        if (new_crtc_state->active)
                                drm_crtc_accurate_vblank_count(crtc);
-                       spin_lock_irqsave(&crtc->dev->event_lock, flags);
                        drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
                        spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
 



Home | Main Index | Thread Index | Old Index