<div dir="ltr">Great catch! That was a nasty one.<br><div><br>Reviewed-by: Martin Krastev <<a href="mailto:martin.krastev@broadcom.com">martin.krastev@broadcom.com</a>></div><div><br></div><div>Regards,</div><div>Martin<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 24, 2023 at 7:29 AM Zack Rusin <<a href="mailto:zack.rusin@broadcom.com">zack.rusin@broadcom.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Switch to a new plane state requires unreferencing of all held surfaces.<br>
In the work required for mob cursors the mapped surfaces started being<br>
cached but the variable indicating whether the surface is currently<br>
mapped was not being reset. This leads to crashes as the duplicated<br>
state, incorrectly, indicates the that surface is mapped even when<br>
no surface is present. That's because after unreferencing the surface<br>
it's perfectly possible for the plane to be backed by a bo instead of a<br>
surface.<br>
<br>
Reset the surface mapped flag when unreferencing the plane state surface<br>
to fix null derefs in cleanup. Fixes crashes in KDE KWin 6.0 on Wayland:<br>
<br>
Oops: 0000 [#1] PREEMPT SMP PTI<br>
CPU: 4 PID: 2533 Comm: kwin_wayland Not tainted 6.7.0-rc3-vmwgfx #2<br>
Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020<br>
RIP: 0010:vmw_du_cursor_plane_cleanup_fb+0x124/0x140 [vmwgfx]<br>
Code: 00 00 00 75 3a 48 83 c4 10 5b 5d c3 cc cc cc cc 48 8b b3 a8 00 00 00 48 c7 c7 99 90 43 c0 e8 93 c5 db ca 48 8b 83 a8 00 00 00 <48> 8b 78 28 e8 e3 f><br>
RSP: 0018:ffffb6b98216fa80 EFLAGS: 00010246<br>
RAX: 0000000000000000 RBX: ffff969d84cdcb00 RCX: 0000000000000027<br>
RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff969e75f21600<br>
RBP: ffff969d4143dc50 R08: 0000000000000000 R09: ffffb6b98216f920<br>
R10: 0000000000000003 R11: ffff969e7feb3b10 R12: 0000000000000000<br>
R13: 0000000000000000 R14: 000000000000027b R15: ffff969d49c9fc00<br>
FS:  00007f1e8f1b4180(0000) GS:ffff969e75f00000(0000) knlGS:0000000000000000<br>
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033<br>
CR2: 0000000000000028 CR3: 0000000104006004 CR4: 00000000003706f0<br>
Call Trace:<br>
 <TASK><br>
 ? __die+0x23/0x70<br>
 ? page_fault_oops+0x171/0x4e0<br>
 ? exc_page_fault+0x7f/0x180<br>
 ? asm_exc_page_fault+0x26/0x30<br>
 ? vmw_du_cursor_plane_cleanup_fb+0x124/0x140 [vmwgfx]<br>
 drm_atomic_helper_cleanup_planes+0x9b/0xc0<br>
 commit_tail+0xd1/0x130<br>
 drm_atomic_helper_commit+0x11a/0x140<br>
 drm_atomic_commit+0x97/0xd0<br>
 ? __pfx___drm_printfn_info+0x10/0x10<br>
 drm_atomic_helper_update_plane+0xf5/0x160<br>
 drm_mode_cursor_universal+0x10e/0x270<br>
 drm_mode_cursor_common+0x102/0x230<br>
 ? __pfx_drm_mode_cursor2_ioctl+0x10/0x10<br>
 drm_ioctl_kernel+0xb2/0x110<br>
 drm_ioctl+0x26d/0x4b0<br>
 ? __pfx_drm_mode_cursor2_ioctl+0x10/0x10<br>
 ? __pfx_drm_ioctl+0x10/0x10<br>
 vmw_generic_ioctl+0xa4/0x110 [vmwgfx]<br>
 __x64_sys_ioctl+0x94/0xd0<br>
 do_syscall_64+0x61/0xe0<br>
 ? __x64_sys_ioctl+0xaf/0xd0<br>
 ? syscall_exit_to_user_mode+0x2b/0x40<br>
 ? do_syscall_64+0x70/0xe0<br>
 ? __x64_sys_ioctl+0xaf/0xd0<br>
 ? syscall_exit_to_user_mode+0x2b/0x40<br>
 ? do_syscall_64+0x70/0xe0<br>
 ? exc_page_fault+0x7f/0x180<br>
 entry_SYSCALL_64_after_hwframe+0x6e/0x76<br>
RIP: 0033:0x7f1e93f279ed<br>
Code: 04 25 28 00 00 00 48 89 45 c8 31 c0 48 8d 45 10 c7 45 b0 10 00 00 00 48 89 45 b8 48 8d 45 d0 48 89 45 c0 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff f><br>
RSP: 002b:00007ffca0faf600 EFLAGS: 00000246 ORIG_RAX: 0000000000000010<br>
RAX: ffffffffffffffda RBX: 000055db876ed2c0 RCX: 00007f1e93f279ed<br>
RDX: 00007ffca0faf6c0 RSI: 00000000c02464bb RDI: 0000000000000015<br>
RBP: 00007ffca0faf650 R08: 000055db87184010 R09: 0000000000000007<br>
R10: 000055db886471a0 R11: 0000000000000246 R12: 00007ffca0faf6c0<br>
R13: 00000000c02464bb R14: 0000000000000015 R15: 00007ffca0faf790<br>
 </TASK><br>
Modules linked in: snd_seq_dummy snd_hrtimer nf_conntrack_netbios_ns nf_conntrack_broadcast nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_ine><br>
CR2: 0000000000000028<br>
---[ end trace 0000000000000000 ]---<br>
RIP: 0010:vmw_du_cursor_plane_cleanup_fb+0x124/0x140 [vmwgfx]<br>
Code: 00 00 00 75 3a 48 83 c4 10 5b 5d c3 cc cc cc cc 48 8b b3 a8 00 00 00 48 c7 c7 99 90 43 c0 e8 93 c5 db ca 48 8b 83 a8 00 00 00 <48> 8b 78 28 e8 e3 f><br>
RSP: 0018:ffffb6b98216fa80 EFLAGS: 00010246<br>
RAX: 0000000000000000 RBX: ffff969d84cdcb00 RCX: 0000000000000027<br>
RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff969e75f21600<br>
RBP: ffff969d4143dc50 R08: 0000000000000000 R09: ffffb6b98216f920<br>
R10: 0000000000000003 R11: ffff969e7feb3b10 R12: 0000000000000000<br>
R13: 0000000000000000 R14: 000000000000027b R15: ffff969d49c9fc00<br>
FS:  00007f1e8f1b4180(0000) GS:ffff969e75f00000(0000) knlGS:0000000000000000<br>
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033<br>
CR2: 0000000000000028 CR3: 0000000104006004 CR4: 00000000003706f0<br>
<br>
Signed-off-by: Zack Rusin <<a href="mailto:zack.rusin@broadcom.com" target="_blank">zack.rusin@broadcom.com</a>><br>
Fixes: 485d98d472d5 ("drm/vmwgfx: Add support for CursorMob and CursorBypass 4")<br>
Reported-by: Stefan Hoffmeister <<a href="mailto:stefan.hoffmeister@econos.de" target="_blank">stefan.hoffmeister@econos.de</a>><br>
Closes: <a href="https://gitlab.freedesktop.org/drm/misc/-/issues/34" rel="noreferrer" target="_blank">https://gitlab.freedesktop.org/drm/misc/-/issues/34</a><br>
Cc: Martin Krastev <<a href="mailto:martin.krastev@broadcom.com" target="_blank">martin.krastev@broadcom.com</a>><br>
Cc: Maaz Mombasawala <<a href="mailto:maaz.mombasawala@broadcom.com" target="_blank">maaz.mombasawala@broadcom.com</a>><br>
Cc: Ian Forbes <<a href="mailto:ian.forbes@broadcom.com" target="_blank">ian.forbes@broadcom.com</a>><br>
Cc: Broadcom internal kernel review list <<a href="mailto:bcm-kernel-feedback-list@broadcom.com" target="_blank">bcm-kernel-feedback-list@broadcom.com</a>><br>
Cc: <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
Cc: <<a href="mailto:stable@vger.kernel.org" target="_blank">stable@vger.kernel.org</a>> # v5.19+<br>
---<br>
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 4 ++++<br>
 1 file changed, 4 insertions(+)<br>
<br>
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c<br>
index 65ed9b061753..e7bbe4b05233 100644<br>
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c<br>
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c<br>
@@ -693,6 +693,10 @@ vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,<br>
        int ret = 0;<br>
<br>
        if (vps->surf) {<br>
+               if (vps->surf_mapped) {<br>
+                       vmw_bo_unmap(vps->surf->res.guest_memory_bo);<br>
+                       vps->surf_mapped = false;<br>
+               }<br>
                vmw_surface_unreference(&vps->surf);<br>
                vps->surf = NULL;<br>
        }<br>
-- <br>
2.40.1<br>
<br>
</blockquote></div>