Skip to content

Commit

Permalink
drm/i915: Use struct vma_resource instead of struct vma_snapshot
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
  • Loading branch information
Thomas Hellström authored and intel-lab-lkp committed Dec 15, 2021
1 parent e6b0542 commit ede0258
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 313 deletions.
1 change: 0 additions & 1 deletion drivers/gpu/drm/i915/Makefile
Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
Expand Up @@ -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;
Expand Down Expand Up @@ -1952,7 +1951,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];
Expand All @@ -1962,11 +1960,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;

Expand All @@ -1975,10 +1968,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);
}
}

Expand Down Expand Up @@ -3281,9 +3273,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,
Expand Down
9 changes: 3 additions & 6 deletions drivers/gpu/drm/i915/gt/intel_engine_cs.c
Expand Up @@ -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)
Expand Down
87 changes: 40 additions & 47 deletions drivers/gpu/drm/i915/i915_gpu_error.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -1037,20 +1038,20 @@ 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;
if (drm_mm_node_allocated(&ggtt->error_capture)) {
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);
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions drivers/gpu/drm/i915/i915_request.c
Expand Up @@ -116,8 +116,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
Expand Down Expand Up @@ -308,7 +310,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;
}
Expand Down Expand Up @@ -854,7 +856,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);
}
Expand Down Expand Up @@ -960,7 +962,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
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/i915/i915_request.h
Expand Up @@ -40,7 +40,7 @@
#include "i915_scheduler.h"
#include "i915_selftest.h"
#include "i915_sw_fence.h"
#include "i915_vma_snapshot.h"
#include "i915_vma_resource.h"

#include <uapi/drm/i915_drm.h>

Expand All @@ -52,7 +52,7 @@ struct i915_request;

#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
struct i915_capture_list {
struct i915_vma_snapshot *vma_snapshot;
struct i915_vma_resource *vma_res;
struct i915_capture_list *next;
};

Expand Down Expand Up @@ -300,7 +300,7 @@ struct i915_request {
/** Batch buffer pointer for selftest internal use. */
I915_SELFTEST_DECLARE(struct i915_vma *batch);

struct i915_vma_snapshot batch_snapshot;
struct i915_vma_resource *batch_res;

#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
/**
Expand Down

0 comments on commit ede0258

Please sign in to comment.