Linux vhost-user interrupt management fixes
Hi,
I recently did some stress tests of a vhost-user interface using an UDP traffic generator. Traffic generator was connected to 2 physical ports that are in turn connected to 2 virtio ports through a linux bridge, VM (running linux) doing routing to forward packets between the 2 virtio ports. When traffic reaches high pps rates of small packets, I faced the 2 following problems:
- at some time, my qemu socket becomes full, causing qemu to send incomplete SET_VRING_CALL messages to vhost-user backend (without proper fd set in ancillary data).
- after some time, some interrupts are lost, causing the VM to stop transmitting packets.
Both problems come from the fact that interrupt masking/unmasking of the VM is deferred to vhost-user backend through the linux socket.
First problem comes from the fact that socket buffer gets full; it is corrected in the first patch of the serie.
Second problem is a bit more complex. From what i understand of the code, when VM wants to mask/unmask interrupts, qemu traps the command and sends a SET_VRING_CALL to the vhost-user to swap interrupt notifications either to a dummy descriptor or to an fd that was given to kvm module to route interruption to the VM. After sending SET_VRING_CALL message through the socket, VM code continues to run, assuming that the interrupts are now masked; but due to linux socket, this message may be buffered and not currently treated by the vhost-user backend, ie interrupts are not really masked/unmasked as they ought to be.
I think it can be solved in two different ways:
- by waiting for an acknowledgement of vhost-user backend before exiting interrupt masking function, this ensures that interrupt masking is correctly taken into account before giving back hand to the VM, but it has a very high cost in term of cycles. Moreover, unless specifying a new option, it will break current API, since existing vhost-user implementations do not expect a return message on a SET_VRING_CALL call.
- second way could be, in case vhost-user is involved, to restore the initial behaviour of interrupt masking (ie masking/unmasking interrupts by taking/giving vring_call fd from/to kernel kvm module).
Patches 2 and 3 of the serie propose an implementation of this second option.
Didier
Didier Pallard (3):
char: fix vhost-user socket full
virtio-pci: add an option to bypass guest_notifier_mask
vhost-net: force guest_notifier_mask bypass in vhost-user case
hw/net/vhost_net.c | 19 ++++++++++++++++++- hw/virtio/vhost.c | 13 +++++++++++++ hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ qemu-char.c | 10 ++++++++++ 5 files changed, 70 insertions(+), 7 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/3 char: fix vhost-user socket full
unix_send_msgfds is used by vhost-user control socket. qemu_chr_fe_write_all is used to send a message and retries as long as EAGAIN errno is set, but write_msgfds buffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.
In case unix_send_msgfds is called through qemu_chr_fe_write, it will be user responsability to resend message as is or to free write_msgfds using set_msgfds(0)
--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
qemu-char.c +10 -0
@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Hi
Quoted 23 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR );
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2626
Quoted 10 lines
qemu-char.c +10
-0+/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +
This looks reasonable to me. However, I don't know what happens with partial write of ancillary data. Hopefully it's all or nothing. Apparently, reading unix_stream_sendmsg() in kernel shows that as long as a few bytes have been sent, the ancillary data is sent. So it looks like it still does the right thing in case of a partial write.
Quoted 7 lines
qemu-char.c +0
-1/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds); --2.1.4
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 27 lines · Marc-André Lureau
Hi
Quoted 23 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR );
Quoted 16 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2626
Quoted 10 lines
qemu-char.c +10
-0+/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +This looks reasonable to me. However, I don't know what happens with partial write of ancillary data. Hopefully it's all or nothing. Apparently, reading
unix_stream_sendmsg()in kernel shows that as long as a few bytes have been sent, the ancillary data is sent. So it looks like it still does the right thing in case of a partial write.
If I may put my two cents in, it looks to me very similar to an fd leakage on back-end side. When a new set_call_fd request arrives, it is very easy to forget closing the previous file descriptor. As result, if interrupts are actively maksed/unmasked by the guest, the back-end can easily reach maximum fds, which will cause receiving side silently drop new fds in aux data. --Victor
Quoted 16 lines
Reviewed-by Marc-André Lureau <[email protected]>Quoted 7 lines
qemu-char.c +0
-1/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds); --2.1.4
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 45 lines · Victor Kaplansky
Quoted 27 lines · Marc-André Lureau
Hi
Quoted 23 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR );Quoted 16 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2626
Quoted 10 lines
qemu-char.c +10
-0+/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +This looks reasonable to me. However, I don't know what happens with partial write of ancillary data. Hopefully it's all or nothing. Apparently, reading
unix_stream_sendmsg()in kernel shows that as long as a few bytes have been sent, the ancillary data is sent. So it looks like it still does the right thing in case of a partial write.
Quoted 8 lines
If I may put my two cents in, it looks to me very similar to an fd leakage on back-end side. When a new
set_call_fdrequest arrives, it is very easy to forget closing the previous file descriptor. As result, if interrupts are actively maksed/unmasked by the guest, the back-end can easily reach maximum fds, which will cause receiving side silently drop new fds in aux data. --Victor
Hi victor,
This is not a problem of fd exausted. This was my first axe of investigation, but fd management is correct in our vhost-user backend, there is no fd leakage.
And i guess you are refering to the problem fixed by patches 2 and 3, since the problem corrected by this patch is a message arriving from qemu without ancillary data, whatever the state of the fds in the vhost-user backend.
thanks
didier
Quoted 16 lines
Quoted 16 lines
Reviewed-by Marc-André Lureau <[email protected]>Quoted 7 lines
qemu-char.c +0
-1/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds); --2.1.4
--
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 55 lines · Didier Pallard
Quoted 45 lines · Victor Kaplansky
Quoted 27 lines · Marc-André Lureau
Hi
Quoted 23 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR );Quoted 16 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2626
Quoted 10 lines
qemu-char.c +10
-0+/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +This looks reasonable to me. However, I don't know what happens with partial write of ancillary data. Hopefully it's all or nothing. Apparently, reading
unix_stream_sendmsg()in kernel shows that as long as a few bytes have been sent, the ancillary data is sent. So it looks like it still does the right thing in case of a partial write.Quoted 8 lines
If I may put my two cents in, it looks to me very similar to an fd leakage on back-end side. When a new
set_call_fdrequest arrives, it is very easy to forget closing the previous file descriptor. As result, if interrupts are actively maksed/unmasked by the guest, the back-end can easily reach maximum fds, which will cause receiving side silently drop new fds in aux data. --Victor
Quoted 4 lines
Hi victor,
This is not a problem of fd exausted. This was my first axe of investigation, but fd management is correct in our vhost-user backend, there is no fd leakage.
That's good.
Quoted 3 lines
And i guess you are refering to the problem fixed by patches 2 and 3, since the problem corrected by this patch is a message arriving from qemu without ancillary data, whatever the state of the fds in the vhost-user backend.
I'm talking about the problem that supposed to be fixed by the first patch. It is not clear to me how the patch fixes the partial send. sendmsg() is called in qemu-char.c:unix_send_msgfds with zero flags, which means a blocking operation, so I'm surprised that sendmsg can return with errno == EAGAIN.
Quoted 23 lines
thanks
didierQuoted 16 lines
Quoted 16 lines
Reviewed-by Marc-André Lureau <[email protected]>Quoted 7 lines
qemu-char.c +0
-1/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds); --2.1.4
--
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 67 lines · Victor Kaplansky
Quoted 55 lines · Didier Pallard
Quoted 45 lines · Victor Kaplansky
Quoted 27 lines · Marc-André Lureau
Hi
Quoted 23 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR );Quoted 16 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2626
Quoted 10 lines
qemu-char.c +10
-0+/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +This looks reasonable to me. However, I don't know what happens with partial write of ancillary data. Hopefully it's all or nothing. Apparently, reading
unix_stream_sendmsg()in kernel shows that as long as a few bytes have been sent, the ancillary data is sent. So it looks like it still does the right thing in case of a partial write.Quoted 8 lines
If I may put my two cents in, it looks to me very similar to an fd leakage on back-end side. When a new
set_call_fdrequest arrives, it is very easy to forget closing the previous file descriptor. As result, if interrupts are actively maksed/unmasked by the guest, the back-end can easily reach maximum fds, which will cause receiving side silently drop new fds in aux data. --VictorQuoted 4 lines
Hi victor,
This is not a problem of fd exausted. This was my first axe of investigation, but fd management is correct in our vhost-user backend, there is no fd leakage.That's good.
Quoted 3 lines
And i guess you are refering to the problem fixed by patches 2 and 3, since the problem corrected by this patch is a message arriving from qemu without ancillary data, whatever the state of the fds in the vhost-user backend.
Quoted 6 lines
I'm talking about the problem that supposed to be fixed by the first patch. It is not clear to me how the patch fixes the partial send.
sendmsg()is called in qemu-char.c:unix_send_msgfds with zero flags, which means a blocking operation, so I'm surprised that sendmsg can return with errno == EAGAIN.
Well, vhost-user socket is started with following chardev:
-chardev socket,id=vhostuserchr0,path=/tmp/vhost_sock0,server and according to code in tcp_chr_add_client:
static int tcp_chr_add_client(CharDriverState *chr, int fd) {
...
qemu_set_nonblock(fd);
So fd is set in non blocking mode. This is enough to have an
EAGAIN returned value on socket buffer full, whatever flags used in sendmsg, i think.
Perhaps changing the blocking mode here may also correct the first problem, but I am not able to measure the impact that may have such a modification...
Quoted 23 lines
Quoted 23 lines
thanks
didierQuoted 16 lines
Quoted 16 lines
Reviewed-by Marc-André Lureau <[email protected]>Quoted 7 lines
qemu-char.c +0
-1/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds); --2.1.4
--
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 81 lines · Didier Pallard
Quoted 67 lines · Victor Kaplansky
Quoted 55 lines · Didier Pallard
Quoted 45 lines · Victor Kaplansky
Quoted 27 lines · Marc-André Lureau
Hi
Quoted 23 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR );Quoted 16 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2626
Quoted 10 lines
qemu-char.c +10
-0+/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +This looks reasonable to me. However, I don't know what happens with partial write of ancillary data. Hopefully it's all or nothing. Apparently, reading
unix_stream_sendmsg()in kernel shows that as long as a few bytes have been sent, the ancillary data is sent. So it looks like it still does the right thing in case of a partial write.Quoted 8 lines
If I may put my two cents in, it looks to me very similar to an fd leakage on back-end side. When a new
set_call_fdrequest arrives, it is very easy to forget closing the previous fil descriptor. As result, if interrupts are actively maksed/unmasked by the guest, the back-end can easily reach maximum fds, which will cause receiving side silently drop new fds in aux data. --VictorQuoted 4 lines
Hi victor,
This is not a problem of fd exausted. This was my first axe of investigation, but fd management is correct in our vhost-user backend, there is no fd leakage.That's good.
Quoted 3 lines
And i guess you are refering to the problem fixed by patches 2 and 3, since the problem corrected by this patch is a message arriving from qemu without ancillary data, whatever the state of the fds in the vhost-user backend.
Quoted 6 lines
I'm talking about the problem that supposed to be fixed by the first patch. It is not clear to me how the patch fixes the partial send.
sendmsg()is called in qemu-char.c:unix_send_msgfds with zero flags, which means a blocking operation, so I'm surprised that sendmsg can return with errno == EAGAIN.Well, vhost-user socket is started with following chardev:
-chardev socket,id=vhostuserchr0,path=/tmp/vhost_sock0,server and according to code intcp_chr_add_client:
static inttcp_chr_add_client(CharDriverState *chr, int fd){
...
Quoted 7 lines
qemu_set_nonblock(fd);So fd is set in non blocking mode. This is enough to have an EAGAIN returned value on socket buffer full, whatever flags used in sendmsg, i think.
Perhaps changing the blocking mode here may also correct the first problem, but I am not able to measure the impact that may have such a modification...
Thanks for the clarification. I was able to reproduce both issues
- with send_msgfds() partial send and lost interrupts using code based on vhost-user-bridge test application.
I'm working on a fix for the lost interrupts. Will send an RFC patch by the Sunday.
-- Victor
Quoted 27 lines
Quoted 25 lines
Quoted 25 lines
thanks
didierQuoted 16 lines
Quoted 16 lines
Reviewed-by Marc-André Lureau <[email protected]>Quoted 7 lines
qemu-char.c +0
-1/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds); --2.1.4
--
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
In reply to Didier PallardQuoted 11 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>
I don't see any callers actually retrying though.
Where is it?
Quoted 28 lines
--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +10
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) +*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
In reply to Didier PallardQuoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2621
Quoted 8 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0)
Problem is, if ever anyone tries to send messages with qemu_chr_fe_write and does not retry, there will be a memory leak.
Rather than this, how about adding an assert in qemu_chr_fe_write to make sure its not used with msgfds?
Quoted 11 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 33 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2621
Quoted 8 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.
Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?
Well, in qemu_chr_fe_write, all i have is a CharDriverState. Information on number of fds to pass are located in TCPCharDriver structure.
should i assert as soon as a set_msgfds method is set:assert(s->set_msgfds == NULL);
but it may trigger on unix sockets were message fds are never used.
or try to detect the implementation and really check the number of fds passed:assert((s->chr_write != tcp_chr_write) && ((TCPCharDriver *)s->opaque)->write_msgfds_num == 0))
but i didn't find better than checking a method to detect type of underlying driver and I don't like this kind of code.
Another solution should be to add a new method to get pending fds number, assert would become:assert((s->get_write_msgfds_num == NULL) || (s->get_write_msgfds_num(s) == 0))
s->get_write_msgfds_num being set only for tcp_ socket, with a simple function:
tcp_chr_get_write_msgfds_num(CharDriverState *chr)
{
TCPCharDriver *s = chr->opaque;
return s->write_msgfds_num;
}...s->get_write_msgfds_num = tcp_chr_get_write_msgfds_num;
...
?
Quoted 13 lines
Quoted 12 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 36 lines · Didier Pallard
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?
Quoted 6 lines
Well, in
qemu_chr_fe_write, all i have is a CharDriverState. Information on number of fds to pass are located in TCPCharDriver structure.should i assert as soon as a
set_msgfdsmethod is set:assert(s->set_msgfds == NULL);
but it may trigger on unix sockets were message fds are never used.
Why? Because this field is never initialized?
Let's initialize it unconditionally then?
Quoted 41 lines
or try to detect the implementation and really check the number of fds passed:
assert((s->chr_write != tcp_chr_write) && ((TCPCharDriver *)s->opaque)->write_msgfds_num == 0))
but i didn't find better than checking a method to detect type of underlying driver and I don't like this kind of code.Another solution should be to add a new method to get pending fds number, assert would become:
assert((s->get_write_msgfds_num == NULL) || (s->get_write_msgfds_num(s) == 0))
s->get_write_msgfds_numbeing set only fortcp_socket, with a simple function:
tcp_chr_get_write_msgfds_num(CharDriverState *chr){ TCPCharDriver *s = chr->opaque; return s->write_msgfds_num; }...
s->get_write_msgfds_num=tcp_chr_get_write_msgfds_num;
...?
Quoted 13 lines
Quoted 12 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
In reply to Michael S. TsirkinQuoted 34 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2621
Quoted 8 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.
Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?
NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Adding an assert in qemu_chr_fe_write() won't solve it - the same problem still exists in qemu_chr_fe_write_all() - although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.
We need to update tcp_chr_write() to not free the FDs when io_channel_send_full() returns with errno==EAGAIN, in the same way this patch was doing.
Quoted 8 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2629
Quoted 8 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 44 lines · Daniel P. Berrange
Quoted 34 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2621
Quoted 8 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.
Absolutely. We need to fix qemu_chr_fe_write_all. I am just worried that someone tries to use qemu_chr_fe_write with fds and then we get a memory leak if qemu_chr_fe_write is not retried.
So I propose we teach qemu_chr_fe_write that it can't send msg fds.
Quoted 17 lines
Quoted 9 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2629
Quoted 9 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 51 lines · Michael S. Tsirkin
Quoted 42 lines · Daniel P. Berrange
Quoted 33 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2621
Quoted 8 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.
Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.
Patch is easy to port on head version.
My concern with following assert in qemu_chr_fe_write:
assert(s->set_msgfds == NULL);
Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses qemu_chr_fe_write instead of qemu_chr_fe_write_all. Are we supposed to always use qemu_chr_fe_write_all on a tcp/linux socket?
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through qemu_chr_fe_write, without wanting to send any fd...
anyway, i can put it in the code, but i don't know how to test that it does not break in some unexpected cases.
thanks
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2629
Quoted 8 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 60 lines · Didier Pallard
Quoted 50 lines · Michael S. Tsirkin
Quoted 41 lines · Daniel P. Berrange
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.Patch is easy to port on head version.
Quoted 8 lines
My concern with following assert in
qemu_chr_fe_write:
assert(s->set_msgfds == NULL);Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses
qemu_chr_fe_writeinstead ofqemu_chr_fe_write_all. Are we supposed to always useqemu_chr_fe_write_allon a tcp/linux socket?
No but why will set_msgfds be != NULL if you don't send fds? There's probably something obvious I'm missing.
Quoted 25 lines
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through
qemu_chr_fe_write, without wanting to send any fd...anyway, i can put it in the code, but i don't know how to test that it does not break in some unexpected cases.
thanks
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines
qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2629
Quoted 8 lines
qemu-char.c +5
-0+*/ +if (r <0 && errno ==EAGAIN ) { +return r; + } +/* free the written msgfds, no matter what */ if (s->write_msgfds_num) {g_free (s->write_msgfds);Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
In reply to Didier PallardQuoted 69 lines · Didier Pallard
Quoted 50 lines · Michael S. Tsirkin
Quoted 41 lines · Daniel P. Berrange
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.Patch is easy to port on head version.
My concern with following assert in
qemu_chr_fe_write:
assert(s->set_msgfds == NULL);Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses
qemu_chr_fe_writeinstead ofqemu_chr_fe_write_all. Are we supposed to always useqemu_chr_fe_write_allon a tcp/linux socket?
Quoted 4 lines
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through
qemu_chr_fe_write, without wanting to send any fd...
The qemu_chr_fe_set_msgfds() function is only called from one place in QEMU:
$ git grep qemu_chr_fe_set_msgfds hw/virtio/vhost-user.c: qemu_chr_fe_set_msgfds(chr, fds, fd_num); include/sysemu/char.h: * @qemu_chr_fe_set_msgfds: include/sysemu/char.h:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num); qemu-char.c:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num)
so if vhost-user.c does the write thing calling write_all(), then you're fine.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 83 lines · Daniel P. Berrange
Quoted 69 lines · Didier Pallard
Quoted 50 lines · Michael S. Tsirkin
Quoted 41 lines · Daniel P. Berrange
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.Patch is easy to port on head version.
My concern with following assert in
qemu_chr_fe_write:
assert(s->set_msgfds == NULL);Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses
qemu_chr_fe_writeinstead ofqemu_chr_fe_write_all. Are we supposed to always useqemu_chr_fe_write_allon a tcp/linux socket?Quoted 4 lines
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through
qemu_chr_fe_write, without wanting to send any fd...The
qemu_chr_fe_set_msgfds()function is only called from one place in QEMU:$ git grep qemu_chr_fe_set_msgfds hw/virtio/vhost-user.c: qemu_chr_fe_set_msgfds(chr, fds, fd_num); include/sysemu/char.h: * @qemu_chr_fe_set_msgfds: include/sysemu/char.h:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num); qemu-char.c:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num)
Quoted 5 lines
so if
vhost-user.cdoes the write thing callingwrite_all(), then you're fine.Regards,
Daniel
I agree that it will work as expected for vhost-user, but set_msgfds will be set to tcp_set_msgfds for all "socket" type chardev. If such chardev is configured to be used by some part of code using qemu_chr_fe_write instead of qemu_chr_fe_write_all, it will trigger the assert.
And i just don't know if this case can happen.
I will write a new patchset with the assert in a separate commit. thanks
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 99 lines · Didier Pallard
Quoted 83 lines · Daniel P. Berrange
Quoted 69 lines · Didier Pallard
Quoted 50 lines · Michael S. Tsirkin
Quoted 41 lines · Daniel P. Berrange
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.Patch is easy to port on head version.
My concern with following assert in
qemu_chr_fe_write:
assert(s->set_msgfds == NULL);Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses
qemu_chr_fe_writeinstead ofqemu_chr_fe_write_all. Are we supposed to always useqemu_chr_fe_write_allon a tcp/linux socket?Quoted 4 lines
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through
qemu_chr_fe_write, without wanting to send any fd...The
qemu_chr_fe_set_msgfds()function is only called from one place in QEMU:$ git grep qemu_chr_fe_set_msgfds hw/virtio/vhost-user.c: qemu_chr_fe_set_msgfds(chr, fds, fd_num); include/sysemu/char.h: * @qemu_chr_fe_set_msgfds: include/sysemu/char.h:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num); qemu-char.c:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num)Quoted 5 lines
so if
vhost-user.cdoes the write thing callingwrite_all(), then you're fine.Regards,
DanielI agree that it will work as expected for vhost-user, but
set_msgfdswill be set
totcp_set_msgfdsfor all "socket" type chardev. If such chardev is configured
to be used by some part of code usingqemu_chr_fe_writeinstead ofqemu_chr_fe_write_all,
it will trigger the assert.
And i just don't know if this case can happen.
Quoted 2 lines
I will write a new patchset with the assert in a separate commit. thanks
Oh, I see. I really meant
assert(!s->write_msgfds && !s->write_msgfds_num);
this assert can go into tcp_chr_write.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 100 lines · Michael S. Tsirkin
Quoted 99 lines · Didier Pallard
Quoted 83 lines · Daniel P. Berrange
Quoted 69 lines · Didier Pallard
Quoted 50 lines · Michael S. Tsirkin
Quoted 41 lines · Daniel P. Berrange
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.Patch is easy to port on head version.
My concern with following assert in
qemu_chr_fe_write:
assert(s->set_msgfds == NULL);Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses
qemu_chr_fe_writeinstead ofqemu_chr_fe_write_all. Are we supposed to always useqemu_chr_fe_write_allon a tcp/linux socket?Quoted 4 lines
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through
qemu_chr_fe_write, without wanting to send any fd...The
qemu_chr_fe_set_msgfds()function is only called from one place in QEMU:$ git grep qemu_chr_fe_set_msgfds hw/virtio/vhost-user.c: qemu_chr_fe_set_msgfds(chr, fds, fd_num); include/sysemu/char.h: * @qemu_chr_fe_set_msgfds: include/sysemu/char.h:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num); qemu-char.c:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num)Quoted 5 lines
so if
vhost-user.cdoes the write thing callingwrite_all(), then you're fine.Regards,
DanielI agree that it will work as expected for vhost-user, but
set_msgfdswill be set
totcp_set_msgfdsfor all "socket" type chardev. If such chardev is configured
to be used by some part of code usingqemu_chr_fe_writeinstead ofqemu_chr_fe_write_all,
it will trigger the assert.
And i just don't know if this case can happen.
Quoted 8 lines
Quoted 2 lines
I will write a new patchset with the assert in a separate commit. thanks
Oh, I see. I really meant
assert(!s->write_msgfds && !s->write_msgfds_num);this assert can go into
tcp_chr_write.
Err, no it can't. tcp_chr_write() is the thing responsible for sending FDs, so we can't assert that no FDs are set, as that'll make it impossible for anything to send FDs.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 1/3] char: fix vhost-user socket full
Quoted 106 lines · Daniel P. Berrange
Quoted 105 lines · Michael S. Tsirkin
Quoted 98 lines · Didier Pallard
Quoted 83 lines · Daniel P. Berrange
Quoted 69 lines · Didier Pallard
Quoted 50 lines · Michael S. Tsirkin
Quoted 41 lines · Daniel P. Berrange
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Didier Pallard
unix_send_msgfdsis used by vhost-user control socket.qemu_chr_fe_write_allis used to send a message and retries as long as EAGAIN errno is set, butwrite_msgfdsbuffer is freed after first EAGAIN failure, causing message to be sent without proper fds attachment.In case
unix_send_msgfdsis called throughqemu_chr_fe_write, it will be user responsability to resend message as is or to freewrite_msgfdsusingset_msgfds(0)Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- qemu-char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)qemu-char.c +0
-0qemu-char.c static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) · line 2620
Quoted 7 lines
qemu-char.c +5
-0@@ -2614,6 +2614,16 @@ static int unix_send_msgfds(CharDriverState *chr, const uint8_t *buf, int len) r =sendmsg (s->fd, &msgh,0 ); }while (r <0 && errno ==EINTR ); +/* Ancillary data are not sent if no byte is written +* so don't free msgfds buffer if return value is EAGAIN +* If called from qemu_chr_fe_write_all retry will come soon +* If called from qemu_chr_fe_write, it is the user responsibility +* to resend message or free fds using set_msgfds(0) Problem is, if ever anyone tries to send messages with
qemu_chr_fe_writeand does not retry, there will be a memory leak.Quoted 2 lines
Rather than this, how about adding an assert in
qemu_chr_fe_writeto make sure its not used with msgfds?NB, this TCP chardev code has completely changed since this patch was submitted. It now uses QIOChannel instead of raw sockets APIs. The same problem still exists though - when we get EAGAIN from the sendmsg, we're releasing the file descriptors even though they've not been sent.
Quoted 8 lines
Adding an assert in
qemu_chr_fe_write()won't solve it - the same problem still exists inqemu_chr_fe_write_all()- although that loops to re-try on EAGAIN, the FDs are free'd before it does the retry.We need to update
tcp_chr_write()to not free the FDs whenio_channel_send_full()returns with errno==EAGAIN, in the same way this patch was doing.Quoted 7 lines
Absolutely. We need to fix
qemu_chr_fe_write_all. I am just worried that someone tries to useqemu_chr_fe_writewith fds and then we get a memory leak ifqemu_chr_fe_writeis not retried.So I propose we teach
qemu_chr_fe_writethat it can't send msg fds.Patch is easy to port on head version.
My concern with following assert in
qemu_chr_fe_write:
assert(s->set_msgfds == NULL);Is that it may trigger on a tcp/linux socket that never wants to send message fds but uses
qemu_chr_fe_writeinstead ofqemu_chr_fe_write_all. Are we supposed to always useqemu_chr_fe_write_allon a tcp/linux socket?Quoted 4 lines
I think that only vhost-user socket is using the ability to send message fds through socket, but i don't know all places were a linux/tcp socket can be used through
qemu_chr_fe_write, without wanting to send any fd...The
qemu_chr_fe_set_msgfds()function is only called from one place in QEMU:$ git grep qemu_chr_fe_set_msgfds hw/virtio/vhost-user.c: qemu_chr_fe_set_msgfds(chr, fds, fd_num); include/sysemu/char.h: * @qemu_chr_fe_set_msgfds: include/sysemu/char.h:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num); qemu-char.c:int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num)Quoted 5 lines
so if
vhost-user.cdoes the write thing callingwrite_all(), then you're fine.Regards,
DanielI agree that it will work as expected for vhost-user, but
set_msgfdswill be set
totcp_set_msgfdsfor all "socket" type chardev. If such chardev is configured
to be used by some part of code usingqemu_chr_fe_writeinstead ofqemu_chr_fe_write_all,
it will trigger the assert.
And i just don't know if this case can happen.Quoted 2 lines
I will write a new patchset with the assert in a separate commit. thanks
Oh, I see. I really meant
assert(!s->write_msgfds && !s->write_msgfds_num);
Quoted 7 lines
Quoted 1 line
this assert can go into
tcp_chr_write.Err, no it can't.
tcp_chr_write()is the thing responsible for sending FDs, so we can't assert that no FDs are set, as that'll make it impossible for anything to send FDs.Regards,
Daniel
I fully agree with daniel, i think it can't be done in tcp_chr_write as is. So finally, what should i do?
Add a method that may return the number of pending msgfds to be sent? It may allow to check that no message fds are pending when using tcp_chr_write...
thanks
didier
PATCH 2/3 virtio-pci: add an option to bypass guest_notifier_mask
In reply to Didier PallardUsing guest_notifier_mask function in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning from guest_notifier_mask call, instead message is posted in a unix socket, and processed later.
Add an option bit to disable the use of guest_notifier_mask in virtio pci.
--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)
hw/virtio/virtio-pci.c +23 -6
@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);
@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);
@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);
@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&
@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);
@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }
@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_END_OF_LIST (), };
@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };
@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),
@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),
@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ),DEFINE_PROP_END_OF_LIST (), };
hw/virtio/virtio-pci.h +6 -0
@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq;
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 2/3] virtio-pci: add an option to bypass guest_notifier_mask
Hi
Quoted 7 lines · Didier Pallard
Using
guest_notifier_maskfunction in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning fromguest_notifier_maskcall, instead message is posted in a unix socket, and processed later.Add an option bit to disable the use of
guest_notifier_maskin virtio pci.
Why not disabling it whenever vhost-user is used if it's broken and inefficient to be fixed?
Quoted 139 lines
Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)hw/virtio/virtio-pci.c +23
-6@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_END_OF_LIST (), };@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ),DEFINE_PROP_END_OF_LIST (), };hw/virtio/virtio-pci.h +6
-1@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq; --2.1.4
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 2/3] virtio-pci: add an option to bypass guest_notifier_mask
Hi
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 5 lines · Didier Pallard
Using
guest_notifier_maskfunction in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning fromguest_notifier_maskcall, instead message is posted in a unix socket, and processed later.
Quoted 5 lines
Quoted 2 lines
Add an option bit to disable the use of
guest_notifier_maskin virtio pci.Why not disabling it whenever vhost-user is used if it's broken and inefficient to be fixed?
Sorry, I missed the following patch.
I am not sure it's necessary to have a user-visible property, especially if it's overwritten later. But apparently, other properties are already forced.
looks good overall to me, but maintainers might have different opinions.
Quoted 144 lines
Quoted 136 lines
Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)hw/virtio/virtio-pci.c +23
-6@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_END_OF_LIST (), };@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ),DEFINE_PROP_END_OF_LIST (), };hw/virtio/virtio-pci.h +6
-1@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq; --Quoted 3 lines
2.1.4
--
Marc-André Lureau
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 2/3] virtio-pci: add an option to bypass guest_notifier_mask
Quoted 17 lines · Marc-André Lureau
Hi
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 5 lines · Didier Pallard
Using
guest_notifier_maskfunction in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning fromguest_notifier_maskcall, instead message is posted in a unix socket, and processed later.Quoted 4 lines
Quoted 2 lines
Add an option bit to disable the use of
guest_notifier_maskin virtio pci.Why not disabling it whenever vhost-user is used if it's broken and inefficient to be fixed?
Quoted 150 lines
Sorry, I missed the following patch.
I am not sure it's necessary to have a user-visible property, especially if it's overwritten later. But apparently, other properties are already forced.
looks good overall to me, but maintainers might have different opinions.
Quoted 142 lines
Quoted 135 lines
Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)hw/virtio/virtio-pci.c +23
-6@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_END_OF_LIST (), };@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ),DEFINE_PROP_END_OF_LIST (), };hw/virtio/virtio-pci.h +6
-1@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq; --Quoted 3 lines
2.1.4
--
Marc-André Lureau
Hi marc-André,
thanks for reviewing.
Quoted 1 line
I am not sure it's necessary to have a user-visible property,
I make this a user visible property, because I thought it should perhaps be
useful to have the ability to force this behaviour on some non-pci
bus as well,
(since the patch that forces the option only applies to PCI buses)
and I have
no knowledge of non PCI buses in qemu or if vhost-user can be used on
such
buses.
Didier
Re: [Qemu-devel] [PATCH 2/3] virtio-pci: add an option to bypass guest_notifier_mask
In reply to Didier PallardQuoted 117 lines · Didier Pallard
Using
guest_notifier_maskfunction in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning fromguest_notifier_maskcall, instead message is posted in a unix socket, and processed later.Add an option bit to disable the use of
guest_notifier_maskin virtio pci.Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)hw/virtio/virtio-pci.c +21
-6@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_END_OF_LIST (), };@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),
hw/virtio/virtio-pci.c static const TypeInfo virtio_serial_pci_info = { · line 2237
Quoted 8 lines
hw/virtio/virtio-pci.c +2
-0@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ),DEFINE_PROP_END_OF_LIST (), };
I think we should rename this x-use-notifier mask.
And I'd rather drop it from all devices where it's not relevant.
Quoted 20 lines
hw/virtio/virtio-pci.h +6
-0@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq;Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 2/3] virtio-pci: add an option to bypass guest_notifier_mask
Quoted 120 lines · Michael S. Tsirkin
Quoted 119 lines · Didier Pallard
Using
guest_notifier_maskfunction in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning fromguest_notifier_maskcall, instead message is posted in a unix socket, and processed later.Add an option bit to disable the use of
guest_notifier_maskin virtio pci.Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)hw/virtio/virtio-pci.c +21
-6@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_END_OF_LIST (), };@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = { DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
Quoted 8 lines
hw/virtio/virtio-pci.c static const TypeInfo virtio_serial_pci_info = { · line 2237
Quoted 6 lines
hw/virtio/virtio-pci.c +2
-0VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ), DEFINE_PROP_END_OF_LIST(), };I think we should rename this x-use-notifier mask.
And I'd rather drop it from all devices where it's not relevant.
I will rename the option x-use-notifier-mask.
Currently, only vhost-net has a vhost-user implementation, isn't it? so it is the only place were i need to set the option, that's it?
Quoted 21 lines
Quoted 21 lines
hw/virtio/virtio-pci.h +6
-0@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq;Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 2/3] virtio-pci: add an option to bypass guest_notifier_mask
In reply to Didier PallardQuoted 81 lines · Didier Pallard
Using
guest_notifier_maskfunction in vhost-user case may break interrupt mask paradigm, because mask/unmask is not really done when returning fromguest_notifier_maskcall, instead message is posted in a unix socket, and processed later.Add an option bit to disable the use of
guest_notifier_maskin virtio pci.Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>--- hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-)hw/virtio/virtio-pci.c +13
-6@@ -806,7 +806,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, set up irqfd now. * Otherwise, delay until unmasked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { ret =kvm_virtio_pci_irqfd_use (proxy, queue_no, vector);if (ret <0 ) {kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -822,7 +823,8 @@ undo:if (vector >=msix_nr_vectors_allocated (dev)) {continue ; } -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -849,7 +851,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)/* If guest supports masking, clean up irqfd now. * Otherwise, it was cleaned when masked in the frontend. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector); }kvm_virtio_pci_vq_vector_release (proxy, vector);@@ -882,7 +885,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,/* If guest supports masking, irqfd is already setup, unmask it. * Otherwise, set it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, false);/* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending &&@@ -905,7 +909,8 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,/* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */ -if (k->guest_notifier_mask) { +if ((proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + k->guest_notifier_mask) { k->guest_notifier_mask (vdev, queue_no, true); }else {kvm_virtio_pci_irqfd_release (proxy, queue_no, vector);@@ -1022,7 +1027,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,event_notifier_cleanup (notifier); } -if (!msix_enabled (&proxy->pci_dev) && vdc->guest_notifier_mask) { +if (!msix_enabled (&proxy->pci_dev) && + (proxy->flags &VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ) && + vdc->guest_notifier_mask) { vdc->guest_notifier_mask (vdev, n, !assign); }
hw/virtio/virtio-pci.c static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) · line 1175
Quoted 5 lines
hw/virtio/virtio-pci.c +2
-0@@ -1164,6 +1171,8 @@ static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_9p_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),
Is there a reason why we add the new property to specific classes like virtio_9p_pci_realize, virtio_blk_pci_properties and so on, instead of adding it to the more general class virtio_pci_properties, and thus the new property having inherited, obtained by all PCI devices?
Quoted 60 lines
hw/virtio/virtio-pci.c +8
-0DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1908,6 +1917,8 @@ static Property virtio_blk_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), DEFINE_PROP_END_OF_LIST(), };@@ -1961,6 +1972,8 @@ static const TypeInfo virtio_blk_pci_info = {static Property virtio_scsi_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,DEV_NVECTORS_UNSPECIFIED ),DEFINE_PROP_END_OF_LIST (),@@ -2175,6 +2188,8 @@ static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)static Property virtio_serial_pci_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ),DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ),DEFINE_PROP_END_OF_LIST (),@@ -2215,6 +2230,8 @@ static const TypeInfo virtio_serial_pci_info = {static Property virtio_net_properties[] = {DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , false), +DEFINE_PROP_BIT ("usenotifiermask" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT , true),DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,3 ),DEFINE_PROP_END_OF_LIST (), };hw/virtio/virtio-pci.h +6
-0@@ -86,6 +86,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) +/* Where vhost-user implementation exists, using the guest notifier mask +* feature can lead to improper interrupt management. Add a flag to +* allow to disable this guest notifier mask if desired */ +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT 6 +#define VIRTIO_PCI_FLAG_USE_NOTIFIERMASK (1 << VIRTIO_PCI_FLAG_USE_NOTIFIERMASK_BIT) + typedef struct { MSIMessage msg; int virq;Signature · 1 line
2.1.4
PATCH 3/3 vhost-net: force guest_notifier_mask bypass in vhost-user case
In reply to Didier PallardSince guest_mask_notifier can not be used in vhost-user mode due to buffering implied by unix control socket, force VIRTIO_PCI_FLAG_USE_NOTIFIERMASK on virtio pci of vhost-user interfaces, and send correct callfd to the guest at vhost start.
--- hw/net/vhost_net.c | 19 ++++++++++++++++++- hw/virtio/vhost.c | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-)
hw/net/vhost_net.c +18 -1
@@ -36,9 +36,11 @@#include <stdio.h> #include "standard-headers/linux/virtio_ring.h" +#include "hw/pci/pci.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-pci.h" struct vhost_net {struct vhost_dev dev;
@@ -314,7 +316,22 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, }for (i =0 ; i < total_queues; i++) { -vhost_net_set_vq_index (get_vhost_net (ncs[i].peer), i *2 ); +struct vhost_net *net=get_vhost_net (ncs[i].peer); +vhost_net_set_vq_index (net, i *2 ); + +/* Force VIRTIO_PCI_FLAG_USE_NOTIFIERMASK reset in vhost user case +* Must be done before set_guest_notifier call +*/ +if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) { +BusState *qbus =BUS (qdev_get_parent_bus (DEVICE (dev))); +DeviceState *d =DEVICE (qbus->parent); +if (!strcmp (object_get_typename (OBJECT (d)),TYPE_VIRTIO_NET_PCI )) { +VirtIOPCIProxy *proxy =VIRTIO_PCI (d); + +/* Force proxy to not use mask notifier */ + proxy->flags &= ~VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ; + } + } } r = k->set_guest_notifiers (qbus->parent, total_queues *2 , true);
hw/virtio/vhost.c +13 -0
@@ -854,8 +854,21 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,/* Clear and discard previous events if any. */ event_notifier_test_and_clear (&vq->masked_notifier); +/* If vhost user, register now the call eventfd, guest_notifier_mask +* function is not used anymore +*/ +if (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ) { + file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq)); + r = dev->vhost_ops->vhost_set_vring_call (dev, &file); +if (r) { + r = -errno; + goto fail_call; + } + } +return 0 ; +fail_call: fail_kick: fail_alloc: cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 3/3] vhost-net: force guest_notifier_mask bypass in vhost-user case
Quoted 8 lines · Didier Pallard
Since
guest_mask_notifiercan not be used in vhost-user mode due to buffering implied by unix control socket, forceVIRTIO_PCI_FLAG_USE_NOTIFIERMASKon virtio pci of vhost-user interfaces, and send correct callfd to the guest at vhost start.Signed-off-by Didier Pallard <[email protected]>Reviewed-by Thibaut Collet <[email protected]>
I queued this now so we have a bugfix, but I think we should clean this up using a property and avoid depending on virtio pci.
Quoted 74 lines
--- hw/net/vhost_net.c | 19 ++++++++++++++++++- hw/virtio/vhost.c | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-)hw/net/vhost_net.c +18
-1@@ -36,9 +36,11 @@#include <stdio.h> #include "standard-headers/linux/virtio_ring.h" +#include "hw/pci/pci.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-pci.h" struct vhost_net {struct vhost_dev dev;@@ -314,7 +316,22 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, }for (i =0 ; i < total_queues; i++) { -vhost_net_set_vq_index (get_vhost_net (ncs[i].peer), i *2 ); +struct vhost_net *net=get_vhost_net (ncs[i].peer); +vhost_net_set_vq_index (net, i *2 ); + +/* Force VIRTIO_PCI_FLAG_USE_NOTIFIERMASK reset in vhost user case +* Must be done before set_guest_notifier call +*/ +if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) { +BusState *qbus =BUS (qdev_get_parent_bus (DEVICE (dev))); +DeviceState *d =DEVICE (qbus->parent); +if (!strcmp (object_get_typename (OBJECT (d)),TYPE_VIRTIO_NET_PCI )) { +VirtIOPCIProxy *proxy =VIRTIO_PCI (d); + +/* Force proxy to not use mask notifier */ + proxy->flags &= ~VIRTIO_PCI_FLAG_USE_NOTIFIERMASK ; + } + } } r = k->set_guest_notifiers (qbus->parent, total_queues *2 , true);hw/virtio/vhost.c +13
-0@@ -854,8 +854,21 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,/* Clear and discard previous events if any. */ event_notifier_test_and_clear (&vq->masked_notifier); +/* If vhost user, register now the call eventfd, guest_notifier_mask +* function is not used anymore +*/ +if (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ) { + file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq)); + r = dev->vhost_ops->vhost_set_vring_call (dev, &file); +if (r) { + r = -errno; + goto fail_call; + } + } +return 0 ; +fail_call: fail_kick: fail_alloc: cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),Signature · 1 line
2.1.4
Quoted 47 lines · Didier Pallard
Hi,
I recently did some stress tests of a vhost-user interface using an UDP traffic generator. Traffic generator was connected to 2 physical ports that are in turn connected to 2 virtio ports through a linux bridge, VM (running linux) doing routing to forward packets between the 2 virtio ports. When traffic reaches high pps rates of small packets, I faced the 2 following problems:
- at some time, my qemu socket becomes full, causing qemu to send incomplete
SET_VRING_CALLmessages to vhost-user backend (without proper fd set in ancillary data).
- after some time, some interrupts are lost, causing the VM to stop transmitting packets.Both problems come from the fact that interrupt masking/unmasking of the VM is deferred to vhost-user backend through the linux socket.
First problem comes from the fact that socket buffer gets full; it is corrected in the first patch of the serie.
Second problem is a bit more complex. From what i understand of the code, when VM wants to mask/unmask interrupts, qemu traps the command and sends aSET_VRING_CALLto the vhost-user to swap interrupt notifications either to a dummy descriptor or to an fd that was given to kvm module to route interruption to the VM. After sendingSET_VRING_CALLmessage through the socket, VM code continues to run, assuming that the interrupts are now masked; but due to linux socket, this message may be buffered and not currently treated by the vhost-user backend, ie interrupts are not really masked/unmasked as they ought to be.
I think it can be solved in two different ways:
- by waiting for an acknowledgement of vhost-user backend before exiting interrupt masking function, this ensures that interrupt masking is correctly taken into account before giving back hand to the VM, but it has a very high cost in term of cycles. Moreover, unless specifying a new option, it will break current API, since existing vhost-user implementations do not expect a return message on aSET_VRING_CALLcall.
- second way could be, in case vhost-user is involved, to restore the initial behaviour of interrupt masking (ie masking/unmasking interrupts by taking/givingvring_callfd from/to kernel kvm module).
Patches 2 and 3 of the serie propose an implementation of this second option.Didier
Didier Pallard (3):
char: fix vhost-user socket full
virtio-pci: add an option to bypassguest_notifier_mask
vhost-net: forceguest_notifier_maskbypass in vhost-user case
Quoted 7 lines
hw/net/vhost_net.c | 19 ++++++++++++++++++- hw/virtio/vhost.c | 13 +++++++++++++ hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ qemu-char.c | 10 ++++++++++ 5 files changed, 70 insertions(+), 7 deletions(-)
+maintainers
sorry, i forgot them in initial mail
didier
Victor Kaplansky
Tested-byQuoted 40 lines · Didier Pallard
Hi,
I recently did some stress tests of a vhost-user interface using an UDP traffic generator. Traffic generator was connected to 2 physical ports that are in turn connected to 2 virtio ports through a linux bridge, VM (running linux) doing routing to forward packets between the 2 virtio ports. When traffic reaches high pps rates of small packets, I faced the 2 following problems:
- at some time, my qemu socket becomes full, causing qemu to send incomplete
SET_VRING_CALLmessages to vhost-user backend (without proper fd set in ancillary data).
- after some time, some interrupts are lost, causing the VM to stop transmitting packets.Both problems come from the fact that interrupt masking/unmasking of the VM is deferred to vhost-user backend through the linux socket.
First problem comes from the fact that socket buffer gets full; it is corrected in the first patch of the serie.
Second problem is a bit more complex. From what i understand of the code, when VM wants to mask/unmask interrupts, qemu traps the command and sends aSET_VRING_CALLto the vhost-user to swap interrupt notifications either to a dummy descriptor or to an fd that was given to kvm module to route interruption to the VM. After sendingSET_VRING_CALLmessage through the socket, VM code continues to run, assuming that the interrupts are now masked; but due to linux socket, this message may be buffered and not currently treated by the vhost-user backend, ie interrupts are not really masked/unmasked as they ought to be.
I think it can be solved in two different ways:
- by waiting for an acknowledgement of vhost-user backend before exiting interrupt masking function, this ensures that interrupt masking is correctly taken into account before giving back hand to the VM, but it has a very high cost in term of cycles. Moreover, unless specifying a new option, it will break current API, since existing vhost-user implementations do not expect a return message on aSET_VRING_CALLcall.
- second way could be, in case vhost-user is involved, to restore the initial behaviour of interrupt masking (ie masking/unmasking interrupts by taking/givingvring_callfd from/to kernel kvm module).
Patches 2 and 3 of the serie propose an implementation of this second option.
Quoted 2 lines
Didier
Quoted 16 lines
Didier Pallard (3):
char: fix vhost-user socket full
virtio-pci: add an option to bypassguest_notifier_mask
vhost-net: forceguest_notifier_maskbypass in vhost-user casehw/net/vhost_net.c | 19 ++++++++++++++++++- hw/virtio/vhost.c | 13 +++++++++++++ hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ qemu-char.c | 10 ++++++++++ 5 files changed, 70 insertions(+), 7 deletions(-)Signature · 1 line
2.1.4
Quoted 41 lines · Victor Kaplansky
Quoted 40 lines · Didier Pallard
Hi,
I recently did some stress tests of a vhost-user interface using an UDP traffic generator. Traffic generator was connected to 2 physical ports that are in turn connected to 2 virtio ports through a linux bridge, VM (running linux) doing routing to forward packets between the 2 virtio ports. When traffic reaches high pps rates of small packets, I faced the 2 following problems:
- at some time, my qemu socket becomes full, causing qemu to send incomplete
SET_VRING_CALLmessages to vhost-user backend (without proper fd set in ancillary data).
- after some time, some interrupts are lost, causing the VM to stop transmitting packets.Both problems come from the fact that interrupt masking/unmasking of the VM is deferred to vhost-user backend through the linux socket.
First problem comes from the fact that socket buffer gets full; it is corrected in the first patch of the serie.
Second problem is a bit more complex. From what i understand of the code, when VM wants to mask/unmask interrupts, qemu traps the command and sends aSET_VRING_CALLto the vhost-user to swap interrupt notifications either to a dummy descriptor or to an fd that was given to kvm module to route interruption to the VM. After sendingSET_VRING_CALLmessage through the socket, VM code continues to run, assuming that the interrupts are now masked; but due to linux socket, this message may be buffered and not currently treated by the vhost-user backend, ie interrupts are not really masked/unmasked as they ought to be.
I think it can be solved in two different ways:
- by waiting for an acknowledgement of vhost-user backend before exiting interrupt masking function, this ensures that interrupt masking is correctly taken into account before giving back hand to the VM, but it has a very high cost in term of cycles. Moreover, unless specifying a new option, it will break current API, since existing vhost-user implementations do not expect a return message on aSET_VRING_CALLcall.
- second way could be, in case vhost-user is involved, to restore the initial behaviour of interrupt masking (ie masking/unmasking interrupts by taking/givingvring_callfd from/to kernel kvm module).
Patches 2 and 3 of the serie propose an implementation of this second option.
Quoted 20 lines
Quoted 2 lines
Didier
Tested-by Victor Kaplansky <[email protected]>Quoted 16 lines
Didier Pallard (3):
char: fix vhost-user socket full
virtio-pci: add an option to bypassguest_notifier_mask
vhost-net: forceguest_notifier_maskbypass in vhost-user casehw/net/vhost_net.c | 19 ++++++++++++++++++- hw/virtio/vhost.c | 13 +++++++++++++ hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++------ hw/virtio/virtio-pci.h | 6 ++++++ qemu-char.c | 10 ++++++++++ 5 files changed, 70 insertions(+), 7 deletions(-)Signature · 1 line
2.1.4
thanks for the tests, victor
didier