* [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM
@ 2023-06-14 16:15 Jeffrey Hugo
2023-06-15 7:05 ` Christian König
2023-06-20 14:17 ` Jeffrey Hugo
0 siblings, 2 replies; 4+ messages in thread
From: Jeffrey Hugo @ 2023-06-14 16:15 UTC (permalink / raw)
To: quic_carlv, quic_pkanojiy, christian.koenig, sukrut.bellary,
sumit.semwal
Cc: Jeffrey Hugo, linux-arm-msm, ogabbay, kernel-janitors,
linux-kernel, dri-devel, linaro-mm-sig, linux-media
From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
smatch warning:
drivers/accel/qaic/qaic_data.c:620 qaic_free_object() error:
dereferencing freed memory 'obj->import_attach'
obj->import_attach is detached and freed using dma_buf_detach().
But used after free to decrease the dmabuf ref count using
dma_buf_put().
drm_prime_gem_destroy() handles this issue and performs the proper clean
up instead of open coding it in the driver.
Fixes: ff13be830333 ("accel/qaic: Add datapath")
Reported-by: Sukrut Bellary <sukrut.bellary@linux.com>
Closes: https://lore.kernel.org/all/20230610021200.377452-1-sukrut.bellary@linux.com/
Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
Reviewed-by: Carl Vanderlip <quic_carlv@quicinc.com>
Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
---
drivers/accel/qaic/qaic_data.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index e42c1f9ffff8..e9a1cb779b30 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -23,6 +23,7 @@
#include <linux/wait.h>
#include <drm/drm_file.h>
#include <drm/drm_gem.h>
+#include <drm/drm_prime.h>
#include <drm/drm_print.h>
#include <uapi/drm/qaic_accel.h>
@@ -616,8 +617,7 @@ static void qaic_free_object(struct drm_gem_object *obj)
if (obj->import_attach) {
/* DMABUF/PRIME Path */
- dma_buf_detach(obj->import_attach->dmabuf, obj->import_attach);
- dma_buf_put(obj->import_attach->dmabuf);
+ drm_prime_gem_destroy(obj, NULL);
} else {
/* Private buffer allocation path */
qaic_free_sgt(bo->sgt);
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM
2023-06-14 16:15 [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM Jeffrey Hugo
@ 2023-06-15 7:05 ` Christian König
2023-06-15 15:23 ` Jeffrey Hugo
2023-06-20 14:17 ` Jeffrey Hugo
1 sibling, 1 reply; 4+ messages in thread
From: Christian König @ 2023-06-15 7:05 UTC (permalink / raw)
To: Jeffrey Hugo, quic_carlv, quic_pkanojiy, sukrut.bellary, sumit.semwal
Cc: linux-arm-msm, ogabbay, kernel-janitors, linux-kernel, dri-devel,
linaro-mm-sig, linux-media
Am 14.06.23 um 18:15 schrieb Jeffrey Hugo:
> From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
>
> smatch warning:
> drivers/accel/qaic/qaic_data.c:620 qaic_free_object() error:
> dereferencing freed memory 'obj->import_attach'
>
> obj->import_attach is detached and freed using dma_buf_detach().
> But used after free to decrease the dmabuf ref count using
> dma_buf_put().
>
> drm_prime_gem_destroy() handles this issue and performs the proper clean
> up instead of open coding it in the driver.
>
> Fixes: ff13be830333 ("accel/qaic: Add datapath")
> Reported-by: Sukrut Bellary <sukrut.bellary@linux.com>
> Closes: https://lore.kernel.org/all/20230610021200.377452-1-sukrut.bellary@linux.com/
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
> Reviewed-by: Carl Vanderlip <quic_carlv@quicinc.com>
> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/accel/qaic/qaic_data.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> index e42c1f9ffff8..e9a1cb779b30 100644
> --- a/drivers/accel/qaic/qaic_data.c
> +++ b/drivers/accel/qaic/qaic_data.c
> @@ -23,6 +23,7 @@
> #include <linux/wait.h>
> #include <drm/drm_file.h>
> #include <drm/drm_gem.h>
> +#include <drm/drm_prime.h>
> #include <drm/drm_print.h>
> #include <uapi/drm/qaic_accel.h>
>
> @@ -616,8 +617,7 @@ static void qaic_free_object(struct drm_gem_object *obj)
>
> if (obj->import_attach) {
> /* DMABUF/PRIME Path */
> - dma_buf_detach(obj->import_attach->dmabuf, obj->import_attach);
> - dma_buf_put(obj->import_attach->dmabuf);
> + drm_prime_gem_destroy(obj, NULL);
> } else {
> /* Private buffer allocation path */
> qaic_free_sgt(bo->sgt);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM
2023-06-15 7:05 ` Christian König
@ 2023-06-15 15:23 ` Jeffrey Hugo
0 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Hugo @ 2023-06-15 15:23 UTC (permalink / raw)
To: Christian König, quic_carlv, quic_pkanojiy, sukrut.bellary,
sumit.semwal
Cc: linux-arm-msm, ogabbay, kernel-janitors, linux-kernel, dri-devel,
linaro-mm-sig, linux-media
On 6/15/2023 1:05 AM, Christian König wrote:
>
>
> Am 14.06.23 um 18:15 schrieb Jeffrey Hugo:
>> From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
>>
>> smatch warning:
>> drivers/accel/qaic/qaic_data.c:620 qaic_free_object() error:
>> dereferencing freed memory 'obj->import_attach'
>>
>> obj->import_attach is detached and freed using dma_buf_detach().
>> But used after free to decrease the dmabuf ref count using
>> dma_buf_put().
>>
>> drm_prime_gem_destroy() handles this issue and performs the proper clean
>> up instead of open coding it in the driver.
>>
>> Fixes: ff13be830333 ("accel/qaic: Add datapath")
>> Reported-by: Sukrut Bellary <sukrut.bellary@linux.com>
>> Closes:
>> https://lore.kernel.org/all/20230610021200.377452-1-sukrut.bellary@linux.com/
>>
>> Suggested-by: Christian König <christian.koenig@amd.com>
>> Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
>> Reviewed-by: Carl Vanderlip <quic_carlv@quicinc.com>
>> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
>> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
Thanks for the guidance and review!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM
2023-06-14 16:15 [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM Jeffrey Hugo
2023-06-15 7:05 ` Christian König
@ 2023-06-20 14:17 ` Jeffrey Hugo
1 sibling, 0 replies; 4+ messages in thread
From: Jeffrey Hugo @ 2023-06-20 14:17 UTC (permalink / raw)
To: quic_carlv, quic_pkanojiy, christian.koenig, sukrut.bellary,
sumit.semwal
Cc: linux-arm-msm, ogabbay, kernel-janitors, linux-kernel, dri-devel,
linaro-mm-sig, linux-media
On 6/14/2023 10:15 AM, Jeffrey Hugo wrote:
> From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
>
> smatch warning:
> drivers/accel/qaic/qaic_data.c:620 qaic_free_object() error:
> dereferencing freed memory 'obj->import_attach'
>
> obj->import_attach is detached and freed using dma_buf_detach().
> But used after free to decrease the dmabuf ref count using
> dma_buf_put().
>
> drm_prime_gem_destroy() handles this issue and performs the proper clean
> up instead of open coding it in the driver.
>
> Fixes: ff13be830333 ("accel/qaic: Add datapath")
> Reported-by: Sukrut Bellary <sukrut.bellary@linux.com>
> Closes: https://lore.kernel.org/all/20230610021200.377452-1-sukrut.bellary@linux.com/
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
> Reviewed-by: Carl Vanderlip <quic_carlv@quicinc.com>
> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Pushed to drm-misc-fixes
-Jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-20 14:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 16:15 [PATCH] accel/qaic: Call DRM helper function to destroy prime GEM Jeffrey Hugo
2023-06-15 7:05 ` Christian König
2023-06-15 15:23 ` Jeffrey Hugo
2023-06-20 14:17 ` Jeffrey Hugo
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).