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 <skamble@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2877633
(cherry picked from commit 410d3603ff)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2880975
Reviewed-by: Jonathan Hunter <jonathanh@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
Tested-by: Jonathan Hunter <jonathanh@nvidia.com>
This commit is contained in:
Sagar Kamble
2023-03-27 16:58:32 +05:30
committed by mobile promotions
parent ddbd2da4a9
commit dd8f7114ba
2 changed files with 32 additions and 18 deletions

View File

@@ -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

View File

@@ -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 <linux/version.h>
#include <linux/device.h>
#include <linux/dma-buf.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0)
#include <linux/dma-resv.h>
#else
#include <linux/reservation.h>
#include <linux/ww_mutex.h>
#endif
#include <linux/fs.h>
#include <linux/scatterlist.h>
#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);