vhost: fix condition check for # of outstanding dma buffers
Subsystems (3)
PATCH 1/1 vhost: fix condition check for # of outstanding dma buffers
---
drivers/vhost/net.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/net.c +4 -2
@@ -189,8 +189,10 @@ static void handle_tx(struct vhost_net *net)break ; }/* If more outstanding DMAs, queue the work */ -if (unlikely (vq->upend_idx - vq->done_idx > -VHOST_MAX_PEND )) { +if (unlikely ((vq->upend_idx - vq->done_idx > +VHOST_MAX_PEND ) || + (vq->upend_idx - vq->done_idx > +VHOST_MAX_PEND -UIO_MAXIOV ))) {tx_poll_start (net, sock);set_bit (SOCK_ASYNC_NOSPACE , &sock->flags);break ;
Michael S. Tsirkin
maintainerQuoted 11 lines · Shirley Ma
Signed-off-by Shirley Ma <[email protected]>---
drivers/vhost/net.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +0
-0
drivers/vhost/net.c static void handle_tx(struct vhost_net *net) · line 195
Quoted 9 lines
drivers/vhost/net.c +4
-2@@ -189,8 +189,10 @@ static void handle_tx(struct vhost_net *net)break ; }/* If more outstanding DMAs, queue the work */ -if (unlikely (vq->upend_idx - vq->done_idx > -VHOST_MAX_PEND )) { +if (unlikely ((vq->upend_idx - vq->done_idx > +VHOST_MAX_PEND ) || + (vq->upend_idx - vq->done_idx > +VHOST_MAX_PEND -UIO_MAXIOV ))) {
Could you please explain why this makes sense please? VHOST_MAX_PEND is 128 UIO_MAXIOV is 1024 so the result is negative?
I thought upend_idx - done_idx is exactly the number of buffers, so once we get too many we stop until one gets freed?
Quoted 4 lines
drivers/vhost/net.c +0
-0tx_poll_start (net, sock);set_bit (SOCK_ASYNC_NOSPACE , &sock->flags);break ;
Quoted 23 lines · Michael S. Tsirkin
Quoted 11 lines · Shirley Ma
Signed-off-by Shirley Ma <[email protected]>---
drivers/vhost/net.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +0
-0drivers/vhost/net.c static void handle_tx(struct vhost_net *net) · line 195
Quoted 9 lines
drivers/vhost/net.c +4
-2@@ -189,8 +189,10 @@ static void handle_tx(struct vhost_net *net)break ; }/* If more outstanding DMAs, queue the work */ -if (unlikely (vq->upend_idx - vq->done_idx > -VHOST_MAX_PEND )) { + if (unlikely((vq->upend_idx - vq->done_idx > + VHOST_MAX_PEND) || + (vq->upend_idx - vq->done_idx > + VHOST_MAX_PEND -
UIO_MAXIOV))) {
Quoted 3 lines
Could you please explain why this makes sense please?
VHOST_MAX_PENDis 128UIO_MAXIOVis 1024 so the result is negative?
I thought it is equal to:
if (vq->upend_idx > vq->done_idx)
check vq->upend_idx - vq->done_idx > VHOST_MAX_PEND if (vq->upend_idx < vq->done_idx) check vq->upend_idx + UIO_MAXIOV - vq->done_idx > VHOST_MAX_PEND
Quoted 3 lines
I thought
upend_idx-done_idxis exactly the number of buffers, so once we get too many we stop until one gets freed?
They are index, so in vhost zerocopy callback, we can get the idx right away.
Quoted 6 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net *net) · line 197
Quoted 3 lines
drivers/vhost/net.c +0
-0tx_poll_start (net, sock); set_bit(SOCK_ASYNC_NOSPACE,
&sock->flags);Quoted 2 lines
drivers/vhost/net.c +0
-0break ;
Michael S. Tsirkin
maintainerQuoted 28 lines · Shirley Ma
Quoted 23 lines · Michael S. Tsirkin
Quoted 11 lines · Shirley Ma
Signed-off-by Shirley Ma <[email protected]>---
drivers/vhost/net.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +0
-0drivers/vhost/net.c static void handle_tx(struct vhost_net *net) · line 195
Quoted 9 lines
drivers/vhost/net.c +4
-2@@ -189,8 +189,10 @@ static void handle_tx(struct vhost_net *net)break ; }/* If more outstanding DMAs, queue the work */ -if (unlikely (vq->upend_idx - vq->done_idx > -VHOST_MAX_PEND )) { + if (unlikely((vq->upend_idx - vq->done_idx > + VHOST_MAX_PEND) || + (vq->upend_idx - vq->done_idx > + VHOST_MAX_PEND -
UIO_MAXIOV))) {Quoted 3 lines
Could you please explain why this makes sense please?
VHOST_MAX_PENDis 128UIO_MAXIOVis 1024 so the result is negative?
Quoted 7 lines
I thought it is equal to:
if (
vq->upend_idx>vq->done_idx)check vq->upend_idx - vq->done_idx > VHOST_MAX_PEND if (vq->upend_idx < vq->done_idx) check vq->upend_idx + UIO_MAXIOV - vq->done_idx > VHOST_MAX_PEND
Check it out: upend_idx == done_idx == 0 does not satisfy the above conditions but does trigger in your code, right?
Better keep it simple. Maybe:
if (unlikely(vq->upend_idx - vq->done_idx > VHOST_MAX_PEND) || (unlikely(vq->upend_idx < vq->done_idx) && unlikely(vq->upend_idx + UIO_MAXIOV - vq->done_idx > VHOST_MAX_PEND)))
?
Also, please add commit log documenting what does the patch
fix: something like:
'the test for # of outstanding buffers returned
incorrect results when due to wrap around, upend_idx < done_idx'?
Quoted 13 lines
Quoted 3 lines
I thought
upend_idx-done_idxis exactly the number of buffers, so once we get too many we stop until one gets freed?They are index, so in vhost zerocopy callback, we can get the idx right away.
Quoted 6 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net *net) · line 197
Quoted 3 lines
drivers/vhost/net.c +0
-0tx_poll_start (net, sock); set_bit(SOCK_ASYNC_NOSPACE,
&sock->flags);Quoted 2 lines
drivers/vhost/net.c +0
-0break ;
Quoted 40 lines · Michael S. Tsirkin
Quoted 5 lines · Shirley Ma
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Shirley Ma
Signed-off-by Shirley Ma <[email protected]>---
Quoted 8 lines
Quoted 8 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net
Quoted 8 lines
drivers/vhost/net.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +0
-0@@ -189,8 +189,10 @@ static void handle_tx(struct vhost_net*net)
Quoted 3 lines
Quoted 3 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net · line 191
Quoted 3 lines
drivers/vhost/net.c +0
-0break ; }/* If more outstanding DMAs, queue the work */
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
drivers/vhost/net.c +3
-2- if (unlikely(vq->upend_idx - vq->done_idx -VHOST_MAX_PEND )) { + if (unlikely((vq->upend_idx - vq->done_idx + VHOST_MAX_PEND) || + (vq->upend_idx - vq->done_idxQuoted 6 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net · line 197
Quoted 1 line
drivers/vhost/net.c +1
-0+ VHOST_MAX_PEND -
UIO_MAXIOV))) {Could you please explain why this makes sense please?
VHOST_MAX_PENDis 128UIO_MAXIOVis 1024 so the result is negative?Quoted 6 lines
I thought it is equal to:
if (
vq->upend_idx>vq->done_idx)check vq->upend_idx - vq->done_idx > VHOST_MAX_PEND if (vq->upend_idx < vq->done_idx) check vq->upend_idx + UIO_MAXIOV - vq->done_idx >
Quoted 5 lines
VHOST_MAX_PENDQuoted 1 line
Check it out:
upend_idx==done_idx== 0 does not satisfy the above conditions but does trigger in your code, right?
We don't hit upend_idx == done_idx == 0. Only upend_idx == done_idx == UIO_MAXIOV could happen if the lower device has issue and never DMA any packets out.
Quoted 7 lines
Better keep it simple. Maybe:
if (unlikely(vq->upend_idx - vq->done_idx > VHOST_MAX_PEND) || (unlikely(vq->upend_idx < vq->done_idx) && unlikely(vq->upend_idx + UIO_MAXIOV - vq->done_idx > VHOST_MAX_PEND)))
Quoted 7 lines
?
Also, please add commit log documenting what does the patch
fix: something like:
'the test for # of outstanding buffers returned
incorrect results when due to wrap around,upend_idx<done_idx'?
Sure, will modify it and resubmit.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I thought
upend_idx-done_idxis exactly the number of buffers, so once we get too many we stop until one gets freed?
Quoted 10 lines
Quoted 1 line
They are index, so in vhost zerocopy callback, we can get the idx
right
Quoted 8 lines
away.
Quoted 6 lines
Quoted 3 lines
drivers/vhost/net.c +0
-0tx_poll_start (net, sock);set_bit(SOCK_ASYNC_NOSPACE,
&sock->flags);Quoted 2 lines
break;
Thanks
Shirley
Michael S. Tsirkin
maintainerQuoted 44 lines · Shirley Ma
Quoted 43 lines · Michael S. Tsirkin
Quoted 5 lines · Shirley Ma
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Shirley Ma
Signed-off-by Shirley Ma <[email protected]>---
Quoted 8 lines
Quoted 8 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net
Quoted 8 lines
drivers/vhost/net.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +0
-0@@ -189,8 +189,10 @@ static void handle_tx(struct vhost_net*net)
Quoted 3 lines
Quoted 3 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net · line 191
Quoted 3 lines
drivers/vhost/net.c +0
-0break ; }/* If more outstanding DMAs, queue the work */
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
drivers/vhost/net.c +3
-2- if (unlikely(vq->upend_idx - vq->done_idx -VHOST_MAX_PEND )) { + if (unlikely((vq->upend_idx - vq->done_idx + VHOST_MAX_PEND) || + (vq->upend_idx - vq->done_idxQuoted 6 lines
drivers/vhost/net.c static void handle_tx(struct vhost_net · line 197
Quoted 1 line
drivers/vhost/net.c +1
-0+ VHOST_MAX_PEND -
UIO_MAXIOV))) {Could you please explain why this makes sense please?
VHOST_MAX_PENDis 128UIO_MAXIOVis 1024 so the result is negative?Quoted 6 lines
I thought it is equal to:
if (
vq->upend_idx>vq->done_idx)check vq->upend_idx - vq->done_idx > VHOST_MAX_PEND if (vq->upend_idx < vq->done_idx) check vq->upend_idx + UIO_MAXIOV - vq->done_idx >
VHOST_MAX_PENDQuoted 1 line
Quoted 6 lines
Quoted 2 lines
Check it out:
upend_idx==done_idx== 0 does not satisfy the above conditions but does trigger in your code, right?We don't hit
upend_idx==done_idx== 0. Onlyupend_idx==done_idx==UIO_MAXIOVcould happen if the lower device has issue and never DMA any packets out.
My point was that the logic isn't the same, even though you said 'it is equal to'.
Same applies to upend_idx == 1, done_idx == 0.
Quoted 34 lines
Quoted 7 lines
Better keep it simple. Maybe:
if (unlikely(vq->upend_idx - vq->done_idx > VHOST_MAX_PEND) || (unlikely(vq->upend_idx < vq->done_idx) && unlikely(vq->upend_idx + UIO_MAXIOV - vq->done_idx > VHOST_MAX_PEND)))Quoted 7 lines
?
Also, please add commit log documenting what does the patch
fix: something like:
'the test for # of outstanding buffers returned
incorrect results when due to wrap around,upend_idx<done_idx'?Sure, will modify it and resubmit.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I thought
upend_idx-done_idxis exactly the number of buffers, so once we get too many we stop until one gets freed?Quoted 10 lines
Quoted 1 line
They are index, so in vhost zerocopy callback, we can get the idx
right
Quoted 8 lines
away.
Quoted 6 lines
Quoted 3 lines
drivers/vhost/net.c +0
-0tx_poll_start (net, sock);set_bit(SOCK_ASYNC_NOSPACE,
&sock->flags);Quoted 2 lines
break;Thanks
Shirley
Quoted 3 lines · Michael S. Tsirkin
My point was that the logic isn't the same, even though you said 'it is equal to'.
Same applies toupend_idx== 1,done_idx== 0.
:) not sure what I was thinking.
I will resubmit the patch.
Thanks
Shirley