xref: /linux-6.15/include/uapi/linux/hyperv.h (revision cd8dc054)
1 /*
2  *
3  * Copyright (c) 2011, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <[email protected]>
20  *   Hank Janssen  <[email protected]>
21  *   K. Y. Srinivasan <[email protected]>
22  *
23  */
24 
25 #ifndef _UAPI_HYPERV_H
26 #define _UAPI_HYPERV_H
27 
28 #include <linux/uuid.h>
29 
30 /*
31  * Framework version for util services.
32  */
33 #define UTIL_FW_MINOR  0
34 
35 #define UTIL_WS2K8_FW_MAJOR  1
36 #define UTIL_WS2K8_FW_VERSION     (UTIL_WS2K8_FW_MAJOR << 16 | UTIL_FW_MINOR)
37 
38 #define UTIL_FW_MAJOR  3
39 #define UTIL_FW_VERSION     (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
40 
41 
42 /*
43  * Implementation of host controlled snapshot of the guest.
44  */
45 
46 #define VSS_OP_REGISTER 128
47 
48 /*
49   Daemon code with full handshake support.
50  */
51 #define VSS_OP_REGISTER1 129
52 
53 enum hv_vss_op {
54 	VSS_OP_CREATE = 0,
55 	VSS_OP_DELETE,
56 	VSS_OP_HOT_BACKUP,
57 	VSS_OP_GET_DM_INFO,
58 	VSS_OP_BU_COMPLETE,
59 	/*
60 	 * Following operations are only supported with IC version >= 5.0
61 	 */
62 	VSS_OP_FREEZE, /* Freeze the file systems in the VM */
63 	VSS_OP_THAW, /* Unfreeze the file systems */
64 	VSS_OP_AUTO_RECOVER,
65 	VSS_OP_COUNT /* Number of operations, must be last */
66 };
67 
68 
69 /*
70  * Header for all VSS messages.
71  */
72 struct hv_vss_hdr {
73 	__u8 operation;
74 	__u8 reserved[7];
75 } __attribute__((packed));
76 
77 
78 /*
79  * Flag values for the hv_vss_check_feature. Linux supports only
80  * one value.
81  */
82 #define VSS_HBU_NO_AUTO_RECOVERY	0x00000005
83 
84 struct hv_vss_check_feature {
85 	__u32 flags;
86 } __attribute__((packed));
87 
88 struct hv_vss_check_dm_info {
89 	__u32 flags;
90 } __attribute__((packed));
91 
92 struct hv_vss_msg {
93 	union {
94 		struct hv_vss_hdr vss_hdr;
95 		int error;
96 	};
97 	union {
98 		struct hv_vss_check_feature vss_cf;
99 		struct hv_vss_check_dm_info dm_info;
100 	};
101 } __attribute__((packed));
102 
103 /*
104  * Implementation of a host to guest copy facility.
105  */
106 
107 #define FCOPY_VERSION_0 0
108 #define FCOPY_CURRENT_VERSION FCOPY_VERSION_0
109 #define W_MAX_PATH 260
110 
111 enum hv_fcopy_op {
112 	START_FILE_COPY = 0,
113 	WRITE_TO_FILE,
114 	COMPLETE_FCOPY,
115 	CANCEL_FCOPY,
116 };
117 
118 struct hv_fcopy_hdr {
119 	__u32 operation;
120 	uuid_le service_id0; /* currently unused */
121 	uuid_le service_id1; /* currently unused */
122 } __attribute__((packed));
123 
124 #define OVER_WRITE	0x1
125 #define CREATE_PATH	0x2
126 
127 struct hv_start_fcopy {
128 	struct hv_fcopy_hdr hdr;
129 	__u16 file_name[W_MAX_PATH];
130 	__u16 path_name[W_MAX_PATH];
131 	__u32 copy_flags;
132 	__u64 file_size;
133 } __attribute__((packed));
134 
135 /*
136  * The file is chunked into fragments.
137  */
138 #define DATA_FRAGMENT	(6 * 1024)
139 
140 struct hv_do_fcopy {
141 	struct hv_fcopy_hdr hdr;
142 	__u32   pad;
143 	__u64	offset;
144 	__u32	size;
145 	__u8	data[DATA_FRAGMENT];
146 } __attribute__((packed));
147 
148 /*
149  * An implementation of HyperV key value pair (KVP) functionality for Linux.
150  *
151  *
152  * Copyright (C) 2010, Novell, Inc.
153  * Author : K. Y. Srinivasan <[email protected]>
154  *
155  */
156 
157 /*
158  * Maximum value size - used for both key names and value data, and includes
159  * any applicable NULL terminators.
160  *
161  * Note:  This limit is somewhat arbitrary, but falls easily within what is
162  * supported for all native guests (back to Win 2000) and what is reasonable
163  * for the IC KVP exchange functionality.  Note that Windows Me/98/95 are
164  * limited to 255 character key names.
165  *
166  * MSDN recommends not storing data values larger than 2048 bytes in the
167  * registry.
168  *
169  * Note:  This value is used in defining the KVP exchange message - this value
170  * cannot be modified without affecting the message size and compatibility.
171  */
172 
173 /*
174  * bytes, including any null terminators
175  */
176 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE          (2048)
177 
178 
179 /*
180  * Maximum key size - the registry limit for the length of an entry name
181  * is 256 characters, including the null terminator
182  */
183 
184 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE            (512)
185 
186 /*
187  * In Linux, we implement the KVP functionality in two components:
188  * 1) The kernel component which is packaged as part of the hv_utils driver
189  * is responsible for communicating with the host and responsible for
190  * implementing the host/guest protocol. 2) A user level daemon that is
191  * responsible for data gathering.
192  *
193  * Host/Guest Protocol: The host iterates over an index and expects the guest
194  * to assign a key name to the index and also return the value corresponding to
195  * the key. The host will have atmost one KVP transaction outstanding at any
196  * given point in time. The host side iteration stops when the guest returns
197  * an error. Microsoft has specified the following mapping of key names to
198  * host specified index:
199  *
200  *	Index		Key Name
201  *	0		FullyQualifiedDomainName
202  *	1		IntegrationServicesVersion
203  *	2		NetworkAddressIPv4
204  *	3		NetworkAddressIPv6
205  *	4		OSBuildNumber
206  *	5		OSName
207  *	6		OSMajorVersion
208  *	7		OSMinorVersion
209  *	8		OSVersion
210  *	9		ProcessorArchitecture
211  *
212  * The Windows host expects the Key Name and Key Value to be encoded in utf16.
213  *
214  * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
215  * data gathering functionality in a user mode daemon. The user level daemon
216  * is also responsible for binding the key name to the index as well. The
217  * kernel and user-level daemon communicate using a connector channel.
218  *
219  * The user mode component first registers with the
220  * the kernel component. Subsequently, the kernel component requests, data
221  * for the specified keys. In response to this message the user mode component
222  * fills in the value corresponding to the specified key. We overload the
223  * sequence field in the cn_msg header to define our KVP message types.
224  *
225  *
226  * The kernel component simply acts as a conduit for communication between the
227  * Windows host and the user-level daemon. The kernel component passes up the
228  * index received from the Host to the user-level daemon. If the index is
229  * valid (supported), the corresponding key as well as its
230  * value (both are strings) is returned. If the index is invalid
231  * (not supported), a NULL key string is returned.
232  */
233 
234 
235 /*
236  * Registry value types.
237  */
238 
239 #define REG_SZ 1
240 #define REG_U32 4
241 #define REG_U64 8
242 
243 /*
244  * As we look at expanding the KVP functionality to include
245  * IP injection functionality, we need to maintain binary
246  * compatibility with older daemons.
247  *
248  * The KVP opcodes are defined by the host and it was unfortunate
249  * that I chose to treat the registration operation as part of the
250  * KVP operations defined by the host.
251  * Here is the level of compatibility
252  * (between the user level daemon and the kernel KVP driver) that we
253  * will implement:
254  *
255  * An older daemon will always be supported on a newer driver.
256  * A given user level daemon will require a minimal version of the
257  * kernel driver.
258  * If we cannot handle the version differences, we will fail gracefully
259  * (this can happen when we have a user level daemon that is more
260  * advanced than the KVP driver.
261  *
262  * We will use values used in this handshake for determining if we have
263  * workable user level daemon and the kernel driver. We begin by taking the
264  * registration opcode out of the KVP opcode namespace. We will however,
265  * maintain compatibility with the existing user-level daemon code.
266  */
267 
268 /*
269  * Daemon code not supporting IP injection (legacy daemon).
270  */
271 
272 #define KVP_OP_REGISTER	4
273 
274 /*
275  * Daemon code supporting IP injection.
276  * The KVP opcode field is used to communicate the
277  * registration information; so define a namespace that
278  * will be distinct from the host defined KVP opcode.
279  */
280 
281 #define KVP_OP_REGISTER1 100
282 
283 enum hv_kvp_exchg_op {
284 	KVP_OP_GET = 0,
285 	KVP_OP_SET,
286 	KVP_OP_DELETE,
287 	KVP_OP_ENUMERATE,
288 	KVP_OP_GET_IP_INFO,
289 	KVP_OP_SET_IP_INFO,
290 	KVP_OP_COUNT /* Number of operations, must be last. */
291 };
292 
293 enum hv_kvp_exchg_pool {
294 	KVP_POOL_EXTERNAL = 0,
295 	KVP_POOL_GUEST,
296 	KVP_POOL_AUTO,
297 	KVP_POOL_AUTO_EXTERNAL,
298 	KVP_POOL_AUTO_INTERNAL,
299 	KVP_POOL_COUNT /* Number of pools, must be last. */
300 };
301 
302 /*
303  * Some Hyper-V status codes.
304  */
305 
306 #define HV_S_OK				0x00000000
307 #define HV_E_FAIL			0x80004005
308 #define HV_S_CONT			0x80070103
309 #define HV_ERROR_NOT_SUPPORTED		0x80070032
310 #define HV_ERROR_MACHINE_LOCKED		0x800704F7
311 #define HV_ERROR_DEVICE_NOT_CONNECTED	0x8007048F
312 #define HV_INVALIDARG			0x80070057
313 #define HV_GUID_NOTFOUND		0x80041002
314 #define HV_ERROR_ALREADY_EXISTS		0x80070050
315 
316 #define ADDR_FAMILY_NONE	0x00
317 #define ADDR_FAMILY_IPV4	0x01
318 #define ADDR_FAMILY_IPV6	0x02
319 
320 #define MAX_ADAPTER_ID_SIZE	128
321 #define MAX_IP_ADDR_SIZE	1024
322 #define MAX_GATEWAY_SIZE	512
323 
324 
325 struct hv_kvp_ipaddr_value {
326 	__u16	adapter_id[MAX_ADAPTER_ID_SIZE];
327 	__u8	addr_family;
328 	__u8	dhcp_enabled;
329 	__u16	ip_addr[MAX_IP_ADDR_SIZE];
330 	__u16	sub_net[MAX_IP_ADDR_SIZE];
331 	__u16	gate_way[MAX_GATEWAY_SIZE];
332 	__u16	dns_addr[MAX_IP_ADDR_SIZE];
333 } __attribute__((packed));
334 
335 
336 struct hv_kvp_hdr {
337 	__u8 operation;
338 	__u8 pool;
339 	__u16 pad;
340 } __attribute__((packed));
341 
342 struct hv_kvp_exchg_msg_value {
343 	__u32 value_type;
344 	__u32 key_size;
345 	__u32 value_size;
346 	__u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
347 	union {
348 		__u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
349 		__u32 value_u32;
350 		__u64 value_u64;
351 	};
352 } __attribute__((packed));
353 
354 struct hv_kvp_msg_enumerate {
355 	__u32 index;
356 	struct hv_kvp_exchg_msg_value data;
357 } __attribute__((packed));
358 
359 struct hv_kvp_msg_get {
360 	struct hv_kvp_exchg_msg_value data;
361 };
362 
363 struct hv_kvp_msg_set {
364 	struct hv_kvp_exchg_msg_value data;
365 };
366 
367 struct hv_kvp_msg_delete {
368 	__u32 key_size;
369 	__u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
370 };
371 
372 struct hv_kvp_register {
373 	__u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
374 };
375 
376 struct hv_kvp_msg {
377 	union {
378 		struct hv_kvp_hdr	kvp_hdr;
379 		int error;
380 	};
381 	union {
382 		struct hv_kvp_msg_get		kvp_get;
383 		struct hv_kvp_msg_set		kvp_set;
384 		struct hv_kvp_msg_delete	kvp_delete;
385 		struct hv_kvp_msg_enumerate	kvp_enum_data;
386 		struct hv_kvp_ipaddr_value      kvp_ip_val;
387 		struct hv_kvp_register		kvp_register;
388 	} body;
389 } __attribute__((packed));
390 
391 struct hv_kvp_ip_msg {
392 	__u8 operation;
393 	__u8 pool;
394 	struct hv_kvp_ipaddr_value      kvp_ip_val;
395 } __attribute__((packed));
396 
397 #endif /* _UAPI_HYPERV_H */
398