提交 9e380825 编写于 作者: S Shirley Ma 提交者: Michael S. Tsirkin

vhost: handle wrap around in # of bufs math

The meth for calculating the # of outstanding buffers gives
incorrect results when vq->upend_idx wraps around zero.
Fix that.
Signed-off-by: NShirley Ma <xma@us.ibm.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 c047e5f3
...@@ -182,15 +182,21 @@ static void handle_tx(struct vhost_net *net) ...@@ -182,15 +182,21 @@ static void handle_tx(struct vhost_net *net)
break; break;
/* Nothing new? Wait for eventfd to tell us they refilled. */ /* Nothing new? Wait for eventfd to tell us they refilled. */
if (head == vq->num) { if (head == vq->num) {
int num_pends;
wmem = atomic_read(&sock->sk->sk_wmem_alloc); wmem = atomic_read(&sock->sk->sk_wmem_alloc);
if (wmem >= sock->sk->sk_sndbuf * 3 / 4) { if (wmem >= sock->sk->sk_sndbuf * 3 / 4) {
tx_poll_start(net, sock); tx_poll_start(net, sock);
set_bit(SOCK_ASYNC_NOSPACE, &sock->flags); set_bit(SOCK_ASYNC_NOSPACE, &sock->flags);
break; break;
} }
/* If more outstanding DMAs, queue the work */ /* If more outstanding DMAs, queue the work.
if (unlikely(vq->upend_idx - vq->done_idx > * Handle upend_idx wrap around
VHOST_MAX_PEND)) { */
num_pends = likely(vq->upend_idx >= vq->done_idx) ?
(vq->upend_idx - vq->done_idx) :
(vq->upend_idx + UIO_MAXIOV - vq->done_idx);
if (unlikely(num_pends > VHOST_MAX_PEND)) {
tx_poll_start(net, sock); tx_poll_start(net, sock);
set_bit(SOCK_ASYNC_NOSPACE, &sock->flags); set_bit(SOCK_ASYNC_NOSPACE, &sock->flags);
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册