[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230122100526.2302556-3-lvivier@redhat.com>
Date: Sun, 22 Jan 2023 11:05:24 +0100
From: Laurent Vivier <lvivier@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: "Michael S. Tsirkin" <mst@...hat.com>,
Parav Pandit <parav@...dia.com>,
virtualization@...ts.linux-foundation.org, netdev@...r.kernel.org,
Eli Cohen <elic@...dia.com>, Jason Wang <jasowang@...hat.com>,
Gautam Dawar <gautam.dawar@...inx.com>,
Cindy Lu <lulu@...hat.com>,
"David S. Miller" <davem@...emloft.net>,
Eugenio PĂ©rez <eperezma@...hat.com>
Subject: [PATCH 2/4] virtio_net: add a timeout in virtnet_send_command()
if the device control queue is buggy, don't crash the kernel by
waiting for ever the response.
Signed-off-by: Laurent Vivier <lvivier@...hat.com>
---
drivers/net/virtio_net.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 25511a86590e..29b3cc72082d 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1974,6 +1974,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
struct scatterlist *sgs[4], hdr, stat;
unsigned out_num = 0, tmp;
int ret;
+ unsigned long timeout;
/* Caller should know better */
BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ));
@@ -2006,8 +2007,10 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
/* Spin for a response, the kick causes an ioport write, trapping
* into the hypervisor, so the request should be handled immediately.
*/
+ timeout = jiffies + 20 * HZ;
while (!virtqueue_get_buf(vi->cvq, &tmp) &&
- !virtqueue_is_broken(vi->cvq))
+ !virtqueue_is_broken(vi->cvq) &&
+ !time_after(jiffies, timeout))
cpu_relax();
return vi->ctrl->status == VIRTIO_NET_OK;
--
2.39.0
Powered by blists - more mailing lists