From 221c5b51feb28431f24cf4ab4352e88e0799f454 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Tue, 16 Apr 2024 20:09:57 +0800 Subject: [PATCH] dragonball: fix EPOLLHUP/EPOLLERR events handling in vsock 1. EPOLLHUP events also need to be read and will be got len 0. 2. We should kill the connection when EPOLLERR events are received. Signed-off-by: Tim Zhang Signed-off-by: Fupan Li --- .../src/vsock/csm/connection.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs b/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs index 0e27a36a49..438aa800d1 100644 --- a/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs +++ b/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs @@ -460,7 +460,8 @@ impl VsockEpollListener for VsockConnection { /// Notify the connection about an event (or set of events) that it was /// interested in. fn notify(&mut self, evset: epoll::Events) { - if evset.contains(epoll::Events::EPOLLIN) { + // EPOLLHUP also needs to be read and will be got len 0 + if evset.contains(epoll::Events::EPOLLIN) || evset.contains(epoll::Events::EPOLLHUP) { // Data can be read from the host stream. Setting a Rw pending // indication, so that the muxer will know to call `recv_pkt()` // later. @@ -514,6 +515,19 @@ impl VsockEpollListener for VsockConnection { self.pending_rx.insert(PendingRx::CreditUpdate); } } + + // The host stream has encountered an error. We'll kill this + // connection. + if evset.contains(epoll::Events::EPOLLERR) + && !evset.contains(epoll::Events::EPOLLIN) + && !evset.contains(epoll::Events::EPOLLOUT) + { + warn!( + "vsock: connection received EPOLLERR event: lp={}, pp={}", + self.local_port, self.peer_port + ); + self.kill(); + } } }