Drivers: hv: Miscellaneous fixes and enhancements
Subsystems (2)
cover Drivers: hv: Miscellaneous fixes and enhancements
In addition to some miscellaneous bug fixes and enhancements implement a clockevent device based on the functionality supported by Hyper-V.
K. Y. Srinivasan (6):
Drivers: hv: hv_balloon: Make adjustments in computing the floor
Drivers: hv: hv_balloon: Fix a locking bug in the balloon driver
Drivers: hv: hv_balloon: Don't post pressure status from interrupt
context
Drivers: hv: vmbus: Implement a clockevent device
Drivers: hv: vmbus: Fix a bug in vmbus_establish_gpadl()
Drivers: hv: vmbus: Support a vmbus API for efficiently sending page
arrays
arch/x86/include/uapi/asm/hyperv.h | 11 +++++ drivers/hv/channel.c | 48 +++++++++++++++++++- drivers/hv/hv.c | 78 +++++++++++++++++++++++++++++++ drivers/hv/hv_balloon.c | 88 +++++++++++++++++++++++++++++------- drivers/hv/hyperv_vmbus.h | 21 +++++++++ drivers/hv/vmbus_drv.c | 40 +++++++++++++++- include/linux/hyperv.h | 31 +++++++++++++ 7 files changed, 297 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.4.1
PATCH RESEND 1/6 Drivers: hv: hv_balloon: Make adjustments in computing the floor
Make adjustments in computing the balloon floor. The current computation of the balloon floor was not appropriate for virtual machines with more than 10 GB of assigned memory - we would get into situations where the host would agressively balloon down the guest and leave the guest in an unusable state. This patch fixes the issue by raising the floor.
--- drivers/hv/hv_balloon.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
drivers/hv/hv_balloon.c +5 -4
@@ -928,9 +928,8 @@ static unsigned long compute_balloon_floor(void)* 128 72 (1/2) * 512 168 (1/4) * 2048 360 (1/8) -* 8192 552 (1/32) -* 32768 1320 -* 131072 4392 +* 8192 768 (1/16) +* 32768 1536 (1/32) */ if (totalram_pages <MB2PAGES (128 )) min_pages =MB2PAGES (8 ) + (totalram_pages >>1 );
@@ -938,8 +937,10 @@ static unsigned long compute_balloon_floor(void) min_pages =MB2PAGES (40 ) + (totalram_pages >>2 ); else if (totalram_pages < MB2PAGES(2048)) min_pages =MB2PAGES (104 ) + (totalram_pages >>3 ); + else if (totalram_pages < MB2PAGES(8192)) + min_pages =MB2PAGES (256 ) + (totalram_pages >>4 ); else - min_pages =MB2PAGES (296 ) + (totalram_pages >>5 ); + min_pages =MB2PAGES (512 ) + (totalram_pages >>5 );#undef MB2PAGESreturn min_pages; }
Signature · 1 line
1.7.4.1
PATCH RESEND 2/6 Drivers: hv: hv_balloon: Fix a locking bug in the balloon driver
We support memory hot-add in the Hyper-V balloon driver by hot adding an appropriately sized and aligned region and controlling the on-lining of pages within that region based on the pages that the host wants us to online. We do this because the granularity and alignment requirements in Linux are different from what Windows expects. The state to manage the onlining of pages needs to be correctly protected. Fix this bug.
--- drivers/hv/hv_balloon.c | 68 +++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 63 insertions(+), 5 deletions(-)
drivers/hv/hv_balloon.c +63 -5
@@ -533,6 +533,9 @@ struct hv_dynmem_device {*/ struct task_struct *thread; +struct mutex ha_region_mutex; +struct completion waiter_event; +/* * A list of hot-add regions. */
@@ -549,7 +552,59 @@ struct hv_dynmem_device {static struct hv_dynmem_device dm_device;static void post_status (struct hv_dynmem_device *dm); +#ifdef CONFIG_MEMORY_HOTPLUG +static void acquire_region_mutex (bool trylock) +{ +if (trylock) { +reinit_completion (&dm_device.waiter_event); +while (!mutex_trylock (&dm_device.ha_region_mutex)) +wait_for_completion (&dm_device.waiter_event); + }else { +mutex_lock (&dm_device.ha_region_mutex); + } +} + +static void release_region_mutex (bool trylock) +{ +if (trylock) { +mutex_unlock (&dm_device.ha_region_mutex); + }else { +mutex_unlock (&dm_device.ha_region_mutex); +complete (&dm_device.waiter_event); + } +} + +static int hv_memory_notifier (struct notifier_block *nb,unsigned long val, +void *v) +{ +switch (val) { +case MEM_GOING_ONLINE : +acquire_region_mutex (true); +break ; + +case MEM_ONLINE : +case MEM_CANCEL_ONLINE : +release_region_mutex (true); +if (dm_device.ha_waiting) { + dm_device.ha_waiting = false; +complete (&dm_device.ol_waitevent); + } +break ; + +case MEM_GOING_OFFLINE : +case MEM_OFFLINE : +case MEM_CANCEL_OFFLINE : +break ; + } +return NOTIFY_OK ; +} + +static struct notifier_block hv_memory_nb = { + .notifier_call = hv_memory_notifier, + .priority =0 +}; +static void hv_bring_pgs_online (unsigned long start_pfn,unsigned long size) {
@@ -591,6 +646,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,init_completion (&dm_device.ol_waitevent); dm_device.ha_waiting = true; +release_region_mutex (false); nid =memory_add_physaddr_to_nid (PFN_PHYS (start_pfn)); ret =add_memory (nid,PFN_PHYS ((start_pfn)), (HA_CHUNK <<PAGE_SHIFT ));
@@ -619,6 +675,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,* have not been "onlined" within the allowed time. */ wait_for_completion_timeout (&dm_device.ol_waitevent,5 *HZ ); +acquire_region_mutex (false);post_status (&dm_device); }
@@ -632,11 +689,6 @@ static void hv_online_page(struct page *pg)unsigned long cur_start_pgp;unsigned long cur_end_pgp; -if (dm_device.ha_waiting) { - dm_device.ha_waiting = false; -complete (&dm_device.ol_waitevent); - } -list_for_each (cur, &dm_device.ha_region_list) { has = list_entry(cur, struct hv_hotadd_state, list); cur_start_pgp = (unsigned long)
@@ -834,6 +886,7 @@ static void hot_add_req(struct work_struct *dummy) resp.hdr.size =sizeof (struct dm_hot_add_response );#ifdef CONFIG_MEMORY_HOTPLUG +acquire_region_mutex (false); pg_start = dm->ha_wrk.ha_page_range.finfo.start_page; pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt;
@@ -865,6 +918,7 @@ static void hot_add_req(struct work_struct *dummy)if (do_hot_add) resp.page_count =process_hot_add (pg_start, pfn_cnt, rg_start, rg_sz); +release_region_mutex (false);#endif /* * The result field of the response structure has the
@@ -1388,7 +1442,9 @@ static int balloon_probe(struct hv_device *dev, dm_device.next_version =DYNMEM_PROTOCOL_VERSION_WIN7 ;init_completion (&dm_device.host_event);init_completion (&dm_device.config_event); +init_completion (&dm_device.waiter_event);INIT_LIST_HEAD (&dm_device.ha_region_list); +mutex_init (&dm_device.ha_region_mutex);INIT_WORK (&dm_device.balloon_wrk.wrk, balloon_up);INIT_WORK (&dm_device.ha_wrk.wrk, hot_add_req); dm_device.host_specified_ha_region = false;
@@ -1402,6 +1458,7 @@ static int balloon_probe(struct hv_device *dev,#ifdef CONFIG_MEMORY_HOTPLUG set_online_page_callback (&hv_online_page); +register_memory_notifier (&hv_memory_nb);#endif hv_set_drvdata (dev, &dm_device);
@@ -1520,6 +1577,7 @@ static int balloon_remove(struct hv_device *dev)kfree (send_buffer);#ifdef CONFIG_MEMORY_HOTPLUG restore_online_page_callback (&hv_online_page); +unregister_memory_notifier (&hv_memory_nb);#endif list_for_each_safe (cur, tmp, &dm->ha_region_list) { has = list_entry(cur, struct hv_hotadd_state, list);
Signature · 1 line
1.7.4.1
PATCH RESEND 3/6 Drivers: hv: hv_balloon: Don't post pressure status from interrupt context
In reply to K. Y. SrinivasanWe currently release memory (balloon down) in the interrupt context and we also post memory status while releasing memory. Rather than posting the status in the interrupt context, wakeup the status posting thread to post the status. This will address the inconsistent lock state that Sitsofe Wheeler <[email protected]> reported:
http://lkml.iu.edu/hypermail/linux/kernel/1411.1/00075.html
--- drivers/hv/hv_balloon.c | 11 ++++------- 1 files changed, 4 insertions(+), 7 deletions(-)
drivers/hv/hv_balloon.c +4 -7
@@ -1226,7 +1226,7 @@ static void balloon_down(struct hv_dynmem_device *dm,for (i =0 ; i < range_count; i++) {free_balloon_pages (dm, &range_array[i]); -post_status (&dm_device); +complete (&dm_device.config_event); }if (req->more_pages ==1 )
@@ -1250,19 +1250,16 @@ static void balloon_onchannelcallback(void *context);static int dm_thread_func (void *dm_dev) {struct hv_dynmem_device *dm = dm_dev; -int t;while (!kthread_should_stop ()) { - t =wait_for_completion_interruptible_timeout ( +wait_for_completion_interruptible_timeout ( &dm_device.config_event,1 *HZ );/* * The host expects us to post information on the memory * pressure every second. */ - -if (t ==0 ) -post_status (dm); - +reinit_completion (&dm_device.config_event); +post_status (dm); }return 0 ;
Signature · 1 line
1.7.4.1
PATCH RESEND 4/6 Drivers: hv: vmbus: Implement a clockevent device
In reply to K. Y. SrinivasanImplement a clockevent device based on the timer support available on Hyper-V.
In this version of the patch I have addressed Jason's review comments.
--- arch/x86/include/uapi/asm/hyperv.h | 11 +++++ drivers/hv/hv.c | 78 ++++++++++++++++++++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 21 ++++++++++ drivers/hv/vmbus_drv.c | 37 ++++++++++++++++- 4 files changed, 145 insertions(+), 2 deletions(-)
arch/x86/include/uapi/asm/hyperv.h +11 -0
@@ -187,6 +187,17 @@#define HV_X64_MSR_SINT14 0x4000009E#define HV_X64_MSR_SINT15 0x4000009F +/* +* Synthetic Timer MSRs. Four timers per vcpu. +*/ +#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0 +#define HV_X64_MSR_STIMER0_COUNT 0x400000B1 +#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2 +#define HV_X64_MSR_STIMER1_COUNT 0x400000B3 +#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4 +#define HV_X64_MSR_STIMER2_COUNT 0x400000B5 +#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6 +#define HV_X64_MSR_STIMER3_COUNT 0x400000B7#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
drivers/hv/hv.c +78 -0
125 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +21 -0
@@ -178,6 +178,23 @@ struct hv_message_header { }; }; +/* +* Timer configuration register. +*/ +union hv_timer_config { +u64 as_uint64; +struct { +u64 enable:1 ; +u64 periodic:1 ; +u64 lazy:1 ; +u64 auto_enable:1 ; +u64 reserved_z0:12 ; +u64 sintx:4 ; +u64 reserved_z1:44 ; + }; +}; + +/* Define timer message payload structure. */ struct hv_timer_message_payload {u32 timer_index;
@@ -519,6 +536,10 @@ struct hv_context {* buffer to post messages to the host. */ void *post_msg_page[NR_CPUS ]; +/* +* Support PV clockevent device. +*/ +struct clock_event_device *clk_evt[NR_CPUS ]; };extern struct hv_context hv_context;
drivers/hv/vmbus_drv.c +35 -2
@@ -32,6 +32,7 @@#include <linux/completion.h> #include <linux/hyperv.h> #include <linux/kernel_stat.h> +#include <linux/clockchips.h> #include <asm/hyperv.h> #include <asm/hypervisor.h> #include <asm/mshyperv.h>
@@ -578,6 +579,34 @@ static void vmbus_onmessage_work(struct work_struct *work)kfree (ctx); } +void hv_process_timer_expiration (struct hv_message *msg,int cpu) +{ +struct clock_event_device *dev = hv_context.clk_evt[cpu]; + +if (dev->event_handler) + dev->event_handler (dev); + + msg->header.message_type =HVMSG_NONE ; + +/* +* Make sure the write to MessageType (ie set to +* HVMSG_NONE) happens before we read the +* MessagePending and EOMing. Otherwise, the EOMing +* will not deliver any more messages since there is +* no empty slot +*/ +mb (); + +if (msg->header.message_flags.msg_pending) { +/* +* This will cause message queue rescan to +* possibly deliver another msg from the +* hypervisor +*/ +wrmsrl (HV_X64_MSR_EOM ,0 ); + } +} +static void vmbus_on_msg_dpc (unsigned long data) {int cpu =smp_processor_id ();
@@ -667,8 +696,12 @@ static void vmbus_isr(void) msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ;/* Check if there are actual msgs to be processed */ -if (msg->header.message_type !=HVMSG_NONE ) -tasklet_schedule (&msg_dpc); +if (msg->header.message_type !=HVMSG_NONE ) { +if (msg->header.message_type ==HVMSG_TIMER_EXPIRED ) +hv_process_timer_expiration (msg, cpu); +else +tasklet_schedule (&msg_dpc); + } }/*
Signature · 1 line
1.7.4.1
PATCH RESEND 5/6 Drivers: hv: vmbus: Fix a bug in vmbus_establish_gpadl()
In reply to K. Y. SrinivasanCorrectly compute the local (gpadl) handle.
I would like to thank Michael Brown <[email protected]> for seeing this bug.
--- drivers/hv/channel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/hv/channel.c +2 -2
@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,unsigned long flags;int ret =0 ; - next_gpadl_handle =atomic_read (&vmbus_connection.next_gpadl_handle); -atomic_inc (&vmbus_connection.next_gpadl_handle); + next_gpadl_handle = + (atomic_inc_return (&vmbus_connection.next_gpadl_handle) -1 ); ret =create_gpadl_header (kbuffer, size, &msginfo, &msgcount);if (ret)
Signature · 1 line
1.7.4.1
PATCH RESEND 6/6 Drivers: hv: vmbus: Support a vmbus API for efficiently sending page arrays
In reply to K. Y. SrinivasanCurrently, the API for sending a multi-page buffer over VMBUS is limited to a maximum pfn array of MAX_MULTIPAGE_BUFFER_COUNT. This limitation is not imposed by the host and unnecessarily limits the maximum payload that can be sent. Implement an API that does not have this restriction.
--- drivers/hv/channel.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/hyperv.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)
drivers/hv/channel.c +44 -0
@@ -686,6 +686,50 @@ EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer);/* * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet * using a GPADL Direct packet type. +* The buffer includes the vmbus descriptor. +*/ +int vmbus_sendpacket_mpb_desc (struct vmbus_channel *channel, +struct vmbus_packet_mpb_array *desc, +u32 desc_size, +void *buffer,u32 bufferlen,u64 requestid) +{ +int ret; +u32 packetlen; +u32 packetlen_aligned; +struct kvec bufferlist[3 ]; +u64 aligned_data =0 ; +bool signal = false; + + packetlen = desc_size + bufferlen; + packetlen_aligned =ALIGN (packetlen,sizeof (u64)); + +/* Setup the descriptor */ + desc->type =VM_PKT_DATA_USING_GPA_DIRECT ; + desc->flags =VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED ; + desc->dataoffset8 = desc_size >>3 ;/* in 8-bytes grandularity */ + desc->length8 = (u16)(packetlen_aligned >>3 ); + desc->transactionid = requestid; + desc->rangecount =1 ; + + bufferlist[0 ].iov_base = desc; + bufferlist[0 ].iov_len = desc_size; + bufferlist[1 ].iov_base = buffer; + bufferlist[1 ].iov_len = bufferlen; + bufferlist[2 ].iov_base = &aligned_data; + bufferlist[2 ].iov_len = (packetlen_aligned - packetlen); + + ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , &signal); + +if (ret ==0 && signal) +vmbus_setevent (channel); + +return ret; +} +EXPORT_SYMBOL_GPL (vmbus_sendpacket_mpb_desc); + +/* +* vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet +* using a GPADL Direct packet type. */ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, struct hv_multipage_buffer *multi_pagebuffer,
include/linux/hyperv.h +31 -0
@@ -57,6 +57,18 @@ struct hv_multipage_buffer {u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT ]; }; +/* +* Multiple-page buffer array; the pfn array is variable size: +* The number of entries in the PFN array is determined by +* "len" and "offset". +*/ +struct hv_mpb_array { +/* Length and Offset determines the # of pfns in the array */ +u32 len; +u32 offset; +u64 pfn_array[]; +}; +/* 0x18 includes the proprietary packet header */ #define MAX_PAGE_BUFFER_PACKET (0x18 + \ (sizeof(struct hv_page_buffer) * \
@@ -814,6 +826,18 @@ struct vmbus_channel_packet_multipage_buffer {struct hv_multipage_buffer range; } __packed; +/* The format must be the same as struct vmdata_gpa_direct */ +struct vmbus_packet_mpb_array { +u16 type; +u16 dataoffset8; +u16 length8; +u16 flags; +u64 transactionid; +u32 reserved; +u32 rangecount;/* Always 1 in this case */ +struct hv_mpb_array range; +} __packed; + extern int vmbus_open(struct vmbus_channel *channel, u32 send_ringbuffersize,
@@ -845,6 +869,13 @@ extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,u32 bufferlen, u64 requestid); +extern int vmbus_sendpacket_mpb_desc (struct vmbus_channel *channel, +struct vmbus_packet_mpb_array *mpb, +u32 desc_size, +void *buffer, +u32 bufferlen, +u64 requestid); + extern int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, u32 size,
Signature · 1 line
1.7.4.1