From owner-freebsd-xen@freebsd.org Fri Nov 4 07:54:58 2016 Return-Path: Delivered-To: freebsd-xen@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E50CDC2F687 for ; Fri, 4 Nov 2016 07:54:58 +0000 (UTC) (envelope-from liuyingdong@huawei.com) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [119.145.14.66]) by mx1.freebsd.org (Postfix) with ESMTP id 74A4F1EC1 for ; Fri, 4 Nov 2016 07:54:54 +0000 (UTC) (envelope-from liuyingdong@huawei.com) Received: from 172.24.1.60 (EHLO SZXEMA417-HUB.china.huawei.com) ([172.24.1.60]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CKU72020; Fri, 04 Nov 2016 15:43:50 +0800 (CST) Received: from SZXEMA506-MBS.china.huawei.com ([169.254.4.3]) by SZXEMA417-HUB.china.huawei.com ([10.82.72.34]) with mapi id 14.03.0235.001; Fri, 4 Nov 2016 15:43:42 +0800 From: Liuyingdong To: "roger.pau@citrix.com" CC: "freebsd-xen@freebsd.org" , "Zhaojun (Euler)" , Suoben Subject: [PATCH]netfront: need release all resources after adding and removing NICs time and again Thread-Topic: [PATCH]netfront: need release all resources after adding and removing NICs time and again Thread-Index: AdI2bwZCMPRaycDjRRazBkm6EMcXXQ== Date: Fri, 4 Nov 2016 07:43:41 +0000 Message-ID: <3655E9A8B903724782E1F75DCFD74E6BF966FF5A@szxema506-mbs.china.huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.177.20.238] MIME-Version: 1.0 X-CFilter-Loop: Reflected Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-xen@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussion of the freebsd port to xen - implementation and usage List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Nov 2016 07:54:59 -0000 On xen,freebsd 10.2 virtual machines hang after adding and removing NICs ti= me and again(more than 30 times). I found error log is as follows: "netfront can't alloc tx grant refs" Signed-off-by: Liudong Liu diff --git a/dev/xen/netfront/netfront.c b/dev/xen/netfront/netfront.c index 5497139..e96bbba 100644 --- a/dev/xen/netfront/netfront.c +++ b/dev/xen/netfront/netfront.c @@ -790,6 +790,44 @@ netif_release_tx_bufs(struct netfront_info *np) } } +static void netif_release_rx_bufs_copy(struct netfront_info *np) +{ + struct mbuf *m; + int i, ref; + int busy =3D 0, inuse =3D 0; + + XN_RX_LOCK(np); + + for (i =3D 0; i < NET_RX_RING_SIZE; i++) { + ref =3D np->grant_rx_ref[i]; + + if (ref =3D=3D GRANT_REF_INVALID) + continue; + + inuse++; + + m =3D np->rx_mbufs[i]; + + if (!gnttab_end_foreign_access_ref(ref)) + { + busy++; + continue; + } + + gnttab_release_grant_reference(&np->gref_rx_head, ref); + np->grant_rx_ref[i] =3D GRANT_REF_INVALID; + add_id_to_freelist(np->rx_mbufs, i); + + m_freem(m); + } + + if (busy) + DPRINTK("%s: Unable to release %d of %d inuse grant refere= nces out of %ld total.\n", + __FUNCTION__, busy, inuse, NET_RX_RING_SIZE); + + XN_RX_UNLOCK(np); +} + static void network_alloc_rx_buffers(struct netfront_info *sc) { @@ -2185,6 +2223,13 @@ netif_free(struct netfront_info *info) info->xn_ifp =3D NULL; } ifmedia_removeall(&info->sc_media); + + netif_release_tx_bufs(info); + if (info->copying_receiver) + netif_release_rx_bufs_copy(info); + gnttab_free_grant_references(info->gref_tx_head); + gnttab_free_grant_references(info->gref_rx_head); + } static void