]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/hv/vmbus_drv.c
hv: run non-blocking message handlers in the dispatch tasklet
[linux.git] / drivers / hv / vmbus_drv.c
index f518b8d7a5b5190eb01b741d0961f6b9fbf6cd33..c85235e9f245b6d210384673168bef12c6f9f0de 100644 (file)
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
 #include <linux/clockchips.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
+#include <linux/notifier.h>
+#include <linux/ptrace.h>
 #include "hyperv_vmbus.h"
 
 static struct acpi_device  *hv_acpi_dev;
@@ -44,6 +47,31 @@ static struct tasklet_struct msg_dpc;
 static struct completion probe_event;
 static int irq;
 
+
+static int hyperv_panic_event(struct notifier_block *nb,
+                       unsigned long event, void *ptr)
+{
+       struct pt_regs *regs;
+
+       regs = current_pt_regs();
+
+       wrmsrl(HV_X64_MSR_CRASH_P0, regs->ip);
+       wrmsrl(HV_X64_MSR_CRASH_P1, regs->ax);
+       wrmsrl(HV_X64_MSR_CRASH_P2, regs->bx);
+       wrmsrl(HV_X64_MSR_CRASH_P3, regs->cx);
+       wrmsrl(HV_X64_MSR_CRASH_P4, regs->dx);
+
+       /*
+        * Let Hyper-V know there is crash data available
+        */
+       wrmsrl(HV_X64_MSR_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block hyperv_panic_block = {
+       .notifier_call = hyperv_panic_event,
+};
+
 struct resource hyperv_mmio = {
        .name  = "hyperv mmio",
        .flags = IORESOURCE_MEM,
@@ -507,14 +535,26 @@ static int vmbus_probe(struct device *child_device)
  */
 static int vmbus_remove(struct device *child_device)
 {
-       struct hv_driver *drv = drv_to_hv_drv(child_device->driver);
+       struct hv_driver *drv;
        struct hv_device *dev = device_to_hv_device(child_device);
-
-       if (drv->remove)
-               drv->remove(dev);
-       else
-               pr_err("remove not set for driver %s\n",
-                       dev_name(child_device));
+       u32 relid = dev->channel->offermsg.child_relid;
+
+       if (child_device->driver) {
+               drv = drv_to_hv_drv(child_device->driver);
+               if (drv->remove)
+                       drv->remove(dev);
+               else {
+                       hv_process_channel_removal(dev->channel, relid);
+                       pr_err("remove not set for driver %s\n",
+                               dev_name(child_device));
+               }
+       } else {
+               /*
+                * We don't have a driver for this device; deal with the
+                * rescind message by removing the channel.
+                */
+               hv_process_channel_removal(dev->channel, relid);
+       }
 
        return 0;
 }
@@ -573,6 +613,10 @@ static void vmbus_onmessage_work(struct work_struct *work)
 {
        struct onmessage_work_context *ctx;
 
+       /* Do not process messages if we're in DISCONNECTED state */
+       if (vmbus_connection.conn_state == DISCONNECTED)
+               return;
+
        ctx = container_of(work, struct onmessage_work_context,
                           work);
        vmbus_onmessage(&ctx->msg);
@@ -613,21 +657,36 @@ static void vmbus_on_msg_dpc(unsigned long data)
        void *page_addr = hv_context.synic_message_page[cpu];
        struct hv_message *msg = (struct hv_message *)page_addr +
                                  VMBUS_MESSAGE_SINT;
+       struct vmbus_channel_message_header *hdr;
+       struct vmbus_channel_message_table_entry *entry;
        struct onmessage_work_context *ctx;
 
        while (1) {
-               if (msg->header.message_type == HVMSG_NONE) {
+               if (msg->header.message_type == HVMSG_NONE)
                        /* no msg */
                        break;
-               } else {
+
+               hdr = (struct vmbus_channel_message_header *)msg->u.payload;
+
+               if (hdr->msgtype >= CHANNELMSG_COUNT) {
+                       WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype);
+                       goto msg_handled;
+               }
+
+               entry = &channel_message_table[hdr->msgtype];
+               if (entry->handler_type == VMHT_BLOCKING) {
                        ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
                        if (ctx == NULL)
                                continue;
+
                        INIT_WORK(&ctx->work, vmbus_onmessage_work);
                        memcpy(&ctx->msg, msg, sizeof(*msg));
+
                        queue_work(vmbus_connection.work_queue, &ctx->work);
-               }
+               } else
+                       entry->message_handler(hdr);
 
+msg_handled:
                msg->header.message_type = HVMSG_NONE;
 
                /*
@@ -704,6 +763,39 @@ static void vmbus_isr(void)
        }
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+       return -ENOSYS;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+       static void *previous_cpu_disable;
+
+       /*
+        * Offlining a CPU when running on newer hypervisors (WS2012R2, Win8,
+        * ...) is not supported at this moment as channel interrupts are
+        * distributed across all of them.
+        */
+
+       if ((vmbus_proto_version == VERSION_WS2008) ||
+           (vmbus_proto_version == VERSION_WIN7))
+               return;
+
+       if (vmbus_loaded) {
+               previous_cpu_disable = smp_ops.cpu_disable;
+               smp_ops.cpu_disable = hyperv_cpu_disable;
+               pr_notice("CPU offlining is not supported by hypervisor\n");
+       } else if (previous_cpu_disable)
+               smp_ops.cpu_disable = previous_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -744,6 +836,16 @@ static int vmbus_bus_init(int irq)
        if (ret)
                goto err_alloc;
 
+       hv_cpu_hotplug_quirk(true);
+
+       /*
+        * Only register if the crash MSRs are available
+        */
+       if (ms_hyperv.features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
+               atomic_notifier_chain_register(&panic_notifier_list,
+                                              &hyperv_panic_block);
+       }
+
        vmbus_request_offers();
 
        return 0;
@@ -840,10 +942,8 @@ int vmbus_device_register(struct hv_device *child_device_obj)
 {
        int ret = 0;
 
-       static atomic_t device_num = ATOMIC_INIT(0);
-
-       dev_set_name(&child_device_obj->device, "vmbus_0_%d",
-                    atomic_inc_return(&device_num));
+       dev_set_name(&child_device_obj->device, "vmbus_%d",
+                    child_device_obj->channel->id);
 
        child_device_obj->device.bus = &hv_bus;
        child_device_obj->device.parent = &hv_acpi_dev->dev;
@@ -992,11 +1092,19 @@ static int __init hv_acpi_init(void)
 
 static void __exit vmbus_exit(void)
 {
+       int cpu;
+
+       vmbus_connection.conn_state = DISCONNECTED;
+       hv_synic_clockevents_cleanup();
        hv_remove_vmbus_irq();
        vmbus_free_channels();
        bus_unregister(&hv_bus);
        hv_cleanup();
+       for_each_online_cpu(cpu)
+               smp_call_function_single(cpu, hv_synic_cleanup, NULL, 1);
        acpi_bus_unregister_driver(&vmbus_acpi_driver);
+       hv_cpu_hotplug_quirk(false);
+       vmbus_disconnect();
 }