ub.c badness in current bk
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · On Thu, 16 Sep 2004 12:06:01 +1000 Benjamin Herrenschmidt…
usb 1-1: new full speed USB device using address 2
ub: sizeofub_scsi_cmd60ub_dev924
uba: device 2 capacity nsec 50 bsize 512
uba: made changed
uba: device 2 capacity nsec 126720 bsize 512
uba: device 2 capacity nsec 126720 bsize 512
uba: uba1
uba: uba1kobject_registerfailed for uba1 (-17)
Quoted 7 lines
Call trace: [8000ba5c] dump_stack+0x18/0x28 [80132a04] kobject_register+0x68/0x6c [80094e34] add_partition+0xdc/0x100 [80094ff8] register_disk+0x134/0x13c [801866d4] add_disk+0x58/0x74 [c211a070] ub_probe+0x250/0x2c0 [ub]
I'll look tomorrow. These duplicated messages are suspicious, something must be racing.
-- Pete
Quoted 8 lines · On Thu, 16 Sep 2004 12:06:01 +1000 Benjamin Herrenschmidt…
ub: sizeof
ub_scsi_cmd60ub_dev924
uba: device 2 capacity nsec 50 bsize 512
uba: made changed
uba: device 2 capacity nsec 126720 bsize 512
uba: device 2 capacity nsec 126720 bsize 512
uba: uba1
uba: uba1kobject_registerfailed for uba1 (-17)
Please try this (includes the right size for REQUEST SENSE, it's vital):
drivers/block/ub.c +13 -4
@@ -1185,9 +1213,17 @@ goto error; } +/* +* ``If the allocation length is eighteen or greater, and a device +* server returns less than eithteen bytes of data, the application +* client should assume that the bytes not transferred would have been +* zeroes had the device server returned those bytes.'' +*/ memset (&sc->top_sense,0 ,UB_SENSE_SIZE ); + scmd = &sc->top_rqs_cmd; scmd->cdb[0 ] =REQUEST_SENSE ; + scmd->cdb[4 ] =UB_SENSE_SIZE ; scmd->cdb_len =6 ; scmd->dir =UB_DIR_READ ; scmd->state =UB_CMDST_INIT ;
@@ -1474,6 +1515,7 @@static int ub_bd_media_changed (struct gendisk *disk) {struct ub_dev *sc = disk->private_data; +int ret;if (!sc->removable)return 0 ;
@@ -1493,10 +1535,10 @@return 1 ; } -/* The sd.c clears this before returning (one-shot flag). Why? */ -/* P3 */ printk ("%s: %s changed\n" , sc->name, - sc->changed?"is" :"was not" ); -return sc->changed; + ret = sc->changed; +/* P3 */ printk ("%s: %s changed\n" , sc->name, ret ?"is" :"was not" ); + sc->changed =0 ; +return ret; }static struct block_device_operations ub_bd_fops = {
Regardless of the result, I'd like to see the dmesg, and cat $(find /sys -name diag)
-- Pete
Ok, here's a modified patch that fixes the problem for me. As you noticed, it seems the changed flag need to be one-shot, but your code that "made" changed didn't follow that logic. Note that in it's current form, the "new" function is equivalent to getting rid of the "changed" flag completely and just returning the result of ub_sync_tur(). I'll let you do that though if you think it's correct.
Ben.
===== drivers/block/ub.c 1.5 vs edited =====
drivers/block/ub.c +14 -4
@@ -1217,9 +1217,18 @@ goto error; } +/* +* ``If the allocation length is eighteen or greater, and a device +* server returns less than eithteen bytes of data, the application +* client should assume that the bytes not transferred would have been +* zeroes had the device server returned those bytes.'' +*/ +memset (&sc->top_sense,0 ,UB_SENSE_SIZE ); + scmd = &sc->top_rqs_cmd; scmd->cdb[0 ] =REQUEST_SENSE ; + scmd->cdb[4 ] =UB_SENSE_SIZE ; scmd->cdb_len =6 ; scmd->dir =UB_DIR_READ ; scmd->state =UB_CMDST_INIT ;
@@ -1352,7 +1361,6 @@*/ static void ub_revalidate (struct ub_dev *sc) { - sc->readonly =0 ;/* XXX Query this from the device */ /*
@@ -1509,6 +1517,7 @@static int ub_bd_media_changed (struct gendisk *disk) {struct ub_dev *sc = disk->private_data; +int ret;if (!sc->removable)return 0 ;
@@ -1525,12 +1534,13 @@if (ub_sync_tur (sc) !=0 ) { sc->changed =1 ;/* P3 */ printk ("%s: made changed\n" , sc->name); -return 1 ; }/* The sd.c clears this before returning (one-shot flag). Why? */ -/* P3 */ printk ("%s: %s changed\n" , sc->name, - sc->changed?"is" :"was not" ); + ret = sc->changed; +/* P3 */ printk ("%s: %s changed\n" , sc->name, ret ?"is" :"was not" ); + + sc->changed =0 ;return sc->changed; }
drivers/block/ub.c line 1545
Quoted 8 lines · On Fri, 17 Sep 2004 19:46:34 +1000 Benjamin Herrenschmidt…
Ok, here's a modified patch that fixes the problem for me.
drivers/block/ub.c +4
-0+ ret = sc->changed; +/* P3 */ printk ("%s: %s changed\n" , sc->name, ret ?"is" :"was not" ); + + sc->changed =0 ;return sc->changed; }
You return zero always. I don't think it's supposed to be that way. I'm sorry, but I cannot apply it. I'll look for a better solution.
-- Pete
Quoted 5 lines · Pete Zaitcev
Quoted 1 line · On Fri, 17 Sep 2004 19:46:34 +1000 Benjamin Herrenschmidt…
Ok, here's a modified patch that fixes the problem for me.
Quoted 9 lines
drivers/block/ub.c line 1545
Quoted 6 lines
drivers/block/ub.c +4
-0+ ret = sc->changed; +/* P3 */ printk ("%s: %s changed\n" , sc->name, ret ?"is" :"was not" ); + + sc->changed =0 ;return sc->changed; }You return zero always. I don't think it's supposed to be that way. I'm sorry, but I cannot apply it. I'll look for a better solution.
Oops, my wrong, it indeed doesn't make sense... Well, the problem is definitely around here anyway... I'll do more tests when I'm more awake this week-end, the above was done while I was fairly tired ;)
Ben.
Quoted 5 lines · Pete Zaitcev
Quoted 1 line · On Fri, 17 Sep 2004 19:46:34 +1000 Benjamin Herrenschmidt…
Ok, here's a modified patch that fixes the problem for me.
Quoted 9 lines
drivers/block/ub.c line 1545
Quoted 6 lines
drivers/block/ub.c +4
-0+ ret = sc->changed; +/* P3 */ printk ("%s: %s changed\n" , sc->name, ret ?"is" :"was not" ); + + sc->changed =0 ;return sc->changed; }You return zero always. I don't think it's supposed to be that way. I'm sorry, but I cannot apply it. I'll look for a better solution.
Oh, and I confirm that just returning "ret" here (that is practically making sure we only ever return 1 once in my test) still triggers the problem... weird weird
Ben.
Ok, here's a patch that works for me and makes more sense ;)
What happens is that ub_sync_tur() fails a few times when the device is inserted. So we end up returning changed = 1 from within the call to check_disk_change() done by do_open() from the partition code itself, causing a re-entrance in there...
I think add_disk() is very fragile here, but I'll let others like viro (or you :) to fix that.
Anyway, the fix is to better mimmic sd_spinup_disk() within our own revalidate. I think we _should_ actually request sense & analyze it properly, eventually sending spinup commands etc... but in the meantime, a simple retry works well enough for me. Here's the patch:
===== drivers/block/ub.c 1.5 vs edited =====
drivers/block/ub.c +24 -2
@@ -1217,9 +1217,16 @@ goto error; } +/* +* ``If the allocation length is eighteen or greater, and a device +* server returns less than eithteen bytes of data, the application +* client should assume that the bytes not transferred would have been +* zeroes had the device server returned those bytes.'' +*/ memset (&sc->top_sense,0 ,UB_SENSE_SIZE ); scmd = &sc->top_rqs_cmd; scmd->cdb[0 ] =REQUEST_SENSE ; + scmd->cdb[4 ] =UB_SENSE_SIZE ; scmd->cdb_len =6 ; scmd->dir =UB_DIR_READ ; scmd->state =UB_CMDST_INIT ;
@@ -1352,6 +1359,7 @@*/ static void ub_revalidate (struct ub_dev *sc) { +int retries; sc->readonly =0 ;/* XXX Query this from the device */
@@ -1364,8 +1372,21 @@ sc->capacity.bsize =512 ; sc->capacity.bshift =0 ; -if (ub_sync_tur (sc) !=0 ) -return ;/* Not ready */ +/* +* Here's our equivalent of spinup. We probably need to better check +* the sense codes from TUR ? Anyway, some flash devices tend to want +* us to wait a little bit before beeing ready. We may want to do something +* closer to what sd.c does here. --BenH +*/ + retries =0 ; +for (;;) { +if (ub_sync_tur (sc) ==0 ) +break ; +if (++retries >3 ) +return ; +msleep (10 );/* ahem ... */ + } + sc->changed =0 ;if (ub_sync_read_cap (sc, &sc->capacity) !=0 ) {
@@ -1531,6 +1552,7 @@/* The sd.c clears this before returning (one-shot flag). Why? */ /* P3 */ printk ("%s: %s changed\n" , sc->name, sc->changed?"is" :"was not" ); + sc->changed =0 ;return sc->changed; }
Quoted 3 lines · Benjamin Herrenschmidt
Ok, here's a patch that works for me and makes more sense ;)
.../...
And the real one without fuckup in media_change(), sorry, I sent the wrong patch.
===== drivers/block/ub.c 1.5 vs edited =====
drivers/block/ub.c +27 -3
@@ -1217,9 +1217,16 @@ goto error; } +/* +* ``If the allocation length is eighteen or greater, and a device +* server returns less than eithteen bytes of data, the application +* client should assume that the bytes not transferred would have been +* zeroes had the device server returned those bytes.'' +*/ memset (&sc->top_sense,0 ,UB_SENSE_SIZE ); scmd = &sc->top_rqs_cmd; scmd->cdb[0 ] =REQUEST_SENSE ; + scmd->cdb[4 ] =UB_SENSE_SIZE ; scmd->cdb_len =6 ; scmd->dir =UB_DIR_READ ; scmd->state =UB_CMDST_INIT ;
@@ -1352,6 +1359,7 @@*/ static void ub_revalidate (struct ub_dev *sc) { +int retries; sc->readonly =0 ;/* XXX Query this from the device */
@@ -1364,8 +1372,21 @@ sc->capacity.bsize =512 ; sc->capacity.bshift =0 ; -if (ub_sync_tur (sc) !=0 ) -return ;/* Not ready */ +/* +* Here's our equivalent of spinup. We probably need to better check +* the sense codes from TUR ? Anyway, some flash devices tend to want +* us to wait a little bit before beeing ready. We may want to do something +* closer to what sd.c does here. --BenH +*/ + retries =0 ; +for (;;) { +if (ub_sync_tur (sc) ==0 ) +break ; +if (++retries >3 ) +return ; +msleep (10 );/* ahem ... */ + } + sc->changed =0 ;if (ub_sync_read_cap (sc, &sc->capacity) !=0 ) {
@@ -1509,6 +1530,7 @@static int ub_bd_media_changed (struct gendisk *disk) {struct ub_dev *sc = disk->private_data; +int ret;if (!sc->removable)return 0 ;
@@ -1531,7 +1553,9 @@/* The sd.c clears this before returning (one-shot flag). Why? */ /* P3 */ printk ("%s: %s changed\n" , sc->name, sc->changed?"is" :"was not" ); -return sc->changed; + ret = sc->changed; + sc->changed =0 ; +return ret; }static struct block_device_operations ub_bd_fops = {
Review
Quoted 5 lines · On Sat, 18 Sep 2004 12:08:46 +1000 Benjamin Herrenschmidt…
And the real one without fuckup in
media_change(), sorry, I sent the wrong patch.(quoted diff) +2
-0+ * Here's our equivalent of spinup. We probably need to better check + * the sense codes from TUR ?
This really bothers me. The key 6 is asking for a clearing and possibly a spin-up (my ZIP 100 returns 6 until it's spun up), that's right. But it won't start without START_STOP command, on pure TURs. So it's a delusion to accept this as a spin-up. I do plan for a decent spin-up code, but it's a little difficult within the ub's phylosophy (possibly it was a bad design to rely on a state machine too much).
How about this deal. I'll add a clearly marked workaround like the appended patch, and then ask you to try again when a proper spin-up gets implemented?
Note that the patch is against -mm where the REQUEST SENSE is set correctly. I strongly suggest you to use ub from -mm. Linus' tree is behind.
Also, I might have screwed something along the way, so if it fails, please send me dmesg and the contents of /sys/..../diag.
Greetings,
-- Pete
drivers/block/ub.c +21 -11
@@ -25,6 +25,7 @@* -- prune comments, they are too volumnous * -- Exterminate P3 printks * -- Resove XXX's +* -- Redo "benh's retries", perhaps have spin-up code to handle them. V:D=? */ #include <linux/kernel.h> #include <linux/module.h>
@@ -157,7 +158,8 @@ struct ub_scsi_cmd {struct ub_scsi_cmd *next;int error;/* Return code - valid upon done */ -int act_len;/* Return size */ +unsigned int act_len;/* Return size */ +unsigned char key, asc, ascq;/* May be valid if error==-EIO */ int stat_count;/* Retries getting status. */
@@ -1141,16 +1146,8 @@ static void ub_scsi_urb_compl(struct ub_ (*cmd->done)(sc, cmd); }else if (cmd->state ==UB_CMDST_SENSE ) { -/* -* We do not look at sense, because even if there was no sense, -* we get into UB_CMDST_SENSE from a STALL or CSW FAIL only. -* We request sense because we want to clear CHECK CONDITION -* on devices with delusions of SCSI, and not because we -* are curious in any way about the sense itself. -*/ -/* if ((cmd->top_sense[2] & 0x0F) == NO_SENSE) { foo } */ -ub_state_done (sc, cmd, -EIO ); + }else { printk(KERN_WARNING "%s: " "wrong command state %d on device %u\n",
@@ -1309,6 +1306,10 @@ static void ub_top_sense_done(struct ub_*/ ub_cmdtr_sense (sc, scmd, sense); +/* +* Find the command which triggered the unit attention or a check, +* save the sense into it, and advance its state machine. +*/ if ((cmd =ub_cmdq_peek (sc)) ==NULL ) {printk (KERN_WARNING "%s: sense done while idle\n" , sc->name);return ;
@@ -1326,6 +1327,10 @@ static void ub_top_sense_done(struct ub_return ; } + cmd->key = sense[2 ] &0x0F ; + cmd->asc = sense[12 ]; + cmd->ascq = sense[13 ]; +ub_scsi_urb_compl (sc, cmd); }
@@ -1621,6 +1638,9 @@ static int ub_sync_tur(struct ub_dev *sc rc = cmd->error; +if (rc == -EIO && cmd->key !=0 )/* Retries for benh's key */ + rc = cmd->key; + err_submit:kfree (cmd); err_alloc:
@@ -1836,6 +1856,7 @@ static int ub_probe(struct usb_interfacerequest_queue_t *q;struct gendisk *disk;int rc; +int i; rc = -ENOMEM ;if ((sc =kmalloc (sizeof (struct ub_dev ),GFP_KERNEL )) ==NULL )
@@ -1902,7 +1923,11 @@ static int ub_probe(struct usb_interface* has to succeed, so we clear checks with an additional one here. * In any case it's not our business how revaliadation is implemented. */ -ub_sync_tur (sc); +for (i =0 ; i <3 ; i++) {/* Retries for benh's key */ +if ((rc =ub_sync_tur (sc)) <=0 )break ; +if (rc !=0x6 )break ; +msleep (10 ); + } sc->removable =1 ;/* XXX Query this from the device */
Quoted 3 lines · Pete Zaitcev
How about this deal. I'll add a clearly marked workaround like the appended patch, and then ask you to try again when a proper spin-up gets implemented?
Ok, I'll give it a try, but you don't need to call it "benh's key" :) I think everybody at kernel summit got one of those no ? :)
Ben.
Quoted 5 lines
Note that the patch is against -mm where the REQUEST SENSE is set correctly. I strongly suggest you to use ub from -mm. Linus' tree is behind.
Also, I might have screwed something along the way, so if it fails, please send me dmesg and the contents of
/sys/..../diag.
I will later today or tomorrow, thanks !
Ben.