• Nagarajkumar Narayanan's avatar
    mpt2sas: setpci reset kernel oops fix · 6229b414
    Nagarajkumar Narayanan authored
    mpt2sas: setpci reset on nytro warpdrive card along with sysfs access and
    cli ioctl access resulted in kernel oops
    
    1. pci_access_mutex lock added to provide synchronization between IOCTL,
       sysfs, PCI resource handling path
    
    2. gioc_lock spinlock to protect list operations over multiple
    controllers
    
    >From c53a1cff4c07528b8b9ec7f6716e94950283e8f9 Mon Sep 17 00:00:00 2001
    From: Nagarajkumar Narayanan <nagarajkumar.narayanan@seagate.com>
    Date: Tue, 18 Aug 2015 11:58:13 +0530
    Subject: [PATCH] mpt2sas setpci reset oops fix
    
    In mpt2sas driver due to lack of synchronization between ioctl,
    BRM status access through sysfs, pci resource removal kernel oops
    happen as ioctl path and BRM status sysfs access path still tries
    to access the removed resources
    
    Two locks added to provide syncrhonization
    
    1. pci_access_mutex: Mutex to synchronize ioctl,sysfs show path and
    pci resource handling. PCI resource freeing will lead to free
    vital hardware/memory resource, which might be in use by cli/sysfs
    path functions resulting in Null pointer reference followed by kernel
    crash. To avoid the above race condition we use mutex syncrhonization
    which ensures the syncrhonization between cli/sysfs_show path
    
    Note: pci_access_mutex is used only if nytro warpdrive cards
    (ioc->is_warpdrive based on device id) are used
    as we could not test this case with other SAS2 HBA cards
    We can remove this check if this behaviour confirmed from other
    cards.
    
    2. spinlock on list operations over IOCs
    
    Case: when multiple warpdrive cards(IOCs) are in use
    Each IOC will added to the ioc list stucture on initialization.
    Watchdog threads run at regular intervals to check IOC for any
    fault conditions which will trigger the dead_ioc thread to
    deallocate pci resource, resulting deleting the IOC netry from list,
    this deletion need to protected by spinlock to enusre that
    ioc removal is syncrhonized, if not synchronized it might lead to
    list_del corruption as the ioc list is traversed in cli path
    Signed-off-by: default avatarNagarajkumar Narayanan <nagarajkumar.narayanan@seagate.com>
    Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
    Acked-by: default avatarSreekanth Reddy <sreekanth.reddy@avagotech.com>
    Signed-off-by: default avatarJames Bottomley <JBottomley@Odin.com>
    6229b414
mpt2sas_scsih.c 250 KB