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 0FC1ACD8CAF for ; Thu, 13 Nov 2025 17:16:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6301110E8F8; Thu, 13 Nov 2025 17:16:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="BrnMHwZC"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id B698D10E8DF for ; Thu, 13 Nov 2025 17:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763054183; x=1794590183; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=Q4e0e2iSkrV9kp2bmZiPVcyhli5G/Yj4thhvnBK2PKc=; b=BrnMHwZCdX5Zj75aIxaC4Cpqji57pKdtYFwOlC2xfYqzySDVK95OTKh2 ZVSbOlrYYWCrOIa46wFEVM9B52uBOOmX5Lfyxubuztr6Wilw79XcLwva8 4ptJ4RGHJGeN53nHDj+NQ6bnjRljzesNHodT2XrQn3CnUYaAnDhuzRnv+ 6lfrXuNJy1pZ0t+T44qL7wEygkFTXX+/aigLxQntTLezpH6NvkktfNDvw 4PyC5BGoy4VaiUoqKVU51XV5V/NrIXz4GFCpM3/0zNez83f8L9RVkmVib vBC5lR17rKxFHYsinvZrFe8jtt6aRpETR4E11HbEiSA3poY5lCeTOh/nT A==; X-CSE-ConnectionGUID: 4uOFofwdSJC1Z35g2OD+8w== X-CSE-MsgGUID: OcX11N0HQAWAhSPCmmVWtA== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="64345919" X-IronPort-AV: E=Sophos;i="6.19,302,1754982000"; d="scan'208";a="64345919" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 09:16:22 -0800 X-CSE-ConnectionGUID: H/elT1T+TmOXsmFb2vCBcA== X-CSE-MsgGUID: Rcf6FPWjSP+P1LcD/jl9cA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,302,1754982000"; d="scan'208";a="194705459" Received: from dut7069bmgfrd.fm.intel.com (HELO DUT7069BMGFRD..) ([10.1.40.39]) by orviesa005.jf.intel.com with ESMTP; 13 Nov 2025 09:16:21 -0800 From: nishit.sharma@intel.com To: igt-dev@lists.freedesktop.org Subject: [PATCH i-g-t v7 01/10] lib/xe: Add instance parameter to xe_vm_madvise and introduce lr_sync helpers Date: Thu, 13 Nov 2025 17:16:12 +0000 Message-ID: <20251113171621.635811-2-nishit.sharma@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251113171621.635811-1-nishit.sharma@intel.com> References: <20251113171621.635811-1-nishit.sharma@intel.com> MIME-Version: 1.0 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 Add an 'instance' parameter to xe_vm_madvise and __xe_vm_madvise to support per-instance memory advice operations.Implement xe_vm_bind_lr_sync and xe_vm_unbind_lr_sync helpers for synchronous VM bind/unbind using user fences. These changes improve memory advice and binding operations for multi-GPU and multi-instance scenarios in IGT tests. Signed-off-by: Nishit Sharma --- include/drm-uapi/xe_drm.h | 4 +-- lib/xe/xe_ioctl.c | 53 +++++++++++++++++++++++++++++++++++---- lib/xe/xe_ioctl.h | 11 +++++--- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/include/drm-uapi/xe_drm.h b/include/drm-uapi/xe_drm.h index 89ab54935..3472efa58 100644 --- a/include/drm-uapi/xe_drm.h +++ b/include/drm-uapi/xe_drm.h @@ -2060,8 +2060,8 @@ struct drm_xe_madvise { /** @preferred_mem_loc.migration_policy: Page migration policy */ __u16 migration_policy; - /** @preferred_mem_loc.pad : MBZ */ - __u16 pad; + /** @preferred_mem_loc.region_instance: Region instance */ + __u16 region_instance; /** @preferred_mem_loc.reserved : Reserved */ __u64 reserved; diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 39c4667a1..06ce8a339 100644 --- a/lib/xe/xe_ioctl.c +++ b/lib/xe/xe_ioctl.c @@ -687,7 +687,8 @@ int64_t xe_wait_ufence(int fd, uint64_t *addr, uint64_t value, } int __xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, - uint64_t ext, uint32_t type, uint32_t op_val, uint16_t policy) + uint64_t ext, uint32_t type, uint32_t op_val, uint16_t policy, + uint16_t instance) { struct drm_xe_madvise madvise = { .type = type, @@ -704,6 +705,7 @@ int __xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, case DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: madvise.preferred_mem_loc.devmem_fd = op_val; madvise.preferred_mem_loc.migration_policy = policy; + madvise.preferred_mem_loc.region_instance = instance; igt_debug("madvise.preferred_mem_loc.devmem_fd = %d\n", madvise.preferred_mem_loc.devmem_fd); break; @@ -731,14 +733,55 @@ int __xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, * @type: type of attribute * @op_val: fd/atomic value/pat index, depending upon type of operation * @policy: Page migration policy + * @instance: vram instance * * Function initializes different members of struct drm_xe_madvise and calls * MADVISE IOCTL . * - * Asserts in case of error returned by DRM_IOCTL_XE_MADVISE. + * Returns error number in failure and 0 if pass. */ -void xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, - uint64_t ext, uint32_t type, uint32_t op_val, uint16_t policy) +int xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, + uint64_t ext, uint32_t type, uint32_t op_val, uint16_t policy, + uint16_t instance) { - igt_assert_eq(__xe_vm_madvise(fd, vm, addr, range, ext, type, op_val, policy), 0); + return __xe_vm_madvise(fd, vm, addr, range, ext, type, op_val, policy, instance); +} + +#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); } diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h index ae8a23a54..1ae38029d 100644 --- a/lib/xe/xe_ioctl.h +++ b/lib/xe/xe_ioctl.h @@ -100,13 +100,18 @@ int __xe_wait_ufence(int fd, uint64_t *addr, uint64_t value, int64_t xe_wait_ufence(int fd, uint64_t *addr, uint64_t value, uint32_t exec_queue, int64_t timeout); int __xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, uint64_t ext, - uint32_t type, uint32_t op_val, uint16_t policy); -void xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, uint64_t ext, - uint32_t type, uint32_t op_val, uint16_t policy); + uint32_t type, uint32_t op_val, uint16_t policy, uint16_t instance); +int xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, uint64_t ext, + uint32_t type, uint32_t op_val, uint16_t policy, uint16_t instance); int xe_vm_number_vmas_in_range(int fd, struct drm_xe_vm_query_mem_range_attr *vmas_attr); int xe_vm_vma_attrs(int fd, struct drm_xe_vm_query_mem_range_attr *vmas_attr, struct drm_xe_mem_range_attr *mem_attr); struct drm_xe_mem_range_attr *xe_vm_get_mem_attr_values_in_range(int fd, uint32_t vm, uint64_t start, uint64_t range, uint32_t *num_ranges); +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); +void xe_vm_unbind_lr_sync(int fd, uint32_t vm, uint64_t offset, + uint64_t addr, uint64_t size); #endif /* XE_IOCTL_H */ -- 2.48.1