Received: by 10.223.176.5 with SMTP id f5csp528546wra; Fri, 2 Feb 2018 01:46:21 -0800 (PST) X-Google-Smtp-Source: AH8x227+v21G5SF7nLw2wUH0JyXJGob3IixUYU20fyZmOlv1+7VUp+XWV412WdVp/29SAJ1gTSnD X-Received: by 2002:a17:902:820c:: with SMTP id x12-v6mr35502354pln.103.1517564781748; Fri, 02 Feb 2018 01:46:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517564781; cv=none; d=google.com; s=arc-20160816; b=Ob4rqeLNLo7FUbIZGj+Ag31DEsFfISD0Yg7dHLdakX2HPbXLW4msZPoYrJFvP6/f3u 1JsYiciORDsiKF5Ujy/zwBEUqIQyT6BEOeyrzSApDPH1z5jKNW7URqtDKqAGJvlT/4cV wchzmj5dSUMlmXPEXdnIGj0KFycQwcMAW4oycOLuMiKAV/vq5i8r66XJtG3QfDOEvHzH rQmIkbsPdk2giTDhU/ZgZU0oTGqkwBKPkEFpfUBzBx5hsgBfSlxXtQeDmEP7n2YO/Dwc RuACkPPZJXKleLVDvLnhy1/Jpg+fYXPQRN8Jhv3SbrLlciSLyuZL0TqSU2irzKpImJeH Td4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=BpmPJhqK3T9cH9Eb2m+OvGOv3GI5jdopwkYZxLp5BiA=; b=G8dp4FCJnHGkeGUnKoCXITFwW+Rysa6+D8aGRqbbStWRlkLNuoAE5j0UjZDIbbWtDt mpRf02De+yVN5P0uXXZbkW+6JVDw2U184K72EuBFlTqFjhCnTYGYSbmMmDZrWMBzQoDb gU6+bMw2Ijg3RhISfy7tETVrTt2q4Rqj1kjnVJt1HoqbE4YchjSI7oGA62NQRjsoyZZ1 0otHNYFQ3rza9GRWq7EPr2rZDKUuvSx/IqbTitrPpXLK+Wu6jiYgrU2XGbmQd0VPLvps elohuXIfYz8EJStl0kbjUyQRxTmP6EpxQWkIqXu12XuKyvrlgiSeaoe63GDx+m8r8CEI leSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CK1sbF18; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si1428616plo.697.2018.02.02.01.46.07; Fri, 02 Feb 2018 01:46:21 -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=@gmail.com header.s=20161025 header.b=CK1sbF18; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751708AbeBBJpf (ORCPT + 99 others); Fri, 2 Feb 2018 04:45:35 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:46207 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750781AbeBBJpZ (ORCPT ); Fri, 2 Feb 2018 04:45:25 -0500 Received: by mail-lf0-f68.google.com with SMTP id q194so30507940lfe.13; Fri, 02 Feb 2018 01:45:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=BpmPJhqK3T9cH9Eb2m+OvGOv3GI5jdopwkYZxLp5BiA=; b=CK1sbF18rps4ZNyScTG3l78GZN+DVMRYc2WxUx7+smp+8pdTwhdecsCiRO9qOR/OIS WG4JRfF+iOfI8rFCvFVpSELJSlIaM3i2K6YJHZBI9jSPSY2F9GothmTGN1RCs1n5lOcx BfM0iLNz2hz8nZsaSiO04gTPwSY3Jq8DZ7PJZLzKtUXIS/EhO6TNcUHQYOnl443/Q2Tm /9kvRSVHIOdyn9Tx0oNFGpZgxCxjLIKqE7pDz1EvGcPY6DCaM6tLKxGNwKPUfx5plDU6 U78TiRCKNF99FFwx8/1Nk9VSoTU5ZANMTBIJQmgtWaYa0HVg8xPxMxxiqItnvFSmYxjY +GoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=BpmPJhqK3T9cH9Eb2m+OvGOv3GI5jdopwkYZxLp5BiA=; b=odPtBURIOdH5LMepO5kZ2FGP8c1VFjRZ3W7+2psBevsKFCvuqI1GUrCrHzwSt+kCiW yUbaErcf1SRzMgPQlExKMGY7YfipVsCqGmLAk1B5pCB+sepBOEu3LBuKTURMUuNhJgM7 MaAPmOLvLKOKnfHwWHtIa7B0EGP6yDCK2r2I3I871VyKnRiBp4jz0EmMltpEw+ccCa3/ vBtpnBZJzJEPggt5BFiZbyDM9vfKn0PpFK611wmyfiFpd5wlM99yUMHv11wqsnkdtRbX PxWNVGMDgIIMmVZU6yOVdVArzHsheOrOX45OLurmVwjG202GZ5DzjQ/uenvP2CPaYPwe 5rkw== X-Gm-Message-State: AKwxyte5ag2iKZg3KMmPHMN0cbY+jdNWfUPf7BnPftXhCEzgKwRoS91T 1Ypvzo50ECcTRZ8Rw+rM+E4= X-Received: by 10.25.222.18 with SMTP id v18mr23388518lfg.92.1517564723432; Fri, 02 Feb 2018 01:45:23 -0800 (PST) Received: from [10.17.182.9] (ll-54.209.223.85.sovam.net.ua. [85.223.209.54]) by smtp.gmail.com with ESMTPSA id q11sm304095lje.42.2018.02.02.01.45.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 01:45:22 -0800 (PST) Subject: Re: [Xen-devel] [PATCHv2] xen-netfront: remove warning when unloading module To: Eduardo Otubo Cc: xen-devel@lists.xenproject.org, jgross@suse.com, wei.liu2@citrix.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, paul.durrant@citrix.com, cheshi@redhat.com, vkuznets@redhat.com, mgamal@redhat.com, cavery@redhat.com, boris.ostrovsky@oracle.com References: <20171123141835.5820-1-otubo@redhat.com> <20180202085428.GA26899@vader> From: Oleksandr Andrushchenko Message-ID: Date: Fri, 2 Feb 2018 11:45:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180202085428.GA26899@vader> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/02/2018 10:54 AM, Eduardo Otubo wrote: > On Wed, Jan 31, 2018 at 05:00:23PM +0200, Oleksandr Andrushchenko wrote: >> Hi, Eduardo! >> >> I am working on a frontend driver (PV DRM) and also seeing some strange >> >> things on driver unloading: >> >> xt# rmmod -f drm_xen_front.ko >> [ 3236.462497] [drm] Unregistering XEN PV vdispl >> [ 3236.485745] [drm:xen_drv_remove [drm_xen_front]] *ERROR* Backend state is >> InitWait while removing driver >> [ 3236.486950] vdispl vdispl-0: 22 freeing event channel 11 >> [ 3236.496123] vdispl vdispl-0: failed to write error node for >> device/vdispl/0 (22 freeing event channel 11) >> [ 3236.496271] vdispl vdispl-0: 22 freeing event channel 12 >> [ 3236.501633] vdispl vdispl-0: failed to write error node for >> device/vdispl/0 (22 freeing event channel 12) >> >> These are somewhat different from your use-case with grant references, but I >> have a question: >> >> do you really see that XenbusStateClosed and XenbusStateClosing are >> >> called? In my driver I can't see those and once I tried to dig deeper into >> the problem >> >> I saw that on driver removal it is disconnected from XenBus, so no backend >> state >> >> change events come in via .otherend_changed callback. >> >> The only difference I see here is that the backend is a user-space >> application >> >> Thank you, >> Oleksandr > To be honest, most of the things I assumed were true, according to some talks on > IRC with maintainers. Since I assumed it was true I started to write code based > on that and all the behaviors that followed were correct according to my > assumptions (and discussions). > > But if you find something else weird, please let me know and we can fix it. There is nothing wrong with the patch. One thing that I cannot get in my driver is that .otherend_changed callback is not called on .remove. Please see [1] >> On 11/23/2017 04:18 PM, Eduardo Otubo wrote: >>> 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); [1] https://patchwork.kernel.org/patch/10195163/