drm/vmwgfx: Don't use the HB port if memory encryption is active
Subsystems (3)
PATCH 1/9 drm/vmwgfx: Don't use the HB port if memory encryption is active
From: Thomas Hellstrom <[email protected]>
With memory encryption active, the hypervisor typically can't read the guest memory using the HB port, since it is encrypted using a key known only to the guest. In that case fall back to processing 4 bytes at a time using the ordinary backdoor port.
The other option would be to use unencrypted bounce buffers for the hypervisor to read out from or write into, but given the limited message sizes it appears more efficient to just fall back to the ordinary backdoor port.
--- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +5 -2
@@ -28,6 +28,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/mem_encrypt.h> #include <asm/hypervisor.h>
@@ -148,7 +149,8 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,unsigned long si, di, eax, ebx, ecx, edx;unsigned long msg_len =strlen (msg); -if (hb) { +/* HB port can't access encrypted memory. */ +if (hb && !mem_encrypt_active ()) {unsigned long bp = channel->cookie_high; si = (uintptr_t ) msg;
@@ -202,7 +204,8 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply, {unsigned long si, di, eax, ebx, ecx, edx; -if (hb) { +/* HB port can't access encrypted memory */ +if (hb && !mem_encrypt_active ()) {unsigned long bp = channel->cookie_low; si = channel->cookie_high;
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/9 drm/vmwgfx: Call vmw_driver_{load, unload}() before registering device
From: Thomas Zimmermann <[email protected]>
The load/unload callbacks in struct drm_driver are deprecated. Remove them and call functions explicitly.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 42 +++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +37 -5
@@ -28,10 +28,10 @@#include <linux/console.h> #include <linux/dma-mapping.h> #include <linux/module.h> +#include <linux/pci.h> #include <drm/drm_drv.h> #include <drm/drm_ioctl.h> -#include <drm/drm_pci.h> #include <drm/drm_sysfs.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_module.h>
@@ -1211,8 +1211,10 @@ static void vmw_remove(struct pci_dev *pdev) {struct drm_device *dev =pci_get_drvdata (pdev); +drm_dev_unregister (dev); +vmw_driver_unload (dev); +drm_dev_put (dev);pci_disable_device (pdev); -drm_put_dev (dev); } static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
@@ -1391,8 +1393,6 @@ static const struct file_operations vmwgfx_driver_fops = {static struct drm_driver driver = { .driver_features =DRIVER_MODESET |DRIVER_RENDER |DRIVER_ATOMIC , - .load = vmw_driver_load, - .unload = vmw_driver_unload, .get_vblank_counter = vmw_get_vblank_counter, .enable_vblank = vmw_enable_vblank, .disable_vblank = vmw_disable_vblank,
@@ -1431,7 +1431,39 @@ static struct pci_driver vmw_pci_driver = {static int vmw_probe (struct pci_dev *pdev,const struct pci_device_id *ent) { -return drm_get_pci_dev (pdev, ent, &driver); +struct drm_device *dev; +int ret; + + ret =pci_enable_device (pdev); +if (ret) +return ret; + + dev =drm_dev_alloc (&driver, &pdev->dev); +if (IS_ERR (dev)) { + ret =PTR_ERR (dev); + goto err_pci_disable_device; + } + + dev->pdev = pdev; +pci_set_drvdata (pdev, dev); + + ret =vmw_driver_load (dev, ent->driver_data); +if (ret) + goto err_drm_dev_put; + + ret =drm_dev_register (dev, ent->driver_data); +if (ret) + goto err_vmw_driver_unload; + +return 0 ; + +err_vmw_driver_unload: +vmw_driver_unload (dev); +err_drm_dev_put: +drm_dev_put (dev); +err_pci_disable_device: +pci_disable_device (pdev); +return ret; }static int __init vmwgfx_init (void )
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/9 drm/vmwgfx: Replace deprecated PTR_RET
In reply to Thomas Hellström (VMware)From: Lukas Bulwahn <[email protected]>
Commit 508108ea2747 ("drm/vmwgfx: Don't refcount command-buffer managed resource lookups during command buffer validation") slips in use of deprecated PTR_RET. Use PTR_ERR_OR_ZERO instead.
As the PTR_ERR_OR_ZERO is a bit longer than PTR_RET, we introduce local variable ret for proper indentation and line-length limits.
--- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +15 -6
@@ -2377,9 +2377,12 @@ static int vmw_cmd_dx_clear_rendertarget_view(struct vmw_private *dev_priv, {VMW_DECLARE_CMD_VAR (*cmd, SVGA3dCmdDXClearRenderTargetView) =container_of (header,typeof (*cmd), header); +struct vmw_resource *ret; -return PTR_RET (vmw_view_id_val_add (sw_context, vmw_view_rt, - cmd->body.renderTargetViewId)); + ret =vmw_view_id_val_add (sw_context, vmw_view_rt, + cmd->body.renderTargetViewId); + +return PTR_ERR_OR_ZERO (ret); }/**
@@ -2396,9 +2399,12 @@ static int vmw_cmd_dx_clear_depthstencil_view(struct vmw_private *dev_priv, {VMW_DECLARE_CMD_VAR (*cmd, SVGA3dCmdDXClearDepthStencilView) =container_of (header,typeof (*cmd), header); +struct vmw_resource *ret; + + ret =vmw_view_id_val_add (sw_context, vmw_view_ds, + cmd->body.depthStencilViewId); -return PTR_RET (vmw_view_id_val_add (sw_context, vmw_view_ds, - cmd->body.depthStencilViewId)); +return PTR_ERR_OR_ZERO (ret); } static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv,
@@ -2741,9 +2747,12 @@ static int vmw_cmd_dx_genmips(struct vmw_private *dev_priv, {VMW_DECLARE_CMD_VAR (*cmd, SVGA3dCmdDXGenMips) =container_of (header,typeof (*cmd), header); +struct vmw_resource *ret; + + ret =vmw_view_id_val_add (sw_context, vmw_view_sr, + cmd->body.shaderResourceViewId); -return PTR_RET (vmw_view_id_val_add (sw_context, vmw_view_sr, - cmd->body.shaderResourceViewId)); +return PTR_ERR_OR_ZERO (ret); }/**
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/9 drm/vmwgfx: move the require_exist handling together
In reply to Thomas Hellström (VMware)From: Emil Velikov <[email protected]>
Move the render_client hunk for require_exist alongside the rest. Keeping all the reasons why an existing object is needed, in a single place makes it easier to follow.
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +5 -4
@@ -934,16 +934,12 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv,uint32_t handle;struct ttm_base_object *base;int ret; -bool require_exist = false;if (handle_type ==DRM_VMW_HANDLE_PRIME ) { ret =ttm_prime_fd_to_handle (tfile, u_handle, &handle);if (unlikely (ret !=0 ))return ret; }else { -if (unlikely (drm_is_render_client (file_priv))) - require_exist = true; - handle = u_handle; }
@@ -960,6 +956,8 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv, }if (handle_type !=DRM_VMW_HANDLE_PRIME ) { +bool require_exist = false; + user_srf = container_of(base, struct vmw_user_surface, prime.base);
@@ -971,6 +969,9 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv, user_srf->master != file_priv->master) require_exist = true; +if (unlikely (drm_is_render_client (file_priv))) + require_exist = true; + ret =ttm_ref_object_add (tfile, base,TTM_REF_USAGE ,NULL , require_exist);if (unlikely (ret !=0 )) {
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/9 drm/vmwgfx: check master authentication in surface_ref ioctls
In reply to Thomas Hellström (VMware)From: Emil Velikov <[email protected]>
With later commit we'll rework DRM authentication handling. Namely DRM_AUTH will not be a requirement for DRM_RENDER_ALLOW ioctls.
Since vmwgfx does isolation for primary clients in different master realms, the DRM_AUTH can be dropped.
The only place where authentication matters, is surface_reference ioctls whenever a legacy (non-prime) handle is used. For those ioctls we call vmw_surface_handle_reference(), where we explicitly check if the client is both a) master and b) unauthenticated - bailing out as result.
Otherwise the usual isolation path kicks in and we're all good.
v2: Reword commit message, since the isolation work has landed.
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +7 -0
@@ -961,6 +961,13 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv, user_srf = container_of(base, struct vmw_user_surface, prime.base); +/* Error out if we are unauthenticated primary */ +if (drm_is_primary_client (file_priv) && + !file_priv->authenticated) { + ret = -EACCES ; + goto out_bad_resource; + } +/* * Make sure the surface creator has the same * authenticating master, or is already registered with us.
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/9 drm/vmwgfx: drop DRM_AUTH for render ioctls
In reply to Thomas Hellström (VMware)From: Emil Velikov <[email protected]>
With earlier commit 9c84aeba67cc ("drm/vmwgfx: Kill unneeded legacy security features") we removed the no longer applicable validation, as we now have isolation of primary clients from different master realms.
As of last commit, we're explicitly checking for authentication in the only render ioctls which care about one.
With those in place, the DRM_AUTH token serves no real purpose. Let's drop it.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +14 -14
@@ -165,9 +165,9 @@static const struct drm_ioctl_desc vmw_ioctls[] = {VMW_IOCTL_DEF (VMW_GET_PARAM , vmw_getparam_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_ALLOC_DMABUF , vmw_bo_alloc_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_UNREF_DMABUF , vmw_bo_unref_ioctl,DRM_RENDER_ALLOW ), VMW_IOCTL_DEF(VMW_CURSOR_BYPASS,
@@ -182,16 +182,16 @@ static const struct drm_ioctl_desc vmw_ioctls[] = { DRM_MASTER),VMW_IOCTL_DEF (VMW_CREATE_CONTEXT , vmw_context_define_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_UNREF_CONTEXT , vmw_context_destroy_ioctl,DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_CREATE_SURFACE , vmw_surface_define_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_UNREF_SURFACE , vmw_surface_destroy_ioctl,DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_REF_SURFACE , vmw_surface_reference_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_EXECBUF , vmw_execbuf_ioctl,DRM_AUTH | +DRM_RENDER_ALLOW ), +VMW_IOCTL_DEF (VMW_EXECBUF , vmw_execbuf_ioctl,DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_FENCE_WAIT , vmw_fence_obj_wait_ioctl, DRM_RENDER_ALLOW),
@@ -201,9 +201,9 @@ static const struct drm_ioctl_desc vmw_ioctls[] = {VMW_IOCTL_DEF (VMW_FENCE_UNREF , vmw_fence_obj_unref_ioctl,DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_FENCE_EVENT , vmw_fence_event_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_GET_3D_CAP , vmw_get_cap_3d_ioctl, -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),/* these allow direct access to the framebuffers mark as master only */ VMW_IOCTL_DEF(VMW_PRESENT, vmw_present_ioctl,
@@ -221,28 +221,28 @@ static const struct drm_ioctl_desc vmw_ioctls[] = { DRM_RENDER_ALLOW),VMW_IOCTL_DEF (VMW_CREATE_SHADER ,vmw_shader_define_ioctl , -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_UNREF_SHADER ,vmw_shader_destroy_ioctl ,DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_GB_SURFACE_CREATE ,vmw_gb_surface_define_ioctl , -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_GB_SURFACE_REF ,vmw_gb_surface_reference_ioctl , -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_SYNCCPU ,vmw_user_bo_synccpu_ioctl ,DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_CREATE_EXTENDED_CONTEXT ,vmw_extended_context_define_ioctl , -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_GB_SURFACE_CREATE_EXT ,vmw_gb_surface_define_ext_ioctl , -DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_RENDER_ALLOW ),VMW_IOCTL_DEF (VMW_GB_SURFACE_REF_EXT ,vmw_gb_surface_reference_ext_ioctl , - DRM_AUTH | DRM_RENDER_ALLOW), + DRM_RENDER_ALLOW), };static const struct pci_device_id vmw_pci_id_list[] = {
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/9 drm/vmwgfx: prevent memory leak in vmw_cmdbuf_res_add
In reply to Thomas Hellström (VMware)From: Navid Emamdoost <[email protected]>
In vmw_cmdbuf_res_add if drm_ht_insert_item fails the allocated memory for cres should be released.
--- drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c +3 -1
@@ -209,8 +209,10 @@ int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man, cres->hash.key = user_key | (res_type <<24 ); ret =drm_ht_insert_item (&man->resources, &cres->hash); -if (unlikely (ret !=0 )) +if (unlikely (ret !=0 )) { +kfree (cres); goto out_invalid_key; + } cres->state =VMW_CMDBUF_RES_ADD ; cres->res =vmw_resource_reference (res);
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/9 drm/vmwgfx: add ioctl for messaging from/to guest userspace to/from host
In reply to Thomas Hellström (VMware)From: Roland Scheidegger <[email protected]>
Up to now, guest userspace does logging directly to host using essentially the same rather complex port assembly stuff as the kernel.
We'd rather use the same mechanism than duplicate it (it may also change in the future), hence add a new ioctl for relaying guest/host messaging (logging is just one application of it).
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 6 +++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 2 + drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 83 +++++++++++++++++++++++++++++ include/uapi/drm/vmwgfx_drm.h | 17 ++++++ 4 files changed, 108 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +6 -0
@@ -150,6 +150,9 @@#define DRM_IOCTL_VMW_GB_SURFACE_REF_EXT \ DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GB_SURFACE_REF_EXT, \ union drm_vmw_gb_surface_reference_ext_arg) +#define DRM_IOCTL_VMW_MSG \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_MSG, \ + struct drm_vmw_msg_arg)/** * The core DRM version of this macro doesn't account for
@@ -243,6 +246,9 @@ static const struct drm_ioctl_desc vmw_ioctls[] = {VMW_IOCTL_DEF (VMW_GB_SURFACE_REF_EXT , vmw_gb_surface_reference_ext_ioctl,DRM_RENDER_ALLOW ), +VMW_IOCTL_DEF (VMW_MSG , + vmw_msg_ioctl, + DRM_RENDER_ALLOW), }; static const struct pci_device_id vmw_pci_id_list[] = {
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +2 -0
@@ -1403,6 +1403,8 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,int vmw_host_get_guestinfo (const char *guest_info_param,char *buffer,size_t *length);int vmw_host_log (const char *log); +int vmw_msg_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv);/* VMW logging */
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +83 -0
92 lines not on this page · raw message
include/uapi/drm/vmwgfx_drm.h +17 -0
@@ -71,6 +71,7 @@ extern "C" {#define DRM_VMW_CREATE_EXTENDED_CONTEXT 26#define DRM_VMW_GB_SURFACE_CREATE_EXT 27#define DRM_VMW_GB_SURFACE_REF_EXT 28 +#define DRM_VMW_MSG 29/*************************************************************************/ /**
@@ -1213,6 +1214,22 @@ union drm_vmw_gb_surface_reference_ext_arg {struct drm_vmw_surface_arg req; }; +/** +* struct drm_vmw_msg_arg +* +* @send: Pointer to user-space msg string (null terminated). +* @receive: Pointer to user-space receive buffer. +* @send_only: Boolean whether this is only sending or receiving too. +* +* Argument to the DRM_VMW_MSG ioctl. +*/ +struct drm_vmw_msg_arg { +__u64 send; +__u64 receive; +__s32 send_only; +__u32 receive_len; +}; +#if defined(__cplusplus) }#endif
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/9 drm/vmwgfx: Bump driver minor version
In reply to Thomas Hellström (VMware)From: Thomas Hellstrom <[email protected]>
Bump driver minor version to signal availability of the host messaging ioctl.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +2 -2
@@ -56,9 +56,9 @@#define VMWGFX_DRIVER_NAME "vmwgfx" -#define VMWGFX_DRIVER_DATE "20190328" +#define VMWGFX_DRIVER_DATE "20200114"#define VMWGFX_DRIVER_MAJOR 2 -#define VMWGFX_DRIVER_MINOR 16 +#define VMWGFX_DRIVER_MINOR 17#define VMWGFX_DRIVER_PATCHLEVEL 0#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)#define VMWGFX_MAX_RELOCATIONS 2048
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel