From patchwork Tue Jun 20 17:27:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 778431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3wsZZK5gD4z9s7m; Wed, 21 Jun 2017 03:28:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b="Y3ypgdRn"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1dNMxD-0001vi-1e; Tue, 20 Jun 2017 17:28:39 +0000 Received: from mail-ua0-f180.google.com ([209.85.217.180]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1dNMwj-0001ij-P5 for kernel-team@lists.ubuntu.com; Tue, 20 Jun 2017 17:28:09 +0000 Received: by mail-ua0-f180.google.com with SMTP id d45so48629517uai.1 for ; Tue, 20 Jun 2017 10:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4uUN1srGj4XUzSRvcVNUKJyJcSkIB0Fn2I7wBPwwAiw=; b=Y3ypgdRnQo9aczqGSnnpniZblWzTmLyYWebehTh6r6jmHOIAxjPlmKsWcbLEVMVn39 jOp8ZTfAmWzqhFU4iCyTdZkGO0iJxkHDPkA6mDFYYVcKxB+G9a5WpAKjho+KSW8ogvoa 3yd3Q+mTbFjNkXe38hX+XmlDqlTCaTH/eFgZWriNtsNUP4pSokIe2RClSeLhs+ZxvwR1 v0IFTzeZ3mmBv2ToPXSU3/IINy5q0AGl4mWhmXDH/VEot5RsDW+NhbCQBSjJK1dPB+F9 /YMn7kd8nLpP8U7j238dl3tQV4qWkX+WszwYu/aF941GDRUqyqlIkh0l4vS13UHasCzR Kgvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4uUN1srGj4XUzSRvcVNUKJyJcSkIB0Fn2I7wBPwwAiw=; b=ZIgCFJlR53kEsjKhNZeDaxmG8K2Z+AMfEpmVWO0unXaAVmxkSZCaRMdG4SqDWmw7R6 pBbGXrtW85c8z7RLiDlF84nJDgRLDf2OzUdbvvgCfZCYyu3Qfj7+EF+A8v+L0kouHTa3 1KR/e1SQ+CBvwKruJCcb4JGqqkTUlx04AaVsAlvv4qdzaSrWXGd//K7yfaMVsM4NFH/Y DtTO0ej/HMj+6THxQdIWddV7HGJQQn0rqLTfbFujZPN4HHWYOIT3JVxjvYznYcf4+tFp Qd1HbQa8yo8JcKiLExAMVeowIHlis07B1m7hxrGN8+Rh4FzwiJiTE9CuXvFrb9EoxRcC HVuw== X-Gm-Message-State: AKS2vOzyTHFuefSQiJL0SG7uf4Kcjs6XuM/sNyXSuUT3eOT4N9/FROjA 4cPGcHWhETqjsphbRuw= X-Received: by 10.176.80.219 with SMTP id d27mr15954981uaa.99.1497979688166; Tue, 20 Jun 2017 10:28:08 -0700 (PDT) Received: from localhost.localdomain ([191.8.96.73]) by smtp.gmail.com with ESMTPSA id x2sm4922955vkd.35.2017.06.20.10.28.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 10:28:07 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [azure][PATCH 13/14] UBUNTU: SAUCE: vmbus: add vmbus onoffer/onoffer_rescind sync. Date: Tue, 20 Jun 2017 14:27:33 -0300 Message-Id: <1497979654-27251-14-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497979654-27251-1-git-send-email-marcelo.cerri@canonical.com> References: <1497979654-27251-1-git-send-email-marcelo.cerri@canonical.com> Cc: "K . Y . Srinivasan" , Dexuan Cui , Cheng-mean Liu X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Dexuan Cui BugLink: http://bugs.launchpad.net/bugs/1698425 Signed-off-by: Dexuan Cui Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/channel_mgmt.c | 25 +++++++++++++++++++------ drivers/hv/hyperv_vmbus.h | 1 + drivers/hv/vmbus_drv.c | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 19ad79099492..a12b1eabc15e 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -467,6 +467,7 @@ void vmbus_free_channels(void) static void vmbus_process_offer(struct vmbus_channel *newchannel) { struct vmbus_channel *channel; + struct hv_device *device_obj; bool fnew = true; unsigned long flags; u16 dev_type; @@ -524,6 +525,7 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel) if (channel->sc_creation_callback != NULL) channel->sc_creation_callback(newchannel); atomic_dec(&vmbus_connection.offer_in_progress); + atomic_dec(&vmbus_connection.register_in_progress); return; } @@ -532,33 +534,36 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel) * We need to set the DeviceObject field before calling * vmbus_child_dev_add() */ - newchannel->device_obj = vmbus_device_create( + device_obj = vmbus_device_create( &newchannel->offermsg.offer.if_type, &newchannel->offermsg.offer.if_instance, newchannel); - if (!newchannel->device_obj) + if (!device_obj) goto err_deq_chan; - newchannel->device_obj->device_id = dev_type; + device_obj->device_id = dev_type; /* * Add the new device to the bus. This will kick off device-driver * binding which eventually invokes the device driver's AddDevice() * method. */ - ret = vmbus_device_register(newchannel->device_obj); + atomic_dec(&vmbus_connection.offer_in_progress); + ret = vmbus_device_register(device_obj); if (ret != 0) { pr_err("unable to add child device object (relid %d)\n", newchannel->offermsg.child_relid); - kfree(newchannel->device_obj); + kfree(device_obj); goto err_deq_chan; } + newchannel->device_obj = device_obj; + atomic_dec(&vmbus_connection.register_in_progress); - atomic_dec(&vmbus_connection.offer_in_progress); return; err_deq_chan: atomic_dec(&vmbus_connection.offer_in_progress); + atomic_dec(&vmbus_connection.register_in_progress); mutex_lock(&vmbus_connection.channel_mutex); list_del(&newchannel->listentry); mutex_unlock(&vmbus_connection.channel_mutex); @@ -889,6 +894,14 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) vmbus_rescind_cleanup(channel); + while (atomic_read(&vmbus_connection.register_in_progress) != 0) { + /* + * We wait here until any channel offer is currently + * being processed. + */ + msleep(1); + } + if (channel->device_obj) { if (channel->chn_rescind_callback) { channel->chn_rescind_callback(channel); diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 7b8603a00555..30ae1d291527 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -309,6 +309,7 @@ struct vmbus_connection { int connect_cpu; atomic_t offer_in_progress; + atomic_t register_in_progress; enum vmbus_connect_state conn_state; diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index fd221cffeb4d..fc6a5893d54c 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -871,6 +871,7 @@ static void vmbus_dispatch_msg_work(struct work_struct *work) flush_workqueue(vmbus_connection.work_queue_rescind); atomic_inc(&vmbus_connection.offer_in_progress); + atomic_inc(&vmbus_connection.register_in_progress); queue_work_on(vmbus_connection.connect_cpu, vmbus_connection.work_queue, &context->work);