Skip to content

Commit 21d2052

Browse files
andrea-parriliuw
authored andcommitted
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) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Martin K. Petersen <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Wei Liu <[email protected]>
1 parent 8a99e50 commit 21d2052

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/scsi/storvsc_drv.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ struct storvsc_device {
462462
* Mask of CPUs bound to subchannels.
463463
*/
464464
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;
465470
/* Used for vsc/vsp channel reset process */
466471
struct storvsc_cmd_request init_request;
467472
struct storvsc_cmd_request reset_request;
@@ -639,7 +644,7 @@ static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old,
639644
return;
640645

641646
/* See storvsc_do_io() -> get_og_chn(). */
642-
spin_lock_irqsave(&device->channel->lock, flags);
647+
spin_lock_irqsave(&stor_device->lock, flags);
643648

644649
/*
645650
* Determines if the storvsc device has other channels assigned to
@@ -676,7 +681,7 @@ static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old,
676681
WRITE_ONCE(stor_device->stor_chns[new], channel);
677682
cpumask_set_cpu(new, &stor_device->alloced_cpus);
678683

679-
spin_unlock_irqrestore(&device->channel->lock, flags);
684+
spin_unlock_irqrestore(&stor_device->lock, flags);
680685
}
681686

682687
static void handle_sc_creation(struct vmbus_channel *new_sc)
@@ -1433,14 +1438,14 @@ static int storvsc_do_io(struct hv_device *device,
14331438
}
14341439
}
14351440
} else {
1436-
spin_lock_irqsave(&device->channel->lock, flags);
1441+
spin_lock_irqsave(&stor_device->lock, flags);
14371442
outgoing_channel = stor_device->stor_chns[q_num];
14381443
if (outgoing_channel != NULL) {
1439-
spin_unlock_irqrestore(&device->channel->lock, flags);
1444+
spin_unlock_irqrestore(&stor_device->lock, flags);
14401445
goto found_channel;
14411446
}
14421447
outgoing_channel = get_og_chn(stor_device, q_num);
1443-
spin_unlock_irqrestore(&device->channel->lock, flags);
1448+
spin_unlock_irqrestore(&stor_device->lock, flags);
14441449
}
14451450

14461451
found_channel:
@@ -1881,6 +1886,7 @@ static int storvsc_probe(struct hv_device *device,
18811886
init_waitqueue_head(&stor_device->waiting_to_drain);
18821887
stor_device->device = device;
18831888
stor_device->host = host;
1889+
spin_lock_init(&stor_device->lock);
18841890
hv_set_drvdata(device, stor_device);
18851891

18861892
stor_device->port_number = host->host_no;

0 commit comments

Comments
 (0)