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 51386CA0FE1 for ; Fri, 22 Aug 2025 08:31:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 05CAF10EA91; Fri, 22 Aug 2025 08:31:25 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="D3PsiHzO"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 04D9C10EA91 for ; Fri, 22 Aug 2025 08:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755851485; x=1787387485; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=oreWiOT7Vwd6B2aFIZ0V97RD1wcc2Z15X7PDmIbXrz0=; b=D3PsiHzOf6FSq0j2EjiPwjq0nG7VC/b0trYFT/lzJJkC8gWdVQKCSUOX BaivpskkfXjuIBtzvylyoZASHIQkP9FZvK5bN0ikg6llvGXJFWn8cZsbR KbIl/idqWA9ltRuvslPPn0qasFo4A+uY0TEndNjKVAeQGFAbp8Kk4k2kW 1UcYukpB0nLoyzSyKNKLLuW3Sq4KUM/0Q22VFGRVtOnWSqlf4c0ZgQnci lpn1MeS3v2/n/O+PWWxtabuqCTnyGay0fQUpeFw4oauLCKjLRjol8tKYf l5B6xqKqv5lRi54gKj0lk76hrMSUxJhcA5YFCEFHozmTaoNZLCT+rHnMX g==; X-CSE-ConnectionGUID: ChDoaYIqTyq5TgfTUgBNhg== X-CSE-MsgGUID: nJ6TtIzlRmaW7L2TiO/RKg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="61801501" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="61801501" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 01:31:24 -0700 X-CSE-ConnectionGUID: IkGtdXFuR7G6HVvh9ZBeZA== X-CSE-MsgGUID: vi4FkD2QQPey3CBUpjUG7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="169478987" Received: from dut2051bmgfrd.iind.intel.com ([10.190.232.68]) by fmviesa010.fm.intel.com with ESMTP; 22 Aug 2025 01:31:22 -0700 From: nishit.sharma@intel.com To: igt-dev@lists.freedesktop.org, himal.prasad.ghimiray@intel.com, nishit.sharma@intel.com Subject: [PATCH i-g-t 2/5] lib/xe: Added xe_vm_madvise ioctl support Date: Fri, 22 Aug 2025 08:31:15 +0000 Message-ID: <20250822083118.496366-3-nishit.sharma@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822083118.496366-1-nishit.sharma@intel.com> References: <20250822083118.496366-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 Added xe_vm_madvise() which issues madvise ioctl DRM_IOCTL_XE_MADVISE for VM region advising the driver about expected usage or memory policy for specified address range. MADVISE ioctl requires pointer to drm_xe_madvise structure as one of the inputs. Depending upon type of madvise operation like Atomic, Preferred LOC or PAT required members of drm_xe_madvise structure are initialized and passed in MADVISE ioctl. Signed-off-by: Nishit Sharma --- lib/xe/xe_ioctl.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ lib/xe/xe_ioctl.h | 5 ++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 1e95af409..43bad8452 100644 --- a/lib/xe/xe_ioctl.c +++ b/lib/xe/xe_ioctl.c @@ -585,3 +585,59 @@ int64_t xe_wait_ufence(int fd, uint64_t *addr, uint64_t value, igt_assert_eq(__xe_wait_ufence(fd, addr, value, exec_queue, &timeout), 0); return 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) +{ + struct drm_xe_madvise madvise = {}; + + madvise.extensions = ext; + madvise.vm_id = vm; + madvise.start = addr; + madvise.range = range; + + if (type == DRM_XE_MEM_RANGE_ATTR_ATOMIC) { + madvise.type = DRM_XE_MEM_RANGE_ATTR_ATOMIC; + madvise.atomic.val = op_val; + } else if (type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC) { + madvise.type = DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC; + madvise.preferred_mem_loc.devmem_fd = op_val; + madvise.preferred_mem_loc.migration_policy = policy; + igt_debug("madvise.preferred_mem_loc.devmem_fd = %d\n", + madvise.preferred_mem_loc.devmem_fd); + } else if (type == DRM_XE_MEM_RANGE_ATTR_PAT) { + madvise.type = DRM_XE_MEM_RANGE_ATTR_PAT; + madvise.pat_index.val = op_val; + } else { + igt_warn("Unknown attribute\n"); + return -EINVAL; + } + + if (igt_ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise)) + return -errno; + + return 0; +} + +/** + * xe_vm_madvise: + * @fd: xe device fd + * @vm: vm_id of the virtual range + * @addr: start of the virtual address range + * @range: size of the virtual address range + * @ext: Pointer to the first extension struct, if any + * @type: type of attribute + * @op_val: fd/atomic value/pat index, depending upon type of operation + * @policy: Page migration policy + * + * Function initializes different members of struct drm_xe_madvise and calls + * MADVISE IOCTL . + * + * Returns 0 if success and asserts otherwise. + */ +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) +{ + igt_assert_eq(__xe_vm_madvise(fd, vm, addr, range, ext, type, op_val, policy), 0); + return 0; +} diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h index 6302d1a7d..a5996cf65 100644 --- a/lib/xe/xe_ioctl.h +++ b/lib/xe/xe_ioctl.h @@ -99,5 +99,8 @@ int __xe_wait_ufence(int fd, uint64_t *addr, uint64_t value, uint32_t exec_queue, int64_t *timeout); 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); +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); #endif /* XE_IOCTL_H */ -- 2.43.0