drm: validate possible_crtcs for primary and cursor planes
authorSimon Ser <contact@emersion.fr>
Fri, 11 Dec 2020 18:46:32 +0000 (19:46 +0100)
committerSimon Ser <contact@emersion.fr>
Tue, 15 Dec 2020 15:46:45 +0000 (16:46 +0100)
If a primary or cursor plane is not compatible with a CRTC it's attached
to via the legacy primary/cursor field, things will be broken for legacy
user-space.

v4: use drm_crtc_mask instead of BIT (Ville)

Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201211184634.74534-2-contact@emersion.fr
drivers/gpu/drm/drm_mode_config.c

index f1affc1..1628c8b 100644 (file)
@@ -625,6 +625,7 @@ static void validate_encoder_possible_crtcs(struct drm_encoder *encoder)
 void drm_mode_config_validate(struct drm_device *dev)
 {
        struct drm_encoder *encoder;
+       struct drm_crtc *crtc;
 
        if (!drm_core_check_feature(dev, DRIVER_MODESET))
                return;
@@ -636,4 +637,19 @@ void drm_mode_config_validate(struct drm_device *dev)
                validate_encoder_possible_clones(encoder);
                validate_encoder_possible_crtcs(encoder);
        }
+
+       drm_for_each_crtc(crtc, dev) {
+               if (crtc->primary) {
+                       WARN(!(crtc->primary->possible_crtcs & drm_crtc_mask(crtc)),
+                            "Bogus primary plane possible_crtcs: [PLANE:%d:%s] must be compatible with [CRTC:%d:%s]\n",
+                            crtc->primary->base.id, crtc->primary->name,
+                            crtc->base.id, crtc->name);
+               }
+               if (crtc->cursor) {
+                       WARN(!(crtc->cursor->possible_crtcs & drm_crtc_mask(crtc)),
+                            "Bogus cursor plane possible_crtcs: [PLANE:%d:%s] must be compatible with [CRTC:%d:%s]\n",
+                            crtc->cursor->base.id, crtc->cursor->name,
+                            crtc->base.id, crtc->name);
+               }
+       }
 }