public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Fix __kernel_off_t to 64 Bits in RV32
@ 2026-02-05  5:58 Hui Min Mina Chou
  2026-02-05  7:57 ` Arnd Bergmann
  2026-02-05 22:26 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Min Mina Chou @ 2026-02-05  5:58 UTC (permalink / raw)
  To: pjw, palmer, aou, alex, arnd, linux-riscv, linux-kernel,
	linux-arch
  Cc: tim609, ben717, minachou, az70021, Randolph

From: Randolph <randolph@andestech.com>

Modify the __kernel_off_t type for RV32 to 64 bits to comply with
the current glibc calling convention.

In RISC-V, off_t is 64 bits in glibc, and __kernel_off_t must match
this size. For RV32, the kernel uses the long type, which should be
changed to long long to ensure consistency.

To address the Y2038 problem, the glibc upstream for RISC-V has adopted
64-bit time_t and off_t for both RV32 and RV64 [*1].
However, no corresponding modification was made on the kernel side,
leading to test case failures in LTP’s fnctl due to size inconsistencies.
This discrepancy causes errors when glibc passes the struct flock
parameter to the kernel through fnctl().

The structure of flock are shown as below:

struct flock in glibc:
------------------------------------------------------
struct flock
  {
    short int l_type;
    short int l_whence;
    __off_t l_start;
    __off_t l_len;
    __off64_t l_start;
    __off64_t l_len;             <------  "__off64_t" in glibc is 64bit
    __pid_t l_pid;
  };
------------------------------------------------------

struct flock in kernel:
------------------------------------------------------
struct flock {
    short   l_type;
    short   l_whence;
    __kernel_off_t  l_start;
    __kernel_off_t  l_len;       <----- "__kernel_off_t" in kernel is 32bit
    __kernel_pid_t  l_pid;
    __ARCH_FLOCK_EXTRA_SYSID
    __ARCH_FLOCK_PAD
};
------------------------------------------------------

[*1]: 4e95f95966.1578824547.git.alistair.francis@wdc.com/#2360267

Signed-off-by: Randolph <randolph@andestech.com>
---
 arch/riscv/include/uapi/asm/posix_types.h | 39 +++++++++++++++++++++++
 include/uapi/asm-generic/posix_types.h    |  3 ++
 2 files changed, 42 insertions(+)
 create mode 100644 arch/riscv/include/uapi/asm/posix_types.h

diff --git a/arch/riscv/include/uapi/asm/posix_types.h b/arch/riscv/include/uapi/asm/posix_types.h
new file mode 100644
index 000000000000..91b47340bbc3
--- /dev/null
+++ b/arch/riscv/include/uapi/asm/posix_types.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _ASM_RISCV_POSIX_TYPES_H
+#define _ASM_RISCV_POSIX_TYPES_H
+
+#include <asm/bitsperlong.h>
+
+/*
+ * In the generic flow, this file is automatically created if it does not
+ * already exist, as indicated by the line.
+ * "#include <asm-generic/posix_types.h>"
+ *
+ * If the file already exists, the automatic creation process will be skipped.
+ * Adding architecture-specific types to this file may alter the generic flow,
+ * potentially causing type conflicts during the build phase. To avoid this,
+ * define a variable to instruct the generic code to skip the re-typedef
+ * process.
+ */
+#if __BITS_PER_LONG == 32
+typedef long long		__kernel_off_t;
+#define _arch_kernel_off_t	_arch_kernel_off_t
+#endif
+
+/*
+ * The "long" type is 4 bytes in RV32 and 8 bytes in RV64.
+ *
+ * Before adding an architecture specific type:
+ * In RV32: __kernel_off_t -> __kernel_long_t -> long (4 byte)
+ * In RV64: __kernel_off_t -> __kernel_long_t -> long (8 byte)
+ *
+ * After adding architecture specific type:
+ * In RV32: __kernel_off_t -> long long (8 byte)
+ * In RV64: __kernel_off_t -> __kernel_long_t -> long (8 byte)
+ *
+ * This architecture specific type is only for RV32.
+ */
+
+#include <asm-generic/posix_types.h>
+
+#endif /* _ASM_RISCV_POSIX_TYPES_H */
diff --git a/include/uapi/asm-generic/posix_types.h b/include/uapi/asm-generic/posix_types.h
index 0a90ad92dbf3..dc5dd32f6d33 100644
--- a/include/uapi/asm-generic/posix_types.h
+++ b/include/uapi/asm-generic/posix_types.h
@@ -84,7 +84,10 @@ typedef struct {
 /*
  * anything below here should be completely generic
  */
+#ifndef _arch_kernel_off_t
 typedef __kernel_long_t	__kernel_off_t;
+#endif
+
 typedef long long	__kernel_loff_t;
 typedef unsigned long long	__kernel_uoff_t;
 typedef __kernel_long_t	__kernel_old_time_t;
-- 
2.34.1


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

end of thread, other threads:[~2026-02-05 22:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05  5:58 [PATCH] riscv: Fix __kernel_off_t to 64 Bits in RV32 Hui Min Mina Chou
2026-02-05  7:57 ` Arnd Bergmann
2026-02-05 22:26 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox