From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380760; b=lYM4fl8eihNtHB+RH+4PG2phjwNJomBs6PKGClUJKWARNDlw1J/mpR1pqv0z5GsrhON8 YcUnCCtOl2hWLMNCaAuXEXaXgnsgPjUuqQghw4iNUtaeSBEGBUiKoBKODwtAo7PreJ0HK ueSyhffk/R2uwFKt1tWdDnCOLQLsseeGpBdvIL8UpuPKu+v9JzJ060+H0oU2QiHMg26dN s2NcNrlu/CDJ9BvN2iijyOUayDkTXFmpFzgbKtdu2JNToI+4uGE/sKEJlKOf5ogVI31Xk uDuy3iomOFSn5sqGZRFYW2larF3PCoSczDZtNkXsSDrEuduX0brlQNHLBzXTOosqXSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380760; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=akZi2H2MmC/bACSKFpJMieOGfbhLR2ieaLpe6N+LKWo=; b=eDuw44zVA+ttmhdHOczH+tupj1XsLd5bIY/xfKJCCPkaPZhR0KQZlFs5Qg57aYZWJcoc E/N3cHX9FyzWOHZircCc1HfHcqU63hmR1ykmt0SHx/HC6uE2ZJN+URFxx6NR/W4C1p7Jz e1Tv97Lhi21yZF/1pecNZJdRz3to76dZkCpoqX143GGgsqieaNVrPQDUBkQQpjPDN8gqJ rEcgCpYQAHKj/87iPsFxZaGp8qsKZOYgbkrtz9LWWVH/QugLIZp6xxcgCF9sOmZqHHCjs O/OE2vXPNMeaUCV28l8+5aZuexnfeB7bOyKYSUf9tB0tAetQuWDfuIDcYVVrlcu/HgA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=L1lc4IVj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD1B3606A32C; Fri, 4 Dec 2026 10:39:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=L1lc4IVj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B4851F000C2; Fri, 4 Dec 2026 10:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380760; bh=akZi2H2MmC/bACSKFpJMieOGfbhLR2ieaLpe6N+LKWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=L1lc4IVjTP17sXftRrasJUNzIgrkdv5qFev8kOFAy4tDWnaIoRJSGJ0j/68YiyU+d mQQakcW5BYX4ul4NuqkB8dpsAthFIQ6VUQcs54XyaOUfqtiHA1H7ySr3PdLzS4L35W TZoetVNP2txh/JU8s/ZbSEHmZrugKxPIM9ZLfRIc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zack Rusin , Maaz Mombasawala , fausten Subject: [PATCH 7.3 414/742] drm/vmwgfx: keep cursor mappings and pins with each plane state Date: Fri, 4 Dec 2026 19:04:38 +0900 Message-ID: <20261204100646.099205932@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zack Rusin commit 556271f0ade9d3f1ed0a386f29d3363be294c1fc upstream. Cursor plane states duplicate the user object reference without acquiring its mapping or pin. Preparing the duplicated state nevertheless unmaps that object, and only pins the new buffer if it is not already pinned. Cleanup of an older state can therefore remove a mapping or pin still needed by another cursor commit. Repeated cursor updates from KMS clients can then access an unmapped or movable buffer. Give each prepared state its own mapping, buffer reference and pin, and reset the mapping when duplicating a state. Release only the resources owned by that state in cleanup_fb(). Map the required image extent for every state so resizing a cursor on the same buffer cannot reuse a smaller cached mapping. Unwind the pin and reservation if preparation fails. Fixes: 965544150d1c ("drm/vmwgfx: Refactor cursor handling") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Zack Rusin Reviewed-by: Maaz Mombasawala Tested-by: fausten Link: https://patch.msgid.link/20261027211729.646988-2-zack.rusin@broadcom.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c | 69 ++++++++++++++++----------- drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.h | 4 + drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 1 3 files changed, 48 insertions(+), 26 deletions(-) --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c @@ -112,8 +112,7 @@ static void vmw_cursor_update_mob(struct { 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 +131,6 @@ static void vmw_cursor_update_mob(struct 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); } @@ -490,9 +488,21 @@ vmw_cursor_plane_cleanup_fb(struct drm_p { 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,10 +635,12 @@ int vmw_cursor_plane_prepare_fb(struct d 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) { @@ -652,31 +664,34 @@ int vmw_cursor_plane_prepare_fb(struct d bo = vmw_user_object_buffer(&vps->uo); 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); + 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); + 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 +718,10 @@ int vmw_cursor_plane_prepare_fb(struct d } return 0; + +out_unreserve: + ttm_bo_unreserve(&bo->tbo); + return ret; } /** @@ -796,7 +815,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 = @@ -827,9 +845,8 @@ vmw_cursor_plane_atomic_update(struct dr 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, hotspot_x, hotspot_y); --- 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 + #include 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; --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c @@ -283,6 +283,7 @@ vmw_du_plane_duplicate_state(struct drm_ 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);