Received: by 10.223.176.5 with SMTP id f5csp2840517wra; Mon, 5 Feb 2018 10:45:09 -0800 (PST) X-Google-Smtp-Source: AH8x227hYrMoGEeLGatjQyFv56OhCc9iJmGODl5uPCYeZHADK/yIjcm5IBtAqeZUF1e8YHw98SJQ X-Received: by 2002:a17:902:b496:: with SMTP id y22-v6mr23988643plr.206.1517856308986; Mon, 05 Feb 2018 10:45:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517856308; cv=none; d=google.com; s=arc-20160816; b=wefpjjFk212U1WpgB5ZbfgdWZukJYxNeZRirEkYJVFfC7Xr8dc/Y3PEGATxo+AVMsu d04H6oMlYR7bURpYpCjR0MwKKci6/WUUqGVX5T2akZmPi1YNjTmeznyMS5SdN1VecTzD Ry+pQhd3b6+5Canxn5LtFwEbGX5F8p6LMMXOTK/VDVsGa4zh+nISnysDYXM3MCLPEQDP b2piVpyaj++4esqPWBfiC8+a8q5Ivx6b47FMO0Puj9pOPXxSkkHC7XCdDac/aG3J5bvY mzLr6jqt8cvs9WHGM5LmuaJpSD9vdMIn2FZDinVOQStTGqkutObHgmZ0Gz0Eehm0G2zB EEsw== 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=DWork4z6GULtMT9qTcsUU124jH9YWkyhqXLzYoJu2PY=; b=Qw+wQdxp6eWoE1ijak819FK2X1EqiakIICCKZfzh5Oy+DhmnjqEJ6TciwFYSxVG9aF HR1w0cPbVorQolmhK1TYxAr1l8LtUojqLIHt0zr07Tb9zJsvE3GZHldZ4NaEIy5Q9uGI CBvXfvV4iwTb4a07CcuP0ckuMA6mRyVwFFDUhnDtI/Ut57yA5OSjOlgRv8+jTbh5x3pU yfVVuh4u0i1jLO7zWYf/9NjyMqco3c7FAT8fSMl6jMnNJaSQylW01C6yrKxmBcvUuY6+ LDWA3ywx+WBUXMuHVnX2mmRyDkqGatoPN6wIjrNbI9X6Aj9fh9lO+2z70TWtxijh5S6U WqqQ== 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 z20-v6si7353818plo.73.2018.02.05.10.44.54; Mon, 05 Feb 2018 10:45:08 -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 S1753968AbeBESn5 (ORCPT + 99 others); Mon, 5 Feb 2018 13:43:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:53460 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753890AbeBES0P (ORCPT ); Mon, 5 Feb 2018 13:26:15 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4AA8B1158; Mon, 5 Feb 2018 18:26:08 +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 3.18 15/36] xen-netfront: remove warning when unloading module Date: Mon, 5 Feb 2018 10:23:43 -0800 Message-Id: <20180205182352.401594585@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182351.774761393@linuxfoundation.org> References: <20180205182351.774761393@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 3.18-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 @@ -85,6 +85,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 rx_packets; u64 tx_packets; @@ -2080,10 +2082,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; } @@ -2305,6 +2309,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); xennet_sysfs_delif(info->netdev);