Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp749808imw; Wed, 13 Jul 2022 07:20:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sJGsfC6TUmt8GdKB4C0aunhG2xjyCsMt4GL++vmMehboZiL+E4+3arBwpxBZV8Fwa9feIO X-Received: by 2002:a17:907:16ab:b0:72c:7533:7262 with SMTP id hc43-20020a17090716ab00b0072c75337262mr2197885ejc.288.1657722047225; Wed, 13 Jul 2022 07:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657722047; cv=none; d=google.com; s=arc-20160816; b=Jnkk0MpQumsgpGw9qOnEqoHTebaV5IsRJFK31HU94fOciWjxgguWfafaEhz6tDEnyr uZAxAjRfPg+CW3VDAap851JYrSYsEr4L6RZMSzKy8mVt+cJ/SwZrNOk8vl8uJRHlvr7C z1BewqEvuceCAhiXvmMtY1qft1dP8h/+UjVM9QKukDrgcVahkcqWhGXdt+lqhA7X7732 N1Ap3EgOrsDx4TSj4uFl0Xb4+JuA+CzcUczIMU/LpLFwP5JIamSloBTj8Om+QcTxpnBv CDRGKqJRP5iv0EvHiZ3ym63+GeWD3FtbbhEMEpdr5EwUOSz7GGxqDqbuWqqbSNf71IRe b35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H6G48KEoFr2X1aPMmPDY0olQvb+1p4/DMaEGATkk4+A=; b=G2W1jASmB1zKyixa+BHmHPwRGILVlWWSEuaDe3+5BmNx9rDWK3mhMCRRnQ/AYyW7VB qoLb/ZKan8CKam9P6HzkXWElWyG651819HmMF9JcZOvAtmxJbzw8tcYSN+KoA9UAGRh+ Nc2wk7P4BVYsG+3bUvyfXqLDA9xncTvdrs7VLT0yvH6zb76Ny77dQXJ3tP9C2LRPwM56 Lxhn5rMZi5QlwbwBnmq9mLfupQ6bRjve/YZOpMLhe9mu9IiaeRoylRss4q0FWtmQDcsa wyxxiFkL/naAYQoY0O0990UoQ2W56Jjl8sThgQUgV4INLNlxMx79opEM90ko8UzpDoge EGiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XgTnw6wl; 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=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b1-20020aa7df81000000b0043a90a309aasi17179250edy.130.2022.07.13.07.20.08; Wed, 13 Jul 2022 07:20:47 -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=pass header.i=@collabora.com header.s=mail header.b=XgTnw6wl; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236351AbiGMNvI (ORCPT + 99 others); Wed, 13 Jul 2022 09:51:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236279AbiGMNuq (ORCPT ); Wed, 13 Jul 2022 09:50:46 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 099A514D3C for ; Wed, 13 Jul 2022 06:50:44 -0700 (PDT) Received: from hermes-devbox.fritz.box (82-71-8-225.dsl.in-addr.zen.co.uk [82.71.8.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbeckett) by madras.collabora.co.uk (Postfix) with ESMTPSA id 80BEB66019BF; Wed, 13 Jul 2022 14:50:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1657720243; bh=uwyKpWlNH8QK8xQy7lI/WZGpczdTFtV/IRUxiesx9gY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgTnw6wlQ/AA3P4NVbhMSJJGJT7StIXLfdSrRA7iEk/eC0sCupkCs28FO/0VnF7Ze iWNS0M8zEo3y9Me3Wu+mwdcB3lCjz0eXnReuugnnMow0aRQD3bwwaw7YlD+UJQTnzP O+2bhlAjFOktoDgcLEKpA0+b+8ra5lymJDoKVwp1tOSO7pS8iyQB4JQrjSpLGG78Xo J9EsIO0yF6Ffkn+V0c0Kf0UuTCb0pwheQpejhyl7GAsNlrL1tV6MLJRVKKMusTcTw7 NyobeSE8OscKUF/sA7ac7x6hCdTb0KVw7FsHvltZQBrDkn3/VhLp41J8IOjMPrq50U d1KRIRf+DyPeA== From: Robert Beckett To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Cc: kernel@collabora.com, Robert Beckett , Matthew Auld , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , linux-kernel@vger.kernel.org Subject: [PATCH v11 06/10] drm/i915: ttm move/clear logic fix Date: Wed, 13 Jul 2022 14:50:18 +0100 Message-Id: <20220713135022.3710682-7-bob.beckett@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220713135022.3710682-1-bob.beckett@collabora.com> References: <20220713135022.3710682-1-bob.beckett@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ttm managed buffers start off with system resource definitions and ttm_tt tracking structures allocated (though unpopulated). currently this prevents clearing of buffers on first move to desired placements. The desired behaviour is to clear user allocated buffers and any kernel buffers that specifically requests it only. Make the logic match the desired behaviour. Signed-off-by: Robert Beckett Reviewed-by: Thomas Hellström --- drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c index 18d574ac167f..6671345b2abe 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c @@ -3,6 +3,7 @@ * Copyright © 2021 Intel Corporation */ +#include "drm/ttm/ttm_tt.h" #include #include "i915_deps.h" @@ -546,6 +547,25 @@ __i915_ttm_move(struct ttm_buffer_object *bo, return fence; } +static bool +allow_clear(struct drm_i915_gem_object *obj, struct ttm_tt *ttm, struct ttm_resource *dst_mem) +{ + /* never clear stolen */ + if (dst_mem->mem_type == I915_PL_STOLEN) + return false; + /* + * we want to clear user buffers and any kernel buffers + * that specifically request clearing. + */ + if (obj->flags & I915_BO_ALLOC_USER) + return true; + + if (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) + return true; + + return false; +} + /** * i915_ttm_move - The TTM move callback used by i915. * @bo: The buffer object. @@ -596,7 +616,7 @@ int i915_ttm_move(struct ttm_buffer_object *bo, bool evict, return PTR_ERR(dst_rsgt); clear = !i915_ttm_cpu_maps_iomem(bo->resource) && (!ttm || !ttm_tt_is_populated(ttm)); - if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC))) { + if (!clear || allow_clear(obj, ttm, dst_mem)) { struct i915_deps deps; i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); -- 2.25.1