From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-901460-1516769691-2-746502973944818233 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=1516769690; b=LfgkVP21cVFlnw4cfr+ph0pD5CWv6t8e3eDFvGnZDS72+dF m0dc22mpurKFNorIFts5OJedcEp/Svl8YayYGJiEN4ycIgl12WoFc+0HvuMHOVGx IwLPiqCvg5OvhyAmqPg1mZo+Wr+2MavoIKTJirRUVOHBvOUsOgEla7FjpuZJPilS tBsSj86Fkmh/HDkXeNGoMxm30RRFFsJSieK9Q6gESuIvaF5H5AciaUpSVXB28JX2 sCOoffrblN8BelJ0lQswCSCLAmbC0OhVEADl5HN1t5aG1Z6R6dgxeP2LyHqUVEnS OKRXLKyY+gWqE5cUEadOomGv3Mm7uiTcIArUQfw== 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=1516769690; bh=9DOzrw KL/ISEqyYhHltMkqeB36XI5Ol98Jhb6nTLCes=; b=ew96oP7GaIYvkXYesG3pWe oml/76eRY3l+e+hK2LPu6AdOtXYpd45QowGyLtZfZwMXeCDcMwNJQEJVIAzL6e0h 9doSr5SfVQfqhfEkTK+PzjgtBmWWYKfXaDcFCFrFW5gJ4rKom06dPQOUCb7RnShh 9+f41GqUicM6j1vbTXqcUhe4RKH10ge+j9OdtAEb7aP0Fc0/U8539IBNWAD8AljK RBY3c3w6tyyjvJAE3FYFriB8Yb/uQAesx9B5MciWYG7cbTT4IESWJpDWqr0TrY3A afSysAgdupenWtlmmQql2DyIaxlKi/FztehHLnzR7u73xDD1EFg9Bf41jjfJ5wHw == ARC-Authentication-Results: i=1; mx6.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=eI3PWHQG 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: mx6.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=eI3PWHQG 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 S932212AbeAXEP2 (ORCPT ); Tue, 23 Jan 2018 23:15:28 -0500 Received: from mail-dm3nam03on0107.outbound.protection.outlook.com ([104.47.41.107]:39081 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932213AbeAXEPY (ORCPT ); Tue, 23 Jan 2018 23:15:24 -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.14 054/100] xen-netfront: remove warning when unloading module Thread-Topic: [PATCH AUTOSEL for 4.14 054/100] xen-netfront: remove warning when unloading module Thread-Index: AQHTlMnhE3nHHeMFME60iE6oLkvjVA== Date: Wed, 24 Jan 2018 04:14:51 +0000 Message-ID: <20180124041414.32065-54-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-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;DM5PR2101MB1015;7:xXVRJQYsymNOE21kE1hQdNNlWqiuJ/OF3id6Zr6JogGXsrRS3Y+MgqcrefI6xHxxA7SmIzlmpzVHOmQZnxxT2JNeAiigkM7LaEcX7nwzc2U2qfzurPEroncUQOAZJthAivQU4w2wvCmw3OqsMRCtNTyWNxaJhzX7wxtSOut+xPzDHHURzJarbgsE8ctI2TBAxCBzh09zhzFWNvj2F/fJLz42ypob2i0j3K6Aj9QzuFLZsi1N8vtT9LU0IoRFYkDi x-ms-office365-filtering-correlation-id: 469c481b-ac18-4323-6321-08d562e11472 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:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: 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)(5005006)(8121501046)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(376002)(366004)(39860400002)(346002)(199004)(189003)(478600001)(6666003)(106356001)(6512007)(53936002)(2900100001)(36756003)(102836004)(2950100002)(2501003)(10290500003)(97736004)(14454004)(81166006)(72206003)(8936002)(6486002)(1076002)(10090500001)(6346003)(26005)(54906003)(4326008)(76176011)(99286004)(86362001)(3660700001)(105586002)(6116002)(8676002)(68736007)(22452003)(66066001)(25786009)(6506007)(5660300001)(305945005)(59450400001)(7736002)(3280700002)(5250100002)(2906002)(107886003)(86612001)(6436002)(316002)(81156014)(3846002)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;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: //9e66VsCvXtX9SNmYVZTJ7fTMcsktg55yZZiQpfSypvAi5Ff9JZ1erzyIbNPhTFYiplFV/Yb2XrTagPtPE+fg== 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: 469c481b-ac18-4323-6321-08d562e11472 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:51.9163 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 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 8b8689c6d887..391432e2725d 100644 --- 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) =20 +static DECLARE_WAIT_QUEUE_HEAD(module_unload_q); + struct netfront_stats { u64 packets; u64 bytes; @@ -2021,10 +2023,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; } @@ -2130,6 +2134,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