• Gerd Bayer's avatar
    s390/pci: introduce lock to synchronize state of zpci_dev's · bcb5d6c7
    Gerd Bayer authored
    There's a number of tasks that need the state of a zpci device
    to be stable. Other tasks need to be synchronized as they change the state.
    
    State changes could be generated by the system as availability or error
    events, or be requested by the user through manipulations in sysfs.
    Some other actions accessible through sysfs - like device resets - need the
    state to be stable.
    
    Unsynchronized state handling could lead to unusable devices. This has
    been observed in cases of concurrent state changes through systemd udev
    rules and DPM boot control. Some breakage can be provoked by artificial
    tests, e.g. through repetitively injecting "recover" on a PCI function
    through sysfs while running a "hotplug remove/add" in a loop through a
    PCI slot's "power" attribute in sysfs. After a few iterations this could
    result in a kernel oops.
    
    So introduce a new mutex "state_lock" to guard the state property of the
    struct zpci_dev. Acquire this lock in all task that modify the state:
    
    - hotplug add and remove, through the PCI hotplug slot entry,
    - avaiability events, as reported by the platform,
    - error events, as reported by the platform,
    - during device resets, explicit through sysfs requests or
      implict through the common PCI layer.
    
    Break out an inner _do_recover() routine out of recover_store() to
    separte the necessary synchronizations from the actual manipulations of
    the zpci_dev required for the reset.
    
    With the following changes I was able to run the inject loops for hours
    without hitting an error.
    Signed-off-by: default avatarGerd Bayer <gbayer@linux.ibm.com>
    Reviewed-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
    Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
    bcb5d6c7
pci.h 8.11 KB