Skip to contentSkip to conversation

selftests/uffd: Allow EINTR/EAGAIN

PATCH Applied Peter Xu 2 participants 2 messages Nov 15, 2021

Subsystems (2)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 selftests/uffd: Allow EINTR/EAGAIN

This allow test to continue with interruptions like gdb.

---
 tools/testing/selftests/vm/userfaultfd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/userfaultfd.c +5 -2
index 8a09057d2f22..64845be3971d 100644
@@ -644,7 +644,7 @@ static int uffd_read_msg(int ufd, struct uffd_msg *msg)
 
 	if (ret != sizeof(*msg)) {
 		if (ret < 0) {
-			if (errno == EAGAIN)
+			if (errno == EAGAIN || errno == EINTR)
 				return 1;
 			err("blocking read error");
 		} else {
@@ -720,8 +720,11 @@ static void *uffd_poll_thread(void *arg)
 
 	for (;;) {
 		ret = poll(pollfd, 2, -1);
-		if (ret <= 0)
+		if (ret <= 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
 			err("poll error: %d", ret);
+		}
 		if (pollfd[1].revents & POLLIN) {
 			if (read(pollfd[1].fd, &tmp_chr, 1) != 1)
 				err("read pipefd error");
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw

Looks correct to me!

Quoted 37 lines · Peter Xu

This allow test to continue with interruptions like gdb.

---
 tools/testing/selftests/vm/userfaultfd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/userfaultfd.c +5 -3
index 8a09057d2f22..64845be3971d 100644
@@ -644,7 +644,7 @@ static int uffd_read_msg(int ufd, struct uffd_msg *msg)
 
        if (ret != sizeof(*msg)) {
                if (ret < 0) {
-                       if (errno == EAGAIN)
+                       if (errno == EAGAIN || errno == EINTR)
                                return 1;
                        err("blocking read error");
                } else {
@@ -720,8 +720,11 @@ static void *uffd_poll_thread(void *arg)
 
        for (;;) {
                ret = poll(pollfd, 2, -1);
-               if (ret <= 0)
+               if (ret <= 0) {
+                       if (errno == EINTR || errno == EAGAIN)
+                               continue;
                        err("poll error: %d", ret);
+               }
                if (pollfd[1].revents & POLLIN) {
                        if (read(pollfd[1].fd, &tmp_chr, 1) != 1)
                                err("read pipefd error");
--

2.32.0