Bug 890288

Summary: use set_link to change rtl8139 and e1000 network card's status but fail to make effectively after reboot guest
Product: Red Hat Enterprise Linux 6 Reporter: Sibiao Luo <sluo>
Component: qemu-kvmAssignee: Amos Kong <akong>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.4CC: acathrow, ailan, akong, areis, bsarathy, chayang, dyasny, flang, jasowang, juzhang, michen, mkenneth, mst, qzhang, rhod, sluo, stefanha, tlavigne, virt-maint
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.349.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 907716 913425 (view as bug list) Environment:
Last Closed: 2013-02-21 07:45:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 907397, 907716, 913425    

Description Sibiao Luo 2012-12-26 08:19:13 UTC
Description of problem:
boot guest with rtl8139/e1000 nic device, then set_link the rtl8139/e1000 network card's status to 'off' and check it status is 'down' in guest, but after reboot guest, it will return back to 'up' status. 
BTW, both the rtl8139 and e1000 nic device have this issue, but virtio_net has no such issue.

Version-Release number of selected component (if applicable):
host info:
# uname -r && rpm -q qemu-kvm
2.6.32-351.el6.x86_64
qemu-kvm-0.12.1.2-2.348.el6.x86_64
guest info:
rhel6.4 64bit
kernel-2.6.32-351.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1.boot guest with rtl8139/e1000/virtio_net nic device.
eg:...-netdev tap,id=hostnet1,vhost=on,script=/etc/qemu-ifup -device e1000,netdev=hostnet1,id=e1000-net-pci1,mac=34:40:B5:9E:D3:91,bus=pci.0,addr=0x5
2.check nic status in guest(default: 'up').
# cat /sys/class/net/eth0/operstate 
up
3.change nic status in monitor.
(qemu) set_link $network_device off
4.re-check nic status in guest.
# cat /sys/class/net/eth0/operstate 
down
5.reboot guest and recheck nic status.
# cat /sys/class/net/eth0/operstate
  
Actual results:
after step 5, the rtl8139/e1000 network card's status return back to 'up', but the virtio_net nic is still 'down' status.
# cat /sys/class/net/eth0/operstate
up                   <---------for rtl8139/e1000

Expected results:
the rtl8139/e1000 network card's status is still 'down' status after reboot guest.
# cat /sys/class/net/eth0/operstate
down

Additional info:

Comment 2 Amos Kong 2012-12-27 11:05:33 UTC
This problem can also be reproduced by this steps:

1. boot a guest with e1000 / rtl8139 nic (pause guest by -S option)
2. set link down by monitor
  (qemu) set_link ... off
3. continue guest
  (qemu) c
4. check link status in guest

Comment 3 Amos Kong 2012-12-28 02:07:12 UTC
I tried with latest guest kernel (3.6.10-2.fc17.x86_64, driver updated) & latest upstream qemu

+ virtio-net:
  after reboot, link status is down in guest, network is unavailable.
+ rtl8139:
  after reboot, link status is unexpectedly up in guest, network is unavailable.
+e1000: (guest reboot will reset qemu setup)
  after reboot, link will be reset to be up, and network is (unexpectedly) available.

Comment 4 jason wang 2012-12-28 03:40:41 UTC
(In reply to comment #3)
> I tried with latest guest kernel (3.6.10-2.fc17.x86_64, driver updated) &
> latest upstream qemu
> 
> + virtio-net:
>   after reboot, link status is down in guest, network is unavailable.
> + rtl8139:
>   after reboot, link status is unexpectedly up in guest, network is
> unavailable.
> +e1000: (guest reboot will reset qemu setup)
>   after reboot, link will be reset to be up, and network is (unexpectedly)
> available.

Need to check whether the link status were preserved during reset for 8139. For e1000, I remember that there's a patch to preserved the link status, need to check whether the link status negotiation emulation patch has side effect of this.

Thanks

Comment 5 Amos Kong 2012-12-28 08:03:29 UTC
For e1000, link auto-negotiation emulation will always set link up in e1000_autoneg_timer, it's a regression bug, can be fixed by this patch:

diff --git a/hw/e1000.c b/hw/e1000.c
index 5537ad2..a3b602e 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -164,6 +164,10 @@ static void
 set_phy_ctrl(E1000State *s, int index, uint16_t val)
 {
     if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) {
+        if (s->nic->nc.link_down) {
+            s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE;
+            return;
+        }
         s->nic->nc.link_down = true;
         e1000_link_down(s);
         s->phy_reg[PHY_STATUS] &= ~MII_SR_AUTONEG_COMPLETE;

Comment 6 Amos Kong 2012-12-28 09:37:46 UTC
Posted two patches to upstream:
http://lists.gnu.org/archive/html/qemu-devel/2012-12/msg03555.html

  e1000: no need auto-negotiation if link was down
  rtl8139: preserve link state across device reset

(tested with wxp & rhel6 guests)

Comment 7 Amos Kong 2012-12-29 00:49:53 UTC
Hi Ademar,

> +e1000: (guest reboot will reset qemu setup)
>   after reboot, link will be reset to be up, and network is (unexpectedly)
> available.

^^^ rhel6 kernel & qemu-kvm-rhel6 also got this result

So if Admin limits VM user network by set_link, user can smartly re-got network by a reboot

For e1000, it is a regression introduced in RHEL6.4 by this commit:
so I agree to bug this bz in 6.4 by exception+

| commit ebfdba95f6fd2719dda11f4ebd9267af270e921b
| Author: Xiao Wang <jasowang>
| Date:   Fri Aug 10 09:03:49 2012 -0300
| 
|     e1000: link auto-negotiation emulation

Comment 8 Ademar Reis 2013-01-02 12:58:23 UTC
(In reply to comment #7)
> For e1000, it is a regression introduced in RHEL6.4 by this commit:
> so I agree to bug this bz in 6.4 by exception+
> 
> | commit ebfdba95f6fd2719dda11f4ebd9267af270e921b
> | Author: Xiao Wang <jasowang>
> | Date:   Fri Aug 10 09:03:49 2012 -0300
> | 
> |     e1000: link auto-negotiation emulation

Thanks for the details. Adding Regression keyword and requesting the blocker flag.

Comment 12 Sibiao Luo 2013-01-09 08:39:18 UTC
Verify this bug on qemu-kvm-0.12.1.2-2.349.el6.x86_64 with the comment #0 steps.

host info:
kernel-2.6.32-351.el6.x86_64
qemu-kvm-0.12.1.2-2.349.el6.x86_64
guest info:
kernel-2.6.32-351.el6.x86_64

steps:
the same to comment #0

Results:
after step 5, the rtl8139/e1000 network card's status is still 'down' status after reboot guest, and the network is unavailable.

Base on above, this issue has been fixed correctly.

Comment 14 Amos Kong 2013-02-01 07:59:20 UTC
http://marc.info/?t=135967653900002&r=1&w=3

Michael Roth (mdroth.ibm.com) raised a possible problem in upstream, I will track on it.

Comment 19 errata-xmlrpc 2013-02-21 07:45:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2013-0527.html