linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep
@ 2022-11-01  2:17 Dexuan Cui
  2022-11-01  2:17 ` [PATCH v2 1/2] vsock: remove the unused 'wait' in vsock_connectible_recvmsg() Dexuan Cui
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dexuan Cui @ 2022-11-01  2:17 UTC (permalink / raw)
  To: sgarzare, davem, edumazet, kuba, pabeni, arseny.krasnov, netdev
  Cc: virtualization, linux-kernel, kys, haiyangz, stephen, wei.liu,
	linux-hyperv, Dexuan Cui

Patch 1 removes the unused 'wait' variable.
Patch 2 fixes an infinite sleep issue reported by a hv_sock user.

Made v2 to address Stefano's comments.
Please see each patch's header for changes in v2.

Dexuan Cui (2):
  vsock: remove the unused 'wait' in vsock_connectible_recvmsg()
  vsock: fix possible infinite sleep in vsock_connectible_wait_data()

 net/vmw_vsock/af_vsock.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/2] vsock: remove the unused 'wait' in vsock_connectible_recvmsg()
  2022-11-01  2:17 [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep Dexuan Cui
@ 2022-11-01  2:17 ` Dexuan Cui
  2022-11-01  2:17 ` [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data() Dexuan Cui
  2022-11-03 10:00 ` [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep patchwork-bot+netdevbpf
  2 siblings, 0 replies; 8+ messages in thread
From: Dexuan Cui @ 2022-11-01  2:17 UTC (permalink / raw)
  To: sgarzare, davem, edumazet, kuba, pabeni, arseny.krasnov, netdev
  Cc: virtualization, linux-kernel, kys, haiyangz, stephen, wei.liu,
	linux-hyperv, Dexuan Cui

Remove the unused variable introduced by 19c1b90e1979.

Fixes: 19c1b90e1979 ("af_vsock: separate receive data loop")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---

Changes in v2:
  Added Stefano's Reviewed-by.

 net/vmw_vsock/af_vsock.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index ee418701cdee..d258fd43092e 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2092,8 +2092,6 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 	const struct vsock_transport *transport;
 	int err;
 
-	DEFINE_WAIT(wait);
-
 	sk = sock->sk;
 	vsk = vsock_sk(sk);
 	err = 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data()
  2022-11-01  2:17 [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep Dexuan Cui
  2022-11-01  2:17 ` [PATCH v2 1/2] vsock: remove the unused 'wait' in vsock_connectible_recvmsg() Dexuan Cui
@ 2022-11-01  2:17 ` Dexuan Cui
  2022-11-02  9:31   ` Stefano Garzarella
  2022-11-03 10:00 ` [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep patchwork-bot+netdevbpf
  2 siblings, 1 reply; 8+ messages in thread
From: Dexuan Cui @ 2022-11-01  2:17 UTC (permalink / raw)
  To: sgarzare, davem, edumazet, kuba, pabeni, arseny.krasnov, netdev
  Cc: virtualization, linux-kernel, kys, haiyangz, stephen, wei.liu,
	linux-hyperv, Dexuan Cui

Currently vsock_connectible_has_data() may miss a wakeup operation
between vsock_connectible_has_data() == 0 and the prepare_to_wait().

Fix the race by adding the process to the wait queue before checking
vsock_connectible_has_data().

Fixes: b3f7fd54881b ("af_vsock: separate wait data loop")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---

Changes in v2 (Thanks Stefano!):
  Fixed a typo in the commit message.
  Removed the unnecessary finish_wait() at the end of the loop.

 net/vmw_vsock/af_vsock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index d258fd43092e..884eca7f6743 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1905,8 +1905,11 @@ static int vsock_connectible_wait_data(struct sock *sk,
 	err = 0;
 	transport = vsk->transport;
 
-	while ((data = vsock_connectible_has_data(vsk)) == 0) {
+	while (1) {
 		prepare_to_wait(sk_sleep(sk), wait, TASK_INTERRUPTIBLE);
+		data = vsock_connectible_has_data(vsk);
+		if (data != 0)
+			break;
 
 		if (sk->sk_err != 0 ||
 		    (sk->sk_shutdown & RCV_SHUTDOWN) ||
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data()
  2022-11-01  2:17 ` [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data() Dexuan Cui
@ 2022-11-02  9:31   ` Stefano Garzarella
  2022-11-02  9:42     ` Stefano Garzarella
  0 siblings, 1 reply; 8+ messages in thread
From: Stefano Garzarella @ 2022-11-02  9:31 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: davem, edumazet, kuba, pabeni, arseny.krasnov, netdev,
	virtualization, linux-kernel, kys, haiyangz, stephen, wei.liu,
	linux-hyperv

On Mon, Oct 31, 2022 at 07:17:06PM -0700, Dexuan Cui wrote:
>Currently vsock_connectible_has_data() may miss a wakeup operation
>between vsock_connectible_has_data() == 0 and the prepare_to_wait().
>
>Fix the race by adding the process to the wait queue before checking
>vsock_connectible_has_data().
>
>Fixes: b3f7fd54881b ("af_vsock: separate wait data loop")
>Signed-off-by: Dexuan Cui <decui@microsoft.com>
>---
>
>Changes in v2 (Thanks Stefano!):
>  Fixed a typo in the commit message.
>  Removed the unnecessary finish_wait() at the end of the loop.

LGTM:

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
> net/vmw_vsock/af_vsock.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index d258fd43092e..884eca7f6743 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -1905,8 +1905,11 @@ static int vsock_connectible_wait_data(struct sock *sk,
> 	err = 0;
> 	transport = vsk->transport;
>
>-	while ((data = vsock_connectible_has_data(vsk)) == 0) {
>+	while (1) {
> 		prepare_to_wait(sk_sleep(sk), wait, TASK_INTERRUPTIBLE);
>+		data = vsock_connectible_has_data(vsk);
>+		if (data != 0)
>+			break;
>
> 		if (sk->sk_err != 0 ||
> 		    (sk->sk_shutdown & RCV_SHUTDOWN) ||
>-- 
>2.25.1
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data()
  2022-11-02  9:31   ` Stefano Garzarella
@ 2022-11-02  9:42     ` Stefano Garzarella
  2022-11-02 13:30       ` Frederic Dalleau
  0 siblings, 1 reply; 8+ messages in thread
From: Stefano Garzarella @ 2022-11-02  9:42 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: davem, edumazet, kuba, pabeni, arseny.krasnov, netdev,
	virtualization, linux-kernel, kys, haiyangz, stephen, wei.liu,
	linux-hyperv, frederic.dalleau

On Wed, Nov 02, 2022 at 10:31:37AM +0100, Stefano Garzarella wrote:
>On Mon, Oct 31, 2022 at 07:17:06PM -0700, Dexuan Cui wrote:
>>Currently vsock_connectible_has_data() may miss a wakeup operation
>>between vsock_connectible_has_data() == 0 and the prepare_to_wait().
>>
>>Fix the race by adding the process to the wait queue before checking
>>vsock_connectible_has_data().
>>
>>Fixes: b3f7fd54881b ("af_vsock: separate wait data loop")
>>Signed-off-by: Dexuan Cui <decui@microsoft.com>
>>---
>>
>>Changes in v2 (Thanks Stefano!):
>> Fixed a typo in the commit message.
>> Removed the unnecessary finish_wait() at the end of the loop.
>
>LGTM:
>
>Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>

And I would add

Reported-by: Frédéric Dalleau <frederic.dalleau@docker.com>

Since Frédéric posted a similar patch some months ago (I lost it because 
netdev and I were not in cc):
https://lore.kernel.org/virtualization/20220824074251.2336997-2-frederic.dalleau@docker.com/

Thanks,
Stefano


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data()
  2022-11-02  9:42     ` Stefano Garzarella
@ 2022-11-02 13:30       ` Frederic Dalleau
  2022-11-02 17:30         ` Dexuan Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Frederic Dalleau @ 2022-11-02 13:30 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: Dexuan Cui, davem, edumazet, kuba, pabeni, arseny.krasnov,
	netdev, virtualization, linux-kernel, kys, haiyangz, stephen,
	wei.liu, linux-hyperv

Hi Dexuan, Stefano,

Tested-by: Frédéric Dalleau <frederic.dalleau@docker.com>

Regards,
Frédéric


On Wed, Nov 2, 2022 at 10:42 AM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> On Wed, Nov 02, 2022 at 10:31:37AM +0100, Stefano Garzarella wrote:
> >On Mon, Oct 31, 2022 at 07:17:06PM -0700, Dexuan Cui wrote:
> >>Currently vsock_connectible_has_data() may miss a wakeup operation
> >>between vsock_connectible_has_data() == 0 and the prepare_to_wait().
> >>
> >>Fix the race by adding the process to the wait queue before checking
> >>vsock_connectible_has_data().
> >>
> >>Fixes: b3f7fd54881b ("af_vsock: separate wait data loop")
> >>Signed-off-by: Dexuan Cui <decui@microsoft.com>
> >>---
> >>
> >>Changes in v2 (Thanks Stefano!):
> >> Fixed a typo in the commit message.
> >> Removed the unnecessary finish_wait() at the end of the loop.
> >
> >LGTM:
> >
> >Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> >
>
> And I would add
>
> Reported-by: Frédéric Dalleau <frederic.dalleau@docker.com>
>
> Since Frédéric posted a similar patch some months ago (I lost it because
> netdev and I were not in cc):
> https://lore.kernel.org/virtualization/20220824074251.2336997-2-frederic.dalleau@docker.com/
>
> Thanks,
> Stefano
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data()
  2022-11-02 13:30       ` Frederic Dalleau
@ 2022-11-02 17:30         ` Dexuan Cui
  0 siblings, 0 replies; 8+ messages in thread
From: Dexuan Cui @ 2022-11-02 17:30 UTC (permalink / raw)
  To: Frederic Dalleau, Stefano Garzarella
  Cc: davem, edumazet, kuba, pabeni, arseny.krasnov, netdev,
	virtualization, linux-kernel, KY Srinivasan, Haiyang Zhang,
	stephen, wei.liu, linux-hyperv

> From: Frederic Dalleau <frederic.dalleau@docker.com>
> Sent: Wednesday, November 2, 2022 6:31 AM
> To: Stefano Garzarella <sgarzare@redhat.com>
> ...
> Hi Dexuan, Stefano,
> 
> Tested-by: Frédéric Dalleau <frederic.dalleau@docker.com>
> 
> Regards,
> Frédéric

Thank you, Frederic! I didn't realize you posted a similar patch in Aug :-)

Thanks Stefano for reviewing!

Thanks,
-- Dexuan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep
  2022-11-01  2:17 [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep Dexuan Cui
  2022-11-01  2:17 ` [PATCH v2 1/2] vsock: remove the unused 'wait' in vsock_connectible_recvmsg() Dexuan Cui
  2022-11-01  2:17 ` [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data() Dexuan Cui
@ 2022-11-03 10:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-03 10:00 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: sgarzare, davem, edumazet, kuba, pabeni, arseny.krasnov, netdev,
	virtualization, linux-kernel, kys, haiyangz, stephen, wei.liu,
	linux-hyperv

Hello:

This series was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 31 Oct 2022 19:17:04 -0700 you wrote:
> Patch 1 removes the unused 'wait' variable.
> Patch 2 fixes an infinite sleep issue reported by a hv_sock user.
> 
> Made v2 to address Stefano's comments.
> Please see each patch's header for changes in v2.
> 
> Dexuan Cui (2):
>   vsock: remove the unused 'wait' in vsock_connectible_recvmsg()
>   vsock: fix possible infinite sleep in vsock_connectible_wait_data()
> 
> [...]

Here is the summary with links:
  - [v2,1/2] vsock: remove the unused 'wait' in vsock_connectible_recvmsg()
    https://git.kernel.org/netdev/net/c/cf6ff0df0fd1
  - [v2,2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data()
    https://git.kernel.org/netdev/net/c/466a85336fee

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-03 10:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01  2:17 [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep Dexuan Cui
2022-11-01  2:17 ` [PATCH v2 1/2] vsock: remove the unused 'wait' in vsock_connectible_recvmsg() Dexuan Cui
2022-11-01  2:17 ` [PATCH v2 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data() Dexuan Cui
2022-11-02  9:31   ` Stefano Garzarella
2022-11-02  9:42     ` Stefano Garzarella
2022-11-02 13:30       ` Frederic Dalleau
2022-11-02 17:30         ` Dexuan Cui
2022-11-03 10:00 ` [PATCH v2 0/2] vsock: remove an unused variable and fix infinite sleep patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).