* [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning
@ 2017-06-02 8:15 Marc-André Lureau
2017-06-02 8:35 ` Dr. David Alan Gilbert
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Marc-André Lureau @ 2017-06-02 8:15 UTC (permalink / raw)
To: qemu-devel; +Cc: dgilbert, Marc-André Lureau
CC tests/vhost-user-bridge.o
/home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning: variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]
for (cur = front; front != iov; cur++) {
^~~~~ ~~~
1 warning generated.
Fix the loop, document the function, and fix some related assert().
In practice, the loop bug was harmless because the front sg buffer is
enough to discard/restore the header size.
Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
tests/vhost-user-bridge.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index 8618c20d53..1e5b5ca3da 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
free(elem);
}
+
+/* this function reverse the effect of iov_discard_front() it must be
+ * called with 'front' being the original struct iovec and 'bytes'
+ * being the number of bytes you shaved off
+ */
static void
iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
{
struct iovec *cur;
- for (cur = front; front != iov; cur++) {
+ for (cur = front; cur != iov; cur++) {
+ assert(bytes >= cur->iov_len);
bytes -= cur->iov_len;
}
@@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
}
iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
total += hdrlen;
- assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
+ ret = iov_discard_front(&sg, &num, hdrlen);
+ assert(ret == hdrlen);
}
struct msghdr msg = {
--
2.13.0.91.g00982b8dd
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning
2017-06-02 8:15 [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning Marc-André Lureau
@ 2017-06-02 8:35 ` Dr. David Alan Gilbert
2017-06-02 12:43 ` Jens Freimann
2017-06-07 19:00 ` Marc-André Lureau
2 siblings, 0 replies; 5+ messages in thread
From: Dr. David Alan Gilbert @ 2017-06-02 8:35 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: qemu-devel
* Marc-André Lureau (marcandre.lureau@redhat.com) wrote:
> CC tests/vhost-user-bridge.o
> /home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning: variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]
> for (cur = front; front != iov; cur++) {
> ^~~~~ ~~~
> 1 warning generated.
>
> Fix the loop, document the function, and fix some related assert().
>
> In practice, the loop bug was harmless because the front sg buffer is
> enough to discard/restore the header size.
>
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> tests/vhost-user-bridge.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index 8618c20d53..1e5b5ca3da 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
> free(elem);
> }
>
> +
> +/* this function reverse the effect of iov_discard_front() it must be
> + * called with 'front' being the original struct iovec and 'bytes'
> + * being the number of bytes you shaved off
> + */
> static void
> iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
> {
> struct iovec *cur;
>
> - for (cur = front; front != iov; cur++) {
> + for (cur = front; cur != iov; cur++) {
> + assert(bytes >= cur->iov_len);
> bytes -= cur->iov_len;
> }
>
> @@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
> }
> iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
> total += hdrlen;
> - assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
> + ret = iov_discard_front(&sg, &num, hdrlen);
> + assert(ret == hdrlen);
> }
>
> struct msghdr msg = {
> --
> 2.13.0.91.g00982b8dd
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning
2017-06-02 8:15 [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning Marc-André Lureau
2017-06-02 8:35 ` Dr. David Alan Gilbert
@ 2017-06-02 12:43 ` Jens Freimann
2017-06-07 19:00 ` Marc-André Lureau
2 siblings, 0 replies; 5+ messages in thread
From: Jens Freimann @ 2017-06-02 12:43 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: qemu-devel, dgilbert
On Fri, Jun 02, 2017 at 12:15:19PM +0400, Marc-André Lureau wrote:
> CC tests/vhost-user-bridge.o
> /home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning: variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]
> for (cur = front; front != iov; cur++) {
> ^~~~~ ~~~
> 1 warning generated.
>
> Fix the loop, document the function, and fix some related assert().
>
> In practice, the loop bug was harmless because the front sg buffer is
> enough to discard/restore the header size.
>
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/vhost-user-bridge.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index 8618c20d53..1e5b5ca3da 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
> free(elem);
> }
>
> +
> +/* this function reverse the effect of iov_discard_front() it must be
> + * called with 'front' being the original struct iovec and 'bytes'
> + * being the number of bytes you shaved off
> + */
> static void
> iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
> {
> struct iovec *cur;
>
> - for (cur = front; front != iov; cur++) {
> + for (cur = front; cur != iov; cur++) {
> + assert(bytes >= cur->iov_len);
> bytes -= cur->iov_len;
This fixes a problem I saw when trying to pxe-boot
with vhost-user and vhost-user-bridge. It was running in an endless
loop here. Fixed with this patch.
Tested-by: Jens Freimann <jfreiman@redhat.com>
regards,
Jens
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning
2017-06-02 8:15 [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning Marc-André Lureau
2017-06-02 8:35 ` Dr. David Alan Gilbert
2017-06-02 12:43 ` Jens Freimann
@ 2017-06-07 19:00 ` Marc-André Lureau
2017-06-08 0:32 ` Michael S. Tsirkin
2 siblings, 1 reply; 5+ messages in thread
From: Marc-André Lureau @ 2017-06-07 19:00 UTC (permalink / raw)
To: qemu-devel, Michael S. Tsirkin; +Cc: dgilbert
Hi, Michael, could you pick this patch?
thanks
On Fri, Jun 2, 2017 at 12:26 PM Marc-André Lureau <
marcandre.lureau@redhat.com> wrote:
> CC tests/vhost-user-bridge.o
> /home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning:
> variables 'front' and 'iov' used in loop condition not modified in loop
> body [-Wfor-loop-analysis]
> for (cur = front; front != iov; cur++) {
> ^~~~~ ~~~
> 1 warning generated.
>
> Fix the loop, document the function, and fix some related assert().
>
> In practice, the loop bug was harmless because the front sg buffer is
> enough to discard/restore the header size.
>
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/vhost-user-bridge.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index 8618c20d53..1e5b5ca3da 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
> free(elem);
> }
>
> +
> +/* this function reverse the effect of iov_discard_front() it must be
> + * called with 'front' being the original struct iovec and 'bytes'
> + * being the number of bytes you shaved off
> + */
> static void
> iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
> {
> struct iovec *cur;
>
> - for (cur = front; front != iov; cur++) {
> + for (cur = front; cur != iov; cur++) {
> + assert(bytes >= cur->iov_len);
> bytes -= cur->iov_len;
> }
>
> @@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
> }
> iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
> total += hdrlen;
> - assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
> + ret = iov_discard_front(&sg, &num, hdrlen);
> + assert(ret == hdrlen);
> }
>
> struct msghdr msg = {
> --
> 2.13.0.91.g00982b8dd
>
>
> --
Marc-André Lureau
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning
2017-06-07 19:00 ` Marc-André Lureau
@ 2017-06-08 0:32 ` Michael S. Tsirkin
0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2017-06-08 0:32 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: qemu-devel, dgilbert
On Wed, Jun 07, 2017 at 07:00:46PM +0000, Marc-André Lureau wrote:
> Hi, Michael, could you pick this patch?
>
> thanks
OK. Pls cc me on patches you want me to review.
> On Fri, Jun 2, 2017 at 12:26 PM Marc-André Lureau <
> marcandre.lureau@redhat.com> wrote:
>
> > CC tests/vhost-user-bridge.o
> > /home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning:
> > variables 'front' and 'iov' used in loop condition not modified in loop
> > body [-Wfor-loop-analysis]
> > for (cur = front; front != iov; cur++) {
> > ^~~~~ ~~~
> > 1 warning generated.
> >
> > Fix the loop, document the function, and fix some related assert().
> >
> > In practice, the loop bug was harmless because the front sg buffer is
> > enough to discard/restore the header size.
> >
> > Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > tests/vhost-user-bridge.c | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> > index 8618c20d53..1e5b5ca3da 100644
> > --- a/tests/vhost-user-bridge.c
> > +++ b/tests/vhost-user-bridge.c
> > @@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
> > free(elem);
> > }
> >
> > +
> > +/* this function reverse the effect of iov_discard_front() it must be
> > + * called with 'front' being the original struct iovec and 'bytes'
> > + * being the number of bytes you shaved off
> > + */
> > static void
> > iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
> > {
> > struct iovec *cur;
> >
> > - for (cur = front; front != iov; cur++) {
> > + for (cur = front; cur != iov; cur++) {
> > + assert(bytes >= cur->iov_len);
> > bytes -= cur->iov_len;
> > }
> >
> > @@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
> > }
> > iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
> > total += hdrlen;
> > - assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
> > + ret = iov_discard_front(&sg, &num, hdrlen);
> > + assert(ret == hdrlen);
> > }
> >
> > struct msghdr msg = {
> > --
> > 2.13.0.91.g00982b8dd
> >
> >
> > --
> Marc-André Lureau
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-06-08 0:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-02 8:15 [Qemu-devel] [PATCH] vhost-user-bridge: fix iov_restore_front() warning Marc-André Lureau
2017-06-02 8:35 ` Dr. David Alan Gilbert
2017-06-02 12:43 ` Jens Freimann
2017-06-07 19:00 ` Marc-André Lureau
2017-06-08 0:32 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).