From patchwork Sun Mar 25 10:57:56 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: 10306551 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 558F360385 for ; Sun, 25 Mar 2018 10:58:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4765129341 for ; Sun, 25 Mar 2018 10:58:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C3F729332; Sun, 25 Mar 2018 10:58:08 +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 C61F729308 for ; Sun, 25 Mar 2018 10:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752526AbeCYK6F (ORCPT ); Sun, 25 Mar 2018 06:58:05 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38945 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752469AbeCYK6D (ORCPT ); Sun, 25 Mar 2018 06:58:03 -0400 Received: by mail-wr0-f194.google.com with SMTP id c24so16091101wrc.6 for ; Sun, 25 Mar 2018 03:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8AQ+/P/VxVM3VxvZTSDMud1800UZCZF8Trw106F9gmg=; b=jv6axO6P5F0IhHiLdL/RUmqyxsP1GCfl9maYgtSh/i6SddvXVbtZoHuZXo6u4N5Byk UVKiczDAuECLDCl4Pb9gEUL54UqPRahYEOCPO/+tCXfrk31lA+Fuo/ZRLZYj47D+xdX+ eIq3QiO+ZVbFuDca/ckZDYG8Z8PUHqiv6F7VuLaK9euTfuHyZo5DJhvIcMQaT6jbRQtX WJUQVIOIRPWLx4/36Pz1NZLtMyyqKkuoV0JeTDZGwFJpJM521FLqVEyopDcZqlm6ueKV cKC4okL43/dIInmf3sFpeZmXtGRpZrbqJbYkjIHz2shjy6CkC1KppLUQ5sxqMSHyr4Tq OUgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8AQ+/P/VxVM3VxvZTSDMud1800UZCZF8Trw106F9gmg=; b=lxzfYpmNAtU42tc3QVK3FTLGM0EXrwy1d4/gVHDCfQBPrTvHNTT6iBP1TxTU0hdGXh 1iA8oex9+LmXCI7qLwA2iJxYMIwRlnYRPgFvmDekz7y8Bln2+t4UoctZgXyd8hdxcUA/ hSbvase54goiKY8clCCWBhWLKZsP2FNL1uT0NEKgPqF1WOiVb8ZR4aj7zHGk0PsiKbpQ UIi9iJJ1GwlAu2xgJQTs0iX4/pEaBkkngARrNz/ZF1eH6pJsMT7IoD6c9PznZjs5IzWj QWCxi7Qku3GISnGf5AOH7DZpXy95tWsNNPohQrw+yWqxSHGU97ZleLFIrjmNa64E5j70 SNjA== X-Gm-Message-State: AElRT7E9XiHNpjaY+0PqHz6QfubP0R6ojiaj+Q2XzvxM5zRZLsn/JWGj PhMtFGI/paClNqpXybUFhiA= X-Google-Smtp-Source: AG47ELsVP8zqhHvfBTs8+mtHVhsnqubJKYwTsrdxg4LQcEooJXxrAQxNN2nMaKpf6kWycD3SSE+wwA== X-Received: by 10.223.195.116 with SMTP id e49mr27156424wrg.5.1521975482560; Sun, 25 Mar 2018 03:58:02 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:80f2:8bcd:4355:2edc]) by smtp.gmail.com with ESMTPSA id c187sm1033899wmf.18.2018.03.25.03.58.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Mar 2018 03:58:02 -0700 (PDT) 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, sumit.semwal@linaro.org Subject: [PATCH 2/5] drm/ttm: keep a reference to transfer pipelined BOs Date: Sun, 25 Mar 2018 12:57:56 +0200 Message-Id: <20180325105759.2151-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180325105759.2151-1-christian.koenig@amd.com> References: <20180325105759.2151-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; }