Skip to content

Commit bedc61a

Browse files
andrea-parriSasha Levin
authored andcommitted
Drivers: hv: vmbus: Introduce table of VMBus protocol versions
The technique used to get the next VMBus version seems increasisly clumsy as the number of VMBus versions increases. Performance is not a concern since this is only done once during system boot; it's just that we'll end up with more lines of code than is really needed. As an alternative, introduce a table with the version numbers listed in order (from the most recent to the oldest). vmbus_connect() loops through the versions listed in the table until it gets an accepted connection or gets to the end of the table (invalid version). Suggested-by: Michael Kelley <[email protected]> Signed-off-by: Andrea Parri <[email protected]> Reviewed-by: Wei Liu <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a99d808 commit bedc61a

File tree

3 files changed

+19
-38
lines changed

3 files changed

+19
-38
lines changed

drivers/hv/connection.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,17 @@ EXPORT_SYMBOL_GPL(vmbus_connection);
4040
__u32 vmbus_proto_version;
4141
EXPORT_SYMBOL_GPL(vmbus_proto_version);
4242

43-
static __u32 vmbus_get_next_version(__u32 current_version)
44-
{
45-
switch (current_version) {
46-
case (VERSION_WIN7):
47-
return VERSION_WS2008;
48-
49-
case (VERSION_WIN8):
50-
return VERSION_WIN7;
51-
52-
case (VERSION_WIN8_1):
53-
return VERSION_WIN8;
54-
55-
case (VERSION_WIN10):
56-
return VERSION_WIN8_1;
57-
58-
case (VERSION_WIN10_V5):
59-
return VERSION_WIN10;
60-
61-
case (VERSION_WS2008):
62-
default:
63-
return VERSION_INVAL;
64-
}
65-
}
43+
/*
44+
* Table of VMBus versions listed from newest to oldest.
45+
*/
46+
static __u32 vmbus_versions[] = {
47+
VERSION_WIN10_V5,
48+
VERSION_WIN10,
49+
VERSION_WIN8_1,
50+
VERSION_WIN8,
51+
VERSION_WIN7,
52+
VERSION_WS2008
53+
};
6654

6755
int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
6856
{
@@ -169,8 +157,8 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
169157
*/
170158
int vmbus_connect(void)
171159
{
172-
int ret = 0;
173160
struct vmbus_channel_msginfo *msginfo = NULL;
161+
int i, ret = 0;
174162
__u32 version;
175163

176164
/* Initialize the vmbus connection */
@@ -244,21 +232,19 @@ int vmbus_connect(void)
244232
* version.
245233
*/
246234

247-
version = VERSION_CURRENT;
235+
for (i = 0; ; i++) {
236+
if (i == ARRAY_SIZE(vmbus_versions))
237+
goto cleanup;
238+
239+
version = vmbus_versions[i];
248240

249-
do {
250241
ret = vmbus_negotiate_version(msginfo, version);
251242
if (ret == -ETIMEDOUT)
252243
goto cleanup;
253244

254245
if (vmbus_connection.conn_state == CONNECTED)
255246
break;
256-
257-
version = vmbus_get_next_version(version);
258-
} while (version != VERSION_INVAL);
259-
260-
if (version == VERSION_INVAL)
261-
goto cleanup;
247+
}
262248

263249
vmbus_proto_version = version;
264250
pr_info("Vmbus version:%d.%d\n",

drivers/hv/vmbus_drv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,8 +2220,7 @@ static int vmbus_bus_resume(struct device *dev)
22202220
* We only use the 'vmbus_proto_version', which was in use before
22212221
* hibernation, to re-negotiate with the host.
22222222
*/
2223-
if (vmbus_proto_version == VERSION_INVAL ||
2224-
vmbus_proto_version == 0) {
2223+
if (!vmbus_proto_version) {
22252224
pr_err("Invalid proto version = 0x%x\n", vmbus_proto_version);
22262225
return -EINVAL;
22272226
}

include/linux/hyperv.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ static inline u32 hv_get_avail_to_write_percent(
192192
#define VERSION_WIN10 ((4 << 16) | (0))
193193
#define VERSION_WIN10_V5 ((5 << 16) | (0))
194194

195-
#define VERSION_INVAL -1
196-
197-
#define VERSION_CURRENT VERSION_WIN10_V5
198-
199195
/* Make maximum size of pipe payload of 16K */
200196
#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
201197

0 commit comments

Comments
 (0)