Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1410336yba; Tue, 2 Apr 2019 08:21:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFbdvEbsfDBRjw0yGh2sS7PGVBgbxW2o5EZLUz5QZ1LeFdz029LUqCt3KgfREvBMoN2cG2 X-Received: by 2002:a62:f20e:: with SMTP id m14mr45947845pfh.228.1554218514359; Tue, 02 Apr 2019 08:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554218514; cv=none; d=google.com; s=arc-20160816; b=t3UIRwrUD54qqI9OoJ0GVQ5pWXNcCwzXLNWSRdVGjkn2/ckHb0yq8/a7ocbq4Sssc7 oD8f8I78gjoX6lTiN6y0qJwfEd6L75TsKM52q9VkXUaRgkzlkQMMOkZKYVgs85CNyvZ7 NorLmEKvySNwQxwU80y9pfS/0pIh6m8+YPLh9sdUfAIH8YyY4iT0bT/7PD3De5YZWwsw 0utX+6HKquc35ChAvbUqIurd1Ww09e2+/rxrgESLCH6Z2Mn76C7d1OEoJMNGsRhqbbhx OeW1nBcXtBzUmsz/sqgHbrlPV7fOolG+KuQzCTMX9k+WAPrxL7vJ2vyCmUtaHqAYeZb3 lcQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=4CxGWb60H6RF2zlr/L17E+bwndlOWRZC33f93jxo0v8=; b=zBtvBCZZSJJ4cACXIMRXhUpPj9LWCeoFDFa65EV2C5AH1kO+AUZNTz87/p9+WLD4pC tl06pA+YvgKyQ0VLW/AAAN71CPxnGsFVbkFe/IlMFmd/yQs5gHS0AR9xJmlS/a/H+LGp NEk2iN1h9Iqd1mUNS/+3pbRdFnzZnc0dYiBPjnqx2xkxd02+zD4lNL6qVjXfcRbj6gQq 88RWRWMkT8qKCX7xOh9FNHxLi+GZyREmWOqs4S9Ai8WCRzHHpdLfmslLXFevUSgu2MZp 2QmP7iBzWh+lCKPZAz3b9voBpYukIGbfHHjRJO3C6XLOBuDto+8ZisfM+58RpDSlMc5t SfNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14si3784627pls.175.2019.04.02.08.21.25; Tue, 02 Apr 2019 08:21:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731209AbfDBNkC (ORCPT + 99 others); Tue, 2 Apr 2019 09:40:02 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:42802 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731141AbfDBNkB (ORCPT ); Tue, 2 Apr 2019 09:40:01 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJdu-0002mV-2k; Tue, 02 Apr 2019 14:39:58 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdt-0004qT-5h; Tue, 02 Apr 2019 14:39:57 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Chris Wilson" , "Ville =?UTF-8?Q?Syrj=C3=A4l=C3=A4?=" Date: Tue, 02 Apr 2019 14:38:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 02/99] drm/i915/ringbuffer: Delay after EMIT_INVALIDATE for gen4/gen5 In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.65-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Chris Wilson commit 55f99bf2a9c331838c981694bc872cd1ec4070b2 upstream. Exercising the gpu reloc path strenuously revealed an issue where the updated relocations (from MI_STORE_DWORD_IMM) were not being observed upon execution. After some experiments with adding pipecontrols (a lot of pipecontrols (32) as gen4/5 do not have a bit to wait on earlier pipe controls or even the current on), it was discovered that we merely needed to delay the EMIT_INVALIDATE by several flushes. It is important to note that it is the EMIT_INVALIDATE as opposed to the EMIT_FLUSH that needs the delay as opposed to what one might first expect -- that the delay is required for the TLB invalidation to take effect (one presumes to purge any CS buffers) as opposed to a delay after flushing to ensure the writes have landed before triggering invalidation. Testcase: igt/gem_tiled_fence_blits Signed-off-by: Chris Wilson Reviewed-by: Ville Syrjälä Link: https://patchwork.freedesktop.org/patch/msgid/20181105094305.5767-1-chris@chris-wilson.co.uk [bwh: Backported to 3.16: - Use intel_ring_emit() instead of assignments - Use ring->scratch.gtt_offset instead of i915_ggtt_offset() - Use (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) instead of (mode & EMIT_INVALIDATE) - Adjust context] Signed-off-by: Ben Hutchings --- drivers/gpu/drm/i915/intel_ringbuffer.c | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -103,6 +103,7 @@ gen4_render_ring_flush(struct intel_engi struct drm_device *dev = ring->dev; u32 cmd; int ret; + int i; /* * read/write caches: @@ -142,12 +143,47 @@ gen4_render_ring_flush(struct intel_engi (IS_G4X(dev) || IS_GEN5(dev))) cmd |= MI_INVALIDATE_ISP; - ret = intel_ring_begin(ring, 2); + i = 2; + if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) + i += 20; + + ret = intel_ring_begin(ring, i); if (ret) return ret; intel_ring_emit(ring, cmd); - intel_ring_emit(ring, MI_NOOP); + + /* + * A random delay to let the CS invalidate take effect? Without this + * delay, the GPU relocation path fails as the CS does not see + * the updated contents. Just as important, if we apply the flushes + * to the EMIT_FLUSH branch (i.e. immediately after the relocation + * write and before the invalidate on the next batch), the relocations + * still fail. This implies that is a delay following invalidation + * that is required to reset the caches as opposed to a delay to + * ensure the memory is written. + */ + if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) { + intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4) | + PIPE_CONTROL_QW_WRITE); + intel_ring_emit(ring, ring->scratch.gtt_offset | + PIPE_CONTROL_GLOBAL_GTT); + intel_ring_emit(ring, 0); + intel_ring_emit(ring, 0); + + for (i = 0; i < 12; i++) + intel_ring_emit(ring, MI_FLUSH); + + intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4) | + PIPE_CONTROL_QW_WRITE); + intel_ring_emit(ring, ring->scratch.gtt_offset | + PIPE_CONTROL_GLOBAL_GTT); + intel_ring_emit(ring, 0); + intel_ring_emit(ring, 0); + } + + intel_ring_emit(ring, cmd); + intel_ring_advance(ring); return 0;