mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: fix misra violation in bug unit
Modify the callback interface from bug to quiesce unit to remove a possible cyclic dependency in the bug unit. Make the list of callbacks from bug unit, UT specific. The quiesce callback function and argument are kept in separate variables, and in a normal run the only callback that bug unit would invoke will be the quiesce specific function. These changes will fix the violation of Rule 17.2 in bug unit. JIRA NVGPU-6537 Change-Id: Icb6bc92077f8d26c87425768b09a7194a98e015d Signed-off-by: ajesh <akv@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2527207 (cherry picked from commit 7696565648c5dd573a03be19ba9525856b781ea6) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2530900 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: svc_kernel_abi <svc_kernel_abi@nvidia.com> Reviewed-by: Rajesh Devaraj <rdevaraj@nvidia.com> Reviewed-by: Vaibhav Kachore <vkachore@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
@@ -163,6 +163,7 @@ static int nvgpu_sw_quiesce_init_support(struct gk20a *g)
|
|||||||
/* register callback to SW quiesce GPU in case of BUG() */
|
/* register callback to SW quiesce GPU in case of BUG() */
|
||||||
g->sw_quiesce_bug_cb.cb = nvgpu_sw_quiesce_bug_cb;
|
g->sw_quiesce_bug_cb.cb = nvgpu_sw_quiesce_bug_cb;
|
||||||
g->sw_quiesce_bug_cb.arg = g;
|
g->sw_quiesce_bug_cb.arg = g;
|
||||||
|
g->sw_quiesce_bug_cb.sw_quiesce_data = true;
|
||||||
nvgpu_bug_register_cb(&g->sw_quiesce_bug_cb);
|
nvgpu_bug_register_cb(&g->sw_quiesce_bug_cb);
|
||||||
|
|
||||||
#ifdef CONFIG_NVGPU_RECOVERY
|
#ifdef CONFIG_NVGPU_RECOVERY
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ struct nvgpu_bug_cb
|
|||||||
void (*cb)(void *arg);
|
void (*cb)(void *arg);
|
||||||
void *arg;
|
void *arg;
|
||||||
struct nvgpu_list_node node;
|
struct nvgpu_list_node node;
|
||||||
|
bool sw_quiesce_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct nvgpu_bug_cb *
|
static inline struct nvgpu_bug_cb *
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ void nvgpu_bug_cb_longjmp(void *arg);
|
|||||||
({ \
|
({ \
|
||||||
jmp_buf handler; \
|
jmp_buf handler; \
|
||||||
volatile bool bug_result = true; \
|
volatile bool bug_result = true; \
|
||||||
struct nvgpu_bug_cb callback; \
|
struct nvgpu_bug_cb callback = {0}; \
|
||||||
callback.cb = nvgpu_bug_cb_longjmp; \
|
callback.cb = nvgpu_bug_cb_longjmp; \
|
||||||
callback.arg = &handler; \
|
callback.arg = &handler; \
|
||||||
nvgpu_bug_register_cb(&callback); \
|
nvgpu_bug_register_cb(&callback); \
|
||||||
|
|||||||
@@ -40,14 +40,20 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct nvgpu_bug_desc {
|
struct nvgpu_bug_desc {
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
bool in_use;
|
bool in_use;
|
||||||
pthread_once_t once;
|
pthread_once_t once;
|
||||||
struct nvgpu_spinlock lock;
|
struct nvgpu_spinlock lock;
|
||||||
struct nvgpu_list_node head;
|
struct nvgpu_list_node head;
|
||||||
|
#endif
|
||||||
|
void (*quiesce_cb)(void *arg);
|
||||||
|
void *quiesce_arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct nvgpu_bug_desc bug_desc = {
|
static struct nvgpu_bug_desc bug_desc = {
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
.once = PTHREAD_ONCE_INIT
|
.once = PTHREAD_ONCE_INIT
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __NVGPU_UNIT_TEST__
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
@@ -84,12 +90,14 @@ void dump_stack(void)
|
|||||||
nvgpu_posix_dump_stack(frames);
|
nvgpu_posix_dump_stack(frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
static void nvgpu_bug_init(void)
|
static void nvgpu_bug_init(void)
|
||||||
{
|
{
|
||||||
nvgpu_spinlock_init(&bug_desc.lock);
|
nvgpu_spinlock_init(&bug_desc.lock);
|
||||||
nvgpu_init_list_node(&bug_desc.head);
|
nvgpu_init_list_node(&bug_desc.head);
|
||||||
bug_desc.in_use = true;
|
bug_desc.in_use = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void nvgpu_bug_exit(int status)
|
void nvgpu_bug_exit(int status)
|
||||||
{
|
{
|
||||||
@@ -101,27 +109,40 @@ void nvgpu_bug_exit(int status)
|
|||||||
|
|
||||||
void nvgpu_bug_register_cb(struct nvgpu_bug_cb *cb)
|
void nvgpu_bug_register_cb(struct nvgpu_bug_cb *cb)
|
||||||
{
|
{
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
int err;
|
int err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (cb->sw_quiesce_data) {
|
||||||
|
bug_desc.quiesce_cb = cb->cb;
|
||||||
|
bug_desc.quiesce_arg = cb->arg;
|
||||||
|
} else {
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
err = pthread_once(&bug_desc.once, nvgpu_bug_init);
|
err = pthread_once(&bug_desc.once, nvgpu_bug_init);
|
||||||
nvgpu_assert(err == 0);
|
nvgpu_assert(err == 0);
|
||||||
|
|
||||||
nvgpu_spinlock_acquire(&bug_desc.lock);
|
nvgpu_spinlock_acquire(&bug_desc.lock);
|
||||||
nvgpu_list_add_tail(&cb->node, &bug_desc.head);
|
nvgpu_list_add_tail(&cb->node, &bug_desc.head);
|
||||||
nvgpu_spinlock_release(&bug_desc.lock);
|
nvgpu_spinlock_release(&bug_desc.lock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvgpu_bug_unregister_cb(struct nvgpu_bug_cb *cb)
|
void nvgpu_bug_unregister_cb(struct nvgpu_bug_cb *cb)
|
||||||
{
|
{
|
||||||
int err;
|
if (cb->sw_quiesce_data) {
|
||||||
|
bug_desc.quiesce_cb = NULL;
|
||||||
err = pthread_once(&bug_desc.once, nvgpu_bug_init);
|
bug_desc.quiesce_arg = NULL;
|
||||||
nvgpu_assert(err == 0);
|
} else {
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
|
if (bug_desc.in_use) {
|
||||||
nvgpu_spinlock_acquire(&bug_desc.lock);
|
nvgpu_spinlock_acquire(&bug_desc.lock);
|
||||||
nvgpu_list_del(&cb->node);
|
nvgpu_list_del(&cb->node);
|
||||||
nvgpu_spinlock_release(&bug_desc.lock);
|
nvgpu_spinlock_release(&bug_desc.lock);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ahhh! A bug!
|
* Ahhh! A bug!
|
||||||
@@ -129,13 +150,21 @@ void nvgpu_bug_unregister_cb(struct nvgpu_bug_cb *cb)
|
|||||||
void nvgpu_posix_bug(const char *msg, int line_no)
|
void nvgpu_posix_bug(const char *msg, int line_no)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
struct nvgpu_bug_cb *cb;
|
struct nvgpu_bug_cb *cb;
|
||||||
|
#endif
|
||||||
|
|
||||||
nvgpu_err(NULL, "%s:%d BUG detected!", msg, line_no);
|
nvgpu_err(NULL, "%s:%d BUG detected!", msg, line_no);
|
||||||
|
|
||||||
#ifndef __NVGPU_UNIT_TEST__
|
#ifndef __NVGPU_UNIT_TEST__
|
||||||
dump_stack();
|
dump_stack();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (bug_desc.quiesce_cb != NULL) {
|
||||||
|
bug_desc.quiesce_cb(bug_desc.quiesce_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
if (!bug_desc.in_use) {
|
if (!bug_desc.in_use) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@@ -164,6 +193,8 @@ void nvgpu_posix_bug(const char *msg, int line_no)
|
|||||||
nvgpu_spinlock_release(&bug_desc.lock);
|
nvgpu_spinlock_release(&bug_desc.lock);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __NVGPU_UNIT_TEST__
|
#ifdef __NVGPU_UNIT_TEST__
|
||||||
dump_stack();
|
dump_stack();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
|
* Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -117,8 +117,8 @@ static void other_bug_cb(void *arg)
|
|||||||
int test_bug_cb(struct unit_module *m,
|
int test_bug_cb(struct unit_module *m,
|
||||||
struct gk20a *g, void *args)
|
struct gk20a *g, void *args)
|
||||||
{
|
{
|
||||||
struct nvgpu_bug_cb callback;
|
struct nvgpu_bug_cb callback = {0};
|
||||||
struct nvgpu_bug_cb other_callback;
|
struct nvgpu_bug_cb other_callback = {0};
|
||||||
jmp_buf handler;
|
jmp_buf handler;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user