Commit 60dc43d1 authored by Thomas Hellström's avatar Thomas Hellström
Browse files

drm/i915: Use struct vma_resource instead of struct vma_snapshot



There is always a struct vma_resource guaranteed to be alive when we
access a corresponding struct vma_snapshot.

So ditch the latter and instead of allocating vma_snapshots, reference
the already existning vma_resource.

This requires a couple of extra members in struct vma_resource but that's
a small price to pay for the simplification.

v2:
- Fix a missing include and declaration (kernel test robot <lkp@intel.com>)

Signed-off-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220110172219.107131-7-thomas.hellstrom@linux.intel.com
parent 950505ca
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -175,7 +175,6 @@ i915-y += \
	  i915_ttm_buddy_manager.o \
	  i915_vma.o \
	  i915_vma_resource.o \
	  i915_vma_snapshot.o \
	  intel_wopcm.o

# general-purpose microcontroller (GuC) support
+3 −12
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
#include "i915_gem_ioctls.h"
#include "i915_trace.h"
#include "i915_user_extensions.h"
#include "i915_vma_snapshot.h"

struct eb_vma {
	struct i915_vma *vma;
@@ -1941,7 +1940,6 @@ static void eb_capture_stage(struct i915_execbuffer *eb)
{
	const unsigned int count = eb->buffer_count;
	unsigned int i = count, j;
	struct i915_vma_snapshot *vsnap;

	while (i--) {
		struct eb_vma *ev = &eb->vma[i];
@@ -1951,11 +1949,6 @@ static void eb_capture_stage(struct i915_execbuffer *eb)
		if (!(flags & EXEC_OBJECT_CAPTURE))
			continue;

		vsnap = i915_vma_snapshot_alloc(GFP_KERNEL);
		if (!vsnap)
			continue;

		i915_vma_snapshot_init(vsnap, vma, "user");
		for_each_batch_create_order(eb, j) {
			struct i915_capture_list *capture;

@@ -1964,10 +1957,9 @@ static void eb_capture_stage(struct i915_execbuffer *eb)
				continue;

			capture->next = eb->capture_lists[j];
			capture->vma_snapshot = i915_vma_snapshot_get(vsnap);
			capture->vma_res = i915_vma_resource_get(vma->resource);
			eb->capture_lists[j] = capture;
		}
		i915_vma_snapshot_put(vsnap);
	}
}

@@ -3270,9 +3262,8 @@ eb_requests_create(struct i915_execbuffer *eb, struct dma_fence *in_fence,
		 * _onstack interface.
		 */
		if (eb->batches[i]->vma)
			i915_vma_snapshot_init_onstack(&eb->requests[i]->batch_snapshot,
						       eb->batches[i]->vma,
						       "batch");
			eb->requests[i]->batch_res =
				i915_vma_resource_get(eb->batches[i]->vma->resource);
		if (eb->batch_pool) {
			GEM_BUG_ON(intel_context_is_parallel(eb->context));
			intel_gt_buffer_pool_mark_active(eb->batch_pool,
+3 −6
Original line number Diff line number Diff line
@@ -1708,18 +1708,15 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,

static void print_request_ring(struct drm_printer *m, struct i915_request *rq)
{
	struct i915_vma_snapshot *vsnap = &rq->batch_snapshot;
	struct i915_vma_resource *vma_res = rq->batch_res;
	void *ring;
	int size;

	if (!i915_vma_snapshot_present(vsnap))
		vsnap = NULL;

	drm_printf(m,
		   "[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]:\n",
		   rq->head, rq->postfix, rq->tail,
		   vsnap ? upper_32_bits(vsnap->vma_resource->start) : ~0u,
		   vsnap ? lower_32_bits(vsnap->vma_resource->start) : ~0u);
		   vma_res ? upper_32_bits(vma_res->start) : ~0u,
		   vma_res ? lower_32_bits(vma_res->start) : ~0u);

	size = rq->tail - rq->head;
	if (rq->tail < rq->head)
+40 −47
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@
#include "i915_gpu_error.h"
#include "i915_memcpy.h"
#include "i915_scatterlist.h"
#include "i915_vma_snapshot.h"

#define ALLOW_FAIL (__GFP_KSWAPD_RECLAIM | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
#define ATOMIC_MAYFAIL (GFP_ATOMIC | __GFP_NOWARN)
@@ -1013,8 +1012,10 @@ void __i915_gpu_coredump_free(struct kref *error_ref)

static struct i915_vma_coredump *
i915_vma_coredump_create(const struct intel_gt *gt,
			 const struct i915_vma_snapshot *vsnap,
			 struct i915_vma_compress *compress)
			 const struct i915_vma_resource *vma_res,
			 struct i915_vma_compress *compress,
			 const char *name)

{
	struct i915_ggtt *ggtt = gt->ggtt;
	const u64 slot = ggtt->error_capture.start;
@@ -1024,7 +1025,7 @@ i915_vma_coredump_create(const struct intel_gt *gt,

	might_sleep();

	if (!vsnap || !vsnap->pages || !compress)
	if (!vma_res || !vma_res->bi.pages || !compress)
		return NULL;

	dst = kmalloc(sizeof(*dst), ALLOW_FAIL);
@@ -1037,12 +1038,12 @@ i915_vma_coredump_create(const struct intel_gt *gt,
	}

	INIT_LIST_HEAD(&dst->page_list);
	strcpy(dst->name, vsnap->name);
	strcpy(dst->name, name);
	dst->next = NULL;

	dst->gtt_offset = vsnap->vma_resource->start;
	dst->gtt_size = vsnap->vma_resource->node_size;
	dst->gtt_page_sizes = vsnap->vma_resource->page_sizes_gtt;
	dst->gtt_offset = vma_res->start;
	dst->gtt_size = vma_res->node_size;
	dst->gtt_page_sizes = vma_res->page_sizes_gtt;
	dst->unused = 0;

	ret = -EINVAL;
@@ -1050,7 +1051,7 @@ i915_vma_coredump_create(const struct intel_gt *gt,
		void __iomem *s;
		dma_addr_t dma;

		for_each_sgt_daddr(dma, iter, vsnap->pages) {
		for_each_sgt_daddr(dma, iter, vma_res->bi.pages) {
			mutex_lock(&ggtt->error_mutex);
			ggtt->vm.insert_page(&ggtt->vm, dma, slot,
					     I915_CACHE_NONE, 0);
@@ -1068,11 +1069,11 @@ i915_vma_coredump_create(const struct intel_gt *gt,
			if (ret)
				break;
		}
	} else if (vsnap->mr && vsnap->mr->type != INTEL_MEMORY_SYSTEM) {
		struct intel_memory_region *mem = vsnap->mr;
	} else if (vma_res->bi.lmem) {
		struct intel_memory_region *mem = vma_res->mr;
		dma_addr_t dma;

		for_each_sgt_daddr(dma, iter, vsnap->pages) {
		for_each_sgt_daddr(dma, iter, vma_res->bi.pages) {
			void __iomem *s;

			s = io_mapping_map_wc(&mem->iomap,
@@ -1088,7 +1089,7 @@ i915_vma_coredump_create(const struct intel_gt *gt,
	} else {
		struct page *page;

		for_each_sgt_page(page, iter, vsnap->pages) {
		for_each_sgt_page(page, iter, vma_res->bi.pages) {
			void *s;

			drm_clflush_pages(&page, 1);
@@ -1324,33 +1325,32 @@ static bool record_context(struct i915_gem_context_coredump *e,

struct intel_engine_capture_vma {
	struct intel_engine_capture_vma *next;
	struct i915_vma_snapshot *vsnap;
	struct i915_vma_resource *vma_res;
	char name[16];
	bool lockdep_cookie;
};

static struct intel_engine_capture_vma *
capture_vma_snapshot(struct intel_engine_capture_vma *next,
		     struct i915_vma_snapshot *vsnap,
		     gfp_t gfp)
		     struct i915_vma_resource *vma_res,
		     gfp_t gfp, const char *name)
{
	struct intel_engine_capture_vma *c;

	if (!i915_vma_snapshot_present(vsnap))
	if (!vma_res)
		return next;

	c = kmalloc(sizeof(*c), gfp);
	if (!c)
		return next;

	if (!i915_vma_snapshot_resource_pin(vsnap, &c->lockdep_cookie)) {
	if (!i915_vma_resource_hold(vma_res, &c->lockdep_cookie)) {
		kfree(c);
		return next;
	}

	strcpy(c->name, vsnap->name);
	c->vsnap = vsnap;
	i915_vma_snapshot_get(vsnap);
	strcpy(c->name, name);
	c->vma_res = i915_vma_resource_get(vma_res);

	c->next = next;
	return c;
@@ -1362,8 +1362,6 @@ capture_vma(struct intel_engine_capture_vma *next,
	    const char *name,
	    gfp_t gfp)
{
	struct i915_vma_snapshot *vsnap;

	if (!vma)
		return next;

@@ -1372,19 +1370,10 @@ capture_vma(struct intel_engine_capture_vma *next,
	 * to a struct i915_vma_snapshot at command submission time.
	 * Not here.
	 */
	GEM_WARN_ON(!i915_vma_is_pinned(vma));
	if (!i915_vma_is_pinned(vma))
		return next;

	vsnap = i915_vma_snapshot_alloc(gfp);
	if (!vsnap)
	if (GEM_WARN_ON(!i915_vma_is_pinned(vma)))
		return next;

	i915_vma_snapshot_init(vsnap, vma, name);
	next = capture_vma_snapshot(next, vsnap, gfp);

	/* FIXME: Replace on async unbind. */
	i915_vma_snapshot_put(vsnap);
	next = capture_vma_snapshot(next, vma->resource, gfp, name);

	return next;
}
@@ -1397,7 +1386,8 @@ capture_user(struct intel_engine_capture_vma *capture,
	struct i915_capture_list *c;

	for (c = rq->capture_list; c; c = c->next)
		capture = capture_vma_snapshot(capture, c->vma_snapshot, gfp);
		capture = capture_vma_snapshot(capture, c->vma_res, gfp,
					       "user");

	return capture;
}
@@ -1415,16 +1405,19 @@ static struct i915_vma_coredump *
create_vma_coredump(const struct intel_gt *gt, struct i915_vma *vma,
		    const char *name, struct i915_vma_compress *compress)
{
	struct i915_vma_coredump *ret;
	struct i915_vma_snapshot tmp;
	struct i915_vma_coredump *ret = NULL;
	struct i915_vma_resource *vma_res;
	bool lockdep_cookie;

	if (!vma)
		return NULL;

	GEM_WARN_ON(!i915_vma_is_pinned(vma));
	i915_vma_snapshot_init_onstack(&tmp, vma, name);
	ret = i915_vma_coredump_create(gt, &tmp, compress);
	i915_vma_snapshot_put_onstack(&tmp);
	vma_res = vma->resource;

	if (i915_vma_resource_hold(vma_res, &lockdep_cookie)) {
		ret = i915_vma_coredump_create(gt, vma_res, compress, name);
		i915_vma_resource_unhold(vma_res, lockdep_cookie);
	}

	return ret;
}
@@ -1471,7 +1464,7 @@ intel_engine_coredump_add_request(struct intel_engine_coredump *ee,
	 * as the simplest method to avoid being overwritten
	 * by userspace.
	 */
	vma = capture_vma_snapshot(vma, &rq->batch_snapshot, gfp);
	vma = capture_vma_snapshot(vma, rq->batch_res, gfp, "batch");
	vma = capture_user(vma, rq, gfp);
	vma = capture_vma(vma, rq->ring->vma, "ring", gfp);
	vma = capture_vma(vma, rq->context->state, "HW context", gfp);
@@ -1492,14 +1485,14 @@ intel_engine_coredump_add_vma(struct intel_engine_coredump *ee,

	while (capture) {
		struct intel_engine_capture_vma *this = capture;
		struct i915_vma_snapshot *vsnap = this->vsnap;
		struct i915_vma_resource *vma_res = this->vma_res;

		add_vma(ee,
			i915_vma_coredump_create(engine->gt,
						 vsnap, compress));
			i915_vma_coredump_create(engine->gt, vma_res,
						 compress, this->name));

		i915_vma_snapshot_resource_unpin(vsnap, this->lockdep_cookie);
		i915_vma_snapshot_put(vsnap);
		i915_vma_resource_unhold(vma_res, this->lockdep_cookie);
		i915_vma_resource_put(vma_res);

		capture = this->next;
		kfree(this);
+7 −5
Original line number Diff line number Diff line
@@ -115,8 +115,10 @@ static void i915_fence_release(struct dma_fence *fence)
		   rq->guc_prio != GUC_PRIO_FINI);

	i915_request_free_capture_list(fetch_and_zero(&rq->capture_list));
	if (i915_vma_snapshot_present(&rq->batch_snapshot))
		i915_vma_snapshot_put_onstack(&rq->batch_snapshot);
	if (rq->batch_res) {
		i915_vma_resource_put(rq->batch_res);
		rq->batch_res = NULL;
	}

	/*
	 * The request is put onto a RCU freelist (i.e. the address
@@ -307,7 +309,7 @@ void i915_request_free_capture_list(struct i915_capture_list *capture)
	while (capture) {
		struct i915_capture_list *next = capture->next;

		i915_vma_snapshot_put(capture->vma_snapshot);
		i915_vma_resource_put(capture->vma_res);
		kfree(capture);
		capture = next;
	}
@@ -853,7 +855,7 @@ static void __i915_request_ctor(void *arg)
	i915_sw_fence_init(&rq->semaphore, semaphore_notify);

	clear_capture_list(rq);
	rq->batch_snapshot.present = false;
	rq->batch_res = NULL;

	init_llist_head(&rq->execute_cb);
}
@@ -959,7 +961,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
	__rq_init_watchdog(rq);
	assert_capture_list_is_null(rq);
	GEM_BUG_ON(!llist_empty(&rq->execute_cb));
	GEM_BUG_ON(i915_vma_snapshot_present(&rq->batch_snapshot));
	GEM_BUG_ON(rq->batch_res);

	/*
	 * Reserve space in the ring buffer for all the commands required to
Loading