Received: by 10.223.176.5 with SMTP id f5csp987455wra; Fri, 2 Feb 2018 09:17:34 -0800 (PST) X-Google-Smtp-Source: AH8x227UEd9imgaIzO6Jc+bR5cG4FySZHe0Ady8fvWxVqYGcXZnccspTEufoFqPfaM8W8IpgfNKG X-Received: by 2002:a17:902:6ac7:: with SMTP id i7-v6mr34830770plt.368.1517591854414; Fri, 02 Feb 2018 09:17:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591854; cv=none; d=google.com; s=arc-20160816; b=JbBDK8busEVuZCpp58M/LatErE/R56Z64WqMQ0RQvgxk86QNNaToqr5qrz7fAR8fz4 Ou3DJ5UrU5hzecmKAN0M4jXKeGDBrC7GQAmfWZ9oOW5BCNsVhVBTYWEISNiSBnGP5orl MSwDSdzl2tgHmwMYk8aNtk/yV3bB40R02CDScq4QLDFNiP+vPJWRZ2hzsTooDmCmTBeC bq7ymlpvk1tu4wXSTQc0v9iF8cnCbtqJ6AgcsHJ+6pX5Q/nYLIOup21PMAaKyA10TvIj 2ktGTXHG16ja4gDyHGAZxkfz+9780iZ3owGctoL4jMV1a/GoRQdsOv68vWsUFZjQJfgj 1Epg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=G7t6Xf0dUWkCjNHWIH7z1/fyL42h54PWFQOgh+tqAkw=; b=MXeQJ8UJKia9jjzJnX+qRhz/tDiQgp+CGzBrrlhGjJkiTRNf9ofeVslc3Xj4by6Wnv szpCg9jX3edYw3qjfuOrfFU5yP3I24KeT6wm4AVfORleBJ345y/qGlcwAAf1LKD72FaV /+fU7BLZelTtSY6xbWfWXxJ11/7L6hv5TkyF6eemHZNvJVY+oaducbLZbmuLgQYi3oyX pP0Y1fDF3MIieXdj89MS4+p8GulUdrC0wy80K5qkYN8zJbcjZUdxJPONSt6TovgFYEff rFtNTzlfUdVe6mc1/DVnyt0Hhe6Xj5rl35Ce8kKh1xjtZLTjabvOEZ39dV8mp9X9ZsEE pz7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z9si1470804pfl.34.2018.02.02.09.17.19; Fri, 02 Feb 2018 09:17:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753859AbeBBRQq (ORCPT + 99 others); Fri, 2 Feb 2018 12:16:46 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38418 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753013AbeBBRKo (ORCPT ); Fri, 2 Feb 2018 12:10:44 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B4CD0EF7; Fri, 2 Feb 2018 17:10:43 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eduardo Otubo , Juergen Gross , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 083/156] xen-netfront: remove warning when unloading module Date: Fri, 2 Feb 2018 17:57:44 +0100 Message-Id: <20180202140844.020505090@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eduardo Otubo [ Upstream commit 5b5971df3bc2775107ddad164018a8a8db633b81 ] v2: * Replace busy wait with wait_event()/wake_up_all() * Cannot garantee that at the time xennet_remove is called, the xen_netback state will not be XenbusStateClosed, so added a condition for that * There's a small chance for the xen_netback state is XenbusStateUnknown by the time the xen_netfront switches to Closed, so added a condition for that. When unloading module xen_netfront from guest, dmesg would output warning messages like below: [ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805) This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg. The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states. Signed-off-by: Eduardo Otubo Acked-by: Juergen Gross Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/xen-netfront.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -87,6 +87,8 @@ struct netfront_cb { /* IRQ name is queue name with "-tx" or "-rx" appended */ #define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3) +static DECLARE_WAIT_QUEUE_HEAD(module_unload_q); + struct netfront_stats { u64 packets; u64 bytes; @@ -2021,10 +2023,12 @@ static void netback_changed(struct xenbu break; case XenbusStateClosed: + wake_up_all(&module_unload_q); if (dev->state == XenbusStateClosed) break; /* Missed the backend's CLOSING state -- fallthrough */ case XenbusStateClosing: + wake_up_all(&module_unload_q); xenbus_frontend_closed(dev); break; } @@ -2130,6 +2134,20 @@ static int xennet_remove(struct xenbus_d dev_dbg(&dev->dev, "%s\n", dev->nodename); + if (xenbus_read_driver_state(dev->otherend) != XenbusStateClosed) { + xenbus_switch_state(dev, XenbusStateClosing); + wait_event(module_unload_q, + xenbus_read_driver_state(dev->otherend) == + XenbusStateClosing); + + xenbus_switch_state(dev, XenbusStateClosed); + wait_event(module_unload_q, + xenbus_read_driver_state(dev->otherend) == + XenbusStateClosed || + xenbus_read_driver_state(dev->otherend) == + XenbusStateUnknown); + } + xennet_disconnect_backend(info); unregister_netdev(info->netdev);