Skip to contentSkip to conversation

tools/hv: terminate fcopy daemon if read from uio fails

PATCH Applied Olaf Hering 3 participants 3 messages Nov 5, 2024 – Dec 7, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/hv: terminate fcopy daemon if read from uio fails

Terminate endless loop in reading fails, to avoid flooding syslog.

This happens if the state of "Guest services" integration service is changed from "enabled" to "disabled" at runtime in the VM settings. In this case pread returns EIO.

Also handle an interrupted system call, and continue in this case.

---
v2: update commit message

A more complete fix is to handle this properly in the kernel, by making the file descriptor unavailable for further operations.

 tools/hv/hv_fcopy_uio_daemon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/hv/hv_fcopy_uio_daemon.c +3 -1
index 7a00f3066a98..281fd95dc0d8 100644
@@ -468,8 +468,10 @@ int main(int argc, char *argv[])
 		 */
 		ret = pread(fcopy_fd, &tmp, sizeof(int), 0);
 		if (ret < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
 			syslog(LOG_ERR, "pread failed: %s", strerror(errno));
-			continue;
+			goto close;
 		}
 
 		len = HV_RING_SIZE;
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Olaf Hering

Terminate endless loop in reading fails, to avoid flooding syslog.

This happens if the state of "Guest services" integration service is changed from "enabled" to "disabled" at runtime in the VM settings. In this case pread returns EIO.

My comment on V1 was meant to log this information in the syslog, so the user can look for the Guest Service status incase of EIO. Capturing these details in the commit will require additional effort from user.

Nevertheless, thanks for fixing this:

Quoted 29 lines

Also handle an interrupted system call, and continue in this case.

---
v2: update commit message

A more complete fix is to handle this properly in the kernel, by making the file descriptor unavailable for further operations.

 tools/hv/hv_fcopy_uio_daemon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/hv/hv_fcopy_uio_daemon.c +3 -1
index 7a00f3066a98..281fd95dc0d8 100644
@@ -468,8 +468,10 @@ int main(int argc, char *argv[])
 		 */
 		ret = pread(fcopy_fd, &tmp, sizeof(int), 0);
 		if (ret < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
 			syslog(LOG_ERR, "pread failed: %s", strerror(errno));
-			continue;
+			goto close;
 		}
 
 		len = HV_RING_SIZE;
maintainer Applied
#2 lore raw
In reply to Olaf Hering
Quoted 9 lines · Olaf Hering

Terminate endless loop in reading fails, to avoid flooding syslog.

This happens if the state of "Guest services" integration service is changed from "enabled" to "disabled" at runtime in the VM settings. In this case pread returns EIO.

Also handle an interrupted system call, and continue in this case.

Applied to hyperv-fixes. Thanks.