virtio-net: properly check the vhost status during status set
PATCH 1/1 virtio-net: properly check the vhost status during status set
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.
Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
virtio_net_save: Assertion `!n->vhost_started' failed.
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +2 -2
@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {
Signature · 1 line
1.7.1
Quoted 7 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.
Quoted 8 lines
Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>
Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?
Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
Quoted 6 lines
Quoted 4 lines
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
If vm has been stopeed, and the link is up later, vhost won't be started. this is expected.
If vm has been started, and the link is up later, since n->vhost_started is false but both virtio_net_started() and !nc->peer->link_down is true, so the vhost will be started.
Looks ok?
Quoted 26 lines
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 20 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
Quoted 6 lines
Quoted 4 lines
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
Quoted 7 lines
If vm has been stopeed, and the link is up later, vhost won't be started. this is expected.
If vm has been started, and the link is up later, sincen->vhost_startedis false but bothvirtio_net_started()and !nc->peer->link_down is true, so the vhost will be started.Looks ok?
Let me clarify: virtio link is up but peer link is down. So guest will send packets. Will they never be completed?
Quoted 26 lines
Quoted 26 lines
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
Quoted 6 lines
Quoted 4 lines
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
If vm has been stopeed, and the link is up later, vhost won't be started. this is expected.
If vm has been started, and the link is up later, sincen->vhost_startedis false but bothvirtio_net_started()and !nc->peer->link_down is true, so the vhost will be started.
Quoted 4 lines
Quoted 1 line
Looks ok?
Let me clarify: virtio link is up but peer link is down. So guest will send packets. Will they never be completed?
qemu_deliver_packet_iov() will assume the packet were sent when peer link is down. So we are still ok?
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 27 lines · Jason Wang
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
Quoted 6 lines
Quoted 4 lines
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
If vm has been stopeed, and the link is up later, vhost won't be started. this is expected.
If vm has been started, and the link is up later, sincen->vhost_startedis false but bothvirtio_net_started()and !nc->peer->link_down is true, so the vhost will be started.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Looks ok?
Let me clarify: virtio link is up but peer link is down. So guest will send packets. Will they never be completed?
qemu_deliver_packet_iov()will assume the packet were sent when peer link is down. So we are still ok?
Right so I think userspace will start dropping packets. I think this is unnecessarily fragile, I think it's best to make sure vhost=on means userspace does not process tx/rx rings.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang
Quoted 30 lines · Michael S. Tsirkin
Quoted 19 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
Quoted 6 lines
Quoted 4 lines
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
Quoted 7 lines
If vm has been stopeed, and the link is up later, vhost won't be started. this is expected.
If vm has been started, and the link is up later, sincen->vhost_startedis false but bothvirtio_net_started()and !nc->peer->link_down is true, so the vhost will be started.Looks ok?
Let me clarify: virtio link is up but peer link is down. So guest will send packets. Will they never be completed?
Quoted 6 lines
Quoted 2 lines
qemu_deliver_packet_iov()will assume the packet were sent when peer link is down. So we are still ok?Right so I think userspace will start dropping packets. I think this is unnecessarily fragile, I think it's best to make sure vhost=on means userspace does not process tx/rx rings.
But this is also what other nic does such as e1000. Anyway it's harmless so we can just keep it.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang
Quoted 30 lines · Michael S. Tsirkin
Quoted 19 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
Quoted 6 lines
Quoted 4 lines
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>Hmm okay, but now that I think about this, e.g. if link is up later, vhost will not be started.
Quoted 7 lines
If vm has been stopeed, and the link is up later, vhost won't be started. this is expected.
If vm has been started, and the link is up later, sincen->vhost_startedis false but bothvirtio_net_started()and !nc->peer->link_down is true, so the vhost will be started.Looks ok?
Let me clarify: virtio link is up but peer link is down. So guest will send packets. Will they never be completed?
Quoted 6 lines
Quoted 2 lines
qemu_deliver_packet_iov()will assume the packet were sent when peer link is down. So we are still ok?Right so I think userspace will start dropping packets. I think this is unnecessarily fragile, I think it's best to make sure vhost=on means userspace does not process tx/rx rings.
It may make sense, but let's do it in the future. So ack or apply this patch to fix the bug first?
Thanks
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
So the correct thing is maybe to start vhost but use some backend that will drop all packets.
And add a callback so we know peer state changed. Hmm do we need a kernel change for this?Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Quoted 7 lines · Jason Wang
Commit 32993698 (vhost: disable on tap link down) tries to disable the vhost also when the peer's link is down. But the check was not done properly, the vhost were only started when:
1) peer's link is not down
2) virtio-net has already been started.
Quoted 8 lines
Since == have a higher precedence than &&, place a brace to make sure both the conditions were met then does the check. This fixes the crash when doing a savem after set the link off which let qemu crash and complains:
virtio_net_save: Assertion `!n->vhost_started' failed.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>
Too late for 1.5?
Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hw/net/virtio-net.c +2
-2@@ -114,8 +114,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)return ; } -if (!!n->vhost_started ==virtio_net_started (n, status) && - !nc->peer->link_down) { +if (!!n->vhost_started == + (virtio_net_started (n, status) && !nc->peer->link_down)) {return ; }if (!n->vhost_started) {Signature · 1 line
1.7.1
Anthony Liguori
AppliedApplied. Thanks.
Regards,
Anthony Liguori