Skip to content

Commit

Permalink
[S390] dasd: fix race condition in resume code
Browse files Browse the repository at this point in the history
There is a race while re-reading the device characteristics. After
cleaning the memory area a cqr is build which reads the device
characteristics. This may take a rather long time and the device
characteristics structure is zero during this. Now it could be
possible that the block tasklet starts working and a new cqr will be
build. The build_cp command refers to the device characteristics
structure and this may lead into a divide by zero exception.
Fix this by re-reading the device characteristics into a temporary
structur and copy the data to the original structure. Also take the
ccwdev_lock.

Signed-off-by: Stefan Haberland <stefan.haberland@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
stefan-haberland authored and Martin Schwidefsky committed Oct 6, 2009
1 parent af9d2ff commit 6fca97a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions drivers/s390/block/dasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2508,8 +2508,6 @@ int dasd_generic_restore_device(struct ccw_device *cdev)
device->stopped &= ~DASD_UNRESUMED_PM;

dasd_schedule_device_bh(device);
if (device->block)
dasd_schedule_block_bh(device->block);

if (device->discipline->restore)
rc = device->discipline->restore(device);
Expand All @@ -2520,6 +2518,9 @@ int dasd_generic_restore_device(struct ccw_device *cdev)
*/
device->stopped |= DASD_UNRESUMED_PM;

if (device->block)
dasd_schedule_block_bh(device->block);

dasd_put_device(device);
return 0;
}
Expand Down
9 changes: 7 additions & 2 deletions drivers/s390/block/dasd_eckd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,8 @@ static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
/* Calculate number of blocks/records per track. */
blksize = block->bp_block;
blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
if (blk_per_trk == 0)
return ERR_PTR(-EINVAL);
/* Calculate record id of first and last block. */
first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
first_offs = sector_div(first_trk, blk_per_trk);
Expand Down Expand Up @@ -3211,6 +3213,7 @@ int dasd_eckd_pm_freeze(struct dasd_device *device)
int dasd_eckd_restore_device(struct dasd_device *device)
{
struct dasd_eckd_private *private;
struct dasd_eckd_characteristics temp_rdc_data;
int is_known, rc;
struct dasd_uid temp_uid;

Expand Down Expand Up @@ -3245,15 +3248,17 @@ int dasd_eckd_restore_device(struct dasd_device *device)
dasd_eckd_read_features(device);

/* Read Device Characteristics */
memset(&private->rdc_data, 0, sizeof(private->rdc_data));
rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
&private->rdc_data, 64);
&temp_rdc_data, 64);
if (rc) {
DBF_EVENT(DBF_WARNING,
"Read device characteristics failed, rc=%d for "
"device: %s", rc, dev_name(&device->cdev->dev));
goto out_err;
}
spin_lock(get_ccwdev_lock(device->cdev));
memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
spin_unlock(get_ccwdev_lock(device->cdev));

/* add device to alias management */
dasd_alias_add_device(device);
Expand Down

0 comments on commit 6fca97a

Please sign in to comment.