From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367212; b=cg55n375eEq8u48Gs4ArGuwUhAN4g3H1KT1oSTxcoMdvJAOn6fFKfHzpt/PDpXqtLP4C t71DA3lrLFEE2zTs8kLFCcCTYga1yjnaIX0aVXrvmfXAI2ekLcntzW+vGHhm47fzTK0cJ qlgXHs3GwxSHh+D821HDPV+abRNM622BluwuzZKIAhMjeIPfXiYf7ysS5fM1ypMpQgzfD 3tH8k6XP9zEyRhPN7l8ZNSfW8lpiDjdhvWnI4zbWfH1oOJ1H+5/9Nt6Tzm54MnjS+q/uC y8tRBQb0wo4fRZKZzPC4+n6X0PK6YfS1zdGHMNwO179gG2r++hx8MM+U3U7i0cuBwig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367212; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=u/iZoRdtTk5IALIvip1Hfkc/e/IV53oZeA79fZdWefI=; b=URPHWNL3eIHnZ4k6y1UJRbTxKnr+23iJyHYYZXjHGFiZdGFLXv0AXMbmViC0I/D9vtcw 5is7QdUFBZlshF57O/GKDRsvn2VTDNocDqbK9fFV5FzM0H76kki7EO1wgACjDSlA+nYMk jgU0QlcdwFx9bdkPZjWDgdB5HszotWZtQEsFu1B28Vs+rpvOd3GUnKSM5jIQPCNDvzoVN t9v+hKax7TpGdAYEOiWjuv+ChtA/rFV+SxiDQtNVloRncgfKNuKQ1Sbuzxrlu/v11HhB1 3ukR7TwzFu9OKMK6LBnPk7lKQqlbwDBhAj1/qxFdQehCLibgWHO0cBA9jHsa5tTH1sQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="C/5uz2Yw"; arc=none smtp.remote-ip=198.175.65.15 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58505606A68B for ; Fri, 4 Dec 2026 06:53:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 58505606A68B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=C/5uz2Yw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796367212; x=1827903212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u/iZoRdtTk5IALIvip1Hfkc/e/IV53oZeA79fZdWefI=; b=C/5uz2YwAtluTlZJXIDVheNMJdDmNt1PqdIAOeCOnBWBU+kr57V6JzG8 rYNA1eb0SVtCD8rWqNrEi/TE3lD4i8oyhjtOl2/m53fqlCmw/SIJezNIK 2uK1ZKT028ABujcmm8w/2ws/h5qQsJKkvnuQ8ZZ+s3dkB9L39bA1amLL0 F0u3m6/Zq8klQeFJZUwfbcWoHHzeV7pN/ItUgajlWVKgYcJvRDUVKG3g+ +rOcbXni1H7oL+diV0aF6YHwL12hFATaZpZxA060qLgw/NSk+A8WGzbrj +uTxRl5qzuV2Y4cnRPE99szXso+wBAH5fFjNm6CDsMmIb59PDzgDL4+X5 A==; X-CSE-ConnectionGUID: 8rMjWOpXQBOHIwbPLLUFQw== X-CSE-MsgGUID: mWb/MUslQ4ecGgNQi4WAzA== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5341210" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5341210" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:53:32 -0800 X-CSE-ConnectionGUID: BCvoq++tRemwO2czKU1tfA== X-CSE-MsgGUID: /QjBKFOeQaW+HygwVow0Ng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="13917097" Received: from varungup-desk.iind.intel.com ([10.190.238.71]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:53:30 -0800 From: Arvind Yadav To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, himal.prasad.ghimiray@intel.com Subject: [PATCH v2 1/2] drm/xe: Snapshot inline DMA addresses before staging page tables Date: Fri, 4 Dec 2026 12:23:17 +0530 Message-ID: <20261204065318.1785149-2-arvind.yadav@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204065318.1785149-1-arvind.yadav@intel.com> References: <20261204065318.1785149-1-arvind.yadav@intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clearing inline DMA storage during unmap can race with xe_pt_stage_bind(). The userptr path reads it without notifier_lock, and the SVM path keeps a pointer after releasing the lock. Protect the userptr lookup with notifier_lock and copy inline entries for both paths. Use the copy throughout page-table staging. For invalidated userptrs, return -EAGAIN in fault mode. Otherwise, stage cleared PTEs and keep those tiles marked invalidated at commit until exec or the rebind worker repins and rebinds them. This prepares Xe for clearing inline DMA storage during unmap. v2: - Add a preparatory Xe patch to protect DMA lookup and snapshot inline entries for userptr and SVM binds. Cc: Matthew Brost Cc: Thomas Hellström Cc: Himal Prasad Ghimiray Signed-off-by: Arvind Yadav --- drivers/gpu/drm/xe/xe_pt.c | 82 ++++++++++++++++++++++++++++---- drivers/gpu/drm/xe/xe_pt_types.h | 2 + 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c index 0e0bf428df0f..4a6135ab2c8d 100644 --- a/drivers/gpu/drm/xe/xe_pt.c +++ b/drivers/gpu/drm/xe/xe_pt.c @@ -770,6 +770,7 @@ static u32 xe_pt_target_leaf_level_from_bo(struct xe_device *xe, * the main tree at commit time. * @num_entries: On output contains the number of @entries used. * @clear_pt: Clear the page table entries. + * @pt_cleared: Whether the staged page table entries were cleared. * * This function builds a disconnected page-table tree for a given address * range. The tree is connected to the main vm tree for the gpu using @@ -784,11 +785,12 @@ static int xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, struct xe_svm_range *range, struct xe_vm_pgtable_update *entries, - u32 *num_entries, bool clear_pt) + u32 *num_entries, bool clear_pt, bool *pt_cleared) { struct xe_device *xe = tile_to_xe(tile); struct xe_bo *bo = xe_vma_bo(vma); struct xe_res_cursor curs = {}; + struct drm_pagemap_addr inline_addr; struct xe_vm *vm = xe_vma_vm(vma); struct xe_pt_stage_bind_walk xe_walk = { .base = { @@ -842,6 +844,11 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, bool contiguous; addr = xe_svm_range_first_dma(range, &contiguous); + /* Keep inline storage stable after dropping the notifier lock. */ + if (contiguous) { + inline_addr = *addr; + addr = &inline_addr; + } xe_res_first_dma(addr, 0, xe_svm_range_size(range), contiguous, &curs); xe_svm_range_debug(range, "BIND PREPARE - MIXED"); @@ -876,13 +883,38 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, if (!xe_vma_is_null(vma) && !range && !is_purged) { if (xe_vma_is_userptr(vma)) { + struct xe_userptr_vma *uvma = to_userptr_vma(vma); const struct drm_pagemap_addr *addr; bool contiguous; - addr = drm_gpusvm_pages_first_dma(&to_userptr_vma(vma)->userptr.pages, - &contiguous); + xe_svm_notifier_lock(vm); + if (xe_vma_userptr_check_repin(uvma)) + addr = NULL; + else + addr = drm_gpusvm_pages_first_dma(&uvma->userptr.pages, + &contiguous); + if (!addr) { + xe_svm_notifier_unlock(vm); + if (xe_vm_in_fault_mode(vm)) + return -EAGAIN; + + /* Exec or the rebind worker will repin invalidated userptrs. */ + xe_walk.clear_pt = true; + curs.size = xe_vma_size(vma); + goto walk_pt; + } + if (contiguous) { + inline_addr = *addr; + addr = &inline_addr; + } xe_res_first_dma(addr, 0, xe_vma_size(vma), contiguous, &curs); + /* + * The snapshot protects cursor storage, not the DMA mapping. + * Fault-mode binds recheck validity at pre-commit. Other VMs + * repin and rebind invalidated userptrs before execution. + */ + xe_svm_notifier_unlock(vm); } else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo)) xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma), xe_vma_size(vma), &curs); @@ -900,6 +932,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, &xe_walk.base); *num_entries = xe_walk.wupd.num_used_entries; + *pt_cleared = xe_walk.clear_pt; return ret; } @@ -1291,13 +1324,14 @@ static int xe_pt_prepare_bind(struct xe_tile *tile, struct xe_vma *vma, struct xe_svm_range *range, struct xe_vm_pgtable_update *entries, - u32 *num_entries, bool invalidate_on_bind) + u32 *num_entries, bool invalidate_on_bind, bool *pt_cleared) { int err; *num_entries = 0; + *pt_cleared = false; err = xe_pt_stage_bind(tile, vma, range, entries, num_entries, - invalidate_on_bind); + invalidate_on_bind, pt_cleared); if (!err) xe_tile_assert(tile, *num_entries); @@ -2166,7 +2200,8 @@ static int bind_op_prepare(struct xe_vm *vm, struct xe_tile *tile, return err; err = xe_pt_prepare_bind(tile, vma, NULL, pt_op->entries, - &pt_op->num_entries, invalidate_on_bind); + &pt_op->num_entries, invalidate_on_bind, + &pt_op->pt_cleared); if (!err) { xe_tile_assert(tile, pt_op->num_entries <= ARRAY_SIZE(pt_op->entries)); @@ -2234,7 +2269,7 @@ static int bind_range_prepare(struct xe_vm *vm, struct xe_tile *tile, pt_op->rebind = BIT(tile->id) & range->tile_present; err = xe_pt_prepare_bind(tile, vma, range, pt_op->entries, - &pt_op->num_entries, false); + &pt_op->num_entries, false, &pt_op->pt_cleared); if (!err) { xe_tile_assert(tile, pt_op->num_entries <= ARRAY_SIZE(pt_op->entries)); @@ -2869,7 +2904,6 @@ xe_pt_update_ops_run(struct xe_device *xe, struct xe_vma_ops *vops) xe_pt_commit(pt_op->vma, pt_op->entries, pt_op->num_entries, &pt_update_ops->pt_job_ops->deferred); - pt_op->vma = NULL; /* skip in xe_pt_update_ops_abort */ tile_mask |= BIT(tile->id); } } @@ -2905,6 +2939,38 @@ xe_pt_update_ops_run(struct xe_device *xe, struct xe_vma_ops *vops) tile_mask); } + /* + * op_commit() assumes a normal bind installed valid PTEs. Restore the + * actual userptr state from the staged operations, in operation order, + * before releasing the notifier lock. With shared page tables, tile 0 + * determines the state for all tiles. + */ + for_each_tile(tile, xe, j) { + struct xe_vm_pgtable_update_ops *pt_update_ops = + &vops->pt_update_ops[j]; + u8 mask = xe->info.has_pt_mirror ? BIT(tile->id) : tile_mask; + + if (pt_mirroring_disabled_for_tile(vm, j)) + continue; + + for (i = 0; i < get_current_op(pt_update_ops); ++i) { + struct xe_vm_pgtable_update_op *pt_op = + to_pt_op(pt_update_ops, i); + struct xe_vma *vma = pt_op->vma; + + if (pt_op->bind && xe_vma_is_userptr(vma)) { + /* Pairs with READ_ONCE in xe_vm_has_valid_gpu_mapping(). */ + if (pt_op->pt_cleared) + WRITE_ONCE(vma->tile_invalidated, + vma->tile_invalidated | mask); + else + WRITE_ONCE(vma->tile_invalidated, + vma->tile_invalidated & ~mask); + } + pt_op->vma = NULL; /* skip in xe_pt_update_ops_abort */ + } + } + if (needs_svm_lock) xe_pt_svm_userptr_notifier_unlock(vm); diff --git a/drivers/gpu/drm/xe/xe_pt_types.h b/drivers/gpu/drm/xe/xe_pt_types.h index 0d4bac22ee6c..56f8c2a00762 100644 --- a/drivers/gpu/drm/xe/xe_pt_types.h +++ b/drivers/gpu/drm/xe/xe_pt_types.h @@ -95,6 +95,8 @@ struct xe_vm_pgtable_update_op { bool bind; /** @rebind: is a rebind */ bool rebind; + /** @pt_cleared: bind staged cleared PTEs instead of DMA mappings */ + bool pt_cleared; }; /** -- 2.43.0