From nobody@FreeBSD.org  Mon Oct 21 00:41:59 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 33882EF8
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Oct 2013 00:41:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 20ACC2CB3
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Oct 2013 00:41:59 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r9L0fw6l079884
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Oct 2013 00:41:58 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r9L0fw4i079883;
	Mon, 21 Oct 2013 00:41:58 GMT
	(envelope-from nobody)
Message-Id: <201310210041.r9L0fw4i079883@oldred.freebsd.org>
Date: Mon, 21 Oct 2013 00:41:58 GMT
From: Adam McDougall <mcdouga9@egr.msu.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ifconfig options on xn0 lost after xen vm migration to another server
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         183139
>Category:       kern
>Synopsis:       [xen] [patch] ifconfig options on xn0 lost after xen vm migration to another server
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-xen
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 21 00:50:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Mon Nov 11 01:08:34 UTC 2013
>Originator:     Adam McDougall
>Release:        9.2-PRERELEASE
>Organization:
>Environment:
FreeBSD hostname 9.2-PRERELEASE FreeBSD 9.2-PRERELEASE #0 r255480: Wed Sep 11 19:30:27 EDT 2013     root@build9:/usr/obj/proto/src9/src/sys/AMD64-9  amd64

>Description:
If I change the "options" on any of the xn network interfaces with ifconfig then perform a xenmotion, the options are reset to default after the xenmotion.  This is on a server with XenServer 6.0.2 running fairly recent patches.  I plan to re-test on XenServer 6.2 but we don't have a pool setup yet.  I'd test on FreeBSD 10 but xen-tools needs to be built with gcc instead of clang and I haven't put much effort into that yet.
>How-To-Repeat:
# ifconfig xn0
xn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=503<RXCSUM,TXCSUM,TSO4,LRO>

# ifconfig xn0 -rxcsum
# ifconfig xn0 -lro
# ifconfig xn0
xn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=102<TXCSUM,TSO4>

(perform xenmotion)

# ifconfig xn0
xn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=503<RXCSUM,TXCSUM,TSO4,LRO>


>Fix:


>Release-Note:
>Audit-Trail:

From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= <roger.pau@citrix.com>
To: <bug-followup@FreeBSD.org>, <mcdouga9@egr.msu.edu>
Cc:  
Subject: Re: kern/183139: ifconfig options on xn0 lost after xen vm migration
 to another server
Date: Mon, 28 Oct 2013 17:13:01 +0100

 Hello,
 
 The following patch seems to solve the problem, but I'm not that much 
 familiar with netfront or net drivers in general (also netfront code is 
 not that great, which makes it even harder to understand IMHO).
 
 ---
 diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c
 index f9c72e6..99d3cf9 100644
 --- a/sys/dev/xen/netfront/netfront.c
 +++ b/sys/dev/xen/netfront/netfront.c
 @@ -2022,15 +2022,31 @@ static int
  xn_configure_features(struct netfront_info *np)
  {
  	int err;
 +	bool resume;
  
  	err = 0;
 +	resume = !!np->xn_ifp->if_capenable;
 +
 +	if (!resume || ((np->xn_ifp->if_capenable & np->xn_ifp->if_capabilities)
 +	    != np->xn_ifp->if_capenable)) {
 +	    	/*
 +	    	 * Check if current enabled capabilities are available,
 +	    	 * if not switch to default capabilities.
 +	    	 */
  #if __FreeBSD_version >= 700000
 -	if ((np->xn_ifp->if_capenable & IFCAP_LRO) != 0)
 -		tcp_lro_free(&np->xn_lro);
 +		if ((np->xn_ifp->if_capenable & IFCAP_LRO) != 0)
 +			tcp_lro_free(&np->xn_lro);
  #endif
 -    	np->xn_ifp->if_capenable =
 -	    np->xn_ifp->if_capabilities & ~(IFCAP_LRO|IFCAP_TSO4);
 -	np->xn_ifp->if_hwassist &= ~CSUM_TSO;
 +    		np->xn_ifp->if_capenable =
 +	    		np->xn_ifp->if_capabilities & ~(IFCAP_LRO|IFCAP_TSO4);
 +		np->xn_ifp->if_hwassist &= ~CSUM_TSO;
 +	} else {
 +		/*
 +		 * What we have currently enabled is supported by the
 +		 * new host, no need to change anything.
 +		 */
 +		return 0;
 +	}
  #if __FreeBSD_version >= 700000
  	if (xn_enable_lro && (np->xn_ifp->if_capabilities & IFCAP_LRO) != 0) {
  		err = tcp_lro_init(&np->xn_lro);
 -- 

From: Adam McDougall <mcdouga9@egr.msu.edu>
To: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= <roger.pau@citrix.com>, 
 bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/183139: ifconfig options on xn0 lost after xen vm migration
 to another server
Date: Mon, 28 Oct 2013 17:28:13 -0400

 On 10/28/2013 12:13, Roger Pau Monn wrote:
 > Hello,
 > 
 > The following patch seems to solve the problem, but I'm not that much 
 > familiar with netfront or net drivers in general (also netfront code is 
 > not that great, which makes it even harder to understand IMHO).
 > 
 > --- (trimmed)
 
 So far, it almost works as I expect.  It seems to work as long as at
 least one option is left (example: options=400<LRO>) but if I have none,
 they all come back on migrate.  Thanks.
 

From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= <roger.pau@citrix.com>
To: Adam McDougall <mcdouga9@egr.msu.edu>, <bug-followup@FreeBSD.org>
Cc:  
Subject: Re: kern/183139: ifconfig options on xn0 lost after xen vm migration
 to another server
Date: Tue, 29 Oct 2013 10:42:55 +0100

 On 28/10/13 22:28, Adam McDougall wrote:
 > So far, it almost works as I expect.  It seems to work as long as at
 > least one option is left (example: options=400<LRO>) but if I have none,
 > they all come back on migrate.  Thanks.
 
 Yes, the "resume" condition is not triggered if there isn't any 
 feature enabled. I've updated the patch, now it should work as expected:
 
 ---
 diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c
 index f9c72e6..52d8c11 100644
 --- a/sys/dev/xen/netfront/netfront.c
 +++ b/sys/dev/xen/netfront/netfront.c
 @@ -287,6 +287,8 @@ struct netfront_info {
  	multicall_entry_t	rx_mcl[NET_RX_RING_SIZE+1];
  	mmu_update_t		rx_mmu[NET_RX_RING_SIZE];
  	struct ifmedia		sc_media;
 +
 +	bool			xn_resume;
  };
  
  #define rx_mbufs xn_cdata.xn_rx_chain
 @@ -502,6 +504,7 @@ netfront_resume(device_t dev)
  {
  	struct netfront_info *info = device_get_softc(dev);
  
 +	info->xn_resume = true;
  	netif_disconnect_backend(info);
  	return (0);
  }
 @@ -2024,13 +2027,28 @@ xn_configure_features(struct netfront_info *np)
  	int err;
  
  	err = 0;
 +
 +	if (!np->xn_resume ||
 +	    ((np->xn_ifp->if_capenable & np->xn_ifp->if_capabilities)
 +	    != np->xn_ifp->if_capenable)) {
 +	    	/*
 +	    	 * Check if current enabled capabilities are available,
 +	    	 * if not switch to default capabilities.
 +	    	 */
  #if __FreeBSD_version >= 700000
 -	if ((np->xn_ifp->if_capenable & IFCAP_LRO) != 0)
 -		tcp_lro_free(&np->xn_lro);
 +		if ((np->xn_ifp->if_capenable & IFCAP_LRO) != 0)
 +			tcp_lro_free(&np->xn_lro);
  #endif
 -    	np->xn_ifp->if_capenable =
 -	    np->xn_ifp->if_capabilities & ~(IFCAP_LRO|IFCAP_TSO4);
 -	np->xn_ifp->if_hwassist &= ~CSUM_TSO;
 +    		np->xn_ifp->if_capenable =
 +	    		np->xn_ifp->if_capabilities & ~(IFCAP_LRO|IFCAP_TSO4);
 +		np->xn_ifp->if_hwassist &= ~CSUM_TSO;
 +	} else {
 +		/*
 +		 * What we have currently enabled is supported by the
 +		 * new host, no need to change anything.
 +		 */
 +		return 0;
 +	}
  #if __FreeBSD_version >= 700000
  	if (xn_enable_lro && (np->xn_ifp->if_capabilities & IFCAP_LRO) != 0) {
  		err = tcp_lro_init(&np->xn_lro);
 
 

From: Adam McDougall <mcdouga9@egr.msu.edu>
To: Roger Pau =?iso-8859-1?Q?Monn=E9?= <roger.pau@citrix.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/183139: ifconfig options on xn0 lost after xen vm migration
 to another server
Date: Wed, 30 Oct 2013 16:58:28 -0400

 Thanks, this works!
 
 On Tue, Oct 29, 2013 at 10:42:55AM +0100, Roger Pau Monn wrote:
 
   On 28/10/13 22:28, Adam McDougall wrote:
   > So far, it almost works as I expect.  It seems to work as long as at
   > least one option is left (example: options=400<LRO>) but if I have none,
   > they all come back on migrate.  Thanks.
   
   Yes, the "resume" condition is not triggered if there isn't any 
   feature enabled. I've updated the patch, now it should work as expected:
   
   ---
   diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c
   index f9c72e6..52d8c11 100644
   --- a/sys/dev/xen/netfront/netfront.c
   +++ b/sys/dev/xen/netfront/netfront.c
   @@ -287,6 +287,8 @@ struct netfront_info {
    	multicall_entry_t	rx_mcl[NET_RX_RING_SIZE+1];
    	mmu_update_t		rx_mmu[NET_RX_RING_SIZE];
    	struct ifmedia		sc_media;
   +
   +	bool			xn_resume;
    };
    
    #define rx_mbufs xn_cdata.xn_rx_chain
   @@ -502,6 +504,7 @@ netfront_resume(device_t dev)
    {
    	struct netfront_info *info = device_get_softc(dev);
    
   +	info->xn_resume = true;
    	netif_disconnect_backend(info);
    	return (0);
    }
   @@ -2024,13 +2027,28 @@ xn_configure_features(struct netfront_info *np)
    	int err;
    
    	err = 0;
   +
   +	if (!np->xn_resume ||
   +	    ((np->xn_ifp->if_capenable & np->xn_ifp->if_capabilities)
   +	    != np->xn_ifp->if_capenable)) {
   +	    	/*
   +	    	 * Check if current enabled capabilities are available,
   +	    	 * if not switch to default capabilities.
   +	    	 */
    #if __FreeBSD_version >= 700000
   -	if ((np->xn_ifp->if_capenable & IFCAP_LRO) != 0)
   -		tcp_lro_free(&np->xn_lro);
   +		if ((np->xn_ifp->if_capenable & IFCAP_LRO) != 0)
   +			tcp_lro_free(&np->xn_lro);
    #endif
   -    	np->xn_ifp->if_capenable =
   -	    np->xn_ifp->if_capabilities & ~(IFCAP_LRO|IFCAP_TSO4);
   -	np->xn_ifp->if_hwassist &= ~CSUM_TSO;
   +    		np->xn_ifp->if_capenable =
   +	    		np->xn_ifp->if_capabilities & ~(IFCAP_LRO|IFCAP_TSO4);
   +		np->xn_ifp->if_hwassist &= ~CSUM_TSO;
   +	} else {
   +		/*
   +		 * What we have currently enabled is supported by the
   +		 * new host, no need to change anything.
   +		 */
   +		return 0;
   +	}
    #if __FreeBSD_version >= 700000
    	if (xn_enable_lro && (np->xn_ifp->if_capabilities & IFCAP_LRO) != 0) {
    		err = tcp_lro_init(&np->xn_lro);
   
   
Responsible-Changed-From-To: freebsd-bugs->freebsd-xen 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Nov 11 01:07:54 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=183139 
>Unformatted:
