From patchwork Fri Mar 16 23:04:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10290465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0549760386 for ; Fri, 16 Mar 2018 23:04:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB4EE290E4 for ; Fri, 16 Mar 2018 23:04:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF13C290EE; Fri, 16 Mar 2018 23:04:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6BBF2290E4 for ; Fri, 16 Mar 2018 23:04:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1257489DA6; Fri, 16 Mar 2018 23:04:40 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 809E789DA6 for ; Fri, 16 Mar 2018 23:04:38 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 11060542-1500050 for multiple; Fri, 16 Mar 2018 23:04:30 +0000 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Fri, 16 Mar 2018 23:04:29 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 16 Mar 2018 23:04:23 +0000 Message-Id: <20180316230423.28124-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.16.2 In-Reply-To: <152123420579.18954.12115249281792091361@mail.alporthouse.com> References: <152123420579.18954.12115249281792091361@mail.alporthouse.com> X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH] force-preempt-reset X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP A more concrete idea of what I think the serialisation should be between reset timer and tasklet. --- drivers/gpu/drm/i915/intel_lrc.c | 43 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.h | 4 +++ 2 files changed, 47 insertions(+) diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index 2c2eb6d3868a..b6fd4323663d 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -531,6 +531,39 @@ static void inject_preempt_context(struct intel_engine_cs *engine) execlists_clear_active(execlists, EXECLISTS_ACTIVE_HWACK); execlists_set_active(execlists, EXECLISTS_ACTIVE_PREEMPT); + + /* Set a timer to force preemption vs hostile userspace */ + if (execlists->preempt_timeout_ns) + hrtimer_start(&execlists->preempt_timer, + ktime_set(0, execlists->preempt_timeout_ns), + HRTIMER_MODE_REL); +} + +static enum hrtimer_restart preempt_timeout(struct hrtimer *hrtimer) +{ + struct intel_engine_cs *engine = + container_of(hrtimer, typeof(*engine), execlists.preempt_timer); + + if (execlists_is_active(&engine->execlists, EXECLISTS_ACTIVE_PREEMPT)) + queue_work(system_highpri_wq, &engine->execlists.preempt_reset); + + return HRTIMER_NORESTART; +} + +static void preempt_reset(struct work_struct *work) +{ + struct intel_engine_cs *engine = + container_of(work, typeof(*engine), execlists.preempt_reset); + + tasklet_disable(&engine->execlists.tasklet); + + engine->execlists.tasklet.func(engine->execlists.tasklet.data); + + if (execlists_is_active(&engine->execlists, EXECLISTS_ACTIVE_PREEMPT)) + i915_handle_error(engine->i915, BIT(engine->id), 0, + "preemption timed out on %s", engine->name); + + tasklet_enable(&engine->execlists.tasklet); } static void complete_preempt_context(struct intel_engine_execlists *execlists) @@ -539,6 +572,11 @@ static void complete_preempt_context(struct intel_engine_execlists *execlists) execlists_unwind_incomplete_requests(execlists); GEM_BUG_ON(!execlists_is_active(execlists, EXECLISTS_ACTIVE_PREEMPT)); + + /* If the timer already fired, complete the reset */ + if (hrtimer_try_to_cancel(&execlists->preempt_timer) < 0) + return; + execlists_clear_active(execlists, EXECLISTS_ACTIVE_PREEMPT); } @@ -2182,6 +2220,11 @@ logical_ring_setup(struct intel_engine_cs *engine) tasklet_init(&engine->execlists.tasklet, execlists_submission_tasklet, (unsigned long)engine); + INIT_WORK(&engine->execlists.preempt_reset, preempt_reset); + hrtimer_init(&engine->execlists.preempt_timer, + CLOCK_MONOTONIC, HRTIMER_MODE_REL); + engine->execlists.preempt_timer.function = preempt_timeout; + logical_ring_default_vfuncs(engine); logical_ring_default_irqs(engine); } diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 495b21fc33db..74fcff8a2a6e 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -307,6 +307,10 @@ struct intel_engine_execlists { * @preempt_complete_status: expected CSB upon completing preemption */ u32 preempt_complete_status; + + struct hrtimer preempt_timer; + struct work_struct preempt_reset; + unsigned long preempt_timeout_ns; }; #define INTEL_ENGINE_CS_MAX_NAME 8