From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48236606A32D for ; Fri, 4 Dec 2026 23:41:16 +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=GS7TsgrE Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AAF2F10ECEC; Fri, 4 Dec 2026 23:41:10 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id C1B8C10ECEC for ; Fri, 4 Dec 2026 23:41:04 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 67D25429D6; Fri, 4 Dec 2026 23:41:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3918D1F0093B; Fri, 4 Dec 2026 23:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796427664; bh=A9sjnsrBIxKuGvXGxYRoBHXhFQ5vnxnpcQmVyJzyR58=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GS7TsgrEB5PagVsRyyWdbnZJkddlduqp/eRllg3k0WSUN95Y2ojlABeNzHtuvhpcV LCLQfAStyOJxo1Daz5QRKXVhdU/NBGVmlFJsl7xY/YhEaaMcS5wbRMzQO8m5lyU/nO wUBHi+S73Uw/mCKzv39lZwpECF6tVrYr+cBI2wFc1fHozFub5o01srA1Pzr9+sbh2W 0BrHi+D0utamA/DE7pIL5g9y5Rf1XgQyimgVui+LnA5JVMIPDOCT2F1R0zz/NypinI oQlIXcADerX4JLzSoBvaoBJtrNhbGnA6I2AZwO6lfS+M0ixBPAcVUfPp5pUBjDt1fZ 6+UUinr/dCzMg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 1/2] drm/msm/gem: defer shared GPU VM teardown until last VMA user To: "Vladimir Bely" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261204231058.699120-2-vlwwwwww@gmail.com> References: <20261204231058.699120-1-vlwwwwww@gmail.com> <20261204231058.699120-2-vlwwwwww@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 23:41:03 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] drm/msm: unbounded uninterruptible fence wait in msm_gem_vma_put() - [Medium] drm/msm: has_vma() locks obj->resv on per-process pagetable GPUs - [Medium] drm/msm: uninterruptible fence wait under modeset lock in msm_gem_vma_put() - [Medium] drm/msm: unchecked msm_gem_lock_vm_and_obj() return in msm_gem_vma_put() - [Medium] drm/msm/gem: blocking GPU fence wait and VM unmap in msm_gem_vma_put() - [Low] drm/msm: stale vma_ref comments only mention kms->vm -- commit 04b8493963f48ed195419d586c3d301c918f3f68 Author: Vladimir Bely drm/msm/gem: defer shared GPU VM teardown until last VMA user This commit skips per-handle VMA teardown in msm_gem_close() when ctx->vm is the shared priv->gpu->vm, and instead tears down that mapping in msm_gem_vma_put() once vma_ref drops to zero. > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c > index 6ee0e7d146157..aac5926fbc904 100644 > --- a/drivers/gpu/drm/msm/msm_gem.c > +++ b/drivers/gpu/drm/msm/msm_gem.c > @@ -53,8 +53,21 @@ static int msm_gem_open(struct drm_gem_object *obj, st= ruct drm_file *file) > static void put_iova_spaces(struct drm_gem_object *obj, struct drm_gpuvm= *vm, > bool close, const char *reason); > =20 > +static bool has_vma(struct drm_gem_object *obj, struct drm_gpuvm *vm) > +{ > + struct drm_gpuvm_bo *vm_bo; > + > + msm_gem_lock(obj); > + vm_bo =3D drm_gpuvm_bo_find(vm, obj); > + drm_gpuvm_bo_put(vm_bo); > + msm_gem_unlock(obj); > + > + return !!vm_bo; > +} [Severity: Medium] Does has_vma() still acquire obj->resv on GPUs with per-process pagetables? msm_gpu_init() unconditionally creates priv->gpu->vm for kernel buffers on a6xx/a7xx/a8xx as well, so priv->gpu && priv->gpu->vm is always true in msm_gem_vma_put(). Every final vma_ref drop therefore takes dma_resv_lock(obj->resv) and walks obj->gpuva.list. For MSM_BO_NO_SHARE buffers, obj->resv aliases the process-wide ctx->vm reservation lock used on every submit and VM_BIND ioctl, adding lock contention on handle closes that previously took no locks. [ ... ] > @@ -105,6 +127,39 @@ void msm_gem_vma_put(struct drm_gem_object *obj) > if (atomic_dec_return(&to_msm_bo(obj)->vma_ref)) > return; > =20 > + /* > + * Without per-process pagetables, every context maps the object in > + * the shared global GPU VM, see msm_gem_close(). Drop that mapping, > + * and the reference it holds on the object, once the last user is > + * gone. Check has_vma() first so GPUs with per-process pagetables > + * don't wait on fences or lock the global GPU VM. > + */ [Severity: Low] The comment above msm_gem_vma_get() in msm_gem.c ("Get/put for kms->vm VMA") and the kernel-doc for msm_gem_object::vma_ref in msm_gem.h still only mention kms->vm, even though vma_ref now also governs priv->gpu->vm teardown. > + if (priv->gpu && priv->gpu->vm && has_vma(obj, priv->gpu->vm)) { > + struct drm_exec exec; > + > + for (;;) { > + dma_resv_wait_timeout(obj->resv, > + DMA_RESV_USAGE_BOOKKEEP, false, > + MAX_SCHEDULE_TIMEOUT); [Severity: Medium] Can this uninterruptible fence wait now sleep while drm_modeset_lock is held? If a synchronous atomic commit is interrupted by a signal during drm_atomic_helper_wait_for_fences(dev, state, true), the error path runs drm_atomic_helper_unprepare_planes() -> msm_framebuffer_cleanup() -> msm_gem_vma_put() while still holding drm_modeset_lock. When the GEM handle was already closed, vma_ref drops to zero and this re-enters an uninterruptible wait on the same unsignaled fence, turning a signal-aborted commit into an unkillable wait that blocks other modesets and VT switches. > + if (atomic_read(&to_msm_bo(obj)->vma_ref)) > + return; > + > + msm_gem_lock_vm_and_obj(&exec, obj, priv->gpu->vm); [Severity: Medium] What happens if msm_gem_lock_vm_and_obj() fails with -ENOMEM here? drm_exec_lock_obj() can return -ENOMEM without holding either lock when allocating exec->objects fails (for instance, during exit_files() of an OOM-killed process whose ALLOC_OOM reserves are exhausted). Ignoring the return value lets put_iova_spaces() unlink and free VMAs from the shared priv->gpu->vm without holding obj->resv or the VM lock, risking rb-tree and list corruption against concurrent contexts. > + if (atomic_read(&to_msm_bo(obj)->vma_ref)) { > + drm_exec_fini(&exec); > + return; > + } > + if (dma_resv_test_signaled(obj->resv, > + DMA_RESV_USAGE_BOOKKEEP)) { > + put_iova_spaces(obj, priv->gpu->vm, true, > + "vma_put"); > + drm_exec_fini(&exec); > + break; > + } [Severity: Medium] Is it safe to block on GPU fences, the global priv->gpu->vm lock, and synchronous IOMMU unmap inside msm_gem_vma_put()? msm_atomic_commit_tail() -> msm_framebuffer_cleanup() runs before drm_atomic_helper_commit_cleanup_done(), so an active or hung GPU job on an old scanout BO whose handle was already closed stalls subsequent commits in stall_checks(). Likewise, delayed_fput() -> msm_gem_dmabuf_release() drains deferred file closes serially on a single global work item, so blocking here stalls unrelated deferred file releases system-wide. Deferring shared GPU VMA teardown to a worker or fence callback would avoid blocking both paths. > + drm_exec_fini(&exec); > + } > + } [Severity: High] Can this unbounded retry loop livelock on a foreign imported dma-buf? msm_gem_import() sets obj->resv =3D dmabuf->resv, while each import gets an independent vma_ref. Once vma_ref reaches zero, nothing can raise it again, yet another dma-buf holder can keep attaching unsignaled fences to dmabuf->resv via DMA_BUF_IOCTL_IMPORT_SYNC_FILE or another GPU context. When a new fence lands while dma_resv_wait_timeout() sleeps on an earlier one, dma_resv_test_signaled() sees the new fence under the lock and loops indefinitely in uninterruptible sleep, hanging msm_gem_close() in D state or wedging atomic commit_work. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204231058.6991= 20-1-vlwwwwww@gmail.com?part=3D1