Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
To: Nirmoy Das <nirmoy.das@intel.com>, <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v3 6/7] drm/xe/uapi: Introduce VMA bind flag for device atomics
Date: Fri, 19 Apr 2024 10:16:54 +0300	[thread overview]
Message-ID: <f763388c-2d45-4780-90c0-8ac8c359e090@intel.com> (raw)
In-Reply-To: <20240415145214.25641-7-nirmoy.das@intel.com>

[-- Attachment #1: Type: text/plain, Size: 7973 bytes --]

On 15/04/2024 17:52, Nirmoy Das wrote:
> Adds a new VMA bind flag to enable device atomics on SMEM only buffers.
>
> Given that simultaneous usage of device atomics and CPU atomics on
> the same SMEM buffer is not guaranteed to function without migration,
> and UMD expects no migration for SMEM-only buffer objects, so this provide
> a way to set device atomics when UMD is certain to use the buffer only
> for device atomics.
>
> Signed-off-by: Nirmoy Das<nirmoy.das@intel.com>
> ---
>   drivers/gpu/drm/xe/xe_vm.c       | 28 ++++++++++++++++++++++++----
>   drivers/gpu/drm/xe/xe_vm_types.h |  2 ++
>   include/uapi/drm/xe_drm.h        | 17 +++++++++++++----
>   3 files changed, 39 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 8380f1d23074..b0907a7bb88b 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -753,6 +753,7 @@ static void xe_vma_free(struct xe_vma *vma)
>   #define VMA_CREATE_FLAG_READ_ONLY	BIT(0)
>   #define VMA_CREATE_FLAG_IS_NULL		BIT(1)
>   #define VMA_CREATE_FLAG_DUMPABLE	BIT(2)
> +#define VMA_CREATE_FLAG_DEVICE_ATOMICS	BIT(3)
>   
>   static struct xe_vma *xe_vma_create(struct xe_vm *vm,
>   				    struct xe_bo *bo,
> @@ -766,6 +767,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
>   	bool read_only = (flags & VMA_CREATE_FLAG_READ_ONLY);
>   	bool is_null = (flags & VMA_CREATE_FLAG_IS_NULL);
>   	bool dumpable = (flags & VMA_CREATE_FLAG_DUMPABLE);
> +	bool enable_atomics = (flags & VMA_CREATE_FLAG_DEVICE_ATOMICS);
>   
>   	xe_assert(vm->xe, start < end);
>   	xe_assert(vm->xe, end < vm->size);
> @@ -814,7 +816,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
>   		xe_bo_assert_held(bo);
>   
>   		if (vm->xe->info.has_atomic_enable_pte_bit &&
> -		    (xe_bo_is_vram(bo) || !IS_DGFX(vm->xe)))
> +		    (xe_bo_is_vram(bo) || !IS_DGFX(vm->xe) || enable_atomics))
>   			vma->gpuva.flags |= XE_VMA_ATOMIC_PTE_BIT;
>   
>   		vm_bo = drm_gpuvm_bo_obtain(vma->gpuva.vm, &bo->ttm.base);
> @@ -2116,6 +2118,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
>   		if (__op->op == DRM_GPUVA_OP_MAP) {
>   			op->map.is_null = flags & DRM_XE_VM_BIND_FLAG_NULL;
>   			op->map.dumpable = flags & DRM_XE_VM_BIND_FLAG_DUMPABLE;
> +			op->map.enable_device_atomics = flags & DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS;
>   			op->map.pat_index = pat_index;
>   		} else if (__op->op == DRM_GPUVA_OP_PREFETCH) {
>   			op->prefetch.region = prefetch_region;
> @@ -2312,6 +2315,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
>   				VMA_CREATE_FLAG_IS_NULL : 0;
>   			flags |= op->map.dumpable ?
>   				VMA_CREATE_FLAG_DUMPABLE : 0;
> +			flags |= op->map.enable_device_atomics ?
> +				VMA_CREATE_FLAG_DEVICE_ATOMICS : 0;
>   
>   			vma = new_vma(vm, &op->base.map, op->map.pat_index,
>   				      flags);
> @@ -2339,6 +2344,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
>   				flags |= op->base.remap.unmap->va->flags &
>   					XE_VMA_DUMPABLE ?
>   					VMA_CREATE_FLAG_DUMPABLE : 0;
> +				flags |= op->base.remap.unmap->va->flags ?
> +					VMA_CREATE_FLAG_DEVICE_ATOMICS : 0;
>   
>   				vma = new_vma(vm, op->base.remap.prev,
>   					      old->pat_index, flags);
> @@ -2376,6 +2383,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
>   				flags |= op->base.remap.unmap->va->flags &
>   					XE_VMA_DUMPABLE ?
>   					VMA_CREATE_FLAG_DUMPABLE : 0;
> +				flags |= op->base.remap.unmap->va->flags ?
> +					VMA_CREATE_FLAG_DEVICE_ATOMICS : 0;
>   
>   				vma = new_vma(vm, op->base.remap.next,
>   					      old->pat_index, flags);
> @@ -2731,7 +2740,8 @@ static int vm_bind_ioctl_ops_execute(struct xe_vm *vm,
>   	(DRM_XE_VM_BIND_FLAG_READONLY | \
>   	 DRM_XE_VM_BIND_FLAG_IMMEDIATE | \
>   	 DRM_XE_VM_BIND_FLAG_NULL | \
> -	 DRM_XE_VM_BIND_FLAG_DUMPABLE)
> +	 DRM_XE_VM_BIND_FLAG_DUMPABLE | \
> +	 DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS)
>   #define XE_64K_PAGE_MASK 0xffffull
>   #define ALL_DRM_XE_SYNCS_FLAGS (DRM_XE_SYNCS_FLAG_WAIT_FOR_OP)
>   
> @@ -2874,7 +2884,7 @@ static int vm_bind_ioctl_signal_fences(struct xe_vm *vm,
>   
>   static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
>   					u64 addr, u64 range, u64 obj_offset,
> -					u16 pat_index)
> +					u16 pat_index, u32 flags)
>   {
>   	u16 coh_mode;
>   
> @@ -2909,6 +2919,15 @@ static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
>   		return  -EINVAL;
>   	}
>   
> +	if (XE_IOCTL_DBG(xe, (flags & DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS) &&
> +			 (!xe->info.has_device_atomics_on_smem &&
> +			  !xe_bo_is_vram(bo))))
> +		return -EINVAL;


Is the check correct?

I'm not sure what you're trying to forbid here.


I would have guessed :


  (flags & DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS) &&
  (!xe->info.has_device_atomics_on_smem || !xe_bo_is_vram(bo))


> +
> +	if (XE_IOCTL_DBG(xe, (flags & DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS) &&
> +			 !xe_bo_has_single_placement(bo)))
> +		return -EINVAL;
> +
>   	return 0;
>   }
>   
> @@ -3007,7 +3026,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
>   		bos[i] = gem_to_xe_bo(gem_obj);
>   
>   		err = xe_vm_bind_ioctl_validate_bo(xe, bos[i], addr, range,
> -						   obj_offset, pat_index);
> +						   obj_offset, pat_index,
> +						   bind_ops[i].flags);
>   		if (err)
>   			goto put_obj;
>   	}
> diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
> index badf3945083d..5a20bd80c456 100644
> --- a/drivers/gpu/drm/xe/xe_vm_types.h
> +++ b/drivers/gpu/drm/xe/xe_vm_types.h
> @@ -276,6 +276,8 @@ struct xe_vm {
>   struct xe_vma_op_map {
>   	/** @vma: VMA to map */
>   	struct xe_vma *vma;
> +	/** @enable_device_atomics: Whether the VMA will allow device atomics */
> +	bool enable_device_atomics;
>   	/** @is_null: is NULL binding */
>   	bool is_null;
>   	/** @dumpable: whether BO is dumped on GPU hang */
> diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
> index 1446c3bae515..ca4447e10ac9 100644
> --- a/include/uapi/drm/xe_drm.h
> +++ b/include/uapi/drm/xe_drm.h
> @@ -883,6 +883,14 @@ struct drm_xe_vm_destroy {
>    *    will only be valid for DRM_XE_VM_BIND_OP_MAP operations, the BO
>    *    handle MBZ, and the BO offset MBZ. This flag is intended to
>    *    implement VK sparse bindings.
> + *  - %DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS - When this flag is set for
> + *    a VA range, all the corresponding PTEs will have atomic access bit
> + *    set. This will allow device atomics operation for that VA range.
> + *    This flag only works for single placement buffer objects and
> + *    mainly for SMEM only buffer objects where CPU atomics can be perform
> + *    by an application and so KMD can not set device atomics on such buffers
> + *    by default. This flag has no effect on LMEM only placed buffers as atomic
> + *    access bit is always set for LMEM backed PTEs.


Maybe we should be more explicit about when this flag is allowed :

   - error ifDRM_XE_QUERY_CONFIG_FLAG_HAS_DEV_ATOMIC_ON_SMEM is not reported

- error on multi region BOs

- ignored for LMEM only BOs

-Lionel


>    */
>   struct drm_xe_vm_bind_op {
>   	/** @extensions: Pointer to the first extension struct, if any */
> @@ -969,10 +977,11 @@ struct drm_xe_vm_bind_op {
>   	/** @op: Bind operation to perform */
>   	__u32 op;
>   
> -#define DRM_XE_VM_BIND_FLAG_READONLY	(1 << 0)
> -#define DRM_XE_VM_BIND_FLAG_IMMEDIATE	(1 << 1)
> -#define DRM_XE_VM_BIND_FLAG_NULL	(1 << 2)
> -#define DRM_XE_VM_BIND_FLAG_DUMPABLE	(1 << 3)
> +#define DRM_XE_VM_BIND_FLAG_READONLY		(1 << 0)
> +#define DRM_XE_VM_BIND_FLAG_IMMEDIATE		(1 << 1)
> +#define DRM_XE_VM_BIND_FLAG_NULL		(1 << 2)
> +#define DRM_XE_VM_BIND_FLAG_DUMPABLE		(1 << 3)
> +#define DRM_XE_VM_BIND_FLAG_DEVICE_ATOMICS	(1 << 4)
>   	/** @flags: Bind flags */
>   	__u32 flags;
>   


[-- Attachment #2: Type: text/html, Size: 9045 bytes --]

  reply	other threads:[~2024-04-19  7:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 14:52 [PATCH v3 0/7] Enable device atomics with a VM bind flag Nirmoy Das
2024-04-15 14:52 ` [PATCH v3 1/7] drm/xe: Introduce has_atomic_enable_pte_bit device info Nirmoy Das
2024-04-19 16:06   ` Zeng, Oak
2024-04-15 14:52 ` [PATCH v3 2/7] drm/xe: Consolidate setting PTE_AE into one place Nirmoy Das
2024-04-16 14:33   ` Nirmoy Das
2024-04-19 18:35   ` Zeng, Oak
2024-04-22  8:18     ` Nirmoy Das
2024-04-15 14:52 ` [PATCH v3 3/7] drm/xe: Add function to check if BO has single placement Nirmoy Das
2024-04-15 14:52 ` [PATCH v3 4/7] drm/xe: Move vm bind bo validation to a helper function Nirmoy Das
2024-04-16  0:55   ` Matthew Brost
2024-04-16 13:32     ` Nirmoy Das
2024-04-19 20:14   ` Zeng, Oak
2024-04-15 14:52 ` [PATCH v3 5/7] drm/xe: Introduce has_device_atomics_on_smem device info Nirmoy Das
2024-04-19 20:24   ` Zeng, Oak
2024-04-15 14:52 ` [PATCH v3 6/7] drm/xe/uapi: Introduce VMA bind flag for device atomics Nirmoy Das
2024-04-19  7:16   ` Lionel Landwerlin [this message]
2024-04-22  8:39     ` Nirmoy Das
2024-04-19 21:04   ` Zeng, Oak
2024-04-22 10:12     ` Nirmoy Das
2024-04-22 21:39       ` Zeng, Oak
2024-04-23 12:33         ` Nirmoy Das
2024-04-15 14:52 ` [PATCH v3 7/7] drm/xe/uapi: Add a query flag for has_device_atomics_on_smem Nirmoy Das
2024-04-19  7:08   ` Lionel Landwerlin
2024-04-22  8:53     ` Nirmoy Das
2024-04-19 21:06   ` Zeng, Oak
2024-04-15 21:19 ` ✓ CI.Patch_applied: success for Enable device atomics with a VM bind flag (rev3) Patchwork
2024-04-15 21:19 ` ✓ CI.checkpatch: " Patchwork
2024-04-15 21:21 ` ✓ CI.KUnit: " Patchwork
2024-04-15 21:37 ` ✓ CI.Build: " Patchwork
2024-04-15 21:40 ` ✓ CI.Hooks: " Patchwork
2024-04-15 21:41 ` ✓ CI.checksparse: " Patchwork
2024-04-15 22:22 ` ✗ CI.BAT: failure " Patchwork
2024-04-16 13:46 ` ✓ CI.FULL: success " Patchwork
2024-04-19  7:17 ` [PATCH v3 0/7] Enable device atomics with a VM bind flag Lionel Landwerlin
2024-04-22 10:13   ` Nirmoy Das
2024-04-22 14:50 ` Souza, Jose

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=f763388c-2d45-4780-90c0-8ac8c359e090@intel.com \
    --to=lionel.g.landwerlin@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=nirmoy.das@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