From 4c634053305d57cb88880a3d6cddb4f3dcafaa27 Mon Sep 17 00:00:00 2001 From: Claudio Imbrenda Date: Tue, 22 Mar 2016 17:05:52 +0100 Subject: [PATCH] BACKPORT: AF_VSOCK: Shrink the area influenced by prepare_to_wait When a thread is prepared for waiting by calling prepare_to_wait, sleeping is not allowed until either the wait has taken place or finish_wait has been called. The existing code in af_vsock imposed unnecessary no-sleep assumptions to a broad list of backend functions. This patch shrinks the influence of prepare_to_wait to the area where it is strictly needed, therefore relaxing the no-sleep restriction there. Signed-off-by: Claudio Imbrenda Signed-off-by: David S. Miller (cherry picked from commit f7f9b5e7f8eccfd68ffa7b8d74b07c478bb9e7f0) [astrachan: Backported around stable backport 3223ea1 ("vsock: use new wait API for vsock_stream_sendmsg()")] Bug: 121166534 Test: Ran cuttlefish with android-4.4 + VSOCKETS, VMWARE_VMCI_VSOCKETS Signed-off-by: Cody Schuffelen Change-Id: Ic1d7bae4b1187ad48194bf4d0b1dd09ab0275734 --- net/vmw_vsock/af_vsock.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 7f1d166ce612..2cb12fe3b60d 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1559,7 +1559,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, while (total_written < len) { ssize_t written; - add_wait_queue(sk_sleep(sk), &wait); + prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); while (vsock_stream_has_space(vsk) == 0 && sk->sk_err == 0 && !(sk->sk_shutdown & SEND_SHUTDOWN) && @@ -1568,13 +1568,13 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, /* Don't wait for non-blocking sockets. */ if (timeout == 0) { err = -EAGAIN; - remove_wait_queue(sk_sleep(sk), &wait); + finish_wait(sk_sleep(sk), &wait); goto out_err; } err = transport->notify_send_pre_block(vsk, &send_data); if (err < 0) { - remove_wait_queue(sk_sleep(sk), &wait); + finish_wait(sk_sleep(sk), &wait); goto out_err; } @@ -1583,15 +1583,15 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, lock_sock(sk); if (signal_pending(current)) { err = sock_intr_errno(timeout); - remove_wait_queue(sk_sleep(sk), &wait); + finish_wait(sk_sleep(sk), &wait); goto out_err; } else if (timeout == 0) { err = -EAGAIN; - remove_wait_queue(sk_sleep(sk), &wait); + finish_wait(sk_sleep(sk), &wait); goto out_err; } } - remove_wait_queue(sk_sleep(sk), &wait); + finish_wait(sk_sleep(sk), &wait); /* These checks occur both as part of and after the loop * conditional since we need to check before and after