Skip to contentSkip to conversation

drm/atomic: Reject events for inactive crtc's.

PATCH Maarten Lankhorst 3 participants 7 messages Jul 30, 2015 – Aug 31, 2015

Subsystems (2)
lore
Share & tools
lore

Maarten Lankhorst

author maintainer
#0 lore raw

This will cause drm_atomic_helper_page_flip and drm_mode_atomic_ioctl to fail with -EINVAL if a event is requested on a inactive crtc.

---

drivers/gpu/drm/drm_atomic.c +6 -0
index d719ce0b10a0..679577e8e02d 100644
@@ -476,6 +476,12 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
 		return -EINVAL;
 	}
 
+	if (!state->active && state->event) {
+		DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+				 crtc->base.id);
+		return -EINVAL;
+	}
+
 	/* The state->enable vs. state->mode_blob checks can be WARN_ON,
 	 * as this is a kernel-internal detail that userspace should never
 	 * be able to trigger. */

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

Hi,

Quoted 10 lines · Maarten Lankhorst

This will cause drm_atomic_helper_page_flip and drm_mode_atomic_ioctl to fail with -EINVAL if a event is requested on a inactive crtc.

---

drivers/gpu/drm/drm_atomic.c +0 -0
index d719ce0b10a0..679577e8e02d 100644

drivers/gpu/drm/drm_atomic.c static int drm_atomic_crtc_check(struct drm_crtc *crtc, · line 483

Quoted 8 lines
drivers/gpu/drm/drm_atomic.c +5 -0
@@ -476,6 +476,12 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
                return -EINVAL;
        }
 
+       if (!state->active && state->event) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+                                crtc->base.id);
+               return -EINVAL;
+       }

Hmm, even if disabling? Maybe (!crtc->state->active && !state->active) && state->event.

Cheers,
Daniel
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

author maintainer
#2 lore raw

Hey,

Op 06-08-15 om 11:47 schreef Daniel Stone:

Quoted 17 lines

Hi,

Quoted 13 lines · Maarten Lankhorst

This will cause drm_atomic_helper_page_flip and drm_mode_atomic_ioctl to fail with -EINVAL if a event is requested on a inactive crtc.

---

drivers/gpu/drm/drm_atomic.c +0 -0
index d719ce0b10a0..679577e8e02d 100644
@@ -476,6 +476,12 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
                return -EINVAL;
        }
 
Quoted 7 lines

drivers/gpu/drm/drm_atomic.c static int drm_atomic_crtc_check(struct drm_crtc *crtc, · line 483

Quoted 5 lines
drivers/gpu/drm/drm_atomic.c +5 -0
+       if (!state->active && state->event) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+                                crtc->base.id);
+               return -EINVAL;
+       }

Hmm, even if disabling? Maybe (!crtc->state->active && !state->active) && state->event.

How do you want to send a vblank event after disabling?

I think the only thing that makes sense would be not creating events when crtc_state->enable = false, so when a crtc is removed and an event is requested you won't return -EINVAL.

~Maarten
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
Quoted 20 lines · Maarten Lankhorst

Hey,

Op 06-08-15 om 11:47 schreef Daniel Stone:

Quoted 17 lines

Hi,

Quoted 13 lines · Maarten Lankhorst

This will cause drm_atomic_helper_page_flip and drm_mode_atomic_ioctl to fail with -EINVAL if a event is requested on a inactive crtc.

---

drivers/gpu/drm/drm_atomic.c +0 -0
index d719ce0b10a0..679577e8e02d 100644
@@ -476,6 +476,12 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
                return -EINVAL;
        }
 
Quoted 8 lines
Quoted 7 lines

drivers/gpu/drm/drm_atomic.c static int drm_atomic_crtc_check(struct drm_crtc *crtc, · line 483

Quoted 5 lines
drivers/gpu/drm/drm_atomic.c +5 -0
+       if (!state->active && state->event) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+                                crtc->base.id);
+               return -EINVAL;
+       }

Hmm, even if disabling? Maybe (!crtc->state->active && !state->active) && state->event.

How do you want to send a vblank event after disabling?

The event would be when we stop scanning out, but yeah that's a bit a tricky one. I guess for now (until we have someone who needs this) we could just merge Maarten's patch as the easier thing to do right now? Maybe with a small code comment that this is intentional?

Atomic is a ridiculously complex interface, restricting it to just the features we actually need is imo the right approach. -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Hi,

Quoted 9 lines · Daniel Vetter
Quoted 8 lines · Maarten Lankhorst

Op 06-08-15 om 11:47 schreef Daniel Stone:

Quoted 7 lines
Quoted 5 lines · Maarten Lankhorst
drivers/gpu/drm/drm_atomic.c +5 -0
+       if (!state->active && state->event) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+                                crtc->base.id);
+               return -EINVAL;
+       }
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Hmm, even if disabling? Maybe (!crtc->state->active && !state->active) && state->event.

How do you want to send a vblank event after disabling?

The event would be when we stop scanning out, but yeah that's a bit a tricky one. I guess for now (until we have someone who needs this) we could just merge Maarten's patch as the easier thing to do right now? Maybe with a small code comment that this is intentional?

Exactly that. Surely this (when the CRTC actually goes dark) is something we already know? Assuming you don't have atomic_disable / instant-scanout-stop, and have to wait until the next vblank to kill it, then how does this work?
- create FB
- assign FB to plane on CRTC
- unreference FB such that plane holds the last remaining reference
- set plane->fb == NULL + crtc->active = 0, i.e. SetCrtc(NULL, 0, 0,
0, 0, ...)

You can't immediately unpin/destroy the FB since you might still be mid-scanout. So you already need to defer this, and that would be the point at which you stop scanout. In a lot of hardware, this is just another latched register which takes effect on the next vblank, for which you still catch an IRQ - at which point you send the event. If you actually have atomic_disable hardware that stops scanout immediately, you can just send the event immediately.

What am I missing?

Cheers,
Daniel
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw
Quoted 39 lines · Daniel Stone

Hi,

Quoted 9 lines · Daniel Vetter
Quoted 8 lines · Maarten Lankhorst

Op 06-08-15 om 11:47 schreef Daniel Stone:

Quoted 7 lines
Quoted 5 lines · Maarten Lankhorst
drivers/gpu/drm/drm_atomic.c +5 -0
+       if (!state->active && state->event) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+                                crtc->base.id);
+               return -EINVAL;
+       }
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Hmm, even if disabling? Maybe (!crtc->state->active && !state->active) && state->event.

How do you want to send a vblank event after disabling?

The event would be when we stop scanning out, but yeah that's a bit a tricky one. I guess for now (until we have someone who needs this) we could just merge Maarten's patch as the easier thing to do right now? Maybe with a small code comment that this is intentional?

Exactly that. Surely this (when the CRTC actually goes dark) is something we already know? Assuming you don't have atomic_disable / instant-scanout-stop, and have to wait until the next vblank to kill it, then how does this work?
- create FB
- assign FB to plane on CRTC
- unreference FB such that plane holds the last remaining reference
- set plane->fb == NULL + crtc->active = 0, i.e. SetCrtc(NULL, 0, 0,
0, 0, ...)

You can't immediately unpin/destroy the FB since you might still be mid-scanout. So you already need to defer this, and that would be the point at which you stop scanout. In a lot of hardware, this is just another latched register which takes effect on the next vblank, for which you still catch an IRQ - at which point you send the event. If you actually have atomic_disable hardware that stops scanout immediately, you can just send the event immediately.

Quoted 1 line

What am I missing?

The userspace which actually wants this and the testcases which makes sure it works. Until we have that I'd really prefer to just close that undefined behaviour gap in the atomic api, similar to how we just merged a patch to disallow switching live planes.

We can always extend this later on easily, there's lots of little features like this that people suggested for atomic.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#6 lore raw

Op 27-08-15 om 17:22 schreef Daniel Vetter:

Quoted 39 lines · Daniel Stone
Quoted 37 lines

Hi,

Quoted 9 lines · Daniel Vetter
Quoted 8 lines · Maarten Lankhorst

Op 06-08-15 om 11:47 schreef Daniel Stone:

Quoted 7 lines
Quoted 5 lines · Maarten Lankhorst
drivers/gpu/drm/drm_atomic.c +5 -0
+       if (!state->active && state->event) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event and not active\n",
+                                crtc->base.id);
+               return -EINVAL;
+       }
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Hmm, even if disabling? Maybe (!crtc->state->active && !state->active) && state->event.

How do you want to send a vblank event after disabling?

The event would be when we stop scanning out, but yeah that's a bit a tricky one. I guess for now (until we have someone who needs this) we could just merge Maarten's patch as the easier thing to do right now? Maybe with a small code comment that this is intentional?

Exactly that. Surely this (when the CRTC actually goes dark) is something we already know? Assuming you don't have atomic_disable / instant-scanout-stop, and have to wait until the next vblank to kill it, then how does this work?
- create FB
- assign FB to plane on CRTC
- unreference FB such that plane holds the last remaining reference
- set plane->fb == NULL + crtc->active = 0, i.e. SetCrtc(NULL, 0, 0,
0, 0, ...)

You can't immediately unpin/destroy the FB since you might still be mid-scanout. So you already need to defer this, and that would be the point at which you stop scanout. In a lot of hardware, this is just another latched register which takes effect on the next vblank, for which you still catch an IRQ - at which point you send the event. If you actually have atomic_disable hardware that stops scanout immediately, you can just send the event immediately.

Quoted 1 line

What am I missing?

Quoted 8 lines

The userspace which actually wants this and the testcases which makes sure it works. Until we have that I'd really prefer to just close that undefined behaviour gap in the atomic api, similar to how we just merged a patch to disallow switching live planes.

We can always extend this later on easily, there's lots of little features like this that people suggested for atomic.
-Daniel

Or in this case it's really solved in the kernel. Old fb's don't get unpinned until the update, so why should userspace care about any of it, assuming kernel refcount is correct?

~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel