lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
* [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64
@ 2022-10-27  5:54 Alistair Francis via lttng-dev
  2022-12-13  5:09 ` Alistair Francis via lttng-dev
  0 siblings, 1 reply; 4+ messages in thread
From: Alistair Francis via lttng-dev @ 2022-10-27  5:54 UTC (permalink / raw)
  To: lttng-dev; +Cc: alistair23

From: Alistair Francis <alistair.francis@wdc.com>

Add support for the  64-bit time_t syscalls SYS_ppoll_time64
and SYS_pselect6_time64.

These are the syscalls that exist 32-bit platforms since the 5.1 kernel.
32-bit platforms with a 64-bit time_t only have these and don't have the
original syscalls (such as 32-bit RISC-V).

Fixes: https://github.com/lttng/lttng-tools/pull/162
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
To keep the test_cases[] array clean I have implemented the functions
for all builds, but the functions are a no-op if the syscall is missing.

v2:
 - Split out a seperate _time64 test

 tests/regression/kernel/select_poll_epoll.cpp | 184 ++++++++++++++++++
 1 file changed, 184 insertions(+)

diff --git a/tests/regression/kernel/select_poll_epoll.cpp b/tests/regression/kernel/select_poll_epoll.cpp
index c0b688217..dfaab52c8 100644
--- a/tests/regression/kernel/select_poll_epoll.cpp
+++ b/tests/regression/kernel/select_poll_epoll.cpp
@@ -5,6 +5,7 @@
  *
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <poll.h>
@@ -48,10 +49,14 @@ int lttng_opt_quiet, lttng_opt_verbose, lttng_opt_mi;
 
 static void run_working_cases(FILE *validation_output_file);
 static void pselect_invalid_fd(FILE *validation_output_file);
+static void pselect_time64_invalid_fd(FILE *validation_output_file);
 static void test_ppoll_big(FILE *validation_output_file);
 static void ppoll_fds_buffer_overflow(FILE *validation_output_file);
+static void ppoll_time64_fds_buffer_overflow(FILE *validation_output_file);
 static void pselect_invalid_pointer(FILE *validation_output_file);
+static void pselect_time64_invalid_pointer(FILE *validation_output_file);
 static void ppoll_fds_ulong_max(FILE *validation_output_file);
+static void ppoll_time64_fds_ulong_max(FILE *validation_output_file);
 static void epoll_pwait_invalid_pointer(FILE *validation_output_file);
 static void epoll_pwait_int_max(FILE *validation_output_file);
 static void ppoll_concurrent_write(FILE *validation_output_file);
@@ -69,10 +74,14 @@ const struct test_case {
 	{ .run = run_working_cases, .produces_validation_info = true, .timeout = -1 },
 	{ .run = run_working_cases, .produces_validation_info = true, .timeout = 1 },
 	{ .run = pselect_invalid_fd, .produces_validation_info = false, .timeout = 0 },
+	{ .run = pselect_time64_invalid_fd, .produces_validation_info = false, .timeout = 0 },
 	{ .run = test_ppoll_big, .produces_validation_info = false, .timeout = 0 },
 	{ .run = ppoll_fds_buffer_overflow, .produces_validation_info = false, .timeout = 0 },
+	{ .run = ppoll_time64_fds_buffer_overflow, .produces_validation_info = false, .timeout = 0 },
 	{ .run = pselect_invalid_pointer, .produces_validation_info = false, .timeout = 0 },
+	{ .run = pselect_time64_invalid_pointer, .produces_validation_info = false, .timeout = 0 },
 	{ .run = ppoll_fds_ulong_max, .produces_validation_info = false, .timeout = 0 },
+	{ .run = ppoll_time64_fds_ulong_max, .produces_validation_info = false, .timeout = 0 },
 	{ .run = epoll_pwait_invalid_pointer, .produces_validation_info = true, .timeout = 0 },
 	{ .run = epoll_pwait_int_max, .produces_validation_info = true, .timeout = 0 },
 	{ .run = ppoll_concurrent_write, .produces_validation_info = false, .timeout = 0 },
@@ -440,6 +449,44 @@ end:
 	return;
 }
 
+/*
+ * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
+ * segfault (eventually with a "*** stack smashing detected ***" message).
+ * The event should contain an array of 100 FDs filled with garbage.
+ */
+static
+void ppoll_time64_fds_buffer_overflow(
+		FILE *validation_output_file __attribute__((unused)))
+{
+#ifdef SYS_ppoll_time64
+	struct pollfd ufds[NB_FD];
+	char buf[BUF_SIZE];
+	int ret;
+
+	ufds[0].fd = wait_fd;
+	ufds[0].events = POLLIN|POLLPRI;
+
+	/*
+	 * As there is no timeout value, we don't convert to/from
+	 * 64/32-bit time_t.
+	 */
+	ret = syscall(SYS_ppoll_time64, ufds, 100, NULL, NULL);
+	/*
+	 * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
+	 * to work and if it doesn't we fail.
+	 */
+
+	if (ret < 0) {
+		PERROR("ppoll_time64");
+	} else if (ret > 0) {
+		ret = read(wait_fd, buf, BUF_SIZE);
+		if (ret < 0) {
+			PERROR("[ppoll_time64] read");
+		}
+	}
+#endif
+}
+
 /*
  * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
  * segfault (eventually with a "*** stack smashing detected ***" message).
@@ -449,6 +496,7 @@ static
 void ppoll_fds_buffer_overflow(
 		FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_ppoll
 	struct pollfd ufds[NB_FD];
 	char buf[BUF_SIZE];
 	int ret;
@@ -466,6 +514,46 @@ void ppoll_fds_buffer_overflow(
 			PERROR("[ppoll] read");
 		}
 	}
+#endif
+}
+
+/*
+ * Ask for ULONG_MAX FDs in a buffer for allocated for only 1 FD, should
+ * cleanly fail with a "Invalid argument".
+ * The event should contain an empty array of FDs and overflow = 1.
+ */
+static
+void ppoll_time64_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
+{
+#ifdef SYS_ppoll_time64
+	struct pollfd ufds[NB_FD];
+	char buf[BUF_SIZE];
+	int ret;
+
+	ufds[0].fd = wait_fd;
+	ufds[0].events = POLLIN|POLLPRI;
+
+	/*
+	 * As there is no timeout value, we don't convert to/from
+	 * 64/32-bit time_t.
+	 */
+	ret = syscall(SYS_ppoll_time64, ufds, ULONG_MAX, NULL, NULL);
+	/*
+	 * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
+	 * to work and if it doesn't we fail.
+	 */
+
+	if (ret < 0 && errno != ENOSYS) {
+		/* Expected error. */
+	} else if (errno == ENOSYS) {
+		PERROR("[ppoll_time64] missing syscall");
+	} else if (ret > 0) {
+		ret = read(wait_fd, buf, BUF_SIZE);
+		if (ret < 0) {
+			PERROR("[ppoll_time64] read");
+		}
+	}
+#endif
 }
 
 /*
@@ -476,6 +564,7 @@ void ppoll_fds_buffer_overflow(
 static
 void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_ppoll
 	struct pollfd ufds[NB_FD];
 	char buf[BUF_SIZE];
 	int ret;
@@ -492,6 +581,59 @@ void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
 			PERROR("[ppoll] read");
 		}
 	}
+#endif
+}
+
+/*
+ * Pass an invalid file descriptor to pselect6(). The syscall should return
+ * -EBADF. The recorded event should contain a "ret = -EBADF (-9)".
+ */
+static
+void pselect_time64_invalid_fd(FILE *validation_output_file __attribute__((unused)))
+{
+#ifdef SYS_pselect6_time64
+	fd_set rfds;
+	int ret;
+	int fd;
+	char buf[BUF_SIZE];
+
+	/*
+	 * Open a file, close it and use the closed FD in the pselect6 call.
+	 */
+	fd = open("/dev/null", O_RDONLY);
+	if (fd == -1) {
+		PERROR("open");
+		goto error;
+	}
+
+	ret = close(fd);
+	if (ret == -1) {
+		PERROR("close");
+		goto error;
+	}
+
+	FD_ZERO(&rfds);
+	FD_SET(fd, &rfds);
+
+	ret = syscall(SYS_pselect6_time64, fd + 1, &rfds, NULL, NULL, NULL, NULL);
+	/*
+	 * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
+	 * to work and if it doesn't we fail.
+	 */
+
+	if (ret == -1 && errno != ENOSYS) {
+		/* Expected error. */
+	} else if (errno == ENOSYS) {
+		PERROR("[pselect_time64] missing syscall");
+	} else if (ret) {
+		ret = read(wait_fd, buf, BUF_SIZE);
+		if (ret < 0) {
+			PERROR("[pselect_time64] read");
+		}
+	}
+error:
+	return;
+#endif
 }
 
 /*
@@ -501,6 +643,7 @@ void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
 static
 void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_pselect6
 	fd_set rfds;
 	int ret;
 	int fd;
@@ -525,6 +668,7 @@ void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
 	FD_SET(fd, &rfds);
 
 	ret = syscall(SYS_pselect6, fd + 1, &rfds, NULL, NULL, NULL, NULL);
+
 	if (ret == -1) {
 		/* Expected error. */
 	} else if (ret) {
@@ -535,6 +679,44 @@ void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
 	}
 error:
 	return;
+#endif
+}
+
+/*
+ * Invalid pointer as writefds, should output a ppoll event
+ * with 0 FDs.
+ */
+static
+void pselect_time64_invalid_pointer(
+		FILE *validation_output_file __attribute__((unused)))
+{
+#ifdef SYS_pselect6_time64
+	fd_set rfds;
+	int ret;
+	char buf[BUF_SIZE];
+	void *invalid = (void *) 0x42;
+
+	FD_ZERO(&rfds);
+	FD_SET(wait_fd, &rfds);
+
+	ret = syscall(SYS_pselect6_time64, 1, &rfds, (fd_set *) invalid, NULL, NULL,
+			NULL);
+	/*
+	 * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
+	 * to work and if it doesn't we fail.
+	 */
+
+	if (ret == -1 && errno != ENOSYS) {
+		/* Expected error. */
+	} else if (errno == ENOSYS) {
+		PERROR("[pselect_time64] missing syscall");
+	} else if (ret) {
+		ret = read(wait_fd, buf, BUF_SIZE);
+		if (ret < 0) {
+			PERROR("[pselect_time64] read");
+		}
+	}
+#endif
 }
 
 /*
@@ -545,6 +727,7 @@ static
 void pselect_invalid_pointer(
 		FILE *validation_output_file __attribute__((unused)))
 {
+#ifdef SYS_pselect6
 	fd_set rfds;
 	int ret;
 	char buf[BUF_SIZE];
@@ -563,6 +746,7 @@ void pselect_invalid_pointer(
 			PERROR("[pselect] read");
 		}
 	}
+#endif
 }
 
 /*
-- 
2.37.3

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64
  2022-10-27  5:54 [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64 Alistair Francis via lttng-dev
@ 2022-12-13  5:09 ` Alistair Francis via lttng-dev
  2022-12-14 20:20   ` Jérémie Galarneau via lttng-dev
  0 siblings, 1 reply; 4+ messages in thread
From: Alistair Francis via lttng-dev @ 2022-12-13  5:09 UTC (permalink / raw)
  To: Alistair Francis; +Cc: lttng-dev

On Thu, Oct 27, 2022 at 3:54 PM Alistair Francis
<alistair.francis@opensource.wdc.com> wrote:
>
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Add support for the  64-bit time_t syscalls SYS_ppoll_time64
> and SYS_pselect6_time64.
>
> These are the syscalls that exist 32-bit platforms since the 5.1 kernel.
> 32-bit platforms with a 64-bit time_t only have these and don't have the
> original syscalls (such as 32-bit RISC-V).
>
> Fixes: https://github.com/lttng/lttng-tools/pull/162
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Ping!

Alistair

> ---
> To keep the test_cases[] array clean I have implemented the functions
> for all builds, but the functions are a no-op if the syscall is missing.
>
> v2:
>  - Split out a seperate _time64 test
>
>  tests/regression/kernel/select_poll_epoll.cpp | 184 ++++++++++++++++++
>  1 file changed, 184 insertions(+)
>
> diff --git a/tests/regression/kernel/select_poll_epoll.cpp b/tests/regression/kernel/select_poll_epoll.cpp
> index c0b688217..dfaab52c8 100644
> --- a/tests/regression/kernel/select_poll_epoll.cpp
> +++ b/tests/regression/kernel/select_poll_epoll.cpp
> @@ -5,6 +5,7 @@
>   *
>   */
>
> +#include <errno.h>
>  #include <fcntl.h>
>  #include <limits.h>
>  #include <poll.h>
> @@ -48,10 +49,14 @@ int lttng_opt_quiet, lttng_opt_verbose, lttng_opt_mi;
>
>  static void run_working_cases(FILE *validation_output_file);
>  static void pselect_invalid_fd(FILE *validation_output_file);
> +static void pselect_time64_invalid_fd(FILE *validation_output_file);
>  static void test_ppoll_big(FILE *validation_output_file);
>  static void ppoll_fds_buffer_overflow(FILE *validation_output_file);
> +static void ppoll_time64_fds_buffer_overflow(FILE *validation_output_file);
>  static void pselect_invalid_pointer(FILE *validation_output_file);
> +static void pselect_time64_invalid_pointer(FILE *validation_output_file);
>  static void ppoll_fds_ulong_max(FILE *validation_output_file);
> +static void ppoll_time64_fds_ulong_max(FILE *validation_output_file);
>  static void epoll_pwait_invalid_pointer(FILE *validation_output_file);
>  static void epoll_pwait_int_max(FILE *validation_output_file);
>  static void ppoll_concurrent_write(FILE *validation_output_file);
> @@ -69,10 +74,14 @@ const struct test_case {
>         { .run = run_working_cases, .produces_validation_info = true, .timeout = -1 },
>         { .run = run_working_cases, .produces_validation_info = true, .timeout = 1 },
>         { .run = pselect_invalid_fd, .produces_validation_info = false, .timeout = 0 },
> +       { .run = pselect_time64_invalid_fd, .produces_validation_info = false, .timeout = 0 },
>         { .run = test_ppoll_big, .produces_validation_info = false, .timeout = 0 },
>         { .run = ppoll_fds_buffer_overflow, .produces_validation_info = false, .timeout = 0 },
> +       { .run = ppoll_time64_fds_buffer_overflow, .produces_validation_info = false, .timeout = 0 },
>         { .run = pselect_invalid_pointer, .produces_validation_info = false, .timeout = 0 },
> +       { .run = pselect_time64_invalid_pointer, .produces_validation_info = false, .timeout = 0 },
>         { .run = ppoll_fds_ulong_max, .produces_validation_info = false, .timeout = 0 },
> +       { .run = ppoll_time64_fds_ulong_max, .produces_validation_info = false, .timeout = 0 },
>         { .run = epoll_pwait_invalid_pointer, .produces_validation_info = true, .timeout = 0 },
>         { .run = epoll_pwait_int_max, .produces_validation_info = true, .timeout = 0 },
>         { .run = ppoll_concurrent_write, .produces_validation_info = false, .timeout = 0 },
> @@ -440,6 +449,44 @@ end:
>         return;
>  }
>
> +/*
> + * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
> + * segfault (eventually with a "*** stack smashing detected ***" message).
> + * The event should contain an array of 100 FDs filled with garbage.
> + */
> +static
> +void ppoll_time64_fds_buffer_overflow(
> +               FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_ppoll_time64
> +       struct pollfd ufds[NB_FD];
> +       char buf[BUF_SIZE];
> +       int ret;
> +
> +       ufds[0].fd = wait_fd;
> +       ufds[0].events = POLLIN|POLLPRI;
> +
> +       /*
> +        * As there is no timeout value, we don't convert to/from
> +        * 64/32-bit time_t.
> +        */
> +       ret = syscall(SYS_ppoll_time64, ufds, 100, NULL, NULL);
> +       /*
> +        * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret < 0) {
> +               PERROR("ppoll_time64");
> +       } else if (ret > 0) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[ppoll_time64] read");
> +               }
> +       }
> +#endif
> +}
> +
>  /*
>   * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
>   * segfault (eventually with a "*** stack smashing detected ***" message).
> @@ -449,6 +496,7 @@ static
>  void ppoll_fds_buffer_overflow(
>                 FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_ppoll
>         struct pollfd ufds[NB_FD];
>         char buf[BUF_SIZE];
>         int ret;
> @@ -466,6 +514,46 @@ void ppoll_fds_buffer_overflow(
>                         PERROR("[ppoll] read");
>                 }
>         }
> +#endif
> +}
> +
> +/*
> + * Ask for ULONG_MAX FDs in a buffer for allocated for only 1 FD, should
> + * cleanly fail with a "Invalid argument".
> + * The event should contain an empty array of FDs and overflow = 1.
> + */
> +static
> +void ppoll_time64_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_ppoll_time64
> +       struct pollfd ufds[NB_FD];
> +       char buf[BUF_SIZE];
> +       int ret;
> +
> +       ufds[0].fd = wait_fd;
> +       ufds[0].events = POLLIN|POLLPRI;
> +
> +       /*
> +        * As there is no timeout value, we don't convert to/from
> +        * 64/32-bit time_t.
> +        */
> +       ret = syscall(SYS_ppoll_time64, ufds, ULONG_MAX, NULL, NULL);
> +       /*
> +        * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret < 0 && errno != ENOSYS) {
> +               /* Expected error. */
> +       } else if (errno == ENOSYS) {
> +               PERROR("[ppoll_time64] missing syscall");
> +       } else if (ret > 0) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[ppoll_time64] read");
> +               }
> +       }
> +#endif
>  }
>
>  /*
> @@ -476,6 +564,7 @@ void ppoll_fds_buffer_overflow(
>  static
>  void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_ppoll
>         struct pollfd ufds[NB_FD];
>         char buf[BUF_SIZE];
>         int ret;
> @@ -492,6 +581,59 @@ void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
>                         PERROR("[ppoll] read");
>                 }
>         }
> +#endif
> +}
> +
> +/*
> + * Pass an invalid file descriptor to pselect6(). The syscall should return
> + * -EBADF. The recorded event should contain a "ret = -EBADF (-9)".
> + */
> +static
> +void pselect_time64_invalid_fd(FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_pselect6_time64
> +       fd_set rfds;
> +       int ret;
> +       int fd;
> +       char buf[BUF_SIZE];
> +
> +       /*
> +        * Open a file, close it and use the closed FD in the pselect6 call.
> +        */
> +       fd = open("/dev/null", O_RDONLY);
> +       if (fd == -1) {
> +               PERROR("open");
> +               goto error;
> +       }
> +
> +       ret = close(fd);
> +       if (ret == -1) {
> +               PERROR("close");
> +               goto error;
> +       }
> +
> +       FD_ZERO(&rfds);
> +       FD_SET(fd, &rfds);
> +
> +       ret = syscall(SYS_pselect6_time64, fd + 1, &rfds, NULL, NULL, NULL, NULL);
> +       /*
> +        * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret == -1 && errno != ENOSYS) {
> +               /* Expected error. */
> +       } else if (errno == ENOSYS) {
> +               PERROR("[pselect_time64] missing syscall");
> +       } else if (ret) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[pselect_time64] read");
> +               }
> +       }
> +error:
> +       return;
> +#endif
>  }
>
>  /*
> @@ -501,6 +643,7 @@ void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
>  static
>  void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_pselect6
>         fd_set rfds;
>         int ret;
>         int fd;
> @@ -525,6 +668,7 @@ void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
>         FD_SET(fd, &rfds);
>
>         ret = syscall(SYS_pselect6, fd + 1, &rfds, NULL, NULL, NULL, NULL);
> +
>         if (ret == -1) {
>                 /* Expected error. */
>         } else if (ret) {
> @@ -535,6 +679,44 @@ void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
>         }
>  error:
>         return;
> +#endif
> +}
> +
> +/*
> + * Invalid pointer as writefds, should output a ppoll event
> + * with 0 FDs.
> + */
> +static
> +void pselect_time64_invalid_pointer(
> +               FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_pselect6_time64
> +       fd_set rfds;
> +       int ret;
> +       char buf[BUF_SIZE];
> +       void *invalid = (void *) 0x42;
> +
> +       FD_ZERO(&rfds);
> +       FD_SET(wait_fd, &rfds);
> +
> +       ret = syscall(SYS_pselect6_time64, 1, &rfds, (fd_set *) invalid, NULL, NULL,
> +                       NULL);
> +       /*
> +        * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret == -1 && errno != ENOSYS) {
> +               /* Expected error. */
> +       } else if (errno == ENOSYS) {
> +               PERROR("[pselect_time64] missing syscall");
> +       } else if (ret) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[pselect_time64] read");
> +               }
> +       }
> +#endif
>  }
>
>  /*
> @@ -545,6 +727,7 @@ static
>  void pselect_invalid_pointer(
>                 FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_pselect6
>         fd_set rfds;
>         int ret;
>         char buf[BUF_SIZE];
> @@ -563,6 +746,7 @@ void pselect_invalid_pointer(
>                         PERROR("[pselect] read");
>                 }
>         }
> +#endif
>  }
>
>  /*
> --
> 2.37.3
>
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64
  2022-12-13  5:09 ` Alistair Francis via lttng-dev
@ 2022-12-14 20:20   ` Jérémie Galarneau via lttng-dev
  2023-01-31  8:56     ` Alistair Francis via lttng-dev
  0 siblings, 1 reply; 4+ messages in thread
From: Jérémie Galarneau via lttng-dev @ 2022-12-14 20:20 UTC (permalink / raw)
  To: Alistair Francis, Alistair Francis; +Cc: lttng-dev


[-- Attachment #1.1: Type: text/plain, Size: 12244 bytes --]

Hi Alistair,

The patch you submitted doesn't pass on x86 and x86-64.

I have written an alternative patch that works on the 32/64 variants of ARM and x86. I could only verify that it builds on RISC-V 64.

Are you able to compile-test it on RISC-V 32?

https://review.lttng.org/c/lttng-tools/+/8907

Thanks,
Jérémie


--
Jérémie Galarneau
EfficiOS Inc.
https://www.efficios.com
________________________________
From: lttng-dev <lttng-dev-bounces@lists.lttng.org> on behalf of Alistair Francis via lttng-dev <lttng-dev@lists.lttng.org>
Sent: December 13, 2022 00:09
To: Alistair Francis <alistair.francis@opensource.wdc.com>
Cc: lttng-dev@lists.lttng.org <lttng-dev@lists.lttng.org>
Subject: Re: [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64

On Thu, Oct 27, 2022 at 3:54 PM Alistair Francis
<alistair.francis@opensource.wdc.com> wrote:
>
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Add support for the  64-bit time_t syscalls SYS_ppoll_time64
> and SYS_pselect6_time64.
>
> These are the syscalls that exist 32-bit platforms since the 5.1 kernel.
> 32-bit platforms with a 64-bit time_t only have these and don't have the
> original syscalls (such as 32-bit RISC-V).
>
> Fixes: https://github.com/lttng/lttng-tools/pull/162
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Ping!

Alistair

> ---
> To keep the test_cases[] array clean I have implemented the functions
> for all builds, but the functions are a no-op if the syscall is missing.
>
> v2:
>  - Split out a seperate _time64 test
>
>  tests/regression/kernel/select_poll_epoll.cpp | 184 ++++++++++++++++++
>  1 file changed, 184 insertions(+)
>
> diff --git a/tests/regression/kernel/select_poll_epoll.cpp b/tests/regression/kernel/select_poll_epoll.cpp
> index c0b688217..dfaab52c8 100644
> --- a/tests/regression/kernel/select_poll_epoll.cpp
> +++ b/tests/regression/kernel/select_poll_epoll.cpp
> @@ -5,6 +5,7 @@
>   *
>   */
>
> +#include <errno.h>
>  #include <fcntl.h>
>  #include <limits.h>
>  #include <poll.h>
> @@ -48,10 +49,14 @@ int lttng_opt_quiet, lttng_opt_verbose, lttng_opt_mi;
>
>  static void run_working_cases(FILE *validation_output_file);
>  static void pselect_invalid_fd(FILE *validation_output_file);
> +static void pselect_time64_invalid_fd(FILE *validation_output_file);
>  static void test_ppoll_big(FILE *validation_output_file);
>  static void ppoll_fds_buffer_overflow(FILE *validation_output_file);
> +static void ppoll_time64_fds_buffer_overflow(FILE *validation_output_file);
>  static void pselect_invalid_pointer(FILE *validation_output_file);
> +static void pselect_time64_invalid_pointer(FILE *validation_output_file);
>  static void ppoll_fds_ulong_max(FILE *validation_output_file);
> +static void ppoll_time64_fds_ulong_max(FILE *validation_output_file);
>  static void epoll_pwait_invalid_pointer(FILE *validation_output_file);
>  static void epoll_pwait_int_max(FILE *validation_output_file);
>  static void ppoll_concurrent_write(FILE *validation_output_file);
> @@ -69,10 +74,14 @@ const struct test_case {
>         { .run = run_working_cases, .produces_validation_info = true, .timeout = -1 },
>         { .run = run_working_cases, .produces_validation_info = true, .timeout = 1 },
>         { .run = pselect_invalid_fd, .produces_validation_info = false, .timeout = 0 },
> +       { .run = pselect_time64_invalid_fd, .produces_validation_info = false, .timeout = 0 },
>         { .run = test_ppoll_big, .produces_validation_info = false, .timeout = 0 },
>         { .run = ppoll_fds_buffer_overflow, .produces_validation_info = false, .timeout = 0 },
> +       { .run = ppoll_time64_fds_buffer_overflow, .produces_validation_info = false, .timeout = 0 },
>         { .run = pselect_invalid_pointer, .produces_validation_info = false, .timeout = 0 },
> +       { .run = pselect_time64_invalid_pointer, .produces_validation_info = false, .timeout = 0 },
>         { .run = ppoll_fds_ulong_max, .produces_validation_info = false, .timeout = 0 },
> +       { .run = ppoll_time64_fds_ulong_max, .produces_validation_info = false, .timeout = 0 },
>         { .run = epoll_pwait_invalid_pointer, .produces_validation_info = true, .timeout = 0 },
>         { .run = epoll_pwait_int_max, .produces_validation_info = true, .timeout = 0 },
>         { .run = ppoll_concurrent_write, .produces_validation_info = false, .timeout = 0 },
> @@ -440,6 +449,44 @@ end:
>         return;
>  }
>
> +/*
> + * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
> + * segfault (eventually with a "*** stack smashing detected ***" message).
> + * The event should contain an array of 100 FDs filled with garbage.
> + */
> +static
> +void ppoll_time64_fds_buffer_overflow(
> +               FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_ppoll_time64
> +       struct pollfd ufds[NB_FD];
> +       char buf[BUF_SIZE];
> +       int ret;
> +
> +       ufds[0].fd = wait_fd;
> +       ufds[0].events = POLLIN|POLLPRI;
> +
> +       /*
> +        * As there is no timeout value, we don't convert to/from
> +        * 64/32-bit time_t.
> +        */
> +       ret = syscall(SYS_ppoll_time64, ufds, 100, NULL, NULL);
> +       /*
> +        * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret < 0) {
> +               PERROR("ppoll_time64");
> +       } else if (ret > 0) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[ppoll_time64] read");
> +               }
> +       }
> +#endif
> +}
> +
>  /*
>   * Ask for 100 FDs in a buffer for allocated for only 1 FD, should
>   * segfault (eventually with a "*** stack smashing detected ***" message).
> @@ -449,6 +496,7 @@ static
>  void ppoll_fds_buffer_overflow(
>                 FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_ppoll
>         struct pollfd ufds[NB_FD];
>         char buf[BUF_SIZE];
>         int ret;
> @@ -466,6 +514,46 @@ void ppoll_fds_buffer_overflow(
>                         PERROR("[ppoll] read");
>                 }
>         }
> +#endif
> +}
> +
> +/*
> + * Ask for ULONG_MAX FDs in a buffer for allocated for only 1 FD, should
> + * cleanly fail with a "Invalid argument".
> + * The event should contain an empty array of FDs and overflow = 1.
> + */
> +static
> +void ppoll_time64_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_ppoll_time64
> +       struct pollfd ufds[NB_FD];
> +       char buf[BUF_SIZE];
> +       int ret;
> +
> +       ufds[0].fd = wait_fd;
> +       ufds[0].events = POLLIN|POLLPRI;
> +
> +       /*
> +        * As there is no timeout value, we don't convert to/from
> +        * 64/32-bit time_t.
> +        */
> +       ret = syscall(SYS_ppoll_time64, ufds, ULONG_MAX, NULL, NULL);
> +       /*
> +        * There is no fallback to SYS_ppoll, we expect SYS_ppoll_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret < 0 && errno != ENOSYS) {
> +               /* Expected error. */
> +       } else if (errno == ENOSYS) {
> +               PERROR("[ppoll_time64] missing syscall");
> +       } else if (ret > 0) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[ppoll_time64] read");
> +               }
> +       }
> +#endif
>  }
>
>  /*
> @@ -476,6 +564,7 @@ void ppoll_fds_buffer_overflow(
>  static
>  void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_ppoll
>         struct pollfd ufds[NB_FD];
>         char buf[BUF_SIZE];
>         int ret;
> @@ -492,6 +581,59 @@ void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
>                         PERROR("[ppoll] read");
>                 }
>         }
> +#endif
> +}
> +
> +/*
> + * Pass an invalid file descriptor to pselect6(). The syscall should return
> + * -EBADF. The recorded event should contain a "ret = -EBADF (-9)".
> + */
> +static
> +void pselect_time64_invalid_fd(FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_pselect6_time64
> +       fd_set rfds;
> +       int ret;
> +       int fd;
> +       char buf[BUF_SIZE];
> +
> +       /*
> +        * Open a file, close it and use the closed FD in the pselect6 call.
> +        */
> +       fd = open("/dev/null", O_RDONLY);
> +       if (fd == -1) {
> +               PERROR("open");
> +               goto error;
> +       }
> +
> +       ret = close(fd);
> +       if (ret == -1) {
> +               PERROR("close");
> +               goto error;
> +       }
> +
> +       FD_ZERO(&rfds);
> +       FD_SET(fd, &rfds);
> +
> +       ret = syscall(SYS_pselect6_time64, fd + 1, &rfds, NULL, NULL, NULL, NULL);
> +       /*
> +        * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret == -1 && errno != ENOSYS) {
> +               /* Expected error. */
> +       } else if (errno == ENOSYS) {
> +               PERROR("[pselect_time64] missing syscall");
> +       } else if (ret) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[pselect_time64] read");
> +               }
> +       }
> +error:
> +       return;
> +#endif
>  }
>
>  /*
> @@ -501,6 +643,7 @@ void ppoll_fds_ulong_max(FILE *validation_output_file __attribute__((unused)))
>  static
>  void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_pselect6
>         fd_set rfds;
>         int ret;
>         int fd;
> @@ -525,6 +668,7 @@ void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
>         FD_SET(fd, &rfds);
>
>         ret = syscall(SYS_pselect6, fd + 1, &rfds, NULL, NULL, NULL, NULL);
> +
>         if (ret == -1) {
>                 /* Expected error. */
>         } else if (ret) {
> @@ -535,6 +679,44 @@ void pselect_invalid_fd(FILE *validation_output_file __attribute__((unused)))
>         }
>  error:
>         return;
> +#endif
> +}
> +
> +/*
> + * Invalid pointer as writefds, should output a ppoll event
> + * with 0 FDs.
> + */
> +static
> +void pselect_time64_invalid_pointer(
> +               FILE *validation_output_file __attribute__((unused)))
> +{
> +#ifdef SYS_pselect6_time64
> +       fd_set rfds;
> +       int ret;
> +       char buf[BUF_SIZE];
> +       void *invalid = (void *) 0x42;
> +
> +       FD_ZERO(&rfds);
> +       FD_SET(wait_fd, &rfds);
> +
> +       ret = syscall(SYS_pselect6_time64, 1, &rfds, (fd_set *) invalid, NULL, NULL,
> +                       NULL);
> +       /*
> +        * There is no fallback to SYS_pselect6, we expect SYS_pselect6_time64
> +        * to work and if it doesn't we fail.
> +        */
> +
> +       if (ret == -1 && errno != ENOSYS) {
> +               /* Expected error. */
> +       } else if (errno == ENOSYS) {
> +               PERROR("[pselect_time64] missing syscall");
> +       } else if (ret) {
> +               ret = read(wait_fd, buf, BUF_SIZE);
> +               if (ret < 0) {
> +                       PERROR("[pselect_time64] read");
> +               }
> +       }
> +#endif
>  }
>
>  /*
> @@ -545,6 +727,7 @@ static
>  void pselect_invalid_pointer(
>                 FILE *validation_output_file __attribute__((unused)))
>  {
> +#ifdef SYS_pselect6
>         fd_set rfds;
>         int ret;
>         char buf[BUF_SIZE];
> @@ -563,6 +746,7 @@ void pselect_invalid_pointer(
>                         PERROR("[pselect] read");
>                 }
>         }
> +#endif
>  }
>
>  /*
> --
> 2.37.3
>
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

[-- Attachment #1.2: Type: text/html, Size: 26045 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64
  2022-12-14 20:20   ` Jérémie Galarneau via lttng-dev
@ 2023-01-31  8:56     ` Alistair Francis via lttng-dev
  0 siblings, 0 replies; 4+ messages in thread
From: Alistair Francis via lttng-dev @ 2023-01-31  8:56 UTC (permalink / raw)
  To: Jérémie Galarneau; +Cc: Alistair Francis, lttng-dev

On Thu, Dec 15, 2022 at 6:20 AM Jérémie Galarneau <jgalar@efficios.com> wrote:
>
> Hi Alistair,
>
> The patch you submitted doesn't pass on x86 and x86-64.

Are you able to provide the failures? It should just be a simple fix

>
> I have written an alternative patch that works on the 32/64 variants of ARM and x86. I could only verify that it builds on RISC-V 64.
>
> Are you able to compile-test it on RISC-V 32?
>
> https://review.lttng.org/c/lttng-tools/+/8907

Thanks!

I am currently having some trouble building it. The requirement on
liburcu >= 0.14 is proving difficult to meet and the patch conflicts
with earlier versions of lttng.

I had a look at the patch though.

It seems like you still call SYS_ppoll, which won't work on 64-bit
time_t 32-bit systems.

Changes like this:

+       #ifdef sys_pselect6_time64
+       test_pselect_time64();
+       #else
       test_pselect();
+       #endif /* sys_pselect6_time64 */

will mean that test_pselect() isn't called on 32-bit platforms with a
5.4+ kernel. Which I thought is what you wanted to avoid.

Alistair
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-31 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27  5:54 [lttng-dev] [PATCH v2] Tests: select_poll_epoll: Add support for _time64 Alistair Francis via lttng-dev
2022-12-13  5:09 ` Alistair Francis via lttng-dev
2022-12-14 20:20   ` Jérémie Galarneau via lttng-dev
2023-01-31  8:56     ` Alistair Francis via lttng-dev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).