netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] virtio_net: fix missing lock protection on control_buf access
@ 2024-05-30  3:41 Heng Qi
  2024-05-30  3:52 ` Jason Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Heng Qi @ 2024-05-30  3:41 UTC (permalink / raw)
  To: netdev, virtualization
  Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Jiri Pirko, Daniel Jurgens, Hariprasad Kelam

Refactored the handling of control_buf to be within the cvq_lock
critical section, mitigating race conditions between reading device
responses and new command submissions.

Fixes: 6f45ab3e0409 ("virtio_net: Add a lock for the command VQ.")
Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
---
v1->v2:
  - Use the ok instead of ret.

 drivers/net/virtio_net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4a802c0ea2cb..1ea8e6a24286 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2686,6 +2686,7 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
 {
 	struct scatterlist *sgs[5], hdr, stat;
 	u32 out_num = 0, tmp, in_num = 0;
+	bool ok;
 	int ret;
 
 	/* Caller should know better */
@@ -2731,8 +2732,9 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
 	}
 
 unlock:
+	ok = vi->ctrl->status == VIRTIO_NET_OK;
 	mutex_unlock(&vi->cvq_lock);
-	return vi->ctrl->status == VIRTIO_NET_OK;
+	return ok;
 }
 
 static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
-- 
2.32.0.3.g01195cf9f


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

* Re: [PATCH net v2] virtio_net: fix missing lock protection on control_buf access
  2024-05-30  3:41 [PATCH net v2] virtio_net: fix missing lock protection on control_buf access Heng Qi
@ 2024-05-30  3:52 ` Jason Wang
  2024-05-30  3:57 ` Xuan Zhuo
  2024-06-01 22:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2024-05-30  3:52 UTC (permalink / raw)
  To: Heng Qi
  Cc: netdev, virtualization, Michael S. Tsirkin, Xuan Zhuo,
	Eugenio Pérez, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Jiri Pirko, Daniel Jurgens, Hariprasad Kelam

On Thu, May 30, 2024 at 11:41 AM Heng Qi <hengqi@linux.alibaba.com> wrote:
>
> Refactored the handling of control_buf to be within the cvq_lock
> critical section, mitigating race conditions between reading device
> responses and new command submissions.
>
> Fixes: 6f45ab3e0409 ("virtio_net: Add a lock for the command VQ.")
> Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
> Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
> ---
> v1->v2:
>   - Use the ok instead of ret.
>
>  drivers/net/virtio_net.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 4a802c0ea2cb..1ea8e6a24286 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2686,6 +2686,7 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
>  {
>         struct scatterlist *sgs[5], hdr, stat;
>         u32 out_num = 0, tmp, in_num = 0;
> +       bool ok;
>         int ret;
>
>         /* Caller should know better */
> @@ -2731,8 +2732,9 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
>         }
>
>  unlock:
> +       ok = vi->ctrl->status == VIRTIO_NET_OK;
>         mutex_unlock(&vi->cvq_lock);
> -       return vi->ctrl->status == VIRTIO_NET_OK;
> +       return ok;
>  }
>
>  static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> --
> 2.32.0.3.g01195cf9f

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks


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

* Re: [PATCH net v2] virtio_net: fix missing lock protection on control_buf access
  2024-05-30  3:41 [PATCH net v2] virtio_net: fix missing lock protection on control_buf access Heng Qi
  2024-05-30  3:52 ` Jason Wang
@ 2024-05-30  3:57 ` Xuan Zhuo
  2024-06-01 22:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Xuan Zhuo @ 2024-05-30  3:57 UTC (permalink / raw)
  To: Heng Qi
  Cc: Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Jiri Pirko, Daniel Jurgens, Hariprasad Kelam, netdev,
	virtualization

On Thu, 30 May 2024 11:41:43 +0800, Heng Qi <hengqi@linux.alibaba.com> wrote:
> Refactored the handling of control_buf to be within the cvq_lock
> critical section, mitigating race conditions between reading device
> responses and new command submissions.
>
> Fixes: 6f45ab3e0409 ("virtio_net: Add a lock for the command VQ.")
> Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
> Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>

Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

> ---
> v1->v2:
>   - Use the ok instead of ret.
>
>  drivers/net/virtio_net.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 4a802c0ea2cb..1ea8e6a24286 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2686,6 +2686,7 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
>  {
>  	struct scatterlist *sgs[5], hdr, stat;
>  	u32 out_num = 0, tmp, in_num = 0;
> +	bool ok;
>  	int ret;
>
>  	/* Caller should know better */
> @@ -2731,8 +2732,9 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
>  	}
>
>  unlock:
> +	ok = vi->ctrl->status == VIRTIO_NET_OK;
>  	mutex_unlock(&vi->cvq_lock);
> -	return vi->ctrl->status == VIRTIO_NET_OK;
> +	return ok;
>  }
>
>  static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> --
> 2.32.0.3.g01195cf9f
>

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

* Re: [PATCH net v2] virtio_net: fix missing lock protection on control_buf access
  2024-05-30  3:41 [PATCH net v2] virtio_net: fix missing lock protection on control_buf access Heng Qi
  2024-05-30  3:52 ` Jason Wang
  2024-05-30  3:57 ` Xuan Zhuo
@ 2024-06-01 22:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-06-01 22:20 UTC (permalink / raw)
  To: Heng Qi
  Cc: netdev, virtualization, mst, jasowang, xuanzhuo, eperezma, davem,
	edumazet, kuba, pabeni, jiri, danielj, hkelam

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 30 May 2024 11:41:43 +0800 you wrote:
> Refactored the handling of control_buf to be within the cvq_lock
> critical section, mitigating race conditions between reading device
> responses and new command submissions.
> 
> Fixes: 6f45ab3e0409 ("virtio_net: Add a lock for the command VQ.")
> Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
> Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
> 
> [...]

Here is the summary with links:
  - [net,v2] virtio_net: fix missing lock protection on control_buf access
    https://git.kernel.org/netdev/net/c/30636258a7c9

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] 4+ messages in thread

end of thread, other threads:[~2024-06-01 22:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-30  3:41 [PATCH net v2] virtio_net: fix missing lock protection on control_buf access Heng Qi
2024-05-30  3:52 ` Jason Wang
2024-05-30  3:57 ` Xuan Zhuo
2024-06-01 22:20 ` 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).