public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Arvind Yadav <arvind.yadav@intel.com>, intel-xe@lists.freedesktop.org
Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com,
	 pallavi.mishra@intel.com, Jose Souze <jose.souza@intel.com>
Subject: Re: [PATCH v6 01/12] drm/xe/uapi: Add UAPI support for purgeable buffer objects
Date: Tue, 10 Mar 2026 09:31:26 +0100	[thread overview]
Message-ID: <eb2263b1eac45e018d26bacdca65337e5120aff4.camel@linux.intel.com> (raw)
In-Reply-To: <20260303152015.3499248-2-arvind.yadav@intel.com>

On Tue, 2026-03-03 at 20:49 +0530, Arvind Yadav wrote:
> From: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> 
> 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:
> 
> - 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.
> 
>   To prevent undefined behavior, the following operations are blocked
>   while a BO is in DONTNEED state:
>   - New mmap() operations return -EBUSY
>   - VM_BIND operations return -EBUSY
>   - New dma-buf exports return -EBUSY
>   - CPU page faults return SIGBUS
>   - GPU page faults fail with -EACCES
> 
>   This ensures applications cannot use a BO while marked as DONTNEED,
>   preventing erratic behavior when the kernel purges the backing
> store.
> 
> 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).
> 
> Added DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT flag to allow
> userspace to detect kernel support for purgeable buffer objects
> before attempting to use the feature.
> 
> 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)
> 
> v5:
>   - Update UAPI documentation to clarify retained must be initialized
>     to 0(Thomas)
> 
> v6:
>   - Document DONTNEED BO access blocking behavior to prevent
> undefined
>     behavior and clarify uAPI contract (Thomas, Matt)
>   - Add query flag DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT for
>     feature detection. (Jose)
>   - Rename retained to retained_ptr. (Jose)
> 
> Cc: Jose Souze <jose.souza@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Signed-off-by: Himal Prasad Ghimiray
> <himal.prasad.ghimiray@intel.com>
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>


> ---
>  include/uapi/drm/xe_drm.h | 60
> +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
> index ef2565048bdf..42aedd30189d 100644
> --- a/include/uapi/drm/xe_drm.h
> +++ b/include/uapi/drm/xe_drm.h
> @@ -425,6 +425,7 @@ struct drm_xe_query_config {
>  	#define DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY	(1
> << 1)
>  	#define DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR	(1
> << 2)
>  	#define DRM_XE_QUERY_CONFIG_FLAG_HAS_NO_COMPRESSION_HINT (1
> << 3)
> +	#define DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT	(1
> << 4)
>  #define DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT		2
>  #define DRM_XE_QUERY_CONFIG_VA_BITS			3
>  #define DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY	4
> @@ -2067,6 +2068,7 @@ struct drm_xe_query_eu_stall {
>   *  - DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: Set preferred memory
> location.
>   *  - DRM_XE_MEM_RANGE_ATTR_ATOMIC: Set atomic access policy.
>   *  - DRM_XE_MEM_RANGE_ATTR_PAT: Set page attribute table index.
> + *  - DRM_XE_VMA_ATTR_PURGEABLE_STATE: Set purgeable state for BOs.
>   *
>   * Example:
>   *
> @@ -2099,6 +2101,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 +2192,63 @@ 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 previously purged, returns
> retained=0 (backing store lost).
> +		 *
> +		 *  - DRM_XE_VMA_PURGEABLE_STATE_DONTNEED (1): Marks
> BO as not currently
> +		 *    needed. Kernel may purge it under memory
> pressure to reclaim memory.
> +		 *    Only applies to non-shared BOs. Returns
> retained=1 if not purged yet.
> +		 *
> +		 *    Important: Once marked as DONTNEED, touching
> the BO's memory
> +		 *    is undefined behavior. It may succeed
> temporarily (before the
> +		 *    kernel purges the backing store) but will
> suddenly fail once
> +		 *    the BO transitions to PURGED state.
> +		 *
> +		 *    The following operations are blocked in
> DONTNEED state to
> +		 *    prevent the BO from being re-mapped after
> madvise:
> +		 *    - New mmap() calls: Fail with -EBUSY
> +		 *    - VM_BIND operations: Fail with -EBUSY
> +		 *    - New dma-buf exports: Fail with -EBUSY
> +		 *    - CPU page faults (existing mmap): Fail with
> SIGBUS
> +		 *    - GPU page faults (fault-mode VMs): Fail with
> -EACCES
> +		 */
> +		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: MBZ */
> +			__u32 pad;
> +			/**
> +			 * @purge_state_val.retained_ptr: Pointer to
> a __u32 output
> +			 * field for backing store status.
> +			 *
> +			 * Userspace must initialize the __u32 value
> at this address
> +			 * to 0 before the ioctl. Kernel writes a
> __u32 after the
> +			 * operation:
> +			 * - 1 if backing store exists (not purged)
> +			 * - 0 if backing store was purged
> +			 *
> +			 * If userspace fails to initialize to 0,
> ioctl returns -EINVAL.
> +			 * This ensures a safe default (0 = assume
> purged) if kernel
> +			 * cannot write the result.
> +			 *
> +			 * Similar to i915's
> drm_i915_gem_madvise.retained field.
> +			 */
> +			__u64 retained_ptr;
> +		} purge_state_val;
>  	};
>  
>  	/** @reserved: Reserved */

  parent reply	other threads:[~2026-03-10  8:31 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 15:19 [PATCH v6 00/12] drm/xe/madvise: Add support for purgeable buffer objects Arvind Yadav
2026-03-03 15:19 ` [PATCH v6 01/12] drm/xe/uapi: Add UAPI " Arvind Yadav
2026-03-03 15:53   ` Souza, Jose
2026-03-20  4:00     ` Yadav, Arvind
2026-03-10  8:31   ` Thomas Hellström [this message]
2026-03-03 15:19 ` [PATCH v6 02/12] drm/xe/bo: Add purgeable bo state tracking and field madv to xe_bo Arvind Yadav
2026-03-03 15:19 ` [PATCH v6 03/12] drm/xe/madvise: Implement purgeable buffer object support Arvind Yadav
2026-03-10  8:41   ` Thomas Hellström
2026-03-03 15:20 ` [PATCH v6 04/12] drm/xe/bo: Block CPU faults to purgeable buffer objects Arvind Yadav
2026-03-05 15:26   ` Thomas Hellström
2026-03-03 15:20 ` [PATCH v6 05/12] drm/xe/vm: Prevent binding of purged " Arvind Yadav
2026-03-05 15:38   ` Thomas Hellström
2026-03-20  2:34     ` Yadav, Arvind
2026-03-03 15:20 ` [PATCH v6 06/12] drm/xe/madvise: Implement per-VMA purgeable state tracking Arvind Yadav
2026-03-10  9:57   ` Thomas Hellström
2026-03-23  6:47     ` Yadav, Arvind
2026-03-03 15:20 ` [PATCH v6 07/12] drm/xe/madvise: Block imported and exported dma-bufs Arvind Yadav
2026-03-03 15:20 ` [PATCH v6 08/12] drm/xe/bo: Block mmap of DONTNEED/purged BOs Arvind Yadav
2026-03-10 10:17   ` Thomas Hellström
2026-03-18 13:03     ` Yadav, Arvind
2026-03-03 15:20 ` [PATCH v6 09/12] drm/xe/dma_buf: Block export " Arvind Yadav
2026-03-10 10:19   ` Thomas Hellström
2026-03-18 13:02     ` Yadav, Arvind
2026-03-03 15:20 ` [PATCH v6 10/12] drm/xe/bo: Add purgeable shrinker state helpers Arvind Yadav
2026-03-10 10:01   ` Thomas Hellström
2026-03-18 12:15     ` Yadav, Arvind
2026-03-03 15:20 ` [PATCH v6 11/12] drm/xe/madvise: Enable purgeable buffer object IOCTL support Arvind Yadav
2026-03-10 10:23   ` Thomas Hellström
2026-03-03 15:20 ` [PATCH v6 12/12] drm/xe/bo: Skip zero-refcount BOs in shrinker Arvind Yadav
2026-03-05 15:49   ` Thomas Hellström
2026-03-17  5:59     ` Yadav, Arvind
2026-03-03 16:12 ` ✗ CI.checkpatch: warning for drm/xe/madvise: Add support for purgeable buffer objects (rev7) Patchwork
2026-03-03 16:14 ` ✓ CI.KUnit: success " Patchwork
2026-03-03 16:50 ` ✓ Xe.CI.BAT: " Patchwork
2026-03-03 22:05 ` [PATCH v6 00/12] drm/xe/madvise: Add support for purgeable buffer objects Souza, Jose
2026-03-03 22:49   ` Matthew Brost
2026-03-04 13:29     ` Souza, Jose
2026-03-23  6:37       ` Yadav, Arvind
2026-03-04  4:01 ` ✗ Xe.CI.FULL: failure for drm/xe/madvise: Add support for purgeable buffer objects (rev7) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb2263b1eac45e018d26bacdca65337e5120aff4.camel@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=arvind.yadav@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jose.souza@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=pallavi.mishra@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox