Re: i2c_powermac: Kernel access of bad area
Hi Christian, hi Ben, On Tue, 29 Dec 2009 20:34:15 +1100, Benjamin Herrenschmidt wrote: > On Mon, 2009-12-28 at 20:40 -0800, Christian Kujau wrote: > > Hi there, > > > > I was trying to find out if I still need i2c_powermac to get details off > > /sys/devices/temperatures, since lm-sensors isn't working for me anyway. This is because the macintosh/therm_adt746x driver doesn't follow the standard hwmon sysfs interface. I would love to see that change. > > After unloading this module, I noticed that reading certain objects would > > fail with a segfault on the prompt and an Oops in the kernel log: > > Definitely looks like we fail to clean things up on remove. Indeed. > I don't have much time to look into this right now, so best is you file > a bug report on bugzilla.kernel.org, make sure I'm CCed. > > Jean (added on CC), in case you already know what's up, please share :-) I don't know anything about this for now. But I'll help if I can. Christian, did you happen to try removing the i2c-powermac driver before? I am curious if this is a recent problem, possibly caused by changes to the i2c stack, or if older kernels already had this problem and nobody ever noticed. I suspect the latter. Looking at drivers/macintosh/therm_adt746x.c, the sysfs files are created in thermostat_init() and removed in thermostat_exit(), which are the driver's init and exit functions. These files are backed-up by a per-device structure, so it looks like the wrong thing to do. I think this is the problem: the sysfs files have a lifetime longer than the data structure that is backing it up. This is somewhat different from "we fail to clean things up on remove": I suspect that even if i2c-powermac was never ever loaded, the same problem would happen. I think that sysfs files creation should be moved to the end of probe_thermostat() and sysfs files removal should be moved to the beginning of remove_thermostat(). Something like the totally untested patch below (no ppc machine at hand): --- drivers/macintosh/therm_adt746x.c | 34 -- 1 file changed, 24 insertions(+), 10 deletions(-) --- linux-2.6.33-rc3.orig/drivers/macintosh/therm_adt746x.c 2010-01-06 17:30:48.0 +0100 +++ linux-2.6.33-rc3/drivers/macintosh/therm_adt746x.c 2010-01-06 17:36:35.0 +0100 @@ -90,6 +90,8 @@ static struct task_struct *thread_therm static void write_both_fan_speed(struct thermostat *th, int speed); static void write_fan_speed(struct thermostat *th, int speed, int fan); +static void thermostat_create_files(void); +static void thermostat_remove_files(void); static int write_reg(struct thermostat* th, int reg, u8 data) @@ -161,6 +163,8 @@ remove_thermostat(struct i2c_client *cli struct thermostat *th = i2c_get_clientdata(client); int i; + thermostat_remove_files(); + if (thread_therm != NULL) { kthread_stop(thread_therm); } @@ -449,6 +453,8 @@ static int probe_thermostat(struct i2c_c return -ENOMEM; } + thermostat_create_files(); + return 0; } @@ -566,7 +572,6 @@ thermostat_init(void) struct device_node* np; const u32 *prop; int i = 0, offset = 0; - int err; np = of_find_node_by_name(NULL, "fan"); if (!np) @@ -633,6 +638,17 @@ thermostat_init(void) return -ENODEV; } +#ifndef CONFIG_I2C_POWERMAC + request_module("i2c-powermac"); +#endif + + return i2c_add_driver(&thermostat_driver); +} + +static void thermostat_create_files(void) +{ + int err; + err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature); err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature); err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit); @@ -647,16 +663,9 @@ thermostat_init(void) if (err) printk(KERN_WARNING "Failed to create tempertaure attribute file(s).\n"); - -#ifndef CONFIG_I2C_POWERMAC - request_module("i2c-powermac"); -#endif - - return i2c_add_driver(&thermostat_driver); } -static void __exit -thermostat_exit(void) +static void thermostat_remove_files(void) { if (of_dev) { device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature); @@ -673,9 +682,14 @@ thermostat_exit(void) device_remove_file(&of_dev->dev, &dev_attr_sensor2_fan_speed); - of_device_unregister(of_dev); } +} + +static void __exit +thermostat_exit(void) +{ i2c_del_driver(&thermostat_driver); + of_device_unregister(of_dev); } module_init(thermostat_init); -- Jean Delvare ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: i2c_powermac: Kernel access of bad area
On Wed, 6 Jan 2010 at 17:37, Jean Delvare wrote: > Christian, did you happen to try removing the i2c-powermac driver > before? Well, I definitely removed the driver before, but I'm not sure if I ever read the /sys files after doing this :-\ > I am curious if this is a recent problem, possibly caused by > changes to the i2c stack, or if older kernels already had this problem > and nobody ever noticed. I suspect the latter. Fair question, but I really could't tell. I realize a bisection would be helpful, but I don't think I'll have to time to do this on this machine (it's a PowerBook G4, but kernel still compilation usually takes ~30min) and I'm not sure that I care _that_ much about this particular issue. I just wanted to report this one, for the sake of the archives, as noone else seems to be bothered by it anyway... > I think that sysfs files creation should be moved to the end of > probe_thermostat() and sysfs files removal should be moved to the > beginning of remove_thermostat(). Something like the totally untested > patch below (no ppc machine at hand): OK, thanks Jean - I'll give it a try later today and let you know. Thanks again, Christian. -- BOFH excuse #398: Data for intranet got routed through the extranet and landed on the internet. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: i2c_powermac: Kernel access of bad area
Hi Jean, On Wed, 6 Jan 2010 at 17:37, Jean Delvare wrote: > I think that sysfs files creation should be moved to the end of > probe_thermostat() and sysfs files removal should be moved to the > beginning of remove_thermostat(). Something like the totally untested > patch below (no ppc machine at hand): I applied your patch to 2.6.33-rc3, and was able to unload i2c-powermac and then reading the files left in /sys/devices/temperatures. I even tried to read the non-existant files (e.g. sensor1_fan_speed, etc...), but the kernel just wouldn't oops :) So the initial oops is gone - yeah! However, the "Badness" remains when I try to modprobe i2c-powermac again: [ 442.148222] PowerMac i2c bus pmu 2 registered [ 442.148792] PowerMac i2c bus pmu 1 registered [ 442.149299] PowerMac i2c bus mac-io 0 registered [ 442.163573] adt746x: ADT7467 initializing [ 442.170072] adt746x: Lowering max temperatures from 73, 80, 109 to 67, 47, 67 [ 442.176559] PowerMac i2c bus uni-n 1 registered [ 442.227115] sysfs: cannot create duplicate filename '/devices/ams' [ 442.227697] [ cut here ] [ 442.228176] Badness at fs/sysfs/dir.c:487 [ 442.228642] NIP: c00eb71c LR: c00eb71c CTR: [ 442.229117] REGS: eea0fa50 TRAP: 0700 Not tainted (2.6.33-rc3) [ 442.229592] MSR: 00029032 CR: 42008444 XER: [ 442.230151] TASK = eea1[2821] 'modprobe' THREAD: eea0e000 [ 442.230191] GPR00: c00eb71c eea0fb00 eea1 004c 64c6 [ 442.230758] GPR08: efa71740 c03e 64c6 44008428 10020390 100e 100df49c [ 442.231326] GPR16: 100b54c0 100df49c 100ddd20 1018fb08 100b5340 c03e674c c03e6720 c03ea044 [ 442.231902] GPR24: 24008422 ffea eea0fb58 ef0e9000 ef0e9000 ef0a9ea0 ffef [ 442.233187] NIP [c00eb71c] sysfs_add_one+0x94/0xc0 [ 442.233695] LR [c00eb71c] sysfs_add_one+0x94/0xc0 [ 442.234363] Call Trace: I've put the whole dmesg on: http://nerdbynature.de/bits/2.6.33-rc2/i2c_powermac/r1/ Thanks for your time, Christian. -- BOFH excuse #168: le0: no carrier: transceiver cable problem? ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: i2c_powermac: Kernel access of bad area
Ben, Christian, On Thu, 7 Jan 2010 17:17:38 +0100, Jean Delvare wrote: > On Wed, 6 Jan 2010 19:41:05 -0800 (PST), Christian Kujau wrote: > > Hi Jean, > > > > On Wed, 6 Jan 2010 at 17:37, Jean Delvare wrote: > > > I think that sysfs files creation should be moved to the end of > > > probe_thermostat() and sysfs files removal should be moved to the > > > beginning of remove_thermostat(). Something like the totally untested > > > patch below (no ppc machine at hand): > > > > I applied your patch to 2.6.33-rc3, and was able to unload i2c-powermac and > > then reading the files left in /sys/devices/temperatures. I even tried to > > read the non-existant files (e.g. sensor1_fan_speed, etc...), but the > > kernel just wouldn't oops :) > > > > So the initial oops is gone - yeah! Ben, what about applying this patch of mine, as Christian reported it fixed his oops? > > However, the "Badness" remains when I try to modprobe i2c-powermac again: > > > > [ 442.148222] PowerMac i2c bus pmu 2 registered > > [ 442.148792] PowerMac i2c bus pmu 1 registered > > [ 442.149299] PowerMac i2c bus mac-io 0 registered > > [ 442.163573] adt746x: ADT7467 initializing > > [ 442.170072] adt746x: Lowering max temperatures from 73, 80, 109 to 67, > > 47, 67 > > [ 442.176559] PowerMac i2c bus uni-n 1 registered > > [ 442.227115] sysfs: cannot create duplicate filename '/devices/ams' > > [ 442.227697] [ cut here ] > > [ 442.228176] Badness at fs/sysfs/dir.c:487 > > [ 442.228642] NIP: c00eb71c LR: c00eb71c CTR: > > [ 442.229117] REGS: eea0fa50 TRAP: 0700 Not tainted (2.6.33-rc3) > > [ 442.229592] MSR: 00029032 CR: 42008444 XER: > > [ 442.230151] TASK = eea1[2821] 'modprobe' THREAD: eea0e000 > > [ 442.230191] GPR00: c00eb71c eea0fb00 eea1 004c 64c6 > > > > [ 442.230758] GPR08: efa71740 c03e 64c6 44008428 10020390 > > 100e 100df49c > > [ 442.231326] GPR16: 100b54c0 100df49c 100ddd20 1018fb08 100b5340 c03e674c > > c03e6720 c03ea044 > > [ 442.231902] GPR24: 24008422 ffea eea0fb58 ef0e9000 ef0e9000 > > ef0a9ea0 ffef > > [ 442.233187] NIP [c00eb71c] sysfs_add_one+0x94/0xc0 > > [ 442.233695] LR [c00eb71c] sysfs_add_one+0x94/0xc0 > > [ 442.234363] Call Trace: > > > > I've put the whole dmesg on: > > > >http://nerdbynature.de/bits/2.6.33-rc2/i2c_powermac/r1/ > > Hmm. Looks like a different but somewhat similar problem in the ams > driver: some code that is in ams_exit() (the module exit code) should > instead be called when the device (not module) is removed. It probably > doesn't make much of a difference in the PMU case, but in the I2C case > it does matter. > > The following, totally untested patch may fix it. I make no guarantee > that my code isn't racy though, I'm not familiar enough with the ams > driver code to tell for sure. > > --- > drivers/hwmon/ams/ams-core.c | 11 +++ > drivers/hwmon/ams/ams-i2c.c |2 ++ > drivers/hwmon/ams/ams-pmu.c |2 ++ > drivers/hwmon/ams/ams.h |1 + > 4 files changed, 12 insertions(+), 4 deletions(-) > > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams-core.c2009-06-10 > 05:05:27.0 +0200 > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams-core.c 2010-01-07 > 17:14:25.0 +0100 > @@ -213,7 +213,7 @@ int __init ams_init(void) > return -ENODEV; > } > > -void ams_exit(void) > +void ams_sensor_detach(void) > { > /* Remove input device */ > ams_input_exit(); > @@ -221,9 +221,6 @@ void ams_exit(void) > /* Remove attributes */ > device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); > > - /* Shut down implementation */ > - ams_info.exit(); > - > /* Flush interrupt worker >* >* We do this after ams_info.exit(), because an interrupt might > @@ -239,6 +236,12 @@ void ams_exit(void) > pmf_unregister_irq_client(&ams_freefall_client); > } > > +static void __exit ams_exit(void) > +{ > + /* Shut down implementation */ > + ams_info.exit(); > +} > + > MODULE_AUTHOR("Stelian Pop, Michael Hanselmann"); > MODULE_DESCRIPTION("Apple Motion Sensor driver"); > MODULE_LICENSE("GPL"); > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams-i2c.c 2009-06-10 > 05:05:27.0 +0200 > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams-i2c.c 2010-01-07 > 17:12:46.0 +0100 > @@ -238,6 +238,8 @@ static int ams_i2c_probe(struct i2c_clie > static int ams_i2c_remove(struct i2c_client *client) > { > if (ams_info.has_device) { > + ams_sensor_detach(); > + > /* Disable interrupts */ > ams_i2c_set_irq(AMS_IRQ_ALL, 0); > > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams-pmu.c 2009-06-10 > 05:05:27.0 +0200 > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams-pmu.c 2010-01-07 > 17:13:47.0 +0100 > @@ -133,6 +133,8 @@ static void ams_pmu_get_xyz(s8 *x, s8 *y > > static void
Re: i2c_powermac: Kernel access of bad area
> Ben, what about applying this patch of mine, as Christian reported it > fixed his oops? Sure. I never quite know with i2c which ones you will apply directly and which ones you want to go through my tree :-) Hopefully they should still be referened on patchwork, I'll dig there and pick them up. Cheers, Ben. > > > However, the "Badness" remains when I try to modprobe i2c-powermac again: > > > > > > [ 442.148222] PowerMac i2c bus pmu 2 registered > > > [ 442.148792] PowerMac i2c bus pmu 1 registered > > > [ 442.149299] PowerMac i2c bus mac-io 0 registered > > > [ 442.163573] adt746x: ADT7467 initializing > > > [ 442.170072] adt746x: Lowering max temperatures from 73, 80, 109 to 67, > > > 47, 67 > > > [ 442.176559] PowerMac i2c bus uni-n 1 registered > > > [ 442.227115] sysfs: cannot create duplicate filename '/devices/ams' > > > [ 442.227697] [ cut here ] > > > [ 442.228176] Badness at fs/sysfs/dir.c:487 > > > [ 442.228642] NIP: c00eb71c LR: c00eb71c CTR: > > > [ 442.229117] REGS: eea0fa50 TRAP: 0700 Not tainted (2.6.33-rc3) > > > [ 442.229592] MSR: 00029032 CR: 42008444 XER: > > > [ 442.230151] TASK = eea1[2821] 'modprobe' THREAD: eea0e000 > > > [ 442.230191] GPR00: c00eb71c eea0fb00 eea1 004c 64c6 > > > > > > [ 442.230758] GPR08: efa71740 c03e 64c6 44008428 > > > 10020390 100e 100df49c > > > [ 442.231326] GPR16: 100b54c0 100df49c 100ddd20 1018fb08 100b5340 > > > c03e674c c03e6720 c03ea044 > > > [ 442.231902] GPR24: 24008422 ffea eea0fb58 ef0e9000 > > > ef0e9000 ef0a9ea0 ffef > > > [ 442.233187] NIP [c00eb71c] sysfs_add_one+0x94/0xc0 > > > [ 442.233695] LR [c00eb71c] sysfs_add_one+0x94/0xc0 > > > [ 442.234363] Call Trace: > > > > > > I've put the whole dmesg on: > > > > > >http://nerdbynature.de/bits/2.6.33-rc2/i2c_powermac/r1/ > > > > Hmm. Looks like a different but somewhat similar problem in the ams > > driver: some code that is in ams_exit() (the module exit code) should > > instead be called when the device (not module) is removed. It probably > > doesn't make much of a difference in the PMU case, but in the I2C case > > it does matter. > > > > The following, totally untested patch may fix it. I make no guarantee > > that my code isn't racy though, I'm not familiar enough with the ams > > driver code to tell for sure. > > > > --- > > drivers/hwmon/ams/ams-core.c | 11 +++ > > drivers/hwmon/ams/ams-i2c.c |2 ++ > > drivers/hwmon/ams/ams-pmu.c |2 ++ > > drivers/hwmon/ams/ams.h |1 + > > 4 files changed, 12 insertions(+), 4 deletions(-) > > > > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams-core.c 2009-06-10 > > 05:05:27.0 +0200 > > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams-core.c 2010-01-07 > > 17:14:25.0 +0100 > > @@ -213,7 +213,7 @@ int __init ams_init(void) > > return -ENODEV; > > } > > > > -void ams_exit(void) > > +void ams_sensor_detach(void) > > { > > /* Remove input device */ > > ams_input_exit(); > > @@ -221,9 +221,6 @@ void ams_exit(void) > > /* Remove attributes */ > > device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); > > > > - /* Shut down implementation */ > > - ams_info.exit(); > > - > > /* Flush interrupt worker > > * > > * We do this after ams_info.exit(), because an interrupt might > > @@ -239,6 +236,12 @@ void ams_exit(void) > > pmf_unregister_irq_client(&ams_freefall_client); > > } > > > > +static void __exit ams_exit(void) > > +{ > > + /* Shut down implementation */ > > + ams_info.exit(); > > +} > > + > > MODULE_AUTHOR("Stelian Pop, Michael Hanselmann"); > > MODULE_DESCRIPTION("Apple Motion Sensor driver"); > > MODULE_LICENSE("GPL"); > > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams-i2c.c 2009-06-10 > > 05:05:27.0 +0200 > > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams-i2c.c2010-01-07 > > 17:12:46.0 +0100 > > @@ -238,6 +238,8 @@ static int ams_i2c_probe(struct i2c_clie > > static int ams_i2c_remove(struct i2c_client *client) > > { > > if (ams_info.has_device) { > > + ams_sensor_detach(); > > + > > /* Disable interrupts */ > > ams_i2c_set_irq(AMS_IRQ_ALL, 0); > > > > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams-pmu.c 2009-06-10 > > 05:05:27.0 +0200 > > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams-pmu.c2010-01-07 > > 17:13:47.0 +0100 > > @@ -133,6 +133,8 @@ static void ams_pmu_get_xyz(s8 *x, s8 *y > > > > static void ams_pmu_exit(void) > > { > > + ams_sensor_detach(); > > + > > /* Disable interrupts */ > > ams_pmu_set_irq(AMS_IRQ_ALL, 0); > > > > --- linux-2.6.33-rc3.orig/drivers/hwmon/ams/ams.h 2009-06-10 > > 05:05:27.0 +0200 > > +++ linux-2.6.33-rc3/drivers/hwmon/ams/ams.h2010-01-07 > > 17:11:43.0 +0100 > > @@ -61,6 +61,7 @@ extern struct ams ams_in
Re: i2c_powermac: Kernel access of bad area
On Fri, 29 Jan 2010 at 09:18, Jean Delvare wrote: > Christian, did you ever test this second patch of mine? If you did, > what was the outcome? Sorry, I must've missed that 2nd patch of yours. I'll test this now and report back. Thanks, Christian. -- BOFH excuse #112: The monitor is plugged into the serial port ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: i2c_powermac: Kernel access of bad area
On Sat, 30 Jan 2010 08:34:55 +1100, Benjamin Herrenschmidt wrote: > > > Ben, what about applying this patch of mine, as Christian reported it > > fixed his oops? > > Sure. I never quite know with i2c which ones you will apply directly and > which ones you want to go through my tree :-) > > Hopefully they should still be referened on patchwork, I'll dig there > and pick them up. Well, basically I pick patches that touch drivers/i2c/*, and I don't pick patches that touch drivers/macintosh/*. When I can't build the drivers, I don't really feel like pushing the patches myself. -- Jean Delvare ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: i2c_powermac: Kernel access of bad area
On Fri, 29 Jan 2010 at 22:03, Christian Kujau wrote: > On Fri, 29 Jan 2010 at 09:18, Jean Delvare wrote: > > Christian, did you ever test this second patch of mine? If you did, > > what was the outcome? OK, I've now applied both the drivers/hwmon/ams/ patches and your earlier one for drivers/macintosh/therm_adt746x.c [0] to a current -git checkout and now I can unload i2c_powermac, list and read the remaining files in /sys/devices/temperatures, load i2c_powermac again, and unload, and load, and ... - it's wonderful! :-) No oopses so far. Feel free to add a Tested-by: Christian Kujau so that the patches can be pushed into mainline. Thanks for the fixes, Jean! Christian. [0] http://nerdbynature.de/bits/2.6.33-rc2/i2c_powermac/r2/ -- BOFH excuse #337: the butane lighter causes the pincushioning ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: i2c_powermac: Kernel access of bad area
On Sat, 30 Jan 2010 22:05:26 -0800 (PST), Christian Kujau wrote: > OK, I've now applied both the drivers/hwmon/ams/ patches and your earlier > one for drivers/macintosh/therm_adt746x.c [0] to a current -git checkout > and now I can unload i2c_powermac, list and read the remaining files in > /sys/devices/temperatures, load i2c_powermac again, and unload, and > load, and ... - it's wonderful! :-) No oopses so far. > > Feel free to add a Tested-by: Christian Kujau > so that the patches can be pushed into mainline. Thanks, I'll resend both patches with proper comments and headers now. > Thanks for the fixes, Jean! You're welcome. -- Jean Delvare http://khali.linux-fr.org/wishlist.html ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev