Disk shock protection in GNU/Linux
Subsystems (2)
Hi all,
yet again, I'm trying to get this feature into the Linux kernel. This time, I have tried to arrange the code in such a way that hardly anything not strictly belonging to the libata or ide subsystem is touched at all. Since former attempts to design this in a more generic way involving the block and scsi layer have proven very difficult and since this is all about an ATA specific feature anyway, I think the best solution (for now at least) is to stick to those two subsystems as far as possible.
Nevertheless, I'd welcome James' opinion on the third patch in the series with regard to the use of vendor specific cdbs. If it is acceptable in principle, the question remains whether we sould reserve part of the range 0xf800 - 0xffff of vendor specific service actions for the exclusive use by LLDDs (in much the way I did it here), or whether all these codes should be unique in the kernel and defined in scsi.h.
Also, we have to agree upon a suitable way to deal with devices that actually do support the UNLOAD FEATURE but don't report that capability in their ID as specified in ATA-7. Perhaps we even want to fall back to STANDBY IMMEDIATE on devices that definitely don't support IDLE IMMEDIATE with UNLOAD FEATURE; this has been the case for the original hdaps / disk-protect patch but I'm not quite sure whether anybody actually relies on this feature and whether it would be advisable in the first place. Regarding devices that support head unloading but don't report it properly, there seem to be the following options:
a) Provide an attribute in sysfs for the user to indicate that the device really does support the UNLOAD FEATURE.
b) Issue the command (for the first time) anyway and check whether the device responds as specified in ATA-7. Make a note of the result and act accordingly from there on.
The second option looks appealing because no user intervention is required and it is known to work at least for some devices. On the other hand, it may be dangerous on old hardware and I don't even know whether all pre-ATA-7 devices supporting the UNLOAD FEATURE really do return the correct data in the command registers.
Here is a short description of the patches in this series applying cleanly on top of next-20080725:
1. This is a trivial patch making things slightly easier for #3. More importantly though, it also fixes a potential memory leak and should probably be applied regardless of the rest of the series (Jeff?).
2. This is a small patch to ata.h in order to provide a simple check for support of the UNLOAD FEATURE as indicated in a device's ID.
3. Here disk head unloading is implemented in the libata subsystem. See the changelog entry for current shortcomings of this patch.
4. The same for ide.
5. A little bit of documentation.
There are some questions I need your advice on that have been inserted as FIXME comments into the code. However, here is a more general question that interests me even though it could turn out to be a good idea (or at least acceptable) to merge these patches before that question has been fully resolved. Alan once mentioned that it might be desirable to abort commands currently in progress and issue IDLE IMMEDIATE straight away. My question is whether this is at all possible for non SATA command protocols. In volume 2 of the ATA-7 specification I haven't found a well defined way to abort or shor circuit, say, a DMA or PIO command in progress. It even says that after the host has aborted data transfer when DMA was in progress, it is supposed to initiate a SRST. Obviously, I'd like to avoid that at all costs.
Thank you in advance for your cooperation,
Elias
PATCH 1/5 Make sure that ata_force_tbl is freed in case of an error
This is just a trivial fix of a potential memory leak when ata_init() encounters an error.
---
drivers/ata/libata-core.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
drivers/ata/libata-core.c +9 -5
@@ -6088,16 +6088,20 @@ static int __init ata_init(void) ata_wq =create_workqueue ("ata" );if (!ata_wq) -return -ENOMEM ; + goto free_force_tbl; ata_aux_wq =create_singlethread_workqueue ("ata_aux" ); -if (!ata_aux_wq) { -destroy_workqueue (ata_wq); -return -ENOMEM ; - } +if (!ata_aux_wq) + goto free_wq;printk (KERN_DEBUG "libata version " DRV_VERSION " loaded.\n" );return 0 ; + +free_wq: +destroy_workqueue (ata_wq); +free_force_tbl: +kfree (ata_force_tbl); +return -ENOMEM ; } static void __exit ata_exit(void)
PATCH 2/5 Introduce ata_id_has_unload()
In reply to Elias OltmannsAdd a function to check an ATA device's id for head unload support as specified in ATA-7.
---
include/linux/ata.h | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
include/linux/ata.h +15 -0
@@ -530,6 +530,21 @@ static inline bool ata_id_has_dipm(const u16 *id) } +static inline int ata_id_has_unload (const u16 *id) +{ +/* +* ATA-7 specifies two places to indicate unload feature support. +* Since I don't really understand the difference, I'll just check +* both and only return zero if none of them indicates otherwise. +*/ +if ((id[ATA_ID_CFSSE ] &0xC000 ) ==0x4000 + && id[ATA_ID_CFSSE ] & (1 <<13 )) +return id[ATA_ID_CFSSE ] & (1 <<13 ); +if ((id[ATA_ID_CSF_DEFAULT ] &0xC000 ) ==0x4000 ) +return id[ATA_ID_CSF_DEFAULT ] & (1 <<13 ); +return 0 ; +} +static inline int ata_id_has_fua (const u16 *id) {if ((id[ATA_ID_CFSSE ] &0xC000 ) !=0x4000 )
PATCH 3/5 libata: Implement disk shock protection support
In reply to Elias OltmannsOn user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the speified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). This patch simply stops processing the request queue. In particular, it does not yet, for instance, defer an SRST issued in order to recover from an error on the other device on the interface.
---
drivers/ata/ahci.c | 1 drivers/ata/ata_piix.c | 6 + drivers/ata/libata-core.c | 6 + drivers/ata/libata-scsi.c | 343 +++++++++++++++++++++++++++++++++++++++++++-- drivers/ata/libata.h | 11 + include/linux/libata.h | 6 + 6 files changed, 360 insertions(+), 13 deletions(-)
drivers/ata/ahci.c +1 -0
@@ -316,6 +316,7 @@ static struct device_attribute *ahci_shost_attrs[] = {static struct device_attribute *ahci_sdev_attrs[] = { &dev_attr_sw_activity, + &dev_attr_unload_heads,NULL };
drivers/ata/ata_piix.c +6 -0
@@ -289,8 +289,14 @@ static struct pci_driver piix_pci_driver = {#endif }; +static struct device_attribute *piix_sdev_attrs[] = { + &dev_attr_unload_heads, +NULL +}; +static struct scsi_host_template piix_sht = {ATA_BMDMA_SHT (DRV_NAME ), + .sdev_attrs = piix_sdev_attrs, };static struct ata_port_operations piix_pata_ops = {
drivers/ata/libata-core.c +6 -0
@@ -6094,6 +6094,11 @@ static int __init ata_init(void)if (!ata_aux_wq) goto free_wq; +if (ata_scsi_register_pm_notifier ()) { +destroy_workqueue (ata_aux_wq); + goto free_wq; + } +printk (KERN_DEBUG "libata version " DRV_VERSION " loaded.\n" );return 0 ;
@@ -6109,6 +6114,7 @@ static void __exit ata_exit(void)kfree (ata_force_tbl);destroy_workqueue (ata_wq);destroy_workqueue (ata_aux_wq); +ata_scsi_unregister_pm_notifier (); }subsys_initcall (ata_init);
drivers/ata/libata-scsi.c +330 -13
458 lines not on this page · raw message
drivers/ata/libata.h +11 -0
@@ -31,6 +31,10 @@#define DRV_NAME "libata"#define DRV_VERSION "3.00"/* must be exactly four chars */ +/* private scsi opcodes */ +#define PARK_HEADS 0xf800 +#define UNPARK_HEADS 0xf801 +struct ata_scsi_args {struct ata_device *dev;u16 *id;
@@ -149,6 +153,13 @@ extern void ata_scsi_hotplug(struct work_struct *work);extern void ata_schedule_scsi_eh (struct Scsi_Host *shost);extern void ata_scsi_dev_rescan (struct work_struct *work);extern int ata_bus_probe (struct ata_port *ap); +#if defined(CONFIG_PM_SLEEP ) || defined(CONFIG_HIBERNATION ) +extern int ata_scsi_register_pm_notifier (void ); +extern int ata_scsi_unregister_pm_notifier (void ); +#else +static inline int ata_scsi_register_pm_notifier (void ) {return 0 ; } +static inline int ata_scsi_unregister_pm_notifier (void ) {return 0 ; } +#endif /* libata-eh.c */ extern unsigned long ata_internal_cmd_timeout (struct ata_device *dev,u8 cmd);
include/linux/libata.h +6 -0
@@ -150,6 +150,7 @@ enum {ATA_DFLAG_DETACH = (1 <<24 ),ATA_DFLAG_DETACHED = (1 <<25 ), +ATA_DFLAG_PARKED = (1 <<26 ),ATA_DEV_UNKNOWN =0 ,/* unknown device */ ATA_DEV_ATA = 1, /* ATA device */
@@ -451,6 +452,7 @@ enum link_pm { MEDIUM_POWER, };extern struct device_attribute dev_attr_link_power_management_policy; +extern struct device_attribute dev_attr_unload_heads;extern struct device_attribute dev_attr_em_message_type;extern struct device_attribute dev_attr_em_message;extern struct device_attribute dev_attr_sw_activity;
@@ -592,6 +594,10 @@ struct ata_device {u16 id[ATA_ID_WORDS ];/* IDENTIFY xxx DEVICE data */ u32 gscr[SATA_PMP_GSCR_DWORDS ];/* PMP GSCR block */ }; + +/* protected by block layer queue lock */ +struct timer_list park_timer; +struct work_struct unpark_work; };/* Offset into struct ata_device. Fields above it are maintained
PATCH 4/5 ide: Implement disk shock protection support
In reply to Elias OltmannsOn user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the speified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). This patch simply stops processing the request queue. In particular, it does not yet, for instance, defer an SRST issued in order to recover from an error on the other device on the interface.
---
drivers/ide/ide-io.c | 26 ++++++ drivers/ide/ide.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/ide.h | 5 + 3 files changed, 254 insertions(+), 0 deletions(-)
drivers/ide/ide-io.c +26 -0
@@ -717,7 +717,28 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,static ide_startstop_t ide_special_rq (ide_drive_t *drive,struct request *rq) { +ide_hwif_t *hwif = drive->hwif; +ide_task_t task; +struct ide_taskfile *tf = &task.tf; + +memset (&task,0 ,sizeof (task));switch (rq->cmd[0 ]) { +case REQ_PARK_HEADS : +if (unlikely (!timer_pending (&drive->park_timer))) { +ide_end_request (drive,0 ,0 ); +return ide_stopped; + } + drive->sleep = drive->park_timer.expires; + drive->sleeping =1 ; + tf->command =WIN_IDLEIMMEDIATE ; + tf->feature =0x44 ; + tf->lbal =0x4c ; + tf->lbam =0x4e ; + tf->lbah =0x55 ; +break ; +case REQ_UNPARK_HEADS : + tf->command =WIN_CHECKPOWERMODE1 ; +break ;case REQ_DRIVE_RESET :return ide_do_reset (drive);default :
@@ -725,6 +746,11 @@ static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)ide_end_request (drive,0 ,0 );return ide_stopped; } + task.tf_flags =IDE_TFLAG_TF |IDE_TFLAG_DEVICE ; + task.rq = rq; + rq->special = &task; + hwif->data_phase = task.data_phase =TASKFILE_NO_DATA ; +return do_rw_taskfile (drive, &task); }static void ide_check_pm_state (ide_drive_t *drive,struct request *rq)
drivers/ide/ide.c +223 -0
268 lines not on this page · raw message
include/linux/ide.h +5 -0
@@ -143,6 +143,8 @@ struct ide_io_ports {* Values should be in the range of 0x20 to 0x3f. */ #define REQ_DRIVE_RESET 0x20 +#define REQ_PARK_HEADS 0x21 +#define REQ_UNPARK_HEADS 0x22/* * Check for an interrupt and acknowledge the interrupt status
@@ -477,6 +479,9 @@ struct ide_drive_s {void (*pc_callback)(struct ide_drive_s *);unsigned long atapi_flags; + +struct timer_list park_timer;/* protected by queue_lock */ +struct work_struct unpark_work; };typedef struct ide_drive_s ide_drive_t ;
PATCH 5/5 Add documentation for hard disk shock protection interface
In reply to Elias OltmannsPut some information (and pointers to more) into the kernel's doc tree, describing briefly how to set up disk shock protection under GNU/Linux.
---
Documentation/laptops/disk-shock-protection.txt | 66 +++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-) create mode 100644 Documentation/laptops/disk-shock-protection.txt
Documentation/laptops/disk-shock-protection.txt new file +66 -0
@@ -0,0 +1,66 @@ +Hard disk shock protection +========================== + +Author: Elias Oltmanns <[email protected]> +Last modified: 2008-07-24 + + +Intro +----- + +ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with UNLOAD FEATURE. +Issuing this command should cause the drive to switch to idle mode and +unload disk heads. This feature is being used in modern laptops in +conjunction with accelerometers and appropriate software to implement +a shock protection facility. The idea is to stop all I/O operations on +the internal hard drive and park its heads on the ramp when critical +situations are anticipated. The desire to have such a feature +available on GNU/Linux systems has been the original motivation to +implement a generic disk head parking interface in the Linux kernel. + + +The interface +------------- + +The interface works as follows: Writing an integer value to +/sys/block/*/device/unload_heads will take the heads of the respective +drive off the platter and block all I/O operations for the specified +number of seconds. When the timeout expires and no further disk head +park request has been issued in the meantime, normal operation will be +resumed. + +FIXME: +Once we've addressed the problem with pre-ATA-7 drives supporting the +UNLOAD FEATURE but not announcing it properly, we'll document it +accordingly. + + +References +---------- + +There are several laptops from different brands featuring shock +protection capabilities. As manufacturers have refused to support open +source development of the required software components so far, Linux +support for shock protection varies considerably between different +hardware implementations. Ideally, this section should contain a list +of pointers at different projects aiming at an implementation of shock +protection on different systeems. Unfortunately, I only know of a +single project which, although still considered experimental, is fit +for use. Please feel free to add projects that have been the victims +of my ignorance. + +- http://www.thinkwiki.org/wiki/HDAPS + See this page for information about Linux support of the hard disk + active protection syystem as implemented in IBM/Lenovo Thinkpads. + (FIXME: The information there will have to be updated once this + patch has been approved or the user interface has been agreed upon + at least.) + + +CREDITS +------- + +This implementation of disk head parking has been based on a patch +originally published by Jon Escombe <[email protected]>. Assisted by +various kernel developers, the author of this document has rewritten +the original patch in order to make it fit for upstream submission.
Re: [PATCH 5/5] Add documentation for hard disk shock protection interface
Hello.
Quoted 5 lines · Elias Oltmanns
Put some information (and pointers to more) into the kernel's doc tree, describing briefly how to set up disk shock protection under GNU/Linux.
Signed-off-by Elias Oltmanns <[email protected]>
[...]
Quoted 6 lines
Documentation/laptops/disk-shock-protection.txt new file +0
-0
[...]
Documentation/laptops/disk-shock-protection.txt line 54
Quoted 5 lines
Documentation/laptops/disk-shock-protection.txt new file +4
-0+ +- http://www.thinkwiki.org/wiki/HDAPS + See this page for information about Linux support of the hard disk + active protection syystem as implemented in IBM/Lenovo Thinkpads.
A typo in "system". :-)
MBR, Sergei
Re: [PATCH 2/5] Introduce ata_id_has_unload()
In reply to Elias OltmannsQuoted 2 lines · On Sat, 26 Jul 2008 08:24:35 +0200 Elias Oltmanns <[email protected]> wrote:
Add a function to check an ATA device's id for head unload support as specified in ATA-7.
If a feature is new in ATA 7 you should also check the ATA version is >=7 in the tests. Just in case some prehistoric device has it down for a different purpose.
Alan
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Elias OltmannsQuoted 10 lines · Elias Oltmanns
On user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the speified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). This patch simply stops processing the request queue. In particular, it does not yet, for instance, defer an SRST issued in order to recover from an error on the other device on the interface.
For libata, the easiest way to achieve the above would be adding a per-dev EH action, say, ATA_EH_UNLOAD and schedule EH w/ the action OR'd to eh_info->action. The EH_UNLOAD handler can then issue the command wait for the specified number of seconds and continue. This will be pretty simple to implement as command exclusion and stuff are all automatically handled by EH framework.
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus). The only reliable way to abort in-flight commands are by issuing hardreset. However, ATA reset protocol is not designed for quick recovery. The machine is gonna hit the ground hard way before the reset protocol is complete.
The only way to solve this nicely is either to build the accelerometer into the drive and let the drive itself protect itself or implement a sideband signal to tell it to duck for cover. For SATA, this sideband signal can be another OOB sequence. If it's ever implemented this way, it will be in SControl, I guess.
Well, short of that, all we can do is to wait for the currently in-flight commands to drain and hope that it happens before the machine hits the ground. Also, that the harddrive is not going through one of the longish EH recovery sequences when it starts to fall. :-(
Signature · 1 line
tejun
Re: [PATCH 3/5] libata: Implement disk shock protection support
Quoted 8 lines
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus). The only reliable way to abort in-flight commands are by issuing hardreset. However, ATA reset protocol is not designed for quick recovery. The machine is gonna hit the ground hard way before the reset protocol is complete.
Actually you cau can issue idle immediate on older ATA devices. I am not clear if that was stuck back into the current accelerometer friendly drives or not. Would need to check with IBLenovo
Re: [PATCH 3/5] libata: Implement disk shock protection support
Quoted 9 lines · Alan Cox
Quoted 8 lines
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus). The only reliable way to abort in-flight commands are by issuing hardreset. However, ATA reset protocol is not designed for quick recovery. The machine is gonna hit the ground hard way before the reset protocol is complete.
Quoted 3 lines
Actually you cau can issue idle immediate on older ATA devices. I am not clear if that was stuck back into the current accelerometer friendly drives or not. Would need to check with IBLenovo
Was that something intentional or was it a happy accident? There can be bus ownership problem on PATA and on SATA this is much more state logic on both sides of the cable and I think things like that would be more difficult to work accidentally.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 3/5] libata: Implement disk shock protection support
Quoted 2 lines
Was that something intentional or was it a happy accident? There can be bus ownership problem on PATA and on SATA this is much more state logic
IDLE IMMEDIATE is part of the "historic" specification rather than modern ATA standards. Older drives support it happily newer ones tended to get quite cross.
Quoted 2 lines
on both sides of the cable and I think things like that would be more difficult to work accidentally.
We'd have to query the drive vendors to see what they expected.
Re: [PATCH 3/5] libata: Implement disk shock protection support
Quoted 4 lines · Alan Cox
Quoted 2 lines
on both sides of the cable and I think things like that would be more difficult to work accidentally.
We'd have to query the drive vendors to see what they expected.
We'll have to query the controller vendors too and I think it's highly likely to cause problems on many controllers.
Signature · 1 line
tejun
Re: [PATCH 4/5] ide: Implement disk shock protection support
In reply to Elias OltmannsHi!
drivers/ide/ide.c line 66
Quoted 6 lines
#include <
linux/ide.h>
#include <linux/completion.h>
#include <linux/device.h>drivers/ide/ide.c +3
-0+#if defined(CONFIG_PM_SLEEP ) || defined(CONFIG_HIBERNATION ) +# include <linux/suspend.h> +#endif
This ifdef should be unneccessary.
Quoted 32 lines
drivers/ide/ide.c +32
-0+#if defined(CONFIG_PM_SLEEP ) || defined(CONFIG_HIBERNATION ) +static int ide_park_count =1 ; +DECLARE_WAIT_QUEUE_HEAD (ide_park_wq); + +static inline int suspend_parking (void ) +{ +spin_lock_irq (&ide_lock); +if (ide_park_count ==1 ) + ide_park_count =0 ; +spin_unlock_irq (&ide_lock); +return !ide_park_count; +} + +static int ide_pm_notifier (struct notifier_block *nb,unsigned long val, +void *null) +{ +switch (val) { +case PM_SUSPEND_PREPARE : +wait_event (ide_park_wq,suspend_parking ()); +break ; +case PM_POST_SUSPEND : + ide_park_count =1 ; +break ; +default : +return NOTIFY_DONE ; + } +return NOTIFY_OK ; +} + +static struct notifier_block ide_pm_notifier_block = { + .notifier_call = ide_pm_notifier, +};
drivers/ide/ide.c DEFINE_MUTEX(ide_cfg_mtx); · line 126
Quoted 10 lines
drivers/ide/ide.c +10
-0+ +static inline int ide_register_pm_notifier (void ) +{ +return register_pm_notifier (&ide_pm_notifier_block); +} + +static inline int ide_unregister_pm_notifier (void ) +{ +return unregister_pm_notifier (&ide_pm_notifier_block); +}
Any reason this does not use normal driver model suspend/resume callbacks?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Tejun HeoQuoted 13 lines · Tejun Heo
Quoted 11 lines · Elias Oltmanns
On user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD
FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the speified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). This patch simply stops processing the request queue. In particular, it does not yet, for instance, defer an SRST issued in order to recover from an error on the other device on the interface.
Quoted 6 lines
For libata, the easiest way to achieve the above would be adding a per-dev EH action, say,
ATA_EH_UNLOADand schedule EH w/ the action OR'd toeh_info->action. TheEH_UNLOADhandler can then issue the command wait for the specified number of seconds and continue. This will be pretty simple to implement as command exclusion and stuff are all automatically handled by EH framework.
I'm rather afraid this approach is impractical or unfavourable at the very least. Depending on the configured thresholds, a head unload request might well be issued unintentionally, e.g. by accidentally knocking against the table. It is quite alright for the HD to stop I/O for a moment but if the secondary device on the interface happens to be a CD writer, it will be very annoying to have CD writing operations fail due to minor percussions. Also, if there are two devices on the same port that support the UNLOAD FEATURE and you issue a head unload request to both of them in close succession, the IDLE IMMEDIATE to the second device will be blocked until the timeout for the first has expired.
Generally, blocking SRST and the likes on a port seems acceptable, but stopping all I/O on a port just because a head unload request has been issued to a single device attached to it is not an option.
Quoted 9 lines
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus). The only reliable way to abort in-flight commands are by issuing hardreset. However, ATA reset protocol is not designed for quick recovery. The machine is gonna hit the ground hard way before the reset protocol is complete.
Yes, I suspected as much. Thanks for the confirmation.
[...]
Quoted 5 lines
Well, short of that, all we can do is to wait for the currently in-flight commands to drain and hope that it happens before the machine hits the ground. Also, that the harddrive is not going through one of the longish EH recovery sequences when it starts to fall. :-(
Yes, it's a bit unsatisfactory but it's better than nothing.
Regards,
Elias
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Alan CoxQuoted 10 lines · Alan Cox
Quoted 9 lines
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus). The only reliable way to abort in-flight commands are by issuing hardreset. However, ATA reset protocol is not designed for quick recovery. The machine is gonna hit the ground hard way before the reset protocol is complete.
Quoted 3 lines
Actually you cau can issue idle immediate on older ATA devices. I am not clear if that was stuck back into the current accelerometer friendly drives or not. Would need to check with IBLenovo
In ide_atapi_error() IDLE IMMEDIATE is issued even if busy bit is still set. This made me hope that we could do something similar wrt disk head unloading. However, since I haven't found anything about this in the specs and considering Tejun's comments, I'm now wondering whether the code in ide_atapi_error() isn't a little imprudent. Also, as long as nothing definite is said about it in the specs, we can only issue IDLE IMMEDIATE in parallel to other commands on devices we know to support it, right?
Regards,
Elias
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Elias OltmannsQuoted 7 lines · Elias Oltmanns
Quoted 6 lines
For libata, the easiest way to achieve the above would be adding a per-dev EH action, say,
ATA_EH_UNLOADand schedule EH w/ the action OR'd toeh_info->action. TheEH_UNLOADhandler can then issue the command wait for the specified number of seconds and continue. This will be pretty simple to implement as command exclusion and stuff are all automatically handled by EH framework.
Quoted 7 lines
I'm rather afraid this approach is impractical or unfavourable at the very least. Depending on the configured thresholds, a head unload request might well be issued unintentionally, e.g. by accidentally knocking against the table. It is quite alright for the HD to stop I/O for a moment but if the secondary device on the interface happens to be a CD writer, it will be very annoying to have CD writing operations fail due to minor percussions.
Why would it fail?
Quoted 4 lines
Also, if there are two devices on the same
port that support the UNLOAD FEATURE and you issue a head unload request to both of them in close succession, the IDLE IMMEDIATE to the second device will be blocked until the timeout for the first has expired.
Unload can be implemented as port-wide operation so that it issues IDLE IMMEDIATE to all drives on the port but given that this is mostly for laptop, this discussion is a bit peripheral.
Signature · 1 line
tejun
Re: [PATCH 4/5] ide: Implement disk shock protection support
In reply to Pavel MachekQuoted 10 lines · Pavel Machek
Hi!
drivers/ide/ide.c line 66
Quoted 6 lines
#include <
linux/ide.h>
#include <linux/completion.h>
#include <linux/device.h>drivers/ide/ide.c +3
-0+#if defined(CONFIG_PM_SLEEP ) || defined(CONFIG_HIBERNATION ) +# include <linux/suspend.h> +#endif This ifdef should be unneccessary.
Right.
Quoted 39 lines
Quoted 39 lines
drivers/ide/ide.c +37
-0+#if defined(CONFIG_PM_SLEEP ) || defined(CONFIG_HIBERNATION ) +static int ide_park_count =1 ; +DECLARE_WAIT_QUEUE_HEAD (ide_park_wq); + +static inline int suspend_parking (void ) +{ +spin_lock_irq (&ide_lock); +if (ide_park_count ==1 ) + ide_park_count =0 ; +spin_unlock_irq (&ide_lock); +return !ide_park_count; +} + +static int ide_pm_notifier (struct notifier_block *nb,unsigned long val, +void *null) +{ +switch (val) { +case PM_SUSPEND_PREPARE : +wait_event (ide_park_wq,suspend_parking ()); +break ; +case PM_POST_SUSPEND : + ide_park_count =1 ; +break ; +default : +return NOTIFY_DONE ; + } +return NOTIFY_OK ; +} + +static struct notifier_block ide_pm_notifier_block = { + .notifier_call = ide_pm_notifier, +}; + +static inline int ide_register_pm_notifier (void ) +{ +return register_pm_notifier (&ide_pm_notifier_block); +}
Quoted 8 lines
drivers/ide/ide.c DEFINE_MUTEX(ide_cfg_mtx); · line 126
Quoted 5 lines
drivers/ide/ide.c +5
-0+ +static inline int ide_unregister_pm_notifier (void ) +{ +return unregister_pm_notifier (&ide_pm_notifier_block); +}Any reason this does not use normal driver model suspend/resume callbacks?
Yes, two in fact. Firstly, it would appear that after freeze_processes() has completed, timers don't fire anymore. That's why we have to call the unpark hook manually. The ATA suspend callback would be the place to do that but the scsi ULD's suspend callback issues a cache sync and a disk start_stop command before and waits indefinitely for completion.
Secondly and more importantly, using pm_notifiers is the right thing to do as long as user processes control when to park and unpark the disks. This way we can hold back from suspending until user space gives the all clear.
Regards,
Elias
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Tejun HeoQuoted 5 lines · Tejun Heo
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus).
A system lockup may be an acceptable compromise if that saves the hardware. Maybe the kernel should explicitely panic unless the controller/drive is known to be able to recover.
Gabor
Signature · 4 lines
---------------------------------------------------------
MTA SZTAKI Computer and Automation Research Institute
Hungarian Academy of Sciences
---------------------------------------------------------Re: [PATCH 3/5] libata: Implement disk shock protection support
Quoted 11 lines · On Mon, 4 Aug 2008 16:28:32 +0200 Gabor Gombas <[email protected]> wrote:
Quoted 5 lines · Tejun Heo
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus).A system lockup may be an acceptable compromise if that saves the hardware. Maybe the kernel should explicitely panic unless the controller/drive is known to be able to recover.
We've already been told that the accelerometer will now and then randomly trigger due to other shock patterns like a bump. I don't want my laptop to panic randomly on train journeys thank you.
Alan
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Gabor GombasQuoted 11 lines · Gabor Gombas
Quoted 5 lines · Tejun Heo
However, SATA or not, there simply isn't a way to abort commands in ATA.
Issuing random command while other commands are in progress simply is
state machine violation and there will be many interesting results including complete system lockup (ATA controller dying while holding the PCI bus).A system lockup may be an acceptable compromise if that saves the hardware. Maybe the kernel should explicitely panic unless the controller/drive is known to be able to recover.
Such lockups usually would occur before the intervening command is successfully issued. HSM violation occurs when the driver asks the controller to send another command while it's already processing another command. Heh... panicking on accelerometer would be fun tho. We're gonna get ourselves really flamewars on just about every linux news site.
Signature · 1 line
tejun
Re: [PATCH 3/5] libata: Implement disk shock protection support
In reply to Tejun HeoQuoted 17 lines · Tejun Heo
Quoted 8 lines · Elias Oltmanns
Quoted 7 lines
For libata, the easiest way to achieve the above would be adding a
per-dev EH action, say,
ATA_EH_UNLOADand schedule EH w/ the action OR'd toeh_info->action. TheEH_UNLOADhandler can then issue the command wait for the specified number of seconds and continue. This will be pretty simple to implement as command exclusion and stuff are all automatically handled by EH framework.Quoted 7 lines
I'm rather afraid this approach is impractical or unfavourable at the very least. Depending on the configured thresholds, a head unload request might well be issued unintentionally, e.g. by accidentally knocking against the table. It is quite alright for the HD to stop I/O for a moment but if the secondary device on the interface happens to be a CD writer, it will be very annoying to have CD writing operations fail due to minor percussions.
Quoted 1 line
Why would it fail?
To be quite honest, I don't know very much about the way CD writing works. I just assumed that delaying queue processing for a CD writer for several seconds would have very much the same effect as the input buffer of cdrecord getting empty prematurely. Do you mean to say that CD writing (or any other time expensive operation I haven't thought of) won't be affected irrecoverably by interrupted command processing?
Quoted 9 lines
Quoted 5 lines
Also, if there are two devices on the same
port that support the UNLOAD FEATURE and you issue a head unload request to both of them in close succession, the IDLE IMMEDIATE to the second device will be blocked until the timeout for the first has expired.Unload can be implemented as port-wide operation so that it issues IDLE IMMEDIATE to all drives on the port but given that this is mostly for laptop, this discussion is a bit peripheral.
We can't rule out that the HD is connected as master and CDRW as slave to the same controller in a PATA setup. I'm not familiar with the SATA configurations in modern laptops though.
Regards,
Elias
Re: [PATCH 3/5] libata: Implement disk shock protection support
Quoted 7 lines · Elias Oltmanns
Quoted 7 lines
Quoted 7 lines
I'm rather afraid this approach is impractical or unfavourable at the very least. Depending on the configured thresholds, a head unload request might well be issued unintentionally, e.g. by accidentally knocking against the table. It is quite alright for the HD to stop I/O for a moment but if the secondary device on the interface happens to be a CD writer, it will be very annoying to have CD writing operations fail due to minor percussions.
Quoted 8 lines
Quoted 1 line
Why would it fail?
To be quite honest, I don't know very much about the way CD writing works. I just assumed that delaying queue processing for a CD writer for several seconds would have very much the same effect as the input buffer of cdrecord getting empty prematurely. Do you mean to say that CD writing (or any other time expensive operation I haven't thought of) won't be affected irrecoverably by interrupted command processing?
Any modern cd/dvd writer can happily recover from buffer underruns. I think the physical shock itself has better chance of screwing up the recording. The only thing to make sure is that no command is issued to ATAPI devices. Other than that, there should be no problem.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Also, if there are two devices on the same
port that support the UNLOAD FEATURE and you issue a head unload request to both of them in close succession, the IDLE IMMEDIATE to the second device will be blocked until the timeout for the first has expired.Unload can be implemented as port-wide operation so that it issues IDLE IMMEDIATE to all drives on the port but given that this is mostly for laptop, this discussion is a bit peripheral.
We can't rule out that the HD is connected as master and CDRW as slave to the same controller in a PATA setup. I'm not familiar with the SATA configurations in modern laptops though.
On most, they occupy different channels and even when they reside on the same channel, it just doesn't really matter these days. And even on those cases, it would be better to use EH as that will make the IDLE IMMEDIATE command always win the bus as soon as possible while IDLE IMMEDIATE queued at the head of the drive queue could lose to an ATAPI command.
Thanks.
Signature · 1 line
tejun