Skip to content

Commit cba8cf8

Browse files
Alex Dai0day robot
Alex Dai
authored and
0day robot
committed
drm/i915/guc: Simplify code by keeping vmap of guc_client object
GuC client object is always pinned during its life cycle. We cache the vmap of client object, which includes guc_process_desc, doorbell and work queue. By doing so, we can simplify the code where driver communicate with GuC. As a result, this patch removes the kmap_atomic in wq_check_space, where usleep_range could be called while kmap_atomic is held. This fixes issue below. [ 34.098798] BUG: scheduling while atomic: gem_close_race/1941/0x00000002 [ 34.098822] Modules linked in: hid_generic usbhid i915 asix usbnet libphy mii i2c_algo_bit drm_kms_helper cfbfillrect syscopyarea cfbimgblt sysfillrect sysimgblt fb_sys_fops cfbcopyarea drm coretemp i2c_hid hid video pinctrl_sunrisepoint pinctrl_intel acpi_pad nls_iso8859_1 e1000e ptp psmouse pps_core ahci libahci [ 34.098824] CPU: 0 PID: 1941 Comm: gem_close_race Tainted: G U 4.4.0-160121+ torvalds#123 [ 34.098824] Hardware name: Intel Corporation Skylake Client platform/Skylake AIO DDR3L RVP10, BIOS SKLSE2R1.R00.X100.B01.1509220551 09/22/2015 [ 34.098825] 0000000000013e40 ffff880166c27a78 ffffffff81280d02 ffff880172c13e40 [ 34.098826] ffff880166c27a88 ffffffff810c203a ffff880166c27ac8 ffffffff814ec808 [ 34.098827] ffff88016b7c6000 ffff880166c28000 00000000000f4240 0000000000000001 [ 34.098827] Call Trace: [ 34.098831] [<ffffffff81280d02>] dump_stack+0x4b/0x79 [ 34.098833] [<ffffffff810c203a>] __schedule_bug+0x41/0x4f [ 34.098834] [<ffffffff814ec808>] __schedule+0x5a8/0x690 [ 34.098835] [<ffffffff814ec927>] schedule+0x37/0x80 [ 34.098836] [<ffffffff814ef3fd>] schedule_hrtimeout_range_clock+0xad/0x130 [ 34.098837] [<ffffffff81090be0>] ? hrtimer_init+0x10/0x10 [ 34.098838] [<ffffffff814ef3f1>] ? schedule_hrtimeout_range_clock+0xa1/0x130 [ 34.098839] [<ffffffff814ef48e>] schedule_hrtimeout_range+0xe/0x10 [ 34.098840] [<ffffffff814eef9b>] usleep_range+0x3b/0x40 [ 34.098853] [<ffffffffa01ec109>] i915_guc_wq_check_space+0x119/0x210 [i915] [ 34.098861] [<ffffffffa01da47c>] intel_logical_ring_alloc_request_extras+0x5c/0x70 [i915] [ 34.098869] [<ffffffffa01cdbf1>] i915_gem_request_alloc+0x91/0x170 [i915] [ 34.098875] [<ffffffffa01c1c07>] i915_gem_do_execbuffer.isra.25+0xbc7/0x12a0 [i915] [ 34.098882] [<ffffffffa01cb785>] ? i915_gem_object_get_pages_gtt+0x225/0x3c0 [i915] [ 34.098889] [<ffffffffa01d1fb6>] ? i915_gem_pwrite_ioctl+0xd6/0x9f0 [i915] [ 34.098895] [<ffffffffa01c2e68>] i915_gem_execbuffer2+0xa8/0x250 [i915] [ 34.098900] [<ffffffffa00f65d8>] drm_ioctl+0x258/0x4f0 [drm] [ 34.098906] [<ffffffffa01c2dc0>] ? i915_gem_execbuffer+0x340/0x340 [i915] [ 34.098908] [<ffffffff8111590d>] do_vfs_ioctl+0x2cd/0x4a0 [ 34.098909] [<ffffffff8111eac2>] ? __fget+0x72/0xb0 [ 34.098910] [<ffffffff81115b1c>] SyS_ioctl+0x3c/0x70 [ 34.098911] [<ffffffff814effd7>] entry_SYSCALL_64_fastpath+0x12/0x6a [ 34.100208] ------------[ cut here ]------------ Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93847 Cc: Dave Gordon <david.s.gordon@intel.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Signed-off-by: Alex Dai <yu.dai@intel.com>
1 parent 5c224cf commit cba8cf8

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

drivers/gpu/drm/i915/i915_guc_submission.c

+16-37
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,9 @@ static int guc_ring_doorbell(struct i915_guc_client *gc)
195195
struct guc_process_desc *desc;
196196
union guc_doorbell_qw db_cmp, db_exc, db_ret;
197197
union guc_doorbell_qw *db;
198-
void *base;
199198
int attempt = 2, ret = -EAGAIN;
200199

201-
base = kmap_atomic(i915_gem_object_get_page(gc->client_obj, 0));
202-
desc = base + gc->proc_desc_offset;
200+
desc = gc->client_base + gc->proc_desc_offset;
203201

204202
/* Update the tail so it is visible to GuC */
205203
desc->tail = gc->wq_tail;
@@ -215,7 +213,7 @@ static int guc_ring_doorbell(struct i915_guc_client *gc)
215213
db_exc.cookie = 1;
216214

217215
/* pointer of current doorbell cacheline */
218-
db = base + gc->doorbell_offset;
216+
db = gc->client_base + gc->doorbell_offset;
219217

220218
while (attempt--) {
221219
/* lets ring the doorbell */
@@ -244,10 +242,6 @@ static int guc_ring_doorbell(struct i915_guc_client *gc)
244242
db_exc.cookie = 1;
245243
}
246244

247-
/* Finally, update the cached copy of the GuC's WQ head */
248-
gc->wq_head = desc->head;
249-
250-
kunmap_atomic(base);
251245
return ret;
252246
}
253247

@@ -341,10 +335,8 @@ static void guc_init_proc_desc(struct intel_guc *guc,
341335
struct i915_guc_client *client)
342336
{
343337
struct guc_process_desc *desc;
344-
void *base;
345338

346-
base = kmap_atomic(i915_gem_object_get_page(client->client_obj, 0));
347-
desc = base + client->proc_desc_offset;
339+
desc = client->client_base + client->proc_desc_offset;
348340

349341
memset(desc, 0, sizeof(*desc));
350342

@@ -361,8 +353,6 @@ static void guc_init_proc_desc(struct intel_guc *guc,
361353
desc->wq_size_bytes = client->wq_size;
362354
desc->wq_status = WQ_STATUS_ACTIVE;
363355
desc->priority = client->priority;
364-
365-
kunmap_atomic(base);
366356
}
367357

368358
/*
@@ -474,25 +464,16 @@ static void guc_fini_ctx_desc(struct intel_guc *guc,
474464
int i915_guc_wq_check_space(struct i915_guc_client *gc)
475465
{
476466
struct guc_process_desc *desc;
477-
void *base;
478467
u32 size = sizeof(struct guc_wq_item);
479468
int ret = -ETIMEDOUT, timeout_counter = 200;
480469

481470
if (!gc)
482471
return 0;
483472

484-
/* Quickly return if wq space is available since last time we cache the
485-
* head position. */
486-
if (CIRC_SPACE(gc->wq_tail, gc->wq_head, gc->wq_size) >= size)
487-
return 0;
488-
489-
base = kmap_atomic(i915_gem_object_get_page(gc->client_obj, 0));
490-
desc = base + gc->proc_desc_offset;
473+
desc = gc->client_base + gc->proc_desc_offset;
491474

492475
while (timeout_counter-- > 0) {
493-
gc->wq_head = desc->head;
494-
495-
if (CIRC_SPACE(gc->wq_tail, gc->wq_head, gc->wq_size) >= size) {
476+
if (CIRC_SPACE(gc->wq_tail, desc->head, gc->wq_size) >= size) {
496477
ret = 0;
497478
break;
498479
}
@@ -501,24 +482,23 @@ int i915_guc_wq_check_space(struct i915_guc_client *gc)
501482
usleep_range(1000, 2000);
502483
};
503484

504-
kunmap_atomic(base);
505-
506485
return ret;
507486
}
508487

509488
static int guc_add_workqueue_item(struct i915_guc_client *gc,
510489
struct drm_i915_gem_request *rq)
511490
{
491+
struct guc_process_desc *desc;
512492
struct guc_wq_item *wqi;
513-
void *base;
514-
u32 tail, wq_len, wq_off, space;
493+
u32 tail, wq_len, wqi_off, space;
515494

516-
space = CIRC_SPACE(gc->wq_tail, gc->wq_head, gc->wq_size);
495+
desc = gc->client_base + gc->proc_desc_offset;
496+
space = CIRC_SPACE(gc->wq_tail, desc->head, gc->wq_size);
517497
if (WARN_ON(space < sizeof(struct guc_wq_item)))
518498
return -ENOSPC; /* shouldn't happen */
519499

520500
/* postincrement WQ tail for next time */
521-
wq_off = gc->wq_tail;
501+
wqi_off = gc->wq_tail;
522502
gc->wq_tail += sizeof(struct guc_wq_item);
523503
gc->wq_tail &= gc->wq_size - 1;
524504

@@ -530,13 +510,10 @@ static int guc_add_workqueue_item(struct i915_guc_client *gc,
530510
* workqueue buffer dw by dw.
531511
*/
532512
WARN_ON(sizeof(struct guc_wq_item) != 16);
533-
WARN_ON(wq_off & 3);
513+
WARN_ON(wqi_off & 3);
534514

535515
/* wq starts from the page after doorbell / process_desc */
536-
base = kmap_atomic(i915_gem_object_get_page(gc->client_obj,
537-
(wq_off + GUC_DB_SIZE) >> PAGE_SHIFT));
538-
wq_off &= PAGE_SIZE - 1;
539-
wqi = (struct guc_wq_item *)((char *)base + wq_off);
516+
wqi = gc->client_base + gc->wq_offset + wqi_off;
540517

541518
/* len does not include the header */
542519
wq_len = sizeof(struct guc_wq_item) / sizeof(u32) - 1;
@@ -553,8 +530,6 @@ static int guc_add_workqueue_item(struct i915_guc_client *gc,
553530
wqi->ring_tail = tail << WQ_RING_TAIL_SHIFT;
554531
wqi->fence_id = 0; /*XXX: what fence to be here */
555532

556-
kunmap_atomic(base);
557-
558533
return 0;
559534
}
560535

@@ -675,6 +650,8 @@ static void guc_client_free(struct drm_device *dev,
675650
* Be sure to drop any locks
676651
*/
677652

653+
vunmap(client->client_base);
654+
678655
gem_release_guc_obj(client->client_obj);
679656

680657
if (client->ctx_index != GUC_INVALID_CTX_ID) {
@@ -727,6 +704,8 @@ static struct i915_guc_client *guc_client_alloc(struct drm_device *dev,
727704
if (!obj)
728705
goto err;
729706

707+
client->client_base = i915_gem_object_vmap(obj, 0, obj->pages->nents);
708+
730709
client->client_obj = obj;
731710
client->wq_offset = GUC_DB_SIZE;
732711
client->wq_size = GUC_WQ_SIZE;

drivers/gpu/drm/i915/intel_guc.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ struct i915_guc_client {
3434
uint32_t priority;
3535
uint32_t ctx_index;
3636

37+
void *client_base;
38+
3739
uint32_t proc_desc_offset;
3840
uint32_t doorbell_offset;
3941
uint32_t cookie;
@@ -43,7 +45,6 @@ struct i915_guc_client {
4345
uint32_t wq_offset;
4446
uint32_t wq_size;
4547
uint32_t wq_tail;
46-
uint32_t wq_head;
4748

4849
/* GuC submission statistics & status */
4950
uint64_t submissions[GUC_MAX_ENGINES_NUM];

0 commit comments

Comments
 (0)