Skip to contentSkip to conversation

nouveau/dispnv50: add cursor pitch check

PATCH Superseded Simon Ser 3 participants 4 messages Feb 5, 2021

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH v2 1/1 nouveau/dispnv50: add cursor pitch check

The hardware needs a FB which is packed. Add checks to make sure this is the case.

While at it, add debug logs for the existing checks. This allows user-space to more easily figure out why a configuration is rejected.

v2:
- Use drm_format_info instead of hardcoding bytes-per-pixel (Ilia)
- Remove unnecessary size check (Ilia)

Cc Lyude Paul <[email protected]>
Cc Ben Skeggs <[email protected]>
Cc Ilia Mirkin <[email protected]>
---
 drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +19 -2
index 54fbd6fe751d..00f09c9a8d15 100644
@@ -30,6 +30,7 @@
 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>
 
 bool
 curs507a_space(struct nv50_wndw *wndw)
@@ -99,6 +100,8 @@ curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
 		 struct nv50_head_atom *asyh)
 {
 	struct nv50_head *head = nv50_head(asyw->state.crtc);
+	struct drm_device *dev = head->base.base.dev;
+	struct drm_framebuffer *fb = asyw->state.fb;
 	int ret;
 
 	ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
@@ -109,12 +112,26 @@ curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
 	if (ret || !asyh->curs.visible)
 		return ret;
 
-	if (asyw->image.w != asyw->image.h)
+	if (asyw->image.w != asyw->image.h) {
+		drm_dbg_atomic(dev,
+			       "Invalid cursor image size: width (%d) must match height (%d)",
+			       asyw->image.w, asyw->image.h);
 		return -EINVAL;
+	}
+	if (asyw->image.pitch[0] != asyw->image.w * fb->format->cpp[0]) {
+		drm_dbg_atomic(dev,
+			       "Invalid cursor image pitch: image must be packed (pitch = %d, width = %d)",
+			       asyw->image.pitch[0], asyw->image.w);
+		return -EINVAL;
+	}
 
 	ret = head->func->curs_layout(head, asyw, asyh);
-	if (ret)
+	if (ret) {
+		drm_dbg_atomic(dev,
+			       "Invalid cursor image size: unsupported size %dx%d",
+			       asyw->image.w, asyw->image.h);
 		return ret;
+	}
 
 	return head->func->curs_format(head, asyw, asyh);
 }
Signature · 6 lines
2.30.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 64 lines · Simon Ser

The hardware needs a FB which is packed. Add checks to make sure this is the case.

While at it, add debug logs for the existing checks. This allows user-space to more easily figure out why a configuration is rejected.

v2:
- Use drm_format_info instead of hardcoding bytes-per-pixel (Ilia)
- Remove unnecessary size check (Ilia)

Cc Lyude Paul <[email protected]>
Cc Ben Skeggs <[email protected]>
Cc Ilia Mirkin <[email protected]>

---
 drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 21 +++++++++++++++++++--

 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +0 -0
index 54fbd6fe751d..00f09c9a8d15 100644
@@ -30,6 +30,7 @@


 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>

 bool
 curs507a_space(struct nv50_wndw *wndw)

drivers/gpu/drm/nouveau/dispnv50/curs507a.c +2 -0
@@ -99,6 +100,8 @@ curs507a_acquire(struct nv50_wndw *wndw, struct
 nv50_wndw_atom *asyw,
                  struct nv50_head_atom *asyh)
  {
         struct nv50_head *head = nv50_head(asyw->state.crtc);
+       struct drm_device *dev = head->base.base.dev;
+       struct drm_framebuffer *fb = asyw->state.fb;
         int ret;


        ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,

drivers/gpu/drm/nouveau/dispnv50/curs507a.c +0 -0
@@ -109,12 +112,26 @@ curs507a_acquire(struct nv50_wndw *wndw, struct
 nv50_wndw_atom *asyw,
         if (ret || !asyh->curs.visible)
                 return ret;


-       if (asyw->image.w != asyw->image.h)
+       if (asyw->image.w != asyw->image.h) {
+               drm_dbg_atomic(dev,
+                              "Invalid cursor image size: width (%d) must match height (%d)",
+                              asyw->image.w, asyw->image.h); return -EINVAL;
+       }
+       if (asyw->image.pitch[0] != asyw->image.w * fb->format->cpp[0]) { +               drm_dbg_atomic(dev,
+                              "Invalid cursor image pitch: image must be packed (pitch = %d, width = %d)",
+                              asyw->image.pitch[0], asyw->image.w); +               return -EINVAL;
+       }

        ret = head->func->curs_layout(head, asyw, asyh);

Quoted 8 lines

-       if (ret)
+       if (ret) {
+               drm_dbg_atomic(dev,
+                              "Invalid cursor image size: unsupported size %dx%d",
+                              asyw->image.w, asyw->image.h); return ret;
+       }

Oh-some things I forgot to mention:

- You're missing some newlines in your debug messages
- Also, NV_ATOMIC() is a thing

With those two fixed:

Quoted 3 lines


        return head->func->curs_format(head, asyw, asyh); }

Signature · 13 lines
Sincerely,
   Lyude Paul (she/her)
   Software Engineer at Red Hat
   
Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've
asked me a question, are waiting for a review/merge on a patch, etc. and I
haven't responded in a while, please feel free to send me another email to check
on my status. I don't bite!

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
#2 lore raw
In reply to Simon Ser
Quoted 59 lines · Simon Ser

The hardware needs a FB which is packed. Add checks to make sure this is the case.

While at it, add debug logs for the existing checks. This allows user-space to more easily figure out why a configuration is rejected.

v2:
- Use drm_format_info instead of hardcoding bytes-per-pixel (Ilia)
- Remove unnecessary size check (Ilia)

Cc Lyude Paul <[email protected]>
Cc Ben Skeggs <[email protected]>
Cc Ilia Mirkin <[email protected]>
---
 drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +14 -1
index 54fbd6fe751d..00f09c9a8d15 100644
@@ -30,6 +30,7 @@
 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>
 
 bool
 curs507a_space(struct nv50_wndw *wndw)
@@ -99,6 +100,8 @@ curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
                 struct nv50_head_atom *asyh)
 {
        struct nv50_head *head = nv50_head(asyw->state.crtc);
+       struct drm_device *dev = head->base.base.dev;
+       struct drm_framebuffer *fb = asyw->state.fb;
        int ret;
 
        ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
@@ -109,12 +112,26 @@ curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
        if (ret || !asyh->curs.visible)
                return ret;
 
-       if (asyw->image.w != asyw->image.h)
+       if (asyw->image.w != asyw->image.h) {
+               drm_dbg_atomic(dev,
+                              "Invalid cursor image size: width (%d) must match height (%d)",
+                              asyw->image.w, asyw->image.h);
                return -EINVAL;
+       }
+       if (asyw->image.pitch[0] != asyw->image.w * fb->format->cpp[0]) {
+               drm_dbg_atomic(dev,
+                              "Invalid cursor image pitch: image must be packed (pitch = %d, width = %d)",
+                              asyw->image.pitch[0], asyw->image.w);
+               return -EINVAL;
+       }
 

drivers/gpu/drm/nouveau/dispnv50/curs507a.c curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, · line 136

Quoted 10 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +5 -1
        ret = head->func->curs_layout(head, asyw, asyh);
-       if (ret)
+       if (ret) {
+               drm_dbg_atomic(dev,
+                              "Invalid cursor image size: unsupported size %dx%d",
+                              asyw->image.w, asyw->image.h);
                return ret;
+       }
 
        return head->func->curs_format(head, asyw, asyh);

While you're at it, maybe give this one some love too?

Cheers,

-ilia
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

author
#3 lore raw
Quoted 3 lines · Ilia Mirkin
Quoted 1 line

return head->func->curs_format(head, asyw, asyh);

While you're at it, maybe give this one some love too?

Sure, although this would be a driver bug because DRM core already checks the format. curs_format has WARN_ON when it fails.
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau