nouveau/dispnv50: add cursor size/pitch checks
Subsystems (3)
PATCH 1/1 nouveau/dispnv50: add cursor size/pitch checks
The hardware needs a FB which is packed and not too large. Add checks to make sure this is the case.
While at it, add a debug log for the existing check. This allows user-space to more easily figure out why a configuration is rejected.
This commit depends on "drm/nouveau/kms/nv50-: Report max cursor size to userspace", otherwise mode_config.cursor_{width,height} is zero.
--- drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +21 -1
@@ -99,6 +99,7 @@ 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;int ret; ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
@@ -109,8 +110,27 @@ 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.w > dev->mode_config.cursor_width || + asyw->image.h > dev->mode_config.cursor_height) { +drm_dbg_atomic (dev, +"Invalid cursor image size: too large (%dx%d > %dx%d)" , + asyw->image.w, asyw->image.h, + dev->mode_config.cursor_width, + dev->mode_config.cursor_height); +return -EINVAL ; + } +if (asyw->image.pitch[0 ] != asyw->image.w *4 ) { +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)
Signature · 6 lines
2.30.0 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
Quoted 43 lines · Simon Ser
The hardware needs a FB which is packed and not too large. Add checks to make sure this is the case.
While at it, add a debug log for the existing check. This allows user-space to more easily figure out why a configuration is rejected.
This commit depends on "drm/nouveau/kms/nv50-: Report max cursor size to userspace", otherwise mode_config.cursor_{width,height} is zero.
Signed-off-by Simon Ser <[email protected]>Cc Lyude Paul <[email protected]>Cc Ben Skeggs <[email protected]>Cc Ilia Mirkin <[email protected]>--- drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/dispnv50/curs507a.c +6
-1@@ -99,6 +99,7 @@ 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;int ret; ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,@@ -109,8 +110,27 @@ 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 ; + }
drivers/gpu/drm/nouveau/dispnv50/curs507a.c curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, · line 128
Quoted 10 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +10
-0+if (asyw->image.w > dev->mode_config.cursor_width || + asyw->image.h > dev->mode_config.cursor_height) { +drm_dbg_atomic (dev, +"Invalid cursor image size: too large (%dx%d > %dx%d)" , + asyw->image.w, asyw->image.h, + dev->mode_config.cursor_width, + dev->mode_config.cursor_height); +return -EINVAL ; + } +if (asyw->image.pitch[0 ] != asyw->image.w *4 ) {
Rather than hard-coding to 4, make this look at the format (or cpp, which should be available somewhere too I think). (Yeah, currently we only expose RGBA8, but we should also be doing RGB5A1.)
drivers/gpu/drm/nouveau/dispnv50/curs507a.c curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, · line 135
Quoted 7 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +5
-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);
And this will fail due to the width/height not being supported, right?
-ilia
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Lyude Paul
maintainerQuoted 61 lines · Ilia Mirkin
Quoted 49 lines · Simon Ser
The hardware needs a FB which is packed and not too large. Add checks to make sure this is the case.
While at it, add a debug log for the existing check. This allows user-space to more easily figure out why a configuration is rejected.
This commit depends on "drm/nouveau/kms/nv50-: Report max cursor size to userspace", otherwise mode_config.cursor_{width,height} is zero.
Signed-off-by Simon Ser <[email protected]>Cc Lyude Paul <[email protected]>Cc Ben Skeggs <[email protected]>Cc Ilia Mirkin <[email protected]>---
drivers/gpu/drm/nouveau/dispnv50/curs507a.c | 22 ++++++++++++++++++++-1 file changed, 21 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/dispnv50/curs507a.c +1
-0@@ -99,6 +99,7 @@ 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; int ret;ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh-
Quoted 1 line
state,
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +6
-1@@ -109,8 +110,27 @@ 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.w > dev->mode_config.cursor_width ||drivers/gpu/drm/nouveau/dispnv50/curs507a.c curs507a_acquire(struct nv50_wndw *wndw, struct · line 131
Quoted 10 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +9
-0+ asyw->image.h > dev->mode_config.cursor_height) { + drm_dbg_atomic(dev, + "Invalid cursor image size: too large (%dx%d > %dx%d)", + asyw->image.w, asyw->image.h, + dev->mode_config.cursor_width, + dev->mode_config.cursor_height); + return -EINVAL; + } + if (asyw->image.pitch[0] != asyw->image.w * 4) {
Quoted 3 lines
Rather than hard-coding to 4, make this look at the format (or cpp, which should be available somewhere too I think). (Yeah, currently we only expose RGBA8, but we should also be doing RGB5A1.)
FWIW, required pitch for cursors (fun fact - it's actually different then the pitch requirements for any other kind of surface used with evo!) in A1G5G5B5 is
* 2, and the * 4 you have here is correct for A8R8G8B8.
Just a note, I did actually try to enable RGB5A1 at least on pascal when working on igt with nouveau, I'm not sure why but something appears to be broken with that (iirc the RM throws an exception, and unfortunately I think it's one of the few exceptions I don't actually have any secret docs for), just changing the cursor layout isn't enough. Or maybe I screwed something silly up somewhere, but seeing as I tried quite a few times I'd hope not :).
Anyway, the rest of this looks great
Quoted 14 lines
Quoted 9 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +2
-0+ drm_dbg_atomic(dev, + "Invalid cursor image pitch: image must bepacked (pitch = %d, width = %d)",
+ asyw->image.pitch[0],asyw->image.w); + return-EINVAL;
+ }ret =
head->func->curs_layout(head, asyw, asyh);And this will fail due to the width/height not being supported, right?
-ilia
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
Quoted 5 lines · Ilia Mirkin
Quoted 1 line
+ if (asyw->image.pitch[0] !=
asyw->image.w* 4) {Rather than hard-coding to 4, make this look at the format (or cpp, which should be available somewhere too I think). (Yeah, currently we only expose RGBA8, but we should also be doing RGB5A1.)
Makes sense.
Quoted 9 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, · line 135
Quoted 7 lines
drivers/gpu/drm/nouveau/dispnv50/curs507a.c +5
-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);And this will fail due to the width/height not being supported, right?
Oh right, this function will perform size checks, and is better than the one I added above because it actually checks that the combination is supported. Will remove the one above in v2.
Thanks for the comments!
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau