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 DD53DD2ED0F for ; Tue, 20 Jan 2026 06:09:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A229110E4C4; Tue, 20 Jan 2026 06:09:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Cdn7ETgC"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75CE410E4C4 for ; Tue, 20 Jan 2026 06:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1768889356; x=1800425356; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=idvm3YknzyM88NezMGbYqPSoPKdFzkFstObPpdXAG14=; b=Cdn7ETgCL6UlJdtFVdEweXKdu4CQoOTseQFI++rqEYAewRFBF+sSL0as LGRcVor6XVR41QzSM0442xMExZM18jLrqODzvlF2OOebyH4TP79rITgNr qsU2/EhYX0Nio6z7QP1Tjc8hqYIJQdaH394JUVCy4bkM7lw6UO4yzHuw4 UFK9ZALJp7cdENDnfCrMwLuzDP6a2zlb7+/WM6vBAzkSmc58fCq9Hbjhu fIGJbMNK78Koxnntqpe9wN+YlTqPvJxmaCAMitqAvJI8IxR8VyvOyYrNZ KGOIh49Jhue6tNXJxmDND3lTY81ZKjFsafDytERmqKBXIwgPGwRVm1OFX A==; X-CSE-ConnectionGUID: sa95EuzeTJmkpMIJcMJE4w== X-CSE-MsgGUID: q4zeNREFSyiXqnAgjXG7aw== X-IronPort-AV: E=McAfee;i="6800,10657,11676"; a="72676975" X-IronPort-AV: E=Sophos;i="6.21,240,1763452800"; d="scan'208";a="72676975" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2026 22:09:16 -0800 X-CSE-ConnectionGUID: rBX2EcngTZm/d1msi0cR1g== X-CSE-MsgGUID: 9ikvLTwSSXaTfChkkU7LFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,240,1763452800"; d="scan'208";a="205658594" Received: from varungup-desk.iind.intel.com ([10.190.238.71]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2026 22:09:15 -0800 From: Arvind Yadav To: intel-xe@lists.freedesktop.org Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com, thomas.hellstrom@linux.intel.com, pallavi.mishra@intel.com Subject: [PATCH v4 1/8] drm/xe/uapi: Add UAPI support for purgeable buffer objects Date: Tue, 20 Jan 2026 11:38:47 +0530 Message-ID: <20260120060900.3137984-2-arvind.yadav@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120060900.3137984-1-arvind.yadav@intel.com> References: <20260120060900.3137984-1-arvind.yadav@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" From: Himal Prasad Ghimiray Extend the DRM_XE_MADVISE ioctl to support purgeable buffer object management by adding DRM_XE_VMA_ATTR_PURGEABLE_STATE attribute type. This allows userspace applications to provide memory usage hints to the kernel for better memory management under pressure: This allows userspace applications to provide memory usage hints to the kernel for better memory management under pressure: - WILLNEED: Buffer is needed and should not be purged. If the BO was previously purged, retained field returns 0 indicating backing store was lost (once purged, always purged semantics matching i915). - DONTNEED: Buffer is not currently needed and may be purged by the kernel under memory pressure to free resources. Only applies to non-shared BOs. The implementation includes a 'retained' output field (matching i915's drm_i915_gem_madvise.retained) that indicates whether the BO's backing store still exists (1) or has been purged (0). v2: - Add PURGED state for read-only status, change ioctl to DRM_IOWR, add retained field for i915 compatibility v3: - UAPI rule should not be changed (Matthew Brost) - Make 'retained' a userptr (Matthew Brost) v4: - You cannot make this part of the union (purge_state_val) larger than the existing union (16 bytes). So just drop the '__u64 reserved' field. (Matt) Cc: Matthew Brost Cc: Thomas Hellström Signed-off-by: Himal Prasad Ghimiray Signed-off-by: Arvind Yadav --- include/uapi/drm/xe_drm.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h index 077e66a682e2..7b3901e4b85e 100644 --- a/include/uapi/drm/xe_drm.h +++ b/include/uapi/drm/xe_drm.h @@ -2099,6 +2099,7 @@ struct drm_xe_madvise { #define DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC 0 #define DRM_XE_MEM_RANGE_ATTR_ATOMIC 1 #define DRM_XE_MEM_RANGE_ATTR_PAT 2 +#define DRM_XE_VMA_ATTR_PURGEABLE_STATE 3 /** @type: type of attribute */ __u32 type; @@ -2189,6 +2190,42 @@ struct drm_xe_madvise { /** @pat_index.reserved: Reserved */ __u64 reserved; } pat_index; + + /** + * @purge_state_val: Purgeable state configuration + * + * Used when @type == DRM_XE_VMA_ATTR_PURGEABLE_STATE. + * + * Configures the purgeable state of buffer objects in the specified + * virtual address range. This allows applications to hint to the kernel + * about bo's usage patterns for better memory management. + * + * Supported values for @purge_state_val.val: + * - DRM_XE_VMA_PURGEABLE_STATE_WILLNEED (0): Marks BO as needed. + * If BO was purged, returns retained=0 (backing store lost). + * + * - DRM_XE_VMA_PURGEABLE_STATE_DONTNEED (1): Hints that BO is not + * currently needed. Kernel may purge it under memory pressure. + * Only applies to non-shared BOs. Returns retained=1 if not purged. + */ + struct { +#define DRM_XE_VMA_PURGEABLE_STATE_WILLNEED 0 +#define DRM_XE_VMA_PURGEABLE_STATE_DONTNEED 1 + /** @purge_state_val.val: value for DRM_XE_VMA_ATTR_PURGEABLE_STATE */ + __u32 val; + + /* @purge_state_val.pad */ + __u32 pad; + /** + * @purge_state_val.retained: Pointer to output field for backing + * store status. + * + * Userspace provides a pointer to u32. Kernel writes to it: + * 1 if backing store exists, 0 if purged. + * Similar to i915's drm_i915_gem_madvise.retained field. + */ + __u64 retained; + } purge_state_val; }; /** @reserved: Reserved */ -- 2.43.0