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 1FFAFD1D866 for ; Thu, 4 Dec 2025 05:10:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 66CB110E1B8; Thu, 4 Dec 2025 05:10:53 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="PB14TYvp"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9343410E00D for ; Thu, 4 Dec 2025 05:10:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764825053; x=1796361053; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=yK6PYkTbpPP7fSNcu4ZNHyfghdNWljfJE40V6PzfXd0=; b=PB14TYvpjzcoxHgQFOy6OIyZ2g85H7JFEnOYJSLsVfqZtrr1UZFBT0a7 Y35ePflD35B757BlcG2xpbfUxgiyNV69cYaxcteH4XR9lRC+I+kJHWySj s7wlWit853hR2tpgyoQGJgE+XGaj5C4qPHp6/8fI3FdmcRTT906Nrc3fQ Cf2ePTl4OYLiKhVNzcTDpIxA1yTO0/HhAHJuQx5J9S9B/4IJtpPLmMT1N uAwAdwDsCjoV2oS2uGLL7KjaTyb6YOCyjJYpkhLQdYfb3nCH63nUdbFW2 nMPcFJR9E2PqUhPuV5YP4qZ9yZcyv6J5U2FXDIKt0WeS9x5Gz699XXfCE g==; X-CSE-ConnectionGUID: iBASJ+yZSa2CgCStE92oAg== X-CSE-MsgGUID: 1GVlRI8wQfyRsjVqIVed5A== X-IronPort-AV: E=McAfee;i="6800,10657,11631"; a="92314034" X-IronPort-AV: E=Sophos;i="6.20,248,1758610800"; d="scan'208";a="92314034" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2025 21:10:52 -0800 X-CSE-ConnectionGUID: AG0aDpAJSt+sXlBCvAiIqQ== X-CSE-MsgGUID: 5R5Ck3NrRiyDf3Dyov42cw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,248,1758610800"; d="scan'208";a="195678341" Received: from dut7069bmgfrd.fm.intel.com (HELO DUT7069BMGFRD..) ([10.1.40.43]) by fmviesa010.fm.intel.com with ESMTP; 03 Dec 2025 21:10:51 -0800 From: nishit.sharma@intel.com To: igt-dev@lists.freedesktop.org, nishit.sharma@intel.com, thomas.hellstrom@intel.com Subject: [PATCH v11 02/10] lib/xe: Add synchronous helpers for VM bind/unbind operations Date: Thu, 4 Dec 2025 05:10:43 +0000 Message-ID: <20251204051051.27495-3-nishit.sharma@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251204051051.27495-1-nishit.sharma@intel.com> References: <20251204051051.27495-1-nishit.sharma@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Nishit Sharma Introduce synchronous wrappers for VM bind/unbind operations that handle user fence allocation, waiting, and cleanup internally. This simplifies test code by eliminating repetitive synchronization boilerplate. Signed-off-by: Nishit Sharma Reviewed-by: Thomas Hellström Reviewed-by: Pravalika Gurram --- lib/xe/xe_ioctl.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 221fd7c62..e245f810c 100644 --- a/lib/xe/xe_ioctl.c +++ b/lib/xe/xe_ioctl.c @@ -747,3 +747,42 @@ void xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, igt_assert_eq(__xe_vm_madvise(fd, vm, addr, range, ext, type, op_val, policy, instance), 0); } + +#define BIND_SYNC_VAL 0x686868 +void xe_vm_bind_lr_sync(int fd, uint32_t vm, uint32_t bo, uint64_t offset, + uint64_t addr, uint64_t size, uint32_t flags) +{ + volatile uint64_t *sync_addr = malloc(sizeof(*sync_addr)); + struct drm_xe_sync sync = { + .flags = DRM_XE_SYNC_FLAG_SIGNAL, + .type = DRM_XE_SYNC_TYPE_USER_FENCE, + .addr = to_user_pointer((uint64_t *)sync_addr), + .timeline_value = BIND_SYNC_VAL, + }; + + igt_assert(!!sync_addr); + xe_vm_bind_async_flags(fd, vm, 0, bo, 0, addr, size, &sync, 1, flags); + if (*sync_addr != BIND_SYNC_VAL) + xe_wait_ufence(fd, (uint64_t *)sync_addr, BIND_SYNC_VAL, 0, NSEC_PER_SEC * 10); + /* Only free if the wait succeeds */ + free((void *)sync_addr); +} + +void xe_vm_unbind_lr_sync(int fd, uint32_t vm, uint64_t offset, + uint64_t addr, uint64_t size) +{ + volatile uint64_t *sync_addr = malloc(sizeof(*sync_addr)); + struct drm_xe_sync sync = { + .flags = DRM_XE_SYNC_FLAG_SIGNAL, + .type = DRM_XE_SYNC_TYPE_USER_FENCE, + .addr = to_user_pointer((uint64_t *)sync_addr), + .timeline_value = BIND_SYNC_VAL, + }; + + igt_assert(!!sync_addr); + *sync_addr = 0; + xe_vm_unbind_async(fd, vm, 0, 0, addr, size, &sync, 1); + if (*sync_addr != BIND_SYNC_VAL) + xe_wait_ufence(fd, (uint64_t *)sync_addr, BIND_SYNC_VAL, 0, NSEC_PER_SEC * 10); + free((void *)sync_addr); +} -- 2.48.1