From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-858731-1516767819-2-13562695951020588464 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=1516767819; b=DfK1d6fHj46Q+AB4leXxqc+UXHpWZLDmlSWI0cknXJ8/UBn p4jJ0IzmrEpe+v/JXvjbU7VkF3MhlfaP2GKgPcZJH4pXKqcFMul7UZkUTb1ZfoVD J6fRFA191tZvBpCw5NjO0Oq0DokGLouIYMZR5h8N8CjXp1gurdwRdma861qVzgKT PHMqa3zhpor8HcZBsE4WksylgMbm6+grwOmh6e/22zfdMu5THLDo0LQvaG9Bfj4M vyohw11c1y5IKDsz60x0zx3kevEaHkJTNRdTM6eWIU974QGWL1IB5aHoyBcLqn3E pwnu8DOoiGnjhTp/2QWgPswy7oghmlmhMnz7p6A== 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=1516767819; bh=0fchj2 /Jj/4sMsMl+qaT8jlShFS2pOSowKcoKzMMBGM=; b=JVX/2K23MhXYSAuDeGp8wy 8sa2o55gpKRSoem4TBXnJ2klSYY8kh6lgRDKeZID8yiXdOMwRZMTBBD8GZoLMoNd 1Dh1i+zsSTmkv3fuu+Wa1wYohvoDeo7kX7hL37GGTWJQiOK/50V36Srt28HbL+aT j7ByJG5nINFRcMhaaZGVVLKEMkw2q6zPvEMindEahmv27AAwxGPDvx1IJ2kwR+g7 l8k0SP9ewEsTbopJC2ALINyJeXhcUIXbH6xG3JHIeVMKYxfp1BtC6iGAGhGJzo5l bygrG2zJNYhbpoMwhmO2TLPGYnm9qD4hDfXdJEqe2OfFC2t8VzQmIF1n7qBOh5uQ == ARC-Authentication-Results: i=1; mx3.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=T/aABVPw 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: mx3.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=T/aABVPw 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 S932911AbeAXEWc (ORCPT ); Tue, 23 Jan 2018 23:22:32 -0500 Received: from mail-cys01nam02on0129.outbound.protection.outlook.com ([104.47.37.129]:44357 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932570AbeAXEUH (ORCPT ); Tue, 23 Jan 2018 23:20:07 -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 3.18 07/16] xen-netfront: remove warning when unloading module Thread-Topic: [PATCH AUTOSEL for 3.18 07/16] xen-netfront: remove warning when unloading module Thread-Index: AQHTlMo90trmemBsZ0aiSA60k8vYZw== Date: Wed, 24 Jan 2018 04:17:26 +0000 Message-ID: <20180124041716.32520-7-alexander.levin@microsoft.com> References: <20180124041716.32520-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041716.32520-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;DM5PR2101MB0872;7:D8jnxNkZ98V5Wd51x4ihf2qGuhEyTSj0jUN9RHqAzZFKqhIO8PRmEwd8jHp01whLf9E1vM0H6HDf3SeF7yqS3k8hIBazRfY5fl0vWG1Kwa6nzR1SFV9m8ZkUvzK/0tzi/shoIvyavfaQNx04A8fMXKlXQKqqK/1kyeW6OSo6ZPkwMQcFld+HC/hqWm/j9MmZ8/RP3YpxiWe7boqDrOrx0V3tWvqiN+RPJeL5MZNzu8eVC/YGDDzfj2xEih7QAO4h x-ms-office365-filtering-correlation-id: 5352d2d4-27c8-411d-539c-08d562e1be16 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:DM5PR2101MB0872; x-ms-traffictypediagnostic: DM5PR2101MB0872: 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)(93006095)(93001095)(3002001)(10201501046)(3231046)(2400081)(944501161)(6055026)(61426038)(61427038)(6041288)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0872;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0872; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(396003)(366004)(346002)(376002)(39860400002)(199004)(189003)(5660300001)(106356001)(72206003)(3280700002)(5250100002)(66066001)(3660700001)(105586002)(14454004)(86612001)(478600001)(53936002)(2900100001)(10290500003)(2501003)(6512007)(10090500001)(6436002)(6506007)(36756003)(6116002)(3846002)(6486002)(2906002)(22452003)(107886003)(316002)(54906003)(4326008)(110136005)(6346003)(81166006)(25786009)(26005)(2950100002)(6666003)(86362001)(1076002)(8676002)(7736002)(81156014)(99286004)(59450400001)(305945005)(76176011)(68736007)(97736004)(102836004)(8936002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0872;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: ZUlrKwKBIoEj+dHmJgL+boNLKdTXkDyHOq0ktTh5QIbMssIvVNxhtN0v+ihkEkEta9DxrIqSmNgkEJNl9KaKWg== 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: 5352d2d4-27c8-411d-539c-08d562e1be16 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:17:26.3077 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0872 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 8f45be1592ca..e76f46edee08 100644 --- 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) =20 +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 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; } @@ -2305,6 +2309,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 xennet_sysfs_delif(info->netdev); --=20 2.11.0