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 <dsinghatwari@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2690548
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Mahantesh Kumbar <mkumbar@nvidia.com>
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Divya
2022-03-31 06:42:21 +00:00
committed by mobile promotions
parent ad85b60bb0
commit 0946df9865

View File

@@ -617,7 +617,7 @@ static ssize_t aelpg_param_store(struct device *dev,
struct gk20a *g = get_gk20a(dev); struct gk20a *g = get_gk20a(dev);
int status = 0; int status = 0;
union pmu_ap_cmd ap_cmd; union pmu_ap_cmd ap_cmd;
int *paramlist = (int *)g->pmu->pg->aelpg_param; int *paramlist = NULL;
u32 defaultparam[5] = { u32 defaultparam[5] = {
APCTRL_SAMPLING_PERIOD_PG_DEFAULT_US, APCTRL_SAMPLING_PERIOD_PG_DEFAULT_US,
APCTRL_MINIMUM_IDLE_FILTER_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 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*/ /* Get each parameter value from input string*/
sscanf(buf, "%d %d %d %d %d", &paramlist[0], &paramlist[1], sscanf(buf, "%d %d %d %d %d", &paramlist[0], &paramlist[1],
&paramlist[2], &paramlist[3], &paramlist[4]); &paramlist[2], &paramlist[3], &paramlist[4]);
@@ -659,10 +665,15 @@ static ssize_t aelpg_param_read(struct device *dev,
{ {
struct gk20a *g = get_gk20a(dev); struct gk20a *g = get_gk20a(dev);
if (g->aelpg_enabled) {
return snprintf(buf, NVGPU_CPU_PAGE_SIZE, return snprintf(buf, NVGPU_CPU_PAGE_SIZE,
"%d %d %d %d %d\n", g->pmu->pg->aelpg_param[0], "%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[1], g->pmu->pg->aelpg_param[2],
g->pmu->pg->aelpg_param[3], g->pmu->pg->aelpg_param[4]); 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, 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) if (kstrtoul(buf, 10, &val) < 0)
return -EINVAL; return -EINVAL;
if (!g->can_elpg) {
nvgpu_info(g, "Feature not supported");
return count;
}
err = gk20a_busy(g); err = gk20a_busy(g);
if (err) { if (err) {
return err; return err;