Commit 8e4ee5e8 authored by Chris Wilson's avatar Chris Wilson Committed by Andi Shyti
Browse files

drm/i915: Wrap all access to i915_vma.node.start|size



We already wrap i915_vma.node.start for use with the GGTT, as there we
can perform additional sanity checks that the node belongs to the GGTT
and fits within the 32b registers. In the next couple of patches, we
will introduce guard pages around the objects _inside_ the drm_mm_node
allocation. That is we will offset the vma->pages so that the first page
is at drm_mm_node.start + vma->guard (not 0 as is currently the case).
All users must then not use i915_vma.node.start directly, but compute
the guard offset, thus all users are converted to use a
i915_vma_offset() wrapper.

The notable exceptions are the selftests that are testing exact
behaviour of i915_vma_pin/i915_vma_insert.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarTejas Upadhyay <tejaskumarx.surendrakumar.upadhyay@intel.com>
Co-developed-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221130235805.221010-3-andi.shyti@linux.intel.com
parent 09f9b441
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ static int intelfb_create(struct drm_fb_helper *helper,

		/* Our framebuffer is the entirety of fbdev's system memory */
		info->fix.smem_start =
			(unsigned long)(ggtt->gmadr.start + vma->node.start);
			(unsigned long)(ggtt->gmadr.start + i915_ggtt_offset(vma));
		info->fix.smem_len = vma->size;
	}

+18 −15
Original line number Diff line number Diff line
@@ -378,22 +378,25 @@ eb_vma_misplaced(const struct drm_i915_gem_exec_object2 *entry,
		 const struct i915_vma *vma,
		 unsigned int flags)
{
	if (vma->node.size < entry->pad_to_size)
	const u64 start = i915_vma_offset(vma);
	const u64 size = i915_vma_size(vma);

	if (size < entry->pad_to_size)
		return true;

	if (entry->alignment && !IS_ALIGNED(vma->node.start, entry->alignment))
	if (entry->alignment && !IS_ALIGNED(start, entry->alignment))
		return true;

	if (flags & EXEC_OBJECT_PINNED &&
	    vma->node.start != entry->offset)
	    start != entry->offset)
		return true;

	if (flags & __EXEC_OBJECT_NEEDS_BIAS &&
	    vma->node.start < BATCH_OFFSET_BIAS)
	    start < BATCH_OFFSET_BIAS)
		return true;

	if (!(flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) &&
	    (vma->node.start + vma->node.size + 4095) >> 32)
	    (start + size + 4095) >> 32)
		return true;

	if (flags & __EXEC_OBJECT_NEEDS_MAP &&
@@ -439,7 +442,7 @@ eb_pin_vma(struct i915_execbuffer *eb,
	int err;

	if (vma->node.size)
		pin_flags = vma->node.start;
		pin_flags =  __i915_vma_offset(vma);
	else
		pin_flags = entry->offset & PIN_OFFSET_MASK;

@@ -662,8 +665,8 @@ static int eb_reserve_vma(struct i915_execbuffer *eb,
	if (err)
		return err;

	if (entry->offset != vma->node.start) {
		entry->offset = vma->node.start | UPDATE;
	if (entry->offset != i915_vma_offset(vma)) {
		entry->offset = i915_vma_offset(vma) | UPDATE;
		eb->args->flags |= __EXEC_HAS_RELOC;
	}

@@ -983,8 +986,8 @@ static int eb_validate_vmas(struct i915_execbuffer *eb)
			return err;

		if (!err) {
			if (entry->offset != vma->node.start) {
				entry->offset = vma->node.start | UPDATE;
			if (entry->offset != i915_vma_offset(vma)) {
				entry->offset = i915_vma_offset(vma) | UPDATE;
				eb->args->flags |= __EXEC_HAS_RELOC;
			}
		} else {
@@ -1065,7 +1068,7 @@ static inline u64
relocation_target(const struct drm_i915_gem_relocation_entry *reloc,
		  const struct i915_vma *target)
{
	return gen8_canonical_addr((int)reloc->delta + target->node.start);
	return gen8_canonical_addr((int)reloc->delta + i915_vma_offset(target));
}

static void reloc_cache_init(struct reloc_cache *cache,
@@ -1274,7 +1277,7 @@ static void *reloc_iomap(struct i915_vma *batch,
			if (err) /* no inactive aperture space, use cpu reloc */
				return NULL;
		} else {
			cache->node.start = vma->node.start;
			cache->node.start = i915_ggtt_offset(vma);
			cache->node.mm = (void *)vma;
		}
	}
@@ -1437,7 +1440,7 @@ eb_relocate_entry(struct i915_execbuffer *eb,
	 * more work needs to be done.
	 */
	if (!DBG_FORCE_RELOC &&
	    gen8_canonical_addr(target->vma->node.start) == reloc->presumed_offset)
	    gen8_canonical_addr(i915_vma_offset(target->vma)) == reloc->presumed_offset)
		return 0;

	/* Check that the relocation address is valid... */
@@ -2367,7 +2370,7 @@ static int eb_request_submit(struct i915_execbuffer *eb,
	}

	err = rq->context->engine->emit_bb_start(rq,
						 batch->node.start +
						 i915_vma_offset(batch) +
						 eb->batch_start_offset,
						 batch_len,
						 eb->batch_flags);
@@ -2378,7 +2381,7 @@ static int eb_request_submit(struct i915_execbuffer *eb,
		GEM_BUG_ON(intel_context_is_parallel(rq->context));
		GEM_BUG_ON(eb->batch_start_offset);
		err = rq->context->engine->emit_bb_start(rq,
							 eb->trampoline->node.start +
							 i915_vma_offset(eb->trampoline) +
							 batch_len, 0, 0);
		if (err)
			return err;
+1 −1
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
	/* Finally, remap it using the new GTT offset */
	ret = remap_io_mapping(area,
			       area->vm_start + (vma->gtt_view.partial.offset << PAGE_SHIFT),
			       (ggtt->gmadr.start + vma->node.start) >> PAGE_SHIFT,
			       (ggtt->gmadr.start + i915_ggtt_offset(vma)) >> PAGE_SHIFT,
			       min_t(u64, vma->size, area->vm_end - area->vm_start),
			       &ggtt->iomap);
	if (ret)
+1 −1
Original line number Diff line number Diff line
@@ -400,7 +400,7 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr
	mutex_lock(&to_gt(i915)->ggtt->vm.mutex);
	list_for_each_entry_safe(vma, next,
				 &to_gt(i915)->ggtt->vm.bound_list, vm_link) {
		unsigned long count = vma->node.size >> PAGE_SHIFT;
		unsigned long count = i915_vma_size(vma) >> PAGE_SHIFT;
		struct drm_i915_gem_object *obj = vma->obj;

		if (!vma->iomap || i915_vma_is_active(vma))
+2 −2
Original line number Diff line number Diff line
@@ -168,11 +168,11 @@ static bool i915_vma_fence_prepare(struct i915_vma *vma,
		return true;

	size = i915_gem_fence_size(i915, vma->size, tiling_mode, stride);
	if (vma->node.size < size)
	if (i915_vma_size(vma) < size)
		return false;

	alignment = i915_gem_fence_alignment(i915, vma->size, tiling_mode, stride);
	if (!IS_ALIGNED(vma->node.start, alignment))
	if (!IS_ALIGNED(i915_ggtt_offset(vma), alignment))
		return false;

	return true;
Loading