aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hv
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-02-15 13:48:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-15 13:48:44 -0500
commit4ba63072b998cc31515cc6305c25f3b808b50c01 (patch)
tree779863511765c70bfd232f676b885f940ba88722 /drivers/hv
parente29876723f7cb7728f0d6a674d23f92673e9f112 (diff)
parent5fb31cd839c21130c0b2524ceb9244e98dfe10e3 (diff)
Merge tag 'char-misc-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char / misc patches from Greg KH: "Here's the big char/misc driver update for 3.20-rc1. Lots of little things in here, all described in the changelog. Nothing major or unusual, except maybe the binder selinux stuff, which was all acked by the proper selinux people and they thought it best to come through this tree. All of this has been in linux-next with no reported issues for a while" * tag 'char-misc-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (90 commits) coresight: fix function etm_writel_cp14() parameter order coresight-etm: remove check for unknown Kconfig macro coresight: fixing CPU hwid lookup in device tree coresight: remove the unnecessary function coresight_is_bit_set() coresight: fix the debug AMBA bus name coresight: remove the extra spaces coresight: fix the link between orphan connection and newly added device coresight: remove the unnecessary replicator property coresight: fix the replicator subtype value pdfdocs: Fix 'make pdfdocs' failure for 'uio-howto.tmpl' mcb: Fix error path of mcb_pci_probe virtio/console: verify device has config space ti-st: clean up data types (fix harmless memory corruption) mei: me: release hw from reset only during the reset flow mei: mask interrupt set bit on clean reset bit extcon: max77693: Constify struct regmap_config extcon: adc-jack: Release IIO channel on driver remove extcon: Remove duplicated include from extcon-class.c Drivers: hv: vmbus: hv_process_timer_expiration() can be static Drivers: hv: vmbus: serialize Offer and Rescind offer ...
Diffstat (limited to 'drivers/hv')
-rw-r--r--drivers/hv/channel.c54
-rw-r--r--drivers/hv/channel_mgmt.c54
-rw-r--r--drivers/hv/connection.c6
-rw-r--r--drivers/hv/hv.c78
-rw-r--r--drivers/hv/hv_balloon.c88
-rw-r--r--drivers/hv/hv_fcopy.c27
-rw-r--r--drivers/hv/hyperv_vmbus.h21
-rw-r--r--drivers/hv/vmbus_drv.c37
8 files changed, 323 insertions, 42 deletions
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 433f72a1c006..2978f5ee8d2a 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -73,14 +73,14 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
73 unsigned long flags; 73 unsigned long flags;
74 int ret, t, err = 0; 74 int ret, t, err = 0;
75 75
76 spin_lock_irqsave(&newchannel->sc_lock, flags); 76 spin_lock_irqsave(&newchannel->lock, flags);
77 if (newchannel->state == CHANNEL_OPEN_STATE) { 77 if (newchannel->state == CHANNEL_OPEN_STATE) {
78 newchannel->state = CHANNEL_OPENING_STATE; 78 newchannel->state = CHANNEL_OPENING_STATE;
79 } else { 79 } else {
80 spin_unlock_irqrestore(&newchannel->sc_lock, flags); 80 spin_unlock_irqrestore(&newchannel->lock, flags);
81 return -EINVAL; 81 return -EINVAL;
82 } 82 }
83 spin_unlock_irqrestore(&newchannel->sc_lock, flags); 83 spin_unlock_irqrestore(&newchannel->lock, flags);
84 84
85 newchannel->onchannel_callback = onchannelcallback; 85 newchannel->onchannel_callback = onchannelcallback;
86 newchannel->channel_callback_context = context; 86 newchannel->channel_callback_context = context;
@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
366 unsigned long flags; 366 unsigned long flags;
367 int ret = 0; 367 int ret = 0;
368 368
369 next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle); 369 next_gpadl_handle =
370 atomic_inc(&vmbus_connection.next_gpadl_handle); 370 (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1);
371 371
372 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount); 372 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
373 if (ret) 373 if (ret)
@@ -686,6 +686,50 @@ EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer);
686/* 686/*
687 * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet 687 * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet
688 * using a GPADL Direct packet type. 688 * using a GPADL Direct packet type.
689 * The buffer includes the vmbus descriptor.
690 */
691int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
692 struct vmbus_packet_mpb_array *desc,
693 u32 desc_size,
694 void *buffer, u32 bufferlen, u64 requestid)
695{
696 int ret;
697 u32 packetlen;
698 u32 packetlen_aligned;
699 struct kvec bufferlist[3];
700 u64 aligned_data = 0;
701 bool signal = false;
702
703 packetlen = desc_size + bufferlen;
704 packetlen_aligned = ALIGN(packetlen, sizeof(u64));
705
706 /* Setup the descriptor */
707 desc->type = VM_PKT_DATA_USING_GPA_DIRECT;
708 desc->flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
709 desc->dataoffset8 = desc_size >> 3; /* in 8-bytes grandularity */
710 desc->length8 = (u16)(packetlen_aligned >> 3);
711 desc->transactionid = requestid;
712 desc->rangecount = 1;
713
714 bufferlist[0].iov_base = desc;
715 bufferlist[0].iov_len = desc_size;
716 bufferlist[1].iov_base = buffer;
717 bufferlist[1].iov_len = bufferlen;
718 bufferlist[2].iov_base = &aligned_data;
719 bufferlist[2].iov_len = (packetlen_aligned - packetlen);
720
721 ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal);
722
723 if (ret == 0 && signal)
724 vmbus_setevent(channel);
725
726 return ret;
727}
728EXPORT_SYMBOL_GPL(vmbus_sendpacket_mpb_desc);
729
730/*
731 * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet
732 * using a GPADL Direct packet type.
689 */ 733 */
690int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, 734int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
691 struct hv_multipage_buffer *multi_pagebuffer, 735 struct hv_multipage_buffer *multi_pagebuffer,
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 2c59f030546b..3736f71bdec5 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -146,7 +146,7 @@ static struct vmbus_channel *alloc_channel(void)
146 return NULL; 146 return NULL;
147 147
148 spin_lock_init(&channel->inbound_lock); 148 spin_lock_init(&channel->inbound_lock);
149 spin_lock_init(&channel->sc_lock); 149 spin_lock_init(&channel->lock);
150 150
151 INIT_LIST_HEAD(&channel->sc_list); 151 INIT_LIST_HEAD(&channel->sc_list);
152 INIT_LIST_HEAD(&channel->percpu_list); 152 INIT_LIST_HEAD(&channel->percpu_list);
@@ -246,9 +246,9 @@ static void vmbus_process_rescind_offer(struct work_struct *work)
246 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); 246 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
247 } else { 247 } else {
248 primary_channel = channel->primary_channel; 248 primary_channel = channel->primary_channel;
249 spin_lock_irqsave(&primary_channel->sc_lock, flags); 249 spin_lock_irqsave(&primary_channel->lock, flags);
250 list_del(&channel->sc_list); 250 list_del(&channel->sc_list);
251 spin_unlock_irqrestore(&primary_channel->sc_lock, flags); 251 spin_unlock_irqrestore(&primary_channel->lock, flags);
252 } 252 }
253 free_channel(channel); 253 free_channel(channel);
254} 254}
@@ -279,9 +279,6 @@ static void vmbus_process_offer(struct work_struct *work)
279 int ret; 279 int ret;
280 unsigned long flags; 280 unsigned long flags;
281 281
282 /* The next possible work is rescind handling */
283 INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
284
285 /* Make sure this is a new offer */ 282 /* Make sure this is a new offer */
286 spin_lock_irqsave(&vmbus_connection.channel_lock, flags); 283 spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
287 284
@@ -323,9 +320,9 @@ static void vmbus_process_offer(struct work_struct *work)
323 * Process the sub-channel. 320 * Process the sub-channel.
324 */ 321 */
325 newchannel->primary_channel = channel; 322 newchannel->primary_channel = channel;
326 spin_lock_irqsave(&channel->sc_lock, flags); 323 spin_lock_irqsave(&channel->lock, flags);
327 list_add_tail(&newchannel->sc_list, &channel->sc_list); 324 list_add_tail(&newchannel->sc_list, &channel->sc_list);
328 spin_unlock_irqrestore(&channel->sc_lock, flags); 325 spin_unlock_irqrestore(&channel->lock, flags);
329 326
330 if (newchannel->target_cpu != get_cpu()) { 327 if (newchannel->target_cpu != get_cpu()) {
331 put_cpu(); 328 put_cpu();
@@ -341,11 +338,10 @@ static void vmbus_process_offer(struct work_struct *work)
341 if (channel->sc_creation_callback != NULL) 338 if (channel->sc_creation_callback != NULL)
342 channel->sc_creation_callback(newchannel); 339 channel->sc_creation_callback(newchannel);
343 340
344 return; 341 goto done_init_rescind;
345 } 342 }
346 343
347 free_channel(newchannel); 344 goto err_free_chan;
348 return;
349 } 345 }
350 346
351 /* 347 /*
@@ -364,6 +360,8 @@ static void vmbus_process_offer(struct work_struct *work)
364 &newchannel->offermsg.offer.if_type, 360 &newchannel->offermsg.offer.if_type,
365 &newchannel->offermsg.offer.if_instance, 361 &newchannel->offermsg.offer.if_instance,
366 newchannel); 362 newchannel);
363 if (!newchannel->device_obj)
364 goto err_free_chan;
367 365
368 /* 366 /*
369 * Add the new device to the bus. This will kick off device-driver 367 * Add the new device to the bus. This will kick off device-driver
@@ -379,9 +377,19 @@ static void vmbus_process_offer(struct work_struct *work)
379 list_del(&newchannel->listentry); 377 list_del(&newchannel->listentry);
380 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); 378 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
381 kfree(newchannel->device_obj); 379 kfree(newchannel->device_obj);
382 380 goto err_free_chan;
383 free_channel(newchannel);
384 } 381 }
382done_init_rescind:
383 spin_lock_irqsave(&newchannel->lock, flags);
384 /* The next possible work is rescind handling */
385 INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
386 /* Check if rescind offer was already received */
387 if (newchannel->rescind)
388 queue_work(newchannel->controlwq, &newchannel->work);
389 spin_unlock_irqrestore(&newchannel->lock, flags);
390 return;
391err_free_chan:
392 free_channel(newchannel);
385} 393}
386 394
387enum { 395enum {
@@ -516,6 +524,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
516{ 524{
517 struct vmbus_channel_rescind_offer *rescind; 525 struct vmbus_channel_rescind_offer *rescind;
518 struct vmbus_channel *channel; 526 struct vmbus_channel *channel;
527 unsigned long flags;
519 528
520 rescind = (struct vmbus_channel_rescind_offer *)hdr; 529 rescind = (struct vmbus_channel_rescind_offer *)hdr;
521 channel = relid2channel(rescind->child_relid); 530 channel = relid2channel(rescind->child_relid);
@@ -524,11 +533,20 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
524 /* Just return here, no channel found */ 533 /* Just return here, no channel found */
525 return; 534 return;
526 535
536 spin_lock_irqsave(&channel->lock, flags);
527 channel->rescind = true; 537 channel->rescind = true;
538 /*
539 * channel->work.func != vmbus_process_rescind_offer means we are still
540 * processing offer request and the rescind offer processing should be
541 * postponed. It will be done at the very end of vmbus_process_offer()
542 * as rescind flag is being checked there.
543 */
544 if (channel->work.func == vmbus_process_rescind_offer)
545 /* work is initialized for vmbus_process_rescind_offer() from
546 * vmbus_process_offer() where the channel got created */
547 queue_work(channel->controlwq, &channel->work);
528 548
529 /* work is initialized for vmbus_process_rescind_offer() from 549 spin_unlock_irqrestore(&channel->lock, flags);
530 * vmbus_process_offer() where the channel got created */
531 queue_work(channel->controlwq, &channel->work);
532} 550}
533 551
534/* 552/*
@@ -815,7 +833,7 @@ cleanup:
815struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary) 833struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary)
816{ 834{
817 struct list_head *cur, *tmp; 835 struct list_head *cur, *tmp;
818 int cur_cpu = hv_context.vp_index[smp_processor_id()]; 836 int cur_cpu;
819 struct vmbus_channel *cur_channel; 837 struct vmbus_channel *cur_channel;
820 struct vmbus_channel *outgoing_channel = primary; 838 struct vmbus_channel *outgoing_channel = primary;
821 int cpu_distance, new_cpu_distance; 839 int cpu_distance, new_cpu_distance;
@@ -823,6 +841,8 @@ struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary)
823 if (list_empty(&primary->sc_list)) 841 if (list_empty(&primary->sc_list))
824 return outgoing_channel; 842 return outgoing_channel;
825 843
844 cur_cpu = hv_context.vp_index[get_cpu()];
845 put_cpu();
826 list_for_each_safe(cur, tmp, &primary->sc_list) { 846 list_for_each_safe(cur, tmp, &primary->sc_list) {
827 cur_channel = list_entry(cur, struct vmbus_channel, sc_list); 847 cur_channel = list_entry(cur, struct vmbus_channel, sc_list);
828 if (cur_channel->state != CHANNEL_OPENED_STATE) 848 if (cur_channel->state != CHANNEL_OPENED_STATE)
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index e206619b946e..a63a795300b9 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -80,8 +80,10 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
80 msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); 80 msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
81 msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]); 81 msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]);
82 msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]); 82 msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]);
83 if (version == VERSION_WIN8_1) 83 if (version == VERSION_WIN8_1) {
84 msg->target_vcpu = hv_context.vp_index[smp_processor_id()]; 84 msg->target_vcpu = hv_context.vp_index[get_cpu()];
85 put_cpu();
86 }
85 87
86 /* 88 /*
87 * Add to list before we send the request since we may 89 * Add to list before we send the request since we may
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 3e4235c7a47f..50e51a51ff8b 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -28,7 +28,9 @@
28#include <linux/hyperv.h> 28#include <linux/hyperv.h>
29#include <linux/version.h> 29#include <linux/version.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/clockchips.h>
31#include <asm/hyperv.h> 32#include <asm/hyperv.h>
33#include <asm/mshyperv.h>
32#include "hyperv_vmbus.h" 34#include "hyperv_vmbus.h"
33 35
34/* The one and only */ 36/* The one and only */
@@ -37,6 +39,10 @@ struct hv_context hv_context = {
37 .hypercall_page = NULL, 39 .hypercall_page = NULL,
38}; 40};
39 41
42#define HV_TIMER_FREQUENCY (10 * 1000 * 1000) /* 100ns period */
43#define HV_MAX_MAX_DELTA_TICKS 0xffffffff
44#define HV_MIN_DELTA_TICKS 1
45
40/* 46/*
41 * query_hypervisor_info - Get version info of the windows hypervisor 47 * query_hypervisor_info - Get version info of the windows hypervisor
42 */ 48 */
@@ -144,6 +150,8 @@ int hv_init(void)
144 sizeof(int) * NR_CPUS); 150 sizeof(int) * NR_CPUS);
145 memset(hv_context.event_dpc, 0, 151 memset(hv_context.event_dpc, 0,
146 sizeof(void *) * NR_CPUS); 152 sizeof(void *) * NR_CPUS);
153 memset(hv_context.clk_evt, 0,
154 sizeof(void *) * NR_CPUS);
147 155
148 max_leaf = query_hypervisor_info(); 156 max_leaf = query_hypervisor_info();
149 157
@@ -258,10 +266,63 @@ u16 hv_signal_event(void *con_id)
258 return status; 266 return status;
259} 267}
260 268
269static int hv_ce_set_next_event(unsigned long delta,
270 struct clock_event_device *evt)
271{
272 cycle_t current_tick;
273
274 WARN_ON(evt->mode != CLOCK_EVT_MODE_ONESHOT);
275
276 rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
277 current_tick += delta;
278 wrmsrl(HV_X64_MSR_STIMER0_COUNT, current_tick);
279 return 0;
280}
281
282static void hv_ce_setmode(enum clock_event_mode mode,
283 struct clock_event_device *evt)
284{
285 union hv_timer_config timer_cfg;
286
287 switch (mode) {
288 case CLOCK_EVT_MODE_PERIODIC:
289 /* unsupported */
290 break;
291
292 case CLOCK_EVT_MODE_ONESHOT:
293 timer_cfg.enable = 1;
294 timer_cfg.auto_enable = 1;
295 timer_cfg.sintx = VMBUS_MESSAGE_SINT;
296 wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
297 break;
298
299 case CLOCK_EVT_MODE_UNUSED:
300 case CLOCK_EVT_MODE_SHUTDOWN:
301 wrmsrl(HV_X64_MSR_STIMER0_COUNT, 0);
302 wrmsrl(HV_X64_MSR_STIMER0_CONFIG, 0);
303 break;
304 case CLOCK_EVT_MODE_RESUME:
305 break;
306 }
307}
308
309static void hv_init_clockevent_device(struct clock_event_device *dev, int cpu)
310{
311 dev->name = "Hyper-V clockevent";
312 dev->features = CLOCK_EVT_FEAT_ONESHOT;
313 dev->cpumask = cpumask_of(cpu);
314 dev->rating = 1000;
315 dev->owner = THIS_MODULE;
316
317 dev->set_mode = hv_ce_setmode;
318 dev->set_next_event = hv_ce_set_next_event;
319}
320
261 321
262int hv_synic_alloc(void) 322int hv_synic_alloc(void)
263{ 323{
264 size_t size = sizeof(struct tasklet_struct); 324 size_t size = sizeof(struct tasklet_struct);
325 size_t ced_size = sizeof(struct clock_event_device);
265 int cpu; 326 int cpu;
266 327
267 for_each_online_cpu(cpu) { 328 for_each_online_cpu(cpu) {
@@ -272,6 +333,13 @@ int hv_synic_alloc(void)
272 } 333 }
273 tasklet_init(hv_context.event_dpc[cpu], vmbus_on_event, cpu); 334 tasklet_init(hv_context.event_dpc[cpu], vmbus_on_event, cpu);
274 335
336 hv_context.clk_evt[cpu] = kzalloc(ced_size, GFP_ATOMIC);
337 if (hv_context.clk_evt[cpu] == NULL) {
338 pr_err("Unable to allocate clock event device\n");
339 goto err;
340 }
341 hv_init_clockevent_device(hv_context.clk_evt[cpu], cpu);
342
275 hv_context.synic_message_page[cpu] = 343 hv_context.synic_message_page[cpu] =
276 (void *)get_zeroed_page(GFP_ATOMIC); 344 (void *)get_zeroed_page(GFP_ATOMIC);
277 345
@@ -305,6 +373,7 @@ err:
305static void hv_synic_free_cpu(int cpu) 373static void hv_synic_free_cpu(int cpu)
306{ 374{
307 kfree(hv_context.event_dpc[cpu]); 375 kfree(hv_context.event_dpc[cpu]);
376 kfree(hv_context.clk_evt[cpu]);
308 if (hv_context.synic_event_page[cpu]) 377 if (hv_context.synic_event_page[cpu])
309 free_page((unsigned long)hv_context.synic_event_page[cpu]); 378 free_page((unsigned long)hv_context.synic_event_page[cpu]);
310 if (hv_context.synic_message_page[cpu]) 379 if (hv_context.synic_message_page[cpu])
@@ -388,6 +457,15 @@ void hv_synic_init(void *arg)
388 hv_context.vp_index[cpu] = (u32)vp_index; 457 hv_context.vp_index[cpu] = (u32)vp_index;
389 458
390 INIT_LIST_HEAD(&hv_context.percpu_list[cpu]); 459 INIT_LIST_HEAD(&hv_context.percpu_list[cpu]);
460
461 /*
462 * Register the per-cpu clockevent source.
463 */
464 if (ms_hyperv.features & HV_X64_MSR_SYNTIMER_AVAILABLE)
465 clockevents_config_and_register(hv_context.clk_evt[cpu],
466 HV_TIMER_FREQUENCY,
467 HV_MIN_DELTA_TICKS,
468 HV_MAX_MAX_DELTA_TICKS);
391 return; 469 return;
392} 470}
393 471
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index b958ded8ac7e..ff169386b2c7 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -533,6 +533,9 @@ struct hv_dynmem_device {
533 */ 533 */
534 struct task_struct *thread; 534 struct task_struct *thread;
535 535
536 struct mutex ha_region_mutex;
537 struct completion waiter_event;
538
536 /* 539 /*
537 * A list of hot-add regions. 540 * A list of hot-add regions.
538 */ 541 */
@@ -549,7 +552,59 @@ struct hv_dynmem_device {
549static struct hv_dynmem_device dm_device; 552static struct hv_dynmem_device dm_device;
550 553
551static void post_status(struct hv_dynmem_device *dm); 554static void post_status(struct hv_dynmem_device *dm);
555
552#ifdef CONFIG_MEMORY_HOTPLUG 556#ifdef CONFIG_MEMORY_HOTPLUG
557static void acquire_region_mutex(bool trylock)
558{
559 if (trylock) {
560 reinit_completion(&dm_device.waiter_event);
561 while (!mutex_trylock(&dm_device.ha_region_mutex))
562 wait_for_completion(&dm_device.waiter_event);
563 } else {
564 mutex_lock(&dm_device.ha_region_mutex);
565 }
566}
567
568static void release_region_mutex(bool trylock)
569{
570 if (trylock) {
571 mutex_unlock(&dm_device.ha_region_mutex);
572 } else {
573 mutex_unlock(&dm_device.ha_region_mutex);
574 complete(&dm_device.waiter_event);
575 }
576}
577
578static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
579 void *v)
580{
581 switch (val) {
582 case MEM_GOING_ONLINE:
583 acquire_region_mutex(true);
584 break;
585
586 case MEM_ONLINE:
587 case MEM_CANCEL_ONLINE:
588 release_region_mutex(true);
589 if (dm_device.ha_waiting) {
590 dm_device.ha_waiting = false;
591 complete(&dm_device.ol_waitevent);
592 }
593 break;
594
595 case MEM_GOING_OFFLINE:
596 case MEM_OFFLINE:
597 case MEM_CANCEL_OFFLINE:
598 break;
599 }
600 return NOTIFY_OK;
601}
602
603static struct notifier_block hv_memory_nb = {
604 .notifier_call = hv_memory_notifier,
605 .priority = 0
606};
607
553 608
554static void hv_bring_pgs_online(unsigned long start_pfn, unsigned long size) 609static void hv_bring_pgs_online(unsigned long start_pfn, unsigned long size)
555{ 610{
@@ -591,6 +646,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
591 init_completion(&dm_device.ol_waitevent); 646 init_completion(&dm_device.ol_waitevent);
592 dm_device.ha_waiting = true; 647 dm_device.ha_waiting = true;
593 648
649 release_region_mutex(false);
594 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); 650 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
595 ret = add_memory(nid, PFN_PHYS((start_pfn)), 651 ret = add_memory(nid, PFN_PHYS((start_pfn)),
596 (HA_CHUNK << PAGE_SHIFT)); 652 (HA_CHUNK << PAGE_SHIFT));
@@ -619,6 +675,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
619 * have not been "onlined" within the allowed time. 675 * have not been "onlined" within the allowed time.
620 */ 676 */
621 wait_for_completion_timeout(&dm_device.ol_waitevent, 5*HZ); 677 wait_for_completion_timeout(&dm_device.ol_waitevent, 5*HZ);
678 acquire_region_mutex(false);
622 post_status(&dm_device); 679 post_status(&dm_device);
623 } 680 }
624 681
@@ -632,11 +689,6 @@ static void hv_online_page(struct page *pg)
632 unsigned long cur_start_pgp; 689 unsigned long cur_start_pgp;
633 unsigned long cur_end_pgp; 690 unsigned long cur_end_pgp;
634 691
635 if (dm_device.ha_waiting) {
636 dm_device.ha_waiting = false;
637 complete(&dm_device.ol_waitevent);
638 }
639
640 list_for_each(cur, &dm_device.ha_region_list) { 692 list_for_each(cur, &dm_device.ha_region_list) {
641 has = list_entry(cur, struct hv_hotadd_state, list); 693 has = list_entry(cur, struct hv_hotadd_state, list);
642 cur_start_pgp = (unsigned long) 694 cur_start_pgp = (unsigned long)
@@ -834,6 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
834 resp.hdr.size = sizeof(struct dm_hot_add_response); 886 resp.hdr.size = sizeof(struct dm_hot_add_response);
835 887
836#ifdef CONFIG_MEMORY_HOTPLUG 888#ifdef CONFIG_MEMORY_HOTPLUG
889 acquire_region_mutex(false);
837 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page; 890 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
838 pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt; 891 pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt;
839 892
@@ -865,6 +918,7 @@ static void hot_add_req(struct work_struct *dummy)
865 if (do_hot_add) 918 if (do_hot_add)
866 resp.page_count = process_hot_add(pg_start, pfn_cnt, 919 resp.page_count = process_hot_add(pg_start, pfn_cnt,
867 rg_start, rg_sz); 920 rg_start, rg_sz);
921 release_region_mutex(false);
868#endif 922#endif
869 /* 923 /*
870 * The result field of the response structure has the 924 * The result field of the response structure has the
@@ -928,9 +982,8 @@ static unsigned long compute_balloon_floor(void)
928 * 128 72 (1/2) 982 * 128 72 (1/2)
929 * 512 168 (1/4) 983 * 512 168 (1/4)
930 * 2048 360 (1/8) 984 * 2048 360 (1/8)
931 * 8192 552 (1/32) 985 * 8192 768 (1/16)
932 * 32768 1320 986 * 32768 1536 (1/32)
933 * 131072 4392
934 */ 987 */
935 if (totalram_pages < MB2PAGES(128)) 988 if (totalram_pages < MB2PAGES(128))
936 min_pages = MB2PAGES(8) + (totalram_pages >> 1); 989 min_pages = MB2PAGES(8) + (totalram_pages >> 1);
@@ -938,8 +991,10 @@ static unsigned long compute_balloon_floor(void)
938 min_pages = MB2PAGES(40) + (totalram_pages >> 2); 991 min_pages = MB2PAGES(40) + (totalram_pages >> 2);
939 else if (totalram_pages < MB2PAGES(2048)) 992 else if (totalram_pages < MB2PAGES(2048))
940 min_pages = MB2PAGES(104) + (totalram_pages >> 3); 993 min_pages = MB2PAGES(104) + (totalram_pages >> 3);
994 else if (totalram_pages < MB2PAGES(8192))
995 min_pages = MB2PAGES(256) + (totalram_pages >> 4);
941 else 996 else
942 min_pages = MB2PAGES(296) + (totalram_pages >> 5); 997 min_pages = MB2PAGES(512) + (totalram_pages >> 5);
943#undef MB2PAGES 998#undef MB2PAGES
944 return min_pages; 999 return min_pages;
945} 1000}
@@ -1171,7 +1226,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
1171 1226
1172 for (i = 0; i < range_count; i++) { 1227 for (i = 0; i < range_count; i++) {
1173 free_balloon_pages(dm, &range_array[i]); 1228 free_balloon_pages(dm, &range_array[i]);
1174 post_status(&dm_device); 1229 complete(&dm_device.config_event);
1175 } 1230 }
1176 1231
1177 if (req->more_pages == 1) 1232 if (req->more_pages == 1)
@@ -1195,19 +1250,16 @@ static void balloon_onchannelcallback(void *context);
1195static int dm_thread_func(void *dm_dev) 1250static int dm_thread_func(void *dm_dev)
1196{ 1251{
1197 struct hv_dynmem_device *dm = dm_dev; 1252 struct hv_dynmem_device *dm = dm_dev;
1198 int t;
1199 1253
1200 while (!kthread_should_stop()) { 1254 while (!kthread_should_stop()) {
1201 t = wait_for_completion_interruptible_timeout( 1255 wait_for_completion_interruptible_timeout(
1202 &dm_device.config_event, 1*HZ); 1256 &dm_device.config_event, 1*HZ);
1203 /* 1257 /*
1204 * The host expects us to post information on the memory 1258 * The host expects us to post information on the memory
1205 * pressure every second. 1259 * pressure every second.
1206 */ 1260 */
1207 1261 reinit_completion(&dm_device.config_event);
1208 if (t == 0) 1262 post_status(dm);
1209 post_status(dm);
1210
1211 } 1263 }
1212 1264
1213 return 0; 1265 return 0;
@@ -1387,7 +1439,9 @@ static int balloon_probe(struct hv_device *dev,
1387 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7; 1439 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7;
1388 init_completion(&dm_device.host_event); 1440 init_completion(&dm_device.host_event);
1389 init_completion(&dm_device.config_event); 1441 init_completion(&dm_device.config_event);
1442 init_completion(&dm_device.waiter_event);
1390 INIT_LIST_HEAD(&dm_device.ha_region_list); 1443 INIT_LIST_HEAD(&dm_device.ha_region_list);
1444 mutex_init(&dm_device.ha_region_mutex);
1391 INIT_WORK(&dm_device.balloon_wrk.wrk, balloon_up); 1445 INIT_WORK(&dm_device.balloon_wrk.wrk, balloon_up);
1392 INIT_WORK(&dm_device.ha_wrk.wrk, hot_add_req); 1446 INIT_WORK(&dm_device.ha_wrk.wrk, hot_add_req);
1393 dm_device.host_specified_ha_region = false; 1447 dm_device.host_specified_ha_region = false;
@@ -1401,6 +1455,7 @@ static int balloon_probe(struct hv_device *dev,
1401 1455
1402#ifdef CONFIG_MEMORY_HOTPLUG 1456#ifdef CONFIG_MEMORY_HOTPLUG
1403 set_online_page_callback(&hv_online_page); 1457 set_online_page_callback(&hv_online_page);
1458 register_memory_notifier(&hv_memory_nb);
1404#endif 1459#endif
1405 1460
1406 hv_set_drvdata(dev, &dm_device); 1461 hv_set_drvdata(dev, &dm_device);
@@ -1519,6 +1574,7 @@ static int balloon_remove(struct hv_device *dev)
1519 kfree(send_buffer); 1574 kfree(send_buffer);
1520#ifdef CONFIG_MEMORY_HOTPLUG 1575#ifdef CONFIG_MEMORY_HOTPLUG
1521 restore_online_page_callback(&hv_online_page); 1576 restore_online_page_callback(&hv_online_page);
1577 unregister_memory_notifier(&hv_memory_nb);
1522#endif 1578#endif
1523 list_for_each_safe(cur, tmp, &dm->ha_region_list) { 1579 list_for_each_safe(cur, tmp, &dm->ha_region_list) {
1524 has = list_entry(cur, struct hv_hotadd_state, list); 1580 has = list_entry(cur, struct hv_hotadd_state, list);
diff --git a/drivers/hv/hv_fcopy.c b/drivers/hv/hv_fcopy.c
index 23b2ce294c4c..cd453e4b2a07 100644
--- a/drivers/hv/hv_fcopy.c
+++ b/drivers/hv/hv_fcopy.c
@@ -86,6 +86,18 @@ static void fcopy_work_func(struct work_struct *dummy)
86 * process the pending transaction. 86 * process the pending transaction.
87 */ 87 */
88 fcopy_respond_to_host(HV_E_FAIL); 88 fcopy_respond_to_host(HV_E_FAIL);
89
90 /* In the case the user-space daemon crashes, hangs or is killed, we
91 * need to down the semaphore, otherwise, after the daemon starts next
92 * time, the obsolete data in fcopy_transaction.message or
93 * fcopy_transaction.fcopy_msg will be used immediately.
94 *
95 * NOTE: fcopy_read() happens to get the semaphore (very rare)? We're
96 * still OK, because we've reported the failure to the host.
97 */
98 if (down_trylock(&fcopy_transaction.read_sema))
99 ;
100
89} 101}
90 102
91static int fcopy_handle_handshake(u32 version) 103static int fcopy_handle_handshake(u32 version)
@@ -344,6 +356,14 @@ static int fcopy_open(struct inode *inode, struct file *f)
344 return 0; 356 return 0;
345} 357}
346 358
359/* XXX: there are still some tricky corner cases, e.g.,
360 * 1) In a SMP guest, when fcopy_release() runs between
361 * schedule_delayed_work() and fcopy_send_data(), there is
362 * still a chance an obsolete message will be queued.
363 *
364 * 2) When the fcopy daemon is running, if we unload the driver,
365 * we'll notice a kernel oops when we kill the daemon later.
366 */
347static int fcopy_release(struct inode *inode, struct file *f) 367static int fcopy_release(struct inode *inode, struct file *f)
348{ 368{
349 /* 369 /*
@@ -351,6 +371,13 @@ static int fcopy_release(struct inode *inode, struct file *f)
351 */ 371 */
352 in_hand_shake = true; 372 in_hand_shake = true;
353 opened = false; 373 opened = false;
374
375 if (cancel_delayed_work_sync(&fcopy_work)) {
376 /* We haven't up()-ed the semaphore(very rare)? */
377 if (down_trylock(&fcopy_transaction.read_sema))
378 ;
379 fcopy_respond_to_host(HV_E_FAIL);
380 }
354 return 0; 381 return 0;
355} 382}
356 383
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index c386d8dc7223..44b1c9424712 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -178,6 +178,23 @@ struct hv_message_header {
178 }; 178 };
179}; 179};
180 180
181/*
182 * Timer configuration register.
183 */
184union hv_timer_config {
185 u64 as_uint64;
186 struct {
187 u64 enable:1;
188 u64 periodic:1;
189 u64 lazy:1;
190 u64 auto_enable:1;
191 u64 reserved_z0:12;
192 u64 sintx:4;
193 u64 reserved_z1:44;
194 };
195};
196
197
181/* Define timer message payload structure. */ 198/* Define timer message payload structure. */
182struct hv_timer_message_payload { 199struct hv_timer_message_payload {
183 u32 timer_index; 200 u32 timer_index;
@@ -519,6 +536,10 @@ struct hv_context {
519 * buffer to post messages to the host. 536 * buffer to post messages to the host.
520 */ 537 */
521 void *post_msg_page[NR_CPUS]; 538 void *post_msg_page[NR_CPUS];
539 /*
540 * Support PV clockevent device.
541 */
542 struct clock_event_device *clk_evt[NR_CPUS];
522}; 543};
523 544
524extern struct hv_context hv_context; 545extern struct hv_context hv_context;
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index bb3725b672cf..f518b8d7a5b5 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -32,6 +32,7 @@
32#include <linux/completion.h> 32#include <linux/completion.h>
33#include <linux/hyperv.h> 33#include <linux/hyperv.h>
34#include <linux/kernel_stat.h> 34#include <linux/kernel_stat.h>
35#include <linux/clockchips.h>
35#include <asm/hyperv.h> 36#include <asm/hyperv.h>
36#include <asm/hypervisor.h> 37#include <asm/hypervisor.h>
37#include <asm/mshyperv.h> 38#include <asm/mshyperv.h>
@@ -578,6 +579,34 @@ static void vmbus_onmessage_work(struct work_struct *work)
578 kfree(ctx); 579 kfree(ctx);
579} 580}
580 581
582static void hv_process_timer_expiration(struct hv_message *msg, int cpu)
583{
584 struct clock_event_device *dev = hv_context.clk_evt[cpu];
585
586 if (dev->event_handler)
587 dev->event_handler(dev);
588
589 msg->header.message_type = HVMSG_NONE;
590
591 /*
592 * Make sure the write to MessageType (ie set to
593 * HVMSG_NONE) happens before we read the
594 * MessagePending and EOMing. Otherwise, the EOMing
595 * will not deliver any more messages since there is
596 * no empty slot
597 */
598 mb();
599
600 if (msg->header.message_flags.msg_pending) {
601 /*
602 * This will cause message queue rescan to
603 * possibly deliver another msg from the
604 * hypervisor
605 */
606 wrmsrl(HV_X64_MSR_EOM, 0);
607 }
608}
609
581static void vmbus_on_msg_dpc(unsigned long data) 610static void vmbus_on_msg_dpc(unsigned long data)
582{ 611{
583 int cpu = smp_processor_id(); 612 int cpu = smp_processor_id();
@@ -667,8 +696,12 @@ static void vmbus_isr(void)
667 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; 696 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
668 697
669 /* Check if there are actual msgs to be processed */ 698 /* Check if there are actual msgs to be processed */
670 if (msg->header.message_type != HVMSG_NONE) 699 if (msg->header.message_type != HVMSG_NONE) {
671 tasklet_schedule(&msg_dpc); 700 if (msg->header.message_type == HVMSG_TIMER_EXPIRED)
701 hv_process_timer_expiration(msg, cpu);
702 else
703 tasklet_schedule(&msg_dpc);
704 }
672} 705}
673 706
674/* 707/*