RE: [PATCH] drm/xe/pt: Reset prepare state in xe_pt_update_ops_init()

"Cavitt, Jonathan" <[email protected]> Fri, 31 Jul 2026 20:26:30 +0000
Newsgroups org.freedesktop.lists.intel-xe
Message-ID <CH0PR11MB5395D957A67C52FFF1843A8BE5C82@CH0PR11MB5395.namprd11.prod.outlook.com>
-----Original Message-----
From: Intel-xe <[email protected]> On Behalf Of Zongyao Bai
Sent: Monday, July 13, 2026 4:09 PM
To: [email protected]
Cc: Bai, Zongyao <[email protected]>; [email protected]
Subject: [PATCH] drm/xe/pt: Reset prepare state in xe_pt_update_ops_init()
> 
> xe_pt_update_ops_init() resets the per-prepare address range and
> deferred state, but current_op was left unchanged. If the same
> xe_vm_pgtable_update_ops is prepared again, new operations are appended
> after the stale current_op value instead of starting from ops[0]. This
> can make current_op exceed the number of operations allocated by
> xe_vma_ops_alloc(), leading to out-of-bounds access to pt_update_ops->ops.
> So, reset current_op when initializing the PT update ops.
> 
> Also reset needs_svm_lock and needs_invalidation. These flags are derived
> during the same prepare pass as current_op and are consumed by
> xe_pt_update_ops_run(); leaving them stale can select the SVM migrate ops
> or request TLB invalidation even when the current prepared operations do
> not require it.
> 
> Assisted-by: GitHub-Copilot:claude-sonnet-4.6
> Signed-off-by: Bai, Zongyao <[email protected]>

Reviewed-by: Jonathan Cavitt <[email protected]>
-Jonathan Cavitt

> ---
>  drivers/gpu/drm/xe/xe_pt.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
> index e466f714bf86..598c6b2571e7 100644
> --- a/drivers/gpu/drm/xe/xe_pt.c
> +++ b/drivers/gpu/drm/xe/xe_pt.c
> @@ -2371,8 +2371,11 @@ static void
>  xe_pt_update_ops_init(struct xe_vm_pgtable_update_ops *pt_update_ops)
>  {
>  	init_llist_head(&pt_update_ops->deferred);
> +	pt_update_ops->current_op = 0;
>  	pt_update_ops->start = ~0x0ull;
>  	pt_update_ops->last = 0x0ull;
> +	pt_update_ops->needs_svm_lock = false;
> +	pt_update_ops->needs_invalidation = false;
>  	xe_page_reclaim_list_init(&pt_update_ops->prl);
>  }
>  
> -- 
> 2.43.0
> 
>