Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: storvsc: Introduce the per-storvsc_device spinlock

storvsc uses the spinlock of the hv_device's primary channel to
serialize modifications of stor_chns[] performed by storvsc_do_io()
and storvsc_change_target_cpu(), when it could/should use a (per-)
storvsc_device spinlock: this change untangles the synchronization
mechanism for the (storvsc-specific) stor_chns[] array from the
"generic" VMBus code and data structures, clarifying the scope of
this synchronization mechanism.

Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Link: https://lore.kernel.org/r/20200617164642.37393-8-parri.andrea@gmail.com
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Andrea Parri (Microsoft) and committed by
Wei Liu
21d2052c 8a99e501

+11 -5
+11 -5
drivers/scsi/storvsc_drv.c
··· 462 462 * Mask of CPUs bound to subchannels. 463 463 */ 464 464 struct cpumask alloced_cpus; 465 + /* 466 + * Serializes modifications of stor_chns[] from storvsc_do_io() 467 + * and storvsc_change_target_cpu(). 468 + */ 469 + spinlock_t lock; 465 470 /* Used for vsc/vsp channel reset process */ 466 471 struct storvsc_cmd_request init_request; 467 472 struct storvsc_cmd_request reset_request; ··· 644 639 return; 645 640 646 641 /* See storvsc_do_io() -> get_og_chn(). */ 647 - spin_lock_irqsave(&device->channel->lock, flags); 642 + spin_lock_irqsave(&stor_device->lock, flags); 648 643 649 644 /* 650 645 * Determines if the storvsc device has other channels assigned to ··· 681 676 WRITE_ONCE(stor_device->stor_chns[new], channel); 682 677 cpumask_set_cpu(new, &stor_device->alloced_cpus); 683 678 684 - spin_unlock_irqrestore(&device->channel->lock, flags); 679 + spin_unlock_irqrestore(&stor_device->lock, flags); 685 680 } 686 681 687 682 static void handle_sc_creation(struct vmbus_channel *new_sc) ··· 1438 1433 } 1439 1434 } 1440 1435 } else { 1441 - spin_lock_irqsave(&device->channel->lock, flags); 1436 + spin_lock_irqsave(&stor_device->lock, flags); 1442 1437 outgoing_channel = stor_device->stor_chns[q_num]; 1443 1438 if (outgoing_channel != NULL) { 1444 - spin_unlock_irqrestore(&device->channel->lock, flags); 1439 + spin_unlock_irqrestore(&stor_device->lock, flags); 1445 1440 goto found_channel; 1446 1441 } 1447 1442 outgoing_channel = get_og_chn(stor_device, q_num); 1448 - spin_unlock_irqrestore(&device->channel->lock, flags); 1443 + spin_unlock_irqrestore(&stor_device->lock, flags); 1449 1444 } 1450 1445 1451 1446 found_channel: ··· 1886 1881 init_waitqueue_head(&stor_device->waiting_to_drain); 1887 1882 stor_device->device = device; 1888 1883 stor_device->host = host; 1884 + spin_lock_init(&stor_device->lock); 1889 1885 hv_set_drvdata(device, stor_device); 1890 1886 1891 1887 stor_device->port_number = host->host_no;