diff --git a/drivers/video/tegra/nvmap/nvmap_dmabuf.c b/drivers/video/tegra/nvmap/nvmap_dmabuf.c index 9be5d96f..dd0db106 100644 --- a/drivers/video/tegra/nvmap/nvmap_dmabuf.c +++ b/drivers/video/tegra/nvmap/nvmap_dmabuf.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2012-2023, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2012-2025, NVIDIA CORPORATION. All rights reserved. * * dma_buf exporter for nvmap */ @@ -450,6 +450,7 @@ int __nvmap_map(struct nvmap_handle *h, struct vm_area_struct *vma) nvmap_handle_put(h); return -ENOMEM; } + mutex_init(&priv->vma_lock); priv->handle = h; #if defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS) /* Linux v6.3 */ diff --git a/drivers/video/tegra/nvmap/nvmap_fault.c b/drivers/video/tegra/nvmap/nvmap_fault.c index 4e56a1dd..1ab1afeb 100644 --- a/drivers/video/tegra/nvmap/nvmap_fault.c +++ b/drivers/video/tegra/nvmap/nvmap_fault.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2011-2025, NVIDIA CORPORATION. All rights reserved. */ #define pr_fmt(fmt) "%s: " fmt, __func__ @@ -147,6 +147,14 @@ static void nvmap_vma_close(struct vm_area_struct *vma) BUG_ON(!vma_found); nvmap_umaps_dec(h); + mutex_lock(&priv->vma_lock); + if (priv->mm != NULL && h->anon_count != 0) { + nvmap_add_mm_counter(priv->mm, MM_ANONPAGES, priv->map_rss_count); + priv->map_rss_count = 0; + priv->mm = NULL; + } + mutex_unlock(&priv->vma_lock); + if (__atomic_add_unless(&priv->count, -1, 0) == 1) { if (h->heap_pgalloc) { for (i = 0; i < nr_page; i++) { @@ -233,6 +241,14 @@ static int nvmap_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) return VM_FAULT_SIGSEGV; } + mutex_lock(&priv->vma_lock); + if (priv->handle->anon_count != 0 && current->mm != NULL) { + nvmap_add_mm_counter(current->mm, MM_ANONPAGES, -1); + priv->map_rss_count++; + priv->mm = current->mm; + } + mutex_unlock(&priv->vma_lock); + if (!nvmap_handle_track_dirty(priv->handle)) goto finish; mutex_lock(&priv->handle->lock); diff --git a/drivers/video/tegra/nvmap/nvmap_priv.h b/drivers/video/tegra/nvmap/nvmap_priv.h index 3b505936..66c1c9f2 100644 --- a/drivers/video/tegra/nvmap/nvmap_priv.h +++ b/drivers/video/tegra/nvmap/nvmap_priv.h @@ -380,6 +380,9 @@ struct nvmap_vma_priv { struct nvmap_handle *handle; size_t offs; atomic_t count; /* number of processes cloning the VMA */ + u64 map_rss_count; + struct mm_struct *mm; + struct mutex vma_lock; }; struct nvmap_device {