From 01db38f08e6a7670189d972d138c32196a3b9dc7 Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Fri, 9 Jun 2023 08:48:17 +0000 Subject: [PATCH] video: tegra: nvmap: Add support for Serial Id feature Add support for Serial Id feature which will be used by Nsight for buffer tracking purpose. This feature expects a unique serial id per buffer even if it is shared across multiple client processes. Add following code: - Create a new global counter field for serial id in nvmap device. Initialize it to 0 when nvmap device is initialized. - Introduce a new field for serial_id in nvmap_handle struct. - When nvmap_handle is created, assign it's serial_id field with global counter's value, and increment global counter. - During NvRmMemQueryHandleParameters return this serial_id associated with the handle. - Do not decrement counter for serial_id even after freeing the handle. Bug 4138373 Change-Id: Ic1fe22b082eefb352986f8fa44d4c38d186a366f Signed-off-by: Ketan Patil Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2918510 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/video/tegra/nvmap/nvmap_dev.c | 1 + drivers/video/tegra/nvmap/nvmap_handle.c | 6 ++++++ drivers/video/tegra/nvmap/nvmap_ioctl.c | 1 + drivers/video/tegra/nvmap/nvmap_priv.h | 2 ++ include/uapi/linux/nvmap.h | 1 + 5 files changed, 11 insertions(+) diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index fc5d65e2..26dc96dd 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c @@ -1414,6 +1414,7 @@ int __init nvmap_probe(struct platform_device *pdev) dev->dev_user.fops = &nvmap_user_fops; dev->dev_user.parent = &pdev->dev; dev->handles = RB_ROOT; + dev->serial_id_counter = 0; #ifdef NVMAP_CONFIG_PAGE_POOLS e = nvmap_page_pool_init(dev); diff --git a/drivers/video/tegra/nvmap/nvmap_handle.c b/drivers/video/tegra/nvmap/nvmap_handle.c index 3c1564f3..fa7c7618 100644 --- a/drivers/video/tegra/nvmap/nvmap_handle.c +++ b/drivers/video/tegra/nvmap/nvmap_handle.c @@ -77,6 +77,12 @@ void nvmap_handle_add(struct nvmap_device *dev, struct nvmap_handle *h) rb_link_node(&h->node, parent, p); rb_insert_color(&h->node, &dev->handles); nvmap_lru_add(h); + /* + * Set handle's serial_id to global serial id counter and then update the counter. + * This operation is done here, so as to protect from concurrency issue, as we take + * lock on handle_lock. + */ + h->serial_id = dev->serial_id_counter++; spin_unlock(&dev->handle_lock); } diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index e86839d8..d5cd9331 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c @@ -1172,6 +1172,7 @@ int nvmap_ioctl_get_handle_parameters(struct file *filp, void __user *arg) if (is_ro) op.access_flags = NVMAP_HANDLE_RO; + op.serial_id = handle->serial_id; nvmap_handle_put(handle); if (copy_to_user(arg, &op, sizeof(op))) diff --git a/drivers/video/tegra/nvmap/nvmap_priv.h b/drivers/video/tegra/nvmap/nvmap_priv.h index 27de4899..f524113d 100644 --- a/drivers/video/tegra/nvmap/nvmap_priv.h +++ b/drivers/video/tegra/nvmap/nvmap_priv.h @@ -268,6 +268,7 @@ struct nvmap_handle { */ wait_queue_head_t waitq; int numa_id; + u64 serial_id; }; struct nvmap_handle_info { @@ -404,6 +405,7 @@ struct nvmap_device { #endif /* NVMAP_CONFIG_DEBUG_MAPS */ /* Perform cache flush at buffer allocation from carveout */ bool co_cache_flush_at_alloc; + u64 serial_id_counter; /* This is global counter common across different client processes */ }; struct handles_range { diff --git a/include/uapi/linux/nvmap.h b/include/uapi/linux/nvmap.h index 1a771c22..16af5f5a 100644 --- a/include/uapi/linux/nvmap.h +++ b/include/uapi/linux/nvmap.h @@ -227,6 +227,7 @@ struct nvmap_handle_parameters { __u64 coherency; __u64 size; __u64 offset; + __u64 serial_id; }; /**