From dd8f7114baf9d217589f0362722112b8462884c4 Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Mon, 27 Mar 2023 16:58:32 +0530 Subject: [PATCH] gpu: nvgpu: update dmabuf locking All drivers that use dma-bufs have been moved to the updated locking specification wherein dma-buf reservation is to be locked while accessing the dmabuf internal data. Lock is removed. So lock the resv object onwards while updating dmabuf private data used for compression and buffer metadata. With this, we can enable compression for all kernel versions that was disabled earlier for v6.2+ kernels. Bug 3974855 Bug 3995618 Change-Id: Iece3ab57912d0420d4bc5c07d2c0d2e03ff19292 Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2877633 (cherry picked from commit 410d3603ffbfd62c5f4b71db53a40ba5dd827d52) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2880975 Reviewed-by: Jonathan Hunter GVS: Gerrit_Virtual_Submit Tested-by: Jonathan Hunter --- drivers/gpu/nvgpu/Makefile.linux.configs | 12 +------- drivers/gpu/nvgpu/os/linux/dmabuf_priv.c | 38 +++++++++++++++++++----- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/nvgpu/Makefile.linux.configs b/drivers/gpu/nvgpu/Makefile.linux.configs index d231e7c91..431e947f1 100644 --- a/drivers/gpu/nvgpu/Makefile.linux.configs +++ b/drivers/gpu/nvgpu/Makefile.linux.configs @@ -35,18 +35,8 @@ CONFIG_NVGPU_HAL_NON_FUSA := y # Support recovery on failure (which may involve engine reset) CONFIG_NVGPU_RECOVERY := y -# Enable support for compression on pre-K6.2 kernels. K6.2+ changes the -# internals of dma-bufs which breaks some hacks we implemented to support -# compression meta-data tracking. For now, on K6.2+ kernels, just disable -# compression. This is a hack that should be fixed. +# Support for compression CONFIG_NVGPU_COMPRESSION := y -ifeq ($(VERSION),6) -ifneq ($(PATCHLEVEL),0) -ifneq ($(PATCHLEVEL),1) -CONFIG_NVGPU_COMPRESSION := n -endif -endif -endif # Enable MIG Support CONFIG_NVGPU_MIG := y diff --git a/drivers/gpu/nvgpu/os/linux/dmabuf_priv.c b/drivers/gpu/nvgpu/os/linux/dmabuf_priv.c index 363ee68d4..7875a6c42 100644 --- a/drivers/gpu/nvgpu/os/linux/dmabuf_priv.c +++ b/drivers/gpu/nvgpu/os/linux/dmabuf_priv.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2023, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -17,6 +17,12 @@ #include #include #include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0) +#include +#else +#include +#include +#endif #include #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) @@ -100,13 +106,31 @@ static void nvgpu_dma_buf_release(struct dma_buf *dmabuf) dmabuf->ops->release(dmabuf); } +static void gk20a_dma_buf_lock(struct dma_buf *dmabuf) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0) + dma_resv_lock(dmabuf->resv, NULL); +#else + ww_mutex_lock(&dmabuf->resv->lock, NULL); +#endif +} + +static void gk20a_dma_buf_unlock(struct dma_buf *dmabuf) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0) + dma_resv_unlock(dmabuf->resv); +#else + ww_mutex_unlock(&dmabuf->resv->lock); +#endif +} + /* This function must be called with priv->lock held */ static int gk20a_dma_buf_set_drvdata(struct dma_buf *dmabuf, struct device *device, struct gk20a_dmabuf_priv *priv) { priv->dmabuf = dmabuf; - mutex_lock(&dmabuf->lock); + gk20a_dma_buf_lock(dmabuf); priv->previous_ops = dmabuf->ops; /* * Make a copy of the original ops struct and then update the @@ -115,7 +139,7 @@ static int gk20a_dma_buf_set_drvdata(struct dma_buf *dmabuf, struct device *devi priv->local_ops = *(dmabuf->ops); priv->local_ops.release = nvgpu_dma_buf_release; dmabuf->ops = &priv->local_ops; - mutex_unlock(&dmabuf->lock); + gk20a_dma_buf_unlock(dmabuf); return 0; } @@ -131,11 +155,11 @@ struct gk20a_dmabuf_priv *gk20a_dma_buf_get_drvdata( { struct gk20a_dmabuf_priv *priv = NULL; - mutex_lock(&dmabuf->lock); + gk20a_dma_buf_lock(dmabuf); if (dmabuf->ops->release == nvgpu_dma_buf_release) { priv = dma_buf_ops_to_gk20a_priv((struct dma_buf_ops *)dmabuf->ops); } - mutex_unlock(&dmabuf->lock); + gk20a_dma_buf_unlock(dmabuf); return priv; } @@ -211,9 +235,9 @@ void gk20a_mm_delete_priv(struct gk20a_dmabuf_priv *priv) } /* The original pointer to dma_buf_ops is always put back here*/ - mutex_lock(&dmabuf->lock); + gk20a_dma_buf_lock(dmabuf); dmabuf->ops = priv->previous_ops; - mutex_unlock(&dmabuf->lock); + gk20a_dma_buf_unlock(dmabuf); /* Remove this entry from the global tracking list */ nvgpu_list_del(&priv->list);