]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
HV: properly delay KVP packets when negotiation is in progress
authorLong Li <longli@microsoft.com>
Sun, 30 Apr 2017 23:21:19 +0000 (16:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 May 2017 14:55:28 +0000 (16:55 +0200)
The host may send multiple negotiation packets
(due to timeout) before the KVP user-mode daemon
is connected. KVP user-mode daemon is connected.
We need to defer processing those packets
until the daemon is negotiated and connected.
It's okay for guest to respond
to all negotiation packets.

In addition, the host may send multiple staged
KVP requests as soon as negotiation is done.
We need to properly process those packets using one
tasklet for exclusive access to ring buffer.

This patch is based on the work of
Nick Meier <Nick.Meier@microsoft.com>.

Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hv/hv_kvp.c

index e99ff2ddad400c8de68cf4b787db7b1d5d7ab19b..9a90b915b5be420713263b3c80006f5b74f7f9e4 100644 (file)
@@ -112,7 +112,7 @@ static void kvp_poll_wrapper(void *channel)
 {
        /* Transaction is finished, reset the state here to avoid races. */
        kvp_transaction.state = HVUTIL_READY;
-       hv_kvp_onchannelcallback(channel);
+       tasklet_schedule(&((struct vmbus_channel *)channel)->callback_event);
 }
 
 static void kvp_register_done(void)
@@ -159,7 +159,7 @@ static void kvp_timeout_func(struct work_struct *dummy)
 
 static void kvp_host_handshake_func(struct work_struct *dummy)
 {
-       hv_poll_channel(kvp_transaction.recv_channel, hv_kvp_onchannelcallback);
+       tasklet_schedule(&kvp_transaction.recv_channel->callback_event);
 }
 
 static int kvp_handle_handshake(struct hv_kvp_msg *msg)
@@ -625,16 +625,17 @@ void hv_kvp_onchannelcallback(void *context)
                     NEGO_IN_PROGRESS,
                     NEGO_FINISHED} host_negotiatied = NEGO_NOT_STARTED;
 
-       if (host_negotiatied == NEGO_NOT_STARTED &&
-           kvp_transaction.state < HVUTIL_READY) {
+       if (kvp_transaction.state < HVUTIL_READY) {
                /*
                 * If userspace daemon is not connected and host is asking
                 * us to negotiate we need to delay to not lose messages.
                 * This is important for Failover IP setting.
                 */
-               host_negotiatied = NEGO_IN_PROGRESS;
-               schedule_delayed_work(&kvp_host_handshake_work,
+               if (host_negotiatied == NEGO_NOT_STARTED) {
+                       host_negotiatied = NEGO_IN_PROGRESS;
+                       schedule_delayed_work(&kvp_host_handshake_work,
                                      HV_UTIL_NEGO_TIMEOUT * HZ);
+               }
                return;
        }
        if (kvp_transaction.state > HVUTIL_READY)
@@ -702,6 +703,7 @@ void hv_kvp_onchannelcallback(void *context)
                                       VM_PKT_DATA_INBAND, 0);
 
                host_negotiatied = NEGO_FINISHED;
+               hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
        }
 
 }