Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932897AbdCXRq4 (ORCPT ); Fri, 24 Mar 2017 13:46:56 -0400 Received: from a2nlsmtp01-05.prod.iad2.secureserver.net ([198.71.225.49]:47448 "EHLO a2nlsmtp01-05.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932712AbdCXRqo (ORCPT ); Fri, 24 Mar 2017 13:46:44 -0400 x-originating-ip: 107.180.71.197 From: Long Li To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , devel@linuxdriverproject.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [PATCH v3] HV: properly delay KVP packets when negotiation is in progress Date: Fri, 24 Mar 2017 10:45:29 -0700 Message-Id: <1490377529-26435-1-git-send-email-longli@exchange.microsoft.com> X-Mailer: git-send-email 1.7.1 X-CMAE-Envelope: MS4wfI9SW5/eCPR6R+GGfugmOKLvhpxGnMfFFvOK11EV1LkBOrdVs0tZLkSQOr9BsADwwfoBQkGdf/ZjuTBDKohrQDsDmDuHT00YRKfZz8+PgeDxP7QGEYtg AbMHHfWa5aWfcE0AzKhvkFMFqxHsYtf11hBHpg9d5nsGtdZNtQzl05Vbv91MSOnjpuVDYCri2blKaOCu7icOm/KIjZPoEdjPCeJvtXM6eL6HF3WqZnkZBQGz PxHGN9KRiOHYKHmnjekIp8dbd/j3c7YJEsG0i47M4mSwOhNIUc/nH/KG/gTawYZlQn7nHdqi8RbjagjZGrT/yUe0aaivu1E8KaTzBDHL7gSDEvVXTt1/caCs NlGlKV62QvRXpFra8daR2qlpxmYflA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2646 Lines: 75 From: Long Li The host may send multiple negotiation packets (due to timeout) before the 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 . The patch v3 has incorporated suggestions from Vitaly Kuznetsov . Signed-off-by: Long Li --- drivers/hv/hv_kvp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c index de26371..be7222e 100644 --- a/drivers/hv/hv_kvp.c +++ b/drivers/hv/hv_kvp.c @@ -113,7 +113,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) @@ -160,7 +160,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) @@ -628,16 +628,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) @@ -705,6 +706,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); } } -- 2.7.4