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 98224606A321 for ; Sun, 29 Nov 2026 00:23:42 +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=bdal3bPQ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF23110E46D; Sun, 29 Nov 2026 00:23:36 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 58A7810E47C for ; Sun, 29 Nov 2026 00:23:30 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 177E640983; Sun, 29 Nov 2026 00:23:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8F3A1F00896; Sun, 29 Nov 2026 00:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795911810; bh=Nk2VGEC2J4HTWrOgJLaedhz+xKZYupTrEMER+5fRqvo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=bdal3bPQII383zIr07QtukYtidB6ZA7tXSNyZHrY3U6I6oxo+R1O96rlCUwH/gmeN VQheBKWATkmV87jDgKSC1S4E7tDsWWUx9rCgD1dPlXc3Wz8w1W5XLQ2PyL+Nx/FG6+ 9oyyrWLj7Vau9D97lKGf07QqLfvHIQfFJLOLsiN/jIDoMfJ+oVhtz1Ry8ehvQkq5J9 JNW6Ovf7noFHJQUhNG6M6yvgVuHDo3mSxiMoOSSVexkEckr7I95ILTC9SM1qC4S+6i 6xO9Dk0pJ9VK6HzWqmkhO1FmGG0E1wcvYh7IoeoRkRNmms18TQstJPMx1PpEucpHly NN+ltjyRg/bWA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/msm/gem: defer shared GPU VM teardown until last VMA user To: "Vladimir Bely" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261129000944.986285-1-vlwwwwww@gmail.com> References: <20261129000944.986285-1-vlwwwwww@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 00:23:29 +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=-10.8 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 1 potential issue to consider: - [Medium] drm/msm: TOCTOU race on vma_ref across unlocked wait in msm_gem_vma_put() -- commit 465909c901566442dba60b64068077eeb1425e62 Author: Vladimir Bely drm/msm/gem: defer shared GPU VM teardown until last VMA user This commit skips tearing down VMAs in the shared global GPU VM during msm_gem_close() and instead defers the teardown to msm_gem_vma_put() when vma_ref reaches zero. > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c > index 6ee0e7d146157..88a46ec3caad1 100644 > --- a/drivers/gpu/drm/msm/msm_gem.c > +++ b/drivers/gpu/drm/msm/msm_gem.c [ ... ] > @@ -105,6 +131,23 @@ 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. > + */ > + if (priv->gpu && priv->gpu->vm && has_vma(obj, priv->gpu->vm)) { > + struct drm_exec exec; > + > + dma_resv_wait_timeout(obj->resv, DMA_RESV_USAGE_BOOKKEEP, false, > + MAX_SCHEDULE_TIMEOUT); > + msm_gem_lock_vm_and_obj(&exec, obj, priv->gpu->vm); > + put_iova_spaces(obj, priv->gpu->vm, true, "vma_put"); > + drm_exec_fini(&exec); /* drop locks */ > + } > + > if (!priv->kms) > return; [Severity: Medium] Can msm_gem_vma_put() tear down active VMAs in priv->gpu->vm and priv->kms->vm if vma_ref is incremented again while dma_resv_wait_timeout() is sleeping unlocked? For example, an existing drm_framebuffer holds a GEM object reference without holding vma_ref while unprepared, and a concurrent atomic commit can prepare it while msm_gem_vma_put() is waiting on fences: CPU0 CPU1 msm_gem_close() msm_gem_vma_put() atomic_dec_return(&vma_ref) -> 0 dma_resv_wait_timeout(...) msm_framebuffer_prepare() msm_gem_vma_get() atomic_inc(&vma_ref) -> 1 msm_gem_get_and_pin_iova(...) msm_gem_lock_vm_and_obj(...) put_iova_spaces(..., gpu->vm, ...) drm_exec_fini(&exec) msm_gem_lock_vm_and_obj(...) put_iova_spaces(..., kms->vm, ...) <-- unmaps active VMA Because vma_ref is not re-checked after locking the VM and object, put_iova_spaces() unmaps and closes VMAs that are back in use, causing IOMMU faults and causing the later msm_framebuffer_cleanup() -> msm_gem_unpin_iova() call to miss the closed VMA and leak pin_count. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129000944.9862= 85-1-vlwwwwww@gmail.com?part=3D1