Received: by 10.223.164.202 with SMTP id h10csp792337wrb; Thu, 23 Nov 2017 06:19:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMbswlYzIn9iGIrEmpGw6KUJBQltbAZNzLS9ygzhSPmtPU9bKW+SxKpGRFhFVj40j4tFA+ht X-Received: by 10.98.107.133 with SMTP id g127mr22914422pfc.228.1511446785134; Thu, 23 Nov 2017 06:19:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511446785; cv=none; d=google.com; s=arc-20160816; b=QpWcGIgMZAuCTexe0/6jrMBDhp/DfAc7m7Jm5cM9gCY6/TVfwx2ijDKmik45nj1J5r LzJUcFXdqXwRzPcTYSWD/DhuVwC3fe80rFoiR8adVNFFGvFcLu/dErDfgFDIrVlW+n3X W+MMfnwKzJ/73L7YuQ0PSapYf+xnWLlbyEMdfdcEvUAsGWv6w6J/PUiwThaJDZQBg6jd YP37bcKji4H157HFgGOVwtOMdE7xDiZmdKjYgkJpp5SRTqIjKsfg3CSMRn5fXCxJVe3E vUJtGvK23/D3ZcdlXt+hcAFh2wb12gms834jIDv1TJnrRUbpxUrgB5hetUvqNYnE0Cgk q8bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8ivYN9az4a54BNNiRIwTU/AwEq3YTQVoJDfy31L2BjU=; b=It9c+j/fxtFP2KFhSY+awbDM569H0u9xPjHOPNZfipVKW6DQxv8+yvcskTtxZZan0v BTM3JvuDydaFIkvs0QxcHBQYG4SipsKU4/8erFJ9JdE2Z7vYhtJ0Tn4QG1nPCiCKekma S/5hjrZmuYbcun1k9jFqcsJq/dMrQWuBONIT2ZpYnhu6t9l83ihI6xINuyNggzDuKN7U +M/hrurAYBzF4gVY3x+q+BXq+5mq+tu7myhBfqd0bQJ43xx3Ql5LjGovtzDZI+qijsKR 2AClsd6n5+vNtr4tPoTVinMYEsEpXnPS3usYVF1CiGN6o9dQ7AuUNL5vrb2hQrw9Vvm7 qrEw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j70si15541262pge.82.2017.11.23.06.19.34; Thu, 23 Nov 2017 06:19:45 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753050AbdKWOSw (ORCPT + 75 others); Thu, 23 Nov 2017 09:18:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40902 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751921AbdKWOSu (ORCPT ); Thu, 23 Nov 2017 09:18:50 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1CA95FD51; Thu, 23 Nov 2017 14:18:50 +0000 (UTC) Received: from vader.redhat.com (unknown [10.36.118.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8779961781; Thu, 23 Nov 2017 14:18:45 +0000 (UTC) From: Eduardo Otubo To: xen-devel@lists.xenproject.org Cc: netdev@vger.kernel.org, paul.durrant@citrix.com, wei.liu2@citrix.com, linux-kernel@vger.kernel.org, vkuznets@redhat.com, cavery@redhat.com, cheshi@redhat.com, mgamal@redhat.com, jgross@suse.com, boris.ostrovsky@oracle.com Subject: [PATCHv2] xen-netfront: remove warning when unloading module Date: Thu, 23 Nov 2017 15:18:35 +0100 Message-Id: <20171123141835.5820-1-otubo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 23 Nov 2017 14:18:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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) +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 *dev, 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; } @@ -2130,6 +2134,20 @@ static int xennet_remove(struct xenbus_device *dev) 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); unregister_netdev(info->netdev); -- 2.13.6 From 1585247128933352012@xxx Mon Nov 27 19:04:32 +0000 2017 X-GM-THRID: 1585247128933352012 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread