diff --git a/drivers/video/tegra/nvmap/nvmap_carveout.c b/drivers/video/tegra/nvmap/nvmap_carveout.c index b5a64016..8d7b3346 100644 --- a/drivers/video/tegra/nvmap/nvmap_carveout.c +++ b/drivers/video/tegra/nvmap/nvmap_carveout.c @@ -1,14 +1,18 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2011-2023, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2011-2024, NVIDIA CORPORATION. All rights reserved. * * Interface with nvmap carveouts */ #include +#include + #include "nvmap_priv.h" +bool vpr_cpu_access; + extern struct nvmap_device *nvmap_dev; extern const struct file_operations debug_clients_fops; @@ -125,6 +129,10 @@ int nvmap_create_carveout(const struct nvmap_platform_carveout *co) #endif /* NVMAP_CONFIG_DEBUG_MAPS */ nvmap_heap_debugfs_init(heap_root, node->carveout); + if (!tegra_platform_is_silicon() && node->heap_bit == NVMAP_HEAP_CARVEOUT_VPR) + debugfs_create_bool("allow_cpu_access", S_IRUGO | S_IWUGO, + heap_root, (bool *)&vpr_cpu_access); + } } out: diff --git a/drivers/video/tegra/nvmap/nvmap_dmabuf.c b/drivers/video/tegra/nvmap/nvmap_dmabuf.c index 5260c9b4..d46ea5b7 100644 --- a/drivers/video/tegra/nvmap/nvmap_dmabuf.c +++ b/drivers/video/tegra/nvmap/nvmap_dmabuf.c @@ -35,6 +35,8 @@ #define NVMAP_DMABUF_ATTACH nvmap_dmabuf_attach +extern bool vpr_cpu_access; + struct nvmap_handle_sgt { enum dma_data_direction dir; struct sg_table *sgt; @@ -380,12 +382,14 @@ int __nvmap_map(struct nvmap_handle *h, struct vm_area_struct *vma) nvmap_handle_put(h); return -EPERM; } + /* - * Don't allow mmap on VPR memory as it would be mapped - * as device memory. User space shouldn't be accessing - * device memory. + * VPR memory would be mapped as device memory. + * User space shouldn't be accessing device memory. + * NvGPU require to access VPR from user-space for validation on pre-sil. + * So, allow VPR CPU access only if vpr_cpu_access flag is set else don't allow. */ - if (h->heap_type == NVMAP_HEAP_CARVEOUT_VPR) { + if (!vpr_cpu_access && h->heap_type == NVMAP_HEAP_CARVEOUT_VPR) { nvmap_handle_put(h); return -EPERM; } diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index ff58c375..378c43a5 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c @@ -44,6 +44,7 @@ MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); #endif +extern bool vpr_cpu_access; static ssize_t rw_handle(struct nvmap_client *client, struct nvmap_handle *h, int is_read, unsigned long h_offs, @@ -549,7 +550,8 @@ int nvmap_ioctl_rw_handle(struct file *filp, int is_read, void __user *arg, goto fail; } - if (is_read && h->heap_type == NVMAP_HEAP_CARVEOUT_VPR) { + if (!vpr_cpu_access && is_read && + h->heap_type == NVMAP_HEAP_CARVEOUT_VPR) { pr_err("CPU read operation is not allowed on VPR carveout\n"); err = -EPERM; goto fail;