Skip to contentSkip to conversation

driver core: auxiliary bus: Fix IRQ sysfs directory cleanup

PATCH Applied Tariq Toukan 4 participants 4 messages Nov 12 – Nov 23

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 driver core: auxiliary bus: Fix IRQ sysfs directory cleanup

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbound, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind.

[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

The irqs directory state is described by three pieces: the sysfs group, the irq_dir_exists flag and the irqs xarray. Currently, only the sysfs group removal is managed by the devres API, and on unbind the group is removed while the flag and xarray are left intact. Thus, a subsequent bind sees irq_dir_exists still set and skips recreating the directory.

Manage all three under a single release function passed to devm_add_action_or_reset(), so the whole directory state is created and destroyed as a unit.

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
---
 drivers/base/auxiliary_sysfs.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

V3:
- New approach.
- Retitle, and add Danilo's Suggested-by.
- Drop Jacob's Reviewed-by, as the approach changed.

V2:
https://lore.kernel.org/all/[email protected]/

V1:
https://lore.kernel.org/all/[email protected]/

drivers/base/auxiliary_sysfs.c +14 -3
index dea7f46f7dd0..656ba057dc98 100644
@@ -22,21 +22,32 @@ static const struct attribute_group auxiliary_irqs_group = {
 	.attrs = auxiliary_irq_attrs,
 };
 
+static void auxiliary_irq_dir_release(void *data)
+{
+	struct auxiliary_device *auxdev = data;
+
+	xa_destroy(&auxdev->sysfs.irqs);
+	auxdev->sysfs.irq_dir_exists = false;
+	sysfs_remove_group(&auxdev->dev.kobj, &auxiliary_irqs_group);
+}
+
 static int auxiliary_irq_dir_prepare(struct auxiliary_device *auxdev)
 {
-	int ret = 0;
+	int ret;
 
 	guard(mutex)(&auxdev->sysfs.lock);
 	if (auxdev->sysfs.irq_dir_exists)
 		return 0;
 
-	ret = devm_device_add_group(&auxdev->dev, &auxiliary_irqs_group);
+	ret = sysfs_create_group(&auxdev->dev.kobj, &auxiliary_irqs_group);
 	if (ret)
 		return ret;
 
 	auxdev->sysfs.irq_dir_exists = true;
 	xa_init(&auxdev->sysfs.irqs);
-	return 0;
+
+	return devm_add_action_or_reset(&auxdev->dev,
+					auxiliary_irq_dir_release, auxdev);
 }
 
 /**

base-commit: b71c101bbb9814d163c00234d43c41f0a17907d4

Signature · 1 line
2.44.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 23 lines

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbound, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind.

[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

The irqs directory state is described by three pieces: the sysfs group, the irq_dir_exists flag and the irqs xarray. Currently, only the sysfs group removal is managed by the devres API, and on unbind the group is removed while the flag and xarray are left intact. Thus, a subsequent bind sees irq_dir_exists still set and skips recreating the directory.

Manage all three under a single release function passed to devm_add_action_or_reset(), so the whole directory state is created and destroyed as a unit.

Quoted 6 lines
Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v3 1/1
#2 lore raw
In reply to Tariq Toukan
Quoted 29 lines · Tariq Toukan

From: Amir Tzin <[email protected]>

In case an auxiliary device with IRQs directory is unbound, the directory is released, but auxdev->sysfs.irq_dir_exists remains true. This leads to a failure recreating the directory on bind.

[] mlx5_core.sf mlx5_core.sf.2: mlx5_irq_affinity_request:167:(pid 1939):
Failed to create sysfs entry for irq 56, ret = -2
[] mlx5_core.sf mlx5_core.sf.2: mlx5_eq_table_create:1195:(pid 1939):
Failed to create async EQs
[] mlx5_core.sf mlx5_core.sf.2: mlx5_load:1362:(pid 1939):
Failed to create EQs

The irqs directory state is described by three pieces: the sysfs group, the irq_dir_exists flag and the irqs xarray. Currently, only the sysfs group removal is managed by the devres API, and on unbind the group is removed while the flag and xarray are left intact. Thus, a subsequent bind sees irq_dir_exists still set and skips recreating the directory.

Manage all three under a single release function passed to devm_add_action_or_reset(), so the whole directory state is created and destroyed as a unit.

Fixes a808878308a8 ("driver core: auxiliary bus: show auxiliary device IRQs")
Quoted 9 lines
---
 drivers/base/auxiliary_sysfs.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

V3:
- New approach.
- Retitle, and add Danilo's Suggested-by.
- Drop Jacob's Reviewed-by, as the approach changed.

This is much better since the existing behavior already relied on devm/devres, and this avoids needing a lot of changes throughout.

Quoted 48 lines

V2:
https://lore.kernel.org/all/[email protected]/

V1:
https://lore.kernel.org/all/[email protected]/

drivers/base/auxiliary_sysfs.c +14 -3
index dea7f46f7dd0..656ba057dc98 100644
@@ -22,21 +22,32 @@ static const struct attribute_group auxiliary_irqs_group = {
 	.attrs = auxiliary_irq_attrs,
 };
 
+static void auxiliary_irq_dir_release(void *data)
+{
+	struct auxiliary_device *auxdev = data;
+
+	xa_destroy(&auxdev->sysfs.irqs);
+	auxdev->sysfs.irq_dir_exists = false;
+	sysfs_remove_group(&auxdev->dev.kobj, &auxiliary_irqs_group);
+}
+
 static int auxiliary_irq_dir_prepare(struct auxiliary_device *auxdev)
 {
-	int ret = 0;
+	int ret;
 
 	guard(mutex)(&auxdev->sysfs.lock);
 	if (auxdev->sysfs.irq_dir_exists)
 		return 0;
 
-	ret = devm_device_add_group(&auxdev->dev, &auxiliary_irqs_group);
+	ret = sysfs_create_group(&auxdev->dev.kobj, &auxiliary_irqs_group);
 	if (ret)
 		return ret;
 
 	auxdev->sysfs.irq_dir_exists = true;
 	xa_init(&auxdev->sysfs.irqs);
-	return 0;
+
+	return devm_add_action_or_reset(&auxdev->dev,
+					auxiliary_irq_dir_release, auxdev);
 }
 
 /**

base-commit: b71c101bbb9814d163c00234d43c41f0a17907d4

maintainer Applied
#3 lore raw
In reply to Tariq Toukan
Quoted 1 line · Tariq Toukan

[PATCH V3] driver core: auxiliary bus: Fix IRQ sysfs directory cleanup

Applied, thanks!

Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] driver core: auxiliary bus: Fix IRQ sysfs directory cleanup

      commit: b0404f6af48d

The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to driver-core-next after validation.