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: 10306565 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 2D3D5600CC for ; Sun, 25 Mar 2018 10:58:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5532855C for ; Sun, 25 Mar 2018 10:58:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1444B29308; Sun, 25 Mar 2018 10:58:17 +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 B104E2855C for ; Sun, 25 Mar 2018 10:58:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 254206E410; Sun, 25 Mar 2018 10:58:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 04A066E406; Sun, 25 Mar 2018 10:58:03 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id u11so3795965wri.12; 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=cVdfghen244IXp999BINYdZCg7OqYePFQt7nH7t+tCJ8I/uekcgYCWF5EbQE6gJzmL 9/5jH072hlRaraaOQonZ+5MvJcs7jjhcfuJXKgYTtubHj7TZeVBMq01oz2P8A6UDKtaQ kxOr6jflfR9O5+QAfOyvED6A4K/iH8hnX56/8sfWES2uzBOBHE0CM1yQa4GxrSSHH32w gq0Kc5UdeklhXTIN6QoKh2JWIqNv5k85XArEpmsS+H/96rVPmUkPy1I4xisRtP3VI6/X McJ7gRPFi2fKd3k+UPiTjgpvAZY526U1zHucmGCmn/SBmTNRD7a5rMK6EcHA7kmUWuNv m/EQ== X-Gm-Message-State: AElRT7EGLSCH2zK3HB9pS6UqVkev8GeyjMvcBP3ZP/r2hql9QeKyIK3f u1heaAZoLVLKaQjTVXukSjI= 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 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; }