Skip to content

Commit 3eb0ac8

Browse files
andrea-parriliuw
authored andcommitted
Drivers: hv: vmbus: Use channel_mutex in channel_vp_mapping_show()
The primitive currently uses channel->lock to protect the loop over sc_list w.r.t. list additions/deletions but it doesn't protect the target_cpu(s) loads w.r.t. a concurrent target_cpu_store(): while the data races on target_cpu are hardly of any concern here, replace the channel->lock critical section with a channel_mutex critical section and extend the latter to include the loads of target_cpu; this same pattern is also used in hv_synic_cleanup(). Signed-off-by: Andrea Parri (Microsoft) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Wei Liu <[email protected]>
1 parent 12d0dd8 commit 3eb0ac8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,17 @@ static ssize_t channel_vp_mapping_show(struct device *dev,
507507
{
508508
struct hv_device *hv_dev = device_to_hv_device(dev);
509509
struct vmbus_channel *channel = hv_dev->channel, *cur_sc;
510-
unsigned long flags;
511510
int buf_size = PAGE_SIZE, n_written, tot_written;
512511
struct list_head *cur;
513512

514513
if (!channel)
515514
return -ENODEV;
516515

516+
mutex_lock(&vmbus_connection.channel_mutex);
517+
517518
tot_written = snprintf(buf, buf_size, "%u:%u\n",
518519
channel->offermsg.child_relid, channel->target_cpu);
519520

520-
spin_lock_irqsave(&channel->lock, flags);
521-
522521
list_for_each(cur, &channel->sc_list) {
523522
if (tot_written >= buf_size - 1)
524523
break;
@@ -532,7 +531,7 @@ static ssize_t channel_vp_mapping_show(struct device *dev,
532531
tot_written += n_written;
533532
}
534533

535-
spin_unlock_irqrestore(&channel->lock, flags);
534+
mutex_unlock(&vmbus_connection.channel_mutex);
536535

537536
return tot_written;
538537
}

0 commit comments

Comments
 (0)