Skip to contentSkip to conversation

drm/vmwgfx: add local DRM_AUTH check for PRIME TO/FROM HANDLE

PATCH In review Emil Velikov 3 participants 4 messages Aug 2, 2019 – Aug 6, 2019 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/vmwgfx: add local DRM_AUTH check for PRIME TO/FROM HANDLE

From: Emil Velikov <[email protected]>

Realistically no drivers, but vmwgfx care about the DRM_AUTH flag here.

Follow-up work in this driver will properly isolate primary clients from different master realms, thus we'll no longer need to parse _any_ ioctl flags.

Until that work lands, add a local workaround.

v2: Use bitwise or (Deepak)

Cc VMware Graphics <[email protected]>
Cc Thomas Hellstrom <[email protected]>
Cc Deepak Singh Rawat <[email protected]>

---
I'd like to merge this and the next patch hrough the drm-misc tree. Ack and rb are appreciated.

Thanks
Emil

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +9 -0
index cd0d49d8a8da..53afb1d597e8 100644
@@ -1134,6 +1134,15 @@ static long vmw_generic_ioctl(struct file *filp, unsigned int cmd,
 	} else if (!drm_ioctl_flags(nr, &flags))
 		return -EINVAL;
 
+	/*
+	 * Little workaround until the vmwgfx patches providing isolation of
+	 * primary clients from different master realms land.
+	 * With that work, we'll no longer need to parse _any_ ioctl flags.
+	 */
+	if (nr == 0x2d /* DRM_IOCTL_PRIME_HANDLE_TO_FD */ ||
+	    nr == 0x2e /* DRM_IOCTL_PRIME_FD_TO_HANDLE */)
+		flags |= DRM_AUTH;
+
 	vmaster = vmw_master_check(dev, file_priv, flags);
 	if (IS_ERR(vmaster)) {
 		ret = PTR_ERR(vmaster);
Signature · 6 lines
2.21.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 20190802170117.10942-1-emil.l.velikov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v2 2/2 drm: drop DRM_AUTH from PRIME_TO/FROM_HANDLE ioctls

From: Emil Velikov <[email protected]>

As mentioned by Christian, for drivers which support only primary nodes this changes the returned error from -EACCES into -EOPNOTSUPP/-ENOSYS.

For others, this check in particular will be a noop. So let's remove it as suggested by Christian.

---
 drivers/gpu/drm/drm_ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_ioctl.c +2 -2
index f675a3bb2c88..867ab4e50374 100644
@@ -647,8 +647,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, 0),
 
-	DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
-	DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_RENDER_ALLOW),
 
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, 0),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, 0),
Signature · 6 lines
2.21.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v2 1/2
#3 lore raw
In reply to Emil Velikov

Hi Emil,

Thanks for doing this. Looks good to me. By the way I think Thomas had a patch to get rid of legacy locking mechanism. I don't know when it will go upstream. With that we no need for the below check.

Quoted 46 lines · Emil Velikov

From: Emil Velikov <[email protected]>

Realistically no drivers, but vmwgfx care about the DRM_AUTH flag here.

Follow-up work in this driver will properly isolate primary clients from
different master realms, thus we'll no longer need to parse _any_ ioctl
flags.

Until that work lands, add a local workaround.

v2: Use bitwise or (Deepak)

Cc VMware Graphics <[email protected]>
Cc Thomas Hellstrom <[email protected]>
Cc Deepak Singh Rawat <[email protected]>

---
I'd like to merge this and the next patch hrough the drm-misc tree. Ack
and rb are appreciated.

Thanks
Emil

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +2 -0
index cd0d49d8a8da..53afb1d597e8 100644
@@ -1134,6 +1134,15 @@ static long vmw_generic_ioctl(struct file
 *filp, unsigned int cmd,
 	} else if (!drm_ioctl_flags(nr, &flags))
 		return -EINVAL;
 
+	/*
+	 * Little workaround until the vmwgfx patches providing

isolation of

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +2 -0
+	 * primary clients from different master realms land.
+	 * With that work, we'll no longer need to parse _any_ ioctl

flags.

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static long vmw_generic_ioctl(struct file *filp, unsigned int cmd, · line 1148

Quoted 8 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +5 -0
+	 */
+	if (nr == 0x2d /* DRM_IOCTL_PRIME_HANDLE_TO_FD */ ||
+	    nr == 0x2e /* DRM_IOCTL_PRIME_FD_TO_HANDLE */)
+		flags |= DRM_AUTH;
+
 	vmaster = vmw_master_check(dev, file_priv, flags);
 	if (IS_ERR(vmaster)) {
 		ret = PTR_ERR(vmaster);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 7 lines · Deepak Singh Rawat

Hi Emil,

Thanks for doing this. Looks good to me. By the way I think Thomas had a patch to get rid of legacy locking mechanism. I don't know when it will go upstream. With that we no need for the below check.

Agreed the patches were part of the 5.3-rc1 pull request to Linus. Sadly the whole vmwgfx branch was reverted [1] :-(

Once that re-lands, we can remove this temporary workaround.

Quoted 2 lines

Great, thank you.

-Emil

[1] https://lists.freedesktop.org/archives/dri-devel/2019-July/226542.html
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel