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: 10271805 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 1A34C6016D 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 0983529FFB for ; Fri, 9 Mar 2018 19:12:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 071EA29F8A; 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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A19829FDC for ; Fri, 9 Mar 2018 19:11:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932674AbeCITLw (ORCPT ); Fri, 9 Mar 2018 14:11:52 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:39386 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932657AbeCITLu (ORCPT ); Fri, 9 Mar 2018 14:11:50 -0500 Received: by mail-wm0-f65.google.com with SMTP id i3so5680373wmi.4 for ; Fri, 09 Mar 2018 11:11:49 -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=kACbxyHt6NwBvvu5vdwVU8HDE4sxsAqBotGgGuXct+vr4rDKmQWulBmsf3xAhp03Xv /wJ8PyWrbZKOjrLF8loRK4bECz3Qp6/0p/G4Rd/ekjWUE67AD0OEPEt0QhNmHkUinG0H W7nyWr1d/9YMDhtuFQ5+xaUBJ8vLQ96ASCMl+gXvuWenJAwLugshorxAqnsmj91ECnTh mzfU2udtyrrKm495pwXdQH28lagLa/n0dWJZbF82X6lrWwPK65vIDh32V+6CIO7OKo/E Rdbzz597w/1lwTN2nKyypTqshBQPUvJbIPSUV3MSDvIXqZYVXn6zhoE6cj7vMgnOZNC3 zxXQ== X-Gm-Message-State: AElRT7GW7krtnCLAXPB4pxSu8exag46UI1uR96zrQSqAoiSlYE2UXFCp TkKcGxFPwQcdCKYxIoOxuDso4Q== 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 Cc: sumit.semwal@linaro.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 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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; }