From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-874563-1516767999-2-11309191161775145516 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org', XOriginatingCountry='US' X-Spam-charsets: plain='iso-8859-1' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1516767998; b=s/gYmabJbjD89RdZv83s7hrZO4sMMoDoXV3QLzVHCuKU6Wd Y88PR4URl98aPMa3Dmw2PXN//4yfVDMe0aqvBXTMHY49NDkVwLTqv7FHWef5nk9Z 7qW4EdVV6L8VV6mURhURBbuNCm40N3xxt5E2DniZjg9A3LDE61SSqPrFUnu/xnmr Ub/E3+64fOBgth9xAynanDOFkvyscDx17ePi4eVM+r/PRrNLwB59xHGZP72XAJs+ RongO5Eqcf2HDy/m7aeqdTNuv1f023lvellsXHj/9uPpr5AGMCaBiDkU5/0q5ruz BnOhxsXKYWOB2M2fgUCXr6/3Swp8qr2AU0P0Caw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:date:message-id :references:in-reply-to:content-type:content-transfer-encoding :mime-version:sender:list-id; s=arctest; t=1516767998; bh=+yiyKe t5z+fvpHDHxWVbxVfrfXh2xaD2ONVCflI44OQ=; b=UMsDf0yl99ivwvrHy4DKoR jwBOABD+g/asbg7uE1heyleACaPk5pBuiX81Xc6O8o3xod8XSiYsbWd6tWw4vkIQ NORtR4UIvLHaJT0FJrddRVk/WzBfTnbfg1HAzO5neGeZjyXNUyTtCrNfNVJjJYZv X9U7GvjB6wTY+qyvhs2S6RDJrb3OA5HineDvhfVuFKMn/yfCFxbkRqs6h1f+82AA BlkYkqWni8KhBnTkLyobQakCEQuHmSNEs2IffKTEX4Qj/PRG8tbTQvrEj2RfNMAY zKirLmKO5o8Zy+cErZotnfpzvDEigi80HfG4E8+d5yOkp1kErHg6sjrH4trpbOZA == ARC-Authentication-Results: i=1; mx2.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=f03PFn6n x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=reject,has-list-id=yes,d=none) header.from=microsoft.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=microsoft.com header.result=pass header_is_org_domain=yes Authentication-Results: mx2.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=f03PFn6n x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=reject,has-list-id=yes,d=none) header.from=microsoft.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=microsoft.com header.result=pass header_is_org_domain=yes Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932942AbeAXETb (ORCPT ); Tue, 23 Jan 2018 23:19:31 -0500 Received: from mail-dm3nam03on0104.outbound.protection.outlook.com ([104.47.41.104]:64192 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933203AbeAXET1 (ORCPT ); Tue, 23 Jan 2018 23:19:27 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Eduardo Otubo , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 17/35] xen-netfront: remove warning when unloading module Thread-Topic: [PATCH AUTOSEL for 4.4 17/35] xen-netfront: remove warning when unloading module Thread-Index: AQHTlMou7q1KjKKus0KRvjXsvpA04Q== Date: Wed, 24 Jan 2018 04:17:01 +0000 Message-ID: <20180124041645.32420-17-alexander.levin@microsoft.com> References: <20180124041645.32420-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041645.32420-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1094;7:Lgea36f8BsjymNv9MOfNI3O/D1TP+vpnjAhBNydCSpGNy1RO6kRrSlAk+qEyCTboA9xdD0ufJG0AVt1tvgtPvwvcsq88ybznPYZ7+JYty6vHpswwRtKeuOnWjGuEPxKCzpDHoBSqo2uqoR/bIYkaCxEh8kRsO3GDj+uNihdUIsH9Qgou1lKGLlcIjHbVVz9n4eHYBBD9/FvBfCsxKuxuxrHQMIj8tiLczZ05B1TZagkf9Prvbqrj8qZPj4k9U8AH x-ms-office365-filtering-correlation-id: 7f4b3346-c229-475c-9425-08d562e1a4dc x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1094; x-ms-traffictypediagnostic: DM5PR2101MB1094: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(788757137089); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(8121501046)(5005006)(3231046)(2400081)(944501161)(10201501046)(3002001)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1094;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1094; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(346002)(376002)(396003)(366004)(39860400002)(39380400002)(199004)(189003)(14454004)(99286004)(10090500001)(2906002)(86612001)(2900100001)(2950100002)(107886003)(5250100002)(2501003)(26005)(316002)(4326008)(97736004)(54906003)(106356001)(110136005)(25786009)(6666003)(5660300001)(36756003)(305945005)(86362001)(8936002)(3280700002)(6116002)(68736007)(102836004)(3660700001)(6512007)(10290500003)(72206003)(1076002)(105586002)(6436002)(22452003)(59450400001)(53936002)(478600001)(3846002)(7736002)(6486002)(6346003)(81156014)(66066001)(6506007)(8676002)(76176011)(81166006)(22906009)(217873001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1094;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: laIovfXLNJPmhhMZ5+RMKwb2DuaKcXfyg60AAP8P8lomZGMJeq/CJ5yVBkHBDSyax6anXEWCczyyFQChAIoGag== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f4b3346-c229-475c-9425-08d562e1a4dc X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:17:01.0334 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1094 Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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 --- drivers/net/xen-netfront.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index fd221cc4cb79..eb7a9e62371c 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -86,6 +86,8 @@ struct netfront_cb { /* IRQ name is queue name with "-tx" or "-rx" appended */ #define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3) =20 +static DECLARE_WAIT_QUEUE_HEAD(module_unload_q); + struct netfront_stats { u64 packets; u64 bytes; @@ -2037,10 +2039,12 @@ static void netback_changed(struct xenbus_device *d= ev, break; =20 case XenbusStateClosed: + wake_up_all(&module_unload_q); if (dev->state =3D=3D XenbusStateClosed) break; /* Missed the backend's CLOSING state -- fallthrough */ case XenbusStateClosing: + wake_up_all(&module_unload_q); xenbus_frontend_closed(dev); break; } @@ -2146,6 +2150,20 @@ static int xennet_remove(struct xenbus_device *dev) =20 dev_dbg(&dev->dev, "%s\n", dev->nodename); =20 + if (xenbus_read_driver_state(dev->otherend) !=3D XenbusStateClosed) { + xenbus_switch_state(dev, XenbusStateClosing); + wait_event(module_unload_q, + xenbus_read_driver_state(dev->otherend) =3D=3D + XenbusStateClosing); + + xenbus_switch_state(dev, XenbusStateClosed); + wait_event(module_unload_q, + xenbus_read_driver_state(dev->otherend) =3D=3D + XenbusStateClosed || + xenbus_read_driver_state(dev->otherend) =3D=3D + XenbusStateUnknown); + } + xennet_disconnect_backend(info); =20 unregister_netdev(info->netdev); --=20 2.11.0