gpu: nvgpu: add mutex to serialize profiler ioctl calls

Add new mutex prof->ioctl_lock to serialize all IOCTL calls on profiler
object. Running concurrent IOCTL calls could lead to races and
corrupted state.

Bug 2510974
Jira NVGPU-5360

Change-Id: I66a8d9078c35475a13442ccd34b61aca5b9c1d2b
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2389652
Reviewed-by: automaticguardword <automaticguardword@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Deepak Nibade
2020-07-23 12:22:56 +05:30
committed by Alex Waterman
parent 9ea21459b4
commit ccba2e850b
3 changed files with 10 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
#include <nvgpu/profiler.h>
#include <nvgpu/atomic.h>
#include <nvgpu/log.h>
#include <nvgpu/lock.h>
#include <nvgpu/kmem.h>
#include <nvgpu/tsg.h>
@@ -52,6 +53,7 @@ int nvgpu_profiler_alloc(struct gk20a *g,
prof->scope = scope;
prof->g = g;
nvgpu_mutex_init(&prof->ioctl_lock);
nvgpu_init_list_node(&prof->prof_obj_entry);
nvgpu_list_add(&prof->prof_obj_entry, &g->profiler_objects);

View File

@@ -26,6 +26,7 @@
#ifdef CONFIG_NVGPU_PROFILER
#include <nvgpu/list.h>
#include <nvgpu/lock.h>
#include <nvgpu/pm_reservation.h>
struct gk20a;
@@ -57,6 +58,9 @@ struct nvgpu_profiler_object {
*/
bool context_init;
/* Lock to serialize IOCTL/DEVCTL calls */
struct nvgpu_mutex ioctl_lock;
/* If profiler object has reservation for each resource. */
bool reserved[NVGPU_PROFILER_PM_RESOURCE_TYPE_COUNT];

View File

@@ -200,6 +200,8 @@ long nvgpu_prof_fops_ioctl(struct file *filp, unsigned int cmd,
nvgpu_log(g, gpu_dbg_prof, "Profiler handle %u received IOCTL cmd %u",
prof->prof_handle, cmd);
nvgpu_mutex_acquire(&prof->ioctl_lock);
nvgpu_speculation_barrier();
switch (cmd) {
@@ -218,6 +220,8 @@ long nvgpu_prof_fops_ioctl(struct file *filp, unsigned int cmd,
break;
}
nvgpu_mutex_release(&prof->ioctl_lock);
if ((err == 0) && (_IOC_DIR(cmd) & _IOC_READ))
err = copy_to_user((void __user *)arg,
buf, _IOC_SIZE(cmd));