Received: by 10.223.176.46 with SMTP id f43csp278275wra; Tue, 23 Jan 2018 20:55:07 -0800 (PST) X-Google-Smtp-Source: AH8x225jL236E9d2K3lNQc4Bov21zMAPJ6zkWSObnlq/MHSs49LEmuS9LxOyAitrn9YNuRHJxbXo X-Received: by 10.98.153.197 with SMTP id t66mr9892459pfk.142.1516769707373; Tue, 23 Jan 2018 20:55:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769707; cv=none; d=google.com; s=arc-20160816; b=sZaNFAo1aAkfnjzAFj/M/sveKtEkm1LgUSWVKiNXSEeQfzB/BkEVlCq5SU09G6TfOt GasMF5cPzz/ElUIrdp7OYVWqpP2++K+d4vXZcinov2lc5f+l19a4YviUhN9CP7qPrJnq nJ3ErD1IXqaNMaJ7wyhYH6HBHIM0TqTkEaIo5WF6DWGrfJzR+VWBRQfAYXgpKDVaG1fr bAm+G1eFN2rpkRvQ3AGRRNxZLUUt0s3G5TAQRYIi5Tgdqh4I/Vgmwn+AJ2tlJuJf5a0N PMc1+ZKhg18mQMBBIu6Hmgq4zvC4KI0PnhF7wX39OjJUBdkiVua1+z+as8YfEWMUgkO5 uv0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=9DOzrwKL/ISEqyYhHltMkqeB36XI5Ol98Jhb6nTLCes=; b=Or4vVLZeRX1BjaBx75l6ps1dqcX0ewaOlUEUXJSMtaIk7fNPeo8PrnEQbxsKBDymMv lATx4hfL7v4NvddnmHeO+627+6lKy7rsZV98CYVnLOJS6Zu38uXbhwOv9Vc7WiPKpMK6 DwQCrhJE15WRphzbSHiCtEJIIkJraKeItw8FjAn5NebdQG6pFCY2JKNFbfSElG8ZaCT5 4lZJllC6moclB/kyHY/wvzV11xJT62MLGiBdsQnr91bllH9/qrKRW/kHSkqx/t2E48x9 xnUq5VC6qHiyiTd0YZuqFt7MYLdQ/11iMPKJVSxGm5FIYdnrsYKRUSxQF6tu94l+w7Yv M+sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=eI3PWHQG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62-v6si3752672plb.297.2018.01.23.20.54.53; Tue, 23 Jan 2018 20:55:07 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=eI3PWHQG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932304AbeAXEPe (ORCPT + 99 others); Tue, 23 Jan 2018 23:15:34 -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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=9DOzrwKL/ISEqyYhHltMkqeB36XI5Ol98Jhb6nTLCes=; b=eI3PWHQGSDptWTN00BkGZcOsVGm6pd4WRETguSwOL6jGUYH37yYZfNrPtco89duAUEhzqu0YGHi7BDpPOHR4WeYjllHqDDNToqzIUZ5T96cWuaBKo2vE+SNT0GO4YXcPVzdjnMbLKdj7EkmYOCzmWHKZ59mThvvKdycCJczdsV8= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.0; Wed, 24 Jan 2018 04:15:19 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:19 +0000 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; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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