From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47A7EC624D3 for ; Wed, 2 Sep 2026 14:55:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EE2AF10E021; Wed, 2 Sep 2026 14:54:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="W/iz8uxT"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 554F810F266 for ; Wed, 2 Sep 2026 14:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1788360899; x=1819896899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9XsWCITvGtKNQJ8y9WAXy45Ckhxd5siGQK339YInmBw=; b=W/iz8uxTgmjuF5S6ejTWcvCpdgknh/qi4sPL/rSlxIV00gHejhEN2KOd STRoM0uSbAfMaqK9lHhba2WEvSUWiIEwmhGMQL6uVFr8PJ3XLYcbt6hbb na7df9m1pbJkcC8B7Ec9nAS6GX9SSrC+j1SliGCtYf6N7gmjcQkDkW6UK DM1j4qtkAmSjhjQrdBt9Ha7LHxRCiAqzHp2eHpnLBuuITmJtOsn1RzLJn LbaVwCFniVnOhxKCqXWAHkRl/pLnsL6FFk1tbiPuEgtsp5d3Ps+c6Qh83 36fmV+BzVPzZI0u67PSIapEghaI78AebfdS1tVkmeMW/QdEmMtGty/6zN w==; X-CSE-ConnectionGUID: qqZEpyreSxuHhew3PZHQgg== X-CSE-MsgGUID: Pv9zZ+JkReasOpqlGZGing== X-IronPort-AV: E=McAfee;i="6800,10657,11894"; a="92526009" X-IronPort-AV: E=Sophos;i="6.25,258,1779174000"; d="scan'208";a="92526009" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2026 07:54:59 -0700 X-CSE-ConnectionGUID: wT/fJNCYTKaXOOdH2ONE9A== X-CSE-MsgGUID: 6QVzRX0cTNyM+ER3UdmNFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,258,1779174000"; d="scan'208";a="263260017" Received: from tejasupa-desk.iind.intel.com (HELO tejasupa-desk) ([10.190.239.37]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2026 07:54:56 -0700 From: Tejas Upadhyay To: intel-xe@lists.freedesktop.org Cc: himal.prasad.ghimiray@intel.com, rodrigo.vivi@intel.com, Matthew Brost , Tejas Upadhyay Subject: [PATCH V20 06/15] drm/xe: Guard teardown paths against purged BOs Date: Wed, 2 Sep 2026 20:23:49 +0530 Message-ID: <20260902145343.465686-23-tejas.upadhyay@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260902145343.465686-17-tejas.upadhyay@intel.com> References: <20260902145343.465686-17-tejas.upadhyay@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" VRAM page offlining can purge BOs that are still referenced by page tables, exec queues, and DMA-buf exports. Add xe_bo_is_purged() guards in the teardown paths to prevent unpinning or mapping an already-purged BO: - xe_bo_unpin_map_no_vm(): skip unpin if purged - xe_dma_buf_map(): return -ENOENT early if purged - xe_exec_queue_update_run_ticks(): skip LRC timestamp read if purged - xe_pt_destroy(): skip unpin if purged v4(Sashiko): - Move bo purge check in xe_bo_unpin() to handle all instances v3(Sashiko): - Remove dma_resv is already held v2(Himal): - take dma_resv lock before calling xe_bo_is_purged() Reviewed-by: Himal Prasad Ghimiray Signed-off-by: Tejas Upadhyay --- drivers/gpu/drm/xe/xe_bo.c | 3 +++ drivers/gpu/drm/xe/xe_dma_buf.c | 3 +++ drivers/gpu/drm/xe/xe_exec_queue.c | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index c255327669da..b162753cebb7 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -3267,6 +3267,9 @@ void xe_bo_unpin(struct xe_bo *bo) struct ttm_place *place = &bo->placements[0]; struct xe_device *xe = xe_bo_device(bo); + if (xe_bo_is_purged(bo)) + return; + xe_assert(xe, !bo->ttm.base.import_attach); xe_assert(xe, xe_bo_is_pinned(bo)); diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c index bf0728838ead..5d9f1cd24b7f 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -104,6 +104,9 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach, struct sg_table *sgt; int r = 0; + if (xe_bo_is_purged(bo)) + return ERR_PTR(-ENOENT); + if (!attach->peer2peer && !xe_bo_can_migrate(bo, XE_PL_TT)) return ERR_PTR(-EOPNOTSUPP); diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c index f3ea4807ac33..e63559a2f582 100644 --- a/drivers/gpu/drm/xe/xe_exec_queue.c +++ b/drivers/gpu/drm/xe/xe_exec_queue.c @@ -1630,8 +1630,12 @@ void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q) * errors. */ lrc = q->lrc[0]; - new_ts = xe_lrc_update_timestamp(lrc, &old_ts); - q->xef->run_ticks[q->class] += (new_ts - old_ts) * q->width; + xe_bo_lock(lrc->bo, false); + if (!xe_bo_is_purged(lrc->bo)) { + new_ts = xe_lrc_update_timestamp(lrc, &old_ts); + q->xef->run_ticks[q->class] += (new_ts - old_ts) * q->width; + } + xe_bo_unlock(lrc->bo); drm_dev_exit(idx); } -- 2.52.0