summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/vmwgfx
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/vmwgfx')
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_bo.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c166
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.h4
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c208
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_gem.c17
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c55
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c6
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_msg.c21
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c1
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_shader.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c19
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_surface.c22
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_validation.h13
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c2
17 files changed, 443 insertions, 103 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index 9c7a73c0b0dc..a6d7156e4281 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -55,6 +55,8 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
/* Reserve and switch the backing mob. */
mutex_lock(&res->dev_priv->cmdbuf_mutex);
(void)vmw_resource_reserve(res, false, true);
+ /* TTM drops the reservation before calling the destructor. */
+ dma_resv_lock(bo->base.resv, NULL);
vmw_resource_mob_detach(res);
if (res->dirty)
res->func->dirty_free(res);
@@ -62,6 +64,7 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
vmw_bo_dirty_release(res->guest_memory_bo);
res->guest_memory_bo = NULL;
res->guest_memory_offset = 0;
+ dma_resv_unlock(bo->base.resv);
vmw_resource_unreserve(res, true, false, false, NULL,
0);
mutex_unlock(&res->dev_priv->cmdbuf_mutex);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c
index 5a69606a0593..b678e5b68db7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c
@@ -89,10 +89,26 @@ vmw_cursor_plane_update_legacy(struct vmw_private *vmw,
}
}
+static struct vmw_user_object
+vmw_cursor_plane_user_object(struct drm_framebuffer *fb)
+{
+ struct vmw_user_object uo = { 0 };
+
+ if (!fb)
+ return uo;
+
+ if (vmw_framebuffer_to_vfb(fb)->bo)
+ uo.buffer = vmw_framebuffer_to_vfbd(fb)->buffer;
+ else
+ uo = vmw_framebuffer_to_vfbs(fb)->uo;
+
+ return uo;
+}
+
static enum vmw_cursor_update_type
-vmw_cursor_update_type(struct vmw_private *vmw, struct vmw_plane_state *vps)
+vmw_cursor_update_type(struct vmw_private *vmw, struct vmw_user_object *uo)
{
- struct vmw_surface *surface = vmw_user_object_surface(&vps->uo);
+ struct vmw_surface *surface = vmw_user_object_surface(uo);
if (surface && surface->snooper.image)
return VMW_CURSOR_UPDATE_LEGACY;
@@ -112,8 +128,7 @@ static void vmw_cursor_update_mob(struct vmw_private *vmw,
{
SVGAGBCursorHeader *header;
SVGAGBAlphaCursorHeader *alpha_header;
- struct vmw_bo *bo = vmw_user_object_buffer(&vps->uo);
- u32 *image = vmw_bo_map_and_cache(bo);
+ u32 *image = vps->cursor.map.virtual;
const u32 image_size = vps->base.crtc_w * vps->base.crtc_h * sizeof(*image);
header = vmw_bo_map_and_cache(vps->cursor.mob);
@@ -132,7 +147,6 @@ static void vmw_cursor_update_mob(struct vmw_private *vmw,
memcpy(header + 1, image, image_size);
vmw_write(vmw, SVGA_REG_CURSOR_MOBID, vmw_bo_mobid(vps->cursor.mob));
- vmw_bo_unmap(bo);
vmw_bo_unmap(vps->cursor.mob);
}
@@ -152,10 +166,17 @@ static u32 vmw_cursor_mob_size(enum vmw_cursor_update_type update_type,
static void vmw_cursor_mob_destroy(struct vmw_bo **vbo)
{
+ int ret;
+
if (!(*vbo))
return;
+ ret = ttm_bo_reserve(&(*vbo)->tbo, false, false, NULL);
+ if (WARN_ON_ONCE(ret))
+ return;
+
ttm_bo_unpin(&(*vbo)->tbo);
+ ttm_bo_unreserve(&(*vbo)->tbo);
vmw_bo_unreference(vbo);
}
@@ -490,9 +511,21 @@ vmw_cursor_plane_cleanup_fb(struct drm_plane *plane,
{
struct vmw_cursor_plane *vcp = vmw_plane_to_vcp(plane);
struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state);
+ struct vmw_bo *bo;
+ int ret;
- if (!vmw_user_object_is_null(&vps->uo))
- vmw_user_object_unmap(&vps->uo);
+ if (vps->cursor.map.bo) {
+ bo = to_vmw_bo(&vps->cursor.map.bo->base);
+ ret = ttm_bo_reserve(&bo->tbo, false, false, NULL);
+ if (WARN_ON_ONCE(ret))
+ return;
+
+ ttm_bo_kunmap(&vps->cursor.map);
+ vps->cursor.map.bo = NULL;
+ ttm_bo_unpin(&bo->tbo);
+ ttm_bo_unreserve(&bo->tbo);
+ vmw_bo_unreference(&bo);
+ }
vmw_cursor_mob_unmap(vps);
vmw_cursor_mob_put(vcp, vps);
@@ -625,22 +658,17 @@ int vmw_cursor_plane_prepare_fb(struct drm_plane *plane,
struct vmw_surface *surface;
int ret = 0;
- if (!vmw_user_object_is_null(&vps->uo)) {
- vmw_user_object_unmap(&vps->uo);
+ /*
+ * A duplicated state only owns the user object reference. Its mappings
+ * and pins belong to the old state until cleanup_fb().
+ */
+ if (!vmw_user_object_is_null(&vps->uo))
vmw_user_object_unref(&vps->uo);
- }
- if (fb) {
- if (vmw_framebuffer_to_vfb(fb)->bo) {
- vps->uo.buffer = vmw_framebuffer_to_vfbd(fb)->buffer;
- vps->uo.surface = NULL;
- } else {
- memcpy(&vps->uo, &vmw_framebuffer_to_vfbs(fb)->uo, sizeof(vps->uo));
- }
- vmw_user_object_ref(&vps->uo);
- }
+ vps->uo = vmw_cursor_plane_user_object(fb);
+ vmw_user_object_ref(&vps->uo);
- vps->cursor.update_type = vmw_cursor_update_type(vmw, vps);
+ vps->cursor.update_type = vmw_cursor_update_type(vmw, &vps->uo);
switch (vps->cursor.update_type) {
case VMW_CURSOR_UPDATE_LEGACY:
surface = vmw_user_object_surface(&vps->uo);
@@ -650,33 +678,39 @@ int vmw_cursor_plane_prepare_fb(struct drm_plane *plane,
case VMW_CURSOR_UPDATE_GB_ONLY:
case VMW_CURSOR_UPDATE_MOB: {
bo = vmw_user_object_buffer(&vps->uo);
+ if (fb && !bo)
+ return -EINVAL;
+
if (bo) {
struct ttm_operation_ctx ctx = { false, false };
+ size_t size = (size_t)new_state->crtc_w *
+ new_state->crtc_h * sizeof(u32);
ret = ttm_bo_reserve(&bo->tbo, true, false, NULL);
if (ret != 0)
- return -ENOMEM;
+ return ret;
ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
if (ret != 0)
- return -ENOMEM;
+ goto out_unreserve;
/*
- * vmw_bo_pin_reserved also validates, so to skip
- * the extra validation use ttm_bo_pin directly
+ * vmw_bo_pin_reserved() also validates, so to skip
+ * the extra validation use ttm_bo_pin directly.
+ * Every state takes its own pin, the buffer can
+ * still be in use by an older state whose commit
+ * hasn't been cleaned up yet.
*/
- if (!bo->tbo.pin_count)
- ttm_bo_pin(&bo->tbo);
-
- if (vmw_framebuffer_to_vfb(fb)->bo) {
- const u32 size = new_state->crtc_w *
- new_state->crtc_h *
- sizeof(u32);
-
- (void)vmw_bo_map_and_cache_size(bo, size);
- } else {
- vmw_bo_map_and_cache(bo);
+ ttm_bo_pin(&bo->tbo);
+
+ ret = ttm_bo_kmap(&bo->tbo, 0, PFN_UP(size),
+ &vps->cursor.map);
+ if (ret) {
+ vps->cursor.map.bo = NULL;
+ ttm_bo_unpin(&bo->tbo);
+ goto out_unreserve;
}
+ vmw_bo_reference(bo);
ttm_bo_unreserve(&bo->tbo);
}
if (!vmw_user_object_is_null(&vps->uo)) {
@@ -703,6 +737,10 @@ int vmw_cursor_plane_prepare_fb(struct drm_plane *plane,
}
return 0;
+
+out_unreserve:
+ ttm_bo_unreserve(&bo->tbo);
+ return ret;
}
/**
@@ -725,7 +763,7 @@ int vmw_cursor_plane_atomic_check(struct drm_plane *plane,
int ret = 0;
struct drm_crtc_state *crtc_state = NULL;
struct vmw_surface *surface = NULL;
- struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
+ struct vmw_user_object uo;
enum vmw_cursor_update_type update_type;
struct drm_framebuffer *fb = new_state->fb;
@@ -744,7 +782,21 @@ int vmw_cursor_plane_atomic_check(struct drm_plane *plane,
if (!fb)
return 0;
- update_type = vmw_cursor_update_type(vmw, vps);
+ if (!new_state->crtc_w || !new_state->crtc_h) {
+ drm_dbg_kms(&vmw->drm,
+ "Cursor dimensions (%u, %u) must be nonzero\n",
+ new_state->crtc_w, new_state->crtc_h);
+ return -EINVAL;
+ }
+
+ /* The duplicated plane state's user object still belongs to the old FB. */
+ uo = vmw_cursor_plane_user_object(fb);
+ update_type = vmw_cursor_update_type(vmw, &uo);
+ if ((update_type == VMW_CURSOR_UPDATE_GB_ONLY ||
+ update_type == VMW_CURSOR_UPDATE_MOB) &&
+ !vmw_user_object_buffer(&uo))
+ return -EINVAL;
+
if (update_type == VMW_CURSOR_UPDATE_LEGACY) {
if (new_state->crtc_w != VMW_CURSOR_SNOOP_WIDTH ||
new_state->crtc_h != VMW_CURSOR_SNOOP_HEIGHT) {
@@ -753,14 +805,32 @@ int vmw_cursor_plane_atomic_check(struct drm_plane *plane,
new_state->crtc_w, new_state->crtc_h);
return -EINVAL;
}
- surface = vmw_user_object_surface(&vps->uo);
+ surface = vmw_user_object_surface(&uo);
if (!surface || !surface->snooper.image) {
drm_warn(&vmw->drm,
"surface not suitable for cursor\n");
return -EINVAL;
}
- } else if (update_type == VMW_CURSOR_UPDATE_GB_ONLY ||
- update_type == VMW_CURSOR_UPDATE_MOB) {
+ } else if (update_type == VMW_CURSOR_UPDATE_GB_ONLY) {
+ u64 image_size = (u64)new_state->crtc_w *
+ new_state->crtc_h * sizeof(u32);
+ u32 max_size = SVGA_MAX_CURSOR_CMD_BYTES;
+
+ /* The command-buffer limit includes the define-cursor header. */
+ if (vmw->cman)
+ max_size = min_t(u32, max_size,
+ SVGA_CB_MAX_COMMAND_SIZE -
+ sizeof(struct vmw_svga_fifo_cmd_define_cursor));
+
+ if (new_state->crtc_w > SVGA_MAX_CURSOR_CMD_DIMENSION ||
+ new_state->crtc_h > SVGA_MAX_CURSOR_CMD_DIMENSION ||
+ image_size > max_size) {
+ drm_dbg_kms(&vmw->drm,
+ "Cursor dimensions (%u, %u) violate command limits\n",
+ new_state->crtc_w, new_state->crtc_h);
+ return -EINVAL;
+ }
+ } else if (update_type == VMW_CURSOR_UPDATE_MOB) {
u32 cursor_max_dim =
vmw_read(vmw, SVGA_REG_CURSOR_MAX_DIMENSION);
@@ -796,7 +866,6 @@ void
vmw_cursor_plane_atomic_update(struct drm_plane *plane,
struct drm_atomic_commit *state)
{
- struct vmw_bo *bo;
struct drm_plane_state *new_state =
drm_atomic_get_new_plane_state(state, plane);
struct drm_plane_state *old_state =
@@ -815,6 +884,10 @@ vmw_cursor_plane_atomic_update(struct drm_plane *plane,
return;
}
+ /* Include legacy Xorg cursor-bypass offsets in the image and position. */
+ hotspot_x = vps->cursor.legacy.hotspot_x + new_state->hotspot_x;
+ hotspot_y = vps->cursor.legacy.hotspot_y + new_state->hotspot_y;
+
switch (vps->cursor.update_type) {
case VMW_CURSOR_UPDATE_LEGACY:
vmw_cursor_plane_update_legacy(dev_priv, vps);
@@ -823,13 +896,11 @@ vmw_cursor_plane_atomic_update(struct drm_plane *plane,
vmw_cursor_update_mob(dev_priv, vps);
break;
case VMW_CURSOR_UPDATE_GB_ONLY:
- bo = vmw_user_object_buffer(&vps->uo);
- if (bo)
- vmw_send_define_cursor_cmd(dev_priv, bo->map.virtual,
+ if (vps->cursor.map.virtual)
+ vmw_send_define_cursor_cmd(dev_priv, vps->cursor.map.virtual,
vps->base.crtc_w,
vps->base.crtc_h,
- vps->base.hotspot_x,
- vps->base.hotspot_y);
+ hotspot_x, hotspot_y);
break;
case VMW_CURSOR_UPDATE_NONE:
/* do nothing */
@@ -842,9 +913,6 @@ vmw_cursor_plane_atomic_update(struct drm_plane *plane,
cursor_x = new_state->crtc_x + du->set_gui_x;
cursor_y = new_state->crtc_y + du->set_gui_y;
- hotspot_x = vps->cursor.legacy.hotspot_x + new_state->hotspot_x;
- hotspot_y = vps->cursor.legacy.hotspot_y + new_state->hotspot_y;
-
vmw_cursor_update_position(dev_priv, true, cursor_x + hotspot_x,
cursor_y + hotspot_y);
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.h b/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.h
index d32cf17d013b..9b50f80f9635 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.h
@@ -14,6 +14,8 @@
#include "drm/drm_fourcc.h"
#include "drm/drm_plane.h"
+#include <drm/ttm/ttm_bo.h>
+
#include <linux/types.h>
struct SVGA3dCmdHeader;
@@ -41,6 +43,8 @@ struct vmw_cursor_plane_state {
enum vmw_cursor_update_type update_type;
bool changed;
bool surface_changed;
+ /* The mapped buffer is referenced and pinned by this state. */
+ struct ttm_bo_kmap_obj map;
struct vmw_bo *mob;
struct {
s32 hotspot_x;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index a9136a6523cb..435425f1adfa 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -565,6 +565,29 @@ static int vmw_cmd_ok(struct vmw_private *dev_priv,
}
/**
+ * vmw_cmd_body_fits - Check that a command body covers what a handler reads
+ *
+ * @header: Pointer to the command header in the command stream.
+ * @size: Number of body bytes that the command handler interprets.
+ *
+ * vmw_cmd_check() only verifies that @header->size fits into the submitted
+ * command buffer. A handler that reads past the declared body reads the next
+ * command, which is verified separately. A relocation recorded there would
+ * rewrite the already verified command after verification has finished.
+ *
+ * Return: true if the body is at least @size bytes, false otherwise.
+ */
+static bool vmw_cmd_body_fits(const SVGA3dCmdHeader *header, size_t size)
+{
+ if (likely(header->size >= size))
+ return true;
+
+ VMW_DEBUG_USER("SVGA3D command %u: body size %u is smaller than %zu.\n",
+ header->id, header->size, size);
+ return false;
+}
+
+/**
* vmw_resources_reserve - Reserve all resources on the sw_context's resource
* list.
*
@@ -810,6 +833,9 @@ static int vmw_cmd_cid_check(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, uint32_t) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET, user_context_converter,
&cmd->body, NULL);
@@ -853,6 +879,8 @@ static int vmw_cmd_set_render_target_check(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
if (cmd->body.type >= SVGA3D_RT_MAX) {
VMW_DEBUG_USER("Illegal render target type %u.\n",
@@ -898,6 +926,8 @@ static int vmw_cmd_surface_copy_check(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
@@ -918,6 +948,9 @@ static int vmw_cmd_buffer_copy_check(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.src, NULL);
@@ -937,6 +970,9 @@ static int vmw_cmd_pred_copy_check(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.srcSid, NULL);
@@ -956,6 +992,9 @@ static int vmw_cmd_stretch_blt_check(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.src.sid, NULL);
@@ -974,6 +1013,9 @@ static int vmw_cmd_blt_surf_screen_check(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBlitSurfaceToScreen) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.srcImage.sid, NULL);
@@ -986,6 +1028,9 @@ static int vmw_cmd_present_check(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdPresent) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.sid, NULL);
@@ -1243,6 +1288,8 @@ static int vmw_cmd_dx_define_query(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
if (cmd->body.type < SVGA3D_QUERYTYPE_MIN ||
cmd->body.type >= SVGA3D_QUERYTYPE_MAX)
@@ -1280,6 +1327,8 @@ static int vmw_cmd_dx_bind_query(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
/*
* Look up the buffer pointed to by q.mobid, put it on the relocation
@@ -1310,6 +1359,9 @@ static int vmw_cmd_begin_gb_query(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBeginGBQuery) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET, user_context_converter,
&cmd->body.cid, NULL);
@@ -1329,6 +1381,9 @@ static int vmw_cmd_begin_query(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBeginQuery) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (unlikely(dev_priv->has_mob)) {
VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdBeginGBQuery);
@@ -1364,6 +1419,9 @@ static int vmw_cmd_end_gb_query(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
if (unlikely(ret != 0))
return ret;
@@ -1394,6 +1452,9 @@ static int vmw_cmd_end_query(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (dev_priv->has_mob) {
VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdEndGBQuery);
@@ -1440,6 +1501,9 @@ static int vmw_cmd_wait_gb_query(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
if (unlikely(ret != 0))
return ret;
@@ -1468,6 +1532,9 @@ static int vmw_cmd_wait_query(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (dev_priv->has_mob) {
VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdWaitForGBQuery);
@@ -1637,6 +1704,15 @@ static int vmw_cmd_tex_state(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
+ /* The loop below must not read a truncated trailing state. */
+ if ((header->size - sizeof(cmd->body)) % sizeof(*cur_state)) {
+ VMW_DEBUG_USER("Invalid texture state size %u.\n",
+ header->size);
+ return -EINVAL;
+ }
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET, user_context_converter,
@@ -1718,6 +1794,7 @@ static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv,
{
struct vmw_bo *vbo;
void *info;
+ u64 end;
int ret;
info = vmw_execbuf_info_from_res(sw_context, res);
@@ -1728,6 +1805,13 @@ static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv,
if (ret)
return ret;
+ if (check_add_overflow((u64)backup_offset,
+ (u64)res->guest_memory_size, &end) ||
+ end > vbo->tbo.base.size) {
+ VMW_DEBUG_USER("Backup buffer too small for resource.\n");
+ return -EINVAL;
+ }
+
vmw_validation_res_switch_backup(sw_context->ctx, info, vbo,
backup_offset);
return 0;
@@ -1782,6 +1866,9 @@ static int vmw_cmd_bind_gb_surface(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBindGBSurface) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_surface,
user_surface_converter, &cmd->body.sid,
&cmd->body.mobid, 0);
@@ -1801,6 +1888,9 @@ static int vmw_cmd_update_gb_image(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdUpdateGBImage) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.image.sid, NULL);
@@ -1820,6 +1910,9 @@ static int vmw_cmd_update_gb_surface(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdUpdateGBSurface) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_CLEAR, user_surface_converter,
&cmd->body.sid, NULL);
@@ -1839,6 +1932,9 @@ static int vmw_cmd_readback_gb_image(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdReadbackGBImage) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.image.sid, NULL);
@@ -1859,6 +1955,9 @@ static int vmw_cmd_readback_gb_surface(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdReadbackGBSurface) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_CLEAR, user_surface_converter,
&cmd->body.sid, NULL);
@@ -1879,6 +1978,9 @@ static int vmw_cmd_invalidate_gb_image(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdInvalidateGBImage) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.image.sid, NULL);
@@ -1899,6 +2001,9 @@ static int vmw_cmd_invalidate_gb_surface(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdInvalidateGBSurface) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_CLEAR, user_surface_converter,
&cmd->body.sid, NULL);
@@ -1921,6 +2026,8 @@ static int vmw_cmd_shader_define(struct vmw_private *dev_priv,
struct vmw_resource *ctx;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET, user_context_converter,
@@ -1960,6 +2067,8 @@ static int vmw_cmd_shader_destroy(struct vmw_private *dev_priv,
struct vmw_resource *ctx;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET, user_context_converter,
@@ -1999,6 +2108,8 @@ static int vmw_cmd_set_shader(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
if (!vmw_shadertype_is_valid(VMW_SM_LEGACY, cmd->body.type)) {
VMW_DEBUG_USER("Illegal shader type %u.\n",
@@ -2077,6 +2188,8 @@ static int vmw_cmd_set_shader_const(struct vmw_private *dev_priv,
int ret;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET, user_context_converter,
@@ -2104,6 +2217,9 @@ static int vmw_cmd_bind_gb_shader(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBindGBShader) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_shader,
user_shader_converter, &cmd->body.shid,
&cmd->body.mobid, cmd->body.offsetInBytes);
@@ -2133,6 +2249,9 @@ vmw_cmd_dx_set_single_constant_buffer(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.sid, &res);
@@ -2186,6 +2305,9 @@ vmw_cmd_dx_set_constant_buffer_offset(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (cmd->body.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
VMW_DEBUG_USER("Illegal const buffer slot %u.\n",
(unsigned int) cmd->body.slot);
@@ -2217,6 +2339,9 @@ static int vmw_cmd_dx_set_shader_res(struct vmw_private *dev_priv,
u32 num_sr_view = (cmd->header.size - sizeof(cmd->body)) /
sizeof(SVGA3dShaderResourceViewId);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if ((u64) cmd->body.startView + (u64) num_sr_view >
(u64) SVGA3D_DX_MAX_SRVIEWS ||
!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
@@ -2252,6 +2377,8 @@ static int vmw_cmd_dx_set_shader(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
VMW_DEBUG_USER("Illegal shader type %u.\n",
@@ -2309,6 +2436,9 @@ static int vmw_cmd_dx_set_vertex_buffers(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
num = (cmd->header.size - sizeof(cmd->body)) /
sizeof(SVGA3dVertexBuffer);
if ((u64)num + (u64)cmd->body.startBuffer >
@@ -2360,6 +2490,9 @@ static int vmw_cmd_dx_set_index_buffer(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.sid, &res);
@@ -2395,6 +2528,9 @@ static int vmw_cmd_dx_set_rendertargets(struct vmw_private *dev_priv,
sizeof(SVGA3dRenderTargetViewId);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (num_rt_view > SVGA3D_DX_MAX_RENDER_TARGETS) {
VMW_DEBUG_USER("Invalid DX Rendertarget binding.\n");
return -EINVAL;
@@ -2426,6 +2562,9 @@ static int vmw_cmd_dx_clear_rendertarget_view(struct vmw_private *dev_priv,
container_of(header, typeof(*cmd), header);
struct vmw_resource *ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_view_id_val_add(sw_context, vmw_view_rt,
cmd->body.renderTargetViewId);
@@ -2448,6 +2587,9 @@ static int vmw_cmd_dx_clear_depthstencil_view(struct vmw_private *dev_priv,
container_of(header, typeof(*cmd), header);
struct vmw_resource *ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_view_id_val_add(sw_context, vmw_view_ds,
cmd->body.depthStencilViewId);
@@ -2481,6 +2623,9 @@ static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(*cmd) - sizeof(*header)))
+ return -EINVAL;
+
if (unlikely(cmd->sid == SVGA3D_INVALID_ID)) {
VMW_DEBUG_USER("Invalid surface id.\n");
return -EINVAL;
@@ -2529,6 +2674,9 @@ static int vmw_cmd_dx_set_so_targets(struct vmw_private *dev_priv,
return -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
num = (cmd->header.size - sizeof(cmd->body)) / sizeof(SVGA3dSoTarget);
if (num > SVGA3D_DX_MAX_SOTARGETS) {
@@ -2582,6 +2730,9 @@ static int vmw_cmd_dx_so_define(struct vmw_private *dev_priv,
if (IS_ERR_OR_NULL(res))
return res ? PTR_ERR(res) : -EINVAL;
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(*cmd) - sizeof(*header)))
+ return -EINVAL;
+
ret = vmw_cotable_notify(res, cmd->defined_id);
return ret;
@@ -2617,6 +2768,9 @@ static int vmw_cmd_dx_check_subresource(struct vmw_private *dev_priv,
offsetof(typeof(*cmd), sid));
cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->sid)))
+ return -EINVAL;
+
return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->sid, NULL);
@@ -2658,6 +2812,9 @@ static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv,
struct vmw_resource *view;
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!ctx_node)
return -EINVAL;
@@ -2695,6 +2852,9 @@ static int vmw_cmd_dx_define_shader(struct vmw_private *dev_priv,
container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!ctx_node)
return -EINVAL;
@@ -2726,6 +2886,9 @@ static int vmw_cmd_dx_destroy_shader(struct vmw_private *dev_priv,
container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!ctx_node)
return -EINVAL;
@@ -2752,6 +2915,9 @@ static int vmw_cmd_dx_bind_shader(struct vmw_private *dev_priv,
container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (cmd->body.cid != SVGA3D_INVALID_ID) {
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
VMW_RES_DIRTY_SET,
@@ -2803,6 +2969,9 @@ static int vmw_cmd_dx_genmips(struct vmw_private *dev_priv,
struct vmw_resource *view;
struct vmw_res_cache_entry *rcache;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
view = vmw_view_id_val_add(sw_context, vmw_view_sr,
cmd->body.shaderResourceViewId);
if (IS_ERR(view))
@@ -2836,6 +3005,9 @@ static int vmw_cmd_dx_transfer_from_buffer(struct vmw_private *dev_priv,
container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
VMW_RES_DIRTY_NONE, user_surface_converter,
&cmd->body.srcSid, NULL);
@@ -2861,6 +3033,9 @@ static int vmw_cmd_intra_surface_copy(struct vmw_private *dev_priv,
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdIntraSurfaceCopy) =
container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!(dev_priv->capabilities2 & SVGA_CAP2_INTRA_SURFACE_COPY))
return -EINVAL;
@@ -2909,6 +3084,9 @@ static int vmw_cmd_clear_uav_uint(struct vmw_private *dev_priv,
} *cmd = container_of(header, typeof(*cmd), header);
struct vmw_resource *ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -2928,6 +3106,9 @@ static int vmw_cmd_clear_uav_float(struct vmw_private *dev_priv,
} *cmd = container_of(header, typeof(*cmd), header);
struct vmw_resource *ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -2949,6 +3130,9 @@ static int vmw_cmd_set_uav(struct vmw_private *dev_priv,
sizeof(SVGA3dUAViewId);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -2981,6 +3165,9 @@ static int vmw_cmd_set_cs_uav(struct vmw_private *dev_priv,
sizeof(SVGA3dUAViewId);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -3013,6 +3200,9 @@ static int vmw_cmd_dx_define_streamoutput(struct vmw_private *dev_priv,
} *cmd = container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -3044,6 +3234,9 @@ static int vmw_cmd_dx_destroy_streamoutput(struct vmw_private *dev_priv,
SVGA3dCmdDXDestroyStreamOutput body;
} *cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!ctx_node) {
DRM_ERROR("DX Context not set.\n");
return -EINVAL;
@@ -3081,6 +3274,9 @@ static int vmw_cmd_dx_bind_streamoutput(struct vmw_private *dev_priv,
} *cmd = container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -3123,6 +3319,9 @@ static int vmw_cmd_dx_set_streamoutput(struct vmw_private *dev_priv,
} *cmd = container_of(header, typeof(*cmd), header);
int ret;
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!ctx_node) {
DRM_ERROR("DX Context not set.\n");
return -EINVAL;
@@ -3175,6 +3374,9 @@ static int vmw_cmd_indexed_instanced_indirect(struct vmw_private *dev_priv,
SVGA3dCmdDXDrawIndexedInstancedIndirect body;
} *cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -3192,6 +3394,9 @@ static int vmw_cmd_instanced_indirect(struct vmw_private *dev_priv,
SVGA3dCmdDXDrawInstancedIndirect body;
} *cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
@@ -3209,6 +3414,9 @@ static int vmw_cmd_dispatch_indirect(struct vmw_private *dev_priv,
SVGA3dCmdDXDispatchIndirect body;
} *cmd = container_of(header, typeof(*cmd), header);
+ if (!vmw_cmd_body_fits(header, sizeof(cmd->body)))
+ return -EINVAL;
+
if (!has_sm5_context(dev_priv))
return -EINVAL;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
index 39f8c46550c2..2969b74fff17 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
@@ -73,10 +73,13 @@ static struct sg_table *vmw_gem_object_get_sg_table(struct drm_gem_object *obj)
struct vmw_ttm_tt *vmw_tt =
container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm);
- if (vmw_tt->vsgt.sgt)
- return vmw_tt->vsgt.sgt;
-
- return drm_prime_pages_to_sg(obj->dev, vmw_tt->dma_ttm.pages, vmw_tt->dma_ttm.num_pages);
+ /*
+ * Do not return &vmw_tt->sgt: the core owns what this returns and
+ * drm_gem_unmap_dma_buf() sg_free_table()s and kfree()s it, but that
+ * sg_table is embedded in the vmw_ttm_tt allocation.
+ */
+ return drm_prime_pages_to_sg(obj->dev, vmw_tt->dma_ttm.pages,
+ vmw_tt->dma_ttm.num_pages);
}
static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
@@ -184,7 +187,7 @@ struct drm_gem_object *vmw_prime_import_sg_table(struct drm_device *dev,
{
int ret;
struct vmw_private *dev_priv = vmw_priv(dev);
- struct drm_gem_object *gem = NULL;
+ struct drm_gem_object *gem;
struct vmw_bo *vbo;
struct vmw_bo_params params = {
.domain = (dev_priv->has_mob) ? VMW_BO_DOMAIN_SYS : VMW_BO_DOMAIN_VRAM,
@@ -201,8 +204,10 @@ struct drm_gem_object *vmw_prime_import_sg_table(struct drm_device *dev,
dma_resv_lock(params.resv, NULL);
ret = vmw_bo_create(dev_priv, &params, &vbo);
- if (ret != 0)
+ if (ret != 0) {
+ gem = ERR_PTR(ret);
goto out_no_bo;
+ }
vbo->tbo.base.funcs = &vmw_gem_object_funcs;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index d607452dff6a..cc580ce57797 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -54,8 +54,11 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
const struct ttm_place *place,
struct ttm_resource **res)
{
+ struct vmw_private *vmw = vmw_priv_from_ttm(bo->bdev);
struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
- int id;
+ u32 max_gmr_pages = 0;
+ bool mob_overflow = false;
+ int id, ret = 0;
*res = kmalloc_obj(**res);
if (!*res)
@@ -85,43 +88,53 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
const unsigned long max_graphics_pages = totalram_pages() / 2;
uint32_t new_max_pages = 0;
- DRM_WARN("vmwgfx: mob memory overflow. Consider increasing guest RAM and graphicsMemory.\n");
- vmw_host_printf("vmwgfx, warning: mob memory overflow. Consider increasing guest RAM and graphicsMemory.\n");
+ mob_overflow = true;
+ drm_warn(&vmw->drm,
+ "vmwgfx: mob memory overflow. Consider increasing guest RAM and graphicsMemory.\n");
if (gman->max_gmr_pages > (max_graphics_pages / 2)) {
- DRM_WARN("vmwgfx: guest requires more than half of RAM for graphics.\n");
+ drm_warn(&vmw->drm,
+ "vmwgfx: guest requires more than half of RAM for graphics.\n");
new_max_pages = max_graphics_pages;
} else
new_max_pages = gman->max_gmr_pages * 2;
if (new_max_pages > gman->max_gmr_pages && new_max_pages >= gman->used_gmr_pages) {
- DRM_WARN("vmwgfx: increasing guest mob limits to %u KiB.\n",
- ((new_max_pages) << (PAGE_SHIFT - 10)));
+ drm_warn(&vmw->drm,
+ "vmwgfx: increasing guest mob limits to %u KiB.\n",
+ new_max_pages << (PAGE_SHIFT - 10));
gman->max_gmr_pages = new_max_pages;
} else {
- char buf[256];
- snprintf(buf, sizeof(buf),
- "vmwgfx, error: guest graphics is out of memory (mob limit at: %u KiB).\n",
- ((gman->max_gmr_pages) << (PAGE_SHIFT - 10)));
- vmw_host_printf(buf);
- DRM_WARN("%s", buf);
- goto nospace;
+ max_gmr_pages = gman->max_gmr_pages;
+ gman->used_gmr_pages -= PFN_UP((*res)->size);
+ ret = -ENOSPC;
+ goto out_unlock;
}
}
}
(*res)->start = id;
+out_unlock:
spin_unlock(&gman->lock);
- return 0;
-nospace:
- gman->used_gmr_pages -= PFN_UP((*res)->size);
- spin_unlock(&gman->lock);
- ida_free(&gman->gmr_ida, id);
- ttm_resource_fini(man, *res);
- kfree(*res);
- return -ENOSPC;
+ /* Host logging allocates with GFP_KERNEL and must run unlocked. */
+ if (mob_overflow)
+ vmw_host_printf("%s",
+ "vmwgfx, warning: mob memory overflow. Consider increasing guest RAM and graphicsMemory.\n");
+ if (ret) {
+ char buf[256];
+
+ snprintf(buf, sizeof(buf),
+ "vmwgfx, error: guest graphics is out of memory (mob limit at: %u KiB).\n",
+ max_gmr_pages << (PAGE_SHIFT - 10));
+ vmw_host_printf("%s", buf);
+ drm_warn(&vmw->drm, "%s", buf);
+ ida_free(&gman->gmr_ida, id);
+ ttm_resource_fini(man, *res);
+ kfree(*res);
+ }
+ return ret;
}
static void vmw_gmrid_man_put_node(struct ttm_resource_manager *man,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index a6c3304e1a67..fed844ccd789 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -155,9 +155,8 @@ int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
* some actual rendering so give a clue as why it's blank.
*/
if (new_state->enable && !has_primary)
- drm_dbg_driver(&vmw->drm,
- "CRTC without a primary plane will be blank.\n");
-
+ drm_info_once(&vmw->drm,
+ "CRTC without a primary plane will be blank.\n");
if (new_state->connector_mask != connector_mask &&
new_state->connector_mask != 0) {
@@ -275,6 +274,7 @@ vmw_du_plane_duplicate_state(struct drm_plane *plane)
vps->cpp = 0;
vps->cursor.mob = NULL;
+ memset(&vps->cursor.map, 0, sizeof(vps->cursor.map));
/* Each ref counted resource needs to be acquired again */
vmw_user_object_ref(&vps->uo);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index b147f5db9df5..a7828b8ed68e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -33,7 +33,7 @@
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_fourcc.h>
-
+#include <drm/drm_vblank_helper.h>
#define vmw_crtc_to_ldu(x) \
container_of(x, struct vmw_legacy_display_unit, base.crtc)
@@ -256,6 +256,7 @@ static const struct drm_crtc_funcs vmw_legacy_crtc_funcs = {
.page_flip = drm_atomic_helper_page_flip,
.enable_vblank = vmw_vkms_enable_vblank,
.disable_vblank = vmw_vkms_disable_vblank,
+ .sync_vblank = drm_crtc_vblank_helper_sync_vblank_timer,
.get_vblank_timestamp = vmw_vkms_get_vblank_timestamp,
};
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
index fd77ab6568cb..58da332486bd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
@@ -431,7 +431,7 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
/* Remove reply code, which are the first 2 characters of
* the reply
*/
- reply_len = max(reply_len - 2, (size_t) 0);
+ reply_len = reply_len > 2 ? reply_len - 2 : 0;
reply_len = min(reply_len, *length);
if (reply_len > 0)
@@ -939,9 +939,12 @@ int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
struct vmw_private *const dev_priv = vmw_priv(dev);
- const size_t num_pages_stat = PFN_UP(arg->stat_len);
- const size_t num_pages_info = PFN_UP(arg->info_len);
- const size_t num_pages_strs = PFN_UP(arg->strs_len);
+ const u64 max_stat_len = (u64)MKS_GUEST_STAT_INSTANCE_MAX_STAT_PPNS * PAGE_SIZE;
+ const u64 max_info_len = (u64)MKS_GUEST_STAT_INSTANCE_MAX_INFO_PPNS * PAGE_SIZE;
+ const u64 max_strs_len = (u64)MKS_GUEST_STAT_INSTANCE_MAX_STRS_PPNS * PAGE_SIZE;
+ size_t num_pages_stat;
+ size_t num_pages_info;
+ size_t num_pages_strs;
long desc_len;
long nr_pinned_stat;
long nr_pinned_info;
@@ -965,11 +968,15 @@ int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
if (!arg->description)
return -EINVAL;
- if (num_pages_stat > ARRAY_SIZE(pdesc->statPPNs) ||
- num_pages_info > ARRAY_SIZE(pdesc->infoPPNs) ||
- num_pages_strs > ARRAY_SIZE(pdesc->strsPPNs))
+ if (arg->stat_len > max_stat_len ||
+ arg->info_len > max_info_len ||
+ arg->strs_len > max_strs_len)
return -EINVAL;
+ num_pages_stat = PFN_UP(arg->stat_len);
+ num_pages_info = PFN_UP(arg->info_len);
+ num_pages_strs = PFN_UP(arg->strs_len);
+
/* Find an available slot in the mksGuestStats user array and reserve it */
for (slot = 0; slot < ARRAY_SIZE(dev_priv->mksstat_user_pids); ++slot)
if (!atomic_cmpxchg(&dev_priv->mksstat_user_pids[slot], 0, MKSSTAT_PID_RESERVED))
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index e3a187a2c7a1..ad13688bd7da 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -138,6 +138,7 @@ static void vmw_resource_release(struct kref *kref)
}
res->guest_memory_dirty = false;
vmw_resource_mob_detach(res);
+ vmw_bo_del_detached_resource(res->guest_memory_bo, res);
if (res->dirty)
res->func->dirty_free(res);
if (res->coherent)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
index 89714d5c235b..bc6c200f5129 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
@@ -35,6 +35,7 @@
#include <drm/drm_damage_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_vblank.h>
+#include <drm/drm_vblank_helper.h>
#define vmw_crtc_to_sou(x) \
container_of(x, struct vmw_screen_object_unit, base.crtc)
@@ -312,6 +313,7 @@ static const struct drm_crtc_funcs vmw_screen_object_crtc_funcs = {
.page_flip = drm_atomic_helper_page_flip,
.enable_vblank = vmw_vkms_enable_vblank,
.disable_vblank = vmw_vkms_disable_vblank,
+ .sync_vblank = drm_crtc_vblank_helper_sync_vblank_timer,
.get_vblank_timestamp = vmw_vkms_get_vblank_timestamp,
};
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
index 39811cf19db1..033157efb1fc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
@@ -597,7 +597,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
if (!vmw_shader_id_ok(user_key, shader_type))
return -EINVAL;
- shader = kmalloc_obj(*shader);
+ shader = kzalloc_obj(*shader);
if (!shader) {
return -ENOMEM;
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
index cbf55084110a..08b32babc1cd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
@@ -37,6 +37,7 @@
#include <drm/drm_damage_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_vblank.h>
+#include <drm/drm_vblank_helper.h>
#define vmw_crtc_to_stdu(x) \
container_of(x, struct vmw_screen_target_display_unit, base.crtc)
@@ -44,6 +45,8 @@
container_of(x, struct vmw_screen_target_display_unit, base.encoder)
#define vmw_connector_to_stdu(x) \
container_of(x, struct vmw_screen_target_display_unit, base.connector)
+#define vmw_primary_to_stdu(x) \
+ container_of(x, struct vmw_screen_target_display_unit, base.primary)
/*
* Some renderers such as llvmpipe will align the width and height of their
@@ -448,6 +451,13 @@ static void vmw_stdu_crtc_atomic_disable(struct drm_crtc *crtc,
!new_crtc_state->mode_changed)
return;
+ /* Never destroy DU 0's ST so that the VM client always has a
+ * window to accept input from. Otherwise we may never receive
+ * input to wake the VM when the CRTC is disabled during idle.
+ */
+ if (stdu->base.unit == 0)
+ return;
+
ret = vmw_stdu_destroy_st(dev_priv, stdu);
if (ret)
DRM_ERROR("Failed to destroy Screen Target\n");
@@ -785,6 +795,7 @@ static const struct drm_crtc_funcs vmw_stdu_crtc_funcs = {
.page_flip = drm_atomic_helper_page_flip,
.enable_vblank = vmw_vkms_enable_vblank,
.disable_vblank = vmw_vkms_disable_vblank,
+ .sync_vblank = drm_crtc_vblank_helper_sync_vblank_timer,
.get_vblank_timestamp = vmw_vkms_get_vblank_timestamp,
.get_crc_sources = vmw_vkms_get_crc_sources,
.set_crc_source = vmw_vkms_set_crc_source,
@@ -1411,7 +1422,8 @@ vmw_stdu_primary_plane_atomic_update(struct drm_plane *plane,
int ret;
/* If case of device error, maintain consistent atomic state */
- if (crtc && new_state->fb) {
+ if (crtc && new_state->fb &&
+ drm_atomic_get_new_crtc_state(state, crtc)->active) {
struct vmw_framebuffer *vfb =
vmw_framebuffer_to_vfb(new_state->fb);
stdu = vmw_crtc_to_stdu(crtc);
@@ -1435,9 +1447,8 @@ vmw_stdu_primary_plane_atomic_update(struct drm_plane *plane,
if (ret)
DRM_ERROR("Failed to update STDU.\n");
} else {
- crtc = old_state->crtc;
- stdu = vmw_crtc_to_stdu(crtc);
- dev_priv = vmw_priv(crtc->dev);
+ stdu = vmw_primary_to_stdu(plane);
+ dev_priv = vmw_priv(plane->dev);
/* Blank STDU when fb and crtc are NULL */
if (!stdu->defined)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c b/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c
index 52c6cfa163da..34d5b71fa42f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c
@@ -284,7 +284,7 @@ int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
struct vmw_private *dev_priv = ctx->dev_priv;
int ret;
- so = kmalloc_obj(*so);
+ so = kzalloc_obj(*so);
if (!so) {
return -ENOMEM;
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index bd0563741e89..3064a2a960e1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -1718,22 +1718,32 @@ vmw_gb_surface_reference_internal(struct drm_device *dev,
user_srf = container_of(base, struct vmw_user_surface, prime.base);
srf = &user_srf->srf;
+ metadata = &srf->metadata;
+
+ mutex_lock(&dev_priv->cmdbuf_mutex);
+
if (!srf->res.guest_memory_bo) {
+ mutex_unlock(&dev_priv->cmdbuf_mutex);
DRM_ERROR("Shared GB surface is missing a backup buffer.\n");
+ ret = -EINVAL;
goto out_bad_resource;
}
- metadata = &srf->metadata;
- mutex_lock(&dev_priv->cmdbuf_mutex); /* Protect res->backup */
ret = drm_gem_handle_create(file_priv, &srf->res.guest_memory_bo->tbo.base,
&backup_handle);
- mutex_unlock(&dev_priv->cmdbuf_mutex);
if (ret != 0) {
+ mutex_unlock(&dev_priv->cmdbuf_mutex);
drm_err(dev, "Wasn't able to create a backing handle for surface sid = %u.\n",
req->sid);
goto out_bad_resource;
}
+ rep->crep.buffer_map_handle =
+ drm_vma_node_offset_addr(&srf->res.guest_memory_bo->tbo.base.vma_node);
+ rep->crep.buffer_size = srf->res.guest_memory_bo->tbo.base.size;
+
+ mutex_unlock(&dev_priv->cmdbuf_mutex);
+
rep->creq.base.svga3d_flags = SVGA3D_FLAGS_LOWER_32(metadata->flags);
rep->creq.base.format = metadata->format;
rep->creq.base.mip_levels = metadata->mip_levels[0];
@@ -1746,9 +1756,6 @@ vmw_gb_surface_reference_internal(struct drm_device *dev,
rep->crep.handle = user_srf->prime.base.handle;
rep->crep.backup_size = srf->res.guest_memory_size;
rep->crep.buffer_handle = backup_handle;
- rep->crep.buffer_map_handle =
- drm_vma_node_offset_addr(&srf->res.guest_memory_bo->tbo.base.vma_node);
- rep->crep.buffer_size = srf->res.guest_memory_bo->tbo.base.size;
rep->creq.version = drm_vmw_gb_surface_v1;
rep->creq.svga3d_flags_upper_32_bits =
@@ -1758,6 +1765,9 @@ vmw_gb_surface_reference_internal(struct drm_device *dev,
rep->creq.must_be_zero = 0;
out_bad_resource:
+ if (ret)
+ ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
+ base->handle);
ttm_base_object_unref(&base);
return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
index 353d837907d8..fc04555ca505 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
@@ -127,16 +127,23 @@ vmw_validation_bo_reserve(struct vmw_validation_context *ctx,
* vmw_validation_bo_fence - Unreserve and fence buffer objects registered
* with a validation context
* @ctx: The validation context
+ * @fence: Fence with which to fence all buffer objects taking part in the
+ * command submission.
*
* This function unreserves the buffer objects previously reserved using
- * vmw_validation_bo_reserve, and fences them with a fence object.
+ * vmw_validation_bo_reserve, and fences them with a fence object if the
+ * given fence object is not NULL.
*/
static inline void
vmw_validation_bo_fence(struct vmw_validation_context *ctx,
struct vmw_fence_obj *fence)
{
- ttm_eu_fence_buffer_objects(&ctx->ticket, &ctx->bo_list,
- (void *) fence);
+ /* fence is able to be NULL if vmw_execbuf_fence_commands() fails */
+ if (fence)
+ ttm_eu_fence_buffer_objects(&ctx->ticket, &ctx->bo_list,
+ (void *)fence);
+ else
+ ttm_eu_backoff_reservation(&ctx->ticket, &ctx->bo_list);
}
/**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
index 3d0d5dfa869f..8ce10cf9c19e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
@@ -299,7 +299,7 @@ vmw_vkms_crtc_cleanup(struct drm_crtc *crtc)
struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
if (vmw->vkms_enabled)
- drm_crtc_vblank_cancel_timer(crtc);
+ drm_crtc_vblank_stop_timer(crtc);
if (du->vkms.surface)
vmw_surface_unreference(&du->vkms.surface);