scsi_dh_emc: fix panic when handling multiple path failures
PATCH 1/1 scsi_dh_emc: fix panic when handling multiple path failures
From: Eddie Williams <[email protected]>
Do not sdev_printk() a scsi_device that was, or is being, deleted.
If multiple failures occur (e.g. FC switch with multiple paths fails), and both the active path and next path is failed in the process, the scsi_device associated with the next path can be accessed after it was deleted.
--- drivers/scsi/device_handler/scsi_dh_emc.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/scsi/device_handler/scsi_dh_emc.c +5 -3
@@ -537,14 +537,14 @@ static int clariion_activate(struct scsi_device *sdev, result =clariion_send_inquiry (sdev, csdev);if (result !=SCSI_DH_OK ) - goto done; + goto out;if (csdev->lun_state ==CLARIION_LUN_OWNED ) goto done; result =send_trespass_cmd (sdev, csdev);if (result !=SCSI_DH_OK ) - goto done; + goto out;sdev_printk (KERN_INFO , sdev,"%s: %s trespass command sent\n" ,CLARIION_NAME , csdev->flags&CLARIION_SHORT_TRESPASS ?"short" :"long" );
@@ -552,7 +552,7 @@ static int clariion_activate(struct scsi_device *sdev,/* Update status */ result =clariion_send_inquiry (sdev, csdev);if (result !=SCSI_DH_OK ) - goto done; + goto out; done: sdev_printk(KERN_INFO, sdev,
@@ -561,10 +561,12 @@ done: csdev->port, lun_state[csdev->lun_state], csdev->default_sp + 'A'); +out:if (fn)fn (data, result);return 0 ; } +/* * params - parameters in the following format * "no_of_params\0param1\0param2\0param3\0...\0"
Signature · 1 line
1.7.3.4
Quoted 8 lines · Mike Snitzer
From: Eddie Williams <[email protected]>
Do not
sdev_printk()ascsi_devicethat was, or is being, deleted.If multiple failures occur (e.g. FC switch with multiple paths fails), and both the active path and next path is failed in the process, the
scsi_deviceassociated with the next path can be accessed after it was deleted.
This treats the symptom, not the cause, doesn't it? Why do we have a reference to an ungot instance of an sdev here ... and should it have had a reference taken on it?
James
Quoted 49 lines
Signed-off-by Eddie Williams <[email protected]>Signed-off-by Mike Snitzer <[email protected]>--- drivers/scsi/device_handler/scsi_dh_emc.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)drivers/scsi/device_handler/scsi_dh_emc.c +5
-3@@ -537,14 +537,14 @@ static int clariion_activate(struct scsi_device *sdev, result =clariion_send_inquiry (sdev, csdev);if (result !=SCSI_DH_OK ) - goto done; + goto out;if (csdev->lun_state ==CLARIION_LUN_OWNED ) goto done; result =send_trespass_cmd (sdev, csdev);if (result !=SCSI_DH_OK ) - goto done; + goto out;sdev_printk (KERN_INFO , sdev,"%s: %s trespass command sent\n" ,CLARIION_NAME , csdev->flags&CLARIION_SHORT_TRESPASS ?"short" :"long" );@@ -552,7 +552,7 @@ static int clariion_activate(struct scsi_device *sdev,/* Update status */ result =clariion_send_inquiry (sdev, csdev);if (result !=SCSI_DH_OK ) - goto done; + goto out; done: sdev_printk(KERN_INFO, sdev,@@ -561,10 +561,12 @@ done: csdev->port, lun_state[csdev->lun_state], csdev->default_sp + 'A'); +out:if (fn)fn (data, result);return 0 ; } +/* * params - parameters in the following format * "no_of_params\0param1\0param2\0param3\0...\0"
Quoted 5 lines · James Bottomley
Quoted 4 lines · Mike Snitzer
From: Eddie Williams <[email protected]>
Do not
sdev_printk()ascsi_devicethat was, or is being, deleted.
Quoted 8 lines
Quoted 4 lines
If multiple failures occur (e.g. FC switch with multiple paths fails), and both the active path and next path is failed in the process, the
scsi_deviceassociated with the next path can be accessed after it was deleted.This treats the symptom, not the cause, doesn't it? Why do we have a reference to an ungot instance of an sdev here ... and should it have had a reference taken on it?
Stands to reason, and to be fair Eddie thought that might be the case too -- I should have shared as much. I'll take a closer look (quite busy this week but...).
Finding the root cause in the near-term would be ideal. Short of that this "fix" isn't unreasonable. Only problem with taking it would be if someone like me didn't know to actively chase the real problem with this "fix" reverted. Whereby papering over the real issue.
Anyway, it's now on my plate to sort out. No idea if I'll do so by the close of the merge window. But maybe a real fix to this can go in after the window closes?
I guess time will tell, thanks.
Mike
Quoted 3 lines · Mike Snitzer
Anyway, it's now on my plate to sort out. No idea if I'll do so by the close of the merge window. But maybe a real fix to this can go in after the window closes?
It's a bug fix: of course it can.
James
Quoted 6 lines · James Bottomley
Quoted 3 lines · Mike Snitzer
Anyway, it's now on my plate to sort out. No idea if I'll do so by the close of the merge window. But maybe a real fix to this can go in after the window closes?
It's a bug fix: of course it can.
Right, so given scsi_dh_activate()'s {get,put}_device() that wraps the call to scsi_dh->activate (aka clariion_activate) I'm not seeing how accessing sdev->sdev_gendev (via sdev_printk) could result in a panic. So I'll need to dig deeper (hopefully with Eddie's assistance)...
But now that I look it at scsi_dh_activate's 'err' path, it would appear that we don't drop the reference (put_device) before returning 'err'. I unfotunately had a role in the offending change (commit: db422318) getting upstream. /me ducks
Looks to me like we need this:
From: Mike Snitzer <[email protected]>
Subject: [SCSI] scsi_dh: fix reference counting in scsi_dh_activate error path
Commit db422318cbca55168cf965f655471dbf8be82433 ([SCSI] scsi_dh:
propagate SCSI device deletion) introduced a regression where the device reference is not dropped prior to scsi_dh_activate's early return from the error path.
--- drivers/scsi/device_handler/scsi_dh.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +6 -3
@@ -394,12 +394,14 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)unsigned long flags;struct scsi_device *sdev;struct scsi_device_handler *scsi_dh =NULL ; +struct device *dev =NULL ;spin_lock_irqsave (q->queue_lock, flags); sdev = q->queuedata;if (sdev && sdev->scsi_dh_data) scsi_dh = sdev->scsi_dh_data->scsi_dh; -if (!scsi_dh || !get_device (&sdev->sdev_gendev) || + dev =get_device (&sdev->sdev_gendev); +if (!scsi_dh || !dev || sdev->sdev_state ==SDEV_CANCEL || sdev->sdev_state ==SDEV_DEL ) err =SCSI_DH_NOSYS ;
@@ -410,12 +412,13 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)if (err) {if (fn)fn (data, err); -return err; + goto out; }if (scsi_dh->activate) err = scsi_dh->activate (sdev, fn, data); -put_device (&sdev->sdev_gendev); +out: +put_device (dev);return err; }EXPORT_SYMBOL_GPL (scsi_dh_activate);
A message that is not in the archive (sent off-list or not yet received): [email protected]
oops, blasted google mail converted it to html...
Quoted 71 lines · Eddie Williams
OK, I will give it a test in the morning...
EddieQuoted 66 lines · Mike Snitzer
Quoted 6 lines · James Bottomley
Quoted 3 lines · Mike Snitzer
Anyway, it's now on my plate to sort out. No idea if I'll do so by the close of the merge window. But maybe a real fix to this can go in after the window closes?
It's a bug fix: of course it can.
Right, so given scsi_dh_activate()'s {get,put}_device() that wraps the call to
scsi_dh->activate(akaclariion_activate) I'm not seeing how accessingsdev->sdev_gendev(viasdev_printk) could result in a panic. So I'll need to dig deeper (hopefully with Eddie's assistance)...But now that I look it at scsi_dh_activate's 'err' path, it would appear that we don't drop the reference (
put_device) before returning 'err'. I unfotunately had a role in the offending change (commit:db422318) getting upstream. /me ducksLooks to me like we need this:
From: Mike Snitzer <[email protected]>
Subject: [SCSI]scsi_dh: fix reference counting inscsi_dh_activateerror pathCommit
db422318cbca55168cf965f655471dbf8be82433([SCSI]scsi_dh:
propagate SCSI device deletion) introduced a regression where the device reference is not dropped prior to scsi_dh_activate's early return from the error path.Signed-off-by Mike Snitzer <[email protected]>---
drivers/scsi/device_handler/scsi_dh.c | 9 ++++++---1 files changed, 6 insertions(+), 3 deletions(-)drivers/scsi/device_handler/scsi_dh.c +3
-1@@ -394,12 +394,14 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data) unsigned long flags; struct scsi_device *sdev; struct scsi_device_handler *scsi_dh = NULL; + struct device *dev = NULL; spin_lock_irqsave(q->queue_lock, flags); sdev = q->queuedata; if (sdev && sdev->scsi_dh_data) scsi_dh = sdev->scsi_dh_data->scsi_dh; - if (!scsi_dh || !get_device(&sdev->sdev_gendev) || + dev = get_device(&sdev->sdev_gendev); + if (!scsi_dh || !dev ||sdev->sdev_state ==
SDEV_CANCEL||
sdev->sdev_state ==SDEV_DEL)
err =SCSI_DH_NOSYS;drivers/scsi/device_handler/scsi_dh.c +1
-1@@ -410,12 +412,13 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data) if (err) { if (fn) fn(data, err); - return err; + goto out; }
Quoted 10 lines
drivers/scsi/device_handler/scsi_dh.c int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data) · line 424
Quoted 9 lines
drivers/scsi/device_handler/scsi_dh.c +2
-1if (scsi_dh->activate) err = scsi_dh->activate(sdev, fn, data); - put_device(&sdev->sdev_gendev); +out: + put_device(dev); return err; } EXPORT_SYMBOL_GPL(scsi_dh_activate);
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Mike Snitzer
Quoted 1 line
It's a bug fix: of course it can.
Right, so given scsi_dh_activate()'s {get,put}_device() that wraps the call to
scsi_dh->activate(akaclariion_activate) I'm not seeing how accessingsdev->sdev_gendev(viasdev_printk) could result in a panic. So I'll need to dig deeper (hopefully with Eddie's assistance)...
Hi James,
I checked with Eddie and the sdev_printk() panic he saw no longer occurs when commit db422318 is in place. But he also tested with the patch I provided below.
I still feel this fix is needed and would like to get your feedback on this (relative to 2.6.39):
Quoted 59 lines
But now that I look at scsi_dh_activate's 'err' path, it would appear that we don't drop the reference (
put_device) before returning 'err'. I unfotunately had a role in the offending change (commit:db422318) getting upstream. /me ducksLooks to me like we need this:
From: Mike Snitzer <[email protected]>
Subject: [SCSI]scsi_dh: fix reference counting inscsi_dh_activateerror pathCommit
db422318cbca55168cf965f655471dbf8be82433([SCSI]scsi_dh:
propagate SCSI device deletion) introduced a regression where the device reference is not dropped prior to scsi_dh_activate's early return from the error path.Signed-off-by Mike Snitzer <[email protected]>--- drivers/scsi/device_handler/scsi_dh.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)drivers/scsi/device_handler/scsi_dh.c +6
-3@@ -394,12 +394,14 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)unsigned long flags;struct scsi_device *sdev;struct scsi_device_handler *scsi_dh =NULL ; +struct device *dev =NULL ;spin_lock_irqsave (q->queue_lock, flags); sdev = q->queuedata;if (sdev && sdev->scsi_dh_data) scsi_dh = sdev->scsi_dh_data->scsi_dh; -if (!scsi_dh || !get_device (&sdev->sdev_gendev) || + dev =get_device (&sdev->sdev_gendev); +if (!scsi_dh || !dev || sdev->sdev_state ==SDEV_CANCEL || sdev->sdev_state ==SDEV_DEL ) err =SCSI_DH_NOSYS ;@@ -410,12 +412,13 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)if (err) {if (fn)fn (data, err); -return err; + goto out; }if (scsi_dh->activate) err = scsi_dh->activate (sdev, fn, data); -put_device (&sdev->sdev_gendev); +out: +put_device (dev);return err; }EXPORT_SYMBOL_GPL (scsi_dh_activate);
Quoted 10 lines · Mike Snitzer
Quoted 6 lines · Mike Snitzer
Quoted 1 line
It's a bug fix: of course it can.
Right, so given scsi_dh_activate()'s {get,put}_device() that wraps the call to
scsi_dh->activate(akaclariion_activate) I'm not seeing how accessingsdev->sdev_gendev(viasdev_printk) could result in a panic. So I'll need to dig deeper (hopefully with Eddie's assistance)...
Quoted 8 lines
Hi James,
I checked with Eddie and the
sdev_printk()panic he saw no longer occurs when commitdb422318is in place. But he also tested with the patch I provided below.I still feel this fix is needed and would like to get your feedback on this (relative to 2.6.39):
So what about the fix you propose in
Message-id: <[email protected]>
? That looks to be the correct one.
James
Quoted 17 lines · James Bottomley
Quoted 16 lines · Mike Snitzer
Quoted 6 lines · Mike Snitzer
Quoted 1 line
It's a bug fix: of course it can.
Right, so given scsi_dh_activate()'s {get,put}_device() that wraps the call to
scsi_dh->activate(akaclariion_activate) I'm not seeing how accessingsdev->sdev_gendev(viasdev_printk) could result in a panic. So I'll need to dig deeper (hopefully with Eddie's assistance)...Hi James,
I checked with Eddie and the
sdev_printk()panic he saw no longer occurs when commitdb422318is in place. But he also tested with the patch I provided below.
Quoted 8 lines
Quoted 2 lines
I still feel this fix is needed and would like to get your feedback on this (relative to 2.6.39):
So what about the fix you propose in
Message-id: <[email protected]>
? That looks to be the correct one.
Yes, that is the correct fix (that is the same patch I quoted in my mail preceeding this one).
We'd need it in 2.6.38.y too.
Thanks,
Mike