Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Hui Min Mina Chou <minachou@andestech.com>
To: <pjw@kernel.org>, <palmer@dabbelt.com>, <aou@eecs.berkeley.edu>,
	<alex@ghiti.fr>, <arnd@arndb.de>,
	<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	<linux-arch@vger.kernel.org>
Cc: <tim609@andestech.com>, <ben717@andestech.com>,
	<minachou@andestech.com>, <az70021@gmail.com>,
	Randolph <randolph@andestech.com>
Subject: [PATCH] riscv: Fix __kernel_off_t to 64 Bits in RV32
Date: Thu, 5 Feb 2026 13:58:00 +0800	[thread overview]
Message-ID: <20260205055800.586458-1-minachou@andestech.com> (raw)

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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

             reply	other threads:[~2026-02-05  5:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-05  5:58 Hui Min Mina Chou [this message]
2026-02-05  7:57 ` [PATCH] riscv: Fix __kernel_off_t to 64 Bits in RV32 Arnd Bergmann
2026-02-05 22:26 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260205055800.586458-1-minachou@andestech.com \
    --to=minachou@andestech.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=arnd@arndb.de \
    --cc=az70021@gmail.com \
    --cc=ben717@andestech.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=randolph@andestech.com \
    --cc=tim609@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox