diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-21 13:57:13 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-21 13:57:13 -0800 |
commit | 7ed214ac2095f561a94335ca672b6c42a1ea40ff (patch) | |
tree | da41901bff1d0d8d61170bf362384fdc61deb3ab /drivers/hv | |
parent | 21eaab6d19ed43e82ed39c8deb7f192134fb4a0e (diff) | |
parent | 29e5507ae4ab34397f538f06b7070c81a4e4a2bf (diff) | |
download | talos-op-linux-7ed214ac2095f561a94335ca672b6c42a1ea40ff.tar.gz talos-op-linux-7ed214ac2095f561a94335ca672b6c42a1ea40ff.zip |
Merge tag 'char-misc-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver patches from Greg Kroah-Hartman:
"Here's the big char/misc driver patches for 3.9-rc1.
Nothing major here, just lots of different driver updates (mei,
hyperv, ipack, extcon, vmci, etc.).
All of these have been in the linux-next tree for a while."
* tag 'char-misc-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (209 commits)
w1: w1_therm: Add force-pullup option for "broken" sensors
w1: ds2482: Added 1-Wire pull-up support to the driver
vme: add missing put_device() after device_register() fails
extcon: max8997: Use workqueue to check cable state after completing boot of platform
extcon: max8997: Set default UART/USB path on probe
extcon: max8997: Consolidate duplicate code for checking ADC/CHG cable type
extcon: max8997: Set default of ADC debounce time during initialization
extcon: max8997: Remove duplicate code related to set H/W line path
extcon: max8997: Move defined constant to header file
extcon: max77693: Make max77693_extcon_cable static
extcon: max8997: Remove unreachable code
extcon: max8997: Make max8997_extcon_cable static
extcon: max77693: Remove unnecessary goto statement to improve readability
extcon: max77693: Convert to devm_input_allocate_device()
extcon: gpio: Rename filename of extcon-gpio.c according to kernel naming style
CREDITS: update email and address of Harald Hoyer
extcon: arizona: Use MICDET for final microphone identification
extcon: arizona: Always take the first HPDET reading as the final one
extcon: arizona: Clear _trig_sts bits after jack detection
extcon: arizona: Don't HPDET magic when headphones are enabled
...
Diffstat (limited to 'drivers/hv')
-rw-r--r-- | drivers/hv/channel.c | 33 | ||||
-rw-r--r-- | drivers/hv/channel_mgmt.c | 93 | ||||
-rw-r--r-- | drivers/hv/connection.c | 232 | ||||
-rw-r--r-- | drivers/hv/hv.c | 72 | ||||
-rw-r--r-- | drivers/hv/hv_balloon.c | 63 | ||||
-rw-r--r-- | drivers/hv/hv_util.c | 46 | ||||
-rw-r--r-- | drivers/hv/hyperv_vmbus.h | 65 | ||||
-rw-r--r-- | drivers/hv/ring_buffer.c | 130 | ||||
-rw-r--r-- | drivers/hv/vmbus_drv.c | 54 |
9 files changed, 593 insertions, 195 deletions
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 773a2f25a8f0..0b122f8c7005 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -55,7 +55,7 @@ static void vmbus_setevent(struct vmbus_channel *channel) [channel->monitor_grp].pending); } else { - vmbus_set_event(channel->offermsg.child_relid); + vmbus_set_event(channel); } } @@ -181,7 +181,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, open_msg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle; open_msg->downstream_ringbuffer_pageoffset = send_ringbuffer_size >> PAGE_SHIFT; - open_msg->server_contextarea_gpadlhandle = 0; + open_msg->target_vp = newchannel->target_vp; if (userdatalen > MAX_USER_DEFINED_BYTES) { err = -EINVAL; @@ -564,6 +564,7 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, struct scatterlist bufferlist[3]; u64 aligned_data = 0; int ret; + bool signal = false; /* Setup the descriptor */ @@ -580,9 +581,9 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, sg_set_buf(&bufferlist[2], &aligned_data, packetlen_aligned - packetlen); - ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3); + ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); - if (ret == 0 && !hv_get_ringbuffer_interrupt_mask(&channel->outbound)) + if (ret == 0 && signal) vmbus_setevent(channel); return ret; @@ -606,6 +607,7 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, u32 packetlen_aligned; struct scatterlist bufferlist[3]; u64 aligned_data = 0; + bool signal = false; if (pagecount > MAX_PAGE_BUFFER_COUNT) return -EINVAL; @@ -641,9 +643,9 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, sg_set_buf(&bufferlist[2], &aligned_data, packetlen_aligned - packetlen); - ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3); + ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); - if (ret == 0 && !hv_get_ringbuffer_interrupt_mask(&channel->outbound)) + if (ret == 0 && signal) vmbus_setevent(channel); return ret; @@ -665,6 +667,7 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, u32 packetlen_aligned; struct scatterlist bufferlist[3]; u64 aligned_data = 0; + bool signal = false; u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->offset, multi_pagebuffer->len); @@ -703,9 +706,9 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, sg_set_buf(&bufferlist[2], &aligned_data, packetlen_aligned - packetlen); - ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3); + ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); - if (ret == 0 && !hv_get_ringbuffer_interrupt_mask(&channel->outbound)) + if (ret == 0 && signal) vmbus_setevent(channel); return ret; @@ -732,6 +735,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, u32 packetlen; u32 userlen; int ret; + bool signal = false; *buffer_actual_len = 0; *requestid = 0; @@ -758,8 +762,10 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, /* Copy over the packet to the user buffer */ ret = hv_ringbuffer_read(&channel->inbound, buffer, userlen, - (desc.offset8 << 3)); + (desc.offset8 << 3), &signal); + if (signal) + vmbus_setevent(channel); return 0; } @@ -774,8 +780,8 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, { struct vmpacket_descriptor desc; u32 packetlen; - u32 userlen; int ret; + bool signal = false; *buffer_actual_len = 0; *requestid = 0; @@ -788,7 +794,6 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, packetlen = desc.len8 << 3; - userlen = packetlen - (desc.offset8 << 3); *buffer_actual_len = packetlen; @@ -802,7 +807,11 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, *requestid = desc.trans_id; /* Copy over the entire packet to the user buffer */ - ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0); + ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0, + &signal); + + if (signal) + vmbus_setevent(channel); return 0; } diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 2f84c5cff8d4..53a8600162a5 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -257,6 +257,70 @@ static void vmbus_process_offer(struct work_struct *work) } } +enum { + IDE = 0, + SCSI, + NIC, + MAX_PERF_CHN, +}; + +/* + * This is an array of device_ids (device types) that are performance critical. + * We attempt to distribute the interrupt load for these devices across + * all available CPUs. + */ +static const struct hv_vmbus_device_id hp_devs[] = { + /* IDE */ + { HV_IDE_GUID, }, + /* Storage - SCSI */ + { HV_SCSI_GUID, }, + /* Network */ + { HV_NIC_GUID, }, +}; + + +/* + * We use this state to statically distribute the channel interrupt load. + */ +static u32 next_vp; + +/* + * Starting with Win8, we can statically distribute the incoming + * channel interrupt load by binding a channel to VCPU. We + * implement here a simple round robin scheme for distributing + * the interrupt load. + * We will bind channels that are not performance critical to cpu 0 and + * performance critical channels (IDE, SCSI and Network) will be uniformly + * distributed across all available CPUs. + */ +static u32 get_vp_index(uuid_le *type_guid) +{ + u32 cur_cpu; + int i; + bool perf_chn = false; + u32 max_cpus = num_online_cpus(); + + for (i = IDE; i < MAX_PERF_CHN; i++) { + if (!memcmp(type_guid->b, hp_devs[i].guid, + sizeof(uuid_le))) { + perf_chn = true; + break; + } + } + if ((vmbus_proto_version == VERSION_WS2008) || + (vmbus_proto_version == VERSION_WIN7) || (!perf_chn)) { + /* + * Prior to win8, all channel interrupts are + * delivered on cpu 0. + * Also if the channel is not a performance critical + * channel, bind it to cpu 0. + */ + return 0; + } + cur_cpu = (++next_vp % max_cpus); + return 0; +} + /* * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. * @@ -275,6 +339,35 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) return; } + /* + * By default we setup state to enable batched + * reading. A specific service can choose to + * disable this prior to opening the channel. + */ + newchannel->batched_reading = true; + + /* + * Setup state for signalling the host. + */ + newchannel->sig_event = (struct hv_input_signal_event *) + (ALIGN((unsigned long) + &newchannel->sig_buf, + HV_HYPERCALL_PARAM_ALIGN)); + + newchannel->sig_event->connectionid.asu32 = 0; + newchannel->sig_event->connectionid.u.id = VMBUS_EVENT_CONNECTION_ID; + newchannel->sig_event->flag_number = 0; + newchannel->sig_event->rsvdz = 0; + + if (vmbus_proto_version != VERSION_WS2008) { + newchannel->is_dedicated_interrupt = + (offer->is_dedicated_interrupt != 0); + newchannel->sig_event->connectionid.u.id = + offer->connection_id; + } + + newchannel->target_vp = get_vp_index(&offer->offer.if_type); + memcpy(&newchannel->offermsg, offer, sizeof(struct vmbus_channel_offer_channel)); newchannel->monitor_grp = (u8)offer->monitorid / 32; diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 650c9f0b6642..253a74ba245c 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -30,6 +30,7 @@ #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/hyperv.h> +#include <linux/export.h> #include <asm/hyperv.h> #include "hyperv_vmbus.h" @@ -40,15 +41,99 @@ struct vmbus_connection vmbus_connection = { }; /* + * Negotiated protocol version with the host. + */ +__u32 vmbus_proto_version; +EXPORT_SYMBOL_GPL(vmbus_proto_version); + +static __u32 vmbus_get_next_version(__u32 current_version) +{ + switch (current_version) { + case (VERSION_WIN7): + return VERSION_WS2008; + + case (VERSION_WIN8): + return VERSION_WIN7; + + case (VERSION_WS2008): + default: + return VERSION_INVAL; + } +} + +static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, + __u32 version) +{ + int ret = 0; + struct vmbus_channel_initiate_contact *msg; + unsigned long flags; + int t; + + init_completion(&msginfo->waitevent); + + msg = (struct vmbus_channel_initiate_contact *)msginfo->msg; + + msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT; + msg->vmbus_version_requested = version; + msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); + msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages); + msg->monitor_page2 = virt_to_phys( + (void *)((unsigned long)vmbus_connection.monitor_pages + + PAGE_SIZE)); + + /* + * Add to list before we send the request since we may + * receive the response before returning from this routine + */ + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); + list_add_tail(&msginfo->msglistentry, + &vmbus_connection.chn_msg_list); + + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + + ret = vmbus_post_msg(msg, + sizeof(struct vmbus_channel_initiate_contact)); + if (ret != 0) { + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); + list_del(&msginfo->msglistentry); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, + flags); + return ret; + } + + /* Wait for the connection response */ + t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ); + if (t == 0) { + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, + flags); + list_del(&msginfo->msglistentry); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, + flags); + return -ETIMEDOUT; + } + + spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); + list_del(&msginfo->msglistentry); + spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + + /* Check if successful */ + if (msginfo->response.version_response.version_supported) { + vmbus_connection.conn_state = CONNECTED; + } else { + return -ECONNREFUSED; + } + + return ret; +} + +/* * vmbus_connect - Sends a connect request on the partition service connection */ int vmbus_connect(void) { int ret = 0; - int t; struct vmbus_channel_msginfo *msginfo = NULL; - struct vmbus_channel_initiate_contact *msg; - unsigned long flags; + __u32 version; /* Initialize the vmbus connection */ vmbus_connection.conn_state = CONNECTING; @@ -99,69 +184,38 @@ int vmbus_connect(void) goto cleanup; } - init_completion(&msginfo->waitevent); - - msg = (struct vmbus_channel_initiate_contact *)msginfo->msg; - - msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT; - msg->vmbus_version_requested = VMBUS_REVISION_NUMBER; - msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); - msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages); - msg->monitor_page2 = virt_to_phys( - (void *)((unsigned long)vmbus_connection.monitor_pages + - PAGE_SIZE)); - /* - * Add to list before we send the request since we may - * receive the response before returning from this routine + * Negotiate a compatible VMBUS version number with the + * host. We start with the highest number we can support + * and work our way down until we negotiate a compatible + * version. */ - spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_add_tail(&msginfo->msglistentry, - &vmbus_connection.chn_msg_list); - spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + version = VERSION_CURRENT; - ret = vmbus_post_msg(msg, - sizeof(struct vmbus_channel_initiate_contact)); - if (ret != 0) { - spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_del(&msginfo->msglistentry); - spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, - flags); - goto cleanup; - } + do { + ret = vmbus_negotiate_version(msginfo, version); + if (ret == 0) + break; - /* Wait for the connection response */ - t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ); - if (t == 0) { - spin_lock_irqsave(&vmbus_connection.channelmsg_lock, - flags); - list_del(&msginfo->msglistentry); - spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, - flags); - ret = -ETIMEDOUT; - goto cleanup; - } + version = vmbus_get_next_version(version); + } while (version != VERSION_INVAL); - spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); - list_del(&msginfo->msglistentry); - spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); - - /* Check if successful */ - if (msginfo->response.version_response.version_supported) { - vmbus_connection.conn_state = CONNECTED; - } else { - pr_err("Unable to connect, " - "Version %d not supported by Hyper-V\n", - VMBUS_REVISION_NUMBER); - ret = -ECONNREFUSED; + if (version == VERSION_INVAL) goto cleanup; - } + + vmbus_proto_version = version; + pr_info("Hyper-V Host Build:%d-%d.%d-%d-%d.%d; Vmbus version:%d.%d\n", + host_info_eax, host_info_ebx >> 16, + host_info_ebx & 0xFFFF, host_info_ecx, + host_info_edx >> 24, host_info_edx & 0xFFFFFF, + version >> 16, version & 0xFFFF); kfree(msginfo); return 0; cleanup: + pr_err("Unable to connect to host\n"); vmbus_connection.conn_state = DISCONNECTED; if (vmbus_connection.work_queue) @@ -212,6 +266,9 @@ static void process_chn_event(u32 relid) { struct vmbus_channel *channel; unsigned long flags; + void *arg; + bool read_state; + u32 bytes_to_read; /* * Find the channel based on this relid and invokes the @@ -234,10 +291,29 @@ static void process_chn_event(u32 relid) */ spin_lock_irqsave(&channel->inbound_lock, flags); - if (channel->onchannel_callback != NULL) - channel->onchannel_callback(channel->channel_callback_context); - else + if (channel->onchannel_callback != NULL) { + arg = channel->channel_callback_context; + read_state = channel->batched_reading; + /* + * This callback reads the messages sent by the host. + * We can optimize host to guest signaling by ensuring: + * 1. While reading the channel, we disable interrupts from + * host. + * 2. Ensure that we process all posted messages from the host + * before returning from this callback. + * 3. Once we return, enable signaling from the host. Once this + * state is set we check to see if additional packets are + * available to read. In this case we repeat the process. + */ + + do { + hv_begin_read(&channel->inbound); + channel->onchannel_callback(arg); + bytes_to_read = hv_end_read(&channel->inbound); + } while (read_state && (bytes_to_read != 0)); + } else { pr_err("no channel callback for relid - %u\n", relid); + } spin_unlock_irqrestore(&channel->inbound_lock, flags); } @@ -248,10 +324,32 @@ static void process_chn_event(u32 relid) void vmbus_on_event(unsigned long data) { u32 dword; - u32 maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; + u32 maxdword; int bit; u32 relid; - u32 *recv_int_page = vmbus_connection.recv_int_page; + u32 *recv_int_page = NULL; + void *page_addr; + int cpu = smp_processor_id(); + union hv_synic_event_flags *event; + + if ((vmbus_proto_version == VERSION_WS2008) || + (vmbus_proto_version == VERSION_WIN7)) { + maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; + recv_int_page = vmbus_connection.recv_int_page; + } else { + /* + * When the host is win8 and beyond, the event page + * can be directly checked to get the id of the channel + * that has the interrupt pending. + */ + maxdword = HV_EVENT_FLAGS_DWORD_COUNT; + page_addr = hv_context.synic_event_page[cpu]; + event = (union hv_synic_event_flags *)page_addr + + VMBUS_MESSAGE_SINT; + recv_int_page = event->flags32; + } + + /* Check events */ if (!recv_int_page) @@ -307,12 +405,16 @@ int vmbus_post_msg(void *buffer, size_t buflen) /* * vmbus_set_event - Send an event notification to the parent */ -int vmbus_set_event(u32 child_relid) +int vmbus_set_event(struct vmbus_channel *channel) { - /* Each u32 represents 32 channels */ - sync_set_bit(child_relid & 31, - (unsigned long *)vmbus_connection.send_int_page + - (child_relid >> 5)); + u32 child_relid = channel->offermsg.child_relid; + + if (!channel->is_dedicated_interrupt) { + /* Each u32 represents 32 channels */ + sync_set_bit(child_relid & 31, + (unsigned long *)vmbus_connection.send_int_page + + (child_relid >> 5)); + } - return hv_signal_event(); + return hv_signal_event(channel->sig_event); } diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 3648f8f0f368..1c5481da6e4a 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -27,6 +27,7 @@ #include <linux/vmalloc.h> #include <linux/hyperv.h> #include <linux/version.h> +#include <linux/interrupt.h> #include <asm/hyperv.h> #include "hyperv_vmbus.h" @@ -34,13 +35,16 @@ struct hv_context hv_context = { .synic_initialized = false, .hypercall_page = NULL, - .signal_event_param = NULL, - .signal_event_buffer = NULL, }; /* * query_hypervisor_info - Get version info of the windows hypervisor */ +unsigned int host_info_eax; +unsigned int host_info_ebx; +unsigned int host_info_ecx; +unsigned int host_info_edx; + static int query_hypervisor_info(void) { unsigned int eax; @@ -70,13 +74,10 @@ static int query_hypervisor_info(void) edx = 0; op = HVCPUID_VERSION; cpuid(op, &eax, &ebx, &ecx, &edx); - pr_info("Hyper-V Host OS Build:%d-%d.%d-%d-%d.%d\n", - eax, - ebx >> 16, - ebx & 0xFFFF, - ecx, - edx >> 24, - edx & 0xFFFFFF); + host_info_eax = eax; + host_info_ebx = ebx; + host_info_ecx = ecx; + host_info_edx = edx; } return max_leaf; } @@ -137,6 +138,10 @@ int hv_init(void) memset(hv_context.synic_event_page, 0, sizeof(void *) * NR_CPUS); memset(hv_context.synic_message_page, 0, sizeof(void *) * NR_CPUS); + memset(hv_context.vp_index, 0, + sizeof(int) * NR_CPUS); + memset(hv_context.event_dpc, 0, + sizeof(void *) * NR_CPUS); max_leaf = query_hypervisor_info(); @@ -168,24 +173,6 @@ int hv_init(void) hv_context.hypercall_page = virtaddr; - /* Setup the global signal event param for the signal event hypercall */ - hv_context.signal_event_buffer = - kmalloc(sizeof(struct hv_input_signal_event_buffer), - GFP_KERNEL); - if (!hv_context.signal_event_buffer) - goto cleanup; - - hv_context.signal_event_param = - (struct hv_input_signal_event *) - (ALIGN((unsigned long) - hv_context.signal_event_buffer, - HV_HYPERCALL_PARAM_ALIGN)); - hv_context.signal_event_param->connectionid.asu32 = 0; - hv_context.signal_event_param->connectionid.u.id = - VMBUS_EVENT_CONNECTION_ID; - hv_context.signal_event_param->flag_number = 0; - hv_context.signal_event_param->rsvdz = 0; - return 0; cleanup: @@ -213,10 +200,6 @@ void hv_cleanup(void) /* Reset our OS id */ wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); - kfree(hv_context.signal_event_buffer); - hv_context.signal_event_buffer = NULL; - hv_context.signal_event_param = NULL; - if (hv_context.hypercall_page) { hypercall_msr.as_uint64 = 0; wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); @@ -273,13 +256,12 @@ int hv_post_message(union hv_connection_id connection_id, * * This involves a hypercall. */ -u16 hv_signal_event(void) +u16 hv_signal_event(void *con_id) { u16 status; - status = do_hypercall(HVCALL_SIGNAL_EVENT, - hv_context.signal_event_param, - NULL) & 0xFFFF; + status = (do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL) & 0xFFFF); + return status; } @@ -297,6 +279,7 @@ void hv_synic_init(void *irqarg) union hv_synic_siefp siefp; union hv_synic_sint shared_sint; union hv_synic_scontrol sctrl; + u64 vp_index; u32 irq_vector = *((u32 *)(irqarg)); int cpu = smp_processor_id(); @@ -307,6 +290,15 @@ void hv_synic_init(void *irqarg) /* Check the version */ rdmsrl(HV_X64_MSR_SVERSION, version); + hv_context.event_dpc[cpu] = (struct tasklet_struct *) + kmalloc(sizeof(struct tasklet_struct), + GFP_ATOMIC); + if (hv_context.event_dpc[cpu] == NULL) { + pr_err("Unable to allocate event dpc\n"); + goto cleanup; + } + tasklet_init(hv_context.event_dpc[cpu], vmbus_on_event, cpu); + hv_context.synic_message_page[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); @@ -345,7 +337,7 @@ void hv_synic_init(void *irqarg) shared_sint.as_uint64 = 0; shared_sint.vector = irq_vector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ shared_sint.masked = false; - shared_sint.auto_eoi = false; + shared_sint.auto_eoi = true; wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); @@ -356,6 +348,14 @@ void hv_synic_init(void *irqarg) wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); hv_context.synic_initialized = true; + + /* + * Setup the mapping between Hyper-V's notion + * of cpuid and Linux' notion of cpuid. + * This array will be indexed using Linux cpuid. + */ + rdmsrl(HV_X64_MSR_VP_INDEX, vp_index); + hv_context.vp_index[cpu] = (u32)vp_index; return; cleanup: diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index dd289fd179ca..37873213e24f 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -29,7 +29,6 @@ #include <linux/memory_hotplug.h> #include <linux/memory.h> #include <linux/notifier.h> -#include <linux/mman.h> #include <linux/percpu_counter.h> #include <linux/hyperv.h> @@ -415,10 +414,17 @@ struct dm_info_msg { static bool hot_add; static bool do_hot_add; +/* + * Delay reporting memory pressure by + * the specified number of seconds. + */ +static uint pressure_report_delay = 30; module_param(hot_add, bool, (S_IRUGO | S_IWUSR)); MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add"); +module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR)); +MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure"); static atomic_t trans_id = ATOMIC_INIT(0); static int dm_ring_size = (5 * PAGE_SIZE); @@ -517,6 +523,34 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg) } } +unsigned long compute_balloon_floor(void) +{ + unsigned long min_pages; +#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT)) + /* Simple continuous piecewiese linear function: + * max MiB -> min MiB gradient + * 0 0 + * 16 16 + * 32 24 + * 128 72 (1/2) + * 512 168 (1/4) + * 2048 360 (1/8) + * 8192 552 (1/32) + * 32768 1320 + * 131072 4392 + */ + if (totalram_pages < MB2PAGES(128)) + min_pages = MB2PAGES(8) + (totalram_pages >> 1); + else if (totalram_pages < MB2PAGES(512)) + min_pages = MB2PAGES(40) + (totalram_pages >> 2); + else if (totalram_pages < MB2PAGES(2048)) + min_pages = MB2PAGES(104) + (totalram_pages >> 3); + else + min_pages = MB2PAGES(296) + (totalram_pages >> 5); +#undef MB2PAGES + return min_pages; +} + /* * Post our status as it relates memory pressure to the * host. Host expects the guests to post this status @@ -530,15 +564,30 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg) static void post_status(struct hv_dynmem_device *dm) { struct dm_status status; + struct sysinfo val; - + if (pressure_report_delay > 0) { + --pressure_report_delay; + return; + } + si_meminfo(&val); memset(&status, 0, sizeof(struct dm_status)); status.hdr.type = DM_STATUS_REPORT; status.hdr.size = sizeof(struct dm_status); status.hdr.trans_id = atomic_inc_return(&trans_id); - - status.num_committed = vm_memory_committed(); + /* + * The host expects the guest to report free memory. + * Further, the host expects the pressure information to + * include the ballooned out pages. + * For a given amount of memory that we are managing, we + * need to compute a floor below which we should not balloon. + * Compute this and add it to the pressure report. + */ + status.num_avail = val.freeram; + status.num_committed = vm_memory_committed() + + dm->num_pages_ballooned + + compute_balloon_floor(); vmbus_sendpacket(dm->dev->channel, &status, sizeof(struct dm_status), @@ -547,8 +596,6 @@ static void post_status(struct hv_dynmem_device *dm) } - - static void free_balloon_pages(struct hv_dynmem_device *dm, union dm_mem_page_range *range_array) { @@ -1013,9 +1060,7 @@ static int balloon_remove(struct hv_device *dev) static const struct hv_vmbus_device_id id_table[] = { /* Dynamic Memory Class ID */ /* 525074DC-8985-46e2-8057-A307DC18A502 */ - { VMBUS_DEVICE(0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, - 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02) - }, + { HV_DM_GUID, }, { }, }; diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index a0667de7a04c..1d4cbd8e8261 100644 --- a/drivers/hv/hv_util.c +++ b/drivers/hv/hv_util.c @@ -49,6 +49,16 @@ static struct hv_util_service util_kvp = { .util_deinit = hv_kvp_deinit, }; +static void perform_shutdown(struct work_struct *dummy) +{ + orderly_poweroff(true); +} + +/* + * Perform the shutdown operation in a thread context. + */ +static DECLARE_WORK(shutdown_work, perform_shutdown); + static void shutdown_onchannelcallback(void *context) { struct vmbus_channel *channel = context; @@ -106,7 +116,7 @@ static void shutdown_onchannelcallback(void *context) } if (execute_shutdown == true) - orderly_poweroff(true); + schedule_work(&shutdown_work); } /* @@ -274,6 +284,16 @@ static int util_probe(struct hv_device *dev, } } + /* + * The set of services managed by the util driver are not performance + * critical and do not need batched reading. Furthermore, some services + * such as KVP can only handle one message from the host at a time. + * Turn off batched reading for all util drivers before we open the + * channel. + */ + + set_channel_read_state(dev->channel, false); + ret = vmbus_open(dev->channel, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL, 0, srv->util_cb, dev->channel); if (ret) @@ -304,21 +324,21 @@ static int util_remove(struct hv_device *dev) static const struct hv_vmbus_device_id id_table[] = { /* Shutdown guid */ - { VMBUS_DEVICE(0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49, - 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB) - .driver_data = (unsigned long)&util_shutdown }, + { HV_SHUTDOWN_GUID, + .driver_data = (unsigned long)&util_shutdown + }, /* Time synch guid */ - { VMBUS_DEVICE(0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, - 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf) - .driver_data = (unsigned long)&util_timesynch }, + { HV_TS_GUID, + .driver_data = (unsigned long)&util_timesynch + }, /* Heartbeat guid */ - { VMBUS_DEVICE(0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, - 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d) - .driver_data = (unsigned long)&util_heartbeat }, + { HV_HEART_BEAT_GUID, + .driver_data = (unsigned long)&util_heartbeat + }, /* KVP guid */ - { VMBUS_DEVICE(0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, - 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6) - .driver_data = (unsigned long)&util_kvp }, + { HV_KVP_GUID, + .driver_data = (unsigned long)&util_kvp + }, { }, }; diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index d8d1fadb398a..12f2f9e989f7 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -101,15 +101,6 @@ enum hv_message_type { /* Define invalid partition identifier. */ #define HV_PARTITION_ID_INVALID ((u64)0x0) -/* Define connection identifier type. */ -union hv_connection_id { - u32 asu32; - struct { - u32 id:24; - u32 reserved:8; - } u; -}; - /* Define port identifier type. */ union hv_port_id { u32 asu32; @@ -338,13 +329,6 @@ struct hv_input_post_message { u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; }; -/* Definition of the hv_signal_event hypercall input structure. */ -struct hv_input_signal_event { - union hv_connection_id connectionid; - u16 flag_number; - u16 rsvdz; -}; - /* * Versioning definitions used for guests reporting themselves to the * hypervisor, and visa versa. @@ -498,11 +482,6 @@ static const uuid_le VMBUS_SERVICE_ID = { -struct hv_input_signal_event_buffer { - u64 align8; - struct hv_input_signal_event event; -}; - struct hv_context { /* We only support running on top of Hyper-V * So at this point this really can only contain the Hyper-V ID @@ -513,16 +492,24 @@ struct hv_context { bool synic_initialized; - /* - * This is used as an input param to HvCallSignalEvent hypercall. The - * input param is immutable in our usage and must be dynamic mem (vs - * stack or global). */ - struct hv_input_signal_event_buffer *signal_event_buffer; - /* 8-bytes aligned of the buffer above */ - struct hv_input_signal_event *signal_event_param; - void *synic_message_page[NR_CPUS]; void *synic_event_page[NR_CPUS]; + /* + * Hypervisor's notion of virtual processor ID is different from + * Linux' notion of CPU ID. This information can only be retrieved + * in the context of the calling CPU. Setup a map for easy access + * to this information: + * + * vp_index[a] is the Hyper-V's processor ID corresponding to + * Linux cpuid 'a'. + */ + u32 vp_index[NR_CPUS]; + /* + * Starting with win8, we can take channel interrupts on any CPU; + * we will manage the tasklet that handles events on a per CPU + * basis. + */ + struct tasklet_struct *event_dpc[NR_CPUS]; }; extern struct hv_context hv_context; @@ -538,12 +525,19 @@ extern int hv_post_message(union hv_connection_id connection_id, enum hv_message_type message_type, void *payload, size_t payload_size); -extern u16 hv_signal_event(void); +extern u16 hv_signal_event(void *con_id); extern void hv_synic_init(void *irqarg); extern void hv_synic_cleanup(void *arg); +/* + * Host version information. + */ +extern unsigned int host_info_eax; +extern unsigned int host_info_ebx; +extern unsigned int host_info_ecx; +extern unsigned int host_info_edx; /* Interface */ @@ -555,7 +549,7 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info); int hv_ringbuffer_write(struct hv_ring_buffer_info *ring_info, struct scatterlist *sglist, - u32 sgcount); + u32 sgcount, bool *signal); int hv_ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer, u32 buflen); @@ -563,13 +557,16 @@ int hv_ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer, int hv_ringbuffer_read(struct hv_ring_buffer_info *ring_info, void *buffer, u32 buflen, - u32 offset); + u32 offset, bool *signal); -u32 hv_get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *ring_info); void hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, struct hv_ring_buffer_debug_info *debug_info); +void hv_begin_read(struct hv_ring_buffer_info *rbi); + +u32 hv_end_read(struct hv_ring_buffer_info *rbi); + /* * Maximum channels is determined by the size of the interrupt page * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt @@ -657,7 +654,7 @@ int vmbus_connect(void); int vmbus_post_msg(void *buffer, size_t buflen); -int vmbus_set_event(u32 child_relid); +int vmbus_set_event(struct vmbus_channel *channel); void vmbus_on_event(unsigned long data); diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 7233c88f01b8..cafa72ffdc30 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -29,6 +29,105 @@ #include "hyperv_vmbus.h" +void hv_begin_read(struct hv_ring_buffer_info *rbi) +{ + rbi->ring_buffer->interrupt_mask = 1; + smp_mb(); +} + +u32 hv_end_read(struct hv_ring_buffer_info *rbi) +{ + u32 read; + u32 write; + + rbi->ring_buffer->interrupt_mask = 0; + smp_mb(); + + /* + * Now check to see if the ring buffer is still empty. + * If it is not, we raced and we need to process new + * incoming messages. + */ + hv_get_ringbuffer_availbytes(rbi, &read, &write); + + return read; +} + +/* + * When we write to the ring buffer, check if the host needs to + * be signaled. Here is the details of this protocol: + * + * 1. The host guarantees that while it is draining the + * ring buffer, it will set the interrupt_mask to + * indicate it does not need to be interrupted when + * new data is placed. + * + * 2. The host guarantees that it will completely drain + * the ring buffer before exiting the read loop. Further, + * once the ring buffer is empty, it will clear the + * interrupt_mask and re-check to see if new data has + * arrived. + */ + +static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi) +{ + if (rbi->ring_buffer->interrupt_mask) + return false; + + /* + * This is the only case we need to signal when the + * ring transitions from being empty to non-empty. + */ + if (old_write == rbi->ring_buffer->read_index) + return true; + + return false; +} + +/* + * To optimize the flow management on the send-side, + * when the sender is blocked because of lack of + * sufficient space in the ring buffer, potential the + * consumer of the ring buffer can signal the producer. + * This is controlled by the following parameters: + * + * 1. pending_send_sz: This is the size in bytes that the + * producer is trying to send. + * 2. The feature bit feat_pending_send_sz set to indicate if + * the consumer of the ring will signal when the ring + * state transitions from being full to a state where + * there is room for the producer to send the pending packet. + */ + +static bool hv_need_to_signal_on_read(u32 old_rd, + struct hv_ring_buffer_info *rbi) +{ + u32 prev_write_sz; + u32 cur_write_sz; + u32 r_size; + u32 write_loc = rbi->ring_buffer->write_index; + u32 read_loc = rbi->ring_buffer->read_index; + u32 pending_sz = rbi->ring_buffer->pending_send_sz; + + /* + * If the other end is not blocked on write don't bother. + */ + if (pending_sz == 0) + return false; + + r_size = rbi->ring_datasize; + cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc) : + read_loc - write_loc; + + prev_write_sz = write_loc >= old_rd ? r_size - (write_loc - old_rd) : + old_rd - write_loc; + + + if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz)) + return true; + + return false; +} /* * hv_get_next_write_location() @@ -239,19 +338,6 @@ void hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, } } - -/* - * - * hv_get_ringbuffer_interrupt_mask() - * - * Get the interrupt mask for the specified ring buffer - * - */ -u32 hv_get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *rbi) -{ - return rbi->ring_buffer->interrupt_mask; -} - /* * * hv_ringbuffer_init() @@ -298,7 +384,7 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info) * */ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, - struct scatterlist *sglist, u32 sgcount) + struct scatterlist *sglist, u32 sgcount, bool *signal) { int i = 0; u32 bytes_avail_towrite; @@ -307,6 +393,7 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, struct scatterlist *sg; u32 next_write_location; + u32 old_write; u64 prev_indices = 0; unsigned long flags; @@ -335,6 +422,8 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, /* Write to the ring buffer */ next_write_location = hv_get_next_write_location(outring_info); + old_write = next_write_location; + for_each_sg(sglist, sg, sgcount, i) { next_write_location = hv_copyto_ringbuffer(outring_info, @@ -351,14 +440,16 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, &prev_indices, sizeof(u64)); - /* Make sure we flush all writes before updating the writeIndex */ - smp_wmb(); + /* Issue a full memory barrier before updating the write index */ + smp_mb(); /* Now, update the write location */ hv_set_next_write_location(outring_info, next_write_location); spin_unlock_irqrestore(&outring_info->ring_lock, flags); + + *signal = hv_need_to_signal(old_write, outring_info); return 0; } @@ -414,13 +505,14 @@ int hv_ringbuffer_peek(struct hv_ring_buffer_info *Inring_info, * */ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer, - u32 buflen, u32 offset) + u32 buflen, u32 offset, bool *signal) { u32 bytes_avail_towrite; u32 bytes_avail_toread; u32 next_read_location = 0; u64 prev_indices = 0; unsigned long flags; + u32 old_read; if (buflen <= 0) return -EINVAL; @@ -431,6 +523,8 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer, &bytes_avail_toread, &bytes_avail_towrite); + old_read = bytes_avail_toread; + /* Make sure there is something to read */ if (bytes_avail_toread < buflen) { spin_unlock_irqrestore(&inring_info->ring_lock, flags); @@ -461,5 +555,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer, spin_unlock_irqrestore(&inring_info->ring_lock, flags); + *signal = hv_need_to_signal_on_read(old_read, inring_info); + return 0; } diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 8e1a9ec53003..cf19dfa5ead1 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -33,6 +33,7 @@ #include <acpi/acpi_bus.h> #include <linux/completion.h> #include <linux/hyperv.h> +#include <linux/kernel_stat.h> #include <asm/hyperv.h> #include <asm/hypervisor.h> #include "hyperv_vmbus.h" @@ -41,7 +42,6 @@ static struct acpi_device *hv_acpi_dev; static struct tasklet_struct msg_dpc; -static struct tasklet_struct event_dpc; static struct completion probe_event; static int irq; @@ -454,21 +454,40 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id) union hv_synic_event_flags *event; bool handled = false; + page_addr = hv_context.synic_event_page[cpu]; + if (page_addr == NULL) + return IRQ_NONE; + + event = (union hv_synic_event_flags *)page_addr + + VMBUS_MESSAGE_SINT; /* * Check for events before checking for messages. This is the order * in which events and messages are checked in Windows guests on * Hyper-V, and the Windows team suggested we do the same. */ - page_addr = hv_context.synic_event_page[cpu]; - event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT; + if ((vmbus_proto_version == VERSION_WS2008) || + (vmbus_proto_version == VERSION_WIN7)) { - /* Since we are a child, we only need to check bit 0 */ - if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) { + /* Since we are a child, we only need to check bit 0 */ + if (sync_test_and_clear_bit(0, + (unsigned long *) &event->flags32[0])) { + handled = true; + } + } else { + /* + * Our host is win8 or above. The signaling mechanism + * has changed and we can directly look at the event page. + * If bit n is set then we have an interrup on the channel + * whose id is n. + */ handled = true; - tasklet_schedule(&event_dpc); } + if (handled) + tasklet_schedule(hv_context.event_dpc[cpu]); + + page_addr = hv_context.synic_message_page[cpu]; msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; @@ -485,6 +504,19 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id) } /* + * vmbus interrupt flow handler: + * vmbus interrupts can concurrently occur on multiple CPUs and + * can be handled concurrently. + */ + +static void vmbus_flow_handler(unsigned int irq, struct irq_desc *desc) +{ + kstat_incr_irqs_this_cpu(irq, desc); + + desc->action->handler(irq, desc->action->dev_id); +} + +/* * vmbus_bus_init -Main vmbus driver initialization routine. * * Here, we @@ -506,7 +538,6 @@ static int vmbus_bus_init(int irq) } tasklet_init(&msg_dpc, vmbus_on_msg_dpc, 0); - tasklet_init(&event_dpc, vmbus_on_event, 0); ret = bus_register(&hv_bus); if (ret) @@ -520,6 +551,13 @@ static int vmbus_bus_init(int irq) goto err_unregister; } + /* + * Vmbus interrupts can be handled concurrently on + * different CPUs. Establish an appropriate interrupt flow + * handler that can support this model. + */ + irq_set_handler(irq, vmbus_flow_handler); + vector = IRQ0_VECTOR + irq; /* @@ -575,8 +613,6 @@ int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, c ret = driver_register(&hv_driver->driver); - vmbus_request_offers(); - return ret; } EXPORT_SYMBOL_GPL(__vmbus_driver_register); |