History

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).

Andrea Parri committed 7 years ago

Commit bedc61a1 parent a99d8083 files · +19 −38Browse files

Unified · Split

3 files
  1. drivers/hv/connection.c +18 −32
  2. drivers/hv/vmbus_drv.c +1 −2
  3. include/linux/hyperv.h +0 −4
drivers/hv/connection.c+18−32
@@ -40,29 +40,17 @@ EXPORT_SYMBOL_GPL(vmbus_connection); · 39 unmodified lines
40__u32 vmbus_proto_version;40__u32 vmbus_proto_version;
41EXPORT_SYMBOL_GPL(vmbus_proto_version);41EXPORT_SYMBOL_GPL(vmbus_proto_version);
42 42
43static __u32 vmbus_get_next_version(__u32 current_version)43/*
44{44 * Table of VMBus versions listed from newest to oldest.
45 switch (current_version) {45 */
46 case (VERSION_WIN7):46static __u32 vmbus_versions[] = {
47 return VERSION_WS2008;47 VERSION_WIN10_V5,
48 48 VERSION_WIN10,
49 case (VERSION_WIN8):49 VERSION_WIN8_1,
50 return VERSION_WIN7;50 VERSION_WIN8,
51 51 VERSION_WIN7,
52 case (VERSION_WIN8_1):52 VERSION_WS2008
53 return VERSION_WIN8;53};
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}
66 54
67int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)55int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
68{56{
@@ -169,8 +157,8 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) · 100 unmodified lines
169 */157 */
170int vmbus_connect(void)158int vmbus_connect(void)
171{159{
172 int ret = 0;
173 struct vmbus_channel_msginfo *msginfo = NULL;160 struct vmbus_channel_msginfo *msginfo = NULL;
161 int i, ret = 0;
174 __u32 version;162 __u32 version;
175 163
176 /* Initialize the vmbus connection */164 /* Initialize the vmbus connection */
@@ -244,21 +232,19 @@ int vmbus_connect(void) · 67 unmodified lines
244 * version.232 * version.
245 */233 */
246 234
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];
248 240
249 do {
250 ret = vmbus_negotiate_version(msginfo, version);241 ret = vmbus_negotiate_version(msginfo, version);
251 if (ret == -ETIMEDOUT)242 if (ret == -ETIMEDOUT)
252 goto cleanup;243 goto cleanup;
253 244
254 if (vmbus_connection.conn_state == CONNECTED)245 if (vmbus_connection.conn_state == CONNECTED)
255 break;246 break;
256 247 }
257 version = vmbus_get_next_version(version);
258 } while (version != VERSION_INVAL);
259
260 if (version == VERSION_INVAL)
261 goto cleanup;
262 248
263 vmbus_proto_version = version;249 vmbus_proto_version = version;
264 pr_info("Vmbus version:%d.%d\n",250 pr_info("Vmbus version:%d.%d\n",
drivers/hv/vmbus_drv.c+1−2
@@ -2220,8 +2220,7 @@ static int vmbus_bus_resume(struct device *dev) · 2219 unmodified lines
2220 * We only use the 'vmbus_proto_version', which was in use before2220 * We only use the 'vmbus_proto_version', which was in use before
2221 * hibernation, to re-negotiate with the host.2221 * hibernation, to re-negotiate with the host.
2222 */2222 */
2223 if (vmbus_proto_version == VERSION_INVAL ||2223 if (!vmbus_proto_version) {
2224 vmbus_proto_version == 0) {
2225 pr_err("Invalid proto version = 0x%x\n", vmbus_proto_version);2224 pr_err("Invalid proto version = 0x%x\n", vmbus_proto_version);
2226 return -EINVAL;2225 return -EINVAL;
2227 }2226 }
include/linux/hyperv.h+0−4
@@ -192,10 +192,6 @@ static inline u32 hv_get_avail_to_write_percent( · 191 unmodified lines
192#define VERSION_WIN10 ((4 << 16) | (0))192#define VERSION_WIN10 ((4 << 16) | (0))
193#define VERSION_WIN10_V5 ((5 << 16) | (0))193#define VERSION_WIN10_V5 ((5 << 16) | (0))
194 194
195#define VERSION_INVAL -1
196
197#define VERSION_CURRENT VERSION_WIN10_V5
198
199/* Make maximum size of pipe payload of 16K */195/* Make maximum size of pipe payload of 16K */
200#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)196#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
201 197

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t