Skip to contentSkip to conversation

drm: don't override possible_crtcs for primary/cursor planes

PATCH In review Rob Clark 3 participants 4 messages Oct 20, 2016

Subsystems (2)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm: don't override possible_crtcs for primary/cursor planes

It is kind of a pointless restriction. If userspace does silly things like using crtcA's cursor plane on crtcB, and then setcursor on crtcA, it will end up with the overlay disabled on crtcB. But userspace is allowed to shoot itself like this.

---
Note that cursor and primary planes are slightly useless to non-atomic userspace, since userspace has no way to know *which* crtc a primary or cursor plane belongs to. So lighting up a 2nd display may or may not make your overlay planes go *poof*.

So basically use of cursor/primary planes plus legacy ioctls is an undefined behavior if we go with this patch.

*Maybe* we want to restrict this to atomic userspace. (Ie. advertise the more limited possible_crtcs for legacy userspace.) Depends on whether we can (slightly retroactively) declare that mixing atomic and legacy APIs is undefined behavior. Or if really needed, add DRM_CLIENT_CAP_REALLY_REALLY_ATOMIC_NO_LEGACY_PLS. (Or just pass in value 2 for existing DRM_CLIENT_CAP_ATOMIC)

 drivers/gpu/drm/drm_crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -2
index c215802..1e6d37f 100644
@@ -707,9 +707,9 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
 	crtc->primary = primary;
 	crtc->cursor = cursor;
 	if (primary)
-		primary->possible_crtcs = 1 << drm_crtc_index(crtc);
+		WARN_ON(!(primary->possible_crtcs & (1 << drm_crtc_index(crtc))));
 	if (cursor)
-		cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
+		WARN_ON(!(cursor->possible_crtcs & (1 << drm_crtc_index(crtc))));
 
 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 		drm_object_attach_property(&crtc->base, config->prop_active, 0);
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 30 lines · Rob Clark

It is kind of a pointless restriction. If userspace does silly things like using crtcA's cursor plane on crtcB, and then setcursor on crtcA, it will end up with the overlay disabled on crtcB. But userspace is allowed to shoot itself like this.

---
Note that cursor and primary planes are slightly useless to non-atomic userspace, since userspace has no way to know *which* crtc a primary or cursor plane belongs to. So lighting up a 2nd display may or may not make your overlay planes go *poof*.

So basically use of cursor/primary planes plus legacy ioctls is an undefined behavior if we go with this patch.

*Maybe* we want to restrict this to atomic userspace. (Ie. advertise the more limited possible_crtcs for legacy userspace.) Depends on whether we can (slightly retroactively) declare that mixing atomic and legacy APIs is undefined behavior. Or if really needed, add DRM_CLIENT_CAP_REALLY_REALLY_ATOMIC_NO_LEGACY_PLS. (Or just pass in value 2 for existing DRM_CLIENT_CAP_ATOMIC)

 drivers/gpu/drm/drm_crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_crtc.c +0 -0
index c215802..1e6d37f 100644

drivers/gpu/drm/drm_crtc.c int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, · line 712

Quoted 8 lines
drivers/gpu/drm/drm_crtc.c +2 -2
@@ -707,9 +707,9 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
 	crtc->primary = primary;
 	crtc->cursor = cursor;
 	if (primary)
-		primary->possible_crtcs = 1 << drm_crtc_index(crtc);
+		WARN_ON(!(primary->possible_crtcs & (1 << drm_crtc_index(crtc))));
 	if (cursor)
-		cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
+		WARN_ON(!(cursor->possible_crtcs & (1 << drm_crtc_index(crtc))));

The slight issue here is that this would require the caller to know the upcoming crtc index before its even assigned. So might be better just having the caller populate these however it likes after the crtc_init()?

Quoted 5 lines
drivers/gpu/drm/drm_crtc.c +0 -0
 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 		drm_object_attach_property(&crtc->base, config->prop_active, 0);
Signature · 1 line
2.7.4
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
In reply to Rob Clark
Quoted 15 lines · Rob Clark

It is kind of a pointless restriction. If userspace does silly things like using crtcA's cursor plane on crtcB, and then setcursor on crtcA, it will end up with the overlay disabled on crtcB. But userspace is allowed to shoot itself like this.

---
Note that cursor and primary planes are slightly useless to non-atomic userspace, since userspace has no way to know *which* crtc a primary or cursor plane belongs to. So lighting up a 2nd display may or may not make your overlay planes go *poof*.

So basically use of cursor/primary planes plus legacy ioctls is an undefined behavior if we go with this patch.

Quoted 6 lines

*Maybe* we want to restrict this to atomic userspace. (Ie. advertise the more limited possible_crtcs for legacy userspace.) Depends on whether we can (slightly retroactively) declare that mixing atomic and legacy APIs is undefined behavior. Or if really needed, add DRM_CLIENT_CAP_REALLY_REALLY_ATOMIC_NO_LEGACY_PLS. (Or just pass in value 2 for existing DRM_CLIENT_CAP_ATOMIC)

Being biased and selfish, I'd like to avoid adding another behavior bit. So I'm fine with this path.

Sean

Quoted 21 lines
 drivers/gpu/drm/drm_crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -3
index c215802..1e6d37f 100644
@@ -707,9 +707,9 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
        crtc->primary = primary;
        crtc->cursor = cursor;
        if (primary)
-               primary->possible_crtcs = 1 << drm_crtc_index(crtc);
+               WARN_ON(!(primary->possible_crtcs & (1 << drm_crtc_index(crtc))));
        if (cursor)
-               cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
+               WARN_ON(!(cursor->possible_crtcs & (1 << drm_crtc_index(crtc))));
 
        if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
                drm_object_attach_property(&crtc->base, config->prop_active, 0);
--
Quoted 2 lines

2.7.4

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

author
#2 lore raw
In reply to Ville Syrjälä
Quoted 35 lines · Ville Syrjälä
Quoted 34 lines · Rob Clark

It is kind of a pointless restriction. If userspace does silly things like using crtcA's cursor plane on crtcB, and then setcursor on crtcA, it will end up with the overlay disabled on crtcB. But userspace is allowed to shoot itself like this.

---
Note that cursor and primary planes are slightly useless to non-atomic userspace, since userspace has no way to know *which* crtc a primary or cursor plane belongs to. So lighting up a 2nd display may or may not make your overlay planes go *poof*.

So basically use of cursor/primary planes plus legacy ioctls is an undefined behavior if we go with this patch.

*Maybe* we want to restrict this to atomic userspace. (Ie. advertise the more limited possible_crtcs for legacy userspace.) Depends on whether we can (slightly retroactively) declare that mixing atomic and legacy APIs is undefined behavior. Or if really needed, add DRM_CLIENT_CAP_REALLY_REALLY_ATOMIC_NO_LEGACY_PLS. (Or just pass in value 2 for existing DRM_CLIENT_CAP_ATOMIC)

 drivers/gpu/drm/drm_crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_crtc.c +0 -1
index c215802..1e6d37f 100644
@@ -707,9 +707,9 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
      crtc->primary = primary;
      crtc->cursor = cursor;
      if (primary)
-             primary->possible_crtcs = 1 << drm_crtc_index(crtc);
Quoted 8 lines

drivers/gpu/drm/drm_crtc.c int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, · line 712

Quoted 4 lines
drivers/gpu/drm/drm_crtc.c +2 -1
+             WARN_ON(!(primary->possible_crtcs & (1 << drm_crtc_index(crtc))));
      if (cursor)
-             cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
+             WARN_ON(!(cursor->possible_crtcs & (1 << drm_crtc_index(crtc))));

The slight issue here is that this would require the caller to know the upcoming crtc index before its even assigned. So might be better just having the caller populate these however it likes after the crtc_init()?

hmm, bleh.. I wanted to make sure we catch drivers that left it as zero..

but how 'bout:

  if (cursor && !cursor->possible_crtcs)
     cursor->possible_crtcs = 1 << drm_crtc_index(crtc);

BR,
-R

Quoted 9 lines
Quoted 5 lines
drivers/gpu/drm/drm_crtc.c +0 -1
      if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
              drm_object_attach_property(&crtc->base, config->prop_active, 0);
--

2.7.4

--
Ville Syrjälä
Intel OTC

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