Skip to contentSkip to conversation

nouveau/dispnv50: add cursor pitch check

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

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH v3 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)

v3:
- Add missing newlines in debug messages (Lyude)
- Use NV_ATOMIC (Lyude)
- Add missing debug log for invalid format (Ilia)

---
 drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 31 +++++++++++++++++++--
 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +28 -3
index 54fbd6fe751d..56459cfd037e 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 nouveau_drm *drm = nouveau_drm(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,14 +112,36 @@ 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) {
+		NV_ATOMIC(drm,
+			  "Invalid cursor image size: width (%d) must match height (%d)\n",
+			  asyw->image.w, asyw->image.h);
 		return -EINVAL;
+	}
+	if (asyw->image.pitch[0] != asyw->image.w * fb->format->cpp[0]) {
+		NV_ATOMIC(drm,
+			  "Invalid cursor image pitch: image must be packed (pitch = %d, width = %d)\n",
+			  asyw->image.pitch[0], asyw->image.w);
+		return -EINVAL;
+	}
 
 	ret = head->func->curs_layout(head, asyw, asyh);
-	if (ret)
+	if (ret) {
+		NV_ATOMIC(drm,
+			  "Invalid cursor image size: unsupported size %dx%d\n",
+			  asyw->image.w, asyw->image.h);
+		return ret;
+	}
+
+	ret = head->func->curs_format(head, asyw, asyh);
+	if (ret) {
+		NV_ATOMIC(drm,
+			  "Invalid cursor image format 0x%X\n",
+			  fb->format->format);
 		return ret;
+	}
 
-	return head->func->curs_format(head, asyw, asyh);
+	return 0;
 }
 
 static const u32
Signature · 6 lines
2.30.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Reviewed-by on v3 1/1
#1 lore raw
Quoted 30 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)

v3:
- Add missing newlines in debug messages (Lyude)
- Use NV_ATOMIC (Lyude)
- Add missing debug log for invalid format (Ilia)

---
 drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 31 +++++++++++++++++++--
 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +0 -0
index 54fbd6fe751d..56459cfd037e 100644

drivers/gpu/drm/nouveau/dispnv50/curs507a.c line 33

Quoted 4 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +1 -0
@@ -30,6 +30,7 @@
 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>

Why is this needed?

Quoted 13 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +2 -0
 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 nouveau_drm *drm = nouveau_drm(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 curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, · line 118

Quoted 8 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +4 -1
@@ -109,14 +112,36 @@ 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) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image size: width (%d) must match height (%d)\n",
+                         asyw->image.w, asyw->image.h);

Maybe keep with the style of the other NV_ATOMIC's, e.g. include %s:
at the beginning with wndw->plane.name as the value?

Either way,

Quoted 32 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +21 -3
                return -EINVAL;
+       }
+       if (asyw->image.pitch[0] != asyw->image.w * fb->format->cpp[0]) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image pitch: image must be packed (pitch = %d, width = %d)\n",
+                         asyw->image.pitch[0], asyw->image.w);
+               return -EINVAL;
+       }
 
        ret = head->func->curs_layout(head, asyw, asyh);
-       if (ret)
+       if (ret) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image size: unsupported size %dx%d\n",
+                         asyw->image.w, asyw->image.h);
+               return ret;
+       }
+
+       ret = head->func->curs_format(head, asyw, asyh);
+       if (ret) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image format 0x%X\n",
+                         fb->format->format);
                return ret;
+       }
 
-       return head->func->curs_format(head, asyw, asyh);
+       return 0;
 }
 
 static const u32
--
Quoted 2 lines

2.30.0

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

maintainer
#2 lore raw
Quoted 58 lines · Ilia Mirkin
Quoted 31 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)

v3:
- Add missing newlines in debug messages (Lyude)
- Use NV_ATOMIC (Lyude)
- Add missing debug log for invalid format (Ilia)

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

 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +0 -0
index 54fbd6fe751d..56459cfd037e 100644

drivers/gpu/drm/nouveau/dispnv50/curs507a.c line 33

Quoted 4 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +1 -0
@@ -30,6 +30,7 @@
 
  #include <drm/drm_atomic_helper.h>
  #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>

Why is this needed?

Quoted 19 lines

 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 nouveau_drm *drm = nouveau_drm(head->base.base.dev);
+       struct drm_framebuffer *fb = asyw->state.fb;
         int ret;
 

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

Quoted 1 line

state,

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

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

Quoted 6 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +4 -1
-       if (asyw->image.w != asyw->image.h)
+       if (asyw->image.w != asyw->image.h) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image size: width (%d) must match
 height (%d)\n",
+                         asyw->image.w, asyw->image.h);

Maybe keep with the style of the other NV_ATOMIC's, e.g. include %s:
at the beginning with wndw->plane.name as the value?

Seconded on that - thanks for catching that!

Quoted 42 lines

Either way,

Quoted 36 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +21 -2
                 return -EINVAL;
+       }
+       if (asyw->image.pitch[0] != asyw->image.w * fb->format->cpp[0]) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image pitch: image must be packed
 (pitch = %d, width = %d)\n",
+                         asyw->image.pitch[0], asyw->image.w);
+               return -EINVAL;
+       }
 
         ret = head->func->curs_layout(head, asyw, asyh);
-       if (ret)
+       if (ret) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image size: unsupported size
 %dx%d\n",
+                         asyw->image.w, asyw->image.h);
+               return ret;
+       }
+
+       ret = head->func->curs_format(head, asyw, asyh);
+       if (ret) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image format 0x%X\n",
+                         fb->format->format);
                 return ret;
+       }
 
-       return head->func->curs_format(head, asyw, asyh);
+       return 0;

 }

 static const u32
--
2.30.0

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
author
#3 lore raw
In reply to Ilia Mirkin
Quoted 9 lines · Ilia Mirkin

drivers/gpu/drm/nouveau/dispnv50/curs507a.c line 33

Quoted 7 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +1 -0
@@ -30,6 +30,7 @@
 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>

Why is this needed?

This is needed for the definition of struct drm_format_info.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +2 -0
 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 nouveau_drm *drm = nouveau_drm(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,14 +112,36 @@ curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
        if (ret || !asyh->curs.visible)
                return ret;
 
Quoted 8 lines

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

Quoted 5 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +4 -1
-       if (asyw->image.w != asyw->image.h)
+       if (asyw->image.w != asyw->image.h) {
+               NV_ATOMIC(drm,
+                         "Invalid cursor image size: width (%d) must match height (%d)\n",
+                         asyw->image.w, asyw->image.h);

Maybe keep with the style of the other NV_ATOMIC's, e.g. include %s:
at the beginning with wndw->plane.name as the value?

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