• Stefan Haberland's avatar
    s390/dasd: fix unusable device after safe offline processing · 2757fe1d
    Stefan Haberland authored
    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: default avatarStefan Haberland <sth@linux.vnet.ibm.com>
    Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
    2757fe1d
dasd_devmap.c 40.2 KB