Sync from SUSE:SLFO:Main hyper-v revision 920028c3cd1dd098469a5e5be0869e26
This commit is contained in:
parent
daefaea87c
commit
b3b43e70eb
@ -1,3 +1,25 @@
|
||||
-------------------------------------------------------------------
|
||||
Tue Oct 22 22:22:22 UTC 2024 - ohering@suse.de
|
||||
|
||||
- Add memory allocation check in hv_fcopy_start (94e86b17)
|
||||
- suppress the invalid warning for packed member alignment (207e03b0)
|
||||
- Add new fcopy application based on uio driver (82b0945c)
|
||||
- Add vmbus_bufring (45bab4d7)
|
||||
- kvp: Handle IPv4 and Ipv6 combination for keyfile format (f971f6dd)
|
||||
- kvp: Some small fixes for handling NM keyfiles (c3803203)
|
||||
- kvp: Support for keyfile based connection profile (42999c90)
|
||||
- kvp: remove unnecessary (void*) conversions (22589542)
|
||||
- Remove an extraneous "the" (f15f39fa)
|
||||
- change http to https in hv_kvp_daemon.c (fa52a4b2)
|
||||
- replace the copy of include/linux/hyperv.h with include/uapi/linux/hyperv.h (6de74d10)
|
||||
- merge individual udev rules files into a single rules file
|
||||
- package only files, not directories already owned by filesystem.rpm
|
||||
- remove braces from rpm spec macros
|
||||
- remove obsolete Group tag
|
||||
- replace RPM_BUILD_ROOT with buildroot
|
||||
- use a meaningful name for the UAPI include file
|
||||
- use a meaningful variable name for ifcfg in hv_set_ifconfig.sh
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Apr 23 10:01:10 UTC 2024 - pgajdos@suse.com
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2011, Microsoft Corporation.
|
||||
@ -22,14 +23,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HYPERV_H
|
||||
#define _HYPERV_H
|
||||
#ifndef _UAPI_HYPERV_H
|
||||
#define _UAPI_HYPERV_H
|
||||
|
||||
#include <linux/types.h>
|
||||
/* from linux/uuid.h */
|
||||
typedef struct {
|
||||
__u8 b[16];
|
||||
} uuid_le;
|
||||
|
||||
/*
|
||||
* Framework version for util services.
|
||||
*/
|
||||
#define UTIL_FW_MINOR 0
|
||||
|
||||
#define UTIL_WS2K8_FW_MAJOR 1
|
||||
#define UTIL_WS2K8_FW_VERSION (UTIL_WS2K8_FW_MAJOR << 16 | UTIL_FW_MINOR)
|
||||
|
||||
#define UTIL_FW_MAJOR 3
|
||||
#define UTIL_FW_VERSION (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
|
||||
|
||||
|
||||
/*
|
||||
@ -82,6 +90,17 @@ struct hv_vss_check_dm_info {
|
||||
__u32 flags;
|
||||
} __attribute__((packed));
|
||||
|
||||
/*
|
||||
* struct hv_vss_msg encodes the fields that the Linux VSS
|
||||
* driver accesses. However, FREEZE messages from Hyper-V contain
|
||||
* additional LUN information that Linux doesn't use and are not
|
||||
* represented in struct hv_vss_msg. A received FREEZE message may
|
||||
* be as large as 6,260 bytes, so the driver must allocate at least
|
||||
* that much space, not sizeof(struct hv_vss_msg). Other messages
|
||||
* such as AUTO_RECOVER may be as large as 12,500 bytes. However,
|
||||
* because the Linux VSS driver responds that it doesn't support
|
||||
* auto-recovery, it should not receive such messages.
|
||||
*/
|
||||
struct hv_vss_msg {
|
||||
union {
|
||||
struct hv_vss_hdr vss_hdr;
|
||||
@ -93,7 +112,6 @@ struct hv_vss_msg {
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of a host to guest copy facility.
|
||||
*/
|
||||
@ -112,8 +130,8 @@ enum hv_fcopy_op {
|
||||
|
||||
struct hv_fcopy_hdr {
|
||||
__u32 operation;
|
||||
uuid_le service_id0; /* currently unused */
|
||||
uuid_le service_id1; /* currently unused */
|
||||
__u8 service_id0[16]; /* currently unused */
|
||||
__u8 service_id1[16]; /* currently unused */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define OVER_WRITE 0x1
|
||||
@ -140,7 +158,6 @@ struct hv_do_fcopy {
|
||||
__u8 data[DATA_FRAGMENT];
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/*
|
||||
* An implementation of HyperV key value pair (KVP) functionality for Linux.
|
||||
*
|
||||
@ -213,7 +230,7 @@ struct hv_do_fcopy {
|
||||
* kernel and user-level daemon communicate using a connector channel.
|
||||
*
|
||||
* The user mode component first registers with the
|
||||
* the kernel component. Subsequently, the kernel component requests, data
|
||||
* kernel component. Subsequently, the kernel component requests, data
|
||||
* for the specified keys. In response to this message the user mode component
|
||||
* fills in the value corresponding to the specified key. We overload the
|
||||
* sequence field in the cn_msg header to define our KVP message types.
|
||||
@ -391,880 +408,4 @@ struct hv_kvp_ip_msg {
|
||||
struct hv_kvp_ipaddr_value kvp_ip_val;
|
||||
} __attribute__((packed));
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/uuid.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
|
||||
|
||||
#define MAX_PAGE_BUFFER_COUNT 19
|
||||
#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/* Single-page buffer */
|
||||
struct hv_page_buffer {
|
||||
u32 len;
|
||||
u32 offset;
|
||||
u64 pfn;
|
||||
};
|
||||
|
||||
/* Multiple-page buffer */
|
||||
struct hv_multipage_buffer {
|
||||
/* Length and Offset determines the # of pfns in the array */
|
||||
u32 len;
|
||||
u32 offset;
|
||||
u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
|
||||
};
|
||||
|
||||
/* 0x18 includes the proprietary packet header */
|
||||
#define MAX_PAGE_BUFFER_PACKET (0x18 + \
|
||||
(sizeof(struct hv_page_buffer) * \
|
||||
MAX_PAGE_BUFFER_COUNT))
|
||||
#define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
|
||||
sizeof(struct hv_multipage_buffer))
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
struct hv_ring_buffer {
|
||||
/* Offset in bytes from the start of ring data below */
|
||||
u32 write_index;
|
||||
|
||||
/* Offset in bytes from the start of ring data below */
|
||||
u32 read_index;
|
||||
|
||||
u32 interrupt_mask;
|
||||
|
||||
/* Pad it to PAGE_SIZE so that data starts on page boundary */
|
||||
u8 reserved[4084];
|
||||
|
||||
/* NOTE:
|
||||
* The interrupt_mask field is used only for channels but since our
|
||||
* vmbus connection also uses this data structure and its data starts
|
||||
* here, we commented out this field.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ring data starts here + RingDataStartOffset
|
||||
* !!! DO NOT place any fields below this !!!
|
||||
*/
|
||||
u8 buffer[0];
|
||||
} __packed;
|
||||
|
||||
struct hv_ring_buffer_info {
|
||||
struct hv_ring_buffer *ring_buffer;
|
||||
u32 ring_size; /* Include the shared header */
|
||||
spinlock_t ring_lock;
|
||||
|
||||
u32 ring_datasize; /* < ring_size */
|
||||
u32 ring_data_startoffset;
|
||||
};
|
||||
|
||||
struct hv_ring_buffer_debug_info {
|
||||
u32 current_interrupt_mask;
|
||||
u32 current_read_index;
|
||||
u32 current_write_index;
|
||||
u32 bytes_avail_toread;
|
||||
u32 bytes_avail_towrite;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* hv_get_ringbuffer_availbytes()
|
||||
*
|
||||
* Get number of bytes available to read and to write to
|
||||
* for the specified ring buffer
|
||||
*/
|
||||
static inline void
|
||||
hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
|
||||
u32 *read, u32 *write)
|
||||
{
|
||||
u32 read_loc, write_loc, dsize;
|
||||
|
||||
smp_read_barrier_depends();
|
||||
|
||||
/* Capture the read/write indices before they changed */
|
||||
read_loc = rbi->ring_buffer->read_index;
|
||||
write_loc = rbi->ring_buffer->write_index;
|
||||
dsize = rbi->ring_datasize;
|
||||
|
||||
*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
|
||||
read_loc - write_loc;
|
||||
*read = dsize - *write;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We use the same version numbering for all Hyper-V modules.
|
||||
*
|
||||
* Definition of versioning is as follows;
|
||||
*
|
||||
* Major Number Changes for these scenarios;
|
||||
* 1. When a new version of Windows Hyper-V
|
||||
* is released.
|
||||
* 2. A Major change has occurred in the
|
||||
* Linux IC's.
|
||||
* (For example the merge for the first time
|
||||
* into the kernel) Every time the Major Number
|
||||
* changes, the Revision number is reset to 0.
|
||||
* Minor Number Changes when new functionality is added
|
||||
* to the Linux IC's that is not a bug fix.
|
||||
*
|
||||
* 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
|
||||
*/
|
||||
#define HV_DRV_VERSION "3.1"
|
||||
|
||||
|
||||
/*
|
||||
* A revision number of vmbus that is used for ensuring both ends on a
|
||||
* partition are using compatible versions.
|
||||
*/
|
||||
#define VMBUS_REVISION_NUMBER 13
|
||||
|
||||
/* Make maximum size of pipe payload of 16K */
|
||||
#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
|
||||
|
||||
/* Define PipeMode values. */
|
||||
#define VMBUS_PIPE_TYPE_BYTE 0x00000000
|
||||
#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
|
||||
|
||||
/* The size of the user defined data buffer for non-pipe offers. */
|
||||
#define MAX_USER_DEFINED_BYTES 120
|
||||
|
||||
/* The size of the user defined data buffer for pipe offers. */
|
||||
#define MAX_PIPE_USER_DEFINED_BYTES 116
|
||||
|
||||
/*
|
||||
* At the center of the Channel Management library is the Channel Offer. This
|
||||
* struct contains the fundamental information about an offer.
|
||||
*/
|
||||
struct vmbus_channel_offer {
|
||||
uuid_le if_type;
|
||||
uuid_le if_instance;
|
||||
u64 int_latency; /* in 100ns units */
|
||||
u32 if_revision;
|
||||
u32 server_ctx_size; /* in bytes */
|
||||
u16 chn_flags;
|
||||
u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
|
||||
|
||||
union {
|
||||
/* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
|
||||
struct {
|
||||
unsigned char user_def[MAX_USER_DEFINED_BYTES];
|
||||
} std;
|
||||
|
||||
/*
|
||||
* Pipes:
|
||||
* The following sructure is an integrated pipe protocol, which
|
||||
* is implemented on top of standard user-defined data. Pipe
|
||||
* clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
|
||||
* use.
|
||||
*/
|
||||
struct {
|
||||
u32 pipe_mode;
|
||||
unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
|
||||
} pipe;
|
||||
} u;
|
||||
u32 padding;
|
||||
} __packed;
|
||||
|
||||
/* Server Flags */
|
||||
#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
|
||||
#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
|
||||
#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
|
||||
#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
|
||||
#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
|
||||
#define VMBUS_CHANNEL_PARENT_OFFER 0x200
|
||||
#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
|
||||
|
||||
struct vmpacket_descriptor {
|
||||
u16 type;
|
||||
u16 offset8;
|
||||
u16 len8;
|
||||
u16 flags;
|
||||
u64 trans_id;
|
||||
} __packed;
|
||||
|
||||
struct vmpacket_header {
|
||||
u32 prev_pkt_start_offset;
|
||||
struct vmpacket_descriptor descriptor;
|
||||
} __packed;
|
||||
|
||||
struct vmtransfer_page_range {
|
||||
u32 byte_count;
|
||||
u32 byte_offset;
|
||||
} __packed;
|
||||
|
||||
struct vmtransfer_page_packet_header {
|
||||
struct vmpacket_descriptor d;
|
||||
u16 xfer_pageset_id;
|
||||
u8 sender_owns_set;
|
||||
u8 reserved;
|
||||
u32 range_cnt;
|
||||
struct vmtransfer_page_range ranges[1];
|
||||
} __packed;
|
||||
|
||||
struct vmgpadl_packet_header {
|
||||
struct vmpacket_descriptor d;
|
||||
u32 gpadl;
|
||||
u32 reserved;
|
||||
} __packed;
|
||||
|
||||
struct vmadd_remove_transfer_page_set {
|
||||
struct vmpacket_descriptor d;
|
||||
u32 gpadl;
|
||||
u16 xfer_pageset_id;
|
||||
u16 reserved;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* This structure defines a range in guest physical space that can be made to
|
||||
* look virtually contiguous.
|
||||
*/
|
||||
struct gpa_range {
|
||||
u32 byte_count;
|
||||
u32 byte_offset;
|
||||
u64 pfn_array[0];
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the format for an Establish Gpadl packet, which contains a handle by
|
||||
* which this GPADL will be known and a set of GPA ranges associated with it.
|
||||
* This can be converted to a MDL by the guest OS. If there are multiple GPA
|
||||
* ranges, then the resulting MDL will be "chained," representing multiple VA
|
||||
* ranges.
|
||||
*/
|
||||
struct vmestablish_gpadl {
|
||||
struct vmpacket_descriptor d;
|
||||
u32 gpadl;
|
||||
u32 range_cnt;
|
||||
struct gpa_range range[1];
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* This is the format for a Teardown Gpadl packet, which indicates that the
|
||||
* GPADL handle in the Establish Gpadl packet will never be referenced again.
|
||||
*/
|
||||
struct vmteardown_gpadl {
|
||||
struct vmpacket_descriptor d;
|
||||
u32 gpadl;
|
||||
u32 reserved; /* for alignment to a 8-byte boundary */
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* This is the format for a GPA-Direct packet, which contains a set of GPA
|
||||
* ranges, in addition to commands and/or data.
|
||||
*/
|
||||
struct vmdata_gpa_direct {
|
||||
struct vmpacket_descriptor d;
|
||||
u32 reserved;
|
||||
u32 range_cnt;
|
||||
struct gpa_range range[1];
|
||||
} __packed;
|
||||
|
||||
/* This is the format for a Additional Data Packet. */
|
||||
struct vmadditional_data {
|
||||
struct vmpacket_descriptor d;
|
||||
u64 total_bytes;
|
||||
u32 offset;
|
||||
u32 byte_cnt;
|
||||
unsigned char data[1];
|
||||
} __packed;
|
||||
|
||||
union vmpacket_largest_possible_header {
|
||||
struct vmpacket_descriptor simple_hdr;
|
||||
struct vmtransfer_page_packet_header xfer_page_hdr;
|
||||
struct vmgpadl_packet_header gpadl_hdr;
|
||||
struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
|
||||
struct vmestablish_gpadl establish_gpadl_hdr;
|
||||
struct vmteardown_gpadl teardown_gpadl_hdr;
|
||||
struct vmdata_gpa_direct data_gpa_direct_hdr;
|
||||
};
|
||||
|
||||
#define VMPACKET_DATA_START_ADDRESS(__packet) \
|
||||
(void *)(((unsigned char *)__packet) + \
|
||||
((struct vmpacket_descriptor)__packet)->offset8 * 8)
|
||||
|
||||
#define VMPACKET_DATA_LENGTH(__packet) \
|
||||
((((struct vmpacket_descriptor)__packet)->len8 - \
|
||||
((struct vmpacket_descriptor)__packet)->offset8) * 8)
|
||||
|
||||
#define VMPACKET_TRANSFER_MODE(__packet) \
|
||||
(((struct IMPACT)__packet)->type)
|
||||
|
||||
enum vmbus_packet_type {
|
||||
VM_PKT_INVALID = 0x0,
|
||||
VM_PKT_SYNCH = 0x1,
|
||||
VM_PKT_ADD_XFER_PAGESET = 0x2,
|
||||
VM_PKT_RM_XFER_PAGESET = 0x3,
|
||||
VM_PKT_ESTABLISH_GPADL = 0x4,
|
||||
VM_PKT_TEARDOWN_GPADL = 0x5,
|
||||
VM_PKT_DATA_INBAND = 0x6,
|
||||
VM_PKT_DATA_USING_XFER_PAGES = 0x7,
|
||||
VM_PKT_DATA_USING_GPADL = 0x8,
|
||||
VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
|
||||
VM_PKT_CANCEL_REQUEST = 0xa,
|
||||
VM_PKT_COMP = 0xb,
|
||||
VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
|
||||
VM_PKT_ADDITIONAL_DATA = 0xd
|
||||
};
|
||||
|
||||
#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
|
||||
|
||||
|
||||
/* Version 1 messages */
|
||||
enum vmbus_channel_message_type {
|
||||
CHANNELMSG_INVALID = 0,
|
||||
CHANNELMSG_OFFERCHANNEL = 1,
|
||||
CHANNELMSG_RESCIND_CHANNELOFFER = 2,
|
||||
CHANNELMSG_REQUESTOFFERS = 3,
|
||||
CHANNELMSG_ALLOFFERS_DELIVERED = 4,
|
||||
CHANNELMSG_OPENCHANNEL = 5,
|
||||
CHANNELMSG_OPENCHANNEL_RESULT = 6,
|
||||
CHANNELMSG_CLOSECHANNEL = 7,
|
||||
CHANNELMSG_GPADL_HEADER = 8,
|
||||
CHANNELMSG_GPADL_BODY = 9,
|
||||
CHANNELMSG_GPADL_CREATED = 10,
|
||||
CHANNELMSG_GPADL_TEARDOWN = 11,
|
||||
CHANNELMSG_GPADL_TORNDOWN = 12,
|
||||
CHANNELMSG_RELID_RELEASED = 13,
|
||||
CHANNELMSG_INITIATE_CONTACT = 14,
|
||||
CHANNELMSG_VERSION_RESPONSE = 15,
|
||||
CHANNELMSG_UNLOAD = 16,
|
||||
#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
|
||||
CHANNELMSG_VIEWRANGE_ADD = 17,
|
||||
CHANNELMSG_VIEWRANGE_REMOVE = 18,
|
||||
#endif
|
||||
CHANNELMSG_COUNT
|
||||
};
|
||||
|
||||
struct vmbus_channel_message_header {
|
||||
enum vmbus_channel_message_type msgtype;
|
||||
u32 padding;
|
||||
} __packed;
|
||||
|
||||
/* Query VMBus Version parameters */
|
||||
struct vmbus_channel_query_vmbus_version {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 version;
|
||||
} __packed;
|
||||
|
||||
/* VMBus Version Supported parameters */
|
||||
struct vmbus_channel_version_supported {
|
||||
struct vmbus_channel_message_header header;
|
||||
u8 version_supported;
|
||||
} __packed;
|
||||
|
||||
/* Offer Channel parameters */
|
||||
struct vmbus_channel_offer_channel {
|
||||
struct vmbus_channel_message_header header;
|
||||
struct vmbus_channel_offer offer;
|
||||
u32 child_relid;
|
||||
u8 monitorid;
|
||||
u8 monitor_allocated;
|
||||
} __packed;
|
||||
|
||||
/* Rescind Offer parameters */
|
||||
struct vmbus_channel_rescind_offer {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* Request Offer -- no parameters, SynIC message contains the partition ID
|
||||
* Set Snoop -- no parameters, SynIC message contains the partition ID
|
||||
* Clear Snoop -- no parameters, SynIC message contains the partition ID
|
||||
* All Offers Delivered -- no parameters, SynIC message contains the partition
|
||||
* ID
|
||||
* Flush Client -- no parameters, SynIC message contains the partition ID
|
||||
*/
|
||||
|
||||
/* Open Channel parameters */
|
||||
struct vmbus_channel_open_channel {
|
||||
struct vmbus_channel_message_header header;
|
||||
|
||||
/* Identifies the specific VMBus channel that is being opened. */
|
||||
u32 child_relid;
|
||||
|
||||
/* ID making a particular open request at a channel offer unique. */
|
||||
u32 openid;
|
||||
|
||||
/* GPADL for the channel's ring buffer. */
|
||||
u32 ringbuffer_gpadlhandle;
|
||||
|
||||
/* GPADL for the channel's server context save area. */
|
||||
u32 server_contextarea_gpadlhandle;
|
||||
|
||||
/*
|
||||
* The upstream ring buffer begins at offset zero in the memory
|
||||
* described by RingBufferGpadlHandle. The downstream ring buffer
|
||||
* follows it at this offset (in pages).
|
||||
*/
|
||||
u32 downstream_ringbuffer_pageoffset;
|
||||
|
||||
/* User-specific data to be passed along to the server endpoint. */
|
||||
unsigned char userdata[MAX_USER_DEFINED_BYTES];
|
||||
} __packed;
|
||||
|
||||
/* Open Channel Result parameters */
|
||||
struct vmbus_channel_open_result {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
u32 openid;
|
||||
u32 status;
|
||||
} __packed;
|
||||
|
||||
/* Close channel parameters; */
|
||||
struct vmbus_channel_close_channel {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
} __packed;
|
||||
|
||||
/* Channel Message GPADL */
|
||||
#define GPADL_TYPE_RING_BUFFER 1
|
||||
#define GPADL_TYPE_SERVER_SAVE_AREA 2
|
||||
#define GPADL_TYPE_TRANSACTION 8
|
||||
|
||||
/*
|
||||
* The number of PFNs in a GPADL message is defined by the number of
|
||||
* pages that would be spanned by ByteCount and ByteOffset. If the
|
||||
* implied number of PFNs won't fit in this packet, there will be a
|
||||
* follow-up packet that contains more.
|
||||
*/
|
||||
struct vmbus_channel_gpadl_header {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
u32 gpadl;
|
||||
u16 range_buflen;
|
||||
u16 rangecount;
|
||||
struct gpa_range range[0];
|
||||
} __packed;
|
||||
|
||||
/* This is the followup packet that contains more PFNs. */
|
||||
struct vmbus_channel_gpadl_body {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 msgnumber;
|
||||
u32 gpadl;
|
||||
u64 pfn[0];
|
||||
} __packed;
|
||||
|
||||
struct vmbus_channel_gpadl_created {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
u32 gpadl;
|
||||
u32 creation_status;
|
||||
} __packed;
|
||||
|
||||
struct vmbus_channel_gpadl_teardown {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
u32 gpadl;
|
||||
} __packed;
|
||||
|
||||
struct vmbus_channel_gpadl_torndown {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 gpadl;
|
||||
} __packed;
|
||||
|
||||
#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
|
||||
struct vmbus_channel_view_range_add {
|
||||
struct vmbus_channel_message_header header;
|
||||
PHYSICAL_ADDRESS viewrange_base;
|
||||
u64 viewrange_length;
|
||||
u32 child_relid;
|
||||
} __packed;
|
||||
|
||||
struct vmbus_channel_view_range_remove {
|
||||
struct vmbus_channel_message_header header;
|
||||
PHYSICAL_ADDRESS viewrange_base;
|
||||
u32 child_relid;
|
||||
} __packed;
|
||||
#endif
|
||||
|
||||
struct vmbus_channel_relid_released {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 child_relid;
|
||||
} __packed;
|
||||
|
||||
struct vmbus_channel_initiate_contact {
|
||||
struct vmbus_channel_message_header header;
|
||||
u32 vmbus_version_requested;
|
||||
u32 padding2;
|
||||
u64 interrupt_page;
|
||||
u64 monitor_page1;
|
||||
u64 monitor_page2;
|
||||
} __packed;
|
||||
|
||||
struct vmbus_channel_version_response {
|
||||
struct vmbus_channel_message_header header;
|
||||
u8 version_supported;
|
||||
} __packed;
|
||||
|
||||
enum vmbus_channel_state {
|
||||
CHANNEL_OFFER_STATE,
|
||||
CHANNEL_OPENING_STATE,
|
||||
CHANNEL_OPEN_STATE,
|
||||
};
|
||||
|
||||
struct vmbus_channel_debug_info {
|
||||
u32 relid;
|
||||
enum vmbus_channel_state state;
|
||||
uuid_le interfacetype;
|
||||
uuid_le interface_instance;
|
||||
u32 monitorid;
|
||||
u32 servermonitor_pending;
|
||||
u32 servermonitor_latency;
|
||||
u32 servermonitor_connectionid;
|
||||
u32 clientmonitor_pending;
|
||||
u32 clientmonitor_latency;
|
||||
u32 clientmonitor_connectionid;
|
||||
|
||||
struct hv_ring_buffer_debug_info inbound;
|
||||
struct hv_ring_buffer_debug_info outbound;
|
||||
};
|
||||
|
||||
/*
|
||||
* Represents each channel msg on the vmbus connection This is a
|
||||
* variable-size data structure depending on the msg type itself
|
||||
*/
|
||||
struct vmbus_channel_msginfo {
|
||||
/* Bookkeeping stuff */
|
||||
struct list_head msglistentry;
|
||||
|
||||
/* So far, this is only used to handle gpadl body message */
|
||||
struct list_head submsglist;
|
||||
|
||||
/* Synchronize the request/response if needed */
|
||||
struct completion waitevent;
|
||||
union {
|
||||
struct vmbus_channel_version_supported version_supported;
|
||||
struct vmbus_channel_open_result open_result;
|
||||
struct vmbus_channel_gpadl_torndown gpadl_torndown;
|
||||
struct vmbus_channel_gpadl_created gpadl_created;
|
||||
struct vmbus_channel_version_response version_response;
|
||||
} response;
|
||||
|
||||
u32 msgsize;
|
||||
/*
|
||||
* The channel message that goes out on the "wire".
|
||||
* It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
|
||||
*/
|
||||
unsigned char msg[0];
|
||||
};
|
||||
|
||||
struct vmbus_close_msg {
|
||||
struct vmbus_channel_msginfo info;
|
||||
struct vmbus_channel_close_channel msg;
|
||||
};
|
||||
|
||||
struct vmbus_channel {
|
||||
struct list_head listentry;
|
||||
|
||||
struct hv_device *device_obj;
|
||||
|
||||
struct work_struct work;
|
||||
|
||||
enum vmbus_channel_state state;
|
||||
|
||||
struct vmbus_channel_offer_channel offermsg;
|
||||
/*
|
||||
* These are based on the OfferMsg.MonitorId.
|
||||
* Save it here for easy access.
|
||||
*/
|
||||
u8 monitor_grp;
|
||||
u8 monitor_bit;
|
||||
|
||||
u32 ringbuffer_gpadlhandle;
|
||||
|
||||
/* Allocated memory for ring buffer */
|
||||
void *ringbuffer_pages;
|
||||
u32 ringbuffer_pagecount;
|
||||
struct hv_ring_buffer_info outbound; /* send to parent */
|
||||
struct hv_ring_buffer_info inbound; /* receive from parent */
|
||||
spinlock_t inbound_lock;
|
||||
struct workqueue_struct *controlwq;
|
||||
|
||||
struct vmbus_close_msg close_msg;
|
||||
|
||||
/* Channel callback are invoked in this workqueue context */
|
||||
/* HANDLE dataWorkQueue; */
|
||||
|
||||
void (*onchannel_callback)(void *context);
|
||||
void *channel_callback_context;
|
||||
};
|
||||
|
||||
void vmbus_onmessage(void *context);
|
||||
|
||||
int vmbus_request_offers(void);
|
||||
|
||||
/* The format must be the same as struct vmdata_gpa_direct */
|
||||
struct vmbus_channel_packet_page_buffer {
|
||||
u16 type;
|
||||
u16 dataoffset8;
|
||||
u16 length8;
|
||||
u16 flags;
|
||||
u64 transactionid;
|
||||
u32 reserved;
|
||||
u32 rangecount;
|
||||
struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
|
||||
} __packed;
|
||||
|
||||
/* The format must be the same as struct vmdata_gpa_direct */
|
||||
struct vmbus_channel_packet_multipage_buffer {
|
||||
u16 type;
|
||||
u16 dataoffset8;
|
||||
u16 length8;
|
||||
u16 flags;
|
||||
u64 transactionid;
|
||||
u32 reserved;
|
||||
u32 rangecount; /* Always 1 in this case */
|
||||
struct hv_multipage_buffer range;
|
||||
} __packed;
|
||||
|
||||
|
||||
extern int vmbus_open(struct vmbus_channel *channel,
|
||||
u32 send_ringbuffersize,
|
||||
u32 recv_ringbuffersize,
|
||||
void *userdata,
|
||||
u32 userdatalen,
|
||||
void(*onchannel_callback)(void *context),
|
||||
void *context);
|
||||
|
||||
extern void vmbus_close(struct vmbus_channel *channel);
|
||||
|
||||
extern int vmbus_sendpacket(struct vmbus_channel *channel,
|
||||
const void *buffer,
|
||||
u32 bufferLen,
|
||||
u64 requestid,
|
||||
enum vmbus_packet_type type,
|
||||
u32 flags);
|
||||
|
||||
extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
|
||||
struct hv_page_buffer pagebuffers[],
|
||||
u32 pagecount,
|
||||
void *buffer,
|
||||
u32 bufferlen,
|
||||
u64 requestid);
|
||||
|
||||
extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
|
||||
struct hv_multipage_buffer *mpb,
|
||||
void *buffer,
|
||||
u32 bufferlen,
|
||||
u64 requestid);
|
||||
|
||||
extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
|
||||
void *kbuffer,
|
||||
u32 size,
|
||||
u32 *gpadl_handle);
|
||||
|
||||
extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
|
||||
u32 gpadl_handle);
|
||||
|
||||
extern int vmbus_recvpacket(struct vmbus_channel *channel,
|
||||
void *buffer,
|
||||
u32 bufferlen,
|
||||
u32 *buffer_actual_len,
|
||||
u64 *requestid);
|
||||
|
||||
extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
|
||||
void *buffer,
|
||||
u32 bufferlen,
|
||||
u32 *buffer_actual_len,
|
||||
u64 *requestid);
|
||||
|
||||
|
||||
extern void vmbus_get_debug_info(struct vmbus_channel *channel,
|
||||
struct vmbus_channel_debug_info *debug);
|
||||
|
||||
extern void vmbus_ontimer(unsigned long data);
|
||||
|
||||
struct hv_dev_port_info {
|
||||
u32 int_mask;
|
||||
u32 read_idx;
|
||||
u32 write_idx;
|
||||
u32 bytes_avail_toread;
|
||||
u32 bytes_avail_towrite;
|
||||
};
|
||||
|
||||
/* Base driver object */
|
||||
struct hv_driver {
|
||||
const char *name;
|
||||
|
||||
/* the device type supported by this driver */
|
||||
uuid_le dev_type;
|
||||
const struct hv_vmbus_device_id *id_table;
|
||||
|
||||
struct device_driver driver;
|
||||
|
||||
int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
|
||||
int (*remove)(struct hv_device *);
|
||||
void (*shutdown)(struct hv_device *);
|
||||
|
||||
};
|
||||
|
||||
/* Base device object */
|
||||
struct hv_device {
|
||||
/* the device type id of this device */
|
||||
uuid_le dev_type;
|
||||
|
||||
/* the device instance id of this device */
|
||||
uuid_le dev_instance;
|
||||
|
||||
struct device device;
|
||||
|
||||
struct vmbus_channel *channel;
|
||||
};
|
||||
|
||||
|
||||
static inline struct hv_device *device_to_hv_device(struct device *d)
|
||||
{
|
||||
return container_of(d, struct hv_device, device);
|
||||
}
|
||||
|
||||
static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
|
||||
{
|
||||
return container_of(d, struct hv_driver, driver);
|
||||
}
|
||||
|
||||
static inline void hv_set_drvdata(struct hv_device *dev, void *data)
|
||||
{
|
||||
dev_set_drvdata(&dev->device, data);
|
||||
}
|
||||
|
||||
static inline void *hv_get_drvdata(struct hv_device *dev)
|
||||
{
|
||||
return dev_get_drvdata(&dev->device);
|
||||
}
|
||||
|
||||
/* Vmbus interface */
|
||||
#define vmbus_driver_register(driver) \
|
||||
__vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
|
||||
int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
|
||||
struct module *owner,
|
||||
const char *mod_name);
|
||||
void vmbus_driver_unregister(struct hv_driver *hv_driver);
|
||||
|
||||
/**
|
||||
* VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
|
||||
*
|
||||
* This macro is used to create a struct hv_vmbus_device_id that matches a
|
||||
* specific device.
|
||||
*/
|
||||
#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
|
||||
g8, g9, ga, gb, gc, gd, ge, gf) \
|
||||
.guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
|
||||
g8, g9, ga, gb, gc, gd, ge, gf },
|
||||
|
||||
/*
|
||||
* Common header for Hyper-V ICs
|
||||
*/
|
||||
|
||||
#define ICMSGTYPE_NEGOTIATE 0
|
||||
#define ICMSGTYPE_HEARTBEAT 1
|
||||
#define ICMSGTYPE_KVPEXCHANGE 2
|
||||
#define ICMSGTYPE_SHUTDOWN 3
|
||||
#define ICMSGTYPE_TIMESYNC 4
|
||||
#define ICMSGTYPE_VSS 5
|
||||
|
||||
#define ICMSGHDRFLAG_TRANSACTION 1
|
||||
#define ICMSGHDRFLAG_REQUEST 2
|
||||
#define ICMSGHDRFLAG_RESPONSE 4
|
||||
|
||||
|
||||
/*
|
||||
* While we want to handle util services as regular devices,
|
||||
* there is only one instance of each of these services; so
|
||||
* we statically allocate the service specific state.
|
||||
*/
|
||||
|
||||
struct hv_util_service {
|
||||
u8 *recv_buffer;
|
||||
void (*util_cb)(void *);
|
||||
int (*util_init)(struct hv_util_service *);
|
||||
void (*util_deinit)(void);
|
||||
};
|
||||
|
||||
struct vmbuspipe_hdr {
|
||||
u32 flags;
|
||||
u32 msgsize;
|
||||
} __packed;
|
||||
|
||||
struct ic_version {
|
||||
u16 major;
|
||||
u16 minor;
|
||||
} __packed;
|
||||
|
||||
struct icmsg_hdr {
|
||||
struct ic_version icverframe;
|
||||
u16 icmsgtype;
|
||||
struct ic_version icvermsg;
|
||||
u16 icmsgsize;
|
||||
u32 status;
|
||||
u8 ictransaction_id;
|
||||
u8 icflags;
|
||||
u8 reserved[2];
|
||||
} __packed;
|
||||
|
||||
struct icmsg_negotiate {
|
||||
u16 icframe_vercnt;
|
||||
u16 icmsg_vercnt;
|
||||
u32 reserved;
|
||||
struct ic_version icversion_data[1]; /* any size array */
|
||||
} __packed;
|
||||
|
||||
struct shutdown_msg_data {
|
||||
u32 reason_code;
|
||||
u32 timeout_seconds;
|
||||
u32 flags;
|
||||
u8 display_message[2048];
|
||||
} __packed;
|
||||
|
||||
struct heartbeat_msg_data {
|
||||
u64 seq_num;
|
||||
u32 reserved[8];
|
||||
} __packed;
|
||||
|
||||
/* Time Sync IC defs */
|
||||
#define ICTIMESYNCFLAG_PROBE 0
|
||||
#define ICTIMESYNCFLAG_SYNC 1
|
||||
#define ICTIMESYNCFLAG_SAMPLE 2
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
|
||||
#else
|
||||
#define WLTIMEDELTA 116444736000000000LL
|
||||
#endif
|
||||
|
||||
struct ictimesync_data {
|
||||
u64 parenttime;
|
||||
u64 childtime;
|
||||
u64 roundtriptime;
|
||||
u8 flags;
|
||||
} __packed;
|
||||
|
||||
struct hyperv_service_callback {
|
||||
u8 msg_type;
|
||||
char *log_msg;
|
||||
uuid_le data;
|
||||
struct vmbus_channel *channel;
|
||||
void (*callback) (void *context);
|
||||
};
|
||||
|
||||
#define MAX_SRV_VER 0x7ffffff
|
||||
extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
|
||||
struct icmsg_negotiate *, u8 *, int,
|
||||
int);
|
||||
|
||||
int hv_kvp_init(struct hv_util_service *);
|
||||
void hv_kvp_deinit(void);
|
||||
void hv_kvp_onchannelcallback(void *);
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
#endif /* _HYPERV_H */
|
||||
#endif /* _UAPI_HYPERV_H */
|
||||
|
194
hyper-v.spec
194
hyper-v.spec
@ -19,7 +19,13 @@
|
||||
%define hv_kvp_daemon hv_kvp_daemon
|
||||
%define hv_vss_daemon hv_vss_daemon
|
||||
%define hv_fcopy_daemon hv_fcopy_daemon
|
||||
%define helper_dir /usr/lib/%{name}
|
||||
%define vmbus_bufring vmbus_bufring
|
||||
%define hv_fcopy_uio_daemon hv_fcopy_uio_daemon
|
||||
%define include_uapi_linux_hyperv include_uapi_linux_hyperv
|
||||
%define chardev_kvp vmbus/hv_kvp
|
||||
%define chardev_vss vmbus/hv_vss
|
||||
%define chardev_fcopy vmbus/hv_fcopy
|
||||
%define helper_dir /usr/lib/%name
|
||||
|
||||
Name: hyper-v
|
||||
ExclusiveArch: %ix86 x86_64 aarch64
|
||||
@ -30,19 +36,21 @@ BuildRequires: pkgconfig(systemd)
|
||||
Conflicts: kernel < 4.2
|
||||
Summary: Microsoft Hyper-V tools
|
||||
License: GPL-2.0-only
|
||||
Group: System/Kernel
|
||||
Supplements: modalias(dmi:*svnMicrosoftCorporation*pnVirtualMachine*rnVirtualMachine*)
|
||||
Supplements: modalias(pci:v00001414d00005353sv*sd*bc*sc*i*)
|
||||
URL: http://www.kernel.org
|
||||
# Arbitrary version number
|
||||
Version: 8
|
||||
Version: 9
|
||||
Release: 0
|
||||
Source0: hyper-v.lsvmbus.py
|
||||
Source5: hyper-v.kvptest.ps1.txt
|
||||
Source7: hyper-v.compare-with-upstream.sh
|
||||
Source8: hyper-v.tools.hv.vmbus_bufring.h
|
||||
Source9: hyper-v.include.linux.hyperv.h
|
||||
Source10: hyper-v.tools.hv.hv_kvp_daemon.c
|
||||
Source11: hyper-v.tools.hv.vmbus_bufring.c
|
||||
Source12: hyper-v.tools.hv.hv_vss_daemon.c
|
||||
Source13: hyper-v.tools.hv.hv_fcopy_uio_daemon.c
|
||||
Source14: hyper-v.tools.hv.hv_fcopy_daemon.c
|
||||
Source20: hyper-v.tools.hv.hv_get_dhcp_info.sh
|
||||
Source21: hyper-v.tools.hv.hv_get_dns_info.sh
|
||||
@ -56,107 +64,147 @@ This package contains the Microsoft Hyper-V tools.
|
||||
%prep
|
||||
%setup -Tc
|
||||
cp -avL %{S:5} kvptest.ps1.txt
|
||||
cp -vL %{S:9} %{hv_kvp_daemon}.h
|
||||
cp -vL %{S:8} %vmbus_bufring.h
|
||||
cp -vL %{S:9} %include_uapi_linux_hyperv.h
|
||||
cp -vL %{S:10} .
|
||||
cp -vL %{S:12} %{hv_vss_daemon}.c
|
||||
cp -vL %{S:14} %{hv_fcopy_daemon}.c
|
||||
cp -vL %{S:11} %vmbus_bufring.c
|
||||
cp -vL %{S:12} %hv_vss_daemon.c
|
||||
cp -vL %{S:13} %hv_fcopy_uio_daemon.c
|
||||
cp -vL %{S:14} %hv_fcopy_daemon.c
|
||||
%patch -P 0 -p1
|
||||
mv `basename %{S:10}` %{hv_kvp_daemon}.c
|
||||
mv `basename %{S:10}` %hv_kvp_daemon.c
|
||||
|
||||
%build
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %{hv_kvp_daemon}.c
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %{hv_vss_daemon}.c
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %{hv_fcopy_daemon}.c
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %hv_kvp_daemon.c
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %hv_vss_daemon.c
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %hv_fcopy_uio_daemon.c
|
||||
sed -i~ '/#include <linux.hyperv.h>/d' %hv_fcopy_daemon.c
|
||||
gcc \
|
||||
$RPM_OPT_FLAGS \
|
||||
-Wno-unused-variable \
|
||||
-Wno-pointer-sign \
|
||||
-D_GNU_SOURCE \
|
||||
-g \
|
||||
%{hv_kvp_daemon}.c \
|
||||
-include %{hv_kvp_daemon}.h \
|
||||
%hv_kvp_daemon.c \
|
||||
-include %include_uapi_linux_hyperv.h \
|
||||
-DCN_KVP_IDX=0x9 \
|
||||
-DCN_KVP_VAL=0x1 \
|
||||
-DKVP_SCRIPTS_PATH= \
|
||||
-pthread \
|
||||
-o %{hv_kvp_daemon}
|
||||
-o %hv_kvp_daemon
|
||||
gcc \
|
||||
$RPM_OPT_FLAGS \
|
||||
-Wno-unused-variable \
|
||||
-Wno-pointer-sign \
|
||||
-D_GNU_SOURCE \
|
||||
-g \
|
||||
%{hv_vss_daemon}.c \
|
||||
-include %{hv_kvp_daemon}.h \
|
||||
%hv_vss_daemon.c \
|
||||
-include %include_uapi_linux_hyperv.h \
|
||||
-DCN_VSS_IDX=0xa \
|
||||
-DCN_VSS_VAL=0x1 \
|
||||
-o %{hv_vss_daemon}
|
||||
-o %hv_vss_daemon
|
||||
gcc \
|
||||
$RPM_OPT_FLAGS \
|
||||
-Wno-unused-variable \
|
||||
-Wno-pointer-sign \
|
||||
-D_GNU_SOURCE \
|
||||
-g \
|
||||
%{hv_fcopy_daemon}.c \
|
||||
-include %{hv_kvp_daemon}.h \
|
||||
-o %{hv_fcopy_daemon}
|
||||
%hv_fcopy_daemon.c \
|
||||
-include %include_uapi_linux_hyperv.h \
|
||||
-o %hv_fcopy_daemon
|
||||
|
||||
%ifarch %ix86 x86_64
|
||||
gcc \
|
||||
$RPM_OPT_FLAGS \
|
||||
-Wno-unused-variable \
|
||||
-Wno-pointer-sign \
|
||||
-Wno-address-of-packed-member \
|
||||
-D_GNU_SOURCE \
|
||||
-g \
|
||||
%vmbus_bufring.c \
|
||||
%hv_fcopy_uio_daemon.c \
|
||||
-include %include_uapi_linux_hyperv.h \
|
||||
-o %hv_fcopy_uio_daemon
|
||||
%endif
|
||||
|
||||
%install
|
||||
# It is not a callable app anyway, so move it out of the way
|
||||
bindir=%{helper_dir}/bin
|
||||
mkdir -p $RPM_BUILD_ROOT${bindir}
|
||||
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
|
||||
mkdir -p $RPM_BUILD_ROOT%{helper_dir}/bin
|
||||
install -m755 %{hv_kvp_daemon} $RPM_BUILD_ROOT${bindir}
|
||||
install -m755 %{hv_vss_daemon} $RPM_BUILD_ROOT${bindir}
|
||||
install -m755 %{hv_fcopy_daemon} $RPM_BUILD_ROOT${bindir}
|
||||
cp -avL %{S:0} $RPM_BUILD_ROOT%{_sbindir}/lsvmbus
|
||||
chmod 0755 $RPM_BUILD_ROOT%{_sbindir}/lsvmbus
|
||||
cp -avL %{S:20} $RPM_BUILD_ROOT%{helper_dir}/bin/hv_get_dhcp_info
|
||||
cp -avL %{S:21} $RPM_BUILD_ROOT%{helper_dir}/bin/hv_get_dns_info
|
||||
cp -avL %{S:22} $RPM_BUILD_ROOT%{helper_dir}/bin/hv_set_ifconfig
|
||||
chmod 755 $RPM_BUILD_ROOT%{helper_dir}/bin/*
|
||||
d=$RPM_BUILD_ROOT%{_unitdir}
|
||||
bindir=%helper_dir/bin
|
||||
mkdir -p %buildroot${bindir}
|
||||
mkdir -p %buildroot%_sbindir
|
||||
install -m755 %hv_kvp_daemon %buildroot${bindir}
|
||||
install -m755 %hv_vss_daemon %buildroot${bindir}
|
||||
install -m755 %hv_fcopy_daemon %buildroot${bindir}
|
||||
%ifarch %ix86 x86_64
|
||||
install -m755 %hv_fcopy_uio_daemon %buildroot${bindir}
|
||||
%endif
|
||||
cp -avL %{S:0} %buildroot%_sbindir/lsvmbus
|
||||
chmod 0755 %buildroot%_sbindir/lsvmbus
|
||||
cp -avL %{S:20} %buildroot${bindir}/hv_get_dhcp_info
|
||||
cp -avL %{S:21} %buildroot${bindir}/hv_get_dns_info
|
||||
cp -avL %{S:22} %buildroot${bindir}/hv_set_ifconfig
|
||||
chmod 755 %buildroot${bindir}/*
|
||||
d=%buildroot%_unitdir
|
||||
mkdir -vp ${d}
|
||||
#
|
||||
tee ${d}/%{hv_kvp_daemon}.service <<EOF
|
||||
# started via %{_udevrulesdir}/%{hv_kvp_daemon}.rules
|
||||
tee ${d}/%hv_kvp_daemon.service <<EOF
|
||||
# started via %_udevrulesdir/%name.rules
|
||||
[Unit]
|
||||
Description=Hyper-V KVP Daemon
|
||||
After=local-fs.target
|
||||
ConditionVirtualization=microsoft
|
||||
ConditionPathExists=/dev/%chardev_kvp
|
||||
|
||||
[Service]
|
||||
Environment="PATH=%{helper_dir}/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
ExecStart=${bindir}/%{hv_kvp_daemon} --no-daemon
|
||||
Environment="PATH=${bindir}:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
ExecStart=${bindir}/%hv_kvp_daemon --no-daemon
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
#
|
||||
tee ${d}/%{hv_vss_daemon}.service <<EOF
|
||||
# started via %{_udevrulesdir}/%{hv_vss_daemon}.rules
|
||||
tee ${d}/%hv_vss_daemon.service <<EOF
|
||||
# started via %_udevrulesdir/%name.rules
|
||||
[Unit]
|
||||
Description=Hyper-V VSS Daemon
|
||||
ConditionVirtualization=microsoft
|
||||
ConditionPathExists=/dev/%chardev_vss
|
||||
|
||||
[Service]
|
||||
ExecStart=${bindir}/%{hv_vss_daemon} --no-daemon
|
||||
ExecStart=${bindir}/%hv_vss_daemon --no-daemon
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
#
|
||||
tee ${d}/%{hv_fcopy_daemon}.service <<EOF
|
||||
# started via %{_udevrulesdir}/%{hv_fcopy_daemon}.rules
|
||||
tee ${d}/%hv_fcopy_daemon.service <<EOF
|
||||
# started via %_udevrulesdir/%name.rules
|
||||
[Unit]
|
||||
Description=Hyper-V host to guest file copy daemon
|
||||
ConditionVirtualization=microsoft
|
||||
ConditionPathExists=/dev/%chardev_fcopy
|
||||
|
||||
[Service]
|
||||
ExecStart=${bindir}/%{hv_fcopy_daemon} --no-daemon
|
||||
ExecStart=${bindir}/%hv_fcopy_daemon --no-daemon
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
#
|
||||
tee ${d}/%hv_fcopy_uio_daemon.service <<EOF
|
||||
# started via %_udevrulesdir/%name.rules
|
||||
[Unit]
|
||||
Description=Hyper-V host to guest UIO file copy daemon
|
||||
ConditionVirtualization=microsoft
|
||||
ConditionPathExists=/sys/bus/vmbus/drivers/uio_hv_generic/new_id
|
||||
ConditionPathExists=!/dev/%chardev_fcopy
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/sh -c 'set -e;echo 34d14be3-dee4-41c8-9ae7-6b174977c192 > /sys/bus/vmbus/drivers/uio_hv_generic/new_id'
|
||||
ExecStart=${bindir}/%hv_fcopy_uio_daemon --no-daemon
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
@ -165,53 +213,61 @@ EOF
|
||||
#
|
||||
#
|
||||
#
|
||||
d=$RPM_BUILD_ROOT%{_udevrulesdir}
|
||||
d=%buildroot%_udevrulesdir
|
||||
mkdir -vp ${d}
|
||||
tee ${d}/%{hv_kvp_daemon}.rules <<EOF
|
||||
ACTION=="add", KERNEL=="vmbus/hv_kvp", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%{hv_kvp_daemon}.service"
|
||||
EOF
|
||||
tee ${d}/%{hv_vss_daemon}.rules <<EOF
|
||||
ACTION=="add", KERNEL=="vmbus/hv_vss", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%{hv_vss_daemon}.service"
|
||||
EOF
|
||||
tee ${d}/%{hv_fcopy_daemon}.rules <<EOF
|
||||
ACTION=="add", KERNEL=="vmbus/hv_fcopy", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%{hv_fcopy_daemon}.service"
|
||||
tee ${d}/%name.rules <<EOF
|
||||
ACTION=="add", KERNEL=="%chardev_kvp", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%hv_kvp_daemon.service"
|
||||
ACTION=="add", KERNEL=="%chardev_vss", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%hv_vss_daemon.service"
|
||||
ACTION=="add", KERNEL=="%chardev_fcopy", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%hv_fcopy_daemon.service"
|
||||
ACTION=="add", SUBSYSTEM=="vmbus", ATTRS{class_id}=="{34d14be3-dee4-41c8-9ae7-6b174977c192}", RUN{builtin}+="kmod load uio_hv_generic", TAG+="systemd", ENV{SYSTEMD_WANTS}+="%hv_fcopy_uio_daemon.service"
|
||||
EOF
|
||||
#
|
||||
#
|
||||
helper=inst_sys.sh
|
||||
tee $RPM_BUILD_ROOT${bindir}/${helper} <<EOF
|
||||
tee %buildroot${bindir}/${helper} <<'_EOF_'
|
||||
#!/bin/bash
|
||||
# Starting daemons via RUN== in udev rules is not supported.
|
||||
# In inst-sys systemd is not used, so start all daemons manually.
|
||||
bindir=%helper_dir/bin
|
||||
declare -a helpers
|
||||
test -c /dev/%chardev_kvp && helpers+=(%hv_kvp_daemon)
|
||||
test -c /dev/%chardev_vss && helpers+=(%hv_vss_daemon)
|
||||
if test -c /dev/%chardev_fcopy
|
||||
then
|
||||
helpers+=(%hv_fcopy_daemon)
|
||||
else
|
||||
modprobe -v uio_hv_generic
|
||||
if test -f /sys/bus/vmbus/drivers/uio_hv_generic/new_id
|
||||
then
|
||||
echo '34d14be3-dee4-41c8-9ae7-6b174977c192' > /sys/bus/vmbus/drivers/uio_hv_generic/new_id
|
||||
helpers+=(%hv_fcopy_uio_daemon)
|
||||
fi
|
||||
fi
|
||||
if test -d /sys/bus/vmbus/devices
|
||||
then
|
||||
export PATH=${bindir}:\$PATH
|
||||
export PATH=${bindir}:$PATH
|
||||
echo -n "Starting hyper-v helpers:"
|
||||
for i in \
|
||||
%{hv_kvp_daemon} \
|
||||
%{hv_vss_daemon} \
|
||||
%{hv_fcopy_daemon}
|
||||
for i in "${helpers[@]}"
|
||||
do
|
||||
if mkdir /run/\$i
|
||||
if mkdir /run/$i
|
||||
then
|
||||
echo -n " \$i"
|
||||
\$i < /dev/null &
|
||||
echo -n " $i"
|
||||
$i < /dev/null &
|
||||
fi
|
||||
done
|
||||
echo " ... done"
|
||||
fi
|
||||
EOF
|
||||
chmod 755 $RPM_BUILD_ROOT${bindir}/${helper}
|
||||
_EOF_
|
||||
chmod 755 %buildroot${bindir}/${helper}
|
||||
#
|
||||
%python3_fix_shebang
|
||||
%?python3_fix_shebang
|
||||
|
||||
%files
|
||||
%doc kvptest.ps1.txt
|
||||
%{_unitdir}
|
||||
%dir /usr/lib/udev
|
||||
%{_udevrulesdir}
|
||||
%{_sbindir}/*
|
||||
%{helper_dir}
|
||||
%_unitdir/*
|
||||
%_udevrulesdir/*
|
||||
%_sbindir/*
|
||||
%helper_dir
|
||||
|
||||
%pre
|
||||
# hv_kvp_daemon in SLES11 SP2 stored temporary state files in /var/opt
|
||||
|
497
hyper-v.tools.hv.hv_fcopy_uio_daemon.c
Normal file
497
hyper-v.tools.hv.hv_fcopy_uio_daemon.c
Normal file
@ -0,0 +1,497 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* An implementation of host to guest copy functionality for Linux.
|
||||
*
|
||||
* Copyright (C) 2023, Microsoft, Inc.
|
||||
*
|
||||
* Author : K. Y. Srinivasan <kys@microsoft.com>
|
||||
* Author : Saurabh Sengar <ssengar@microsoft.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/hyperv.h>
|
||||
#include <linux/limits.h>
|
||||
#include "vmbus_bufring.h"
|
||||
|
||||
#define ICMSGTYPE_NEGOTIATE 0
|
||||
#define ICMSGTYPE_FCOPY 7
|
||||
|
||||
#define WIN8_SRV_MAJOR 1
|
||||
#define WIN8_SRV_MINOR 1
|
||||
#define WIN8_SRV_VERSION (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
|
||||
|
||||
#define MAX_FOLDER_NAME 15
|
||||
#define MAX_PATH_LEN 15
|
||||
#define FCOPY_UIO "/sys/bus/vmbus/devices/eb765408-105f-49b6-b4aa-c123b64d17d4/uio"
|
||||
|
||||
#define FCOPY_VER_COUNT 1
|
||||
static const int fcopy_versions[] = {
|
||||
WIN8_SRV_VERSION
|
||||
};
|
||||
|
||||
#define FW_VER_COUNT 1
|
||||
static const int fw_versions[] = {
|
||||
UTIL_FW_VERSION
|
||||
};
|
||||
|
||||
#define HV_RING_SIZE 0x4000 /* 16KB ring buffer size */
|
||||
|
||||
unsigned char desc[HV_RING_SIZE];
|
||||
|
||||
static int target_fd;
|
||||
static char target_fname[PATH_MAX];
|
||||
static unsigned long long filesize;
|
||||
|
||||
static int hv_fcopy_create_file(char *file_name, char *path_name, __u32 flags)
|
||||
{
|
||||
int error = HV_E_FAIL;
|
||||
char *q, *p;
|
||||
|
||||
filesize = 0;
|
||||
p = path_name;
|
||||
snprintf(target_fname, sizeof(target_fname), "%s/%s",
|
||||
path_name, file_name);
|
||||
|
||||
/*
|
||||
* Check to see if the path is already in place; if not,
|
||||
* create if required.
|
||||
*/
|
||||
while ((q = strchr(p, '/')) != NULL) {
|
||||
if (q == p) {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
*q = '\0';
|
||||
if (access(path_name, F_OK)) {
|
||||
if (flags & CREATE_PATH) {
|
||||
if (mkdir(path_name, 0755)) {
|
||||
syslog(LOG_ERR, "Failed to create %s",
|
||||
path_name);
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
syslog(LOG_ERR, "Invalid path: %s", path_name);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
p = q + 1;
|
||||
*q = '/';
|
||||
}
|
||||
|
||||
if (!access(target_fname, F_OK)) {
|
||||
syslog(LOG_INFO, "File: %s exists", target_fname);
|
||||
if (!(flags & OVER_WRITE)) {
|
||||
error = HV_ERROR_ALREADY_EXISTS;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
target_fd = open(target_fname,
|
||||
O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0744);
|
||||
if (target_fd == -1) {
|
||||
syslog(LOG_INFO, "Open Failed: %s", strerror(errno));
|
||||
goto done;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
done:
|
||||
if (error)
|
||||
target_fname[0] = '\0';
|
||||
return error;
|
||||
}
|
||||
|
||||
/* copy the data into the file */
|
||||
static int hv_copy_data(struct hv_do_fcopy *cpmsg)
|
||||
{
|
||||
ssize_t len;
|
||||
int ret = 0;
|
||||
|
||||
len = pwrite(target_fd, cpmsg->data, cpmsg->size, cpmsg->offset);
|
||||
|
||||
filesize += cpmsg->size;
|
||||
if (len != cpmsg->size) {
|
||||
switch (errno) {
|
||||
case ENOSPC:
|
||||
ret = HV_ERROR_DISK_FULL;
|
||||
break;
|
||||
default:
|
||||
ret = HV_E_FAIL;
|
||||
break;
|
||||
}
|
||||
syslog(LOG_ERR, "pwrite failed to write %llu bytes: %ld (%s)",
|
||||
filesize, (long)len, strerror(errno));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int hv_copy_finished(void)
|
||||
{
|
||||
close(target_fd);
|
||||
target_fname[0] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_usage(char *argv[])
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [options]\n"
|
||||
"Options are:\n"
|
||||
" -n, --no-daemon stay in foreground, don't daemonize\n"
|
||||
" -h, --help print this help\n", argv[0]);
|
||||
}
|
||||
|
||||
static bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, unsigned char *buf,
|
||||
unsigned int buflen, const int *fw_version, int fw_vercnt,
|
||||
const int *srv_version, int srv_vercnt,
|
||||
int *nego_fw_version, int *nego_srv_version)
|
||||
{
|
||||
int icframe_major, icframe_minor;
|
||||
int icmsg_major, icmsg_minor;
|
||||
int fw_major, fw_minor;
|
||||
int srv_major, srv_minor;
|
||||
int i, j;
|
||||
bool found_match = false;
|
||||
struct icmsg_negotiate *negop;
|
||||
|
||||
/* Check that there's enough space for icframe_vercnt, icmsg_vercnt */
|
||||
if (buflen < ICMSG_HDR + offsetof(struct icmsg_negotiate, reserved)) {
|
||||
syslog(LOG_ERR, "Invalid icmsg negotiate");
|
||||
return false;
|
||||
}
|
||||
|
||||
icmsghdrp->icmsgsize = 0x10;
|
||||
negop = (struct icmsg_negotiate *)&buf[ICMSG_HDR];
|
||||
|
||||
icframe_major = negop->icframe_vercnt;
|
||||
icframe_minor = 0;
|
||||
|
||||
icmsg_major = negop->icmsg_vercnt;
|
||||
icmsg_minor = 0;
|
||||
|
||||
/* Validate negop packet */
|
||||
if (icframe_major > IC_VERSION_NEGOTIATION_MAX_VER_COUNT ||
|
||||
icmsg_major > IC_VERSION_NEGOTIATION_MAX_VER_COUNT ||
|
||||
ICMSG_NEGOTIATE_PKT_SIZE(icframe_major, icmsg_major) > buflen) {
|
||||
syslog(LOG_ERR, "Invalid icmsg negotiate - icframe_major: %u, icmsg_major: %u\n",
|
||||
icframe_major, icmsg_major);
|
||||
goto fw_error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Select the framework version number we will
|
||||
* support.
|
||||
*/
|
||||
|
||||
for (i = 0; i < fw_vercnt; i++) {
|
||||
fw_major = (fw_version[i] >> 16);
|
||||
fw_minor = (fw_version[i] & 0xFFFF);
|
||||
|
||||
for (j = 0; j < negop->icframe_vercnt; j++) {
|
||||
if (negop->icversion_data[j].major == fw_major &&
|
||||
negop->icversion_data[j].minor == fw_minor) {
|
||||
icframe_major = negop->icversion_data[j].major;
|
||||
icframe_minor = negop->icversion_data[j].minor;
|
||||
found_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_match)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found_match)
|
||||
goto fw_error;
|
||||
|
||||
found_match = false;
|
||||
|
||||
for (i = 0; i < srv_vercnt; i++) {
|
||||
srv_major = (srv_version[i] >> 16);
|
||||
srv_minor = (srv_version[i] & 0xFFFF);
|
||||
|
||||
for (j = negop->icframe_vercnt;
|
||||
(j < negop->icframe_vercnt + negop->icmsg_vercnt);
|
||||
j++) {
|
||||
if (negop->icversion_data[j].major == srv_major &&
|
||||
negop->icversion_data[j].minor == srv_minor) {
|
||||
icmsg_major = negop->icversion_data[j].major;
|
||||
icmsg_minor = negop->icversion_data[j].minor;
|
||||
found_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_match)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Respond with the framework and service
|
||||
* version numbers we can support.
|
||||