* Re: pktcdvd oops [not found] <20071105092018.GD5359@kernel.dk> @ 2007-11-05 22:19 ` Peter Osterlund 2007-11-06 9:06 ` Tejun Heo 0 siblings, 1 reply; 10+ messages in thread From: Peter Osterlund @ 2007-11-05 22:19 UTC (permalink / raw) To: Jens Axboe, Tejun Heo, linux-kernel, Thomas Maier On Mon, 5 Nov 2007, Jens Axboe wrote: > Hi Peter, > > You don't seem to have a bugzilla account, so could not reassign to you. > See http://bugzilla.kernel.org/show_bug.cgi?id=9294 Problem is repeatable on my computer. It dies in __module_get() on this line: BUG_ON(module_refcount(module) == 0); I think this is because commit 7b595756ec1f49e0049a9e01a1298d53a7faaa15, which states: "Note that with this change, userland holding a sysfs node does not prevent the backing module from being unloaded." Unfortunately, I don't know how this sysfs stuff is supposed to work, and therefore don't know how to fix the problem. -- Peter Osterlund - petero2@telia.com http://web.telia.com/~u89404340 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: pktcdvd oops 2007-11-05 22:19 ` pktcdvd oops Peter Osterlund @ 2007-11-06 9:06 ` Tejun Heo 2007-11-06 21:07 ` Thomas Maier 0 siblings, 1 reply; 10+ messages in thread From: Tejun Heo @ 2007-11-06 9:06 UTC (permalink / raw) To: Peter Osterlund; +Cc: Jens Axboe, linux-kernel, Thomas Maier, gregkh [-- Attachment #1: Type: text/plain, Size: 740 bytes --] [Greg cc'd] Peter Osterlund wrote: > On Mon, 5 Nov 2007, Jens Axboe wrote: > >> Hi Peter, >> >> You don't seem to have a bugzilla account, so could not reassign to you. >> See http://bugzilla.kernel.org/show_bug.cgi?id=9294 > > Problem is repeatable on my computer. It dies in __module_get() on this > line: > > BUG_ON(module_refcount(module) == 0); > > I think this is because commit 7b595756ec1f49e0049a9e01a1298d53a7faaa15, > which states: "Note that with this change, userland holding a sysfs node > does not prevent the backing module from being unloaded." > > Unfortunately, I don't know how this sysfs stuff is supposed to work, > and therefore don't know how to fix the problem. Does this fix the problem? -- tejun [-- Attachment #2: patch --] [-- Type: text/plain, Size: 601 bytes --] diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index a8130a4..a5ee213 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -358,10 +358,19 @@ static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf, size_t count) { unsigned int major, minor; + if (sscanf(buf, "%u:%u", &major, &minor) == 2) { + /* pkt_setup_dev() expects caller to hold reference to self */ + if (!try_module_get(THIS_MODULE)) + return -ENODEV; + pkt_setup_dev(MKDEV(major, minor), NULL); + + module_put(THIS_MODULE); + return count; } + return -EINVAL; } ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: pktcdvd oops 2007-11-06 9:06 ` Tejun Heo @ 2007-11-06 21:07 ` Thomas Maier 2007-11-06 21:42 ` Peter Osterlund 0 siblings, 1 reply; 10+ messages in thread From: Thomas Maier @ 2007-11-06 21:07 UTC (permalink / raw) To: Tejun Heo, Peter Osterlund; +Cc: Jens Axboe, linux-kernel, gregkh Hello, have not tested it yet, but i quess, the code mentioned by Peter is in pkt_new_dev() that is called by pkt_setup_dev(): /* This is safe, since we have a reference from open(). */ __module_get(THIS_MODULE); So, now, there must be checks in every sysfs operation in the module code, to ensure that the module is still loaded? BTW: the bug report says: Steps to reproduce: modprobe pktcdvd echo 22:0 >/sys/class/pktcdvd/add Is there any module unload??? Why is the module not available after the modprobe, but the sysfs entries, generated by the module? Confused ;) -Thomas Am 06.11.2007, 10:06 Uhr, schrieb Tejun Heo <htejun@gmail.com>: > [Greg cc'd] > > Peter Osterlund wrote: >> On Mon, 5 Nov 2007, Jens Axboe wrote: >> >>> Hi Peter, >>> >>> You don't seem to have a bugzilla account, so could not reassign to you. >>> See http://bugzilla.kernel.org/show_bug.cgi?id=9294 >> >> Problem is repeatable on my computer. It dies in __module_get() on this >> line: >> >> BUG_ON(module_refcount(module) == 0); >> >> I think this is because commit 7b595756ec1f49e0049a9e01a1298d53a7faaa15, >> which states: "Note that with this change, userland holding a sysfs node >> does not prevent the backing module from being unloaded." >> >> Unfortunately, I don't know how this sysfs stuff is supposed to work, >> and therefore don't know how to fix the problem. > > Does this fix the problem? > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: pktcdvd oops 2007-11-06 21:07 ` Thomas Maier @ 2007-11-06 21:42 ` Peter Osterlund 2007-11-07 2:44 ` Tejun Heo 0 siblings, 1 reply; 10+ messages in thread From: Peter Osterlund @ 2007-11-06 21:42 UTC (permalink / raw) To: Thomas Maier; +Cc: Tejun Heo, Jens Axboe, linux-kernel, gregkh On Tue, 6 Nov 2007, Thomas Maier wrote: > Hello, > > have not tested it yet, but i quess, the code mentioned by Peter > is in pkt_new_dev() that is called by pkt_setup_dev(): > > /* This is safe, since we have a reference from open(). */ > __module_get(THIS_MODULE); > > > So, now, there must be checks in every sysfs operation in the module code, > to ensure that the module is still loaded? I haven't tested it either yet. What I don't understand is this: If the __module_get() is not safe because the module code could have already been unloaded, how can it possibly be made safe by adding more code to the pktcdvd module? If the module is unloaded, trying to execute its code can't be a good thing no matter what the code does. > BTW: the bug report says: > > Steps to reproduce: > > modprobe pktcdvd > echo 22:0 >/sys/class/pktcdvd/add > > Is there any module unload??? Why is the module not available after the > modprobe, but the sysfs entries, generated by the module? Confused ;) I think the purpose of the BUG_ON in __module_get() is to catch cases that are unsafe, even if the call would have happened to work in this particular case. -- Peter Osterlund - petero2@telia.com http://web.telia.com/~u89404340 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: pktcdvd oops 2007-11-06 21:42 ` Peter Osterlund @ 2007-11-07 2:44 ` Tejun Heo 2007-11-07 22:06 ` Peter Osterlund 0 siblings, 1 reply; 10+ messages in thread From: Tejun Heo @ 2007-11-07 2:44 UTC (permalink / raw) To: Peter Osterlund; +Cc: Thomas Maier, Jens Axboe, linux-kernel, gregkh Peter Osterlund wrote: > On Tue, 6 Nov 2007, Thomas Maier wrote: > >> Hello, >> >> have not tested it yet, but i quess, the code mentioned by Peter >> is in pkt_new_dev() that is called by pkt_setup_dev(): >> >> /* This is safe, since we have a reference from open(). */ >> __module_get(THIS_MODULE); >> >> >> So, now, there must be checks in every sysfs operation in the module >> code, >> to ensure that the module is still loaded? > > I haven't tested it either yet. What I don't understand is this: If the > __module_get() is not safe because the module code could have already > been unloaded, how can it possibly be made safe by adding more code to > the pktcdvd module? If the module is unloaded, trying to execute its > code can't be a good thing no matter what the code does. > sysfs itself is now out of module lifespan rules. sysfs callbacks are guaranteed to stay in memory while running by sysfs node removal waiting for completion of in-flight operations before returning. In pktcdvd's case, class_destroy() call in pkt_sysfs_cleanup() will wait for all in-flight sysfs r/w ops to complete. So, even while sysfs callbacks are executing, the module beneath can die but it will stay in memory till all the callbacks return. You need to test module liveness using try_module_get() (and it can fail) if you want to grab module reference from sysfs callbacks. >> BTW: the bug report says: >> >> Steps to reproduce: >> >> modprobe pktcdvd >> echo 22:0 >/sys/class/pktcdvd/add >> >> Is there any module unload??? Why is the module not available after >> the modprobe, but the sysfs entries, generated by the module? Confused ;) > > I think the purpose of the BUG_ON in __module_get() is to catch cases > that are unsafe, even if the call would have happened to work in this > particular case. The BUG_ON is detecting valid condition here. If you rmmod pktcdvd after sysfs write has begun but before __module_get() ran, device node will be created after the module is killed and scheduled to be unloaded. Thanks. -- tejun ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: pktcdvd oops 2007-11-07 2:44 ` Tejun Heo @ 2007-11-07 22:06 ` Peter Osterlund 2007-11-08 2:27 ` [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change Tejun Heo 0 siblings, 1 reply; 10+ messages in thread From: Peter Osterlund @ 2007-11-07 22:06 UTC (permalink / raw) To: Tejun Heo; +Cc: Thomas Maier, Jens Axboe, linux-kernel, gregkh On Wed, 7 Nov 2007, Tejun Heo wrote: > Peter Osterlund wrote: >> If the >> __module_get() is not safe because the module code could have already >> been unloaded, how can it possibly be made safe by adding more code to >> the pktcdvd module? If the module is unloaded, trying to execute its >> code can't be a good thing no matter what the code does. > > sysfs itself is now out of module lifespan rules. sysfs callbacks are > guaranteed to stay in memory while running by sysfs node removal waiting > for completion of in-flight operations before returning. In pktcdvd's > case, class_destroy() call in pkt_sysfs_cleanup() will wait for all > in-flight sysfs r/w ops to complete. > > So, even while sysfs callbacks are executing, the module beneath can die > but it will stay in memory till all the callbacks return. You need to > test module liveness using try_module_get() (and it can fail) if you > want to grab module reference from sysfs callbacks. Thanks for the explanation. Given that explanation, I think the patch is correct and it does fix the BUG on my computer. Can you please push it upstream? In any case: Acked-by: Peter Osterlund <petero2@telia.com> -- Peter Osterlund - petero2@telia.com http://web.telia.com/~u89404340 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change 2007-11-07 22:06 ` Peter Osterlund @ 2007-11-08 2:27 ` Tejun Heo 2007-11-08 5:24 ` Greg KH 0 siblings, 1 reply; 10+ messages in thread From: Tejun Heo @ 2007-11-08 2:27 UTC (permalink / raw) To: Peter Osterlund, gregkh; +Cc: Thomas Maier, Jens Axboe, linux-kernel pkt_setup_dev() expects module reference to be held on invocation. This used to be true for sysfs callbacks but not anymore. Test and grab module reference around pkt_setup_dev() in class_pktcdvd_store_add(). Signed-off-by: Tejun Heo <htejun@gmail.com> Acked-by: Peter Osterlund <petero2@telia.com> --- Greg, can you please push this patch through your tree? Thanks a lot. drivers/block/pktcdvd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index a8130a4..a5ee213 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -358,10 +358,19 @@ static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf, size_t count) { unsigned int major, minor; + if (sscanf(buf, "%u:%u", &major, &minor) == 2) { + /* pkt_setup_dev() expects caller to hold reference to self */ + if (!try_module_get(THIS_MODULE)) + return -ENODEV; + pkt_setup_dev(MKDEV(major, minor), NULL); + + module_put(THIS_MODULE); + return count; } + return -EINVAL; } ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change 2007-11-08 2:27 ` [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change Tejun Heo @ 2007-11-08 5:24 ` Greg KH 2007-11-08 6:55 ` Tejun Heo 0 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2007-11-08 5:24 UTC (permalink / raw) To: Tejun Heo; +Cc: Peter Osterlund, Thomas Maier, Jens Axboe, linux-kernel On Thu, Nov 08, 2007 at 11:27:16AM +0900, Tejun Heo wrote: > pkt_setup_dev() expects module reference to be held on invocation. > This used to be true for sysfs callbacks but not anymore. Test and > grab module reference around pkt_setup_dev() in > class_pktcdvd_store_add(). > > Signed-off-by: Tejun Heo <htejun@gmail.com> > Acked-by: Peter Osterlund <petero2@telia.com> > --- > Greg, can you please push this patch through your tree? > Thanks a lot. > > drivers/block/pktcdvd.c | 9 +++++++++ > 1 file changed, 9 insertions(+) Why through my tree? I don't do block devices :) Shouldn't Jens or at least Andrew take it? thanks, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change 2007-11-08 5:24 ` Greg KH @ 2007-11-08 6:55 ` Tejun Heo 2007-11-08 6:59 ` Jens Axboe 0 siblings, 1 reply; 10+ messages in thread From: Tejun Heo @ 2007-11-08 6:55 UTC (permalink / raw) To: Greg KH; +Cc: Peter Osterlund, Thomas Maier, Jens Axboe, linux-kernel Greg KH wrote: > On Thu, Nov 08, 2007 at 11:27:16AM +0900, Tejun Heo wrote: >> pkt_setup_dev() expects module reference to be held on invocation. >> This used to be true for sysfs callbacks but not anymore. Test and >> grab module reference around pkt_setup_dev() in >> class_pktcdvd_store_add(). >> >> Signed-off-by: Tejun Heo <htejun@gmail.com> >> Acked-by: Peter Osterlund <petero2@telia.com> >> --- >> Greg, can you please push this patch through your tree? >> Thanks a lot. >> >> drivers/block/pktcdvd.c | 9 +++++++++ >> 1 file changed, 9 insertions(+) > > Why through my tree? I don't do block devices :) Because it's a regression introduced by changes in sysfs? > Shouldn't Jens or at least Andrew take it? That's fine too. Jens? -- tejun ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change 2007-11-08 6:55 ` Tejun Heo @ 2007-11-08 6:59 ` Jens Axboe 0 siblings, 0 replies; 10+ messages in thread From: Jens Axboe @ 2007-11-08 6:59 UTC (permalink / raw) To: Tejun Heo; +Cc: Greg KH, Peter Osterlund, Thomas Maier, linux-kernel On Thu, Nov 08 2007, Tejun Heo wrote: > Greg KH wrote: > > On Thu, Nov 08, 2007 at 11:27:16AM +0900, Tejun Heo wrote: > >> pkt_setup_dev() expects module reference to be held on invocation. > >> This used to be true for sysfs callbacks but not anymore. Test and > >> grab module reference around pkt_setup_dev() in > >> class_pktcdvd_store_add(). > >> > >> Signed-off-by: Tejun Heo <htejun@gmail.com> > >> Acked-by: Peter Osterlund <petero2@telia.com> > >> --- > >> Greg, can you please push this patch through your tree? > >> Thanks a lot. > >> > >> drivers/block/pktcdvd.c | 9 +++++++++ > >> 1 file changed, 9 insertions(+) > > > > Why through my tree? I don't do block devices :) > > Because it's a regression introduced by changes in sysfs? > > > Shouldn't Jens or at least Andrew take it? > > That's fine too. Jens? Sure, I'm pushing some stuff off today anyway. -- Jens Axboe ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-11-08 6:59 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20071105092018.GD5359@kernel.dk>
2007-11-05 22:19 ` pktcdvd oops Peter Osterlund
2007-11-06 9:06 ` Tejun Heo
2007-11-06 21:07 ` Thomas Maier
2007-11-06 21:42 ` Peter Osterlund
2007-11-07 2:44 ` Tejun Heo
2007-11-07 22:06 ` Peter Osterlund
2007-11-08 2:27 ` [PATCH] pktcdvd: fix BUG caused by sysfs module reference semantics change Tejun Heo
2007-11-08 5:24 ` Greg KH
2007-11-08 6:55 ` Tejun Heo
2007-11-08 6:59 ` Jens Axboe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox