Message ID | 20241128211223.1805830-5-adrian.larumbe@collabora.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Some Panfrost fixes and improvements | expand |
On Thu, 28 Nov 2024 21:06:19 +0000 Adrián Larumbe <adrian.larumbe@collabora.com> wrote: > If we reach the beginning of the LRU AS list, then return an error. > > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> > --- > drivers/gpu/drm/panfrost/panfrost_job.c | 6 +++++- > drivers/gpu/drm/panfrost/panfrost_mmu.c | 5 +++-- > drivers/gpu/drm/panfrost/panfrost_mmu.h | 2 +- > drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 9 ++++++++- > 4 files changed, 17 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c > index 3f4f0682d69d..fba1a376f593 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_job.c > +++ b/drivers/gpu/drm/panfrost/panfrost_job.c > @@ -214,7 +214,11 @@ static int panfrost_job_hw_submit(struct panfrost_job *job, int js) > goto err_hwsubmit; > } > > - cfg = panfrost_mmu_as_get(pfdev, job->mmu); > + ret = panfrost_mmu_as_get(pfdev, job->mmu); > + if (ret < 0) > + goto err_hwsubmit; > + > + cfg = (u32)ret; > > job_write(pfdev, JS_HEAD_NEXT_LO(js), lower_32_bits(jc_head)); > job_write(pfdev, JS_HEAD_NEXT_HI(js), upper_32_bits(jc_head)); > diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c > index 2189e42d2bfa..03ac527b35e7 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c > +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c > @@ -155,7 +155,7 @@ static void panfrost_mmu_disable(struct panfrost_device *pfdev, u32 as_nr) > write_cmd(pfdev, as_nr, AS_COMMAND_UPDATE); > } > > -u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) > +int panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) > { > int as; > > @@ -197,7 +197,8 @@ u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) > if (!atomic_read(&lru_mmu->as_count)) > break; > } > - WARN_ON(&lru_mmu->list == &pfdev->as_lru_list); > + if (WARN_ON(&lru_mmu->list == &pfdev->as_lru_list)) > + return -EBUSY; > > list_del_init(&lru_mmu->list); > as = lru_mmu->as; > diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.h b/drivers/gpu/drm/panfrost/panfrost_mmu.h > index 022a9a74a114..e6e6966a0cca 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_mmu.h > +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.h > @@ -16,7 +16,7 @@ void panfrost_mmu_fini(struct panfrost_device *pfdev); > void panfrost_mmu_reset(struct panfrost_device *pfdev); > void panfrost_mmu_suspend_irq(struct panfrost_device *pfdev); > > -u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); > +int panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); > void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); > > struct panfrost_mmu *panfrost_mmu_ctx_get(struct panfrost_mmu *mmu); > diff --git a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c > index f30817bcf8ba..2145f9707dde 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c > +++ b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c > @@ -130,7 +130,12 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, > > perfcnt->user = user; > > - as = panfrost_mmu_as_get(pfdev, perfcnt->mapping->mmu); > + ret = panfrost_mmu_as_get(pfdev, perfcnt->mapping->mmu); > + if (ret) > + goto err_unsetuser; > + > + as = (u32)ret; I don't think the explicit cast is needed, since you've already checked that the result is positive. Looks good otherwise. Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > + > cfg = GPU_PERFCNT_CFG_AS(as) | > GPU_PERFCNT_CFG_MODE(GPU_PERFCNT_CFG_MODE_MANUAL); > > @@ -164,6 +169,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, > > return 0; > > +err_unsetuser: > + perfcnt->user = NULL; > err_vunmap: > drm_gem_vunmap_unlocked(&bo->base, &map); > err_put_mapping:
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c index 3f4f0682d69d..fba1a376f593 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -214,7 +214,11 @@ static int panfrost_job_hw_submit(struct panfrost_job *job, int js) goto err_hwsubmit; } - cfg = panfrost_mmu_as_get(pfdev, job->mmu); + ret = panfrost_mmu_as_get(pfdev, job->mmu); + if (ret < 0) + goto err_hwsubmit; + + cfg = (u32)ret; job_write(pfdev, JS_HEAD_NEXT_LO(js), lower_32_bits(jc_head)); job_write(pfdev, JS_HEAD_NEXT_HI(js), upper_32_bits(jc_head)); diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index 2189e42d2bfa..03ac527b35e7 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -155,7 +155,7 @@ static void panfrost_mmu_disable(struct panfrost_device *pfdev, u32 as_nr) write_cmd(pfdev, as_nr, AS_COMMAND_UPDATE); } -u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) +int panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) { int as; @@ -197,7 +197,8 @@ u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) if (!atomic_read(&lru_mmu->as_count)) break; } - WARN_ON(&lru_mmu->list == &pfdev->as_lru_list); + if (WARN_ON(&lru_mmu->list == &pfdev->as_lru_list)) + return -EBUSY; list_del_init(&lru_mmu->list); as = lru_mmu->as; diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.h b/drivers/gpu/drm/panfrost/panfrost_mmu.h index 022a9a74a114..e6e6966a0cca 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.h +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.h @@ -16,7 +16,7 @@ void panfrost_mmu_fini(struct panfrost_device *pfdev); void panfrost_mmu_reset(struct panfrost_device *pfdev); void panfrost_mmu_suspend_irq(struct panfrost_device *pfdev); -u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); +int panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmu); struct panfrost_mmu *panfrost_mmu_ctx_get(struct panfrost_mmu *mmu); diff --git a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c index f30817bcf8ba..2145f9707dde 100644 --- a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c +++ b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c @@ -130,7 +130,12 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, perfcnt->user = user; - as = panfrost_mmu_as_get(pfdev, perfcnt->mapping->mmu); + ret = panfrost_mmu_as_get(pfdev, perfcnt->mapping->mmu); + if (ret) + goto err_unsetuser; + + as = (u32)ret; + cfg = GPU_PERFCNT_CFG_AS(as) | GPU_PERFCNT_CFG_MODE(GPU_PERFCNT_CFG_MODE_MANUAL); @@ -164,6 +169,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, return 0; +err_unsetuser: + perfcnt->user = NULL; err_vunmap: drm_gem_vunmap_unlocked(&bo->base, &map); err_put_mapping:
If we reach the beginning of the LRU AS list, then return an error. Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> --- drivers/gpu/drm/panfrost/panfrost_job.c | 6 +++++- drivers/gpu/drm/panfrost/panfrost_mmu.c | 5 +++-- drivers/gpu/drm/panfrost/panfrost_mmu.h | 2 +- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 9 ++++++++- 4 files changed, 17 insertions(+), 5 deletions(-)