[PATCH]netfront: need release all resources after adding and removing NICs time and again

liuyingdong liuyingdong at huawei.com
Tue Dec 13 06:05:03 UTC 2016


Hello Roger,
    I want to know how about this patch,Please let me know if you have any questions.
    Thanks.

                                                                  Yours

On 2016/11/11 10:04, liuyingdong wrote:
> Hello Roger,
> 	Sorry, I am a freshman. I ran the following command to git kernel source of freebsd 10.2.0:
> 		git clone https://github.com/freebsd/freebsd.git
> 		git checkout origin/release/10.2.0
> 	On the base of the above, I make a patch file as fellows:
> 
> diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c
> index d89c0e0..903eb98 100644
> --- a/sys/dev/xen/netfront/netfront.c
> +++ b/sys/dev/xen/netfront/netfront.c
> @@ -2172,6 +2172,46 @@ netfront_detach(device_t dev)
>  }
> 
>  static void
> +netif_release_rx_bufs_copy(struct netfront_info *np)
> +{
> +	struct mbuf *m;
> +	int i, ref;
> +	int busy = 0, inuse = 0;
> +
> +	XN_RX_LOCK(np);
> +
> +	for (i = 0; i < NET_RX_RING_SIZE; i++) {
> +		ref = np->grant_rx_ref[i];
> +
> +		if (ref == GRANT_REF_INVALID)
> +			continue;
> +
> +		inuse++;
> +
> +		m = 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] = GRANT_REF_INVALID;
> +		add_id_to_freelist(np->rx_mbufs, i);
> +
> +		m_freem(m);
> +	}
> +
> +	if (busy)
> +		device_printf(np->xbdev, "Unable to release %d of %d "
> +			"inuse grant references out of %ld total.\n",
> +			busy, inuse, NET_RX_RING_SIZE);
> +	
> +	XN_RX_UNLOCK(np);
> +}
> +
> +static void
>  netif_free(struct netfront_info *info)
>  {
>  	XN_LOCK(info);
> @@ -2185,6 +2225,13 @@ netif_free(struct netfront_info *info)
>  		info->xn_ifp = 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
> 
> 
> Yours Yingdong Liu
> 
> 
> -----邮件原件-----
> 发件人: roger.pau at citrix.com [mailto:roger.pau at citrix.com]
> 发送时间: 2016年11月8日 21:05
> 收件人: Liuyingdong
> 抄送: freebsd-xen at freebsd.org; Zhaojun (Euler); Suoben
> 主题: Re: [PATCH]netfront: need release all resources after adding and removing NICs time and again
> 
> On Fri, Nov 04, 2016 at 07:43:41AM +0000, Liuyingdong wrote:
>> On xen,freebsd 10.2 virtual machines hang after adding and removing NICs time and again(more than 30 times).
>> I found error log is as follows:
>> "netfront can't alloc tx grant refs"
> 
> Hello,
> 
> Thanks for the patch, although I'm not able to import it, git complain with:
> 
> patch: **** malformed patch at line 7: }
> 
> Could you please resend it using git send-email?
> 
> I also have a couple of comments below regarding style.
> 
>>
>> Signed-off-by: Yingdong Liu<liuyingdong at 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)
>>        }
>> }
> 
> Missing new line.
> 
>> +static void
> netif_release_rx_bufs_copy(struct netfront_info *np)
> 
> This needs to be on a new line.
> 
>> +{
>> +       struct mbuf *m;
>> +       int i, ref;
>> +       int busy = 0, inuse = 0;
>> +
>> +       XN_RX_LOCK(np);
>> +
>> +       for (i = 0; i < NET_RX_RING_SIZE; i++) {
>> +                ref = np->grant_rx_ref[i];
>> +
>> +                if (ref == GRANT_REF_INVALID)
>> +                          continue;
>> +
>> +                inuse++;
>> +
>> +                m = 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] = 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 references out of %ld total.\n",
>> +                          __FUNCTION__, busy, inuse,
>> + NET_RX_RING_SIZE);
> 
> Please use device_printf for this instead of the function name. Also, could you align the string so it doesn't extend past 80 characters?
> 
> Roger.
> 



More information about the freebsd-xen mailing list