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 DB129FD5F85 for ; Wed, 8 Apr 2026 07:36:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DEE710E565; Wed, 8 Apr 2026 07:36:14 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="IvaJlA80"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A8D410E565 for ; Wed, 8 Apr 2026 07:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775633758; x=1807169758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M6hm8ZkbKvuJ26ePe/3x8XTG7xSGJhFbDLD2U/MyYb4=; b=IvaJlA80/qTjcCTlMqelEPmXd26hMxpwfEhJwYAzha10vaZGd3sns3ol qq7zPEVOnLir9BofTafk3BzqU2zBK95Z8IuM4AKRJCUy9bYnCyLrM8dyO ijyC5Ao7IS6rGg1u2yQzoRoAPTyDhxVqkKRURmOZR7hsWnSSdLI7IG9Yb 8OIqAArq3qmrmrU+ceFm+jkuQlPqGOkLmDpZhQkG8+6bVng4HUcqh63/D hy8OADw4eJqU8Y6/5XqyGtCoLcARVn0KpjFiaTZRrb2pwU3qYfJxR3skE BVZVgjC1V8ufHS0mNFsJkIgqviRNTP8uW5ULXo20/S9AZHJ6N7tP5j4L5 g==; X-CSE-ConnectionGUID: g4rGPguKQmCsKxUt7/n+yA== X-CSE-MsgGUID: MB2k6eMhQaSW/yArEJn3+Q== X-IronPort-AV: E=McAfee;i="6800,10657,11752"; a="76488717" X-IronPort-AV: E=Sophos;i="6.23,167,1770624000"; d="scan'208";a="76488717" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2026 00:35:58 -0700 X-CSE-ConnectionGUID: o5SWpHpARUKiEDKVXcc6pg== X-CSE-MsgGUID: SHeq4LJNS/ex6fW/WjO6RQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,167,1770624000"; d="scan'208";a="233277964" Received: from dut6245dg2frd.fm.intel.com ([10.80.54.109]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2026 00:35:57 -0700 From: Sobin Thomas To: igt-dev@lists.freedesktop.org Cc: thomas.hellstrom@intel.com, nishit.sharma@intel.com, Sobin Thomas Subject: [PATCH i-g-t v10 1/2] lib/xe: Add failable variant of xe_vm_bind_lr_sync() Date: Wed, 8 Apr 2026 07:35:45 +0000 Message-ID: <20260408073546.3500698-2-sobin.thomas@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260408073546.3500698-1-sobin.thomas@intel.com> References: <20260408073546.3500698-1-sobin.thomas@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" Add __xe_vm_bind_lr_sync helper function which returns standard error codes instead of asserting on failure. This allows calling function to handle VM bind failures explicitly while preserving the existing xe_vm_bind_lr_sync() wrapper for tests. This enables callers that expect bind / overcommit failures. v7: Introduced xe_vm_bind_lr_sync_failable (Thomas) v8: Modified xe_vm_bind_lr_sync_failable and xe_vm_bind_lr_sync to call __xe_vm_bind_lr_sync v9: Removed redundant typecast and removed xe_vm_bind_lr_sync_failable Signed-off-by: Sobin Thomas --- lib/xe/xe_ioctl.c | 35 +++++++++++++++++++++++++---------- lib/xe/xe_ioctl.h | 2 ++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 7a8444095..bf5c80b71 100644 --- a/lib/xe/xe_ioctl.c +++ b/lib/xe/xe_ioctl.c @@ -827,23 +827,38 @@ void xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, } #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) +int __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)); + 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), + .addr = to_user_pointer(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); + int ret = 0; + + if (!sync_addr) + return -ENOMEM; + WRITE_ONCE(*sync_addr, 0); + ret = __xe_vm_bind(fd, vm, 0, bo, offset, addr, size, DRM_XE_VM_BIND_OP_MAP, flags, + &sync, 1, 0, DEFAULT_PAT_INDEX, 0); + if (ret) + goto out; + + if (READ_ONCE(*sync_addr) != BIND_SYNC_VAL) + xe_wait_ufence(fd, sync_addr, BIND_SYNC_VAL, 0, NSEC_PER_SEC * 10); /* Only free if the wait succeeds */ - free((void *)sync_addr); +out: + free(sync_addr); + return ret; +} + +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) +{ + igt_assert_eq(__xe_vm_bind_lr_sync(fd, vm, bo, offset, addr, size, flags), 0); } void xe_vm_unbind_lr_sync(int fd, uint32_t vm, uint64_t offset, diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h index 4ac526a8e..e81f79bbb 100644 --- a/lib/xe/xe_ioctl.h +++ b/lib/xe/xe_ioctl.h @@ -118,6 +118,8 @@ struct drm_xe_mem_range_attr 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); +int __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.52.0