[PATCH v1 3/4] drm/xe: Force user context allocations in user VRAM
Matthew Auld
matthew.auld at intel.com
Wed Aug 13 16:42:18 UTC 2025
On 18/07/2025 09:17, Piórkowski, Piotr wrote:
> From: Piotr Piórkowski <piotr.piorkowski at intel.com>
>
> In general, kernel structures should be allocated in the kernel-dedicated
> VRAM region. However, userspace context data - while used by the kernel -
> does not need to reside there.
> Let's force the allocation of such data in the general-purpose VRAM region
> accessible to userspace.
>
> Signed-off-by: Piotr Piórkowski <piotr.piorkowski at intel.com>
> ---
> drivers/gpu/drm/xe/xe_exec_queue.c | 7 +++++--
> drivers/gpu/drm/xe/xe_lrc.c | 3 +++
> drivers/gpu/drm/xe/xe_lrc.h | 5 +++--
> drivers/gpu/drm/xe/xe_pt.c | 2 +-
> 4 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c
> index 8991b4aed440..abd29191186e 100644
> --- a/drivers/gpu/drm/xe/xe_exec_queue.c
> +++ b/drivers/gpu/drm/xe/xe_exec_queue.c
> @@ -112,7 +112,7 @@ static struct xe_exec_queue *__xe_exec_queue_alloc(struct xe_device *xe,
> return q;
> }
>
> -static int __xe_exec_queue_init(struct xe_exec_queue *q)
> +static int __xe_exec_queue_init(struct xe_exec_queue *q, u32 exec_queue_flags)
> {
> int i, err;
> u32 flags = 0;
> @@ -131,6 +131,9 @@ static int __xe_exec_queue_init(struct xe_exec_queue *q)
> flags |= XE_LRC_CREATE_RUNALONE;
> }
>
> + if (!(exec_queue_flags & EXEC_QUEUE_FLAG_KERNEL))
> + flags |= XE_LRC_CREATE_USER_CTX;
> +
> for (i = 0; i < q->width; ++i) {
> q->lrc[i] = xe_lrc_create(q->hwe, q->vm, SZ_16K, q->msix_vec, flags);
> if (IS_ERR(q->lrc[i])) {
> @@ -167,7 +170,7 @@ struct xe_exec_queue *xe_exec_queue_create(struct xe_device *xe, struct xe_vm *v
> if (IS_ERR(q))
> return q;
>
> - err = __xe_exec_queue_init(q);
> + err = __xe_exec_queue_init(q, flags);
> if (err)
> goto err_post_alloc;
>
> diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
> index 6d38411bdeba..ed53f8e2448b 100644
> --- a/drivers/gpu/drm/xe/xe_lrc.c
> +++ b/drivers/gpu/drm/xe/xe_lrc.c
> @@ -1203,6 +1203,9 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
> if (vm && vm->xef) /* userspace */
> bo_flags |= XE_BO_FLAG_PINNED_LATE_RESTORE;
>
> + if (init_flags & XE_LRC_CREATE_USER_CTX)
> + bo_flags |= XE_BO_FLAG_FORCE_USER_VRAM;
We can't use the xef check above?
> +
> lrc->bo = xe_bo_create_pin_map(xe, tile, NULL, bo_size,
> ttm_bo_type_kernel,
> bo_flags);
> diff --git a/drivers/gpu/drm/xe/xe_lrc.h b/drivers/gpu/drm/xe/xe_lrc.h
> index b6c8053c581b..57f661aa9b1c 100644
> --- a/drivers/gpu/drm/xe/xe_lrc.h
> +++ b/drivers/gpu/drm/xe/xe_lrc.h
> @@ -42,8 +42,9 @@ struct xe_lrc_snapshot {
> #define LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR (0x34 * 4)
> #define LRC_PPHWSP_PXP_INVAL_SCRATCH_ADDR (0x40 * 4)
>
> -#define XE_LRC_CREATE_RUNALONE 0x1
> -#define XE_LRC_CREATE_PXP 0x2
> +#define XE_LRC_CREATE_RUNALONE BIT(0)
> +#define XE_LRC_CREATE_PXP BIT(1)
> +#define XE_LRC_CREATE_USER_CTX BIT(2)
> struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
> u32 ring_size, u16 msix_vec, u32 flags);
> void xe_lrc_destroy(struct kref *ref);
> diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
> index c8e63bd23300..a6c5f810c815 100644
> --- a/drivers/gpu/drm/xe/xe_pt.c
> +++ b/drivers/gpu/drm/xe/xe_pt.c
> @@ -120,7 +120,7 @@ struct xe_pt *xe_pt_create(struct xe_vm *vm, struct xe_tile *tile,
> XE_BO_FLAG_IGNORE_MIN_PAGE_SIZE |
> XE_BO_FLAG_NO_RESV_EVICT | XE_BO_FLAG_PAGETABLE;
> if (vm->xef) /* userspace */
> - bo_flags |= XE_BO_FLAG_PINNED_LATE_RESTORE;
> + bo_flags |= XE_BO_FLAG_PINNED_LATE_RESTORE | XE_BO_FLAG_FORCE_USER_VRAM;
>
> pt->level = level;
> bo = xe_bo_create_pin_map(vm->xe, tile, vm, SZ_4K,
More information about the Intel-xe
mailing list