Skip to contentSkip to conversation

drm: pre-fill getfb2 modifier array with INVALID

PATCH In review Simon Ser 4 participants 7 messages Nov 11, 2021 – Nov 15, 2021

Subsystems (2)
lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH 1/1 drm: pre-fill getfb2 modifier array with INVALID

User-space shouldn't look up the modifier array when the modifier flag is missing, but at the moment no docs make this clear (working on it). Right now the modifier array is pre-filled with zeroes, aka. LINEAR. Instead, pre-fill with INVALID to avoid footguns.

This is a uAPI change, but OTOH any user-space which looks up the modifier array without checking the flag is broken already, so should be fine.

Cc Daniel Vetter <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Daniel Stone <[email protected]>
---
 drivers/gpu/drm/drm_framebuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_framebuffer.c +1 -1
index 07f5abc875e9..f7041c0a0407 100644
@@ -601,7 +601,7 @@ int drm_mode_getfb2_ioctl(struct drm_device *dev,
 		r->handles[i] = 0;
 		r->pitches[i] = 0;
 		r->offsets[i] = 0;
-		r->modifier[i] = 0;
+		r->modifier[i] = DRM_FORMAT_MOD_INVALID;
 	}
 
 	for (i = 0; i < fb->format->num_planes; i++) {
Signature · 1 line
2.33.1
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · On Thu, 11 Nov 2021 10:10:54 +0000 Simon Ser <[email protected]> wrote:

User-space shouldn't look up the modifier array when the modifier flag is missing, but at the moment no docs make this clear (working on it). Right now the modifier array is pre-filled with zeroes, aka. LINEAR. Instead, pre-fill with INVALID to avoid footguns.

This is a uAPI change, but OTOH any user-space which looks up the modifier array without checking the flag is broken already, so should be fine.

Cc Daniel Vetter <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Daniel Stone <[email protected]>
---
 drivers/gpu/drm/drm_framebuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_framebuffer.c +0 -0
index 07f5abc875e9..f7041c0a0407 100644

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb2_ioctl(struct drm_device *dev, · line 607

Quoted 8 lines
drivers/gpu/drm/drm_framebuffer.c +1 -1
@@ -601,7 +601,7 @@ int drm_mode_getfb2_ioctl(struct drm_device *dev,
 		r->handles[i] = 0;
 		r->pitches[i] = 0;
 		r->offsets[i] = 0;
-		r->modifier[i] = 0;
+		r->modifier[i] = DRM_FORMAT_MOD_INVALID;
 	}
 
 	for (i = 0; i < fb->format->num_planes; i++) {

Thanks,
pq

Acked-by on v1 1/1
#2 lore raw
In reply to Simon Ser
Quoted 8 lines · Simon Ser

User-space shouldn't look up the modifier array when the modifier flag is missing, but at the moment no docs make this clear (working on it). Right now the modifier array is pre-filled with zeroes, aka. LINEAR. Instead, pre-fill with INVALID to avoid footguns.

This is a uAPI change, but OTOH any user-space which looks up the modifier array without checking the flag is broken already, so should be fine.

I don't know of any userspace which this would break.

#3 lore raw
In reply to Simon Ser
Quoted 5 lines · Simon Ser

User-space shouldn't look up the modifier array when the modifier flag is missing, but at the moment no docs make this clear (working on it). Right now the modifier array is pre-filled with zeroes, aka. LINEAR. Instead, pre-fill with INVALID to avoid footguns.

Quoted 8 lines

This is a uAPI change, but OTOH any user-space which looks up the modifier array without checking the flag is broken already, so should be fine.

Cc Daniel Vetter <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Daniel Stone <[email protected]>

Isn't this going to break the test where we pass the get getfb2 result back into addfb2?

Quoted 20 lines
---
 drivers/gpu/drm/drm_framebuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_framebuffer.c +1 -1
index 07f5abc875e9..f7041c0a0407 100644
@@ -601,7 +601,7 @@ int drm_mode_getfb2_ioctl(struct drm_device *dev,
 		r->handles[i] = 0;
 		r->pitches[i] = 0;
 		r->offsets[i] = 0;
-		r->modifier[i] = 0;
+		r->modifier[i] = DRM_FORMAT_MOD_INVALID;
 	}
 
 	for (i = 0; i < fb->format->num_planes; i++) {
Signature · 1 line
2.33.1
Signature · 2 lines
Ville Syrjälä
Intel
author
#4 lore raw
Quoted 10 lines · Ville Syrjälä
Quoted 9 lines · Simon Ser

User-space shouldn't look up the modifier array when the modifier flag is missing, but at the moment no docs make this clear (working on it). Right now the modifier array is pre-filled with zeroes, aka. LINEAR. Instead, pre-fill with INVALID to avoid footguns.

This is a uAPI change, but OTOH any user-space which looks up the modifier array without checking the flag is broken already, so should be fine.

Quoted 7 lines
Quoted 4 lines
Cc Daniel Vetter <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Daniel Stone <[email protected]>

Isn't this going to break the test where we pass the get getfb2 result back into addfb2?

Shouldn't be the case, since the kernel will ignore modifiers if the flag isn't set.

#5 lore raw
Quoted 17 lines · Simon Ser
Quoted 15 lines · Ville Syrjälä
Quoted 13 lines · Simon Ser

User-space shouldn't look up the modifier array when the modifier flag is missing, but at the moment no docs make this clear (working on it). Right now the modifier array is pre-filled with zeroes, aka. LINEAR. Instead, pre-fill with INVALID to avoid footguns.

This is a uAPI change, but OTOH any user-space which looks up the modifier array without checking the flag is broken already, so should be fine.

Cc Daniel Vetter <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Daniel Stone <[email protected]>
Quoted 5 lines
Quoted 2 lines

Isn't this going to break the test where we pass the get getfb2 result back into addfb2?

Shouldn't be the case, since the kernel will ignore modifiers if the flag isn't set.

if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {
	DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
		r->modifier[i], i);
	return -EINVAL;
}
Signature · 2 lines
Ville Syrjälä
Intel
author
#6 lore raw

Hm indeed, RIP. I got confused by this one:

		/* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */
		if (!(r->flags & DRM_MODE_FB_MODIFIERS))
			continue;

But it's only run for unused planes.