Date: Fri, 4 Nov 2016 07:43:41 +0000 From: Liuyingdong <liuyingdong@huawei.com> To: "roger.pau@citrix.com" <roger.pau@citrix.com> Cc: "freebsd-xen@freebsd.org" <freebsd-xen@freebsd.org>, "Zhaojun (Euler)" <zhao.zhaojun@huawei.com>, Suoben <suoben@huawei.com> Subject: [PATCH]netfront: need release all resources after adding and removing NICs time and again Message-ID: <3655E9A8B903724782E1F75DCFD74E6BF966FF5A@szxema506-mbs.china.huawei.com>
next in thread | raw e-mail | index | archive | help
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<Liuyingdong@huawei.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3655E9A8B903724782E1F75DCFD74E6BF966FF5A>