Commit 59eabff2 authored by Thomas Hellström's avatar Thomas Hellström
Browse files

drm/xe: Convert xe_bo_create_pin_map() for exhaustive eviction



Introduce an xe_bo_create_pin_map_novm() function that does not
take the drm_exec paramenter to simplify the conversion of many
callsites.
For the rest, ensure that the same drm_exec context that was used
for locking the vm is passed down to validation.

Use xe_validation_guard() where appropriate.

v2:
- Avoid gotos from within xe_validation_guard(). (Matt Brost)
- Break out the change to pf_provision_vf_lmem8 to a separate
  patch.
- Adapt to signature change of xe_validation_guard().

Signed-off-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250908101246.65025-12-thomas.hellstrom@linux.intel.com
parent e6108ead
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -42,11 +42,11 @@ struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
	obj = ERR_PTR(-ENODEV);

	if (!IS_DGFX(xe) && !XE_GT_WA(xe_root_mmio_gt(xe), 22019338487_display)) {
		obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe),
					   NULL, size,
		obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe),
						size,
						ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
						XE_BO_FLAG_STOLEN |
					   XE_BO_FLAG_GGTT);
						XE_BO_FLAG_GGTT, false);
		if (!IS_ERR(obj))
			drm_info(&xe->drm, "Allocated fbdev into stolen\n");
		else
@@ -54,10 +54,10 @@ struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
	}

	if (IS_ERR(obj)) {
		obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), NULL, size,
		obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe), size,
						ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
						XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
					   XE_BO_FLAG_GGTT);
						XE_BO_FLAG_GGTT, false);
	}

	if (IS_ERR(obj)) {
+5 −5
Original line number Diff line number Diff line
@@ -43,11 +43,11 @@ bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct intel_dsb_buffer *d
		return false;

	/* Set scanout flag for WC mapping */
	obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe),
				   NULL, PAGE_ALIGN(size),
	obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe),
					PAGE_ALIGN(size),
					ttm_bo_type_kernel,
					XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
				   XE_BO_FLAG_SCANOUT | XE_BO_FLAG_GGTT);
					XE_BO_FLAG_SCANOUT | XE_BO_FLAG_GGTT, false);
	if (IS_ERR(obj)) {
		kfree(vma);
		return false;
+4 −4
Original line number Diff line number Diff line
@@ -72,10 +72,10 @@ static int intel_hdcp_gsc_initialize_message(struct xe_device *xe,
	int ret = 0;

	/* allocate object of two page for HDCP command memory and store it */
	bo = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), NULL, PAGE_SIZE * 2,
	bo = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe), PAGE_SIZE * 2,
				       ttm_bo_type_kernel,
				       XE_BO_FLAG_SYSTEM |
				  XE_BO_FLAG_GGTT);
				       XE_BO_FLAG_GGTT, false);

	if (IS_ERR(bo)) {
		drm_err(&xe->drm, "Failed to allocate bo for HDCP streaming command!\n");
+6 −3
Original line number Diff line number Diff line
@@ -204,7 +204,8 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test,

	big = xe_bo_create_pin_map(xe, tile, m->q->vm, SZ_4M,
				   ttm_bo_type_kernel,
				   XE_BO_FLAG_VRAM_IF_DGFX(tile));
				   XE_BO_FLAG_VRAM_IF_DGFX(tile),
				   exec);
	if (IS_ERR(big)) {
		KUNIT_FAIL(test, "Failed to allocate bo: %li\n", PTR_ERR(big));
		goto vunmap;
@@ -212,7 +213,8 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test,

	pt = xe_bo_create_pin_map(xe, tile, m->q->vm, XE_PAGE_SIZE,
				  ttm_bo_type_kernel,
				  XE_BO_FLAG_VRAM_IF_DGFX(tile));
				  XE_BO_FLAG_VRAM_IF_DGFX(tile),
				  exec);
	if (IS_ERR(pt)) {
		KUNIT_FAIL(test, "Failed to allocate fake pt: %li\n",
			   PTR_ERR(pt));
@@ -222,7 +224,8 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test,
	tiny = xe_bo_create_pin_map(xe, tile, m->q->vm,
				    2 * SZ_4K,
				    ttm_bo_type_kernel,
				    XE_BO_FLAG_VRAM_IF_DGFX(tile));
				    XE_BO_FLAG_VRAM_IF_DGFX(tile),
				    exec);
	if (IS_ERR(tiny)) {
		KUNIT_FAIL(test, "Failed to allocate tiny fake pt: %li\n",
			   PTR_ERR(tiny));
+47 −5
Original line number Diff line number Diff line
@@ -2513,16 +2513,59 @@ xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
	return ret ? ERR_PTR(ret) : bo;
}

/**
 * xe_bo_create_pin_map() - Create pinned and mapped bo
 * @xe: The xe device.
 * @tile: The tile to select for migration of this bo, and the tile used for
 * @vm: The vm to associate the buffer object with. The vm's resv must be locked
 * with the transaction represented by @exec.
 * GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
 * @size: The storage size to use for the bo.
 * @type: The TTM buffer object type.
 * @flags: XE_BO_FLAG_ flags.
 * @exec: The drm_exec transaction to use for exhaustive eviction, and
 * previously used for locking @vm's resv.
 *
 * Create a pinned and mapped bo. The bo will be external and not associated
 * with a VM.
 *
 * Return: The buffer object on success. Negative error pointer on failure.
 * In particular, the function may return ERR_PTR(%-EINTR) if @exec was
 * configured for interruptible locking.
 */
struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
				   struct xe_vm *vm, size_t size,
				   enum ttm_bo_type type, u32 flags)
				   enum ttm_bo_type type, u32 flags,
				   struct drm_exec *exec)
{
	struct drm_exec *exec = vm ? xe_vm_validation_exec(vm) : XE_VALIDATION_UNIMPLEMENTED;

	return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, ~0ull, type, flags,
					       0, exec);
}

/**
 * xe_bo_create_pin_map_novm() - Create pinned and mapped bo
 * @xe: The xe device.
 * @tile: The tile to select for migration of this bo, and the tile used for
 * GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
 * @size: The storage size to use for the bo.
 * @type: The TTM buffer object type.
 * @flags: XE_BO_FLAG_ flags.
 * @intr: Whether to execut any waits for backing store interruptible.
 *
 * Create a pinned and mapped bo. The bo will be external and not associated
 * with a VM.
 *
 * Return: The buffer object on success. Negative error pointer on failure.
 * In particular, the function may return ERR_PTR(%-EINTR) if @intr was set
 * to true on entry.
 */
struct xe_bo *xe_bo_create_pin_map_novm(struct xe_device *xe, struct xe_tile *tile,
					size_t size, enum ttm_bo_type type, u32 flags,
					bool intr)
{
	return xe_bo_create_pin_map_at_novm(xe, tile, size, ~0ull, type, flags, 0, intr);
}

static void __xe_bo_unpin_map_no_vm(void *arg)
{
	xe_bo_unpin_map_no_vm(arg);
@@ -2535,8 +2578,7 @@ struct xe_bo *xe_managed_bo_create_pin_map(struct xe_device *xe, struct xe_tile
	int ret;

	KUNIT_STATIC_STUB_REDIRECT(xe_managed_bo_create_pin_map, xe, tile, size, flags);

	bo = xe_bo_create_pin_map(xe, tile, NULL, size, ttm_bo_type_kernel, flags);
	bo = xe_bo_create_pin_map_novm(xe, tile, size, ttm_bo_type_kernel, flags, true);
	if (IS_ERR(bo))
		return bo;

Loading