Skip to content

Commit 16f7432

Browse files
committed
Merge tag 'linux-kselftest-fixes-5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest fixes from Shuah Khan: "Build and run-time fixes to pidfd, clone3, and ir tests" * tag 'linux-kselftest-fixes-5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/ir: fix build with ancient kernel headers selftests: fixup build warnings in pidfd / clone3 tests pidfd: fix test failure due to stack overflow on some arches
2 parents ff00854 + 183f80f commit 16f7432

File tree

6 files changed

+43
-15
lines changed

6 files changed

+43
-15
lines changed

tools/testing/selftests/clone3/clone3.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ static void test_clone3(uint64_t flags, size_t size, int expected,
126126

127127
int main(int argc, char *argv[])
128128
{
129-
pid_t pid;
130-
131129
uid_t uid = getuid();
132130

133131
ksft_print_header();

tools/testing/selftests/ir/ir_loopback.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#define SYSFS_PATH_MAX 256
3030
#define DNAME_PATH_MAX 256
3131

32+
/*
33+
* Support ancient lirc.h which does not have these values. Can be removed
34+
* once RHEL 8 is no longer a relevant testing platform.
35+
*/
36+
#if RC_PROTO_MAX < 26
37+
#define RC_PROTO_RCMM12 24
38+
#define RC_PROTO_RCMM24 25
39+
#define RC_PROTO_RCMM32 26
40+
#endif
41+
3242
static const struct {
3343
enum rc_proto proto;
3444
const char *name;

tools/testing/selftests/pidfd/pidfd.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#define PIDFD_SKIP 3
6969
#define PIDFD_XFAIL 4
7070

71-
int wait_for_pid(pid_t pid)
71+
static inline int wait_for_pid(pid_t pid)
7272
{
7373
int status, ret;
7474

@@ -78,13 +78,20 @@ int wait_for_pid(pid_t pid)
7878
if (errno == EINTR)
7979
goto again;
8080

81+
ksft_print_msg("waitpid returned -1, errno=%d\n", errno);
8182
return -1;
8283
}
8384

84-
if (!WIFEXITED(status))
85+
if (!WIFEXITED(status)) {
86+
ksft_print_msg(
87+
"waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n",
88+
WIFSIGNALED(status), WTERMSIG(status));
8589
return -1;
90+
}
8691

87-
return WEXITSTATUS(status);
92+
ret = WEXITSTATUS(status);
93+
ksft_print_msg("waitpid WEXITSTATUS=%d\n", ret);
94+
return ret;
8895
}
8996

9097
static inline int sys_pidfd_open(pid_t pid, unsigned int flags)

tools/testing/selftests/pidfd/pidfd_fdinfo_test.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string.h>
1313
#include <syscall.h>
1414
#include <sys/wait.h>
15+
#include <sys/mman.h>
1516

1617
#include "pidfd.h"
1718
#include "../kselftest.h"
@@ -80,7 +81,10 @@ static inline int error_check(struct error *err, const char *test_name)
8081
return err->code;
8182
}
8283

84+
#define CHILD_STACK_SIZE 8192
85+
8386
struct child {
87+
char *stack;
8488
pid_t pid;
8589
int fd;
8690
};
@@ -89,17 +93,22 @@ static struct child clone_newns(int (*fn)(void *), void *args,
8993
struct error *err)
9094
{
9195
static int flags = CLONE_PIDFD | CLONE_NEWPID | CLONE_NEWNS | SIGCHLD;
92-
size_t stack_size = 1024;
93-
char *stack[1024] = { 0 };
9496
struct child ret;
9597

9698
if (!(flags & CLONE_NEWUSER) && geteuid() != 0)
9799
flags |= CLONE_NEWUSER;
98100

101+
ret.stack = mmap(NULL, CHILD_STACK_SIZE, PROT_READ | PROT_WRITE,
102+
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
103+
if (ret.stack == MAP_FAILED) {
104+
error_set(err, -1, "mmap of stack failed (errno %d)", errno);
105+
return ret;
106+
}
107+
99108
#ifdef __ia64__
100-
ret.pid = __clone2(fn, stack, stack_size, flags, args, &ret.fd);
109+
ret.pid = __clone2(fn, ret.stack, CHILD_STACK_SIZE, flags, args, &ret.fd);
101110
#else
102-
ret.pid = clone(fn, stack + stack_size, flags, args, &ret.fd);
111+
ret.pid = clone(fn, ret.stack + CHILD_STACK_SIZE, flags, args, &ret.fd);
103112
#endif
104113

105114
if (ret.pid < 0) {
@@ -129,6 +138,11 @@ static inline int child_join(struct child *child, struct error *err)
129138
else if (r > 0)
130139
error_set(err, r, "child %d reported: %d", child->pid, r);
131140

141+
if (munmap(child->stack, CHILD_STACK_SIZE)) {
142+
error_set(err, -1, "munmap of child stack failed (errno %d)", errno);
143+
r = -1;
144+
}
145+
132146
return r;
133147
}
134148

tools/testing/selftests/pidfd/pidfd_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ static void test_pidfd_poll_exec(int use_waitpid)
441441
{
442442
int pid, pidfd = 0;
443443
int status, ret;
444-
pthread_t t1;
445444
time_t prog_start = time(NULL);
446445
const char *test_name = "pidfd_poll check for premature notification on child thread exec";
447446

@@ -500,13 +499,14 @@ static int child_poll_leader_exit_test(void *args)
500499
*/
501500
*child_exit_secs = time(NULL);
502501
syscall(SYS_exit, 0);
502+
/* Never reached, but appeases compiler thinking we should return. */
503+
exit(0);
503504
}
504505

505506
static void test_pidfd_poll_leader_exit(int use_waitpid)
506507
{
507508
int pid, pidfd = 0;
508-
int status, ret;
509-
time_t prog_start = time(NULL);
509+
int status, ret = 0;
510510
const char *test_name = "pidfd_poll check for premature notification on non-empty"
511511
"group leader exit";
512512

tools/testing/selftests/pidfd/pidfd_wait.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ static int sys_waitid(int which, pid_t pid, siginfo_t *info, int options,
3939

4040
TEST(wait_simple)
4141
{
42-
int pidfd = -1, status = 0;
42+
int pidfd = -1;
4343
pid_t parent_tid = -1;
4444
struct clone_args args = {
4545
.parent_tid = ptr_to_u64(&parent_tid),
4646
.pidfd = ptr_to_u64(&pidfd),
4747
.flags = CLONE_PIDFD | CLONE_PARENT_SETTID,
4848
.exit_signal = SIGCHLD,
4949
};
50-
int ret;
5150
pid_t pid;
5251
siginfo_t info = {
5352
.si_signo = 0,
@@ -88,7 +87,7 @@ TEST(wait_simple)
8887

8988
TEST(wait_states)
9089
{
91-
int pidfd = -1, status = 0;
90+
int pidfd = -1;
9291
pid_t parent_tid = -1;
9392
struct clone_args args = {
9493
.parent_tid = ptr_to_u64(&parent_tid),

0 commit comments

Comments
 (0)