From patchwork Tue May 28 07:52:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13676239 X-Patchwork-Delegate: kuba@kernel.org Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA73E73472 for ; Tue, 28 May 2024 07:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716882759; cv=none; b=MuCdpJNZXmvCRI9yUg4+PUzWxKT+SxT2c6X8W32SyG8uLSq6FuKkd7vjQtVRpc4JbEWX/sEm+FE2zGOgxjS9/pCX+367MyJ7Ww7nlWLD4ddzSdneOF2hjvL9R/VBGfLB2o0QhMu7CycandJDHXUO5QHhQCE82a6CjRsLZgkFHGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716882759; c=relaxed/simple; bh=GfEulMx2KhtrizCd56h3xXWnS2UCVQN4StF4rpSymzQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=InoNLR+5lAQ+fZZXE7vgfI9U3bbI0wiw+2yzRHZvDZ1pCAoeorphG8D8oBCZRgYyPvS0nQjTVb3emK47I3dwoBaVEpgAzpL/6RIjnwUGeMZhh47Wb/+wyoASY0WbYOu13aDHcsbUnnf+WeenMsKyOVHdDlgotdKu4ezLeMyPPYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=GDRg9ws3; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="GDRg9ws3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1716882749; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=KdpOhLozJ8bbzcbkjkEZg/h/Suz653QXLD5WRKflAzk=; b=GDRg9ws3UVT2sUua2Xbx1eq8EnaiYjbEONvaCJkPfma4jlSaH2CPBoDyA2GnNfZtKSZPEhNpDYgkn09IfzwMEolJt0ZKI3dYjJXsSZJGGZs78VczTlF208bPkJMNph00tAaUWIFGDWBAwchg5p2TB35+aGJKkQZpd9dgkfPsWmQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067110;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0W7OsRbZ_1716882748; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0W7OsRbZ_1716882748) by smtp.aliyun-inc.com; Tue, 28 May 2024 15:52:29 +0800 From: Heng Qi To: netdev@vger.kernel.org, virtualization@lists.linux.dev Cc: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jiri Pirko , Daniel Jurgens Subject: [PATCH net 1/2] virtio_net: rename ret to err Date: Tue, 28 May 2024 15:52:25 +0800 Message-Id: <20240528075226.94255-2-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240528075226.94255-1-hengqi@linux.alibaba.com> References: <20240528075226.94255-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The integer variable 'ret', denoting the return code, is mismatched with the boolean return type of virtnet_send_command_reply(); hence, it is renamed to 'err'. The usage of 'ret' is deferred to the next patch. Signed-off-by: Heng Qi Reviewed-by: Hariprasad Kelam --- drivers/net/virtio_net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 4a802c0ea2cb..6b0512a628e0 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2686,7 +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; - int ret; + int err; /* Caller should know better */ BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)); @@ -2710,10 +2710,10 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd sgs[out_num + in_num++] = in; BUG_ON(out_num + in_num > ARRAY_SIZE(sgs)); - ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC); - if (ret < 0) { + err = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC); + if (err < 0) { dev_warn(&vi->vdev->dev, - "Failed to add sgs for command vq: %d\n.", ret); + "Failed to add sgs for command vq: %d\n.", err); mutex_unlock(&vi->cvq_lock); return false; } From patchwork Tue May 28 07:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13676240 X-Patchwork-Delegate: kuba@kernel.org Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E4874424 for ; Tue, 28 May 2024 07:52:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716882761; cv=none; b=MB0Aqgxnd7uB+wYyX0woEzOCoBVi373MeAf7po/fl+t8zRtYj6KGh7OrX2xM/srOWpXO7grofH3mcN5LLP7ZbP2zx0mWKbvnhm/uXHrgbvLilxslqvHyiuED9ki90vopc9j2Jhg3YCb2Dg/t0JUUvTNYHP2q1X/wYxVaPwq7+c4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716882761; c=relaxed/simple; bh=MVeOCp1eOAx/0XTSeLRydwTDlUF4aqpYkuUWaZcOeb8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ewHywDj4kRha2OXraCbeA2hPPDrTVGBJc5+1ukxaBS9NcQ7hJ+L4f0WF8hywPHUpXkIqpGPROlOJMvvp3DbltGElZ006eRmFFHR+gyVd6KTkX6xKfXI8u+NKrYoqBuCIK66LX872/TezdXkFpTbHoROW4SgBx2+VXpCH3bt2goo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=WTNi3KVM; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="WTNi3KVM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1716882751; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=gyTS35yXfP4O3KiWeOE7WQ81O2elpED7DfkLuUKlI5k=; b=WTNi3KVM6wHmXUHJA5blVA/eIRtcQ4yJbo1SGDzSdZ5H6U1NSeM7tzKiYv3ACOfmeJxHP6jEhNdjX6kOFIP9sYV4cXg+eWndGoFKlawe3KWL8TAZQ8yTF8TBs+FwDHzcNMLXNKM+4iYhJo6eW0bEW3u7lIL+/PZzWBmryeOwwS4= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0W7Ospqd_1716882749; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0W7Ospqd_1716882749) by smtp.aliyun-inc.com; Tue, 28 May 2024 15:52:30 +0800 From: Heng Qi To: netdev@vger.kernel.org, virtualization@lists.linux.dev Cc: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jiri Pirko , Daniel Jurgens Subject: [PATCH net 2/2] virtio_net: fix missing lock protection on control_buf access Date: Tue, 28 May 2024 15:52:26 +0800 Message-Id: <20240528075226.94255-3-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240528075226.94255-1-hengqi@linux.alibaba.com> References: <20240528075226.94255-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Hariprasad Kelam --- 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 6b0512a628e0..3d8407d9e3d2 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 ret; int err; /* Caller should know better */ @@ -2731,8 +2732,9 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd } unlock: + ret = vi->ctrl->status == VIRTIO_NET_OK; mutex_unlock(&vi->cvq_lock); - return vi->ctrl->status == VIRTIO_NET_OK; + return ret; } static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,