Mini-OS: netfront: fix off-by-one error introduced in 7c8f3483
PATCH 1/1 Mini-OS: netfront: fix off-by-one error introduced in 7c8f3483
7c8f3483 introduced a break within a loop in netfront.c such that cons and nr_consumed were no longer always being incremented. The offset at cons will be processed multiple times with the break in place.
Remove the break and re-add "some !=0" in the loop for HAVE_LIBC.
--- netfront.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
netfront.c +3 -2
@@ -108,8 +108,10 @@ moretodo:#ifdef HAVE_LIBC some =0 ; -#endif +for (cons = dev->rx.rsp_cons; (cons != rp) && !some; nr_consumed++, cons++) +#else for (cons = dev->rx.rsp_cons; cons != rp; nr_consumed++, cons++) +#endif {struct net_buffer * buf;unsigned char * page;
@@ -135,7 +137,6 @@ moretodo:memcpy (dev->data, page+rx->offset, len); dev->rlen = len; some =1 ; -break ; } else#endif dev->netif_rx (page+rx->offset,rx->status);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
CC Samuel
Quoted 44 lines · Sarah Newman
7c8f3483introduced a break within a loop innetfront.csuch that cons andnr_consumedwere no longer always being incremented. The offset at cons will be processed multiple times with the break in place.Remove the break and re-add "some !=0" in the loop for
HAVE_LIBC.Signed-off-by Sarah Newman <[email protected]>--- netfront.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)netfront.c +3
-2@@ -108,8 +108,10 @@ moretodo:#ifdef HAVE_LIBC some =0 ; -#endif +for (cons = dev->rx.rsp_cons; (cons != rp) && !some; nr_consumed++, cons++) +#else for (cons = dev->rx.rsp_cons; cons != rp; nr_consumed++, cons++) +#endif {struct net_buffer * buf;unsigned char * page;@@ -135,7 +137,6 @@ moretodo:memcpy (dev->data, page+rx->offset, len); dev->rlen = len; some =1 ; -break ; } else#endif dev->netif_rx (page+rx->offset,rx->status);Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 1 line · Wei Liu, on Fri 25 Mar 2016 13:09:07 +0000, wrote:
CC Samuel
Thanks.
Quoted 7 lines · Sarah Newman
Quoted 6 lines
7c8f3483introduced a break within a loop innetfront.csuch that cons andnr_consumedwere no longer always being incremented. The offset at cons will be processed multiple times with the break in place.Remove the break and re-add "some !=0" in the loop for
HAVE_LIBC.
Mmm, right.
That ifdef makes things even more difficult to understand then. That however makes me think: how about the attached patch, which actually simplifies the rest.
Thanks!
Samuel
netfront: fix off-by-one error introduced in 7c8f3483
7c8f3483 introduced a break within a loop in netfront.c such that cons and nr_consumed were no longer always being incremented. The offset at cons will be processed multiple times with the break in place.
Remove the break and re-add "some !=0" in the loop for HAVE_LIBC, rename it into dobreak to mitigate confusion.
netfront.c +6 -14
@@ -97,19 +97,15 @@ void network_rx(struct netfront_dev *dev) {RING_IDX rp,cons,req_prod;int nr_consumed, more, i, notify; -#ifdef HAVE_LIBC -int some; -#endif +int dobreak; nr_consumed =0 ; moretodo: rp = dev->rx.sring->rsp_prod;rmb ();/* Ensure we see queued responses up to 'rp'. */ -#ifdef HAVE_LIBC - some =0 ; -#endif -for (cons = dev->rx.rsp_cons; cons != rp; nr_consumed++, cons++) + dobreak =0 ; +for (cons = dev->rx.rsp_cons; cons != rp && !dobreak; nr_consumed++, cons++) {struct net_buffer * buf;unsigned char * page;
@@ -134,8 +130,8 @@ moretodo: len = dev->len;memcpy (dev->data, page+rx->offset, len); dev->rlen = len; - some =1 ; -break ; +/* No need to receive the rest for now */ + dobreak =1 ; } else#endif dev->netif_rx (page+rx->offset,rx->status);
@@ -144,11 +140,7 @@ moretodo: dev->rx.rsp_cons=cons;RING_FINAL_CHECK_FOR_RESPONSES (&dev->rx,more); -#ifdef HAVE_LIBC -if (more && !some) goto moretodo; -#else -if (more) goto moretodo; -#endif +if (more && !dobreak) goto moretodo; req_prod = dev->rx.req_prod_pvt;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 13 lines · Samuel Thibault
Quoted 1 line · Wei Liu, on Fri 25 Mar 2016 13:09:07 +0000, wrote:
CC Samuel
Thanks.
Quoted 7 lines · Sarah Newman
Quoted 6 lines
7c8f3483introduced a break within a loop innetfront.csuch that cons andnr_consumedwere no longer always being incremented. The offset at cons will be processed multiple times with the break in place.Remove the break and re-add "some !=0" in the loop for
HAVE_LIBC.
Quoted 9 lines
Mmm, right.
That ifdef makes things even more difficult to understand then. That however makes me think: how about the attached patch, which actually simplifies the rest.
Thanks!
Samuel
I have no objections to backing out additional changes made in 7c8f3483, but I wasn't the person who submitted that patch.
The patch tests OK with GNT_DEBUG enabled.
--Sarah
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 1 line · Sarah Newman, on Fri 25 Mar 2016 12:19:23 -0700, wrote:
I have no objections to backing out additional changes made in
7c8f3483,
? My patch doesn't really back out more than what you proposed actually.
Quoted 1 line
The patch tests OK with
GNT_DEBUGenabled.
Good :)
Samuel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 4 lines · Samuel Thibault
Quoted 1 line · Sarah Newman, on Fri 25 Mar 2016 12:19:23 -0700, wrote:
I have no objections to backing out additional changes made in
7c8f3483,? My patch doesn't really back out more than what you proposed actually.
It also backs out the #ifdef's on HAVE_LIBC, but yes it's functionally equivalent.
--Sarah
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 8 lines · Samuel Thibault
Quoted 7 lines · Sarah Newman
Quoted 6 lines
7c8f3483introduced a break within a loop innetfront.csuch that cons andnr_consumedwere no longer always being incremented. The offset at cons will be processed multiple times with the break in place.Remove the break and re-add "some !=0" in the loop for
HAVE_LIBC.
Quoted 9 lines
Mmm, right.
That ifdef makes things even more difficult to understand then. That however makes me think: how about the attached patch, which actually simplifies the rest.
Thanks!
Samuel
Does anything else need to happen for this patch to be used with xen master and stable 4.6?
Thanks, Sarah
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 15 lines · Sarah Newman
Quoted 14 lines · Samuel Thibault
Quoted 7 lines · Sarah Newman
Quoted 6 lines
7c8f3483introduced a break within a loop innetfront.csuch that cons andnr_consumedwere no longer always being incremented. The offset at cons will be processed multiple times with the break in place.Remove the break and re-add "some !=0" in the loop for
HAVE_LIBC.Mmm, right.
That ifdef makes things even more difficult to understand then. That however makes me think: how about the attached patch, which actually simplifies the rest.
Quoted 6 lines
Quoted 3 lines
Thanks!
SamuelDoes anything else need to happen for this patch to be used with xen master and stable 4.6?
I take it that you and Samuel have reached an agreement on how to proceed?
Can either of you submit a proper final patch to xen-devel and minios-devel and CC me please? I will see to its backport.
Note that we are near 4.7 freeze at the moment, so it might take some time for me to get to it. But I don't think I will miss it because I want the patch to be in for 4.7.
Wei.
Quoted 1 line
Thanks, Sarah
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel