Drivers: hv: vmbus: Use get/put_cpu() in vmbus_connect()
authorDexuan Cui <decui@microsoft.com>
Mon, 17 Sep 2018 04:14:54 +0000 (04:14 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 16 Dec 2018 22:09:31 +0000 (22:09 +0000)
commit 41e270f6898e7502be9fd6920ee0a108ca259d36 upstream.

With CONFIG_DEBUG_PREEMPT=y, I always see this warning:
BUG: using smp_processor_id() in preemptible [00000000]

Fix the false warning by using get/put_cpu().

Here vmbus_connect() sends a message to the host and waits for the
host's response. The host will deliver the response message and an
interrupt on CPU msg->target_vcpu, and later the interrupt handler
will wake up vmbus_connect(). vmbus_connect() doesn't really have
to run on the same cpu as CPU msg->target_vcpu, so it's safe to
call put_cpu() just here.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.16:
 - smp_processor_id() is only used once here
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/hv/connection.c

index 04e5a98fdc4436e4d94179c98a962d8d869cdec6..0949566ec0496718cf35e9f2d8d409f5e1c92dcb 100644 (file)
@@ -68,6 +68,7 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
                                        __u32 version)
 {
        int ret = 0;
+       unsigned int cur_cpu;
        struct vmbus_channel_initiate_contact *msg;
        unsigned long flags;
 
@@ -80,8 +81,11 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
        msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
        msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]);
        msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]);
-       if (version == VERSION_WIN8_1)
-               msg->target_vcpu = hv_context.vp_index[smp_processor_id()];
+       if (version == VERSION_WIN8_1) {
+               cur_cpu = get_cpu();
+               msg->target_vcpu = hv_context.vp_index[cur_cpu];
+               put_cpu();
+       }
 
        /*
         * Add to list before we send the request since we may