Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp225522imw; Fri, 15 Jul 2022 01:46:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s8SNvrz4DHni8yAJvF9EUG3IyUgl6G3srtTt/JF5IAL5O9LlNrmXfOIbt5D4X3Tn+2wT/e X-Received: by 2002:a17:907:96a8:b0:72b:40b0:658 with SMTP id hd40-20020a17090796a800b0072b40b00658mr12781862ejc.3.1657874813584; Fri, 15 Jul 2022 01:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657874813; cv=none; d=google.com; s=arc-20160816; b=fRXTXy/TX0y43EFOReV2AUXtN7cQxMtoNyntBAXUsksiD1dykMwuK2CJP14sY4AFt1 3ZnbqJMJtmmU8QyafFAVLiaUniLoknXFFhNgJY2XFIAWkH03+idegUzv426dsbqLLORB Yp/6/X9+9MzuKBCDHU/AMhoJy23efBD4eUs6JdxqLOh8SW7A4nQTtqDBp2KNAW0YsSxN hcL1VBN/RFe+LgtBBLRpe/lu2moW2nkJeguThQgYAs9Cb6KDt4/lNo7eszCB+9etv2Mq SwNZwgVnH4rB6Bo75pGXHC0lqPb0uCXvJqyeAOf9TozS1MGhYZ/1XbJVInSAhvgC38+Q kjOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=pOtC54uPNRD/uOwUcT/mSMMhnJFigPO2ZA8tTat+T+U=; b=ApJeZR2OJuIorZNITGm8mDPwE68Xv6yFomvrkDs+QDq9l9kXiYyNp/GRRdufDTFg66 9tIHgx8dfmzDgo7i5Y6g3A09fGC5Dkvr2V3rM+ZfqmLsmLHklywUF3KkDSM8azmI1AOe QemrYQKFZ/RbRQNUiP4GKqs090gqOBEDZoCH7i+uEOajvrhnfdZ1CXm9Yi7bOEbQc4rH FvLfUKDSKjxceA//gjadpcDpe8SBhSsbyf/ZmryjpW4SitnONHM2CvGEw3EV4r7wPLt6 FgdD07Q1H0lK6uS7V456th9ml8F5Xca71oEosIkLueuO4GMiqMDCHbPhWdeTz1MccNBT rNRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="Eg/kmP5x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a170906700e00b007296e194403si2999617ejj.273.2022.07.15.01.46.28; Fri, 15 Jul 2022 01:46:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="Eg/kmP5x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232097AbiGOI0Y (ORCPT + 99 others); Fri, 15 Jul 2022 04:26:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232043AbiGOI0X (ORCPT ); Fri, 15 Jul 2022 04:26:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2604D7FE6B for ; Fri, 15 Jul 2022 01:26:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5BB762057 for ; Fri, 15 Jul 2022 08:26:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1574CC34115; Fri, 15 Jul 2022 08:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657873581; bh=iFolp2jzrEerpXz5e6fXs3X5/rU+qvcxywsSCPc3mvM=; h=From:To:Cc:Subject:Date:From; b=Eg/kmP5xzo/enM6Exj402J70zyK1j+DLRtqwgjhGHusdYy0Mo9MVHVqpZ9P/N5ZQH 4nDDJaSioBjua+9INgDucPBL8E8v7Ps0ZH7dcrQJuNPM0OEJ1k12nEbX0p4UBqZ+gy EeNyFNBnBJf+PHI/TiLM+Wr8Gy94dJ4qg2k36ZqgX8Su8ebOzyJRRM5xHgX/btAHin lGzs959UIzNIW28j4D9TdvAiaeL8+FV0mpOvex/7o5aHG11jaJO0S1e1vgDZzpWwKO KbaLuTB5Fw/nyYnAMQePu+HL4tQ3x3KgWUF4pkiyE5z/syKxeRIsCfWoC3yLND2v6B AdDfxhnfYiB9g== Received: from mchehab by mail.kernel.org with local (Exim 4.95) (envelope-from ) id 1oCGeP-005Phx-FY; Fri, 15 Jul 2022 09:26:17 +0100 From: Mauro Carvalho Chehab Cc: Chris Wilson , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Daniel Vetter , David Airlie , Jani Nikula , John Harrison , Joonas Lahtinen , Maarten Lankhorst , Matt Roper , Matthew Auld , Matthew Brost , Rodrigo Vivi , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Andrzej Hajda , Mika Kuoppala , Mauro Carvalho Chehab Subject: [PATCH RFC] drm/i915/gt: Retry RING_HEAD reset until it sticks Date: Fri, 15 Jul 2022 09:26:16 +0100 Message-Id: <2378da383d043de17172d928e59da0ec423cae76.1657873550.git.mchehab@kernel.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chris Wilson On Haswell, in particular, we see an issue where resets fails because the engine resumes from an incorrect RING_HEAD. Since the RING_HEAD doesn't point to the remaining requests to re-run, but may instead point into the uninitialised portion of the ring, the GPU may be then fed invalid instructions from a privileged context, oft pushing the GPU into an unrecoverable hang. If at first the write doesn't succeed, try, try again. References: https://gitlab.freedesktop.org/drm/intel/-/issues/5432 Testcase: igt/i915_selftest/hangcheck Signed-off-by: Chris Wilson Cc: Andrzej Hajda Cc: Mika Kuoppala Signed-off-by: Mauro Carvalho Chehab --- .../gpu/drm/i915/gt/intel_ring_submission.c | 44 +++++++++++++------ drivers/gpu/drm/i915/i915_utils.h | 10 +++++ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_ring_submission.c b/drivers/gpu/drm/i915/gt/intel_ring_submission.c index d5d6f1fadcae..cc53feb1f8ed 100644 --- a/drivers/gpu/drm/i915/gt/intel_ring_submission.c +++ b/drivers/gpu/drm/i915/gt/intel_ring_submission.c @@ -190,6 +190,7 @@ static bool stop_ring(struct intel_engine_cs *engine) static int xcs_resume(struct intel_engine_cs *engine) { struct intel_ring *ring = engine->legacy.ring; + ktime_t kt; ENGINE_TRACE(engine, "ring:{HEAD:%04x, TAIL:%04x}\n", ring->head, ring->tail); @@ -228,9 +229,20 @@ static int xcs_resume(struct intel_engine_cs *engine) set_pp_dir(engine); /* First wake the ring up to an empty/idle ring */ - ENGINE_WRITE_FW(engine, RING_HEAD, ring->head); + until_timeout_ns(kt, 2 * NSEC_PER_MSEC) { + ENGINE_WRITE_FW(engine, RING_HEAD, ring->head); + if (ENGINE_READ_FW(engine, RING_HEAD) == ring->head) + break; + } + ENGINE_WRITE_FW(engine, RING_TAIL, ring->head); - ENGINE_POSTING_READ(engine, RING_TAIL); + if (ENGINE_READ_FW(engine, RING_HEAD) != ENGINE_READ_FW(engine, RING_TAIL)) { + ENGINE_TRACE(engine, "failed to reset empty ring: [%x, %x]: %x\n", + ENGINE_READ_FW(engine, RING_HEAD), + ENGINE_READ_FW(engine, RING_TAIL), + ring->head); + goto err; + } ENGINE_WRITE_FW(engine, RING_CTL, RING_CTL_SIZE(ring->size) | RING_VALID); @@ -239,12 +251,16 @@ static int xcs_resume(struct intel_engine_cs *engine) if (__intel_wait_for_register_fw(engine->uncore, RING_CTL(engine->mmio_base), RING_VALID, RING_VALID, - 5000, 0, NULL)) + 5000, 0, NULL)) { + ENGINE_TRACE(engine, "failed to restart\n"); goto err; + } - if (GRAPHICS_VER(engine->i915) > 2) + if (GRAPHICS_VER(engine->i915) > 2) { ENGINE_WRITE_FW(engine, RING_MI_MODE, _MASKED_BIT_DISABLE(STOP_RING)); + ENGINE_POSTING_READ(engine, RING_MI_MODE); + } /* Now awake, let it get started */ if (ring->tail != ring->head) { @@ -257,16 +273,16 @@ static int xcs_resume(struct intel_engine_cs *engine) return 0; err: - drm_err(&engine->i915->drm, - "%s initialization failed; " - "ctl %08x (valid? %d) head %08x [%08x] tail %08x [%08x] start %08x [expected %08x]\n", - engine->name, - ENGINE_READ(engine, RING_CTL), - ENGINE_READ(engine, RING_CTL) & RING_VALID, - ENGINE_READ(engine, RING_HEAD), ring->head, - ENGINE_READ(engine, RING_TAIL), ring->tail, - ENGINE_READ(engine, RING_START), - i915_ggtt_offset(ring->vma)); + ENGINE_TRACE(engine, + "initialization failed; " + "ctl %08x (valid? %d) head %08x [%08x] tail %08x [%08x] start %08x [expected %08x]\n", + ENGINE_READ(engine, RING_CTL), + ENGINE_READ(engine, RING_CTL) & RING_VALID, + ENGINE_READ(engine, RING_HEAD), ring->head, + ENGINE_READ(engine, RING_TAIL), ring->tail, + ENGINE_READ(engine, RING_START), + i915_ggtt_offset(ring->vma)); + GEM_TRACE_DUMP(); return -EIO; } diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h index c10d68cdc3ca..717fb6b9cc15 100644 --- a/drivers/gpu/drm/i915/i915_utils.h +++ b/drivers/gpu/drm/i915/i915_utils.h @@ -256,6 +256,16 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms) } } +/** + * until_timeout_ns - Keep retrying (busy spin) until the duration has passed + * @end: temporary var to be used to track the spent time + * @timeout_ns: Maximum timeout, in nanosseconds + */ +#define until_timeout_ns(end, timeout_ns) \ + for ((end) = ktime_get() + (timeout_ns); \ + ktime_before(ktime_get(), (end)); \ + cpu_relax()) + /** * __wait_for - magic wait macro * -- 2.36.1