From 72f27f77472503ccaa840c1fc01efbf5df6075d0 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Tue, 17 Jan 2017 11:30:12 +0530 Subject: gpu: nvgpu: serialize debug session IOCTLs Hold debug_s->ioctl_lock for all debug session IOCTLs to prevent multi-threaded user space IOCTL calls debug session IOCTL calls are not thread-safe and hence this serialization is required Bug 1832267 Change-Id: I847ac951601d4f0093546b592bdb8c8f00185317 Signed-off-by: Deepak Nibade Reviewed-on: http://git-master/r/1286436 Reviewed-by: svccoveritychecker GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c | 8 +++++++- drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a') diff --git a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c index be9f7fc6..ac11e378 100644 --- a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c @@ -1,7 +1,7 @@ /* * Tegra GK20A GPU Debugger/Profiler Driver * - * Copyright (c) 2013-2016, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2013-2017, 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, @@ -117,6 +117,7 @@ static int gk20a_dbg_gpu_do_dev_open(struct inode *inode, init_waitqueue_head(&dbg_session->dbg_events.wait_queue); INIT_LIST_HEAD(&dbg_session->ch_list); mutex_init(&dbg_session->ch_list_lock); + mutex_init(&dbg_session->ioctl_lock); dbg_session->dbg_events.events_enabled = false; dbg_session->dbg_events.num_pending_events = 0; @@ -899,6 +900,9 @@ long gk20a_dbg_gpu_dev_ioctl(struct file *filp, unsigned int cmd, gk20a_idle(g->dev); } + /* protect from threaded user space calls */ + mutex_lock(&dbg_s->ioctl_lock); + switch (cmd) { case NVGPU_DBG_GPU_IOCTL_BIND_CHANNEL: err = dbg_bind_channel_gk20a(dbg_s, @@ -1003,6 +1007,8 @@ long gk20a_dbg_gpu_dev_ioctl(struct file *filp, unsigned int cmd, break; } + mutex_unlock(&dbg_s->ioctl_lock); + gk20a_dbg(gpu_dbg_gpu_dbg, "ret=%d", err); if ((err == 0) && (_IOC_DIR(cmd) & _IOC_READ)) diff --git a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h index 600715f5..773a669c 100644 --- a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h @@ -1,7 +1,7 @@ /* * Tegra GK20A GPU Debugger Driver * - * Copyright (c) 2013-2016, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2013-2017, 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, @@ -73,6 +73,8 @@ struct dbg_session_gk20a { struct dbg_gpu_session_events dbg_events; bool broadcast_stop_trigger; + + struct mutex ioctl_lock; }; struct dbg_session_data { -- cgit v1.2.2