• Oleg Nesterov's avatar
    md/raid5: Fix CPU hotplug callback registration · 4d4ef86d
    Oleg Nesterov authored
    commit 789b5e0315284463617e106baad360cb9e8db3ac upstream.
    
    Subsystems that want to register CPU hotplug callbacks, as well as perform
    initialization for the CPUs that are already online, often do it as shown
    below:
    
    	get_online_cpus();
    
    	for_each_online_cpu(cpu)
    		init_cpu(cpu);
    
    	register_cpu_notifier(&foobar_cpu_notifier);
    
    	put_online_cpus();
    
    This is wrong, since it is prone to ABBA deadlocks involving the
    cpu_add_remove_lock and the cpu_hotplug.lock (when running concurrently
    with CPU hotplug operations).
    
    Interestingly, the raid5 code can actually prevent double initialization and
    hence can use the following simplified form of callback registration:
    
    	register_cpu_notifier(&foobar_cpu_notifier);
    
    	get_online_cpus();
    
    	for_each_online_cpu(cpu)
    		init_cpu(cpu);
    
    	put_online_cpus();
    
    A hotplug operation that occurs between registering the notifier and calling
    get_online_cpus(), won't disrupt anything, because the code takes care to
    perform the memory allocations only once.
    
    So reorganize the code in raid5 this way to fix the deadlock with callback
    registration.
    
    Cc: linux-raid@vger.kernel.org
    Fixes: 36d1c647Signed-off-by: 's avatarOleg Nesterov <oleg@redhat.com>
    [Srivatsa: Fixed the unregister_cpu_notifier() deadlock, added the
    free_scratch_buffer() helper to condense code further and wrote the changelog.]
    Signed-off-by: 's avatarSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
    Signed-off-by: 's avatarNeilBrown <neilb@suse.de>
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    4d4ef86d
Name
Last commit
Last update
..
bcache Loading commit data...
persistent-data Loading commit data...
Kconfig Loading commit data...
Makefile Loading commit data...
bitmap.c Loading commit data...
bitmap.h Loading commit data...
dm-bio-prison.c Loading commit data...
dm-bio-prison.h Loading commit data...
dm-bio-record.h Loading commit data...
dm-bufio.c Loading commit data...
dm-bufio.h Loading commit data...
dm-builtin.c Loading commit data...
dm-cache-block-types.h Loading commit data...
dm-cache-metadata.c Loading commit data...
dm-cache-metadata.h Loading commit data...
dm-cache-policy-cleaner.c Loading commit data...
dm-cache-policy-internal.h Loading commit data...
dm-cache-policy-mq.c Loading commit data...
dm-cache-policy.c Loading commit data...
dm-cache-policy.h Loading commit data...
dm-cache-target.c Loading commit data...
dm-crypt.c Loading commit data...
dm-delay.c Loading commit data...
dm-exception-store.c Loading commit data...
dm-exception-store.h Loading commit data...
dm-flakey.c Loading commit data...
dm-io.c Loading commit data...
dm-ioctl.c Loading commit data...
dm-kcopyd.c Loading commit data...
dm-linear.c Loading commit data...
dm-log-userspace-base.c Loading commit data...
dm-log-userspace-transfer.c Loading commit data...
dm-log-userspace-transfer.h Loading commit data...
dm-log.c Loading commit data...
dm-mpath.c Loading commit data...
dm-mpath.h Loading commit data...
dm-path-selector.c Loading commit data...
dm-path-selector.h Loading commit data...
dm-queue-length.c Loading commit data...
dm-raid.c Loading commit data...
dm-raid1.c Loading commit data...
dm-region-hash.c Loading commit data...
dm-round-robin.c Loading commit data...
dm-service-time.c Loading commit data...
dm-snap-persistent.c Loading commit data...
dm-snap-transient.c Loading commit data...
dm-snap.c Loading commit data...
dm-stripe.c Loading commit data...
dm-sysfs.c Loading commit data...
dm-table.c Loading commit data...
dm-target.c Loading commit data...
dm-thin-metadata.c Loading commit data...
dm-thin-metadata.h Loading commit data...
dm-thin.c Loading commit data...
dm-uevent.c Loading commit data...
dm-uevent.h Loading commit data...
dm-verity.c Loading commit data...
dm-zero.c Loading commit data...
dm.c Loading commit data...
dm.h Loading commit data...
faulty.c Loading commit data...
linear.c Loading commit data...
linear.h Loading commit data...
md.c Loading commit data...
md.h Loading commit data...
multipath.c Loading commit data...
multipath.h Loading commit data...
raid0.c Loading commit data...
raid0.h Loading commit data...
raid1.c Loading commit data...
raid1.h Loading commit data...
raid10.c Loading commit data...
raid10.h Loading commit data...
raid5.c Loading commit data...
raid5.h Loading commit data...