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=1796453964; b=qYJJAT9BLlxG/wDYYyehJ3e4vzHXyXfpkr1/L9tVtmfYv4sC5MU9OUQKa8npkLJ/yLVU bUypo8rIXIEIMAyT6tV8OEFllNEaBfjoPMSp+HG/+CYMyamOqu4PlsCnRg4Iu8csiuGnA IOnVf87pqPJ/aXIimHiwobBGsJ6G8N5TNjtQcTehAY9h6fwJqbKbgshtl/HMsRb79zOxP YpNIleBs46vf9w59rB+CeWSs/rISK9i6yQK1HgNx/wZJJyh79/XRiJnVFcpVLTrUREIZJ TnkrouflKpZkZ8QKKY+Jp8v0bO/+BEc+chYkdv9Y4OHK4U50KZ8CXHLxKRDelyFui5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453964; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9sfdNmPxgTDJNBJ9Ii+6MUMEnPFwqQZ59ZBRhmjeGcI=; b=zOK8H40ZRcpSGFWcao3QOXrq81RdsJmgm3QaQw8s8U33DBqFCctJT1eMJypeBWnktwiP fJLIp+8DD0TzI+fuA8SJiMv/1yn67NTPVYGa6WolJJgkekGBjJxfdRJvkkG9fz4c1h9e9 0ecUc1gPHl4aD7R+R9rqcVJfXRoH22f8EyFVd4O3kfeoiAyoia0orYI+/+ZKvwKJEBdYe ewwlVXz0gdGTmt4EpTa3PAvjPZyq73/ZMegoa3aSdjiYMOetShP1Hb4KUlaCHbdDySQ/Y dpyje8bBnVHpdCg+bkxC/SFBIsLDFZR4arPOLbB9eKjTYHaBn7zWKnIYLfyH5WOrG/A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V7lUA7Vh; 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 B23D7606A32F for ; Sat, 5 Dec 2026 06:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V7lUA7Vh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53F041F00A07; Sat, 5 Dec 2026 06:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796453964; bh=9sfdNmPxgTDJNBJ9Ii+6MUMEnPFwqQZ59ZBRhmjeGcI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=V7lUA7VhNJnTsBkIJQzBGQDTMBfEOdo7fC2b2Vq6D5ga9AQoOKSj56yUqfhuc7hvu i+iAXHpapoSp5VqTPjL6hG+EVGaynQPagmClTDAIeH2MriJFrkL4WnH6Zx28gV1YDl KfFBu+5Sxhb0JyBm5JeczEqflv9qaQuJTpGnXqAnZNAS+DiDtUjK6c7x6PnA2LlK+d pSIXdLiIuxJPCt30BLxDvtn5Vqy1ms4lnHYJYTmU9GbXFB5bNyKnheNBSvET6IESXB xaux8CecoYNkAUwZ9eDU9jgRcziw1T15mhK6Ppx8PWoA8nwUpm+z/0WkiIDXczm9EC Nl+9CErYlUB9g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 1/2] drm/virtio: accumulate confirmed dumb-buffer damage Reply-To: sashiko-reviews@lists.linux.dev To: "Aditya Tipre" , dri-devel@lists.freedesktop.org Cc: virtualization@lists.linux.dev, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261205063321.56168-2-tipreaditya@gmail.com> References: <20261205063321.56168-1-tipreaditya@gmail.com> <20261205063321.56168-2-tipreaditya@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 06:59:23 +0000 X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] drm/virtio: shared fence context breaks transfer fence ordering and isolation - [High] drm/virtio: synchronous BO put in free_vbuf() deadlocks ctrlq dequeue_work - [Medium] drm/virtio: same-FB partial damage regresses to full uploads when tainted - [Medium] drm/virtio: virtio_gpu_transfer_reply() omits ERR_INVALID_PARAMETER - [Medium] drm/virtio: cursor tainting resets global damage_epoch and defeats buffer_age - [Medium] drm/virtio: empty-damage tracked commits trigger full flush and DMA sync - [Medium] drm/virtio: skipping resp_cb on bad used_len leaks BOs and hangs waiters - [Low] drm/virtio: virtgpu_restore() unrefs missing host resources after hibernation - [Low] drm/virtio: virtio_gpu_plane_atomic_check() merges damage clips when unused -- commit 492f9808c0eea48a3f2f0413632f1015bbd8c079 Author: Aditya Tipre drm/virtio: accumulate confirmed dumb-buffer damage This commit adds opt-in damage history tracking for single-scanout linear XRGB8888 shmem dumb buffers when virgl is disabled, confirming uploads via fenced transfer responses so rotating buffers can upload only accumulated damage. > diff --git a/drivers/gpu/drm/virtio/virtgpu_damage.c b/drivers/gpu/drm/vi= rtio/virtgpu_damage.c > new file mode 100644 > index 0000000000000..1bbc4bde1eda5 > --- /dev/null > +++ b/drivers/gpu/drm/virtio/virtgpu_damage.c [ ... ] > +/* Final gate, after every queue-space wait and before descriptor insert= ion. */ > +bool virtio_gpu_damage_plan(struct virtio_gpu_device *vgdev, > + struct virtio_gpu_transfer *transfer) > +{ > + struct virtio_gpu_object *bo =3D transfer->bo; > + struct virtio_gpu_damage_stamp *stamp =3D &bo->damage_stamp; > + struct virtio_gpu_damage_history *history =3D &vgdev->outputs[transfer-= >output].damage; > + u64 sequence, age; > + u32 i; > + > + lockdep_assert_held(&vgdev->ctrlq.qlock); > + transfer->upload =3D transfer->full; > + transfer->stamp.valid =3D vgdev->damage_enabled && !vgdev->damage_broke= n && > + !vgdev->transfers_stopping && !bo->damage_tainted && history->valid && > + virtio_gpu_damage_cookie_matches(vgdev, history, &transfer->stamp.cook= ie); > + if (bo->damage_version =3D=3D U64_MAX) { > + vgdev->damage_broken =3D true; > + transfer->stamp.valid =3D false; > + } > + /* Overlapping full writes cannot establish an execution order either. = */ > + if (bo->damage_pending) > + transfer->stamp.valid =3D false; > + if (!transfer->stamp.valid || vgdev->transfer_count[transfer->output] || > + bo->damage_pending || !stamp->valid || stamp->output !=3D transfer-= >output || > + stamp->cookie.device_epoch !=3D vgdev->damage_epoch || > + stamp->cookie.epoch !=3D history->epoch || stamp->version !=3D bo->= damage_version || > + stamp->cookie.sequence > history->sequence) > + return true; [Severity: Medium] Does this regress same-framebuffer partial damage to full-framebuffer uploads whenever a buffer object is tainted or lacks a confirmed stamp? When a buffer object is tainted (for example by dma-buf export or a second GEM_OPEN) or when a cursor update or overlapping transfer invalidates its stamp, virtio_gpu_damage_eligible() still admits it to the tracked path. virtio_gpu_damage_plan() then defaults transfer->upload to transfer->full (and virtio_gpu_update_damage() does the same on fallback), forcing a full-screen upload and flush even for same-framebuffer commits with small FB_DAMAGE_CLIPS or DIRTYFB rectangles. Excluding tainted objects from virtio_gpu_damage_eligible() or preserving same-framebuffer partial damage on fallback would avoid this regression. [ ... ] > diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virti= o/virtgpu_drv.c > index 52c174f9bff7f..7b28853eb64b0 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_drv.c > +++ b/drivers/gpu/drm/virtio/virtgpu_drv.c [ ... ] > @@ -251,6 +256,9 @@ static int virtgpu_restore(struct virtio_device *vdev) > } > =20 > virtio_device_ready(vdev); > + /* Quarantine refs may release a BO and queue its resource unref. */ > + virtio_gpu_transfer_cancel_all(vgdev); > + virtio_gpu_transfer_start(vgdev); > =20 > virtgpu_hibernation_restore(vgdev); [Severity: Low] Can virtio_gpu_transfer_cancel_all() queue VIRTIO_GPU_CMD_RESOURCE_UNREF for host resources that do not exist yet after hibernation? If a quarantined transfer holds the last gem reference on a buffer object when virtgpu_freeze() runs, virtio_gpu_object_unref_all() unrefs the host resource before reset while leaving bo->created set. Calling virtio_gpu_transfer_cancel_all() before virtgpu_hibernation_restore() then drops that final reference in virtio_gpu_free_object(), which removes bo from obj_restore_list and sends VIRTIO_GPU_CMD_RESOURCE_UNREF to the resumed host. The host rejects it with VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID, logging an error and resetting damage tracking after virtio_gpu_transfer_start(). [ ... ] > diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/vir= tio/virtgpu_plane.c > index 20aa3d108ecfa..ad77686758430 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_plane.c > +++ b/drivers/gpu/drm/virtio/virtgpu_plane.c [ ... ] > @@ -135,6 +157,21 @@ static int virtio_gpu_plane_atomic_check(struct drm_= plane *plane, > DRM_PLANE_NO_SCALING, > DRM_PLANE_NO_SCALING, > is_cursor, true); > + if (!ret && !is_cursor) { > + struct virtio_gpu_plane_state *vgstate =3D to_virtio_gpu_plane_state(n= ew_plane_state); > + struct virtio_gpu_device *vgdev =3D plane->dev->dev_private; > + bool ignore =3D new_plane_state->ignore_damage_clips; > + > + vgstate->damage_eligible =3D virtio_gpu_damage_eligible(vgdev, new_pla= ne_state) && > + new_plane_state->crtc_w =3D=3D crtc_state->mode.hdisplay && > + new_plane_state->crtc_h =3D=3D crtc_state->mode.vdisplay; > + /* Save frame damage before the per-resource FB-switch fallback. */ > + new_plane_state->ignore_damage_clips =3D false; > + if (!drm_atomic_helper_damage_merged(old_plane_state, new_plane_state, > + &vgstate->frame_damage)) > + vgstate->frame_damage =3D (struct drm_rect) {}; > + new_plane_state->ignore_damage_clips =3D ignore; > + } > return ret; > } [Severity: Low] Why is drm_atomic_helper_damage_merged() called unconditionally here when vgstate->damage_eligible is false? On the default buffer_age=3D0 path and on ineligible planes, this walks fb_damage_clips only for virtio_gpu_primary_plane_update() to discard vgstate->frame_damage and run drm_atomic_helper_damage_merged() a second time. Gating the merge on vgstate->damage_eligible avoids the redundant work on every primary-plane commit. [ ... ] > @@ -268,12 +340,25 @@ static void virtio_gpu_primary_plane_update(struct = drm_plane *plane, > return; > } > =20 > - if (!drm_atomic_helper_damage_merged(old_state, plane->state, &rect)) > - return; > - > bo =3D gem_to_virtio_gpu_obj(plane->state->fb->obj[0]); > - if (bo->dumb) > - virtio_gpu_update_dumb_bo(vgdev, plane->state, &rect); > + crtc_state =3D drm_atomic_get_new_crtc_state(state, plane->state->crtc); > + tracked =3D virtio_gpu_damage_begin(vgdev, output->index, vgstate, > + to_virtio_gpu_plane_state(old_state), > + crtc_state && drm_atomic_crtc_needs_modeset(crtc_state)); > + if (tracked) { > + if (!virtio_gpu_update_damage(vgdev, vgstate, &rect)) > + virtio_gpu_update_dumb_bo(vgdev, plane->state, &rect); > + /* A binding change still needs SET_SCANOUT and a valid flush. */ > + if (!drm_rect_visible(&rect)) > + rect =3D DRM_RECT_INIT(0, 0, plane->state->fb->width, > + plane->state->fb->height); > + } else { > + virtio_gpu_damage_invalidate(vgdev, output->index); > + if (!drm_atomic_helper_damage_merged(old_state, plane->state, &rect)) > + return; > + if (bo->dumb) > + virtio_gpu_update_dumb_bo(vgdev, plane->state, &rect); > + } [Severity: Medium] Should an empty rect on a same-framebuffer commit skip the flush instead of expanding to the full framebuffer? When virtio_gpu_damage_plan() returns false for an empty-damage same-framebuffer commit, this unconditionally expands rect to full-screen dimensions and falls through to virtio_gpu_resource_flush(), even when no scanout binding change or modeset occurred. At baseline and on the untracked branch, empty-damage same-framebuffer commits return early without a host flush. In addition, virtio_gpu_transfer_to_host_2d() runs dma_sync_sgtable_for_device() over the entire framebuffer before virtio_gpu_queue_ctrl_sgs() calls virtio_gpu_damage_plan() and decides no copy is needed. [ ... ] > @@ -457,6 +547,7 @@ static void virtio_gpu_cursor_plane_update(struct drm= _plane *plane, > vgfb =3D to_virtio_gpu_framebuffer(plane->state->fb); > vgplane_st =3D to_virtio_gpu_plane_state(plane->state); > bo =3D gem_to_virtio_gpu_obj(vgfb->base.obj[0]); > + virtio_gpu_damage_taint(vgdev, bo); > handle =3D bo->hw_res_handle; > } else { > handle =3D 0; [Severity: Medium] Does tainting the cursor buffer object on every cursor update defeat buffer_age on interactive desktops? virtio_gpu_cursor_plane_update() calls virtio_gpu_damage_taint() on every cursor commit, including pure cursor moves where the cursor framebuffer has not changed. Because virtio_gpu_damage_taint_locked() calls virtio_gpu_damage_reset_locked(), every cursor move acquires ctrlq.qlock, bumps vgdev->damage_epoch, and invalidates all scanout histories; in combined primary and cursor commits the cursor update runs after the primary update and immediately invalidates the primary transfer's stamp. Similarly, a transient -EBUSY or allocation failure in virtio_gpu_update_damage() calls virtio_gpu_damage_taint(), permanently tainting the primary buffer object and resetting global damage history. [ ... ] > diff --git a/drivers/gpu/drm/virtio/virtgpu_transfer.c b/drivers/gpu/drm/= virtio/virtgpu_transfer.c > new file mode 100644 > index 0000000000000..1e71e3e480c94 > --- /dev/null > +++ b/drivers/gpu/drm/virtio/virtgpu_transfer.c [ ... ] > +struct virtio_gpu_transfer * > +virtio_gpu_transfer_alloc(struct virtio_gpu_device *vgdev, > + struct virtio_gpu_object *bo, u32 output) > +{ > + struct virtio_gpu_transfer *transfer; > + > + if (output >=3D VIRTIO_GPU_MAX_SCANOUTS) > + return NULL; > + transfer =3D kzalloc_obj(*transfer); > + if (!transfer) > + return NULL; > + transfer->fence =3D virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.cont= ext, 0); [Severity: High] Does placing transfer->fence on the shared vgdev->fence_drv.context break dma_fence ordering and transfer response isolation? Tracked transfers attach transfer->fence to bo->resv via virtio_gpu_array_add_fence(), and dma_resv_add_fence() replaces any earlier fence on the same context because dma_fence requires monotonic signaling order within a context. Two regressions follow: First, if a tracked transfer F2 replaces an earlier in-flight command F1 in bo->resv and F2 is later cancelled individually by virtio_gpu_fence_cancel(), bo->resv sees all fences as signaled while F1 is still executing on the host. Second, if any later fenced ctrlq command on vgdev->fence_drv.context completes before an earlier transfer T1 is dequeued, virtio_gpu_fence_event_process() signals T1->fence with error 0 and removes it from drv->fences. Waiters on bo->resv proceed as if T1 succeeded, and a subsequent virtio_gpu_fence_cancel() on an error or unmatched reply silently drops the -EIO or -ENODEV error. Giving independently cancellable transfers their own dma_fence context would avoid both violations. [ ... ] > + /* Never infer this command's completion from a later generic fence. */ > + if (length =3D=3D sizeof(*response) && > + (response->flags & cpu_to_le32(VIRTIO_GPU_FLAG_FENCE)) && > + le64_to_cpu(response->fence_id) =3D=3D transfer->fence_id) { > + type =3D le32_to_cpu(response->type); > + matched =3D type =3D=3D VIRTIO_GPU_RESP_OK_NODATA || > + (type >=3D VIRTIO_GPU_RESP_ERR_UNSPEC && > + type <=3D VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID); > + } [Severity: Medium] Should the upper error bound include VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER? In include/uapi/linux/virtio_gpu.h, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER follows VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID. Stopping at VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID misclassifies a valid ERR_INVALID_PARAMETER reply as unmatched, leaving the transfer in VIRTIO_GPU_TRANSFER_UNCERTAIN with vgdev->transfer_count[output] and bo->damage_pending leaked until device reset, which disables incremental uploads on that output. [ ... ] > diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio= /virtgpu_vq.c > index 21271966b05cd..2f8d018554ca7 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_vq.c > +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c [ ... ] > @@ -202,6 +203,7 @@ static void *virtio_gpu_alloc_cmd_cb(struct virtio_gp= u_device *vgdev, > static void free_vbuf(struct virtio_gpu_device *vgdev, > struct virtio_gpu_vbuffer *vbuf) > { > + virtio_gpu_transfer_put(vbuf->transfer); > if (vbuf->resp_size > MAX_INLINE_RESP_SIZE) > kfree(vbuf->resp_buf); > kvfree(vbuf->data_buf); [Severity: High] Can calling virtio_gpu_transfer_put() synchronously in free_vbuf() deadlock ctrlq.dequeue_work? virtio_gpu_transfer_release() drops transfer->bo synchronously via drm_gem_object_put(). In virtio_gpu_dequeue_ctrl_func(), ctrlq.ack_queue is woken and entry->objs is handed to obj_free_work before free_vbuf() runs. If userspace has already closed the buffer object and obj_free_work drops the objs reference first, free_vbuf() drops the final gem reference directly on ctrlq.dequeue_work: ctrlq.dequeue_work obj_free_work / submitter virtio_gpu_dequeue_ctrl_func() wake_up(&ctrlq.ack_queue) (submitter refills ctrlq.vq) virtio_gpu_array_put_free_delayed() virtio_gpu_array_put_free_work() drm_gem_object_put(bo) free_vbuf() virtio_gpu_transfer_put() drm_gem_object_put(bo) virtio_gpu_free_object() virtio_gpu_cmd_unref_resource() wait_event(ctrlq.ack_queue, ...) <-- deadlocks Because ctrlq.dequeue_work is the only worker that reclaims ctrlq slots and wakes ack_queue, ctrlq wedges permanently. The same call path also acquires vgdev->obj_restore_lock inside ctrlq.dequeue_work, creating an ABBA deadlock with virtio_gpu_object_unref_all() and virtio_gpu_object_restore_all(), which hold obj_restore_lock while queuing ctrlq commands. Deferring the transfer's gem release to obj_free_work, like entry->objs, would prevent both deadlocks. [ ... ] > @@ -304,6 +307,25 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct= *work) > =20 > list_for_each_entry(entry, &reclaim_list, list) { > resp =3D (struct virtio_gpu_ctrl_hdr *)entry->resp_buf; > + if (entry->transfer) { > + if (!virtio_gpu_transfer_reply(vgdev, entry->transfer, resp, > + entry->used_len)) { > + DRM_ERROR_RATELIMITED("invalid transfer response, resource %u\n", > + entry->transfer->bo->hw_res_handle); > + continue; > + } > + } > + if (entry->used_len < sizeof(*resp) || entry->used_len > entry->resp_s= ize) { > + spin_lock(&vgdev->ctrlq.qlock); > + virtio_gpu_damage_reset_locked(vgdev); > + spin_unlock(&vgdev->ctrlq.qlock); > + continue; > + } [Severity: Medium] Can continuing on an out-of-range entry->used_len leak buffer objects and hang waiters permanently, even with buffer_age disabled? This check runs unconditionally for all ctrlq commands and skips both virtio_gpu_fence_event_process() and entry->resp_cb(). If a buggy or non-conforming host returns a used length outside [sizeof(*resp), entry->resp_size], skipping virtio_gpu_cmd_unref_cb() leaks the virtio_gpu_object and its backing storage, and skipping virtio_gpu_cmd_resource_uuid_cb() or virtio_gpu_cmd_resource_map_cb() leaves virtgpu_virtio_get_uuid() or virtio_gpu_vram_mmap() stuck in an uninterruptible wait_event(vgdev->resp_wq, ...) forever. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205063321.5616= 8-1-tipreaditya@gmail.com?part=3D1