Skip to contentSkip to conversation

only writing out the last byte of MAC makes it have effect

RFC PATCH In review Amos Kong 3 participants 8 messages Mar 21, 2013 – Apr 8, 2013 virtio core

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

RFC PATCH 1/1 only writing out the last byte of MAC makes it have effect

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. We can change QEMU to make MAC change effect when the last byte of MAC is written to config space.

---
 virtio-spec.lyx | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
virtio-spec.lyx +10 -1
index dbc4ef0..bb289fb 100644
@@ -5430,7 +5430,7 @@ T_CTRL_MAC_TABLE_SET.
 
 \begin_layout Standard
 
-\change_inserted -1930653948 1358506710
+\change_inserted -1930653948 1363832689
 The config space 
 \begin_inset Quotes eld
 \end_inset
@@ -5464,6 +5464,15 @@ mac
  Therefore, VIRTIO_NET_CTRL_MAC_ADDR_SET is preferred, especially while
  the NIC is up.
  The command-specific-data is a 6-byte MAC address.
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted -1930653948 1363833477
+The legacy guests don't support the new command, they still change MAC address
+ in original way, that's not atomic.
+ For more robust, QEMU only makes the MAC change effect when the last byte
+ of MAC address is written to config space.
 \change_unchanged
 
 \end_layout
Signature · 1 line
1.8.1.4
author
#1 lore raw

RFC PATCH 1/1 only writing out the last byte of MAC makes it have effect

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. This patch changed qemu to makes MAC change effect when the last byte of MAC is written to config space.

MAC address takes first 6 bytes of config space of virtio-net, the addr is 5 when the last byte is written in virtio_config_writeb().

MAC change will effect when n->mac is updated in virtio_net_set_config().

---
 hw/virtio.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/virtio.c +2 -1
index 26fbc79..2e08302 100644
@@ -605,8 +605,9 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 
     stb_p(vdev->config + addr, val);
 
-    if (vdev->set_config)
+    if (vdev->set_config && (addr == 5 || strcmp(vdev->name, "virtio-net"))) {
         vdev->set_config(vdev, vdev->config);
+    }
 }
 
 void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
Signature · 1 line
1.7.1
#2 lore raw
Quoted 10 lines · Amos Kong

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. This patch changed qemu to makes MAC change effect when the last byte of MAC is written to config space.

MAC address takes first 6 bytes of config space of virtio-net, the addr is 5 when the last byte is written in virtio_config_writeb().

MAC change will effect when n->mac is updated in virtio_net_set_config().

Let's see what Rusty says about the spec change.

Quoted 21 lines
---
 hw/virtio.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/virtio.c +2 -1
index 26fbc79..2e08302 100644
@@ -605,8 +605,9 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 
     stb_p(vdev->config + addr, val);
 
-    if (vdev->set_config)
+    if (vdev->set_config && (addr == 5 || strcmp(vdev->name, "virtio-net"))) {
         vdev->set_config(vdev, vdev->config);
+    }
 }
 
 void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
Signature · 1 line
1.7.1
#3 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Amos Kong

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. This patch changed qemu to makes MAC change effect when the last byte of MAC is written to config space.

Quoted 8 lines
Quoted 6 lines

MAC address takes first 6 bytes of config space of virtio-net, the addr is 5 when the last byte is written in virtio_config_writeb().

MAC change will effect when n->mac is updated in virtio_net_set_config().

Let's see what Rusty says about the spec change.

Implementation notes like this belong as a footnote, eg:

For older systems, it is recommended and typical that the device write byte 5 of the mac address last, so devices can use that as a trigger to commit the mac address change.

Now, is this a real, or theoretical issue? Have we seen this problem in practice, or should we continue to ignore it?

Cheers,
Rusty.

author
#4 lore raw
Quoted 15 lines · Rusty Russell
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Amos Kong

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. This patch changed qemu to makes MAC change effect when the last byte of MAC is written to config space.

Quoted 8 lines
Quoted 6 lines

MAC address takes first 6 bytes of config space of virtio-net, the addr is 5 when the last byte is written in virtio_config_writeb().

MAC change will effect when n->mac is updated in virtio_net_set_config().

Let's see what Rusty says about the spec change.

Quoted 8 lines

Implementation notes like this belong as a footnote, eg:

For older systems, it is recommended and typical that the device write byte 5 of the mac address last, so devices can use that as a trigger to commit the mac address change.

Now, is this a real, or theoretical issue? Have we seen this problem in practice, or should we continue to ignore it?

Hi Rusty, Michael

I didn't touch any problem. MST, and you?

In Linux guest, we should disable the interface before changing mac address.
ifconfig eth0 down
ifconfig eth0 hw ether 10:12:13:14:15:16
ifconfig eth0 up

In Windows 7 guest, after changing mac address in register table,
re-enabling interface to make it effect.
reg add HKLM SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001] /v NetworkAddress /d 0123456789AB netsh interface set interface "Local Area Connection" DISABLED
netsh interface set interface "Local Area Connection" ENABLED

So when we change the mac address, guest os always disable interface to receive all packages. It seems the theoretical issue doesn't exist?

Quoted 3 lines

Cheers,
Rusty.

Signature · 1 line
			Amos.
#5 lore raw
Quoted 41 lines · Amos Kong
Quoted 15 lines · Rusty Russell
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Amos Kong

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. This patch changed qemu to makes MAC change effect when the last byte of MAC is written to config space.

Quoted 8 lines
Quoted 6 lines

MAC address takes first 6 bytes of config space of virtio-net, the addr is 5 when the last byte is written in virtio_config_writeb().

MAC change will effect when n->mac is updated in virtio_net_set_config().

Let's see what Rusty says about the spec change.

Quoted 8 lines

Implementation notes like this belong as a footnote, eg:

For older systems, it is recommended and typical that the device write byte 5 of the mac address last, so devices can use that as a trigger to commit the mac address change.

Now, is this a real, or theoretical issue? Have we seen this problem in practice, or should we continue to ignore it?

Hi Rusty, Michael

I didn't touch any problem. MST, and you?

In Linux guest, we should disable the interface before changing mac address.
ifconfig eth0 down
ifconfig eth0 hw ether 10:12:13:14:15:16
ifconfig eth0 up

In Windows 7 guest, after changing mac address in register table,
re-enabling interface to make it effect.
reg add HKLM SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001] /v NetworkAddress /d 0123456789AB netsh interface set interface "Local Area Connection" DISABLED
netsh interface set interface "Local Area Connection" ENABLED

Quoted 9 lines

So when we change the mac address, guest os always disable interface to receive all packages. It seems the theoretical issue doesn't exist?

Quoted 3 lines

Cheers,
Rusty.

Signature · 1 line
			Amos.

Nope. Looks like no spec change is necessary. We already say it's not atomic and it looks like guests expect exactly that and disable link to prevent strange issues.

Signature · 1 line
MST
author
#6 lore raw
Quoted 49 lines · Michael S. Tsirkin
Quoted 48 lines · Amos Kong
Quoted 15 lines · Rusty Russell
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Amos Kong

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. This patch changed qemu to makes MAC change effect when the last byte of MAC is written to config space.

Quoted 8 lines
Quoted 6 lines

MAC address takes first 6 bytes of config space of virtio-net, the addr is 5 when the last byte is written in virtio_config_writeb().

MAC change will effect when n->mac is updated in virtio_net_set_config().

Let's see what Rusty says about the spec change.

Quoted 8 lines

Implementation notes like this belong as a footnote, eg:

For older systems, it is recommended and typical that the device write byte 5 of the mac address last, so devices can use that as a trigger to commit the mac address change.

Now, is this a real, or theoretical issue? Have we seen this problem in practice, or should we continue to ignore it?

Hi Rusty, Michael

I didn't touch any problem. MST, and you?

In Linux guest, we should disable the interface before changing mac address.
ifconfig eth0 down
ifconfig eth0 hw ether 10:12:13:14:15:16
ifconfig eth0 up

In Windows 7 guest, after changing mac address in register table,
re-enabling interface to make it effect.
reg add HKLM SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001] /v NetworkAddress /d 0123456789AB netsh interface set interface "Local Area Connection" DISABLED
netsh interface set interface "Local Area Connection" ENABLED

So when we change the mac address, guest os always disable interface to receive all packages. It seems the theoretical issue doesn't exist?

Quoted 3 lines

Cheers,
Rusty.

Quoted 6 lines
Quoted 2 lines
Signature · 1 line
			Amos.

Nope. Looks like no spec change is necessary. We already say it's not atomic and it looks like guests expect exactly that and disable link to prevent strange issues.

I just found Jiri has a commit to allow changing mac when iface is running. It seems only the virt nics are allowned, right?

But the leagcy guests don't allow to change mac when interface is running, so no spec change is necessary.

[upstream kernel]
commit d4fc6918f4b3cc844185f59fc518351525950449

Author: Jiri Pirko <[email protected]>
Date:   Wed Jun 27 05:27:46 2012 +0000

virtio_net: allow to change mac when iface is running

RH-BZ: https://bugzilla.redhat.com/show_bug.cgi?id=882868

Signature · 1 line
			Amos.
#7 lore raw
In reply to Amos Kong
Quoted 28 lines · Amos Kong

The lengcy guests don't have mac programming command, we don't know when it's safe to use MAC. We can change QEMU to make MAC change effect when the last byte of MAC is written to config space.

---
 virtio-spec.lyx | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
virtio-spec.lyx +3 -1
index dbc4ef0..bb289fb 100644
@@ -5430,7 +5430,7 @@ T_CTRL_MAC_TABLE_SET.
 
 \begin_layout Standard
 
-\change_inserted -1930653948 1358506710
+\change_inserted -1930653948 1363832689
 The config space 
 \begin_inset Quotes eld
 \end_inset
@@ -5464,6 +5464,15 @@ mac
  Therefore, VIRTIO_NET_CTRL_MAC_ADDR_SET is preferred, especially while
  the NIC is up.
  The command-specific-data is a 6-byte MAC address.
+\end_layout
+

virtio-spec.lyx mac · line 5478

Quoted 10 lines
virtio-spec.lyx +7 -0
+\begin_layout Standard
+
+\change_inserted -1930653948 1363833477
+The legacy guests don't support the new command, they still change MAC address
+ in original way, that's not atomic.
+ For more robust, QEMU only makes the MAC change effect when the last byte
+ of MAC address is written to config space.
 \change_unchanged
 
 \end_layout

The wording can be improved, but before that - Rusty, what do you think about such a hack? Worth supporting or let's just ask everyone to update drivers?

Quoted 2 lines
Signature · 1 line
1.8.1.4