* [PATCH 1/2] drm/msm/a6xx: Replace kcalloc() with kvzalloc()
@ 2022-09-28 7:18 Akhil P Oommen
2022-09-28 7:19 ` [PATCH 2/2] drm/msm/gpu: Fix crash during system suspend after unbind Akhil P Oommen
0 siblings, 1 reply; 2+ messages in thread
From: Akhil P Oommen @ 2022-09-28 7:18 UTC (permalink / raw)
To: freedreno, dri-devel, linux-arm-msm, Rob Clark
Cc: Jonathan Marek, Douglas Anderson, Matthias Kaehlcke,
Jordan Crouse, Akhil P Oommen, Abhinav Kumar, Daniel Vetter,
David Airlie, Dmitry Baryshkov, Sean Paul, linux-kernel
In order to reduce chance of allocation failure while capturing a6xx
gpu state, use kvzalloc() instead of kcalloc() in state_kcalloc().
Indirectly, this patch helps to fix leaking memory allocated for
gmu_debug object.
Fixes: b859f9b009b (drm/msm/gpu: Snapshot GMU debug buffer)
Signed-off-by: Akhil P Oommen <quic_akhilpo@quicinc.com>
---
drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
index 55f4433..3c112a6 100644
--- a/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
+++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
@@ -91,7 +91,7 @@ struct a6xx_state_memobj {
static void *state_kcalloc(struct a6xx_gpu_state *a6xx_state, int nr, size_t objsize)
{
struct a6xx_state_memobj *obj =
- kzalloc((nr * objsize) + sizeof(*obj), GFP_KERNEL);
+ kvzalloc((nr * objsize) + sizeof(*obj), GFP_KERNEL);
if (!obj)
return NULL;
@@ -819,7 +819,7 @@ static struct msm_gpu_state_bo *a6xx_snapshot_gmu_bo(
snapshot->iova = bo->iova;
snapshot->size = bo->size;
- snapshot->data = kvzalloc(snapshot->size, GFP_KERNEL);
+ snapshot->data = state_kcalloc(a6xx_state, 1, snapshot->size);
if (!snapshot->data)
return NULL;
@@ -1034,14 +1034,8 @@ static void a6xx_gpu_state_destroy(struct kref *kref)
struct a6xx_gpu_state *a6xx_state = container_of(state,
struct a6xx_gpu_state, base);
- if (a6xx_state->gmu_log)
- kvfree(a6xx_state->gmu_log->data);
-
- if (a6xx_state->gmu_hfi)
- kvfree(a6xx_state->gmu_hfi->data);
-
list_for_each_entry_safe(obj, tmp, &a6xx_state->objs, node)
- kfree(obj);
+ kvfree(obj);
adreno_gpu_state_destroy(state);
kfree(a6xx_state);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] drm/msm/gpu: Fix crash during system suspend after unbind
2022-09-28 7:18 [PATCH 1/2] drm/msm/a6xx: Replace kcalloc() with kvzalloc() Akhil P Oommen
@ 2022-09-28 7:19 ` Akhil P Oommen
0 siblings, 0 replies; 2+ messages in thread
From: Akhil P Oommen @ 2022-09-28 7:19 UTC (permalink / raw)
To: freedreno, dri-devel, linux-arm-msm, Rob Clark
Cc: Jonathan Marek, Douglas Anderson, Matthias Kaehlcke,
Jordan Crouse, Akhil P Oommen, Abhinav Kumar,
AngeloGioacchino Del Regno, Daniel Vetter, David Airlie,
Dmitry Baryshkov, Konrad Dybcio, Nathan Chancellor, Sean Paul,
Vladimir Lypak, linux-kernel
In adreno_unbind, we should clean up gpu device's drvdata to avoid
accessing a stale pointer during system suspend. Also, check for NULL
ptr in both system suspend/resume callbacks.
Signed-off-by: Akhil P Oommen <quic_akhilpo@quicinc.com>
---
Rebased on msm-next + some external fixes to boot sc7280 device.
drivers/gpu/drm/msm/adreno/adreno_device.c | 10 +++++++++-
drivers/gpu/drm/msm/msm_gpu.c | 2 ++
drivers/gpu/drm/msm/msm_gpu.h | 4 ++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/msm/adreno/adreno_device.c b/drivers/gpu/drm/msm/adreno/adreno_device.c
index 24b489b..6288064 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_device.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_device.c
@@ -679,6 +679,9 @@ static int adreno_system_suspend(struct device *dev)
struct msm_gpu *gpu = dev_to_gpu(dev);
int remaining, ret;
+ if (!gpu)
+ return 0;
+
suspend_scheduler(gpu);
remaining = wait_event_timeout(gpu->retire_event,
@@ -700,7 +703,12 @@ static int adreno_system_suspend(struct device *dev)
static int adreno_system_resume(struct device *dev)
{
- resume_scheduler(dev_to_gpu(dev));
+ struct msm_gpu *gpu = dev_to_gpu(dev);
+
+ if (!gpu)
+ return 0;
+
+ resume_scheduler(gpu);
return pm_runtime_force_resume(dev);
}
diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c
index 0098ee8..021f4e2 100644
--- a/drivers/gpu/drm/msm/msm_gpu.c
+++ b/drivers/gpu/drm/msm/msm_gpu.c
@@ -997,4 +997,6 @@ void msm_gpu_cleanup(struct msm_gpu *gpu)
}
msm_devfreq_cleanup(gpu);
+
+ platform_set_drvdata(gpu->pdev, NULL);
}
diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h
index ff911e73..58a72e6 100644
--- a/drivers/gpu/drm/msm/msm_gpu.h
+++ b/drivers/gpu/drm/msm/msm_gpu.h
@@ -280,6 +280,10 @@ struct msm_gpu {
static inline struct msm_gpu *dev_to_gpu(struct device *dev)
{
struct adreno_smmu_priv *adreno_smmu = dev_get_drvdata(dev);
+
+ if (!adreno_smmu)
+ return NULL;
+
return container_of(adreno_smmu, struct msm_gpu, adreno_smmu);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-28 7:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 7:18 [PATCH 1/2] drm/msm/a6xx: Replace kcalloc() with kvzalloc() Akhil P Oommen
2022-09-28 7:19 ` [PATCH 2/2] drm/msm/gpu: Fix crash during system suspend after unbind Akhil P Oommen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).