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 829A8E99056 for ; Fri, 10 Apr 2026 08:28:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2FDAC10E1B0; Fri, 10 Apr 2026 08:28:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="B2UNXBzG"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7394E10E87C for ; Fri, 10 Apr 2026 08:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775809673; x=1807345673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W3OEylo8qbk7WNa12MorYKfJscGbIORDelhF2/ceGjE=; b=B2UNXBzGzFAS5dhekvR9RGbTakt4FM5ZrKTySTiPP9Rcb7Rhnu+T9rNl jlWlXHuvqEvvaH6yVPirrPPfIDEfp601CqGvxA0s9mTAQe1JVNt5JEL8R D0EF3P3XIjFQB1g5RyG13zNqCHh64OqVtdqhfzgh9qjaG4CT/fISXrrEX JZx2bSlQvZzuWTuJ+2ojSGcRmW9JRxrzgtWPQD/CEJ1xhl4q40dE8sAj+ sQqp/lE9DaZxjclbWdC4OUoUmguQXzxQm+ViOzOcpSYpoSHV2E39XoMDi SKSSeQWu5y/vYTNS10Lyc99hN8OlnSX6lTcipuxxWDU3jKIA8Y0eU9bN0 Q==; X-CSE-ConnectionGUID: lt2nssJET2WQNlE2SIPlDg== X-CSE-MsgGUID: Xbp+sizzSu+CAbFnXGojgQ== X-IronPort-AV: E=McAfee;i="6800,10657,11754"; a="64361533" X-IronPort-AV: E=Sophos;i="6.23,171,1770624000"; d="scan'208";a="64361533" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 01:27:52 -0700 X-CSE-ConnectionGUID: 4yRNyf1ISEyfby9dVtwkfg== X-CSE-MsgGUID: hujTAdHMR9OX0Vg4GjFNzw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,171,1770624000"; d="scan'208";a="229301943" Received: from varungup-desk.iind.intel.com ([10.190.238.71]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 01:27:50 -0700 From: Arvind Yadav To: igt-dev@lists.freedesktop.org Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com, thomas.hellstrom@linux.intel.com, nishit.sharma@intel.com, pravalika.gurram@intel.com Subject: [PATCH i-g-t v8 1/8] lib/xe: Add purgeable memory ioctl support Date: Fri, 10 Apr 2026 13:57:18 +0530 Message-ID: <20260410082729.2383886-2-arvind.yadav@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260410082729.2383886-1-arvind.yadav@intel.com> References: <20260410082729.2383886-1-arvind.yadav@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" Add xe_vm_madvise_purgeable() helper function to support purgeable memory management through the XE madvise ioctl. This allows applications to hint to the kernel about buffer object usage patterns for better memory management under pressure. The function provides a clean interface to: - Mark buffer objects as DONTNEED (purgeable) - Mark buffer objects as WILLNEED (not purgeable) Returns the retained value directly (1 if backing store exists, 0 if purged). Also update __xe_vm_madvise() to reject purgeable state operations and direct users to the dedicated helper. Here purgeable state requires an output (retained_ptr) field, which does not fit the generic type/op_val model of __xe_vm_madvise(). Add a dedicated helper that populates the purgeable-specific ioctl fields and returns the retained value directly. v2: - retained must be initialized to 0(Thomas) v5: - Rename retained to retained_ptr. (Jose) v7: - Mention this new ioctl instead of __xe_vm_madvise(). (Nishit) Cc: Matthew Brost Cc: Thomas Hellström Cc: Himal Prasad Ghimiray Cc: Pravalika Gurram Reviewed-by: Nishit Sharma Signed-off-by: Arvind Yadav --- lib/xe/xe_ioctl.c | 33 +++++++++++++++++++++++++++++++++ lib/xe/xe_ioctl.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 7a8444095..1dae56444 100644 --- a/lib/xe/xe_ioctl.c +++ b/lib/xe/xe_ioctl.c @@ -790,6 +790,9 @@ int __xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, case DRM_XE_MEM_RANGE_ATTR_PAT: madvise.pat_index.val = op_val; break; + case DRM_XE_VMA_ATTR_PURGEABLE_STATE: + /* Purgeable state handled by xe_vm_madvise_purgeable */ + return -EINVAL; default: igt_warn("Unknown attribute\n"); return -EINVAL; @@ -826,6 +829,36 @@ void xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, instance), 0); } +/** + * xe_vm_madvise_purgeable: + * @fd: xe device fd + * @vm_id: vm_id of the virtual range + * @start: start of the virtual address range + * @range: size of the virtual address range + * @state: purgeable state (DRM_XE_VMA_PURGEABLE_STATE_WILLNEED or DONTNEED) + * + * Sets the purgeable state for a virtual memory range. This allows applications + * to hint to the kernel about buffer object usage patterns for better memory management. + * + * Returns: retained value (1 if backing store exists, 0 if purged) + */ +uint32_t xe_vm_madvise_purgeable(int fd, uint32_t vm_id, uint64_t start, + uint64_t range, uint32_t state) +{ + uint32_t retained_val = 0; + struct drm_xe_madvise madvise = { + .vm_id = vm_id, + .start = start, + .range = range, + .type = DRM_XE_VMA_ATTR_PURGEABLE_STATE, + .purge_state_val.val = state, + .purge_state_val.retained_ptr = (uint64_t)(uintptr_t)&retained_val, + }; + + igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise), 0); + return retained_val; +} + #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) diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h index 4ac526a8e..ceb380685 100644 --- a/lib/xe/xe_ioctl.h +++ b/lib/xe/xe_ioctl.h @@ -109,6 +109,8 @@ int __xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, uint64_t uint32_t type, uint32_t op_val, uint16_t policy, uint16_t instance); 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, uint16_t instance); +uint32_t xe_vm_madvise_purgeable(int fd, uint32_t vm_id, uint64_t start, + uint64_t range, uint32_t state); 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); -- 2.43.0