From 8a4b72a4aad8ab12012175aedc6002da9e88cf81 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Fri, 6 Aug 2021 11:30:54 -0700 Subject: [PATCH] gpu: nvgpu: Fix crash when reading CE_APP debugfs The CE_APP debugfs nodes are created when the NVGPU driver is probed, however, the 'ce_app' structure which contains the variables exposed via the debugfs, is not allocated until nvgpu_finalize_poweron() is called. Therefore, if the user attempts to access the CE_APP debugfs nodes before the NVGPU has been powered on, for example, right after Linux has booted, then this results in a NULL pointer dereference crash. Fix this by moving the creation of the CE_APP debugfs nodes to nvgpu_finalize_poweron_linux() which is called after nvgpu_finalize_poweron(). Bug 200747304 Change-Id: Icd28952112f86887a1d6b6f8beb382f5189461a9 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2572106 (cherry picked from commit 35a0c18d93e97265611c3bbfae41b39d9cd183e3) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2587367 Reviewed-by: svcacv Reviewed-by: svc_kernel_abi Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/debug.c | 3 --- drivers/gpu/nvgpu/os/linux/module.c | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/debug.c b/drivers/gpu/nvgpu/os/linux/debug.c index d39426960..ccd6811c0 100644 --- a/drivers/gpu/nvgpu/os/linux/debug.c +++ b/drivers/gpu/nvgpu/os/linux/debug.c @@ -15,7 +15,6 @@ */ #include "debug_cde.h" -#include "debug_ce.h" #include "debug_fifo.h" #include "debug_gr.h" #include "debug_allocator.h" @@ -520,8 +519,6 @@ void gk20a_debug_init(struct gk20a *g, const char *debugfs_symlink) #endif nvgpu_ltc_debugfs_init(g); #ifdef CONFIG_NVGPU_DGPU - if (!g->is_virtual) - nvgpu_ce_debugfs_init(g); if (g->pci_vendor_id) { nvgpu_xve_debugfs_init(g); nvgpu_bios_debugfs_init(g); diff --git a/drivers/gpu/nvgpu/os/linux/module.c b/drivers/gpu/nvgpu/os/linux/module.c index 813ad86e5..9372bcb79 100644 --- a/drivers/gpu/nvgpu/os/linux/module.c +++ b/drivers/gpu/nvgpu/os/linux/module.c @@ -82,6 +82,7 @@ #include "fecs_trace_linux.h" #include "driver_common.h" #include "channel.h" +#include "debug_ce.h" #include "debug_pmgr.h" #include "dmabuf_priv.h" @@ -307,6 +308,11 @@ int nvgpu_finalize_poweron_linux(struct nvgpu_os_linux *l) return err; } +#ifdef CONFIG_NVGPU_DGPU + if (!g->is_virtual) + nvgpu_ce_debugfs_init(g); +#endif + l->init_done = true; return 0;