From 0946df9865335a1a4154d5ac9692652f235bbfec Mon Sep 17 00:00:00 2001 From: Divya Date: Thu, 31 Mar 2022 06:42:21 +0000 Subject: [PATCH] gpu: nvgpu: add aelpg flag check in sysfs node - When read from aelpg_param_read sysfs node and write to aelpg_param_store sysfs node is done it leads to system crash. - This issue is seen on safety build as power features are not enabled. - To avoid this crash, add aelpg platform flag check in aelpg_param_read and aelpg_param_store sysfs nodes. - Also, as AELPG depends on ELPG add can_elpg check before enabling/disabling aelpg through sysfs node. Bug 3582946 Change-Id: Iaf709db2b5dc0340390767f4b06a0ac06962ed77 Signed-off-by: Divya Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2690548 Reviewed-by: svcacv Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Mahantesh Kumbar Reviewed-by: Vijayakumar Subbu GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/sysfs.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index c6d055126..f7c8a0b90 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -617,7 +617,7 @@ static ssize_t aelpg_param_store(struct device *dev, struct gk20a *g = get_gk20a(dev); int status = 0; union pmu_ap_cmd ap_cmd; - int *paramlist = (int *)g->pmu->pg->aelpg_param; + int *paramlist = NULL; u32 defaultparam[5] = { APCTRL_SAMPLING_PERIOD_PG_DEFAULT_US, APCTRL_MINIMUM_IDLE_FILTER_DEFAULT_US, @@ -626,6 +626,12 @@ static ssize_t aelpg_param_store(struct device *dev, APCTRL_CYCLES_PER_SAMPLE_MAX_DEFAULT }; + if (!g->aelpg_enabled) { + nvgpu_info(g, "AELPG not enabled"); + return count; + } + + paramlist = (int *)g->pmu->pg->aelpg_param; /* Get each parameter value from input string*/ sscanf(buf, "%d %d %d %d %d", ¶mlist[0], ¶mlist[1], ¶mlist[2], ¶mlist[3], ¶mlist[4]); @@ -659,10 +665,15 @@ static ssize_t aelpg_param_read(struct device *dev, { struct gk20a *g = get_gk20a(dev); - return snprintf(buf, NVGPU_CPU_PAGE_SIZE, - "%d %d %d %d %d\n", g->pmu->pg->aelpg_param[0], - g->pmu->pg->aelpg_param[1], g->pmu->pg->aelpg_param[2], - g->pmu->pg->aelpg_param[3], g->pmu->pg->aelpg_param[4]); + if (g->aelpg_enabled) { + return snprintf(buf, NVGPU_CPU_PAGE_SIZE, + "%d %d %d %d %d\n", g->pmu->pg->aelpg_param[0], + g->pmu->pg->aelpg_param[1], g->pmu->pg->aelpg_param[2], + g->pmu->pg->aelpg_param[3], g->pmu->pg->aelpg_param[4]); + } else { + nvgpu_info(g, "AELPG not enabled"); + } + return 0; } static DEVICE_ATTR(aelpg_param, ROOTRW, @@ -680,6 +691,11 @@ static ssize_t aelpg_enable_store(struct device *dev, if (kstrtoul(buf, 10, &val) < 0) return -EINVAL; + if (!g->can_elpg) { + nvgpu_info(g, "Feature not supported"); + return count; + } + err = gk20a_busy(g); if (err) { return err;