Skip to content

Commit

Permalink
Revert "vsock: Fix blocking ops call in prepare_to_wait"
Browse files Browse the repository at this point in the history
This reverts commit 5988818 ("vsock: Fix
blocking ops call in prepare_to_wait")

The commit reverted with this patch caused us to potentially miss wakeups.
Since the condition is not checked between the prepare_to_wait and the
schedule(), if a wakeup happens after the condition is checked but before
the sleep happens, we will miss it. ( A description of the problem can be
found here: http://www.makelinux.net/ldd3/chp-6-sect-2 ).

By reverting the patch, the behaviour is still incorrect (since we
shouldn't sleep between the prepare_to_wait and the schedule) but at least
it will not miss wakeups.

The next patch in the series actually fixes the behaviour.

Signed-off-by: Claudio Imbrenda <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Claudio Imbrenda authored and davem330 committed Mar 22, 2016
1 parent 9a0384c commit 6f57e56
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions net/vmw_vsock/af_vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,8 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
if (err < 0)
goto out;

prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);

while (total_written < len) {
ssize_t written;

Expand All @@ -1576,9 +1578,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
goto out_wait;

release_sock(sk);
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
timeout = schedule_timeout(timeout);
finish_wait(sk_sleep(sk), &wait);
lock_sock(sk);
if (signal_pending(current)) {
err = sock_intr_errno(timeout);
Expand All @@ -1588,6 +1588,8 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
goto out_wait;
}

prepare_to_wait(sk_sleep(sk), &wait,
TASK_INTERRUPTIBLE);
}

/* These checks occur both as part of and after the loop
Expand Down Expand Up @@ -1633,6 +1635,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
out_wait:
if (total_written > 0)
err = total_written;
finish_wait(sk_sleep(sk), &wait);
out:
release_sock(sk);
return err;
Expand Down Expand Up @@ -1713,6 +1716,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (err < 0)
goto out;

prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);

while (1) {
s64 ready = vsock_stream_has_data(vsk);
Expand All @@ -1723,7 +1727,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
*/

err = -ENOMEM;
goto out;
goto out_wait;
} else if (ready > 0) {
ssize_t read;

Expand All @@ -1746,7 +1750,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
vsk, target, read,
!(flags & MSG_PEEK), &recv_data);
if (err < 0)
goto out;
goto out_wait;

if (read >= target || flags & MSG_PEEK)
break;
Expand All @@ -1769,9 +1773,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
break;

release_sock(sk);
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
timeout = schedule_timeout(timeout);
finish_wait(sk_sleep(sk), &wait);
lock_sock(sk);

if (signal_pending(current)) {
Expand All @@ -1781,6 +1783,9 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
err = -EAGAIN;
break;
}

prepare_to_wait(sk_sleep(sk), &wait,
TASK_INTERRUPTIBLE);
}
}

Expand Down Expand Up @@ -1811,6 +1816,8 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
err = copied;
}

out_wait:
finish_wait(sk_sleep(sk), &wait);
out:
release_sock(sk);
return err;
Expand Down

0 comments on commit 6f57e56

Please sign in to comment.