From patchwork Tue Feb 7 14:55:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9560319 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 CCB3B6047A for ; Tue, 7 Feb 2017 14:57:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2B0B28388 for ; Tue, 7 Feb 2017 14:57:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4C9B28401; Tue, 7 Feb 2017 14:57:47 +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 3053128388 for ; Tue, 7 Feb 2017 14:57:46 +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 1cb7At-0003Wb-Qw; Tue, 07 Feb 2017 14:55:19 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cb7As-0003WV-K5 for xen-devel@lists.xenproject.org; Tue, 07 Feb 2017 14:55:18 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 78/70-27165-5DFD9985; Tue, 07 Feb 2017 14:55:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsXitHRDpO7V+zM jDLYuFLP4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOO9neyFHwVrljT9oilgXGDQBcjJ4eEgL9E 68TjTCA2m4CBxK1L35m7GDk4RARUJG7vNehi5OJgFrjAKPHz2wlGkBphAT+J9x1rWUFsFqCav 1eesYPYvAKeEg9uH2SCmCkncfNcJzOILSSgJvF2+RkWiBpBiZMzn4DZzAISEgdfvGCewMg9C0 lqFpLUAkamVYzqxalFZalFupZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiBocA ABDsY724KOMQoycGkJMp7evfMCCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvHfuAeUEi1LTUyvS MnOAQQmTluDgURLhXQ2S5i0uSMwtzkyHSJ1iVJQS550NkhAASWSU5sG1wSLhEqOslDAvI9AhQ jwFqUW5mSWo8q8YxTkYlYR5vUCm8GTmlcBNfwW0mAlo8bYr00AWlyQipKQaGCfxeHzV/pvK/X XCwc9lEjO9hVaKiS49eV1N9/UqtVqzD8FOtumRb6tW7VLWfnw+vjtt5qPzkhkLXnLNPfNt0Wl 3CQWRrTemaC8yOrjb67TulNJ4F4XYBQFdsyacXCATHPL51qlrt0+/ixc/7Ba3+U7aMQ6X8Hsr 7+6xY0286PWrxbv843bu5YVKLMUZiYZazEXFiQD04Tj+fwIAAA== X-Env-Sender: prvs=204a3df98=ross.lagerwall@citrix.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1486479315!55349092!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61793 invoked from network); 7 Feb 2017 14:55:17 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-11.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 7 Feb 2017 14:55:17 -0000 X-IronPort-AV: E=Sophos;i="5.33,346,1477958400"; d="scan'208";a="405035309" From: Ross Lagerwall To: Date: Tue, 7 Feb 2017 14:55:12 +0000 Message-ID: <1486479312-18424-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 v2] 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 --- Changed in V2: * Retested on top of v4.10-rc7 + "xen-netfront: Delete rx_refill_timer in xennet_disconnect_backend()". * Don't move setup_timer as it is not necessary. drivers/net/xen-netfront.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 722fe9f..5399a86 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -1823,27 +1823,23 @@ 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"); + if (num_queues > 0) { + goto destroy_ring; + } else { + 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 +1929,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; }