Skip to content

Commit 5e4304f

Browse files
effective-lightliuw
authored andcommitted
drivers/hv: introduce vmbus_channel_set_cpu()
The core functionality in target_cpu_store() is also needed in a subsequent patch for automatically changing the CPU when taking a CPU offline. As such, factor out the body of target_cpu_store() into new function vmbus_channel_set_cpu() that can also be used elsewhere. No functional change is intended. Cc: Boqun Feng <[email protected]> Cc: Michael Kelley <[email protected]> Cc: Wei Liu <[email protected]> Signed-off-by: Hamza Mahfooz <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Tested-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent 7c0db8a commit 5e4304f

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,16 +1611,16 @@ static ssize_t target_cpu_show(struct vmbus_channel *channel, char *buf)
16111611
{
16121612
return sprintf(buf, "%u\n", channel->target_cpu);
16131613
}
1614-
static ssize_t target_cpu_store(struct vmbus_channel *channel,
1615-
const char *buf, size_t count)
1614+
1615+
int vmbus_channel_set_cpu(struct vmbus_channel *channel, u32 target_cpu)
16161616
{
1617-
u32 target_cpu, origin_cpu;
1618-
ssize_t ret = count;
1617+
u32 origin_cpu;
1618+
int ret = 0;
16191619

1620-
if (vmbus_proto_version < VERSION_WIN10_V4_1)
1621-
return -EIO;
1620+
lockdep_assert_cpus_held();
1621+
lockdep_assert_held(&vmbus_connection.channel_mutex);
16221622

1623-
if (sscanf(buf, "%uu", &target_cpu) != 1)
1623+
if (vmbus_proto_version < VERSION_WIN10_V4_1)
16241624
return -EIO;
16251625

16261626
/* Validate target_cpu for the cpumask_test_cpu() operation below. */
@@ -1630,22 +1630,17 @@ static ssize_t target_cpu_store(struct vmbus_channel *channel,
16301630
if (!cpumask_test_cpu(target_cpu, housekeeping_cpumask(HK_TYPE_MANAGED_IRQ)))
16311631
return -EINVAL;
16321632

1633-
/* No CPUs should come up or down during this. */
1634-
cpus_read_lock();
1635-
1636-
if (!cpu_online(target_cpu)) {
1637-
cpus_read_unlock();
1633+
if (!cpu_online(target_cpu))
16381634
return -EINVAL;
1639-
}
16401635

16411636
/*
1642-
* Synchronizes target_cpu_store() and channel closure:
1637+
* Synchronizes vmbus_channel_set_cpu() and channel closure:
16431638
*
16441639
* { Initially: state = CHANNEL_OPENED }
16451640
*
16461641
* CPU1 CPU2
16471642
*
1648-
* [target_cpu_store()] [vmbus_disconnect_ring()]
1643+
* [vmbus_channel_set_cpu()] [vmbus_disconnect_ring()]
16491644
*
16501645
* LOCK channel_mutex LOCK channel_mutex
16511646
* LOAD r1 = state LOAD r2 = state
@@ -1660,25 +1655,24 @@ static ssize_t target_cpu_store(struct vmbus_channel *channel,
16601655
* Note. The host processes the channel messages "sequentially", in
16611656
* the order in which they are received on a per-partition basis.
16621657
*/
1663-
mutex_lock(&vmbus_connection.channel_mutex);
16641658

16651659
/*
16661660
* Hyper-V will ignore MODIFYCHANNEL messages for "non-open" channels;
16671661
* avoid sending the message and fail here for such channels.
16681662
*/
16691663
if (channel->state != CHANNEL_OPENED_STATE) {
16701664
ret = -EIO;
1671-
goto cpu_store_unlock;
1665+
goto end;
16721666
}
16731667

16741668
origin_cpu = channel->target_cpu;
16751669
if (target_cpu == origin_cpu)
1676-
goto cpu_store_unlock;
1670+
goto end;
16771671

16781672
if (vmbus_send_modifychannel(channel,
16791673
hv_cpu_number_to_vp_number(target_cpu))) {
16801674
ret = -EIO;
1681-
goto cpu_store_unlock;
1675+
goto end;
16821676
}
16831677

16841678
/*
@@ -1708,10 +1702,26 @@ static ssize_t target_cpu_store(struct vmbus_channel *channel,
17081702
origin_cpu, target_cpu);
17091703
}
17101704

1711-
cpu_store_unlock:
1705+
end:
1706+
return ret;
1707+
}
1708+
1709+
static ssize_t target_cpu_store(struct vmbus_channel *channel,
1710+
const char *buf, size_t count)
1711+
{
1712+
u32 target_cpu;
1713+
ssize_t ret;
1714+
1715+
if (sscanf(buf, "%uu", &target_cpu) != 1)
1716+
return -EIO;
1717+
1718+
cpus_read_lock();
1719+
mutex_lock(&vmbus_connection.channel_mutex);
1720+
ret = vmbus_channel_set_cpu(channel, target_cpu);
17121721
mutex_unlock(&vmbus_connection.channel_mutex);
17131722
cpus_read_unlock();
1714-
return ret;
1723+
1724+
return ret ?: count;
17151725
}
17161726
static VMBUS_CHAN_ATTR(cpu, 0644, target_cpu_show, target_cpu_store);
17171727

include/linux/hyperv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ int vmbus_send_tl_connect_request(const guid_t *shv_guest_servie_id,
16611661
const guid_t *shv_host_servie_id);
16621662
int vmbus_send_modifychannel(struct vmbus_channel *channel, u32 target_vp);
16631663
void vmbus_set_event(struct vmbus_channel *channel);
1664+
int vmbus_channel_set_cpu(struct vmbus_channel *channel, u32 target_cpu);
16641665

16651666
/* Get the start of the ring buffer. */
16661667
static inline void *

0 commit comments

Comments
 (0)