Skip to content

Commit 6f57e56

Browse files
Claudio Imbrendadavem330
authored andcommitted
Revert "vsock: Fix blocking ops call in prepare_to_wait"
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 <imbrenda@linux.vnet.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9a0384c commit 6f57e56

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,8 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
15571557
if (err < 0)
15581558
goto out;
15591559

1560+
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
1561+
15601562
while (total_written < len) {
15611563
ssize_t written;
15621564

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

15781580
release_sock(sk);
1579-
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
15801581
timeout = schedule_timeout(timeout);
1581-
finish_wait(sk_sleep(sk), &wait);
15821582
lock_sock(sk);
15831583
if (signal_pending(current)) {
15841584
err = sock_intr_errno(timeout);
@@ -1588,6 +1588,8 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
15881588
goto out_wait;
15891589
}
15901590

1591+
prepare_to_wait(sk_sleep(sk), &wait,
1592+
TASK_INTERRUPTIBLE);
15911593
}
15921594

15931595
/* These checks occur both as part of and after the loop
@@ -1633,6 +1635,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
16331635
out_wait:
16341636
if (total_written > 0)
16351637
err = total_written;
1638+
finish_wait(sk_sleep(sk), &wait);
16361639
out:
16371640
release_sock(sk);
16381641
return err;
@@ -1713,6 +1716,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
17131716
if (err < 0)
17141717
goto out;
17151718

1719+
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
17161720

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

17251729
err = -ENOMEM;
1726-
goto out;
1730+
goto out_wait;
17271731
} else if (ready > 0) {
17281732
ssize_t read;
17291733

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

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

17711775
release_sock(sk);
1772-
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
17731776
timeout = schedule_timeout(timeout);
1774-
finish_wait(sk_sleep(sk), &wait);
17751777
lock_sock(sk);
17761778

17771779
if (signal_pending(current)) {
@@ -1781,6 +1783,9 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
17811783
err = -EAGAIN;
17821784
break;
17831785
}
1786+
1787+
prepare_to_wait(sk_sleep(sk), &wait,
1788+
TASK_INTERRUPTIBLE);
17841789
}
17851790
}
17861791

@@ -1811,6 +1816,8 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
18111816
err = copied;
18121817
}
18131818

1819+
out_wait:
1820+
finish_wait(sk_sleep(sk), &wait);
18141821
out:
18151822
release_sock(sk);
18161823
return err;

0 commit comments

Comments
 (0)