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 C50E5606A31A for ; Wed, 2 Dec 2026 00:19:49 +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=gw2lyoUK Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8755910EB10; Wed, 2 Dec 2026 00:19:44 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E4C010FE68; Wed, 2 Dec 2026 00:19:38 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id C812D600CE; Wed, 2 Dec 2026 00:19:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65E3C1F00893; Wed, 2 Dec 2026 00:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796170777; bh=WLUO0SOrBH/Eu67aSD632zy+iyy1Z/E28SHNVqrAHlA=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=gw2lyoUKIuUoNnmbQ0rChlzBEvO7b+nOg4xhf3W04M+Pr+ODOwpiD86+Bx+/wgmAx QU3wRm18NJGpuq7jVZSjpslrOpowwGYVs1zXjNulay0b41c7/NS/TTVnZku7fFotSc sSQdyaxUE2xZow788rX4QNkuqi1SHCgmd0GFoOAyfmyTV99rUvFAi98B/NNl7LteDm EB4VRzFOo1zdihwjIJ+1ukmThLeU+Z7EHFfTl5SesuCSZtgzyd+Cqn/Fa6U7CWOihh zJppcgCBx+NSvCXuc0vQjXIUJkU5c+zf/EyFog6pysPngfyPoR3W+19g73eR770ctR TScmWrwCknESw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 13/33] drm/xe: Flush L2 asynchronously in xe_bo_trigger_rebind() To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261201234915.3305331-14-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-14-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 00:19:37 +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=-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 4 potential issues to consider: - [High] drm/xe: wrong exec queue in xe_vma_tlb_flush_client() causes crash and race - [High] drm/xe: GFP_KERNEL allocation under fs_reclaim in xe_bo_trigger_rebind() - [Medium] drm/xe: missing tile offset when indexing tlb_inval[] in async TLB flush - [Medium] drm/xe: sync waits in xe_bo_move() defeat async flush and drop intr flag -- commit 84c2ac189fd19c72925ce925ba1b909c879cc4a2 Author: Matthew Brost drm/xe: Flush L2 asynchronously in xe_bo_trigger_rebind() This commit replaces the synchronous idle wait and TLB invalidation in xe_bo_trigger_rebind() on L2-flush-optimized hardware with asynchronous TLB invalidation jobs installed into the BO's dma-resv as kernel fences. > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index ff5610ba4b740..920b7b6094582 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c > @@ -857,6 +857,19 @@ static int xe_bo_trigger_rebind(struct xe_device *xe= , struct xe_bo *bo, > */ > if (!xe_device_is_l2_flush_optimized(xe)) > continue; > + > + /* > + * Attempt to flush L2 async, fallback to sync flush on > + * failure. Skip the async attempt under no_wait_gpu > + * (e.g. the shrinker's reclaim pass): job creation > + * allocates with GFP_KERNEL, which must not run while > + * holding the dma-resv lock under fs_reclaim. The sync > + * fallback below honors no_wait_gpu (returns -EBUSY if > + * the BO is not idle). > + */ > + if (!ctx->no_wait_gpu && > + !xe_vm_flush_vm_bo_tlb_async(vm, bo, vm_bo)) > + continue; > } [Severity: High] Is checking !ctx->no_wait_gpu enough to prevent GFP_KERNEL allocations in xe_vm_flush_vm_bo_tlb_async() under fs_reclaim while holding the BO dma-resv lock? When kswapd runs xe_shrinker_scan(), ttm_bo_shrink_avoid_wait() returns fal= se (!current_is_kswapd()), so passes 2 and 3 in xe_shrinker_walk() call __xe_shrinker_walk() -> xe_bo_shrink() -> xe_bo_move_notify() -> xe_bo_trigger_rebind() with ctx->no_wait_gpu =3D=3D false inside fs_reclaim. Similarly, xe_ttm_bo_swap_notify() calls xe_ttm_bo_purge() with ctx.no_wait_gpu =3D=3D false during swapout. Both paths hit the GFP_KERNEL allocations and might_alloc(GFP_KERNEL) in xe_tlb_inval_job_alloc_dep(), inverting the fs_reclaim -> dma_resv lock order and risking reclaim deadloc= k. [Severity: Medium] Does xe_bo_move() still block synchronously on the new flush fence right after xe_bo_move_notify() returns? xe_device_is_l2_flush_optimized() is only true on !IS_DGFX(xe), where BO eviction moves from XE_PL_TT to XE_PL_SYSTEM. Immediately after xe_bo_move_notify(), xe_bo_move() waits uninterruptibly on DMA_RESV_USAGE_BOOKKEEP before reaching xe_migrate_copy(): drivers/gpu/drm/xe/xe_bo.c:xe_bo_move() { ... if (old_mem_type =3D=3D XE_PL_TT && new_mem->mem_type =3D=3D XE_PL_SYSTEM) { long timeout =3D dma_resv_wait_timeout(ttm_bo->base.resv, DMA_RESV_USAGE_BOOKKEEP, false, MAX_SCHEDULE_TIMEOUT); ... } Because DMA_RESV_USAGE_BOOKKEEP includes the DMA_RESV_USAGE_KERNEL fence installed by xe_vm_flush_vm_bo_tlb_async(), the calling thread still stalls under the BO dma-resv lock for all in-flight GPU work plus the extra dep_scheduler and job_wq hop, and the wait is no longer interruptible when ctx->interruptible is true. > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c > index c774804ca5567..842d99a6ae1a3 100644 > --- a/drivers/gpu/drm/xe/xe_vm.c > +++ b/drivers/gpu/drm/xe/xe_vm.c [ ... ] > @@ -4668,6 +4669,130 @@ int xe_vm_invalidate_vma(struct xe_vma *vma) > return ret; > } > =20 > +/* > + * xe_vma_tlb_flush_client - Queue an async TLB flush for one VMA on one= client > + * > + * Create and push a TLB invalidation job on the tile migrate (kernel) e= xec > + * queue covering @vma's range, depending on @dep (the BO's in-flight GP= U work) > + * so the flush only fires once the GPU is done with the current mapping= . The > + * job's completion fence is installed into @resv as a KERNEL fence so t= he > + * subsequent migration waits on the flush. No PTEs are zapped; this only > + * flushes L2 via the TLB invalidation. > + */ > +static int xe_vma_tlb_flush_client(struct xe_vm *vm, struct xe_vma *vma, > + struct xe_tile *tile, struct xe_gt *gt, > + struct dma_resv *resv, struct dma_fence *dep, > + int type) > +{ > + struct xe_exec_queue *q =3D xe_migrate_exec_queue(tile->migrate); > + struct xe_tlb_inval_job *job; > + struct dma_fence *fence; > + int err; > + > + job =3D xe_tlb_inval_job_create(q, >->tlb_inval, > + q->tlb_inval[type].dep_scheduler, vm, > + xe_vma_start(vma), xe_vma_end(vma), type); > + if (IS_ERR(job)) > + return PTR_ERR(job); > + > + err =3D xe_tlb_inval_job_alloc_dep(job); > + if (err) > + goto out_put; > + > + err =3D dma_resv_reserve_fences(resv, 1); > + if (err) > + goto out_put; > + > + /* Cannot fail; takes its own ref on @dep and returns a referenced fenc= e. */ > + fence =3D xe_tlb_inval_job_push(job, dep); [Severity: High] Should xe_vma_tlb_flush_client() use xe_cpu_bind_queue(vm->xe->cpu_bind) instead of xe_migrate_exec_queue(tile->migrate)? Since commit f5708e761ed6 ("drm/xe: Add CPU bind layer"), xe_tlb_inval_job_push() serializes kernel TLB invalidation jobs via xe_cpu_bind_job_lock(cpu_bind, job->q): drivers/gpu/drm/xe/xe_cpu_bind.c:xe_cpu_bind_job_lock() { bool is_cpu_bind =3D is_cpu_bind_queue(cpu_bind, q); if (is_cpu_bind) mutex_lock(&cpu_bind->job_mutex); else xe_vm_assert_held(q->user_vm); /* User queues VM's should be locked */ } Because tile->migrate->q is not cpu_bind->q and has q->user_vm =3D=3D NULL, xe_cpu_bind_job_lock() skips cpu_bind->job_mutex and dereferences a NULL q->user_vm in xe_vm_assert_held() when CONFIG_LOCKDEP is enabled, followed = by failing xe_assert(xe, q =3D=3D cpu_bind->q) in xe_cpu_bind_job_lock_assert(= ). With lockdep and debug assertions disabled, no lock is taken at all, so concurrent BO evictions race on the shared dep_scheduler entity and on q->tlb_inval[idx].last_fence in xe_exec_queue_tlb_inval_last_fence_set(). > + dma_resv_add_fence(resv, fence, DMA_RESV_USAGE_KERNEL); > + dma_fence_put(fence); > + > +out_put: > + /* Drop the creation reference (destroys the job if it was not pushed).= */ > + xe_tlb_inval_job_put(job); > + return err; > +} [ ... ] > + for_each_tile(tile, xe, id) { > + if (!(vma->tile_present & BIT(id))) > + continue; > + > + err =3D xe_vma_tlb_flush_client(vm, vma, tile, > + tile->primary_gt, resv, dep, > + XE_EXEC_QUEUE_TLB_INVAL_PRIMARY_GT); > + if (err) > + goto out; > + > + if (tile->media_gt) { > + err =3D xe_vma_tlb_flush_client(vm, vma, tile, > + tile->media_gt, resv, dep, > + XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT); > + if (err) > + goto out; > + } > + } [Severity: Medium] Does indexing q->tlb_inval[type] without a tile offset use tile 0's slots f= or every tile? Since commit 366365b7489f ("drm/xe: Make bind queues operate cross-tile"), alloc_dep_schedulers() populates q->tlb_inval[] across all tiles at id * (XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT + 1) + type. Passing the unshifted type (0 or 1) for tile->id > 0 selects tile 0's dep_scheduler and last_fence slot, which gives fences from different tiles the same dma_fence context so dma_resv_add_fence() overwrites tile 0's unsignaled flush fence in resv. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201234915.3305= 331-1-matthew.brost@intel.com?part=3D13