]> git.itanic.dy.fi Git - linux-stable/commit
s390/dasd: fix unusable device after safe offline processing
authorStefan Haberland <sth@linux.vnet.ibm.com>
Tue, 16 May 2017 08:30:13 +0000 (10:30 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 12 Jun 2017 14:26:01 +0000 (16:26 +0200)
commit2757fe1d8ebd0e6ab1dbf1105978b8c8369dcc49
tree581299b3b20bcea725808b7a30ed0138df0fb25d
parentb487a914f853545842a0899329b6b72fe56c4081
s390/dasd: fix unusable device after safe offline processing

The safe offline processing needs, as well as the normal offline
processing, to be locked against multiple parallel executions. But it
should be able to be overtaken by a normal offline processing to make sure
that the device does not wait forever for outstanding I/O if the user
wants to.

Unfortunately the parallel processing of safe offline and normal offline
might lead to a race situation where both threads report successful
execution to the CIO layer which in turn tries to deregister the kobject
of the device twice. This leads to a

refcount_t: underflow; use-after-free.

error and the device is not able to be set online again afterwards without
a reboot.

Correct the locking of the safe offline processing by doing the following:
- Use the cdev lock to secure all set and test operations to the
  device flags.
- Two safe offline processes are locked against each other using
  the DASD_FLAG_SAFE_OFFLINE and DASD_FLAG_SAFE_OFFLINE_RUNNING
  device flags.
  The differentiation between offline triggered and offline running
  is needed since the normal offline attribute is owned by CIO and
  we have to pass over control in between.
- The dasd_generic_set_offline process handles the offline
  processing. It is locked against parallel execution using the
  DASD_FLAG_OFFLINE.
- Only a running safe offline should be able to be overtaken by a
  single normal offline. This is ensured by clearing the
  DASD_FLAG_SAFE_OFFLINE_RUNNING flag when a normal offline
  overtakes. So this can only happen ones.
- The safe offline just aborts in this case doing nothing and
  the normal offline processing finishes as usual.

Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/block/dasd.c
drivers/s390/block/dasd_devmap.c