Skip to contentSkip to conversation

fcntl{34,36}: Fixes for Android arm64

PATCH Superseded Edward Liaw via ltp 3 participants 8 messages Apr 27, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fcntl{34,36}: Fixes for Android arm64

Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")

In Richard's commit I think that he had meant to write that the flock64 type (not fcntl64 type) had been removed from some libcs. I believe that was the reason why he added the my_flock64 type.

On Android arm64, this test was breaking for two reasons:

1. The my_flock64 type definition did not match the expected type when compiled for 64 bits.
2. The test was mixing fcntl and the flock64 struct when compiled for 32 bits.

Both seem to be ok on x86_64 but not on arm64. To fix it, I gated the compat function on TST_ABI64 instead of tst_kernel_bits.

Also, I'm not sure that the my_flock64 struct is needed with these patches. I think that l64 can just have the flock64 type.

Edward Liaw (2):
fcntl{34,36}: Only use fcntl64 with 32bit abi fcntl{34,36}: Use arch dependent types for my_flock64

 .../kernel/syscalls/fcntl/fcntl_common.h      | 24 ++++++++++++-------
 1 file changed, 15 insertions(+), 9 deletions(-)

--
2.40.1.495.gc816e09b53d-goog

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/2 fcntl{34, 36}: Only use fcntl64 with 32bit abi

Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")

On Android arm64, tst_kernel_bits is disregarding the abi, so compiling with the 32bit abi is calling the fcntl syscall instead of fcntl64. The fcntl syscall is not compatible with the flock64 struct being passed (this doesn't seem to be the case with x86_64, only with arm64).

This changes it to only use the fcntl64 compat syscall with the 32bit abi.

---
 testcases/kernel/syscalls/fcntl/fcntl_common.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl_common.h +9 -3
index 5c130a784..485a31367 100644
@@ -10,6 +10,11 @@
 #include "lapi/abisize.h"
 #include "lapi/fcntl.h"
 
+#if defined(TST_ABI64)
+#define FCNTL_COMPAT(fd, cmd, flock) \
+	SAFE_FCNTL(fd, cmd, flock)
+
+#else
 struct my_flock64 {
 	int16_t l_type;
 	int16_t l_whence;
@@ -43,8 +48,8 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 		.l_len = lck->l_len,
 		.l_pid = lck->l_pid,
 	};
-	const int sysno = tst_kernel_bits() > 32 ? __NR_fcntl : __NR_fcntl64;
-	const int ret = tst_syscall(sysno, fd, cmd, &l64);
+
+	const int ret = tst_syscall(__NR_fcntl64, fd, cmd, &l64);
 
 	lck->l_type = l64.l_type;
 	lck->l_whence = l64.l_whence;
@@ -57,7 +62,7 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 
 	tst_brk_(file, line, TBROK | TERRNO,
 		 "%s(%d, %s, { %d, %d, %"PRId64", %"PRId64", %d })",
-		 tst_kernel_bits() > 32 ? "fcntl" : "fcntl64",
+		 "fcntl64",
 		 fd,
 		 cmd_name,
 		 l64.l_type, l64.l_whence, l64.l_start, l64.l_len, l64.l_pid);
@@ -67,5 +72,6 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 
 #define FCNTL_COMPAT(fd, cmd, flock) \
 	fcntl_compat(__FILE__, __LINE__, #cmd, fd, cmd, flock)
+#endif
 
 #endif /* FCNTL_COMMON_H__ */
Signature · 5 lines
2.40.1.495.gc816e09b53d-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/2
#2 lore raw

Re: [LTP] [PATCH v1 1/2] fcntl{34, 36}: Only use fcntl64 with 32bit abi

Hi Edward,

Quoted 3 lines
Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")

On Android arm64, tst_kernel_bits is disregarding the abi, so compiling

What exactly do you mean by "disregarding the abi"? Why is aarch64 different?

Quoted 40 lines

with the 32bit abi is calling the fcntl syscall instead of fcntl64. The fcntl syscall is not compatible with the flock64 struct being passed (this doesn't seem to be the case with x86_64, only with arm64).

This changes it to only use the fcntl64 compat syscall with the 32bit abi.

---
 testcases/kernel/syscalls/fcntl/fcntl_common.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl_common.h +7 -2
index 5c130a784..485a31367 100644
@@ -10,6 +10,11 @@
 #include "lapi/abisize.h"
 #include "lapi/fcntl.h"
 
+#if defined(TST_ABI64)
+#define FCNTL_COMPAT(fd, cmd, flock) \
+	SAFE_FCNTL(fd, cmd, flock)
+
+#else
 struct my_flock64 {
 	int16_t l_type;
 	int16_t l_whence;
@@ -43,8 +48,8 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 		.l_len = lck->l_len,
 		.l_pid = lck->l_pid,
 	};
-	const int sysno = tst_kernel_bits() > 32 ? __NR_fcntl : __NR_fcntl64;
-	const int ret = tst_syscall(sysno, fd, cmd, &l64);
+
+	const int ret = tst_syscall(__NR_fcntl64, fd, cmd, &l64);
 
 	lck->l_type = l64.l_type;
 	lck->l_whence = l64.l_whence;

testcases/kernel/syscalls/fcntl/fcntl_common.h static inline int fcntl_compat(const char *file, const int line, const char *cmd · line 65

Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl_common.h +1 -1
@@ -57,7 +62,7 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 
 	tst_brk_(file, line, TBROK | TERRNO,
 		 "%s(%d, %s, { %d, %d, %"PRId64", %"PRId64", %d })",
-		 tst_kernel_bits() > 32 ? "fcntl" : "fcntl64",
+		 "fcntl64",

Once we removed tst_kernel_bits(), there is no need to pass "fcntl64" as %s, thus it should be:

		 "fcntl64(%d, %s, { %d, %d, %"PRId64", %"PRId64", %d })",
		 fd, cmd_name, l64.l_type, l64.l_whence, l64.l_start, l64.l_len,
		 l64.l_pid);

Otherwise LGTM.

Kind regards,
Petr

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl_common.h +1 -0
 		 fd,
 		 cmd_name,
 		 l64.l_type, l64.l_whence, l64.l_start, l64.l_len, l64.l_pid);
@@ -67,5 +72,6 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 
 #define FCNTL_COMPAT(fd, cmd, flock) \
 	fcntl_compat(__FILE__, __LINE__, #cmd, fd, cmd, flock)
+#endif
 
 #endif /* FCNTL_COMMON_H__ */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v1 1/2] fcntl{34, 36}: Only use fcntl64 with 32bit abi

Quoted 7 lines · Petr Vorel

Hi Edward,

Quoted 3 lines
Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")

On Android arm64, tst_kernel_bits is disregarding the abi, so compiling

What exactly do you mean by "disregarding the abi"? Why is aarch64 different?

In x86/entry/syscalls/syscall_32.tbl, a 64bit kernel uses compat_sys_fcntl64, which is flock64 compatible; whereas in arm/tools/syscall.tbl it uses sys_fcntl, which is not flock64 compatible.

Quoted 8 lines

Once we removed tst_kernel_bits(), there is no need to pass "fcntl64" as %s, thus it should be:

                 "fcntl64(%d, %s, { %d, %d, %"PRId64", %"PRId64", %d })",
                 fd, cmd_name, l64.l_type, l64.l_whence, l64.l_start, l64.l_len,
                 l64.l_pid);

Otherwise LGTM.

Sounds good, I will send a v2.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v1 1/2] fcntl{34, 36}: Only use fcntl64 with 32bit abi

Quoted 6 lines · Petr Vorel
Quoted 4 lines

Hi Edward,

Quoted 1 line
Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")
Quoted 7 lines
Quoted 2 lines
Quoted 1 line

On Android arm64, tst_kernel_bits is disregarding the abi, so compiling

What exactly do you mean by "disregarding the abi"? Why is aarch64 different?

In x86/entry/syscalls/syscall_32.tbl, a 64bit kernel uses compat_sys_fcntl64, which is flock64 compatible; whereas in arm/tools/syscall.tbl it uses sys_fcntl, which is not flock64 compatible.

Thanks for info! Also thanks you updated the description in v2.

Kind regards,
Petr

Quoted 10 lines
Quoted 8 lines

Once we removed tst_kernel_bits(), there is no need to pass "fcntl64" as %s, thus it should be:

                 "fcntl64(%d, %s, { %d, %d, %"PRId64", %"PRId64", %d })",
                 fd, cmd_name, l64.l_type, l64.l_whence, l64.l_start, l64.l_len,
                 l64.l_pid);

Otherwise LGTM.

Sounds good, I will send a v2.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v1 1/2] fcntl{34, 36}: Only use fcntl64 with 32bit abi

In reply to Edward Liaw via ltp

Hello,

Quoted 5 lines · Edward Liaw via ltp
Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")

On Android arm64, tst_kernel_bits is disregarding the abi, so compiling with the 32bit abi is calling the fcntl syscall instead of fcntl64. The

IIRC that's the idea because fcntl64 doesn't exist on a 64bit kernel.

So if you compile the test with -m32/32bit ABI on x86_64 64bit kernel then you will get ENOSYS? If not then I suppose it is fine.

Quoted 56 lines

fcntl syscall is not compatible with the flock64 struct being passed (this doesn't seem to be the case with x86_64, only with arm64).

This changes it to only use the fcntl64 compat syscall with the 32bit abi.

---
 testcases/kernel/syscalls/fcntl/fcntl_common.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl_common.h +9 -3
index 5c130a784..485a31367 100644
@@ -10,6 +10,11 @@
 #include "lapi/abisize.h"
 #include "lapi/fcntl.h"
 
+#if defined(TST_ABI64)
+#define FCNTL_COMPAT(fd, cmd, flock) \
+	SAFE_FCNTL(fd, cmd, flock)
+
+#else
 struct my_flock64 {
 	int16_t l_type;
 	int16_t l_whence;
@@ -43,8 +48,8 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 		.l_len = lck->l_len,
 		.l_pid = lck->l_pid,
 	};
-	const int sysno = tst_kernel_bits() > 32 ? __NR_fcntl : __NR_fcntl64;
-	const int ret = tst_syscall(sysno, fd, cmd, &l64);
+
+	const int ret = tst_syscall(__NR_fcntl64, fd, cmd, &l64);
 
 	lck->l_type = l64.l_type;
 	lck->l_whence = l64.l_whence;
@@ -57,7 +62,7 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 
 	tst_brk_(file, line, TBROK | TERRNO,
 		 "%s(%d, %s, { %d, %d, %"PRId64", %"PRId64", %d })",
-		 tst_kernel_bits() > 32 ? "fcntl" : "fcntl64",
+		 "fcntl64",
 		 fd,
 		 cmd_name,
 		 l64.l_type, l64.l_whence, l64.l_start, l64.l_len, l64.l_pid);
@@ -67,5 +72,6 @@ static inline int fcntl_compat(const char *file, const int line, const char *cmd
 
 #define FCNTL_COMPAT(fd, cmd, flock) \
 	fcntl_compat(__FILE__, __LINE__, #cmd, fd, cmd, flock)
+#endif
 
 #endif /* FCNTL_COMMON_H__ */
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v1 1/2] fcntl{34, 36}: Only use fcntl64 with 32bit abi

Quoted 11 lines · Richard Palethorpe

Hello,

Quoted 5 lines · Edward Liaw via ltp
Fixes 7643115aaacb ("fcntl{34,36}: Always use 64-bit flock struct to avoid EINVAL")

On Android arm64, tst_kernel_bits is disregarding the abi, so compiling with the 32bit abi is calling the fcntl syscall instead of fcntl64. The

Quoted 5 lines

IIRC that's the idea because fcntl64 doesn't exist on a 64bit kernel.

So if you compile the test with -m32/32bit ABI on x86_64 64bit kernel then you will get ENOSYS? If not then I suppose it is fine.

I did not get ENOSYS. I checked with strace and my x86_64 bit kernel does appear to have fcntl64 when compiled with -m32. I'm not sure if that's always the case, though. I checked with the other fcntl tests and they also appear to call fcntl64 with the 32 bit abi.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH 2/2 fcntl{34, 36}: Use arch dependent types for my_flock64

In reply to Edward Liaw via ltp

On Android arm64, fcntl is not accepting the my_flock64 struct being passed (fails with EINVAL). This modifies the struct type to match the flock64 definition in the kernel.

---
 testcases/kernel/syscalls/fcntl/fcntl_common.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl_common.h +6 -6
index 485a31367..78ffcdc2d 100644
@@ -16,13 +16,13 @@
 
 #else
 struct my_flock64 {
-	int16_t l_type;
-	int16_t l_whence;
-	int64_t l_start;
-	int64_t l_len;
-	int32_t l_pid;
+	short l_type;
+	short l_whence;
+	off64_t l_start;
+	off64_t l_len;
+	pid_t l_pid;
 #if defined(__sparc__)
-	int16_t padding;
+	short padding;
 #endif
 };
 
Signature · 5 lines
2.40.1.495.gc816e09b53d-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp