From patchwork Thu Dec 24 14:14:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 560924 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 589D0140C3B for ; Thu, 24 Dec 2015 23:41:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932701AbbLXMlV (ORCPT ); Thu, 24 Dec 2015 07:41:21 -0500 Received: from p3plsmtps2ded03.prod.phx3.secureserver.net ([208.109.80.60]:38536 "EHLO p3plsmtps2ded03.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932402AbbLXMkn (ORCPT ); Thu, 24 Dec 2015 07:40:43 -0500 Received: from linuxonhyperv.com ([72.167.245.219]) by : HOSTING RELAY : with SMTP id C5CFaHpEDdpLfC5CFaYJSe; Thu, 24 Dec 2015 05:40:43 -0700 x-originating-ip: 72.167.245.219 Received: by linuxonhyperv.com (Postfix, from userid 518) id 2112C190343; Thu, 24 Dec 2015 06:14:57 -0800 (PST) From: Dexuan Cui To: gregkh@linuxfoundation.org, davem@davemloft.net, stephen@networkplumber.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, driverdev-devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com, kys@microsoft.com Cc: pebolle@tiscali.nl, stefanha@redhat.com, vkuznets@redhat.com, dan.carpenter@oracle.com Subject: [PATCH V5 8/9] Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister() Date: Thu, 24 Dec 2015 06:14:57 -0800 Message-Id: <1450966497-13310-1-git-send-email-decui@microsoft.com> X-Mailer: git-send-email 1.7.4.1 X-CMAE-Envelope: MS4wfIch8RL7PeblToJSGq/eUOt9RqxntAxBKsN50gl+vNdkj+15hmBJMhGk+WTWmsWVgfxVfgzA6j8SRcs/ayXNg4uO/dS3kTxTch69FwkPfHitEPvH6KTU om98DehTQ4JAT670Q9OMwlUAnyTpwRhLMfybIb7bnyv2oQpvsj4YZFMQsb52sbTXllH9SJR+WAUK5ala32WMJIrY3K0dvzEYZpKmaO4HnAqcUXnobcutOxKA qj8rjsZxURohjNontWF72pIUqVkpRGNAn+r/HeKvebY+63ntaiG8oPo8Q6ECi5JVOb4Rsh2JG4AQG/AjqjuG/oIreDSVIgNUErj8Co/qNeDnSFWPv1rns9aV AH2XksPeKYNJUSK4UXFmriLcn9+1wyQmh9j34oh7ouqtyo5hf/d6y0cRXzK2+N5nFJrtGS96dQlLGE4ePX0gi3ZzkdWnIBRn8x1MWdaAb+FGCxQ2gPNMfxKK HkmYF8JDJwyJtjAKN1G+tWcyDYTCioDRRwpqnnZakgVuiLjvTU51IYiL5BPrBfthgWixVxkyvU0/y61UrT8C6clQiKMLZHu3EUqoCJQ+VNA/fH/S6cl9KdhR 10uT7kaQ+0msus4FzrApbTNCicX7xi4yu/ZuC8PM0MWSSQ== Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The hvsock driver needs this API to release all the resources related to the channel. Signed-off-by: Dexuan Cui --- drivers/hv/channel_mgmt.c | 33 ++++++++++++++++++++++++++++----- drivers/hv/connection.c | 4 ++-- include/linux/hyperv.h | 2 ++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 87fc7d2..f963645 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -195,6 +195,7 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid) vmbus_release_relid(relid); BUG_ON(!channel->rescind); + BUG_ON(!mutex_is_locked(&vmbus_connection.channel_mutex)); if (channel->target_cpu != get_cpu()) { put_cpu(); @@ -206,9 +207,7 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid) } if (channel->primary_channel == NULL) { - mutex_lock(&vmbus_connection.channel_mutex); list_del(&channel->listentry); - mutex_unlock(&vmbus_connection.channel_mutex); primary_channel = channel; } else { @@ -251,6 +250,7 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel) struct vmbus_channel *channel; bool fnew = true; unsigned long flags; + int ret; /* Make sure this is a new offer */ mutex_lock(&vmbus_connection.channel_mutex); @@ -330,7 +330,11 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel) * binding which eventually invokes the device driver's AddDevice() * method. */ - if (vmbus_device_register(newchannel->device_obj) != 0) { + mutex_lock(&vmbus_connection.channel_mutex); + ret = vmbus_device_register(newchannel->device_obj); + mutex_unlock(&vmbus_connection.channel_mutex); + + if (ret != 0) { pr_err("unable to add child device object (relid %d)\n", newchannel->offermsg.child_relid); kfree(newchannel->device_obj); @@ -592,6 +596,8 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) struct device *dev; rescind = (struct vmbus_channel_rescind_offer *)hdr; + + mutex_lock(&vmbus_connection.channel_mutex); channel = relid2channel(rescind->child_relid); if (channel == NULL) { @@ -600,7 +606,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) * vmbus_process_offer(), we have already invoked * vmbus_release_relid() on error. */ - return; + goto out; } spin_lock_irqsave(&channel->lock, flags); @@ -616,7 +622,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) * We can't invoke vmbus_device_unregister() * until the socket fd is closed. */ - return; + goto out; } /* * We will have to unregister this device from the @@ -631,7 +637,24 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) hv_process_channel_removal(channel, channel->offermsg.child_relid); } + +out: + mutex_unlock(&vmbus_connection.channel_mutex); +} + + +void vmbus_hvsock_device_unregister(struct vmbus_channel *channel) +{ + mutex_lock(&vmbus_connection.channel_mutex); + + BUG_ON(!is_hvsock_channel(channel)); + + channel->rescind = true; + vmbus_device_unregister(channel->device_obj); + + mutex_unlock(&vmbus_connection.channel_mutex); } +EXPORT_SYMBOL_GPL(vmbus_hvsock_device_unregister); /* * vmbus_onoffers_delivered - diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 3dc5a9c..deb48e6 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -288,7 +288,8 @@ struct vmbus_channel *relid2channel(u32 relid) struct list_head *cur, *tmp; struct vmbus_channel *cur_sc; - mutex_lock(&vmbus_connection.channel_mutex); + BUG_ON(!mutex_is_locked(&vmbus_connection.channel_mutex)); + list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { if (channel->offermsg.child_relid == relid) { found_channel = channel; @@ -307,7 +308,6 @@ struct vmbus_channel *relid2channel(u32 relid) } } } - mutex_unlock(&vmbus_connection.channel_mutex); return found_channel; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 7e507bb..8e59f98 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1055,6 +1055,8 @@ int __must_check __vmbus_driver_register(struct hv_driver *hv_driver, const char *mod_name); void vmbus_driver_unregister(struct hv_driver *hv_driver); +void vmbus_hvsock_device_unregister(struct vmbus_channel *channel); + int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, resource_size_t min, resource_size_t max, resource_size_t size, resource_size_t align,