Skip to contentSkip to conversation

dmaengine: idxd: Avoid unnecessary destruction of file_ida

PATCH Applied Fenghua Yu 3 participants 4 messages Jan 30, 2024 – May 4, 2024

Subsystems (2)
lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 dmaengine: idxd: Avoid unnecessary destruction of file_ida

file_ida is allocated during cdev open and is freed accordingly during cdev release. This sequence is guaranteed by driver file operations. Therefore, there is no need to destroy an already empty file_ida when the WQ cdev is removed.

Worse, ida_free() in cdev release may happen after destruction of file_ida per WQ cdev. This can lead to accessing an id in file_ida after it has been destroyed, resulting in a kernel panic.

Remove ida_destroy(&file_ida) to address these issues.

Fixes e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened")
---
 drivers/dma/idxd/cdev.c | 1 -
 1 file changed, 1 deletion(-)
drivers/dma/idxd/cdev.c +0 -1
index baa51927675c..3311c920f47a 100644
@@ -1272,7 +1272,6 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
 	struct idxd_cdev *idxd_cdev;
 
 	idxd_cdev = wq->idxd_cdev;
-	ida_destroy(&file_ida);
 	wq->idxd_cdev = NULL;
 	cdev_device_del(&idxd_cdev->cdev, cdev_dev(idxd_cdev));
 	put_device(cdev_dev(idxd_cdev));
Signature · 1 line
2.37.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Fenghua Yu

file_ida is allocated during cdev open and is freed accordingly during cdev release. This sequence is guaranteed by driver file operations. Therefore, there is no need to destroy an already empty file_ida when the WQ cdev is removed.

Worse, ida_free() in cdev release may happen after destruction of file_ida per WQ cdev. This can lead to accessing an id in file_ida after it has been destroyed, resulting in a kernel panic.

Quoted 5 lines

Remove ida_destroy(&file_ida) to address these issues.

Fixes e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened")
Quoted 16 lines
---
 drivers/dma/idxd/cdev.c | 1 -
 1 file changed, 1 deletion(-)
drivers/dma/idxd/cdev.c +0 -1
index baa51927675c..3311c920f47a 100644
@@ -1272,7 +1272,6 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
 	struct idxd_cdev *idxd_cdev;
 
 	idxd_cdev = wq->idxd_cdev;
-	ida_destroy(&file_ida);
 	wq->idxd_cdev = NULL;
 	cdev_device_del(&idxd_cdev->cdev, cdev_dev(idxd_cdev));
 	put_device(cdev_dev(idxd_cdev));
author
#2 lore raw

Hi, Vinod,

Quoted 30 lines · Dave Jiang
Quoted 9 lines · Fenghua Yu

file_ida is allocated during cdev open and is freed accordingly during cdev release. This sequence is guaranteed by driver file operations. Therefore, there is no need to destroy an already empty file_ida when the WQ cdev is removed.

Worse, ida_free() in cdev release may happen after destruction of file_ida per WQ cdev. This can lead to accessing an id in file_ida after it has been destroyed, resulting in a kernel panic.

Quoted 5 lines

Remove ida_destroy(&file_ida) to address these issues.

Fixes e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened")
Quoted 11 lines
---
  drivers/dma/idxd/cdev.c | 1 -
  1 file changed, 1 deletion(-)
drivers/dma/idxd/cdev.c +0 -0
index baa51927675c..3311c920f47a 100644
@@ -1272,7 +1272,6 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
  	struct idxd_cdev *idxd_cdev;
 
Quoted 5 lines

drivers/dma/idxd/cdev.c void idxd_wq_del_cdev(struct idxd_wq *wq) · line 1277

Quoted 5 lines
drivers/dma/idxd/cdev.c +0 -1
  	idxd_cdev = wq->idxd_cdev;
-	ida_destroy(&file_ida);
  	wq->idxd_cdev = NULL;
  	cdev_device_del(&idxd_cdev->cdev, cdev_dev(idxd_cdev));
  	put_device(cdev_dev(idxd_cdev));

I noticed this patch was not merged to upstream yet. The patch is still cleanly applied to upstream.

Could you please help merge this patch?

Thanks.

-Fenghua

maintainer Applied
#3 lore raw
In reply to Fenghua Yu
Quoted 10 lines · Fenghua Yu

file_ida is allocated during cdev open and is freed accordingly during cdev release. This sequence is guaranteed by driver file operations. Therefore, there is no need to destroy an already empty file_ida when the WQ cdev is removed.

Worse, ida_free() in cdev release may happen after destruction of file_ida per WQ cdev. This can lead to accessing an id in file_ida after it has been destroyed, resulting in a kernel panic.

[...]

Applied, thanks!

[1/1] dmaengine: idxd: Avoid unnecessary destruction of file_ida

      commit: 76e43fa6a456787bad31b8d0daeabda27351a480

Best regards,

Signature · 1 line
~Vinod