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 176F0606A333 for ; Mon, 30 Nov 2026 10:45:28 +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=lOYZYKyV Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D2C4D10E209; Mon, 30 Nov 2026 10:45:22 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0B8DC10E86A for ; Mon, 30 Nov 2026 10:45:16 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B7B3741A80; Mon, 30 Nov 2026 10:45:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F9F01F008A0; Mon, 30 Nov 2026 10:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796035515; bh=nz3MDrWTpwcBRzLZ+/L6uwyFixFuDG09TT4/RJEa9kk=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=lOYZYKyVBLvcXCnuFVwA4vyi9bdb9kq4XaDC41h+T2Z7ru1h7mjaTYRPtk4uNpnFA /kjcAyx6BAImHm1a9648XccZWEHmdSBYYpXl32w35QROORJ+YkVLURh1yryQLBA048 vKaWHBDWzTd5++T4gwXSOmdsHOCYb7+D2QcjVLzvBWSXyjzkAsZeDjUlij1n0ok5fb BNIT3sliIMkvHDjp7SZWSR425aVAkquSJVpVw38OjoIzUpbxRRoV8+LuYUoC5Ay1Ja Gy2fb0mKLdepYXL10zsdRIOvcHmDGEs7ItxmdfnyHwcdoSO9csHTFik4T/Z57oaiZf EgONx7fgT/4tg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/xe: Hold VM reference in preempt rebind worker To: "Tejas Upadhyay" , intel-xe@lists.freedesktop.org In-Reply-To: <20261130102837.4056493-2-tejas.upadhyay@intel.com> References: <20261130102837.4056493-2-tejas.upadhyay@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 10:45:14 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,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 3 potential issues to consider: - [High] drm/xe: race in xe_vm_queue_rebind_worker() taking VM ref after queuing work - [Medium] drm/xe: self-flush deadlock in preempt_rebind_work_func() via xe_vm_put() - [Low] drm/xe: missing Fixes trailer for vm_destroy_work_func() flush warning fix -- commit a7801ac2662678d368acc3e11b0b5eed7a84e910 Author: Tejas Upadhyay > drm/xe: Hold VM reference in preempt rebind worker >=20 > vm_destroy_work_func() runs on a WQ_MEM_RECLAIM workqueue and currently > flushes vm->preempt.rebind_work, which is queued on the non-reclaim > rebind_wq. This triggers a workqueue flush dependency warning: >=20 > workqueue: WQ_MEM_RECLAIM xe-destroy-wq:vm_destroy_work_func [xe] is fl= ushing !WQ_MEM_RECLAIM xe-ordered-wq:preempt_rebind_work_func [xe] > WARNING: kernel/workqueue.c:3921 at check_flush_dependency.part.0+0xd9/= 0x110 >=20 > Take a VM reference when queuing vm->preempt.rebind_work and drop it > when preempt_rebind_work_func() exits. Since the VM cannot be destroyed > while rebind_work is pending or running, drop the redundant flush_work() > from vm_destroy_work_func(). >=20 > Signed-off-by: Tejas Upadhyay [Severity: Low] This fixes the workqueue flush dependency warning introduced when deferred VM teardown was moved to the reclaim-marked destroy_wq. Should it include a Fixes: tag? Fixes: 61e18525023a ("drm/xe: Route deferred xe_vma/xe_vm teardown off sy= stem_dfl_wq") > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c > index ab138d495f3f8..547d2c2980a76 100644 > --- a/drivers/gpu/drm/xe/xe_vm.c > +++ b/drivers/gpu/drm/xe/xe_vm.c > @@ -586,14 +586,14 @@ static void preempt_rebind_work_func(struct work_st= ruct *w) > if (xe_vm_is_closed_or_banned(vm)) { > up_write(&vm->lock); > trace_xe_vm_rebind_worker_exit(vm); > - return; > + goto out_put_vm; > } > =20 > if (!try_wait_for_completion(&vm->xe->pm_block) && vm_suspend_rebind_wo= rker(vm)) { > up_write(&vm->lock); > /* We don't actually block but don't make progress. */ > xe_pm_might_block_on_suspend(); > - return; > + goto out_put_vm; > } > =20 > if (xe_vm_userptr_check_repin(vm)) { > @@ -669,7 +669,7 @@ static void preempt_rebind_work_func(struct work_stru= ct *w) > free_preempt_fences(&preempt_fences); > xe_vm_queue_rebind_worker(vm); > trace_xe_vm_rebind_worker_exit(vm); > - return; > + goto out_put_vm; > } > =20 > xe_vm_rebind_worker_reset_inject(vm); > @@ -683,6 +683,8 @@ static void preempt_rebind_work_func(struct work_stru= ct *w) > free_preempt_fences(&preempt_fences); > =20 > trace_xe_vm_rebind_worker_exit(vm); > +out_put_vm: > + xe_vm_put(vm); > } [Severity: Medium] Can calling xe_vm_put(vm) from preempt_rebind_work_func() deadlock on xe->rebind_wq when it drops the last VM reference after device unplug? preempt_rebind_work_func() runs on the per-device xe->rebind_wq. When xe_vm_put() drops the final reference on vm->gpuvm, drm_gpuvm_free() calls xe_vm_free() (which queues vm->destroy_work without holding a drm_device reference) and then synchronously calls drm_dev_put() in the caller's context. If the device was unplugged and the DRM file closed while rebind_work was still pending or re-queued (for example via preempt_fence_work_func() or the -EAGAIN retry path), that drm_dev_put() is the final device reference and runs: preempt_rebind_work_func() [on xe->rebind_wq] xe_vm_put(vm) drm_gpuvm_put(&vm->gpuvm) drm_gpuvm_free() drm_dev_put() drm_managed_release() xe_device_destroy() destroy_workqueue(xe->rebind_wq) <-- self-flush deadlock As noted in vma_destroy_cb(), work items that put a VM reference cannot do so from a per-device workqueue destroyed in xe_device_destroy(). [ ... ] > diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h > index ed590bad892cd..1917deca4679d 100644 > --- a/drivers/gpu/drm/xe/xe_vm.h > +++ b/drivers/gpu/drm/xe/xe_vm.h > @@ -262,8 +262,9 @@ int xe_vm_validate_protected(struct xe_vm *vm); > static inline void xe_vm_queue_rebind_worker(struct xe_vm *vm) > { > xe_assert(vm->xe, xe_vm_in_preempt_fence_mode(vm)); > - queue_work_node(dev_to_node(vm->xe->drm.dev), vm->xe->rebind_wq, > - &vm->preempt.rebind_work); > + if (queue_work_node(dev_to_node(vm->xe->drm.dev), vm->xe->rebind_wq, > + &vm->preempt.rebind_work)) > + xe_vm_get(vm); > } [Severity: High] Can preempt_rebind_work_func() start on another CPU and call xe_vm_put(vm) before xe_vm_queue_rebind_worker() calls xe_vm_get(vm)? vm->xe->rebind_wq is an unbound workqueue. If a caller queues rebind_work when the VM is already closed and only one reference remains (for example preempt_fence_work_func() running after xe_vm_close_and_put(), where q->vm holds the last VM reference): CPU0 CPU1 (rebind_wq) preempt_fence_work_func() xe_vm_queue_rebind_worker(q->vm) queue_work_node(..., rebind_work) preempt_rebind_work_func() xe_vm_is_closed_or_banned(vm) goto out_put_vm; xe_vm_put(vm) <-- kref 1 -> 0 xe_vm_get(vm) <-- refcount_inc on 0 / UAF xe_exec_queue_put(q) ... xe_vm_put(vm) <-- second drop to 0 Taking the reference with xe_vm_get(vm) before queue_work_node() and dropping it with xe_vm_put(vm) if queue_work_node() returns false avoids the race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130102837.4056= 493-2-tejas.upadhyay@intel.com?part=3D1