Skip to contentSkip to conversation

Cell: shutdown method for spu_sysdev_class

RFC Arnd Bergmann 2 participants 3 messages May 29, 2007 – May 30, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 15 lines · Geoff Levand
arch/powerpc/platforms/cell/spu_base.c +9 -0
@@ -463,8 +463,21 @@ void spu_free(struct spu *spu)
 }
 EXPORT_SYMBOL_GPL(spu_free);
 
+static int spu_shutdown(struct sys_device *sysdev)
+{
+       struct spu *spu = container_of(sysdev, struct spu, sysdev);
+
+       // what else here???
+
+       spu_free_irqs(spu);
+       spu_destroy_spu(spu);
+       kfree(spu);

arch/powerpc/platforms/cell/spu_base.c void spu_free(struct spu *spu) · line 483

Quoted 10 lines
arch/powerpc/platforms/cell/spu_base.c +5 -1
+       return 0;
+}
+
 struct sysdev_class spu_sysdev_class = {
-       set_kset_name("spu")
+       set_kset_name("spu"),
+       .shutdown = spu_shutdown,
 };
 
 int spu_add_sysdev_attr(struct sysdev_attribute *attr)

After some debugging, I found that this patch creates an oops when slab debugging is enabled, the reason for that being that sysdev_shutdown() iterates over all system devices using list_for_each_entry(), not list_for_each_entry_safe().

There are two ways of fixing this:

- use list_for_each_entry_safe() to go over all devices so they can be freed in their ->shutdown method.
- not free the device, because we know the system is going down anyway.

Is it documented or implied somewhere that ->shutdown must not free the device? If not, the first option is probably the safer choice.

	Arnd <><
#2 lore raw
Quoted 34 lines · Arnd Bergmann
Quoted 15 lines · Geoff Levand
arch/powerpc/platforms/cell/spu_base.c +9 -0
@@ -463,8 +463,21 @@ void spu_free(struct spu *spu)
 }
 EXPORT_SYMBOL_GPL(spu_free);
 
+static int spu_shutdown(struct sys_device *sysdev)
+{
+       struct spu *spu = container_of(sysdev, struct spu, sysdev);
+
+       // what else here???
+
+       spu_free_irqs(spu);
+       spu_destroy_spu(spu);
+       kfree(spu);

arch/powerpc/platforms/cell/spu_base.c void spu_free(struct spu *spu) · line 483

Quoted 10 lines
arch/powerpc/platforms/cell/spu_base.c +5 -1
+       return 0;
+}
+
 struct sysdev_class spu_sysdev_class = {
-       set_kset_name("spu")
+       set_kset_name("spu"),
+       .shutdown = spu_shutdown,
 };
 
 int spu_add_sysdev_attr(struct sysdev_attribute *attr)

After some debugging, I found that this patch creates an oops when slab debugging is enabled, the reason for that being that sysdev_shutdown() iterates over all system devices using list_for_each_entry(), not list_for_each_entry_safe().

There are two ways of fixing this:

Quoted 7 lines

- use list_for_each_entry_safe() to go over all devices so they can be freed in their ->shutdown method.
- not free the device, because we know the system is going down anyway.

Is it documented or implied somewhere that ->shutdown must not free the device? If not, the first option is probably the safer choice.

It's not documented anywhere, but implicitly assumed. I don't know of any shutdown implementation that frees the device.

#3 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines

Is it documented or implied somewhere that ->shutdown must not free the device? If not, the first option is probably the safer choice.

It's not documented anywhere, but implicitly assumed.  I don't know of any shutdown implementation that frees the device.

Right, I found the explanation now myself:

The ->shutdown method is called for system devices that are still part of a linked linked list. Freeing the object would destroy that list.

Geoff, please merge the patch below in your tree.

	Arnd <><

---

Subject: cell: don't free spu objects in sysdev shutdown

From: Arnd Bergmann <[email protected]> System devices are accessed after they are shut down, so we must not free the data structures.

arch/powerpc/platforms/cell/spu_base.c +0 -1
Index: linux-2.6/arch/powerpc/platforms/cell/spu_base.c
===================================================================
@@ -517,7 +517,6 @@ static int spu_shutdown(struct sys_devic
 
 	spu_free_irqs(spu);
 	spu_destroy_spu(spu);
-	kfree(spu);
 	return 0;
 }