Skip to contentSkip to conversation

selftests/empty_mntns: fix header conflicts and remove TOOLS_INCLUDES

PATCH In review Disha Goel 2 participants 4 messages Oct 1 – Oct 30

Subsystems (2)
lore
Share & tools
lore

Disha Goel

author
#0 lore raw

PATCH 1/2 selftests/empty_mntns: fix header conflicts and remove TOOLS_INCLUDES

Including <linux/mount.h> alongside <sys/mount.h> in empty_mntns test files leads to compilation errors with glibc due to conflicting enum definitions of MS_RDONLY and other mount flags.

Additionally, passing $(TOOLS_INCLUDES) (-isystem tools/include/uapi) causes tools/include/uapi/linux/types.h to be included, forcing int-ll64.h definitions on architectures like PowerPC (ppc64le) that use int-l64.h, resulting in type collisions with system headers.

Fix this by:
- Dropping <linux/mount.h> from the test sources in favor of <sys/mount.h> (with <linux/stat.h> included after system headers).
- Removing $(TOOLS_INCLUDES) from the Makefile since standard UAPI headers are already supplied via $(KHDR_INCLUDES).

Fixes 32f54f2bbccf ("selftests/filesystems: add tests for empty mount namespaces")
Fixes 5b8ffd63fbd9 ("selftests/filesystems: add clone3 tests for empty mount namespaces")
---
 tools/testing/selftests/filesystems/empty_mntns/Makefile       | 2 +-
 .../filesystems/empty_mntns/clone3_empty_mntns_test.c          | 3 +--
 .../selftests/filesystems/empty_mntns/empty_mntns_test.c       | 3 +--
 .../selftests/filesystems/empty_mntns/overmount_chroot_test.c  | 3 +--
 4 files changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/filesystems/empty_mntns/Makefile +1 -1
index 22e3fb915e81..8d2cb46668fc 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
+CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
 LDLIBS += -lcap
 
 TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test
tools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c +1 -2
index 6370086f886d..de0cbd1a5ee0 100644
@@ -15,14 +15,13 @@
 
 #define _GNU_SOURCE
 #include <fcntl.h>
-#include <linux/mount.h>
-#include <linux/stat.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <linux/stat.h>
 
 #include "../utils.h"
 #include "../wrappers.h"
tools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c +1 -2
index 43e296b97d84..a6a90d0b6ff9 100644
@@ -7,8 +7,6 @@
 
 #define _GNU_SOURCE
 #include <fcntl.h>
-#include <linux/mount.h>
-#include <linux/stat.h>
 #include <sched.h>
 #include <stdio.h>
 #include <string.h>
@@ -17,6 +15,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <linux/stat.h>
 
 #include "../utils.h"
 #include "../wrappers.h"
tools/testing/selftests/filesystems/empty_mntns/overmount_chroot_test.c +1 -2
index 6e21c58258c3..574c03311245 100644
@@ -18,8 +18,6 @@
 
 #define _GNU_SOURCE
 #include <fcntl.h>
-#include <linux/mount.h>
-#include <linux/stat.h>
 #include <sched.h>
 #include <stdio.h>
 #include <string.h>
@@ -29,6 +27,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <linux/stat.h>
 
 #include "../utils.h"
 #include "empty_mntns.h"
Signature · 1 line
2.45.1
author
#1 lore raw

PATCH 2/2 selftests/empty_mntns: use unused bit in unknown_flags_rejected test

The unknown_flags_rejected test uses 0x800000000ULL (1ULL << 35) to test that clone3() rejects unknown 64-bit flags with -EINVAL.

However, bit 35 has been allocated to CLONE_NNP, causing clone3() to succeed and the assertion expecting failure to fail.

Switch to (1ULL << 63) which is an unused high bit so the test consistently expects -EINVAL.

Fixes 5b8ffd63fbd9 ("selftests/filesystems: add clone3 tests for empty mount namespaces")
---
 .../selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c +1 -1
index de0cbd1a5ee0..b271fed3ae70 100644
@@ -868,7 +868,7 @@ TEST(unknown_flags_rejected)
 
 	if (pid == 0) {
 		struct __clone_args args = {
-			.flags		= 0x800000000ULL,
+			.flags		= (1ULL << 63),
 			.exit_signal	= SIGCHLD,
 		};
 		pid_t ret;
Signature · 1 line
2.45.1
author
#2 lore raw
In reply to Disha Goel

Hi Christian,

Gentle ping on this series. Could you please review it, and if it looks fine, pick it up?

Quoted 99 lines · Disha Goel

Including <linux/mount.h> alongside <sys/mount.h> in empty_mntns test files leads to compilation errors with glibc due to conflicting enum definitions of MS_RDONLY and other mount flags.

Additionally, passing $(TOOLS_INCLUDES) (-isystem tools/include/uapi) causes tools/include/uapi/linux/types.h to be included, forcing int-ll64.h definitions on architectures like PowerPC (ppc64le) that use int-l64.h, resulting in type collisions with system headers.

Fix this by:
- Dropping <linux/mount.h> from the test sources in favor of <sys/mount.h> (with <linux/stat.h> included after system headers).
- Removing $(TOOLS_INCLUDES) from the Makefile since standard UAPI headers are already supplied via $(KHDR_INCLUDES).

Fixes 32f54f2bbccf ("selftests/filesystems: add tests for empty mount namespaces")
Fixes 5b8ffd63fbd9 ("selftests/filesystems: add clone3 tests for empty mount namespaces")
---
  tools/testing/selftests/filesystems/empty_mntns/Makefile       | 2 +-
  .../filesystems/empty_mntns/clone3_empty_mntns_test.c          | 3 +--
  .../selftests/filesystems/empty_mntns/empty_mntns_test.c       | 3 +--
  .../selftests/filesystems/empty_mntns/overmount_chroot_test.c  | 3 +--
  4 files changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/filesystems/empty_mntns/Makefile +1 -1
index 22e3fb915e81..8d2cb46668fc 100644
@@ -1,6 +1,6 @@
  # SPDX-License-Identifier: GPL-2.0-or-later
 
-CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
+CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
  LDLIBS += -lcap
 
  TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test
tools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c +1 -2
index 6370086f886d..de0cbd1a5ee0 100644
@@ -15,14 +15,13 @@
 
  #define _GNU_SOURCE
  #include <fcntl.h>
-#include <linux/mount.h>
-#include <linux/stat.h>
  #include <stdio.h>
  #include <string.h>
  #include <sys/mount.h>
  #include <sys/stat.h>
  #include <sys/types.h>
  #include <unistd.h>
+#include <linux/stat.h>
 
  #include "../utils.h"
  #include "../wrappers.h"
tools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c +1 -2
index 43e296b97d84..a6a90d0b6ff9 100644
@@ -7,8 +7,6 @@
 
  #define _GNU_SOURCE
  #include <fcntl.h>
-#include <linux/mount.h>
-#include <linux/stat.h>
  #include <sched.h>
  #include <stdio.h>
  #include <string.h>
@@ -17,6 +15,7 @@
  #include <sys/types.h>
  #include <sys/wait.h>
  #include <unistd.h>
+#include <linux/stat.h>
 
  #include "../utils.h"
  #include "../wrappers.h"
tools/testing/selftests/filesystems/empty_mntns/overmount_chroot_test.c +1 -2
index 6e21c58258c3..574c03311245 100644
@@ -18,8 +18,6 @@
 
  #define _GNU_SOURCE
  #include <fcntl.h>
-#include <linux/mount.h>
-#include <linux/stat.h>
  #include <sched.h>
  #include <stdio.h>
  #include <string.h>
@@ -29,6 +27,7 @@
  #include <sys/types.h>
  #include <sys/wait.h>
  #include <unistd.h>
+#include <linux/stat.h>
 
  #include "../utils.h"
  #include "empty_mntns.h"
Signature · 2 lines
Regards,
Disha
#3 lore raw
In reply to Disha Goel
Quoted 3 lines · Disha Goel

Including <linux/mount.h> alongside <sys/mount.h> in empty_mntns test files leads to compilation errors with glibc due to conflicting enum definitions of MS_RDONLY and other mount flags.

That part is fine. Note that ../wrappers.h still pulls in <linux/mount.h>, so what actually fixes this is that <sys/mount.h> now comes first.

Quoted 7 lines

Additionally, passing $(TOOLS_INCLUDES) (-isystem tools/include/uapi) causes tools/include/uapi/linux/types.h to be included, forcing int-ll64.h definitions on architectures like PowerPC (ppc64le) that use int-l64.h, resulting in type collisions with system headers.

- Removing $(TOOLS_INCLUDES) from the Makefile since standard UAPI headers are already supplied via $(KHDR_INCLUDES).

No, please drop this hunk. $(TOOLS_INCLUDES) is there so the tests build without a headers_install and filesystems/statmount, pidfd and namespaces use it the same way. The int-ll64.h vs int-l64.h clash you hit is in tools/include/uapi/linux/types.h and only shows up when the kernel headers aren't installed. Fix it there, not by dropping the include path in one directory.