From patchwork Wed Feb 8 10:57:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9562197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C329601E5 for ; Wed, 8 Feb 2017 11:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 361B6284FB for ; Wed, 8 Feb 2017 11:00:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AB8628501; Wed, 8 Feb 2017 11:00:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD1EB284DB for ; Wed, 8 Feb 2017 11:00:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbPwc-0005lC-Hf; Wed, 08 Feb 2017 10:57:50 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbPwb-0005l4-F2 for xen-devel@lists.xenproject.org; Wed, 08 Feb 2017 10:57:49 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id DA/87-27165-CA9FA985; Wed, 08 Feb 2017 10:57:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsXitHSDve6an7M iDPr6RSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxde1czF3QKVzRemc/ewHibv4uRk0NCwF/i zrWrbCA2m4CBxK1L35m7GDk4RARUJG7vNehi5OJgFrjAKPHz2wlGkBphAT+JyX+fs4DYLEA1J 753M4HYvAKeEj8mXWWCmCkncfNcJzOILSSgJvF2+RkWiBpBiZMzn4DZzAISEgdfvGCewMg9C0 lqFpLUAkamVYwaxalFZalFukZmeklFmekZJbmJmTm6hgZmermpxcWJ6ak5iUnFesn5uZsYgcH AAAQ7GM8sCDzEKMnBpCTK6/N0VoQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd5jP4BygkWp6akV aZk5wLCESUtw8CiJ8EoCQ1OIt7ggMbc4Mx0idYpRUUqc9w1InwBIIqM0D64NFguXGGWlhHkZg Q4R4ilILcrNLEGVf8UozsGoJMz7FmQKT2ZeCdz0V0CLmYAWXz8NtrgkESEl1cC4wHBddpJAu9 pMbr/P/pHuT/rsl5/nU7aTsrx43+p9yLT0hbOXff1sL9MTf03483GpRXF2HY3/HrVK9PiIrT5 n/2OazD/VoLKrAhMkT6ZM/6d03lOTsyVBqfeu/YQ1+3r+HA2PEz79d/b96vV83J9XBlT9Mouf s/z+kW2+Mxo1zj3ba/k7R7lIiaU4I9FQi7moOBEADUKTPIACAAA= X-Env-Sender: prvs=205014f2d=ross.lagerwall@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1486551466!33646972!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8293 invoked from network); 8 Feb 2017 10:57:48 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 8 Feb 2017 10:57:48 -0000 X-IronPort-AV: E=Sophos;i="5.33,346,1477958400"; d="scan'208";a="414234668" From: Ross Lagerwall To: Date: Wed, 8 Feb 2017 10:57:37 +0000 Message-ID: <1486551457-25963-1-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Cc: Juergen Gross , wei.liu2@citrix.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Ross Lagerwall , Boris Ostrovsky Subject: [Xen-devel] [PATCH v3] xen-netfront: Improve error handling during initialization X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This fixes a crash when running out of grant refs when creating many queues across many netdevs. * If creating queues fails (i.e. there are no grant refs available), call xenbus_dev_fatal() to ensure that the xenbus device is set to the closed state. * If no queues are created, don't call xennet_disconnect_backend as netdev->real_num_tx_queues will not have been set correctly. * If setup_netfront() fails, ensure that all the queues created are cleaned up, not just those that have been set up. * If any queues were set up and an error occurs, call xennet_destroy_queues() to clean up the napi context. * If any fatal error occurs, unregister and destroy the netdev to avoid leaving around a half setup network device. Signed-off-by: Ross Lagerwall Reviewed-by: Boris Ostrovsky --- Changed in V3: * If xennet_create_queues returns < 0, it will not have created any queues so there's no need to go to destroy_ring. drivers/net/xen-netfront.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 722fe9f..f90fc72 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -1823,27 +1823,19 @@ static int talk_to_netback(struct xenbus_device *dev, xennet_destroy_queues(info); err = xennet_create_queues(info, &num_queues); - if (err < 0) - goto destroy_ring; + if (err < 0) { + xenbus_dev_fatal(dev, err, "creating queues"); + kfree(info->queues); + info->queues = NULL; + goto out; + } /* Create shared ring, alloc event channel -- for each queue */ for (i = 0; i < num_queues; ++i) { queue = &info->queues[i]; err = setup_netfront(dev, queue, feature_split_evtchn); - if (err) { - /* setup_netfront() will tidy up the current - * queue on error, but we need to clean up - * those already allocated. - */ - if (i > 0) { - rtnl_lock(); - netif_set_real_num_tx_queues(info->netdev, i); - rtnl_unlock(); - goto destroy_ring; - } else { - goto out; - } - } + if (err) + goto destroy_ring; } again: @@ -1933,9 +1925,10 @@ static int talk_to_netback(struct xenbus_device *dev, xenbus_transaction_end(xbt, 1); destroy_ring: xennet_disconnect_backend(info); - kfree(info->queues); - info->queues = NULL; + xennet_destroy_queues(info); out: + unregister_netdev(info->netdev); + xennet_free_netdev(info->netdev); return err; }