From patchwork Fri Apr 1 20:56:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Rusin X-Patchwork-Id: 12798798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B82D2C433EF for ; Fri, 1 Apr 2022 20:56:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E112A10E0FD; Fri, 1 Apr 2022 20:56:09 +0000 (UTC) Received: from letterbox.kde.org (letterbox.kde.org [IPv6:2001:41c9:1:41e::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id C0DE210E0F4 for ; Fri, 1 Apr 2022 20:56:07 +0000 (UTC) Received: from vertex.vmware.com (pool-108-36-85-85.phlapa.fios.verizon.net [108.36.85.85]) (Authenticated sender: zack) by letterbox.kde.org (Postfix) with ESMTPSA id 5512A28A546; Fri, 1 Apr 2022 21:56:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kde.org; s=users; t=1648846565; bh=klNZi8K4qy22qgGHhlckTAOQ2hPHpUShIBvUo1JJcCI=; h=From:To:Cc:Subject:Date:From; b=WTyY+O5q9fEutlpPumiqwtaasBhIihYwH1GcsyXVdOdJxVvwK1ZVUXeK5yR0XRO3O Dd8/UvRhGjnZuhAY44cBH0jcBuUDq2GakkFYteuQtlE2qcZIFDxo02j0H85FdNOxD3 KAodcu+OqILfNnkvKodBifbWzrYjt7S/+/p+ChHLyFDxzAeezvhabNXD1JMEuMZ1S/ Wec2X+15nmtpzG8GUzMqAASLa1/pCIpQOJ+/qqP1gLTK5BpTqqIF08ObLHS3oHVIZK fpDMamVSn1BzZ/Gp8QR9Z+E6iInevDjzEd1muG6QDPyy9oFWZU55FRzpLQNEFCRkn1 Dbk7JAFakdNMg== From: Zack Rusin To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Date: Fri, 1 Apr 2022 16:56:00 -0400 Message-Id: <20220401205602.1172975-1-zack@kde.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Zack Rusin Cc: krastevm@vmware.com, mombasawalam@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Zack Rusin Add a few debugfs entries for every used TTM placement that vmwgfx is using. This allows basic tracking of memory usage inside vmwgfx, e.g. 'cat /sys/kernel/debug/dri/0/mob_ttm' will display mob memory usage. Signed-off-by: Zack Rusin Reviewed-by: Martin Krastev --- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 97 +++++++++++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index 791f9a5f3868..6d675855f065 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -1632,6 +1632,7 @@ static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto out_unload; vmw_debugfs_gem_init(vmw); + vmw_ttm_debugfs_init(vmw); return 0; out_unload: diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index be19aa6e1f13..eabe3e8e9cf9 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -1085,6 +1085,7 @@ vmw_bo_sg_table(struct ttm_buffer_object *bo); extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv, unsigned long bo_size, struct ttm_buffer_object **bo_p); +void vmw_ttm_debugfs_init(struct vmw_private *vdev); extern void vmw_piter_start(struct vmw_piter *viter, const struct vmw_sg_table *vsgt, diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c index b84ecc6d6611..355414595e52 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA + * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -677,3 +677,98 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv, *bo_p = bo; return ret; } + +#if defined(CONFIG_DEBUG_FS) + +static int vmw_ttm_vram_table_show(struct seq_file *m, void *unused) +{ + struct vmw_private *vdev = (struct vmw_private *)m->private; + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev, + TTM_PL_VRAM); + struct drm_printer p = drm_seq_file_printer(m); + + ttm_resource_manager_debug(man, &p); + return 0; +} + +static int vmw_ttm_page_pool_show(struct seq_file *m, void *unused) +{ + struct vmw_private *vdev = (struct vmw_private *)m->private; + + return ttm_pool_debugfs(&vdev->bdev.pool, m); +} + +static int vmw_ttm_mob_table_show(struct seq_file *m, void *unused) +{ + struct vmw_private *vdev = (struct vmw_private *)m->private; + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev, + VMW_PL_MOB); + struct drm_printer p = drm_seq_file_printer(m); + + ttm_resource_manager_debug(man, &p); + return 0; +} + +static int vmw_ttm_gmr_table_show(struct seq_file *m, void *unused) +{ + struct vmw_private *vdev = (struct vmw_private *)m->private; + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev, + VMW_PL_GMR); + struct drm_printer p = drm_seq_file_printer(m); + + ttm_resource_manager_debug(man, &p); + return 0; +} + +static int vmw_ttm_system_table_show(struct seq_file *m, void *unused) +{ + struct vmw_private *vdev = (struct vmw_private *)m->private; + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev, + TTM_PL_SYSTEM); + struct drm_printer p = drm_seq_file_printer(m); + + ttm_resource_manager_debug(man, &p); + return 0; +} + +static int vmw_ttm_system_mob_table_show(struct seq_file *m, void *unused) +{ + struct vmw_private *vdev = (struct vmw_private *)m->private; + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev, + VMW_PL_SYSTEM); + struct drm_printer p = drm_seq_file_printer(m); + + ttm_resource_manager_debug(man, &p); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_vram_table); +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_mob_table); +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_gmr_table); +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_table); +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_mob_table); +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_page_pool); + +#endif + +void vmw_ttm_debugfs_init(struct vmw_private *vdev) +{ +#if defined(CONFIG_DEBUG_FS) + struct drm_device *drm = &vdev->drm; + struct drm_minor *minor = drm->primary; + struct dentry *root = minor->debugfs_root; + + debugfs_create_file("vram_ttm", 0444, root, vdev, + &vmw_ttm_vram_table_fops); + debugfs_create_file("mob_ttm", 0444, root, vdev, + &vmw_ttm_mob_table_fops); + debugfs_create_file("gmr_ttm", 0444, root, vdev, + &vmw_ttm_gmr_table_fops); + debugfs_create_file("system_ttm", 0444, root, vdev, + &vmw_ttm_system_table_fops); + debugfs_create_file("system_mob_ttm", 0444, root, vdev, + &vmw_ttm_system_mob_table_fops); + debugfs_create_file("ttm_page_pool", 0444, root, vdev, + &vmw_ttm_page_pool_fops); +#endif +} From patchwork Fri Apr 1 20:56:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Rusin X-Patchwork-Id: 12798797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB79EC433EF for ; Fri, 1 Apr 2022 20:56:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E1A0510E0F4; Fri, 1 Apr 2022 20:56:08 +0000 (UTC) Received: from letterbox.kde.org (letterbox.kde.org [IPv6:2001:41c9:1:41e::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id F418010E0F9 for ; Fri, 1 Apr 2022 20:56:07 +0000 (UTC) Received: from vertex.vmware.com (pool-108-36-85-85.phlapa.fios.verizon.net [108.36.85.85]) (Authenticated sender: zack) by letterbox.kde.org (Postfix) with ESMTPSA id 2F83028A54B; Fri, 1 Apr 2022 21:56:06 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kde.org; s=users; t=1648846566; bh=eEh++Bp5KnRY3dkxKwL4uFC2SlErQdh0ERiEKx3Dq50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bi+eX4s6Ol1/R5b19yV6GBA5A4GyjRT1HFdx5pbUC6jGQyNX26k9g1vhjosNhn3jZ nBhm3Q7Oe+VjUwACDf4Xr0UpWCriwtN/ntjxENkGGW8JDnQLmOvd0FSkVk6Ytm/EVV K1t7M0M5cDRy8GpXQiHoG40KPTFUODVLY5KbyJI62OIoM43oYGIrKoLdXMiKdCpKCn sDLioMYJ1uPxwYr9hUE1d4tDm0VLDHIHJgsTgpXEnHO975n04HDt5NFAcxZFr3Id0U Qx4Ibn/GHzR4AKl/DMQtAPFVfKSx5/1nHbkm/JNvefaFGx7KN4sXHzCalu/JnPB90I xiW9PUsf2YW0g== From: Zack Rusin To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm/vmwgfx: Write the driver id registers Date: Fri, 1 Apr 2022 16:56:01 -0400 Message-Id: <20220401205602.1172975-2-zack@kde.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220401205602.1172975-1-zack@kde.org> References: <20220401205602.1172975-1-zack@kde.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Zack Rusin Cc: krastevm@vmware.com, mombasawalam@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Zack Rusin Driver id registers are a new mechanism in the svga device to hint to the device which driver is running. This should not change device behavior in any way, but might be convenient to work-around specific bugs in guest drivers. Signed-off-by: Zack Rusin Reviewed-by: Martin Krastev Reviewed-by: Maaz Mombasawala --- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 43 +++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index 6d675855f065..72a17618ba0a 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -25,10 +25,13 @@ * **************************************************************************/ -#include -#include -#include -#include + +#include "vmwgfx_drv.h" + +#include "vmwgfx_devcaps.h" +#include "vmwgfx_mksstat.h" +#include "vmwgfx_binding.h" +#include "ttm_object.h" #include #include @@ -41,11 +44,11 @@ #include #include -#include "ttm_object.h" -#include "vmwgfx_binding.h" -#include "vmwgfx_devcaps.h" -#include "vmwgfx_drv.h" -#include "vmwgfx_mksstat.h" +#include +#include +#include +#include +#include #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices" @@ -806,6 +809,27 @@ static int vmw_detect_version(struct vmw_private *dev) return 0; } +static void vmw_write_driver_id(struct vmw_private *dev) +{ + if ((dev->capabilities2 & SVGA_CAP2_DX2) != 0) { + vmw_write(dev, SVGA_REG_GUEST_DRIVER_ID, + SVGA_REG_GUEST_DRIVER_ID_LINUX); + + vmw_write(dev, SVGA_REG_GUEST_DRIVER_VERSION1, + LINUX_VERSION_MAJOR << 24 | + LINUX_VERSION_PATCHLEVEL << 16 | + LINUX_VERSION_SUBLEVEL); + vmw_write(dev, SVGA_REG_GUEST_DRIVER_VERSION2, + VMWGFX_DRIVER_MAJOR << 24 | + VMWGFX_DRIVER_MINOR << 16 | + VMWGFX_DRIVER_PATCHLEVEL); + vmw_write(dev, SVGA_REG_GUEST_DRIVER_VERSION3, 0); + + vmw_write(dev, SVGA_REG_GUEST_DRIVER_ID, + SVGA_REG_GUEST_DRIVER_ID_SUBMIT); + } +} + static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id) { int ret; @@ -1094,6 +1118,7 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id) vmw_host_printf("vmwgfx: Module Version: %d.%d.%d (kernel: %s)", VMWGFX_DRIVER_MAJOR, VMWGFX_DRIVER_MINOR, VMWGFX_DRIVER_PATCHLEVEL, UTS_RELEASE); + vmw_write_driver_id(dev_priv); if (dev_priv->enable_fb) { vmw_fifo_resource_inc(dev_priv); From patchwork Fri Apr 1 20:56:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Rusin X-Patchwork-Id: 12798799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 503DAC433F5 for ; Fri, 1 Apr 2022 20:56:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 78BCB10E0F9; Fri, 1 Apr 2022 20:56:12 +0000 (UTC) Received: from letterbox.kde.org (letterbox.kde.org [46.43.1.242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 001FE10E0F9 for ; Fri, 1 Apr 2022 20:56:08 +0000 (UTC) Received: from vertex.vmware.com (pool-108-36-85-85.phlapa.fios.verizon.net [108.36.85.85]) (Authenticated sender: zack) by letterbox.kde.org (Postfix) with ESMTPSA id E752C28A54C; Fri, 1 Apr 2022 21:56:06 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kde.org; s=users; t=1648846567; bh=tfeVlceSRZBZu03W2YFP4TmoUfd1ziVx1HM9W7D9bHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cgAs+C1mVGkooOkdPLOeCVduvfX68TJLmbTTvIvA/rfuK5xuwYZ1xybxQB24j5RjT ZKL9s19oZgkLX991pv0hF4vnl34bNnFpgBZHAyonHb6nvnautFGjP7Iqe7ok7ilqyG 04S6qptv6LQxri3ALIpnPAFcGBkg7Mq8uzq8L8oFqbi557fX76WGdCQaHEw8OiqBBi 9yUjhHwB1kf9XkmXbmwdBu2tU0IgAMku6UazPm9IDdUcarHXOH9K5CbrQ2qXLosrwa EUCydbXQ5UBYYZotyOF33NF1BeEhZTh51sF1osTiW6Jm9xRLHGZoS2gn8KYA1nIRxh bOMZdXoyRNTIA== From: Zack Rusin To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/vmwgfx: Fix gem refcounting on prime exported surfaces Date: Fri, 1 Apr 2022 16:56:02 -0400 Message-Id: <20220401205602.1172975-3-zack@kde.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220401205602.1172975-1-zack@kde.org> References: <20220401205602.1172975-1-zack@kde.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Zack Rusin Cc: krastevm@vmware.com, stable@vger.kernel.org, mombasawalam@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Zack Rusin vmwgfx exports two different kinds of gpu buffers to the userspace: surfaces and mob's. Surfaces are backed by mob's. Currently only surfaces are allowed with prime. Surfaces exported as prime weren't increasing the reference count on the backing mob's (gem objects), which meant that if the userspace destroyed the mob's, the exported surface was becoming invalid and its usage lead to crashes (due to usage after free). Surfaces need to increase the reference count on the backing mob's for the duration of the exported file descriptor for purposes of prime. Same has to happen when an already existing mob is passed to the surface, its reference count has to be increased. This fixes crashes with XA state tracker which is used for xrender acceleration on xf86-video-vmware. Signed-off-by: Zack Rusin Cc: # v5.17+ Reviewed-by: Martin Krastev Reviewed-by: Maaz Mombasawala --- drivers/gpu/drm/vmwgfx/ttm_object.c | 7 ++++++- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 2 ++ drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 ++---- drivers/gpu/drm/vmwgfx/vmwgfx_prime.c | 14 ++++++++++++-- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 12 ++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 1 + 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/ttm_object.c b/drivers/gpu/drm/vmwgfx/ttm_object.c index 26a55fef1ab5..53e9f81f7e1b 100644 --- a/drivers/gpu/drm/vmwgfx/ttm_object.c +++ b/drivers/gpu/drm/vmwgfx/ttm_object.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 OR MIT */ /************************************************************************** * - * Copyright (c) 2009-2013 VMware, Inc., Palo Alto, CA., USA + * Copyright (c) 2009-2022 VMware, Inc., Palo Alto, CA., USA * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -51,6 +51,7 @@ #include #include "ttm_object.h" #include "vmwgfx_drv.h" +#include "vmwgfx_resource_priv.h" MODULE_IMPORT_NS(DMA_BUF); @@ -617,6 +618,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, struct ttm_base_object *base; struct dma_buf *dma_buf; struct ttm_prime_object *prime; + struct vmw_resource *res; int ret; base = ttm_base_object_lookup(tfile, handle); @@ -667,6 +669,9 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, ret = dma_buf_fd(dma_buf, flags); if (ret >= 0) { + res = user_surface_converter->base_obj_to_res(&prime->base); + if (res) + vmw_resource_prime_ref(res); *prime_fd = ret; ret = 0; } else diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index eabe3e8e9cf9..bb11f0d0b9b1 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -853,6 +853,8 @@ void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start, pgoff_t end); int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start, pgoff_t end, pgoff_t *num_prefault); +void vmw_resource_prime_ref(struct vmw_resource *res); +void vmw_resource_prime_unref(struct vmw_resource *res); /** * vmw_resource_mob_attached - Whether a resource currently has a mob attached diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c index ce609e7d758f..f41dc638df23 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR MIT */ /* - * Copyright 2021 VMware, Inc. + * Copyright 2021-2022 VMware, Inc. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -46,9 +46,8 @@ vmw_buffer_object(struct ttm_buffer_object *bo) static void vmw_gem_object_free(struct drm_gem_object *gobj) { struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gobj); - if (bo) { + if (bo) ttm_bo_put(bo); - } } static int vmw_gem_object_open(struct drm_gem_object *obj, @@ -158,7 +157,6 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, return ret; } - int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c index 2d72a5ee7c0c..2896d212db54 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2013 VMware, Inc., Palo Alto, CA., USA + * Copyright 2013-2022 VMware, Inc., Palo Alto, CA., USA * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -31,6 +31,7 @@ */ #include "vmwgfx_drv.h" +#include "vmwgfx_resource_priv.h" #include "ttm_object.h" #include @@ -62,12 +63,21 @@ static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach, { } +static void vmw_prime_release(struct dma_buf *dma_buf) +{ + struct ttm_prime_object *prime = dma_buf->priv; + struct vmw_resource *res = + user_surface_converter->base_obj_to_res(&prime->base); + if (res) + vmw_resource_prime_unref(res); +} + const struct dma_buf_ops vmw_prime_dmabuf_ops = { .attach = vmw_prime_map_attach, .detach = vmw_prime_map_detach, .map_dma_buf = vmw_prime_map_dma_buf, .unmap_dma_buf = vmw_prime_unmap_dma_buf, - .release = NULL, + .release = vmw_prime_release, }; int vmw_prime_fd_to_handle(struct drm_device *dev, diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index 6542f1498651..11de5d697351 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c @@ -1169,3 +1169,15 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start, return 0; } + +void vmw_resource_prime_ref(struct vmw_resource *res) +{ + if (res->backup) + drm_gem_object_get(&res->backup->base.base); +} + +void vmw_resource_prime_unref(struct vmw_resource *res) +{ + if (res->backup) + drm_gem_object_put(&res->backup->base.base); +} diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c index 00e8e27e4884..04fdf613df83 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -1502,6 +1502,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev, goto out_unlock; } else { backup_handle = req->base.buffer_handle; + drm_gem_object_get(&res->backup->base.base); } } } else if (req->base.drm_surface_flags &