BUG in scsi_lib.c due to a bad commit
I
Hi Barto,
sorry for the late reply, and thanks for drilling down the exact conditions.
I think we have some issues with the lack of the host lock vs error handling, but I still don't undertand the details.
I've got a test patch for you that just adds the host lock back in a few places while keeing the atomic_t. Can you try to reproduce with that one?
When breaking an existing setup in software it's always the softwares fault, btw..
drivers/scsi/scsi_lib.c +6 -6
@@ -311,16 +311,16 @@ void scsi_device_unbusy(struct scsi_device *sdev)struct scsi_target *starget =scsi_target (sdev);unsigned long flags; +spin_lock_irqsave (shost->host_lock, flags);atomic_dec (&shost->host_busy);if (starget->can_queue >0 )atomic_dec (&starget->target_busy);if (unlikely (scsi_host_in_recovery (shost) && (shost->host_failed || shost->host_eh_scheduled))) { -spin_lock_irqsave (shost->host_lock, flags);scsi_eh_wakeup (shost); -spin_unlock_irqrestore (shost->host_lock, flags); } +spin_unlock_irqrestore (shost->host_lock, flags);atomic_dec (&sdev->device_busy); }
@@ -1504,6 +1504,8 @@ static inline int scsi_host_queue_ready(struct request_queue *q,if (scsi_host_in_recovery (shost))return 0 ; +spin_lock_irq (shost->host_lock); + busy =atomic_inc_return (&shost->host_busy) -1 ;if (atomic_read (&shost->host_blocked) >0 ) {if (busy)
@@ -1527,21 +1529,19 @@ static inline int scsi_host_queue_ready(struct request_queue *q,/* We're OK to process the command, so we can't be starved */ if (!list_empty (&sdev->starved_entry)) { -spin_lock_irq (shost->host_lock);if (!list_empty (&sdev->starved_entry))list_del_init (&sdev->starved_entry); -spin_unlock_irq (shost->host_lock); } +spin_unlock_irq (shost->host_lock);return 1 ; starved: -spin_lock_irq (shost->host_lock);if (list_empty (&sdev->starved_entry))list_add_tail (&sdev->starved_entry, &shost->starved_list); -spin_unlock_irq (shost->host_lock); out_dec:atomic_dec (&shost->host_busy); +spin_unlock_irq (shost->host_lock);return 0 ; }
Hello Christoph,
I tested your patch, it works, the bug is gone with your patch, it's a good news,
I notice that my motherboard doesn't support "AHCI" mode, my motherboard uses an ICH7 sata controler, ICH7 doesn't support AHCI if I check the technical specifications of this controler,
it seems that my bios treats SATA devices like IDE devices ( IDE emulation mode ), for example I can read in the bios these lines "IDE 0 channel master : "the name of Sata harddisk 1", "IDE 3 channel master :
"the name of Sata harddisk 2",
perhaps the bug only occurs when the AHCI mode is not used ?
because on archlinux forums another user has noticed that this bug only occurs if he enables the "IDE emulation" option in the bios of his motherboard ( a recent gigabyte motherboard : Z68P-DS3 intel for i7 CPU ), and if he chooses the "AHCI mode" instead of the "IDE emulation mode" in his bios settings then the bug disappears, no random hangs at boot when AHCI is enabled,
and this user has also a SATA DVD burner,
so perhaps you can reproduce this bug on your PC if you have the same option enabled in the bios ( IDE emulation mode ) and a Sata DVD burner, in this case you will have 20~30% of chance to trigger the bug ( random hangs will occur approximately every 5~10 boots )
Quoted 75 lines · Christoph Hellwig
I
Hi Barto,
sorry for the late reply, and thanks for drilling down the exact conditions.
I think we have some issues with the lack of the host lock vs error handling, but I still don't undertand the details.
I've got a test patch for you that just adds the host lock back in a few places while keeing the
atomic_t. Can you try to reproduce with that one?When breaking an existing setup in software it's always the softwares fault, btw..
drivers/scsi/scsi_lib.c +6
-6@@ -311,16 +311,16 @@ void scsi_device_unbusy(struct scsi_device *sdev)struct scsi_target *starget =scsi_target (sdev);unsigned long flags; +spin_lock_irqsave (shost->host_lock, flags);atomic_dec (&shost->host_busy);if (starget->can_queue >0 )atomic_dec (&starget->target_busy);if (unlikely (scsi_host_in_recovery (shost) && (shost->host_failed || shost->host_eh_scheduled))) { -spin_lock_irqsave (shost->host_lock, flags);scsi_eh_wakeup (shost); -spin_unlock_irqrestore (shost->host_lock, flags); } +spin_unlock_irqrestore (shost->host_lock, flags);atomic_dec (&sdev->device_busy); }@@ -1504,6 +1504,8 @@ static inline int scsi_host_queue_ready(struct request_queue *q,if (scsi_host_in_recovery (shost))return 0 ; +spin_lock_irq (shost->host_lock); + busy =atomic_inc_return (&shost->host_busy) -1 ;if (atomic_read (&shost->host_blocked) >0 ) {if (busy)@@ -1527,21 +1529,19 @@ static inline int scsi_host_queue_ready(struct request_queue *q,/* We're OK to process the command, so we can't be starved */ if (!list_empty (&sdev->starved_entry)) { -spin_lock_irq (shost->host_lock);if (!list_empty (&sdev->starved_entry))list_del_init (&sdev->starved_entry); -spin_unlock_irq (shost->host_lock); } +spin_unlock_irq (shost->host_lock);return 1 ; starved: -spin_lock_irq (shost->host_lock);if (list_empty (&sdev->starved_entry))list_add_tail (&sdev->starved_entry, &shost->starved_list); -spin_unlock_irq (shost->host_lock); out_dec:atomic_dec (&shost->host_busy); +spin_unlock_irq (shost->host_lock);return 0 ; }
Quoted 10 lines · Barto
I notice that my motherboard doesn't support "AHCI" mode, my motherboard uses an ICH7 sata controler, ICH7 doesn't support AHCI if I check the technical specifications of this controler,
it seems that my bios treats SATA devices like IDE devices ( IDE emulation mode ), for example I can read in the bios these lines "IDE 0 channel master : "the name of Sata harddisk 1", "IDE 3 channel master :
"the name of Sata harddisk 2",perhaps the bug only occurs when the AHCI mode is not used ?
Looks like it. I suspect you device only supports a single outstanding command without AHCI, can you confirm this by doing:
for i in /sys/class/scsi_host/*; do cat $i/can_queue; done
Hello,
here is the result of the command :
$ for i in /sys/class/scsi_host/*; do cat $i/can_queue; done 1 1 1 1 1 1 31 31
but the sata DVD burner is now connected on a Jmicron sata PCIe card ( with this configuration the bug doesn't occur ), I don't know if this change can modify the result of your command,
here is the result of another command :
$ for i in /sys/class/scsi_host/*; do cat $i/proc_name; done pata_jmicron pata_jmicron ata_piix ata_piix ata_piix ata_piix ahci ahci
$ dmesg | grep ahci [ 0.883351] ahci 0000:03:00.0: version 3.0 [ 0.883505] ahci 0000:03:00.0: AHCI 0001.0100 32 slots 2 ports 3 Gbps 0x3 impl SATA mode [ 0.883508] ahci 0000:03:00.0: flags: 64bit ncq pm led clo pmp pio slum part [ 0.884329] scsi host6: ahci [ 0.884502] scsi host7: ahci
Quoted 18 lines · Christoph Hellwig
Quoted 10 lines · Barto
I notice that my motherboard doesn't support "AHCI" mode, my motherboard uses an ICH7 sata controler, ICH7 doesn't support AHCI if I check the technical specifications of this controler,
it seems that my bios treats SATA devices like IDE devices ( IDE emulation mode ), for example I can read in the bios these lines "IDE 0 channel master : "the name of Sata harddisk 1", "IDE 3 channel master :
"the name of Sata harddisk 2",perhaps the bug only occurs when the AHCI mode is not used ?
Looks like it. I suspect you device only supports a single outstanding command without AHCI, can you confirm this by doing:
for i in
/sys/class/scsi_host/*; do cat $i/can_queue; done
Quoted 6 lines · Barto
but the sata DVD burner is now connected on a Jmicron sata PCIe card ( with this configuration the bug doesn't occur ), I don't know if this change can modify the result of your command,
here is the result of another command :
Quoted 9 lines
$ for i in /sys/class/scsi_host/*; do cat $i/proc_name; done pata_jmicron pata_jmicron ata_piix ata_piix ata_piix ata_piix ahci ahci
Interesting. So the jmicron card also has a queue depth of just one, but the error still occurs? I've added the linux-ide list, maybe someone there has an idea how piix vs jmicron could have such different behaviors for queueing or error handling.
Hello Christoph,
to be clear :
my JMicron pcie card JMB363/368 has 2 sata ports and one IDE port, JMicron supports AHCI on these 2 sata ports,
my gigabyte motherboard has 4 sata ports and one IDE port, my gigabyte motherboard doesn't support AHCI on these 4 sata ports ( my bios seems to treats sata devices like IDE devices, a kind of "IDE emulation mode" ),
the bug doesn't occur if the Sata DVD burner is not mixed with a hard disk on the Sata ports ( motherboard sata ports ),
the configuration who triggers the bug is mixing a slow device ( sata dvd burner ) with a fast device ( sata harddisk ) on the sata ports of the motherboard ( who doesn't support AHCI ),
the bug doesn't occur if the sata dvd burner is connected on a JMicron pcie card because there is no other sata harddisks connected on this JMicron, I connect only a IDE hardidsk on this JMicron pcie card and also this Sata dvd burner in order to avoid the bug ( it's a workaround ),
2 pata_jmicron = the IDE port in this JMicron pcie card ( master and slave ) 4 ata_piix = 4 sata ports from the gigabyte motherboard, this ports doesn't support AHCI
2 ahci = 2 sata ports in this JMicron pcie card
but another user has the same problem but with an IDE DVD burner ( mixed with an IDE hardidsk ) :
https://bugzilla.kernel.org/show_bug.cgi?id=87581#c18
this user has tested your patch and it solves the bug
Quoted 23 lines · Christoph Hellwig
Quoted 6 lines · Barto
but the sata DVD burner is now connected on a Jmicron sata PCIe card ( with this configuration the bug doesn't occur ), I don't know if this change can modify the result of your command,
here is the result of another command :
Quoted 9 lines
$ for i in /sys/class/scsi_host/*; do cat $i/proc_name; done pata_jmicron pata_jmicron ata_piix ata_piix ata_piix ata_piix ahci ahciInteresting. So the jmicron card also has a queue depth of just one, but the error still occurs? I've added the linux-ide list, maybe someone there has an idea how piix vs jmicron could have such different behaviors for queueing or error handling.