linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] fix for ide-scsi crash
@ 2004-01-20  9:44 Andries.Brouwer
  2004-01-20 12:04 ` Pascal Schmidt
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Andries.Brouwer @ 2004-01-20  9:44 UTC (permalink / raw)
  To: der.eremit, torvalds; +Cc: Andries.Brouwer, akpm, linux-kernel

    From torvalds@osdl.org  Tue Jan 20 08:33:03 2004

    > This patch seems to solve all my 2.6 ide-scsi problems.

    I've applied the fix part of it and pushed it out.

Good.

    If Andries wants to
    re-send the whitespace fixes, I can apply those too, but I hate applying 
    patches like this where the whitespace fixes hide the real fix.

Yes, it seems we presently have no good mechanism / policy here.
Patches are noise. If some kernel version works and another doesnt,
one has to look at the diffs. Whitespace-only diffs are bad,
I would never submit them. They also needlessly invalidate existing patches.

On the other hand, nice, readable kernel sources are important.
I used to polish the immediate neighbourhood of an actual change.
If that is undesirable, what would you prefer?

    > Andrew, you can drop the atapi-mo-support patches from -mm if you
    > like. That patch only works with 2048 byte sector discs, while
    > the ide-scsi/sd solution also works with 512 and 1024 byte sector
    > discs.

    I'd really like the ATA cdrom driver to handle different sector sizes 
    properly. There really is no excuse for a block device driver to hardcode 
    its blocksize if it can avoid it.

Yes, it is very easy to change that.
And another thing that is very easy is to move partitioning away
from the individual block devices. It was part of the stuff I did
last year. Hope to try again for 2.7.
And then there is the read-only part that must be removed.

Those are three reasons why ide-cd today doesnt work so well
with optical disks. But I am not sure it is desirable to make
ide-cd work with them. The source would be littered with ifs -
all this toc stuff is inappropriate for disks.

Andries





^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH] fix for ide-scsi crash
@ 2004-01-20 17:08 Pascal Schmidt
  2004-01-20 20:01 ` Andries Brouwer
  0 siblings, 1 reply; 16+ messages in thread
From: Pascal Schmidt @ 2004-01-20 17:08 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel


>> Agree, it's a bug. Pascal, care to take a stab at fixing it? You're the
>> most avid ide-cd non-2kb block size user at the moment :)

> There's a lot of macros related to sector sizes in ide-cd.h. I suppose
> all that would need to be changed to depend on the real hardware sector
> size?

I've actually looked at the code now and it seems that it might be
quite easy to fix this, after all.

I have a question about cdrom_start_read_continuation:

Variables called nframes and frames are computed but never used. Only
nskip actually gets factored into the request:

	rq->current_nr_sectors += nskip;

The others are local vars and never get assigned to anything more
global. So I conclude they are meaningless? I ask because this
is one of the places that uses SECTORS_PER_FRAME and it doesn't make
sense to me.

Unrelated question:

Later on, the code decides to use DMA only for requests aligned
on a SECTORS_PER_FRAME boundary. Where does this limitation come from?
Does it come from the drive, so that alignment to 512 byte would be
enough on a drive with 512 byte sectors?

I've actually ordered some 512 byte sector MO discs today and will try
to get them working with ide-cd once they arrive here.

-- 
Ciao,
Pascal


^ permalink raw reply	[flat|nested] 16+ messages in thread
[parent not found: <1fMNb-6UA-15@gated-at.bofh.it>]
* Re: [PATCH] fix for ide-scsi crash
@ 2004-01-19 22:56 Andries.Brouwer
  0 siblings, 0 replies; 16+ messages in thread
From: Andries.Brouwer @ 2004-01-19 22:56 UTC (permalink / raw)
  To: Andries.Brouwer, linux-kernel, wrlk

    From: Willem Riede <wrlk@riede.org>

    > -    spin_unlock_irq(cmd->device->host->host_lock);
    > -    (void) ide_do_drive_cmd (drive, rq, ide_end);
    > -    spin_lock_irq(cmd->device->host->host_lock);
    > +    {
    > +        struct Scsi_Host *host = cmd->device->host;
    > +        spin_unlock_irq(host->host_lock);
    > +        (void) ide_do_drive_cmd(drive, rq, ide_end);
    > +        spin_lock_irq(host->host_lock);
    > +    }

    Interesting. So cmd->device->host changed after ide_do_drive_cmd?

It is a race.
ide_do_drive_cmd(..., ide_end) does not wait for I/O to finish,
but when I/O finishes cmd is freed. So, if the device is quick
and the kernel is slow - maybe a timer interrupt in between -
the command can have finished before the spin_lock_irq() is done.

    That may be a problem if the scsi error handler has to spring 
    into action for this command, as it uses that field extensively...

    > -    if (pc) kfree (pc);
    > -    if (rq) kfree (rq);
    > +    kfree (pc);
    > +    kfree (rq);

    So it is OK to rely on the NULL check in kfree?

Yes. Many years ago I regarded it as ugly to do so, but by now
it is common usage.

Andries



^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH] fix for ide-scsi crash
@ 2004-01-19 18:51 Pascal Schmidt
  2004-01-20  7:32 ` Linus Torvalds
  0 siblings, 1 reply; 16+ messages in thread
From: Pascal Schmidt @ 2004-01-19 18:51 UTC (permalink / raw)
  To: Andries.Brouwer, Andrew Morton, linux-kernel


> A rather reproducible crash with ide-scsi that I reported
> yesterday is fixed by the patch below.

> [With this in place I wrote three times 640 MB to floptical and diffed;
> no problems occurred. Without it the system would crash each time.]

I can confirm that it also makes my MO drive work with ide-scsi.
I could also successfully write 4.1 GB of data to a DVD+RW disc.
Writing 700 MB to a normal CD-RW disc also worked (yes, I know I
could use ide-cd for this, I just did this for testing the ide-scsi
fix).

This patch seems to solve all my 2.6 ide-scsi problems.

Andrew, you can drop the atapi-mo-support patches from -mm if you
like. That patch only works with 2048 byte sector discs, while
the ide-scsi/sd solution also works with 512 and 1024 byte sector
discs.

-- 
Ciao,
Pascal


^ permalink raw reply	[flat|nested] 16+ messages in thread
* [PATCH] fix for ide-scsi crash
@ 2004-01-19  4:35 Andries.Brouwer
  2004-01-19 22:35 ` Willem Riede
  0 siblings, 1 reply; 16+ messages in thread
From: Andries.Brouwer @ 2004-01-19  4:35 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

A rather reproducible crash with ide-scsi that I reported
yesterday is fixed by the patch below.

(Most of this is just polishing that emacs did while my eyes
looked at the code. The only change is not doing
       ide_do_drive_cmd (drive, rq, ide_end);
       spin_lock_irq(cmd->device->host->host_lock);
since cmd may be freed already.)

Andries

[With this in place I wrote three times 640 MB to floptical and diffed;
no problems occurred. Without it the system would crash each time.]

diff -u --recursive --new-file -X /linux/dontdiff a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
--- a/drivers/ide/ide-io.c	2004-01-11 14:20:49.000000000 +0100
+++ b/drivers/ide/ide-io.c	2004-01-19 05:00:47.000000000 +0100
@@ -1300,7 +1300,7 @@
  *	Initialize a request before we fill it in and send it down to
  *	ide_do_drive_cmd. Commands must be set up by this function. Right
  *	now it doesn't do a lot, but if that changes abusers will have a
- *	nasty suprise.
+ *	nasty surprise.
  */
 
 void ide_init_drive_cmd (struct request *rq)
diff -u --recursive --new-file -X /linux/dontdiff a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
--- a/drivers/scsi/ide-scsi.c	2003-12-18 03:59:05.000000000 +0100
+++ b/drivers/scsi/ide-scsi.c	2004-01-19 05:30:28.000000000 +0100
@@ -148,7 +148,8 @@
 		count = IDE_MIN (pc->sg->length - pc->b_count, bcount);
 		buf = page_address(pc->sg->page) + pc->sg->offset;
 		atapi_input_bytes (drive, buf + pc->b_count, count);
-		bcount -= count; pc->b_count += count;
+		bcount -= count;
+		pc->b_count += count;
 		if (pc->b_count == pc->sg->length) {
 			pc->sg++;
 			pc->b_count = 0;
@@ -191,8 +192,12 @@
 		return;
 	if (drive->media == ide_cdrom || drive->media == ide_optical) {
 		if (c[0] == READ_6 || c[0] == WRITE_6) {
-			c[8] = c[4];		c[5] = c[3];		c[4] = c[2];
-			c[3] = c[1] & 0x1f;	c[2] = 0;		c[1] &= 0xe0;
+			c[8] = c[4];
+			c[5] = c[3];
+			c[4] = c[2];
+			c[3] = c[1] & 0x1f;
+			c[2] = 0;
+			c[1] &= 0xe0;
 			c[0] += (READ_10 - READ_6);
 		}
 		if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) {
@@ -380,7 +385,7 @@
 static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
 {
 	idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-	idescsi_pc_t *pc=scsi->pc;
+	idescsi_pc_t *pc = scsi->pc;
 	struct request *rq = pc->rq;
 	atapi_bcount_t bcount;
 	atapi_status_t status;
@@ -664,8 +669,6 @@
 	.ioctl		= idescsi_ide_ioctl,
 };
 
-static int idescsi_attach(ide_drive_t *drive);
-
 static int idescsi_slave_configure(Scsi_Device * sdp)
 {
 	/* Configure detected device */
@@ -794,7 +797,8 @@
 	idescsi_pc_t *pc = NULL;
 
 	if (!drive) {
-		printk (KERN_ERR "ide-scsi: drive id %d not present\n", cmd->device->id);
+		printk (KERN_ERR "ide-scsi: drive id %d not present\n",
+			cmd->device->id);
 		goto abort;
 	}
 	scsi = drive_to_idescsi(drive);
@@ -827,25 +831,30 @@
 	idescsi_transform_pc1 (drive, pc);
 
 	if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
-		printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
+		printk ("ide-scsi: %s: que %lu, cmd = ",
+			drive->name, cmd->serial_number);
 		hexdump(cmd->cmnd, cmd->cmd_len);
 		if (memcmp(pc->c, cmd->cmnd, cmd->cmd_len)) {
-			printk ("ide-scsi: %s: que %lu, tsl = ", drive->name, cmd->serial_number);
+			printk("ide-scsi: %s: que %lu, tsl = ",
+			       drive->name, cmd->serial_number);
 			hexdump(pc->c, 12);
 		}
 	}
 
-	ide_init_drive_cmd (rq);
+	ide_init_drive_cmd(rq);
 	rq->special = (char *) pc;
-	rq->bio = idescsi_dma_bio (drive, pc);
+	rq->bio = idescsi_dma_bio(drive, pc);
 	rq->flags = REQ_SPECIAL;
-	spin_unlock_irq(cmd->device->host->host_lock);
-	(void) ide_do_drive_cmd (drive, rq, ide_end);
-	spin_lock_irq(cmd->device->host->host_lock);
+	{
+		struct Scsi_Host *host = cmd->device->host;
+		spin_unlock_irq(host->host_lock);
+		(void) ide_do_drive_cmd(drive, rq, ide_end);
+		spin_lock_irq(host->host_lock);
+	}
 	return 0;
 abort:
-	if (pc) kfree (pc);
-	if (rq) kfree (rq);
+	kfree (pc);
+	kfree (rq);
 	cmd->result = DID_ERROR << 16;
 	done(cmd);
 	return 1;

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2004-01-20 20:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-20  9:44 [PATCH] fix for ide-scsi crash Andries.Brouwer
2004-01-20 12:04 ` Pascal Schmidt
2004-01-20 13:56   ` Jens Axboe
2004-01-20 17:56 ` Linus Torvalds
2004-01-20 18:46 ` Ben Pfaff
  -- strict thread matches above, loose matches on Subject: below --
2004-01-20 17:08 Pascal Schmidt
2004-01-20 20:01 ` Andries Brouwer
2004-01-20 20:58   ` Pascal Schmidt
     [not found] <1fMNb-6UA-15@gated-at.bofh.it>
     [not found] ` <1fYEB-pz-23@gated-at.bofh.it>
     [not found]   ` <1g4Ao-60b-25@gated-at.bofh.it>
2004-01-20 14:59     ` Pascal Schmidt
2004-01-20 19:04       ` bill davidsen
2004-01-19 22:56 Andries.Brouwer
2004-01-19 18:51 Pascal Schmidt
2004-01-20  7:32 ` Linus Torvalds
2004-01-20 13:54   ` Jens Axboe
2004-01-19  4:35 Andries.Brouwer
2004-01-19 22:35 ` Willem Riede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).