From patchwork Fri Mar 9 19:11:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10271809 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 9FB326016D for ; Fri, 9 Mar 2018 19:12:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 909EA29F68 for ; Fri, 9 Mar 2018 19:12:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F67829FB2; Fri, 9 Mar 2018 19:12:02 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 002E529F68 for ; Fri, 9 Mar 2018 19:12:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED45D6EC12; Fri, 9 Mar 2018 19:11:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 682526EC07; Fri, 9 Mar 2018 19:11:50 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id x7so5721890wmc.0; Fri, 09 Mar 2018 11:11:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8AQ+/P/VxVM3VxvZTSDMud1800UZCZF8Trw106F9gmg=; b=S5qGDyaCPBz/UeRWp3amgYcQN5HSRD7yCgknugwATTCL13bLYmB2e3olHUrFKrW0Bg m/h9m8etdxeOX+tiLFU3o0WF8fEQAVCkbtlQh+s5ykf27seuH9ETgnpj3gL3TuFQ9OHf VsiquFoWAmI2omLfl7CE1ACUavo2G6sRP+hGULMsqQtYyHgcvHqmpJRgvlaAfKusW1w9 qKZsnb7+BFh2amylXDI7JgI8KRzo8Fowj0CnsgRzhLicgK63YlU3SgsPEtiX8HGUjrPU Jo4geFlRo1ebjCxPyR7GdwdUw5XPcaC8rnJqjKEtTzRdIjwYCKS69N+KgVXQOg3e0gpV 0q+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8AQ+/P/VxVM3VxvZTSDMud1800UZCZF8Trw106F9gmg=; b=GZKgK1fQwjRdhAWvv+XwK/OXdCmnpCRu504NroawlNgMikN+aXOkwwkGVN3Z6CtwGY kbWB9k77lKxwKVzCw6u0PkOI85hnoN0a6DH2arAUYPgn8KL7m9J7Ks7Y+cXQbpnqdBo/ vW7b0USwhW63U+bIRGnrHuB3ySGZg1n3A3IP+YUy65MMn7mwRlgeaDJCqNvj466d9jza ABivy8BZfHGW2VThvjIkUl8r8EYERWKxzO/BtuKHUiM8ZVbYG2MKpq8CfZgMCubZnu1r y31v4NU7NkaeHjT+rPGjhmhiO0E55g4YpuOCVo0AbvpwUXz90Kdr007BIpyP6JnhN4FY 5lvg== X-Gm-Message-State: AElRT7HtBXslqiy/5yTkeETa0SbqI5B8rtEqfJXso3oM//pPD+M4BjFY Ajno0Z4Ptwn6K8WkE6oRkKo= X-Google-Smtp-Source: AG47ELuUbWcH57I1vVyHWh3YO5+5hmgFNe+R9pfTDcJPMuwooO6KhhlBUfZGUQrqXu0AiJQAH3rzPA== X-Received: by 10.28.217.205 with SMTP id q196mr3007042wmg.149.1520622708896; Fri, 09 Mar 2018 11:11:48 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:ccef:4aaf:cf58:8fe7]) by smtp.gmail.com with ESMTPSA id o12sm1811922wrb.15.2018.03.09.11.11.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Mar 2018 11:11:48 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 2/4] drm/ttm: keep a reference to transfer pipelined BOs Date: Fri, 9 Mar 2018 20:11:42 +0100 Message-Id: <20180309191144.1817-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180309191144.1817-1-christian.koenig@amd.com> References: <20180309191144.1817-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make sure the transfered BO is never destroy before the transfer BO. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo_util.c | 50 +++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 1f730b3f18e5..1ee20558ee31 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -39,6 +39,11 @@ #include #include +struct ttm_transfer_obj { + struct ttm_buffer_object base; + struct ttm_buffer_object *bo; +}; + void ttm_bo_free_old_node(struct ttm_buffer_object *bo) { ttm_bo_mem_put(bo, &bo->mem); @@ -435,7 +440,11 @@ EXPORT_SYMBOL(ttm_bo_move_memcpy); static void ttm_transfered_destroy(struct ttm_buffer_object *bo) { - kfree(bo); + struct ttm_transfer_obj *fbo; + + fbo = container_of(bo, struct ttm_transfer_obj, base); + ttm_bo_unref(&fbo->bo); + kfree(fbo); } /** @@ -456,14 +465,15 @@ static void ttm_transfered_destroy(struct ttm_buffer_object *bo) static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, struct ttm_buffer_object **new_obj) { - struct ttm_buffer_object *fbo; + struct ttm_transfer_obj *fbo; int ret; fbo = kmalloc(sizeof(*fbo), GFP_KERNEL); if (!fbo) return -ENOMEM; - *fbo = *bo; + fbo->base = *bo; + fbo->bo = ttm_bo_reference(bo); /** * Fix up members that we shouldn't copy directly: @@ -471,25 +481,25 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, */ atomic_inc(&bo->bdev->glob->bo_count); - INIT_LIST_HEAD(&fbo->ddestroy); - INIT_LIST_HEAD(&fbo->lru); - INIT_LIST_HEAD(&fbo->swap); - INIT_LIST_HEAD(&fbo->io_reserve_lru); - mutex_init(&fbo->wu_mutex); - fbo->moving = NULL; - drm_vma_node_reset(&fbo->vma_node); - atomic_set(&fbo->cpu_writers, 0); - - kref_init(&fbo->list_kref); - kref_init(&fbo->kref); - fbo->destroy = &ttm_transfered_destroy; - fbo->acc_size = 0; - fbo->resv = &fbo->ttm_resv; - reservation_object_init(fbo->resv); - ret = reservation_object_trylock(fbo->resv); + INIT_LIST_HEAD(&fbo->base.ddestroy); + INIT_LIST_HEAD(&fbo->base.lru); + INIT_LIST_HEAD(&fbo->base.swap); + INIT_LIST_HEAD(&fbo->base.io_reserve_lru); + mutex_init(&fbo->base.wu_mutex); + fbo->base.moving = NULL; + drm_vma_node_reset(&fbo->base.vma_node); + atomic_set(&fbo->base.cpu_writers, 0); + + kref_init(&fbo->base.list_kref); + kref_init(&fbo->base.kref); + fbo->base.destroy = &ttm_transfered_destroy; + fbo->base.acc_size = 0; + fbo->base.resv = &fbo->base.ttm_resv; + reservation_object_init(fbo->base.resv); + ret = reservation_object_trylock(fbo->base.resv); WARN_ON(!ret); - *new_obj = fbo; + *new_obj = &fbo->base; return 0; }