From 2483ab734df8e16a6cc041d3f99865157e2da2cc Mon Sep 17 00:00:00 2001 From: Suneel Kumar Pemmineti Date: Thu, 8 May 2025 10:13:02 +0000 Subject: [PATCH] nvsciipc KMD: Fix incorrect PID The code was using task_pid_nr(current) to get the process ID, which returns the Thread ID (TID) instead of the actual Process ID (PID) for multi-threaded applications. This caused problems with endpoint reservation tracking since different threads of the same process would appear as different owners. current->tgid (Thread Group ID) represents the actual Process ID in Linux. task_pid_nr(current) returns the Thread ID which is unique for each thread within a process. Using TGID ensures all threads from the same process are properly identified as belonging to the same process. This fix ensures proper endpoint reservation tracking across all threads of a multi-threaded application. Bug 5260259 Change-Id: If2f864dc4456de71b1df49e64320463a24203c68 Signed-off-by: Suneel Kumar Pemmineti Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3360307 Reviewed-by: Simon Je GVS: buildbot_gerritrpt Reviewed-by: Joshua Cha Reviewed-by: svcacv Reviewed-by: Jungho Kim --- drivers/misc/nvsciipc/nvsciipc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/misc/nvsciipc/nvsciipc.c b/drivers/misc/nvsciipc/nvsciipc.c index 92c1738e..ca451e59 100644 --- a/drivers/misc/nvsciipc/nvsciipc.c +++ b/drivers/misc/nvsciipc/nvsciipc.c @@ -243,7 +243,7 @@ static int nvsciipc_ioctl_validate_auth_token(struct nvsciipc *ctx, if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); ret = -EPERM; goto exit; } @@ -281,7 +281,7 @@ static int nvsciipc_ioctl_map_vuid(struct nvsciipc *ctx, unsigned int cmd, if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); ret = -EPERM; goto exit; } @@ -319,7 +319,7 @@ static int nvsciipc_ioctl_get_db_by_idx(struct nvsciipc *ctx, unsigned int cmd, if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); return -EPERM; } @@ -360,12 +360,12 @@ static int nvsciipc_ioctl_reserve_ep(struct nvsciipc *ctx, unsigned int cmd, unsigned long arg) { struct nvsciipc_reserve_ep reserve_ep; - pid_t current_pid = task_pid_nr(current); + pid_t current_pid = current->tgid; int i; if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); return -EPERM; } @@ -467,7 +467,7 @@ static int nvsciipc_ioctl_get_db_by_name(struct nvsciipc *ctx, unsigned int cmd, if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); return -EPERM; } @@ -521,7 +521,7 @@ static int nvsciipc_ioctl_get_db_by_vuid(struct nvsciipc *ctx, unsigned int cmd, if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); return -EPERM; } @@ -573,7 +573,7 @@ static int nvsciipc_ioctl_get_vuid(struct nvsciipc *ctx, unsigned int cmd, if ((ctx->num_eps == 0) || (ctx->set_db_f != true)) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); return -EPERM; } @@ -810,7 +810,7 @@ static int nvsciipc_ioctl_get_dbsize(struct nvsciipc *ctx, unsigned int cmd, if (ctx->set_db_f != true) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); ret = -EPERM; goto exit; } @@ -911,7 +911,7 @@ static ssize_t nvsciipc_dbg_read(struct file *filp, char __user *buf, if (ctx->set_db_f != true) { ERR("%s[%d] need to set endpoint database first\n", __func__, - get_current()->pid); + get_current()->tgid); return -EPERM; }