From patchwork Fri Mar 16 13:20:46 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: 10287067 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 2387A6061F for ; Fri, 16 Mar 2018 13:21:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1695128E97 for ; Fri, 16 Mar 2018 13:21:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AF0528E9B; Fri, 16 Mar 2018 13:21:05 +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 B131828E9C for ; Fri, 16 Mar 2018 13:21:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E1BB6EB4A; Fri, 16 Mar 2018 13:20:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 834566EB41; Fri, 16 Mar 2018 13:20:55 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id q83so2998078wme.5; Fri, 16 Mar 2018 06:20:55 -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=gbdWzVeFZsg1wO76MhKjPR3WpCntzQohz6vFIxnqc2gx65U4if3tpSkGkZAxmKKxAh AN+0McGQz6610m3Ek/djydSHqR0xzBtqsLFt75Lx9e2XsNpnxMQRsuw5P0lNPlFKKvQL F2JswUtXG6iTOT7ptcbOqTsCaHQuIf0E1XIwnMmMIj94OmO56sLNH3X4gFFp0mWifu7i dF/kurVfl3gc5lekhEHZbsWhFGTGYJuXj4+pknHpCInkL/dIXUgyXWmRFOooUcqTMDLi TytmGvlBfgvResHl28hShAbD6llXh8aM4xjXBCbXA46hA4UBSN42GMK1G62G7ui32Sie 84+A== 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=sPn12svvcf8LG5MSS0G2s/qE2gNpA/EUDUzBU6UeAx3//DB46qOfTm1Dvse+sa2pzy uePdd6crbKZWwafCFQlG0GHkn2zg3MvKxng+kUjjVo7fS9lgUOFPa2gWiUNSuIFymWEU bFNoLkhojS0DAlBwrfhTyuMTDWYATpFORFzVnqERt63DNtKIpbCqI7WIS6HwlaLi8Pyp mxE7s7egR5uB7vadt66LigG/UbeUCAhl1WtVX/O9iW1TP8Xby6nEo7Mp5unhLYDztrSx ILGNhbNG1TQmcU6BdB3NKLItbuUoLBsWelGf3b0ooVvUwj7AhAkGkMobcUn1soI/fH5o VI9A== X-Gm-Message-State: AElRT7FEdc4dK/4EdBa3t+fGFCfdL718zvnZ85GN9RYWeJIzmiVNE8tO ZBPRPSNkzQ713MZwN12hF1c= X-Google-Smtp-Source: AG47ELsZz+Nexw1usIYfQ28XVrg3Ie0eZfiCmfzJls8uuiZgvRg2u4+psxB5BevF6nuRhgeGuFomBA== X-Received: by 10.28.14.135 with SMTP id 129mr1764579wmo.53.1521206454037; Fri, 16 Mar 2018 06:20:54 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1251:8fc0:20a1:f59:5f9f:5472]) by smtp.gmail.com with ESMTPSA id r136sm4947675wmf.18.2018.03.16.06.20.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Mar 2018 06:20:53 -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 Subject: [PATCH 2/5] drm/ttm: keep a reference to transfer pipelined BOs Date: Fri, 16 Mar 2018 14:20:46 +0100 Message-Id: <20180316132049.1748-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180316132049.1748-1-christian.koenig@amd.com> References: <20180316132049.1748-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; }