* [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
@ 2025-03-25 12:15 guoren
2025-03-25 12:15 ` [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface guoren
` (44 more replies)
0 siblings, 45 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
for construction to reduce cache & memory footprint (Compared to
kernel-lp64-abi, kernel-rv64ilp32-abi decreased the used memory by
about 20%, as shown in "free -h" in the following demo.)
Caution: this patchset doesn't introduce any new userspace ABI; it's
only for the kernel-self.
The patchset targets RISC-V and is built on the RV64ILP32 ABI, which
was introduced into RISC-V's psABI in January 2025 [1]. This patchset
equips an rv64ilp32-abi kernel with all the functionalities of a
traditional lp64-abi kernel, yet restricts the address space to 2GiB.
Hence, the rv64ilp32-abi kernel simultaneously supports lp64-abi
userspace and ilp32-abi (compat) userspace, the same as the
traditional lp64-abi kernel.
+--------------------------------+
| +-------------+--------------+ |
| | | (compat) | |
| | lp64-abi | ilp32-abi | | User
| +-------------+--------------+ |
+--------------------------------+-------
| +----------------------------+ |
| | rv64ilp32-abi / lp64-abi | | Kernel
| | ^^^^^^^^^^^^^ | |
| +----------------------------+ |
+--------------lp64-sbi----------+-------
| +----------------------------+ |
| | lp64-abi | | OpenSBI
| +----------------------------+ |
+--------------------------------+-------
| +----------------------------+ |
| | rv64gcbvh (RISC-V 64-bit) | | ISA
| +----------------------------+ |
+--------------------------------+
Caution: The rv64ilp32-abi and lp64-abi kernels are equivalent
and can be used interchangeably. The only difference is that the
rv64ilp32-abi kernel restricts kernel and user space to separate
2GiB address spaces.
Motivation
==========
Because all RISC-V RVA(B) Profiles are based on the 64-bit ISA, the market
has experienced a significant rise in RISC-V 64-bit ISA SoCs and CPU cores
for resource-constrained scenarios, such as:
- allwinner/sun20i-d1-lichee
- allwinner/sun20i-d1s-mangopi
- bouffalo/bl808
- canaan/k230d
- microchip/mpfs-beaglev-fire
- renesas/rzfive-smarc
- sophgo/cv1800b
- sophgo/cv1812h
- sophgo/sg2002
The listed RV64 ISA-based SoCs with limited memory (less than 1GiB) can
benefit from this patchset. The patchset's benefit is not only decreasing
the memory footprint but also improving performance due to increased cache
density. Hence, All RVA(B) Profile hardwares can benefit from this
patchset.
Patchset Organization
=====================
This patchset is now in its third version. The major update is the
shift to CONFIG_64BIT with user lp64-abi & ilp32-abi support. The prior
versions (v1, v2) are all based on CONFIG_32BIT and only support the
user ilp32-abi.
The innovation of v3 lies in supporting user lp64-abi by inheriting
CONFIG_64BIT.
This patchset comprises 43 patches affecting more than 20 subsystems.
Most modifications are about ensuring the correct usage of
BITS_PER_LONG and CONFIG_64BIT. Part of the Linux code doesn't care
about that because BITS_PER_LONG and CONFIG_64BIT were the same before.
- PATCH[1] : The rv64ilp32-abi kernel reuses lp64-abi uapi.
- PATCH[2~17] : The riscv subsystem-related modifications.
- PATCH[18~43]: Other subsystem-related modifications.
The first patch needs discussion and is titled "uapi: Reuse lp64 ABI
interface." How do we define a unified set of lp64-abi uapi header
files that could be utilized for the lp64-abi kernel and the
rv64ilp32-abi kernel?
To get started with the patch set quickly, check out the following
demo.
Demo Introduction
=================
To test the patchset, use a riscv64 toolchain with rv64ilp32-abi
support. The rv64ilp32-abi is integrated as a -mabi=ilp32 feature within
the standard rv64 toolchain. We've built a multi-lib riscv64-elf-toolchain
[2] containing rv64ilp32-abi. We also provide the pre-compiled demo
materials for a quick start, such as qemu, kernel, and rootfs binaries for
the demo.
After download from [2]:
$ tar zxvf riscv64-elf-ubuntu-20(2).04-gcc-nightly-2025.03.24-nightly.tar.gz
$ cd riscv/qemu-linux
- Image_rv64ilp32 rv64ilp32-abi kernel
- Image_rv64lp64 lp64-abi kernel
- u64lp64_rootfs.ext2 lp64-abi userspace rootfs
- start-qemu-rv64.sh qemu running wrapper script
Compile Image_rv64ilp32:
$ make ARCH=riscv CROSS_COMPILE=<download path>/riscv/bin/riscv64-unknown-elf- rv64ilp32_defconfig all
Compile Image_rv64lp64:
$ make ARCH=riscv CROSS_COMPILE=<download path>/riscv/bin/riscv64-unknown-elf- defconfig all
Quick Start:
$ ./start-qemu-rv64.sh Image_rv64ilp32 u64lp64_rootfs.ext2
v.s.
$ ./start-qemu-rv64.sh Image_rv64lp64 u64lp64_rootfs.ext2
Used Memory Comparison
======================
Under the same configuration, the used memory decreased by 20% (10.8 ->
8.2) with the Image_rv64ilp32 replacement (Qemu, firmware, and lp64-abi
user rootfs are the same).
$ ./start-qemu-rv64.sh Image_rv64ilp32 u64lp64_rootfs.ext2
$ free -h
total used free shared buff/cache available
Mem: 105.4M 8.2M 93.9M 44.0K 3.3M 93.6M
^^^^
$ ./start-qemu-rv64.sh Image_rv64lp64 u64lp64_rootfs.ext2
$ free -h
total used free shared buff/cache available
Mem: 89.3M 10.8M 74.8M 44.0K 3.7M 74.9M
^^^^^
$ cat start-qemu-rv64.sh
exec qemu-system-riscv64 -cpu rv64 -M virt -m 128m -nographic -kernel $1 -drive file=$2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "rootwait root=/dev/vda ro console=ttyS0 earlycon=sbi norandmaps no5lvl no4lvl"
User Virtual Memory Layout
==========================
Here is the comparison running lp64-abi userspace rootfs on
rv64ilp32-abi kernel and lp64-abi kernel:
(rv64ilp32-abi kernel + lp64-abi user rootfs)
$ cat /proc/1/maps
55555000-5560c000 r-xp 00000000 fe:00 17 /bin/busybox
5560c000-5560f000 r--p 000b7000 fe:00 17 /bin/busybox
5560f000-55610000 rw-p 000ba000 fe:00 17 /bin/busybox
55610000-55631000 rw-p 00000000 00:00 0 [heap]
77e69000-77e6b000 rw-p 00000000 00:00 0
77e6b000-77fba000 r-xp 00000000 fe:00 140 /lib/libc.so.6
77fba000-77fbd000 r--p 0014f000 fe:00 140 /lib/libc.so.6
77fbd000-77fbf000 rw-p 00152000 fe:00 140 /lib/libc.so.6
77fbf000-77fcb000 rw-p 00000000 00:00 0
77fcb000-77fd5000 r-xp 00000000 fe:00 148 /lib/libresolv.so.2
77fd5000-77fd6000 r--p 0000a000 fe:00 148 /lib/libresolv.so.2
77fd6000-77fd7000 rw-p 0000b000 fe:00 148 /lib/libresolv.so.2
77fd7000-77fd9000 rw-p 00000000 00:00 0
77fd9000-77fdb000 r--p 00000000 00:00 0 [vvar]
77fdb000-77fdc000 r-xp 00000000 00:00 0 [vdso]
77fdc000-77ffc000 r-xp 00000000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
77ffc000-77ffe000 r--p 0001f000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
77ffe000-78000000 rw-p 00021000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
7ffdf000-80000000 rw-p 00000000 00:00 0 [stack]
(lp64-abi kernel + lp64-abi user rootfs)
$ cat /proc/1/maps
2aaaaaa000-2aaab61000 r-xp 00000000 fe:00 17 /bin/busybox
2aaab61000-2aaab64000 r--p 000b7000 fe:00 17 /bin/busybox
2aaab64000-2aaab65000 rw-p 000ba000 fe:00 17 /bin/busybox
2aaab65000-2aaab86000 rw-p 00000000 00:00 0 [heap]
3ff7e69000-3ff7e6b000 rw-p 00000000 00:00 0
3ff7e6b000-3ff7fba000 r-xp 00000000 fe:00 140 /lib/libc.so.6
3ff7fba000-3ff7fbd000 r--p 0014f000 fe:00 140 /lib/libc.so.6
3ff7fbd000-3ff7fbf000 rw-p 00152000 fe:00 140 /lib/libc.so.6
3ff7fbf000-3ff7fcb000 rw-p 00000000 00:00 0
3ff7fcb000-3ff7fd5000 r-xp 00000000 fe:00 148 /lib/libresolv.so.2
3ff7fd5000-3ff7fd6000 r--p 0000a000 fe:00 148 /lib/libresolv.so.2
3ff7fd6000-3ff7fd7000 rw-p 0000b000 fe:00 148 /lib/libresolv.so.2
3ff7fd7000-3ff7fd9000 rw-p 00000000 00:00 0
3ff7fd9000-3ff7fdb000 r--p 00000000 00:00 0 [vvar]
3ff7fdb000-3ff7fdc000 r-xp 00000000 00:00 0 [vdso]
3ff7fdc000-3ff7ffc000 r-xp 00000000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
3ff7ffc000-3ff7ffe000 r--p 0001f000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
3ff7ffe000-3ff8000000 rw-p 00021000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
3ffffdf000-4000000000 rw-p 00000000 00:00 0 [stack]
~~~~~~~~~~~~~~~~~~~~~~
For the ilp32-abi userspace rootfs, the virtual memory layouts
are the same:
(lp64-abi/rv64ilp32-abi kernel + ilp32-abi user rootfs)
$ cat /proc/1/maps
55555000-55637000 r-xp 00000000 fe:00 17 /bin/busybox
55637000-55639000 r--p 000e1000 fe:00 17 /bin/busybox
55639000-5563a000 rw-p 000e3000 fe:00 17 /bin/busybox
5563a000-5565c000 rw-p 00000000 00:00 0 [heap]
77e63000-77fbe000 r-xp 00000000 fe:00 145 /lib/libc.so.6
77fbe000-77fc0000 r--p 0015a000 fe:00 145 /lib/libc.so.6
77fc0000-77fc1000 rw-p 0015c000 fe:00 145 /lib/libc.so.6
77fc1000-77fcb000 rw-p 00000000 00:00 0
77fcb000-77fd5000 r-xp 00000000 fe:00 154 /lib/libresolv.so.2
77fd5000-77fd6000 r--p 0000a000 fe:00 154 /lib/libresolv.so.2
77fd6000-77fd7000 rw-p 0000b000 fe:00 154 /lib/libresolv.so.2
77fd7000-77fd9000 rw-p 00000000 00:00 0
77fd9000-77fdb000 r--p 00000000 00:00 0 [vvar]
77fdb000-77fdc000 r-xp 00000000 00:00 0 [vdso]
77fdc000-77ffe000 r-xp 00000000 fe:00 138 /lib/ld-linux-riscv32-ilp32d.so.1
77ffe000-77fff000 r--p 00022000 fe:00 138 /lib/ld-linux-riscv32-ilp32d.so.1
77fff000-78000000 rw-p 00023000 fe:00 138 /lib/ld-linux-riscv32-ilp32d.so.1
7ffdf000-80000000 rw-p 00000000 00:00 0 [stack]
Kernel Virtual Memory Layout
============================
Here is the comparison on rv64ilp32-abi kernel and lp64-abi kernel:
Virtual kernel memory layout (rv64ilp32-abi kernel):
fixmap : 0x94a00000 - 0x94ffffff (6144 kB)
pci io : 0x95000000 - 0x95ffffff ( 16 MB)
vmemmap : 0x96000000 - 0x97ffffff ( 32 MB)
vmalloc : 0x98000000 - 0xb7ffffff ( 512 MB)
modules : 0xb8000000 - 0xbbffffff ( 64 MB)
lowmem : 0xc0000000 - 0xc7ffffff ( 128 MB)
kasan : 0x80000000 - 0x8fffffff ( 256 MB)
kernel : 0xbc000000 - 0xbfffffff ( 64 MB)
Virtual kernel memory layout (lp64-abi kernel):
fixmap : 0xffffffc4fea00000 - 0xffffffc4feffffff (6144 kB)
pci io : 0xffffffc4ff000000 - 0xffffffc4ffffffff ( 16 MB)
vmemmap : 0xffffffc500000000 - 0xffffffc5ffffffff (4096 MB)
vmalloc : 0xffffffc600000000 - 0xffffffd5ffffffff ( 64 GB)
modules : 0xffffffff01591000 - 0xffffffff7fffffff (2026 MB)
lowmem : 0xffffffd600000000 - 0xffffffd607ffffff ( 128 MB)
kasan : 0xfffffff700000000 - 0xfffffffeffffffff ( 32 GB)
kernel : 0xffffffff80000000 - 0xfffffffffffffffe (2047 MB)
Memory Info Comparison
======================
$ ./start-qemu-rv64.sh Image_rv64ilp32 u64lp64_rootfs.ext2
$ cat /proc/meminfo
MemTotal: 107916 kB
MemFree: 96200 kB
MemAvailable: 95932 kB
Buffers: 448 kB
Cached: 2268 kB
SwapCached: 0 kB
Active: 2432 kB
Inactive: 832 kB
Active(anon): 44 kB
Inactive(anon): 548 kB
Active(file): 2388 kB
Inactive(file): 284 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 108 kB
Writeback: 0 kB
AnonPages: 648 kB
Mapped: 1672 kB
Shmem: 44 kB
KReclaimable: 688 kB
Slab: 4996 kB
SReclaimable: 688 kB
SUnreclaim: 4308 kB
KernelStack: 768 kB
PageTables: 164 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 53956 kB
Committed_AS: 2240 kB
VmallocTotal: 524288 kB
VmallocUsed: 924 kB
VmallocChunk: 0 kB
Percpu: 76 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
$ ./start-qemu-rv64.sh Image_rv64lp64 u64lp64_rootfs.ext2
$ cat /proc/meminfo
MemTotal: 91428 kB
MemFree: 77048 kB
MemAvailable: 77172 kB
Buffers: 448 kB
Cached: 2268 kB
SwapCached: 0 kB
Active: 2492 kB
Inactive: 768 kB
Active(anon): 48 kB
Inactive(anon): 540 kB
Active(file): 2444 kB
Inactive(file): 228 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 32 kB
Writeback: 0 kB
AnonPages: 648 kB
Mapped: 1768 kB
Shmem: 44 kB
KReclaimable: 1140 kB
Slab: 7220 kB
SReclaimable: 1140 kB
SUnreclaim: 6080 kB
KernelStack: 768 kB
PageTables: 408 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 45712 kB
Committed_AS: 2240 kB
VmallocTotal: 67108864 kB
VmallocUsed: 864 kB
VmallocChunk: 0 kB
Percpu: 88 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
CPU Info Comparison
===================
After disabling sv48 and sv57, there is no difference in the "/proc/cpuinfo".
$ ./start-qemu-rv64.sh Image_rv64lp64 u64lp64_rootfs.ext2
$ cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_zicntr_zicsr_zifencei_zihintpause_zihpm_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa : rv64imafdch_zicbom_zicboz_zicntr_zicsr_zifencei_zihintpause_zihpm_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu
$ ./start-qemu-rv64.sh Image_rv64ilp32 u64lp64_rootfs.ext2
$ cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_zicntr_zicsr_zifencei_zihintpause_zihpm_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa : rv64imafdch_zicbom_zicboz_zicntr_zicsr_zifencei_zihintpause_zihpm_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu
.config Difference
==================
The patchset adds CONFIG_ABI_RV64ILP32 to Kconfig, switching the
compile options from "-mabi=lp64 -melf64lriscv" to
"-mabi=ilp32 -melf32lriscv" depending on CONFIG_64BIT. So, The
differences of Kconfig between with and without ABI_RV64ILP32
are rare:
- CONFIG_PAGE_OFFSET Change to 0xc0000000.
- CONFIG_ILLEGAL_POINTER_VALUE Change to 0x0.
- CONFIG_ABI_RV64ILP32 Compile option depends on CONFIG_64BIT.
- CONFIG_HAVE_CMPXCHG_DOUBLE The rv64ilp32-abi kernel offers new feature.
- CONFIG_ZONE_DMA32 It's unnecessary for rv64ilp32-abi kernel.
- CONFIG_CSD_LOCK_WAIT_DEBUG Because of BITS_PER_LONG = 32, rv64ilp32-abi
kernel doesn't support.
$ diff build-rv64lp64/.config build-rv64ilp32/.config
296c296
< CONFIG_PAGE_OFFSET=0xff60000000000000
---
> CONFIG_PAGE_OFFSET=0xc0000000
308c308
< CONFIG_ILLEGAL_POINTER_VALUE=0xdead000000000000
---
> CONFIG_ILLEGAL_POINTER_VALUE=0
352c352
< # CONFIG_ABI_RV64ILP32 is not set
---
> CONFIG_ABI_RV64ILP32=y
609a610
> CONFIG_HAVE_CMPXCHG_DOUBLE=y
837d837
< CONFIG_ZONE_DMA32=y
7240d7239
< # CONFIG_CSD_LOCK_WAIT_DEBUG is not set
6 differences
Use "zcat /proc/config.gz" to get the .config file in our qemu demo.
Dmesg Difference
================
$ diff rv64lp64.log rv64ilp32.log
1c1
< Linux version 6.14.0-rc1-00041-g804ac3b4d679 (ren.guo@ea134-sw12.eng.xrvm.cn) (riscv64-unknown-elf-gcc (gf9ffd92f861-dirty) 13.2.0, GNU ld (GNU Binutils) 2.42) #1 SMP Sat Mar 15 11:57:20 CST 2025
---
> Linux version 6.14.0-rc1-00041-g804ac3b4d679 (ren.guo@ea134-sw12.eng.xrvm.cn) (riscv64-unknown-elf-gcc (gf9ffd92f861-dirty) 13.2.0, GNU ld (GNU Binutils) 2.42) #1 SMP Sat Mar 15 11:55:33 CST 2025
13,14d12
< Disabled 5-level paging
< Disabled 4-level and 5-level paging
19,20c17
< DMA32 [mem 0x0000000060000000-0x0000000067ffffff]
< Normal empty
---
> Normal [mem 0x0000000060000000-0x0000000067ffffff]
31c28
< percpu: Embedded 22 pages/cpu s49384 r8192 d32536 u90112
---
> percpu: Embedded 16 pages/cpu s34264 r8192 d23080 u65536
33,35c30,33
< printk: log buffer data + meta data: 131072 + 458752 = 589824 bytes
< Dentry cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
< Inode-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
---
> Unknown kernel command line parameters "no5lvl no4lvl", will be passed to user space.
> printk: log buffer data + meta data: 131072 + 409600 = 540672 bytes
> Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
> Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
40c38
< software IO TLB: mapped [mem 0x0000000067f6b000-0x0000000067fab000] (0MB)
---
> software IO TLB: mapped [mem 0x0000000067f8e000-0x0000000067fce000] (0MB)
42,48c40,46
< fixmap : 0xffffffc4fea00000 - 0xffffffc4feffffff (6144 kB)
< pci io : 0xffffffc4ff000000 - 0xffffffc4ffffffff ( 16 MB)
< vmemmap : 0xffffffc500000000 - 0xffffffc5ffffffff (4096 MB)
< vmalloc : 0xffffffc600000000 - 0xffffffd5ffffffff ( 64 GB)
< modules : 0xffffffff0158d000 - 0xffffffff7fffffff (2026 MB)
< lowmem : 0xffffffd600000000 - 0xffffffd607ffffff ( 128 MB)
< kernel : 0xffffffff80000000 - 0xfffffffffffffffe (2047 MB)
---
> fixmap : 0x94a00000 - 0x94ffffff (6144 kB)
> pci io : 0x95000000 - 0x95ffffff ( 16 MB)
> vmemmap : 0x96000000 - 0x97ffffff ( 32 MB)
> vmalloc : 0x98000000 - 0xb7ffffff ( 512 MB)
> modules : 0xb8000000 - 0xbbffffff ( 64 MB)
> lowmem : 0xc0000000 - 0xc7ffffff ( 128 MB)
> kernel : 0xbc000000 - 0xbfffffff ( 64 MB)
68,69c66,67
< Mount-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
< Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
---
> Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
> Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
77c75
< Memory: 87584K/131072K available (9731K kernel code, 4933K rwdata, 4096K rodata, 2307K init, 484K bss, 41948K reserved, 0K cma-reserved)
---
> Memory: 104768K/131072K available (10043K kernel code, 4722K rwdata, 4096K rodata, 2265K init, 371K bss, 25420K reserved, 0K cma-reserved)
85d82
< DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
88c85
< audit: type=2000 audit(0.104:1): state=initialized audit_enabled=0 res=1
---
> audit: type=2000 audit(0.152:1): state=initialized audit_enabled=0 res=1
92c89
< HugeTLB: 28 KiB vmemmap can be freed for a 2.00 MiB page
---
> HugeTLB: 0 KiB vmemmap can be freed for a 2.00 MiB page
106c103
< tcp_listen_portaddr_hash hash table entries: 128 (order: 0, 4096 bytes, linear)
---
> tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 5120 bytes, linear)
108,109c105,106
< TCP established hash table entries: 1024 (order: 1, 8192 bytes, linear)
< TCP bind hash table entries: 1024 (order: 4, 65536 bytes, linear)
---
> TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
> TCP bind hash table entries: 1024 (order: 3, 40960 bytes, linear)
111,112c108,109
< UDP hash table entries: 256 (order: 3, 40960 bytes, linear)
< UDP-Lite hash table entries: 256 (order: 3, 40960 bytes, linear)
---
> UDP hash table entries: 256 (order: 2, 20480 bytes, linear)
> UDP-Lite hash table entries: 256 (order: 2, 20480 bytes, linear)
120c117
< workingset: timestamp_bits=46 max_order=15 bucket_order=0
---
> workingset: timestamp_bits=14 max_order=15 bucket_order=1
165c162
< goldfish_rtc 101000.rtc: setting system clock to 2025-03-15T08:48:58 UTC (1742028538)
---
> goldfish_rtc 101000.rtc: setting system clock to 2025-03-15T08:51:36 UTC (1742028696)
191c188
< Freeing unused kernel image (initmem) memory: 2304K
---
> Freeing unused kernel image (initmem) memory: 2264K
18 differences
References
==========
[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/381
[2] https://github.com/ruyisdk/riscv-gnu-toolchain-rv64ilp32/releases/tag/2025.03.24
Changelog
=========
v3:
- Base on CONFIG_64BIT instead of CONFIG_32BIT
- Add lp64-abi userspace support
- Remove rv64ilp32-abi userspace support
- Rebase on v6.14-rc1
v2:
https://lore.kernel.org/linux-riscv/20231112061514.2306187-1-guoren@kernel.org/
- Add u64ilp32 support
- Rebase v6.5-rc1
- Enable 64ilp32 vgettimeofday for benchmarking
v1:
https://lore.kernel.org/linux-riscv/20230518131013.3366406-1-guoren@kernel.org/
Guo Ren (Alibaba DAMO Academy) (43):
rv64ilp32_abi: uapi: Reuse lp64 ABI interface
rv64ilp32_abi: riscv: Adapt Makefile and Kconfig
rv64ilp32_abi: riscv: Adapt ULL & UL definition
rv64ilp32_abi: riscv: Introduce xlen_t to adapt __riscv_xlen !=
BITS_PER_LONG
rv64ilp32_abi: riscv: crc32: Utilize 64-bit width to improve the
performance
rv64ilp32_abi: riscv: csum: Utilize 64-bit width to improve the
performance
rv64ilp32_abi: riscv: arch_hweight: Adapt cpopw & cpop of zbb
extension
rv64ilp32_abi: riscv: bitops: Adapt ctzw & clzw of zbb extension
rv64ilp32_abi: riscv: Reuse LP64 SBI interface
rv64ilp32_abi: riscv: Update SATP.MODE.ASID width
rv64ilp32_abi: riscv: Introduce PTR_L and PTR_S
rv64ilp32_abi: riscv: Introduce cmpxchg_double
rv64ilp32_abi: riscv: Correct stackframe layout
rv64ilp32_abi: riscv: Adapt kernel module code
rv64ilp32_abi: riscv: mm: Adapt MMU_SV39 for 2GiB address space
rv64ilp32_abi: riscv: Support physical addresses >= 0x80000000
rv64ilp32_abi: riscv: Adapt kasan memory layout
rv64ilp32_abi: riscv: kvm: Initial support
rv64ilp32_abi: irqchip: irq-riscv-intc: Use xlen_t instead of ulong
rv64ilp32_abi: drivers/perf: Adapt xlen_t of sbiret
rv64ilp32_abi: asm-generic: Add custom BITS_PER_LONG definition
rv64ilp32_abi: bpf: Change KERN_ARENA_SZ to 256MiB
rv64ilp32_abi: compat: Correct compat_ulong_t cast
rv64ilp32_abi: compiler_types: Add "long long" into __native_word()
rv64ilp32_abi: exec: Adapt 64lp64 env and argv
rv64ilp32_abi: file_ref: Use 32-bit width for refcnt
rv64ilp32_abi: input: Adapt BITS_PER_LONG to dword
rv64ilp32_abi: iov_iter: Resize kvec to match iov_iter's size
rv64ilp32_abi: locking/atomic: Use BITS_PER_LONG for scripts
rv64ilp32_abi: kernel/smp: Disable CSD_LOCK_WAIT_DEBUG
rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
rv64ilp32_abi: mm: Remove _folio_nr_pages
rv64ilp32_abi: mm/auxvec: Adapt mm->saved_auxv[] to Elf64
rv64ilp32_abi: mm: Adapt vm_flags_t struct
rv64ilp32_abi: net: Use BITS_PER_LONG in struct dst_entry
rv64ilp32_abi: printf: Use BITS_PER_LONG instead of CONFIG_64BIT
rv64ilp32_abi: random: Adapt fast_pool struct
rv64ilp32_abi: syscall: Use CONFIG_64BIT instead of BITS_PER_LONG
rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi
rv64ilp32_abi: tracepoint-defs: Using u64 for trace_print_flags.mask
rv64ilp32_abi: tty: Adapt ptr_to_compat
rv64ilp32_abi: memfd: Use vm_flag_t
riscv: Fixup address space overlay of print_mlk
arch/riscv/Kconfig | 15 +-
arch/riscv/Makefile | 17 ++
arch/riscv/configs/rv64ilp32.config | 1 +
arch/riscv/include/asm/arch_hweight.h | 8 +-
arch/riscv/include/asm/asm.h | 13 +-
arch/riscv/include/asm/bitops.h | 21 +-
arch/riscv/include/asm/checksum.h | 4 +
arch/riscv/include/asm/cmpxchg.h | 57 ++++-
arch/riscv/include/asm/cpu_ops_sbi.h | 4 +-
arch/riscv/include/asm/csr.h | 227 +++++++++---------
arch/riscv/include/asm/kasan.h | 6 +-
arch/riscv/include/asm/kvm_aia.h | 32 +--
arch/riscv/include/asm/kvm_host.h | 192 +++++++--------
arch/riscv/include/asm/kvm_nacl.h | 26 +-
arch/riscv/include/asm/kvm_vcpu_insn.h | 4 +-
arch/riscv/include/asm/kvm_vcpu_pmu.h | 8 +-
arch/riscv/include/asm/kvm_vcpu_sbi.h | 4 +-
arch/riscv/include/asm/page.h | 23 +-
arch/riscv/include/asm/pgtable-64.h | 55 +++--
arch/riscv/include/asm/pgtable.h | 60 ++++-
arch/riscv/include/asm/processor.h | 12 +-
arch/riscv/include/asm/ptrace.h | 92 +++----
arch/riscv/include/asm/sbi.h | 32 +--
arch/riscv/include/asm/scs.h | 4 +-
arch/riscv/include/asm/sparsemem.h | 2 +-
arch/riscv/include/asm/stacktrace.h | 6 +
arch/riscv/include/asm/switch_to.h | 4 +-
arch/riscv/include/asm/syscall_table.h | 2 +-
arch/riscv/include/asm/thread_info.h | 2 +-
arch/riscv/include/asm/timex.h | 4 +-
arch/riscv/include/asm/unistd.h | 4 +-
arch/riscv/include/uapi/asm/bitsperlong.h | 6 +
arch/riscv/include/uapi/asm/elf.h | 4 +-
arch/riscv/include/uapi/asm/kvm.h | 56 ++---
arch/riscv/include/uapi/asm/ptrace.h | 97 ++++----
arch/riscv/include/uapi/asm/ucontext.h | 7 +-
arch/riscv/include/uapi/asm/unistd.h | 2 +-
arch/riscv/kernel/compat_signal.c | 4 +-
arch/riscv/kernel/cpu.c | 4 +-
arch/riscv/kernel/cpu_ops_sbi.c | 4 +-
arch/riscv/kernel/entry.S | 32 +--
arch/riscv/kernel/head.S | 120 ++++++++-
arch/riscv/kernel/module.c | 2 +-
arch/riscv/kernel/process.c | 8 +-
arch/riscv/kernel/sbi_ecall.c | 22 +-
arch/riscv/kernel/signal.c | 4 +-
arch/riscv/kernel/traps.c | 4 +-
arch/riscv/kernel/vector.c | 2 +-
arch/riscv/kvm/aia.c | 26 +-
arch/riscv/kvm/aia_imsic.c | 6 +-
arch/riscv/kvm/main.c | 2 +-
arch/riscv/kvm/mmu.c | 10 +-
arch/riscv/kvm/tlb.c | 76 +++---
arch/riscv/kvm/vcpu.c | 10 +-
arch/riscv/kvm/vcpu_exit.c | 4 +-
arch/riscv/kvm/vcpu_insn.c | 12 +-
arch/riscv/kvm/vcpu_onereg.c | 18 +-
arch/riscv/kvm/vcpu_pmu.c | 8 +-
arch/riscv/kvm/vcpu_sbi_base.c | 2 +-
arch/riscv/kvm/vmid.c | 4 +-
arch/riscv/lib/crc32-riscv.c | 35 +--
arch/riscv/lib/csum.c | 48 ++--
arch/riscv/mm/context.c | 12 +-
arch/riscv/mm/fault.c | 12 +-
arch/riscv/mm/init.c | 63 +++--
arch/riscv/mm/kasan_init.c | 2 +-
arch/riscv/mm/pageattr.c | 4 +-
arch/riscv/mm/pgtable.c | 2 +-
arch/riscv/net/bpf_jit_comp64.c | 6 +-
drivers/char/random.c | 8 +
drivers/input/input.c | 4 +
drivers/irqchip/irq-riscv-intc.c | 9 +-
drivers/perf/riscv_pmu_sbi.c | 4 +-
drivers/tty/tty_io.c | 4 +
fs/exec.c | 4 +
fs/proc/loadavg.c | 10 +-
fs/proc/task_mmu.c | 9 +-
include/asm-generic/bitsperlong.h | 2 +
include/asm-generic/module.h | 2 +-
include/linux/atomic/atomic-long.h | 174 +++++++-------
include/linux/compiler_types.h | 7 +
include/linux/file_ref.h | 4 +-
include/linux/maple_tree.h | 2 +-
include/linux/memfd.h | 4 +-
include/linux/mm.h | 14 +-
include/linux/mm_types.h | 10 +-
include/linux/sched/loadavg.h | 4 +
include/linux/smp_types.h | 2 +-
include/linux/socket.h | 35 +++
include/linux/tracepoint-defs.h | 4 +
include/linux/uio.h | 6 +
include/net/dst.h | 6 +-
include/uapi/asm-generic/siginfo.h | 50 ++++
include/uapi/asm-generic/signal.h | 35 +++
include/uapi/asm-generic/stat.h | 25 ++
include/uapi/linux/atm.h | 7 +
include/uapi/linux/atmdev.h | 7 +
include/uapi/linux/auto_fs.h | 6 +
include/uapi/linux/blkpg.h | 7 +
include/uapi/linux/btrfs.h | 19 ++
include/uapi/linux/capi.h | 11 +
include/uapi/linux/fs.h | 12 +
include/uapi/linux/futex.h | 18 ++
include/uapi/linux/if.h | 6 +
include/uapi/linux/netfilter/x_tables.h | 8 +
include/uapi/linux/netfilter_ipv4/ip_tables.h | 7 +
include/uapi/linux/nfs4_mount.h | 14 ++
include/uapi/linux/ppp-ioctl.h | 7 +
include/uapi/linux/sctp.h | 3 +
include/uapi/linux/sem.h | 38 +++
include/uapi/linux/socket.h | 7 +
include/uapi/linux/sysctl.h | 32 +++
include/uapi/linux/sysinfo.h | 20 ++
include/uapi/linux/uhid.h | 7 +
include/uapi/linux/uio.h | 11 +
include/uapi/linux/usb/tmc.h | 14 ++
include/uapi/linux/usbdevice_fs.h | 50 ++++
include/uapi/linux/uvcvideo.h | 14 ++
include/uapi/linux/vfio.h | 7 +
include/uapi/linux/videodev2.h | 7 +
kernel/bpf/arena.c | 19 +-
kernel/compat.c | 15 +-
kernel/sched/loadavg.c | 4 +
kernel/sys.c | 8 +
lib/Kconfig.debug | 1 +
lib/vsprintf.c | 2 +-
mm/debug.c | 4 +
mm/internal.h | 2 +-
mm/memfd.c | 8 +-
mm/memory.c | 4 +
scripts/atomic/gen-atomic-long.sh | 4 +-
scripts/checksyscalls.sh | 2 +-
132 files changed, 1728 insertions(+), 803 deletions(-)
create mode 100644 arch/riscv/configs/rv64ilp32.config
--
2.40.1
^ permalink raw reply [flat|nested] 63+ messages in thread
* [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 20:30 ` Jan Engelhardt
2025-03-25 20:41 ` Linus Torvalds
2025-03-25 12:15 ` [RFC PATCH V3 02/43] rv64ilp32_abi: riscv: Adapt Makefile and Kconfig guoren
` (43 subsequent siblings)
44 siblings, 2 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 abi kernel accommodates the lp64 abi userspace and
leverages the lp64 abi Linux interface. Hence, unify the
BITS_PER_LONG = 32 memory layout to match BITS_PER_LONG = 64.
#if (__riscv_xlen == 64) && (BITS_PER_LONG == 32)
union {
void *datap;
__u64 __datap;
};
#else
void *datap;
#endif
This is inspired from include/uapi/linux/kvm.h:
struct kvm_dirty_log {
...
union {
void __user *dirty_bitmap; /* one bit per page */
__u64 padding2;
};
};
This is a suggestion solution for __riscv_xlen == 64, but we need a
general way to determine CONFIG_64BIT/32BIT in uapi. Any help are
welcome.
TODO: Find a general way to replace __riscv_xlen for uapi headers.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/socket.h | 35 +++++++++++++
include/uapi/asm-generic/siginfo.h | 50 +++++++++++++++++++
include/uapi/asm-generic/signal.h | 35 +++++++++++++
include/uapi/asm-generic/stat.h | 25 ++++++++++
include/uapi/linux/atm.h | 7 +++
include/uapi/linux/atmdev.h | 7 +++
include/uapi/linux/blkpg.h | 7 +++
include/uapi/linux/btrfs.h | 19 +++++++
include/uapi/linux/capi.h | 11 ++++
include/uapi/linux/fs.h | 12 +++++
include/uapi/linux/futex.h | 18 +++++++
include/uapi/linux/if.h | 6 +++
include/uapi/linux/netfilter/x_tables.h | 8 +++
include/uapi/linux/netfilter_ipv4/ip_tables.h | 7 +++
include/uapi/linux/nfs4_mount.h | 14 ++++++
include/uapi/linux/ppp-ioctl.h | 7 +++
include/uapi/linux/sctp.h | 3 ++
include/uapi/linux/sem.h | 38 ++++++++++++++
include/uapi/linux/socket.h | 7 +++
include/uapi/linux/sysctl.h | 32 ++++++++++++
include/uapi/linux/uhid.h | 7 +++
include/uapi/linux/uio.h | 11 ++++
include/uapi/linux/usb/tmc.h | 14 ++++++
include/uapi/linux/usbdevice_fs.h | 50 +++++++++++++++++++
include/uapi/linux/uvcvideo.h | 14 ++++++
include/uapi/linux/vfio.h | 7 +++
include/uapi/linux/videodev2.h | 7 +++
27 files changed, 458 insertions(+)
diff --git a/include/linux/socket.h b/include/linux/socket.h
index d18cc47e89bd..a1bc6e2b809e 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -81,12 +81,47 @@ struct msghdr {
};
struct user_msghdr {
+#if __riscv_xlen == 64
+ union {
+ void __user *msg_name; /* ptr to socket address structure */
+ u64 __msg_name;
+ };
+#else
void __user *msg_name; /* ptr to socket address structure */
+#endif
int msg_namelen; /* size of socket address structure */
+#if __riscv_xlen == 64
+ union {
+ struct iovec __user *msg_iov; /* scatter/gather array */
+ u64 __msg_iov;
+ };
+#else
struct iovec __user *msg_iov; /* scatter/gather array */
+#endif
+#if __riscv_xlen == 64
+ union {
+ __kernel_size_t msg_iovlen; /* # elements in msg_iov */
+ u64 __msg_iovlen;
+ };
+#else
__kernel_size_t msg_iovlen; /* # elements in msg_iov */
+#endif
+#if __riscv_xlen == 64
+ union {
+ void __user *msg_control; /* ancillary data */
+ u64 __msg_control;
+ };
+#else
void __user *msg_control; /* ancillary data */
+#endif
+#if __riscv_xlen == 64
+ union {
+ __kernel_size_t msg_controllen; /* ancillary data buffer length */
+ u64 __msg_controllen;
+ };
+#else
__kernel_size_t msg_controllen; /* ancillary data buffer length */
+#endif
unsigned int msg_flags; /* flags on received message */
};
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h
index 5a1ca43b5fc6..5c87b85d7858 100644
--- a/include/uapi/asm-generic/siginfo.h
+++ b/include/uapi/asm-generic/siginfo.h
@@ -7,7 +7,14 @@
typedef union sigval {
int sival_int;
+#if __riscv_xlen == 64
+ union {
+ void __user *sival_ptr;
+ __u64 __sival_ptr;
+ };
+#else
void __user *sival_ptr;
+#endif
} sigval_t;
#define SI_MAX_SIZE 128
@@ -67,7 +74,14 @@ union __sifields {
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
struct {
+#if __riscv_xlen == 64
+ union {
+ void __user *_addr; /* faulting insn/memory ref. */
+ __u64 ___addr;
+ };
+#else
void __user *_addr; /* faulting insn/memory ref. */
+#endif
#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \
sizeof(short) : __alignof__(void *))
@@ -82,8 +96,23 @@ union __sifields {
/* used when si_code=SEGV_BNDERR */
struct {
char _dummy_bnd[__ADDR_BND_PKEY_PAD];
+#if __riscv_xlen == 64
+ union {
+ void __user *_lower;
+ __u64 ___lower;
+ };
+#else
void __user *_lower;
+#endif
+
+#if __riscv_xlen == 64
+ union {
+ void __user *_upper;
+ __u64 ___upper;
+ };
+#else
void __user *_upper;
+#endif
} _addr_bnd;
/* used when si_code=SEGV_PKUERR */
struct {
@@ -92,7 +121,14 @@ union __sifields {
} _addr_pkey;
/* used when si_code=TRAP_PERF */
struct {
+#if __riscv_xlen == 64
+ union {
+ unsigned long _data;
+ __u64 ___data;
+ };
+#else
unsigned long _data;
+#endif
__u32 _type;
__u32 _flags;
} _perf;
@@ -101,13 +137,27 @@ union __sifields {
/* SIGPOLL */
struct {
+#if __riscv_xlen == 64
+ union {
+ __ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */
+ __u64 ___band;
+ };
+#else
__ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */
+#endif
int _fd;
} _sigpoll;
/* SIGSYS */
struct {
+#if __riscv_xlen == 64
+ union {
+ void __user *_call_addr; /* calling user insn */
+ __u64 ___call_addr;
+ };
+#else
void __user *_call_addr; /* calling user insn */
+#endif
int _syscall; /* triggering system call number */
unsigned int _arch; /* AUDIT_ARCH_* of syscall */
} _sigsys;
diff --git a/include/uapi/asm-generic/signal.h b/include/uapi/asm-generic/signal.h
index 0eb69dc8e572..efcd31a677ee 100644
--- a/include/uapi/asm-generic/signal.h
+++ b/include/uapi/asm-generic/signal.h
@@ -73,19 +73,54 @@ typedef unsigned long old_sigset_t;
#ifndef __KERNEL__
struct sigaction {
+#if __riscv_xlen == 64
+ union {
+ __sighandler_t sa_handler;
+ __u64 __sa_handler;
+ };
+#else
__sighandler_t sa_handler;
+#endif
+#if __riscv_xlen == 64
+ union {
+ unsigned long sa_flags;
+ __u64 __sa_flags;
+ };
+#else
unsigned long sa_flags;
+#endif
#ifdef SA_RESTORER
+#if __riscv_xlen == 64
+ union {
+ __sigrestore_t sa_restorer;
+ __u64 __sa_restorer;
+ };
+#else
__sigrestore_t sa_restorer;
+#endif
#endif
sigset_t sa_mask; /* mask last for extensibility */
};
#endif
typedef struct sigaltstack {
+#if __riscv_xlen == 64
+ union {
+ void __user *ss_sp;
+ __u64 __ss_sp;
+ };
+#else
void __user *ss_sp;
+#endif
int ss_flags;
+#if __riscv_xlen == 64
+ union {
+ __kernel_size_t ss_size;
+ __u64 __ss_size;
+ };
+#else
__kernel_size_t ss_size;
+#endif
} stack_t;
#endif /* __ASSEMBLY__ */
diff --git a/include/uapi/asm-generic/stat.h b/include/uapi/asm-generic/stat.h
index 0d962ecd1663..c8908df5213f 100644
--- a/include/uapi/asm-generic/stat.h
+++ b/include/uapi/asm-generic/stat.h
@@ -21,6 +21,30 @@
#define STAT_HAVE_NSEC 1
+#if __riscv_xlen == 64
+struct stat {
+ unsigned long long st_dev; /* Device. */
+ unsigned long long st_ino; /* File serial number. */
+ unsigned int st_mode; /* File mode. */
+ unsigned int st_nlink; /* Link count. */
+ unsigned int st_uid; /* User ID of the file's owner. */
+ unsigned int st_gid; /* Group ID of the file's group. */
+ unsigned long long st_rdev; /* Device number, if device. */
+ unsigned long long __pad1;
+ long long st_size; /* Size of file, in bytes. */
+ int st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ long long st_blocks; /* Number 512-byte blocks allocated. */
+ long long st_atime; /* Time of last access. */
+ unsigned long long st_atime_nsec;
+ long long st_mtime; /* Time of last modification. */
+ unsigned long long st_mtime_nsec;
+ long long st_ctime; /* Time of last status change. */
+ unsigned long long st_ctime_nsec;
+ unsigned int __unused4;
+ unsigned int __unused5;
+};
+#else
struct stat {
unsigned long st_dev; /* Device. */
unsigned long st_ino; /* File serial number. */
@@ -43,6 +67,7 @@ struct stat {
unsigned int __unused4;
unsigned int __unused5;
};
+#endif
/* This matches struct stat64 in glibc2.1. Only used for 32 bit. */
#if __BITS_PER_LONG != 64 || defined(__ARCH_WANT_STAT64)
diff --git a/include/uapi/linux/atm.h b/include/uapi/linux/atm.h
index 95ebdcf4fe88..fe0da6a5e26d 100644
--- a/include/uapi/linux/atm.h
+++ b/include/uapi/linux/atm.h
@@ -234,7 +234,14 @@ static __inline__ int atmpvc_addr_in_use(struct sockaddr_atmpvc addr)
struct atmif_sioc {
int number;
int length;
+#if __riscv_xlen == 64
+ union {
+ void __user *arg;
+ __u64 __arg;
+ };
+#else
void __user *arg;
+#endif
};
diff --git a/include/uapi/linux/atmdev.h b/include/uapi/linux/atmdev.h
index 20b0215084fc..e0456ed8b698 100644
--- a/include/uapi/linux/atmdev.h
+++ b/include/uapi/linux/atmdev.h
@@ -155,7 +155,14 @@ struct atm_dev_stats {
struct atm_iobuf {
int length;
+#if __riscv_xlen == 64
+ union {
+ void __user *buffer;
+ __u64 __buffer;
+ };
+#else
void __user *buffer;
+#endif
};
/* for ATM_GETCIRANGE / ATM_SETCIRANGE */
diff --git a/include/uapi/linux/blkpg.h b/include/uapi/linux/blkpg.h
index d0a64ee97c6d..31f70c9114c2 100644
--- a/include/uapi/linux/blkpg.h
+++ b/include/uapi/linux/blkpg.h
@@ -12,7 +12,14 @@ struct blkpg_ioctl_arg {
int op;
int flags;
int datalen;
+#if __riscv_xlen == 64
+ union {
+ void __user *data;
+ __u64 __data;
+ };
+#else
void __user *data;
+#endif
};
/* The subfunctions (for the op field) */
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index d3b222d7af24..25a9570cbb1c 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -838,7 +838,14 @@ struct btrfs_ioctl_received_subvol_args {
struct btrfs_ioctl_send_args {
__s64 send_fd; /* in */
__u64 clone_sources_count; /* in */
+#if __riscv_xlen == 64
+ union {
+ __u64 __user *clone_sources; /* in */
+ __u64 __pad;
+ };
+#else
__u64 __user *clone_sources; /* in */
+#endif
__u64 parent_root; /* in */
__u64 flags; /* in */
__u32 version; /* in */
@@ -959,9 +966,21 @@ struct btrfs_ioctl_encoded_io_args {
* increase in the future). This must also be less than or equal to
* unencoded_len.
*/
+#if __riscv_xlen == 64
+ union {
+ const struct iovec __user *iov;
+ const __u64 __iov;
+ };
+ /* Number of iovecs. */
+ union {
+ unsigned long iovcnt;
+ __u64 __iovcnt;
+ };
+#else
const struct iovec __user *iov;
/* Number of iovecs. */
unsigned long iovcnt;
+#endif
/*
* Offset in file.
*
diff --git a/include/uapi/linux/capi.h b/include/uapi/linux/capi.h
index 31f946f8a88d..dab4bb8e3ebb 100644
--- a/include/uapi/linux/capi.h
+++ b/include/uapi/linux/capi.h
@@ -77,8 +77,19 @@ typedef struct capi_profile {
#define CAPI_GET_PROFILE _IOWR('C',0x09,struct capi_profile)
typedef struct capi_manufacturer_cmd {
+#if __riscv_xlen == 64
+ union {
+ unsigned long cmd;
+ __u64 __cmd;
+ };
+ union {
+ void __user *data;
+ __u64 __data;
+ };
+#else
unsigned long cmd;
void __user *data;
+#endif
} capi_manufacturer_cmd;
/*
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 2bbe00cf1248..3ccd123a23a2 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -122,15 +122,27 @@ struct file_dedupe_range {
/* And dynamically-tunable limits and defaults: */
struct files_stat_struct {
+#if __riscv_xlen == 64
+ unsigned long long nr_files; /* read only */
+ unsigned long long nr_free_files; /* read only */
+ unsigned long long max_files; /* tunable */
+#else
unsigned long nr_files; /* read only */
unsigned long nr_free_files; /* read only */
unsigned long max_files; /* tunable */
+#endif
};
struct inodes_stat_t {
+#if __riscv_xlen == 64
+ long long nr_inodes;
+ long long nr_unused;
+ long long dummy[5]; /* padding for sysctl ABI compatibility */
+#else
long nr_inodes;
long nr_unused;
long dummy[5]; /* padding for sysctl ABI compatibility */
+#endif
};
diff --git a/include/uapi/linux/futex.h b/include/uapi/linux/futex.h
index d2ee625ea189..ae4ee8a66de1 100644
--- a/include/uapi/linux/futex.h
+++ b/include/uapi/linux/futex.h
@@ -108,7 +108,14 @@ struct futex_waitv {
* changed.
*/
struct robust_list {
+#if __riscv_xlen == 64
+ union {
+ struct robust_list __user *next;
+ u64 __next;
+ };
+#else
struct robust_list __user *next;
+#endif
};
/*
@@ -131,7 +138,11 @@ struct robust_list_head {
* we keep userspace flexible, to freely shape its data-structure,
* without hardcoding any particular offset into the kernel:
*/
+#if __riscv_xlen == 64
+ long long futex_offset;
+#else
long futex_offset;
+#endif
/*
* The death of the thread may race with userspace setting
@@ -143,7 +154,14 @@ struct robust_list_head {
* _might_ have taken. We check the owner TID in any case,
* so only truly owned locks will be handled.
*/
+#if __riscv_xlen == 64
+ union {
+ struct robust_list __user *list_op_pending;
+ u64 __list_op_pending;
+ };
+#else
struct robust_list __user *list_op_pending;
+#endif
};
/*
diff --git a/include/uapi/linux/if.h b/include/uapi/linux/if.h
index 797ba2c1562a..232ab74922fe 100644
--- a/include/uapi/linux/if.h
+++ b/include/uapi/linux/if.h
@@ -219,6 +219,9 @@ struct if_settings {
/* interface settings */
sync_serial_settings __user *sync;
te1_settings __user *te1;
+#if __riscv_xlen == 64
+ __u64 unused;
+#endif
} ifs_ifsu;
};
@@ -288,6 +291,9 @@ struct ifconf {
union {
char __user *ifcu_buf;
struct ifreq __user *ifcu_req;
+#if __riscv_xlen == 64
+ __u64 unused;
+#endif
} ifc_ifcu;
};
#endif /* __UAPI_DEF_IF_IFCONF */
diff --git a/include/uapi/linux/netfilter/x_tables.h b/include/uapi/linux/netfilter/x_tables.h
index 796af83a963a..7e02e34c6fad 100644
--- a/include/uapi/linux/netfilter/x_tables.h
+++ b/include/uapi/linux/netfilter/x_tables.h
@@ -18,7 +18,11 @@ struct xt_entry_match {
__u8 revision;
} user;
struct {
+#if __riscv_xlen == 64
+ __u64 match_size;
+#else
__u16 match_size;
+#endif
/* Used inside the kernel */
struct xt_match *match;
@@ -41,7 +45,11 @@ struct xt_entry_target {
__u8 revision;
} user;
struct {
+#if __riscv_xlen == 64
+ __u64 target_size;
+#else
__u16 target_size;
+#endif
/* Used inside the kernel */
struct xt_target *target;
diff --git a/include/uapi/linux/netfilter_ipv4/ip_tables.h b/include/uapi/linux/netfilter_ipv4/ip_tables.h
index 1485df28b239..3a78f8f7bf5d 100644
--- a/include/uapi/linux/netfilter_ipv4/ip_tables.h
+++ b/include/uapi/linux/netfilter_ipv4/ip_tables.h
@@ -200,7 +200,14 @@ struct ipt_replace {
/* Number of counters (must be equal to current number of entries). */
unsigned int num_counters;
/* The old entries' counters. */
+#if __riscv_xlen == 64
+ union {
+ struct xt_counters __user *counters;
+ __u64 __counters;
+ };
+#else
struct xt_counters __user *counters;
+#endif
/* The entries (hang off end: not really an array). */
struct ipt_entry entries[];
diff --git a/include/uapi/linux/nfs4_mount.h b/include/uapi/linux/nfs4_mount.h
index d20bb869bb99..6ec3cec66b6f 100644
--- a/include/uapi/linux/nfs4_mount.h
+++ b/include/uapi/linux/nfs4_mount.h
@@ -21,7 +21,14 @@
struct nfs_string {
unsigned int len;
+#if __riscv_xlen == 64
+ union {
+ const char __user * data;
+ __u64 __data;
+ };
+#else
const char __user * data;
+#endif
};
struct nfs4_mount_data {
@@ -53,7 +60,14 @@ struct nfs4_mount_data {
/* Pseudo-flavours to use for authentication. See RFC2623 */
int auth_flavourlen; /* 1 */
+#if __riscv_xlen == 64
+ union {
+ int __user *auth_flavours; /* 1 */
+ __u64 __auth_flavours;
+ };
+#else
int __user *auth_flavours; /* 1 */
+#endif
};
/* bits in the flags field */
diff --git a/include/uapi/linux/ppp-ioctl.h b/include/uapi/linux/ppp-ioctl.h
index 1cc5ce0ae062..8d48eab430c1 100644
--- a/include/uapi/linux/ppp-ioctl.h
+++ b/include/uapi/linux/ppp-ioctl.h
@@ -59,7 +59,14 @@ struct npioctl {
/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
struct ppp_option_data {
+#if __riscv_xlen == 64
+ union {
+ __u8 __user *ptr;
+ __u64 __ptr;
+ };
+#else
__u8 __user *ptr;
+#endif
__u32 length;
int transmit;
};
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index b7d91d4cf0db..46a06fddcd2f 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -1024,6 +1024,9 @@ struct sctp_getaddrs_old {
#else
struct sockaddr *addrs;
#endif
+#if (__riscv_xlen == 64) && (__SIZEOF_LONG__ == 4)
+ __u32 unused;
+#endif
};
struct sctp_getaddrs {
diff --git a/include/uapi/linux/sem.h b/include/uapi/linux/sem.h
index 75aa3b273cd9..de9f441913cd 100644
--- a/include/uapi/linux/sem.h
+++ b/include/uapi/linux/sem.h
@@ -26,10 +26,29 @@ struct semid_ds {
struct ipc_perm sem_perm; /* permissions .. see ipc.h */
__kernel_old_time_t sem_otime; /* last semop time */
__kernel_old_time_t sem_ctime; /* create/last semctl() time */
+#if __riscv_xlen == 64
+ union {
+ struct sem *sem_base; /* ptr to first semaphore in array */
+ __u64 __sem_base;
+ };
+ union {
+ struct sem_queue *sem_pending; /* pending operations to be processed */
+ __u64 __sem_pending;
+ };
+ union {
+ struct sem_queue **sem_pending_last; /* last pending operation */
+ __u64 __sem_pending_last;
+ };
+ union {
+ struct sem_undo *undo; /* undo requests on this array */
+ __u64 __undo;
+ };
+#else
struct sem *sem_base; /* ptr to first semaphore in array */
struct sem_queue *sem_pending; /* pending operations to be processed */
struct sem_queue **sem_pending_last; /* last pending operation */
struct sem_undo *undo; /* undo requests on this array */
+#endif
unsigned short sem_nsems; /* no. of semaphores in array */
};
@@ -46,10 +65,29 @@ struct sembuf {
/* arg for semctl system calls. */
union semun {
int val; /* value for SETVAL */
+#if __riscv_xlen == 64
+ union {
+ struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
+ __u64 ___buf;
+ };
+ union {
+ unsigned short __user *array; /* array for GETALL & SETALL */
+ __u64 __array;
+ };
+ union {
+ struct seminfo __user *__buf; /* buffer for IPC_INFO */
+ __u64 ____buf;
+ };
+ union {
+ void __user *__pad;
+ __u64 ____pad;
+ };
+#else
struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
unsigned short __user *array; /* array for GETALL & SETALL */
struct seminfo __user *__buf; /* buffer for IPC_INFO */
void __user *__pad;
+#endif
};
struct seminfo {
diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
index d3fcd3b5ec53..5f7a83649395 100644
--- a/include/uapi/linux/socket.h
+++ b/include/uapi/linux/socket.h
@@ -22,7 +22,14 @@ struct __kernel_sockaddr_storage {
/* space to achieve desired size, */
/* _SS_MAXSIZE value minus size of ss_family */
};
+#if __riscv_xlen == 64
+ union {
+ void *__align; /* implementation specific desired alignment */
+ u64 ___align;
+ };
+#else
void *__align; /* implementation specific desired alignment */
+#endif
};
};
diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
index 8981f00204db..8ed7b29897f9 100644
--- a/include/uapi/linux/sysctl.h
+++ b/include/uapi/linux/sysctl.h
@@ -33,13 +33,45 @@
member of a struct __sysctl_args to have? */
struct __sysctl_args {
+#if __riscv_xlen == 64
+ union {
+ int __user *name;
+ __u64 __name;
+ };
+#else
int __user *name;
+#endif
int nlen;
+#if __riscv_xlen == 64
+ union {
+ void __user *oldval;
+ __u64 __oldval;
+ };
+#else
void __user *oldval;
+#endif
+#if __riscv_xlen == 64
+ union {
+ size_t __user *oldlenp;
+ __u64 __oldlenp;
+ };
+#else
size_t __user *oldlenp;
+#endif
+#if __riscv_xlen == 64
+ union {
+ void __user *newval;
+ __u64 __newval;
+ };
+#else
void __user *newval;
+#endif
size_t newlen;
+#if __riscv_xlen == 64
+ unsigned long long __unused[4];
+#else
unsigned long __unused[4];
+#endif
};
/* Define sysctl names first */
diff --git a/include/uapi/linux/uhid.h b/include/uapi/linux/uhid.h
index cef7534d2d19..4a774dbd3de8 100644
--- a/include/uapi/linux/uhid.h
+++ b/include/uapi/linux/uhid.h
@@ -130,7 +130,14 @@ struct uhid_create_req {
__u8 name[128];
__u8 phys[64];
__u8 uniq[64];
+#if __riscv_xlen == 64
+ union {
+ __u8 __user *rd_data;
+ __u64 __rd_data;
+ };
+#else
__u8 __user *rd_data;
+#endif
__u16 rd_size;
__u16 bus;
diff --git a/include/uapi/linux/uio.h b/include/uapi/linux/uio.h
index 649739e0c404..27dfd6032dc6 100644
--- a/include/uapi/linux/uio.h
+++ b/include/uapi/linux/uio.h
@@ -16,8 +16,19 @@
struct iovec
{
+#if __riscv_xlen == 64
+ union {
+ void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
+ __u64 __iov_base;
+ };
+ union {
+ __kernel_size_t iov_len; /* Must be size_t (1003.1g) */
+ __u64 __iov_len;
+ };
+#else
void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
__kernel_size_t iov_len; /* Must be size_t (1003.1g) */
+#endif
};
struct dmabuf_cmsg {
diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
index d791cc58a7f0..443ec5356caf 100644
--- a/include/uapi/linux/usb/tmc.h
+++ b/include/uapi/linux/usb/tmc.h
@@ -51,7 +51,14 @@ struct usbtmc_request {
struct usbtmc_ctrlrequest {
struct usbtmc_request req;
+#if __riscv_xlen == 64
+ union {
+ void __user *data; /* pointer to user space */
+ __u64 __data; /* pointer to user space */
+ };
+#else
void __user *data; /* pointer to user space */
+#endif
} __attribute__ ((packed));
struct usbtmc_termchar {
@@ -70,7 +77,14 @@ struct usbtmc_message {
__u32 transfer_size; /* size of bytes to transfer */
__u32 transferred; /* size of received/written bytes */
__u32 flags; /* bit 0: 0 = synchronous; 1 = asynchronous */
+#if __riscv_xlen == 64
+ union {
+ void __user *message; /* pointer to header and data in user space */
+ __u64 __message;
+ };
+#else
void __user *message; /* pointer to header and data in user space */
+#endif
} __attribute__ ((packed));
/* Request values for USBTMC driver's ioctl entry point */
diff --git a/include/uapi/linux/usbdevice_fs.h b/include/uapi/linux/usbdevice_fs.h
index 74a84e02422a..8c8efef74c3c 100644
--- a/include/uapi/linux/usbdevice_fs.h
+++ b/include/uapi/linux/usbdevice_fs.h
@@ -44,14 +44,28 @@ struct usbdevfs_ctrltransfer {
__u16 wIndex;
__u16 wLength;
__u32 timeout; /* in milliseconds */
+#if __riscv_xlen == 64
+ union {
+ void __user *data;
+ __u64 __data;
+ };
+#else
void __user *data;
+#endif
};
struct usbdevfs_bulktransfer {
unsigned int ep;
unsigned int len;
unsigned int timeout; /* in milliseconds */
+#if __riscv_xlen == 64
+ union {
+ void __user *data;
+ __u64 __data;
+ };
+#else
void __user *data;
+#endif
};
struct usbdevfs_setinterface {
@@ -61,7 +75,14 @@ struct usbdevfs_setinterface {
struct usbdevfs_disconnectsignal {
unsigned int signr;
+#if __riscv_xlen == 64
+ union {
+ void __user *context;
+ __u64 __context;
+ };
+#else
void __user *context;
+#endif
};
#define USBDEVFS_MAXDRIVERNAME 255
@@ -119,7 +140,14 @@ struct usbdevfs_urb {
unsigned char endpoint;
int status;
unsigned int flags;
+#if __riscv_xlen == 64
+ union {
+ void __user *buffer;
+ __u64 __buffer;
+ };
+#else
void __user *buffer;
+#endif
int buffer_length;
int actual_length;
int start_frame;
@@ -130,7 +158,14 @@ struct usbdevfs_urb {
int error_count;
unsigned int signr; /* signal to be sent on completion,
or 0 if none should be sent. */
+#if __riscv_xlen == 64
+ union {
+ void __user *usercontext;
+ __u64 __usercontext;
+ };
+#else
void __user *usercontext;
+#endif
struct usbdevfs_iso_packet_desc iso_frame_desc[];
};
@@ -139,7 +174,14 @@ struct usbdevfs_ioctl {
int ifno; /* interface 0..N ; negative numbers reserved */
int ioctl_code; /* MUST encode size + direction of data so the
* macros in <asm/ioctl.h> give correct values */
+#if __riscv_xlen == 64
+ union {
+ void __user *data; /* param buffer (in, or out) */
+ __u64 __pad;
+ };
+#else
void __user *data; /* param buffer (in, or out) */
+#endif
};
/* You can do most things with hubs just through control messages,
@@ -195,9 +237,17 @@ struct usbdevfs_streams {
#define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb)
#define USBDEVFS_SUBMITURB32 _IOR('U', 10, struct usbdevfs_urb32)
#define USBDEVFS_DISCARDURB _IO('U', 11)
+#if __riscv_xlen == 64
+#define USBDEVFS_REAPURB _IOW('U', 12, __u64)
+#else
#define USBDEVFS_REAPURB _IOW('U', 12, void *)
+#endif
#define USBDEVFS_REAPURB32 _IOW('U', 12, __u32)
+#if __riscv_xlen == 64
+#define USBDEVFS_REAPURBNDELAY _IOW('U', 13, __u64)
+#else
#define USBDEVFS_REAPURBNDELAY _IOW('U', 13, void *)
+#endif
#define USBDEVFS_REAPURBNDELAY32 _IOW('U', 13, __u32)
#define USBDEVFS_DISCSIGNAL _IOR('U', 14, struct usbdevfs_disconnectsignal)
#define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h
index f86185456dc5..3ccb99039a43 100644
--- a/include/uapi/linux/uvcvideo.h
+++ b/include/uapi/linux/uvcvideo.h
@@ -54,7 +54,14 @@ struct uvc_xu_control_mapping {
__u32 v4l2_type;
__u32 data_type;
+#if __riscv_xlen == 64
+ union {
+ struct uvc_menu_info __user *menu_info;
+ __u64 __menu_info;
+ };
+#else
struct uvc_menu_info __user *menu_info;
+#endif
__u32 menu_count;
__u32 reserved[4];
@@ -66,7 +73,14 @@ struct uvc_xu_control_query {
__u8 query; /* Video Class-Specific Request Code, */
/* defined in linux/usb/video.h A.8. */
__u16 size;
+#if __riscv_xlen == 64
+ union {
+ __u8 __user *data;
+ __u64 __data;
+ };
+#else
__u8 __user *data;
+#endif
};
#define UVCIOC_CTRL_MAP _IOWR('u', 0x20, struct uvc_xu_control_mapping)
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index c8dbf8219c4f..0a1dc2a780fb 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -1570,7 +1570,14 @@ struct vfio_iommu_type1_dma_map {
struct vfio_bitmap {
__u64 pgsize; /* page size for bitmap in bytes */
__u64 size; /* in bytes */
+ #if __riscv_xlen == 64
+ union {
+ __u64 __user *data; /* one bit per page */
+ __u64 __data;
+ };
+ #else
__u64 __user *data; /* one bit per page */
+ #endif
};
/**
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index e7c4dce39007..8e5391f07626 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1898,7 +1898,14 @@ struct v4l2_ext_controls {
__u32 error_idx;
__s32 request_fd;
__u32 reserved[1];
+#if __riscv_xlen == 64
+ union {
+ struct v4l2_ext_control *controls;
+ __u64 __controls;
+ };
+#else
struct v4l2_ext_control *controls;
+#endif
};
#define V4L2_CTRL_ID_MASK (0x0fffffff)
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 02/43] rv64ilp32_abi: riscv: Adapt Makefile and Kconfig
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
2025-03-25 12:15 ` [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 03/43] rv64ilp32_abi: riscv: Adapt ULL & UL definition guoren
` (42 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
Extend the ARCH_RV64I base with ABI_RV64ILP32 to compile the Linux
kernel self into ILP32 on CONFIG_64BIT=y, minimizing the kernel's
memory footprint and cache occupation.
The 'cmd_cpp_lds_S' in scripts/Makefile.build uses cpp_flags for
ld.s generation, so add "-mabi=xxx" to KBUILD_CPPFLAGS, just like
what we've done in KBUILD_CLFAGS and KBUILD_AFLAGS.
cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH)
The rv64ilp32 ABI reuses an rv64 toolchain whose default "-mabi="
is lp64, so add "-mabi=ilp32" to correct it.
Add config entry with rv64ilp32.config fragment in Makefile:
- rv64ilp32_defconfig
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/Kconfig | 12 ++++++++++--
arch/riscv/Makefile | 17 +++++++++++++++++
arch/riscv/configs/rv64ilp32.config | 1 +
3 files changed, 28 insertions(+), 2 deletions(-)
create mode 100644 arch/riscv/configs/rv64ilp32.config
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 7612c52e9b1e..da2111b0111c 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -213,7 +213,7 @@ config RISCV
select TRACE_IRQFLAGS_SUPPORT
select UACCESS_MEMCPY if !MMU
select USER_STACKTRACE_SUPPORT
- select ZONE_DMA32 if 64BIT
+ select ZONE_DMA32 if 64BIT && !ABI_RV64ILP32
config RUSTC_SUPPORTS_RISCV
def_bool y
@@ -298,6 +298,7 @@ config PAGE_OFFSET
config KASAN_SHADOW_OFFSET
hex
depends on KASAN_GENERIC
+ default 0x70000000 if ABI_RV64ILP32
default 0xdfffffff00000000 if 64BIT
default 0xffffffff if 32BIT
@@ -341,7 +342,7 @@ config FIX_EARLYCON_MEM
config ILLEGAL_POINTER_VALUE
hex
- default 0 if 32BIT
+ default 0 if 32BIT || ABI_RV64ILP32
default 0xdead000000000000 if 64BIT
config PGTABLE_LEVELS
@@ -418,6 +419,13 @@ config ARCH_RV64I
endchoice
+config ABI_RV64ILP32
+ bool "ABI RV64ILP32"
+ depends on 64BIT
+ help
+ Compile linux kernel self into RV64ILP32 ABI of RISC-V psabi
+ specification.
+
# We must be able to map all physical memory into the kernel, but the compiler
# is still a bit more efficient when generating code if it's setup in a manner
# such that it can only map 2GiB of memory.
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 13fbc0f94238..76db01020a22 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -30,10 +30,21 @@ ifeq ($(CONFIG_ARCH_RV64I),y)
BITS := 64
UTS_MACHINE := riscv64
+ifeq ($(CONFIG_ABI_RV64ILP32),y)
+ KBUILD_CPPFLAGS += -mabi=ilp32
+
+ KBUILD_CFLAGS += -mabi=ilp32
+ KBUILD_AFLAGS += -mabi=ilp32
+
+ KBUILD_LDFLAGS += -melf32lriscv
+else
+ KBUILD_CPPFLAGS += -mabi=lp64
+
KBUILD_CFLAGS += -mabi=lp64
KBUILD_AFLAGS += -mabi=lp64
KBUILD_LDFLAGS += -melf64lriscv
+endif
KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 --target=riscv64imac-unknown-none-elf \
-Cno-redzone
@@ -41,6 +52,8 @@ else
BITS := 32
UTS_MACHINE := riscv32
+ KBUILD_CPPFLAGS += -mabi=ilp32
+
KBUILD_CFLAGS += -mabi=ilp32
KBUILD_AFLAGS += -mabi=ilp32
KBUILD_LDFLAGS += -melf32lriscv
@@ -224,6 +237,10 @@ PHONY += rv32_nommu_virt_defconfig
rv32_nommu_virt_defconfig:
$(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config
+PHONY += rv64ilp32_defconfig
+rv64ilp32_defconfig:
+ $(Q)$(MAKE) -f $(srctree)/Makefile defconfig rv64ilp32.config
+
define archhelp
echo ' Image - Uncompressed kernel image (arch/riscv/boot/Image)'
echo ' Image.gz - Compressed kernel image (arch/riscv/boot/Image.gz)'
diff --git a/arch/riscv/configs/rv64ilp32.config b/arch/riscv/configs/rv64ilp32.config
new file mode 100644
index 000000000000..07536586e169
--- /dev/null
+++ b/arch/riscv/configs/rv64ilp32.config
@@ -0,0 +1 @@
+CONFIG_ABI_RV64ILP32=y
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 03/43] rv64ilp32_abi: riscv: Adapt ULL & UL definition
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
2025-03-25 12:15 ` [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface guoren
2025-03-25 12:15 ` [RFC PATCH V3 02/43] rv64ilp32_abi: riscv: Adapt Makefile and Kconfig guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 04/43] rv64ilp32_abi: riscv: Introduce xlen_t to adapt __riscv_xlen != BITS_PER_LONG guoren
` (41 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
On 64-bit systems with ILP32 ABI, BITS_PER_LONG is 32, making the
register width different from UL's. Thus, correct them into ULL.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/cmpxchg.h | 4 +-
arch/riscv/include/asm/csr.h | 212 ++++++++++++++++---------------
arch/riscv/net/bpf_jit_comp64.c | 6 +-
3 files changed, 115 insertions(+), 107 deletions(-)
diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
index 4cadc56220fe..938d50194dba 100644
--- a/arch/riscv/include/asm/cmpxchg.h
+++ b/arch/riscv/include/asm/cmpxchg.h
@@ -29,7 +29,7 @@
} else { \
u32 *__ptr32b = (u32 *)((ulong)(p) & ~0x3); \
ulong __s = ((ulong)(p) & (0x4 - sizeof(*p))) * BITS_PER_BYTE; \
- ulong __mask = GENMASK(((sizeof(*p)) * BITS_PER_BYTE) - 1, 0) \
+ ulong __mask = GENMASK_ULL(((sizeof(*p)) * BITS_PER_BYTE) - 1, 0) \
<< __s; \
ulong __newx = (ulong)(n) << __s; \
ulong __retx; \
@@ -145,7 +145,7 @@
} else { \
u32 *__ptr32b = (u32 *)((ulong)(p) & ~0x3); \
ulong __s = ((ulong)(p) & (0x4 - sizeof(*p))) * BITS_PER_BYTE; \
- ulong __mask = GENMASK(((sizeof(*p)) * BITS_PER_BYTE) - 1, 0) \
+ ulong __mask = GENMASK_ULL(((sizeof(*p)) * BITS_PER_BYTE) - 1, 0) \
<< __s; \
ulong __newx = (ulong)(n) << __s; \
ulong __oldx = (ulong)(o) << __s; \
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 6fed42e37705..25f7c5afea3a 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -9,74 +9,82 @@
#include <asm/asm.h>
#include <linux/bits.h>
+#if __riscv_xlen == 64
+#define UXL ULL
+#define GENMASK_UXL GENMASK_ULL
+#else
+#define UXL UL
+#define GENMASK_UXL GENMASK
+#endif
+
/* Status register flags */
-#define SR_SIE _AC(0x00000002, UL) /* Supervisor Interrupt Enable */
-#define SR_MIE _AC(0x00000008, UL) /* Machine Interrupt Enable */
-#define SR_SPIE _AC(0x00000020, UL) /* Previous Supervisor IE */
-#define SR_MPIE _AC(0x00000080, UL) /* Previous Machine IE */
-#define SR_SPP _AC(0x00000100, UL) /* Previously Supervisor */
-#define SR_MPP _AC(0x00001800, UL) /* Previously Machine */
-#define SR_SUM _AC(0x00040000, UL) /* Supervisor User Memory Access */
-
-#define SR_FS _AC(0x00006000, UL) /* Floating-point Status */
-#define SR_FS_OFF _AC(0x00000000, UL)
-#define SR_FS_INITIAL _AC(0x00002000, UL)
-#define SR_FS_CLEAN _AC(0x00004000, UL)
-#define SR_FS_DIRTY _AC(0x00006000, UL)
-
-#define SR_VS _AC(0x00000600, UL) /* Vector Status */
-#define SR_VS_OFF _AC(0x00000000, UL)
-#define SR_VS_INITIAL _AC(0x00000200, UL)
-#define SR_VS_CLEAN _AC(0x00000400, UL)
-#define SR_VS_DIRTY _AC(0x00000600, UL)
-
-#define SR_VS_THEAD _AC(0x01800000, UL) /* xtheadvector Status */
-#define SR_VS_OFF_THEAD _AC(0x00000000, UL)
-#define SR_VS_INITIAL_THEAD _AC(0x00800000, UL)
-#define SR_VS_CLEAN_THEAD _AC(0x01000000, UL)
-#define SR_VS_DIRTY_THEAD _AC(0x01800000, UL)
-
-#define SR_XS _AC(0x00018000, UL) /* Extension Status */
-#define SR_XS_OFF _AC(0x00000000, UL)
-#define SR_XS_INITIAL _AC(0x00008000, UL)
-#define SR_XS_CLEAN _AC(0x00010000, UL)
-#define SR_XS_DIRTY _AC(0x00018000, UL)
+#define SR_SIE _AC(0x00000002, UXL) /* Supervisor Interrupt Enable */
+#define SR_MIE _AC(0x00000008, UXL) /* Machine Interrupt Enable */
+#define SR_SPIE _AC(0x00000020, UXL) /* Previous Supervisor IE */
+#define SR_MPIE _AC(0x00000080, UXL) /* Previous Machine IE */
+#define SR_SPP _AC(0x00000100, UXL) /* Previously Supervisor */
+#define SR_MPP _AC(0x00001800, UXL) /* Previously Machine */
+#define SR_SUM _AC(0x00040000, UXL) /* Supervisor User Memory Access */
+
+#define SR_FS _AC(0x00006000, UXL) /* Floating-point Status */
+#define SR_FS_OFF _AC(0x00000000, UXL)
+#define SR_FS_INITIAL _AC(0x00002000, UXL)
+#define SR_FS_CLEAN _AC(0x00004000, UXL)
+#define SR_FS_DIRTY _AC(0x00006000, UXL)
+
+#define SR_VS _AC(0x00000600, UXL) /* Vector Status */
+#define SR_VS_OFF _AC(0x00000000, UXL)
+#define SR_VS_INITIAL _AC(0x00000200, UXL)
+#define SR_VS_CLEAN _AC(0x00000400, UXL)
+#define SR_VS_DIRTY _AC(0x00000600, UXL)
+
+#define SR_VS_THEAD _AC(0x01800000, UXL) /* xtheadvector Status */
+#define SR_VS_OFF_THEAD _AC(0x00000000, UXL)
+#define SR_VS_INITIAL_THEAD _AC(0x00800000, UXL)
+#define SR_VS_CLEAN_THEAD _AC(0x01000000, UXL)
+#define SR_VS_DIRTY_THEAD _AC(0x01800000, UXL)
+
+#define SR_XS _AC(0x00018000, UXL) /* Extension Status */
+#define SR_XS_OFF _AC(0x00000000, UXL)
+#define SR_XS_INITIAL _AC(0x00008000, UXL)
+#define SR_XS_CLEAN _AC(0x00010000, UXL)
+#define SR_XS_DIRTY _AC(0x00018000, UXL)
#define SR_FS_VS (SR_FS | SR_VS) /* Vector and Floating-Point Unit */
-#ifndef CONFIG_64BIT
-#define SR_SD _AC(0x80000000, UL) /* FS/VS/XS dirty */
+#if __riscv_xlen == 32
+#define SR_SD _AC(0x80000000, UXL) /* FS/VS/XS dirty */
#else
-#define SR_SD _AC(0x8000000000000000, UL) /* FS/VS/XS dirty */
+#define SR_SD _AC(0x8000000000000000, UXL) /* FS/VS/XS dirty */
#endif
-#ifdef CONFIG_64BIT
-#define SR_UXL _AC(0x300000000, UL) /* XLEN mask for U-mode */
-#define SR_UXL_32 _AC(0x100000000, UL) /* XLEN = 32 for U-mode */
-#define SR_UXL_64 _AC(0x200000000, UL) /* XLEN = 64 for U-mode */
+#if __riscv_xlen == 64
+#define SR_UXL _AC(0x300000000, UXL) /* XLEN mask for U-mode */
+#define SR_UXL_32 _AC(0x100000000, UXL) /* XLEN = 32 for U-mode */
+#define SR_UXL_64 _AC(0x200000000, UXL) /* XLEN = 64 for U-mode */
#endif
/* SATP flags */
-#ifndef CONFIG_64BIT
-#define SATP_PPN _AC(0x003FFFFF, UL)
-#define SATP_MODE_32 _AC(0x80000000, UL)
+#if __riscv_xlen == 32
+#define SATP_PPN _AC(0x003FFFFF, UXL)
+#define SATP_MODE_32 _AC(0x80000000, UXL)
#define SATP_MODE_SHIFT 31
#define SATP_ASID_BITS 9
#define SATP_ASID_SHIFT 22
-#define SATP_ASID_MASK _AC(0x1FF, UL)
+#define SATP_ASID_MASK _AC(0x1FF, UXL)
#else
-#define SATP_PPN _AC(0x00000FFFFFFFFFFF, UL)
-#define SATP_MODE_39 _AC(0x8000000000000000, UL)
-#define SATP_MODE_48 _AC(0x9000000000000000, UL)
-#define SATP_MODE_57 _AC(0xa000000000000000, UL)
+#define SATP_PPN _AC(0x00000FFFFFFFFFFF, UXL)
+#define SATP_MODE_39 _AC(0x8000000000000000, UXL)
+#define SATP_MODE_48 _AC(0x9000000000000000, UXL)
+#define SATP_MODE_57 _AC(0xa000000000000000, UXL)
#define SATP_MODE_SHIFT 60
#define SATP_ASID_BITS 16
#define SATP_ASID_SHIFT 44
-#define SATP_ASID_MASK _AC(0xFFFF, UL)
+#define SATP_ASID_MASK _AC(0xFFFF, UXL)
#endif
/* Exception cause high bit - is an interrupt if set */
-#define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1))
+#define CAUSE_IRQ_FLAG (_AC(1, UXL) << (__riscv_xlen - 1))
/* Interrupt causes (minus the high bit) */
#define IRQ_S_SOFT 1
@@ -91,7 +99,7 @@
#define IRQ_S_GEXT 12
#define IRQ_PMU_OVF 13
#define IRQ_LOCAL_MAX (IRQ_PMU_OVF + 1)
-#define IRQ_LOCAL_MASK GENMASK((IRQ_LOCAL_MAX - 1), 0)
+#define IRQ_LOCAL_MASK GENMASK_UXL((IRQ_LOCAL_MAX - 1), 0)
/* Exception causes */
#define EXC_INST_MISALIGNED 0
@@ -124,45 +132,45 @@
#define PMP_L 0x80
/* HSTATUS flags */
-#ifdef CONFIG_64BIT
-#define HSTATUS_HUPMM _AC(0x3000000000000, UL)
-#define HSTATUS_HUPMM_PMLEN_0 _AC(0x0000000000000, UL)
-#define HSTATUS_HUPMM_PMLEN_7 _AC(0x2000000000000, UL)
-#define HSTATUS_HUPMM_PMLEN_16 _AC(0x3000000000000, UL)
-#define HSTATUS_VSXL _AC(0x300000000, UL)
+#if __riscv_xlen == 64
+#define HSTATUS_HUPMM _AC(0x3000000000000, UXL)
+#define HSTATUS_HUPMM_PMLEN_0 _AC(0x0000000000000, UXL)
+#define HSTATUS_HUPMM_PMLEN_7 _AC(0x2000000000000, UXL)
+#define HSTATUS_HUPMM_PMLEN_16 _AC(0x3000000000000, UXL)
+#define HSTATUS_VSXL _AC(0x300000000, UXL)
#define HSTATUS_VSXL_SHIFT 32
#endif
-#define HSTATUS_VTSR _AC(0x00400000, UL)
-#define HSTATUS_VTW _AC(0x00200000, UL)
-#define HSTATUS_VTVM _AC(0x00100000, UL)
-#define HSTATUS_VGEIN _AC(0x0003f000, UL)
+#define HSTATUS_VTSR _AC(0x00400000, UXL)
+#define HSTATUS_VTW _AC(0x00200000, UXL)
+#define HSTATUS_VTVM _AC(0x00100000, UXL)
+#define HSTATUS_VGEIN _AC(0x0003f000, UXL)
#define HSTATUS_VGEIN_SHIFT 12
-#define HSTATUS_HU _AC(0x00000200, UL)
-#define HSTATUS_SPVP _AC(0x00000100, UL)
-#define HSTATUS_SPV _AC(0x00000080, UL)
-#define HSTATUS_GVA _AC(0x00000040, UL)
-#define HSTATUS_VSBE _AC(0x00000020, UL)
+#define HSTATUS_HU _AC(0x00000200, UXL)
+#define HSTATUS_SPVP _AC(0x00000100, UXL)
+#define HSTATUS_SPV _AC(0x00000080, UXL)
+#define HSTATUS_GVA _AC(0x00000040, UXL)
+#define HSTATUS_VSBE _AC(0x00000020, UXL)
/* HGATP flags */
-#define HGATP_MODE_OFF _AC(0, UL)
-#define HGATP_MODE_SV32X4 _AC(1, UL)
-#define HGATP_MODE_SV39X4 _AC(8, UL)
-#define HGATP_MODE_SV48X4 _AC(9, UL)
-#define HGATP_MODE_SV57X4 _AC(10, UL)
+#define HGATP_MODE_OFF _AC(0, UXL)
+#define HGATP_MODE_SV32X4 _AC(1, UXL)
+#define HGATP_MODE_SV39X4 _AC(8, UXL)
+#define HGATP_MODE_SV48X4 _AC(9, UXL)
+#define HGATP_MODE_SV57X4 _AC(10, UXL)
#define HGATP32_MODE_SHIFT 31
#define HGATP32_VMID_SHIFT 22
-#define HGATP32_VMID GENMASK(28, 22)
-#define HGATP32_PPN GENMASK(21, 0)
+#define HGATP32_VMID GENMASK_UXL(28, 22)
+#define HGATP32_PPN GENMASK_UXL(21, 0)
#define HGATP64_MODE_SHIFT 60
#define HGATP64_VMID_SHIFT 44
-#define HGATP64_VMID GENMASK(57, 44)
-#define HGATP64_PPN GENMASK(43, 0)
+#define HGATP64_VMID GENMASK_UXL(57, 44)
+#define HGATP64_PPN GENMASK_UXL(43, 0)
#define HGATP_PAGE_SHIFT 12
-#ifdef CONFIG_64BIT
+#if __riscv_xlen == 64
#define HGATP_PPN HGATP64_PPN
#define HGATP_VMID_SHIFT HGATP64_VMID_SHIFT
#define HGATP_VMID HGATP64_VMID
@@ -176,31 +184,31 @@
/* VSIP & HVIP relation */
#define VSIP_TO_HVIP_SHIFT (IRQ_VS_SOFT - IRQ_S_SOFT)
-#define VSIP_VALID_MASK ((_AC(1, UL) << IRQ_S_SOFT) | \
- (_AC(1, UL) << IRQ_S_TIMER) | \
- (_AC(1, UL) << IRQ_S_EXT) | \
- (_AC(1, UL) << IRQ_PMU_OVF))
+#define VSIP_VALID_MASK ((_AC(1, UXL) << IRQ_S_SOFT) | \
+ (_AC(1, UXL) << IRQ_S_TIMER) | \
+ (_AC(1, UXL) << IRQ_S_EXT) | \
+ (_AC(1, UXL) << IRQ_PMU_OVF))
/* AIA CSR bits */
#define TOPI_IID_SHIFT 16
-#define TOPI_IID_MASK GENMASK(11, 0)
-#define TOPI_IPRIO_MASK GENMASK(7, 0)
+#define TOPI_IID_MASK GENMASK_UXL(11, 0)
+#define TOPI_IPRIO_MASK GENMASK_UXL(7, 0)
#define TOPI_IPRIO_BITS 8
#define TOPEI_ID_SHIFT 16
-#define TOPEI_ID_MASK GENMASK(10, 0)
-#define TOPEI_PRIO_MASK GENMASK(10, 0)
+#define TOPEI_ID_MASK GENMASK_UXL(10, 0)
+#define TOPEI_PRIO_MASK GENMASK_UXL(10, 0)
#define ISELECT_IPRIO0 0x30
#define ISELECT_IPRIO15 0x3f
-#define ISELECT_MASK GENMASK(8, 0)
+#define ISELECT_MASK GENMASK_UXL(8, 0)
#define HVICTL_VTI BIT(30)
-#define HVICTL_IID GENMASK(27, 16)
+#define HVICTL_IID GENMASK_UXL(27, 16)
#define HVICTL_IID_SHIFT 16
#define HVICTL_DPR BIT(9)
#define HVICTL_IPRIOM BIT(8)
-#define HVICTL_IPRIO GENMASK(7, 0)
+#define HVICTL_IPRIO GENMASK_UXL(7, 0)
/* xENVCFG flags */
#define ENVCFG_STCE (_AC(1, ULL) << 63)
@@ -210,14 +218,14 @@
#define ENVCFG_PMM_PMLEN_0 (_AC(0x0, ULL) << 32)
#define ENVCFG_PMM_PMLEN_7 (_AC(0x2, ULL) << 32)
#define ENVCFG_PMM_PMLEN_16 (_AC(0x3, ULL) << 32)
-#define ENVCFG_CBZE (_AC(1, UL) << 7)
-#define ENVCFG_CBCFE (_AC(1, UL) << 6)
+#define ENVCFG_CBZE (_AC(1, UXL) << 7)
+#define ENVCFG_CBCFE (_AC(1, UXL) << 6)
#define ENVCFG_CBIE_SHIFT 4
-#define ENVCFG_CBIE (_AC(0x3, UL) << ENVCFG_CBIE_SHIFT)
-#define ENVCFG_CBIE_ILL _AC(0x0, UL)
-#define ENVCFG_CBIE_FLUSH _AC(0x1, UL)
-#define ENVCFG_CBIE_INV _AC(0x3, UL)
-#define ENVCFG_FIOM _AC(0x1, UL)
+#define ENVCFG_CBIE (_AC(0x3, UXL) << ENVCFG_CBIE_SHIFT)
+#define ENVCFG_CBIE_ILL _AC(0x0, UXL)
+#define ENVCFG_CBIE_FLUSH _AC(0x1, UXL)
+#define ENVCFG_CBIE_INV _AC(0x3, UXL)
+#define ENVCFG_FIOM _AC(0x1, UXL)
/* Smstateen bits */
#define SMSTATEEN0_AIA_IMSIC_SHIFT 58
@@ -446,12 +454,12 @@
/* Scalar Crypto Extension - Entropy */
#define CSR_SEED 0x015
-#define SEED_OPST_MASK _AC(0xC0000000, UL)
-#define SEED_OPST_BIST _AC(0x00000000, UL)
-#define SEED_OPST_WAIT _AC(0x40000000, UL)
-#define SEED_OPST_ES16 _AC(0x80000000, UL)
-#define SEED_OPST_DEAD _AC(0xC0000000, UL)
-#define SEED_ENTROPY_MASK _AC(0xFFFF, UL)
+#define SEED_OPST_MASK _AC(0xC0000000, UXL)
+#define SEED_OPST_BIST _AC(0x00000000, UXL)
+#define SEED_OPST_WAIT _AC(0x40000000, UXL)
+#define SEED_OPST_ES16 _AC(0x80000000, UXL)
+#define SEED_OPST_DEAD _AC(0xC0000000, UXL)
+#define SEED_ENTROPY_MASK _AC(0xFFFF, UXL)
#ifdef CONFIG_RISCV_M_MODE
# define CSR_STATUS CSR_MSTATUS
@@ -504,14 +512,14 @@
# define RV_IRQ_TIMER IRQ_S_TIMER
# define RV_IRQ_EXT IRQ_S_EXT
# define RV_IRQ_PMU IRQ_PMU_OVF
-# define SIP_LCOFIP (_AC(0x1, UL) << IRQ_PMU_OVF)
+# define SIP_LCOFIP (_AC(0x1, UXL) << IRQ_PMU_OVF)
#endif /* !CONFIG_RISCV_M_MODE */
/* IE/IP (Supervisor/Machine Interrupt Enable/Pending) flags */
-#define IE_SIE (_AC(0x1, UL) << RV_IRQ_SOFT)
-#define IE_TIE (_AC(0x1, UL) << RV_IRQ_TIMER)
-#define IE_EIE (_AC(0x1, UL) << RV_IRQ_EXT)
+#define IE_SIE (_AC(0x1, UXL) << RV_IRQ_SOFT)
+#define IE_TIE (_AC(0x1, UXL) << RV_IRQ_TIMER)
+#define IE_EIE (_AC(0x1, UXL) << RV_IRQ_EXT)
#ifndef __ASSEMBLY__
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index ca60db75199d..4f958722ca41 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -136,7 +136,7 @@ static u8 rv_tail_call_reg(struct rv_jit_context *ctx)
static bool is_32b_int(s64 val)
{
- return -(1L << 31) <= val && val < (1L << 31);
+ return -(1LL << 31) <= val && val < (1LL << 31);
}
static bool in_auipc_jalr_range(s64 val)
@@ -145,8 +145,8 @@ static bool in_auipc_jalr_range(s64 val)
* auipc+jalr can reach any signed PC-relative offset in the range
* [-2^31 - 2^11, 2^31 - 2^11).
*/
- return (-(1L << 31) - (1L << 11)) <= val &&
- val < ((1L << 31) - (1L << 11));
+ return (-(1LL << 31) - (1LL << 11)) <= val &&
+ val < ((1LL << 31) - (1LL << 11));
}
/* Modify rd pointer to alternate reg to avoid corrupting original reg */
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 04/43] rv64ilp32_abi: riscv: Introduce xlen_t to adapt __riscv_xlen != BITS_PER_LONG
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (2 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 03/43] rv64ilp32_abi: riscv: Adapt ULL & UL definition guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 05/43] rv64ilp32_abi: riscv: crc32: Utilize 64-bit width to improve the performance guoren
` (40 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
Upon RV64ILP32 ABI definition, BITS_PER_LONG couldn't determine
XLEN due to its 32-bit value when CONFIG_64BIT=y. Hence, we've
introduced xlen_t and utilized CONFIG_64BIT or __riscv_xlen == 64
to determine register width.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/checksum.h | 4 ++
arch/riscv/include/asm/csr.h | 15 ++--
arch/riscv/include/asm/processor.h | 10 +--
arch/riscv/include/asm/ptrace.h | 92 ++++++++++++------------
arch/riscv/include/asm/sparsemem.h | 2 +-
arch/riscv/include/asm/switch_to.h | 4 +-
arch/riscv/include/asm/thread_info.h | 2 +-
arch/riscv/include/asm/timex.h | 4 +-
arch/riscv/include/uapi/asm/elf.h | 4 +-
arch/riscv/include/uapi/asm/ptrace.h | 97 ++++++++++++++------------
arch/riscv/include/uapi/asm/ucontext.h | 7 +-
arch/riscv/include/uapi/asm/unistd.h | 2 +-
arch/riscv/kernel/compat_signal.c | 4 +-
arch/riscv/kernel/process.c | 8 +--
arch/riscv/kernel/signal.c | 4 +-
arch/riscv/kernel/traps.c | 4 +-
arch/riscv/kernel/vector.c | 2 +-
arch/riscv/mm/fault.c | 2 +-
18 files changed, 143 insertions(+), 124 deletions(-)
diff --git a/arch/riscv/include/asm/checksum.h b/arch/riscv/include/asm/checksum.h
index 88e6f1499e88..e887f0983b69 100644
--- a/arch/riscv/include/asm/checksum.h
+++ b/arch/riscv/include/asm/checksum.h
@@ -36,7 +36,11 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
*/
static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
{
+#if __riscv_xlen == 64
+ unsigned long long csum = 0;
+#else
unsigned long csum = 0;
+#endif
int pos = 0;
do {
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 25f7c5afea3a..4339600e3c56 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -522,10 +522,11 @@
#define IE_EIE (_AC(0x1, UXL) << RV_IRQ_EXT)
#ifndef __ASSEMBLY__
+#include <asm/ptrace.h>
#define csr_swap(csr, val) \
({ \
- unsigned long __v = (unsigned long)(val); \
+ xlen_t __v = (xlen_t)(val); \
__asm__ __volatile__ ("csrrw %0, " __ASM_STR(csr) ", %1"\
: "=r" (__v) : "rK" (__v) \
: "memory"); \
@@ -534,7 +535,7 @@
#define csr_read(csr) \
({ \
- register unsigned long __v; \
+ register xlen_t __v; \
__asm__ __volatile__ ("csrr %0, " __ASM_STR(csr) \
: "=r" (__v) : \
: "memory"); \
@@ -543,7 +544,7 @@
#define csr_write(csr, val) \
({ \
- unsigned long __v = (unsigned long)(val); \
+ xlen_t __v = (xlen_t)(val); \
__asm__ __volatile__ ("csrw " __ASM_STR(csr) ", %0" \
: : "rK" (__v) \
: "memory"); \
@@ -551,7 +552,7 @@
#define csr_read_set(csr, val) \
({ \
- unsigned long __v = (unsigned long)(val); \
+ xlen_t __v = (xlen_t)(val); \
__asm__ __volatile__ ("csrrs %0, " __ASM_STR(csr) ", %1"\
: "=r" (__v) : "rK" (__v) \
: "memory"); \
@@ -560,7 +561,7 @@
#define csr_set(csr, val) \
({ \
- unsigned long __v = (unsigned long)(val); \
+ xlen_t __v = (xlen_t)(val); \
__asm__ __volatile__ ("csrs " __ASM_STR(csr) ", %0" \
: : "rK" (__v) \
: "memory"); \
@@ -568,7 +569,7 @@
#define csr_read_clear(csr, val) \
({ \
- unsigned long __v = (unsigned long)(val); \
+ xlen_t __v = (xlen_t)(val); \
__asm__ __volatile__ ("csrrc %0, " __ASM_STR(csr) ", %1"\
: "=r" (__v) : "rK" (__v) \
: "memory"); \
@@ -577,7 +578,7 @@
#define csr_clear(csr, val) \
({ \
- unsigned long __v = (unsigned long)(val); \
+ xlen_t __v = (xlen_t)(val); \
__asm__ __volatile__ ("csrc " __ASM_STR(csr) ", %0" \
: : "rK" (__v) \
: "memory"); \
diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h
index 5f56eb9d114a..ca57a650c3d2 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -45,7 +45,7 @@
* This decides where the kernel will search for a free chunk of vm
* space during mmap's.
*/
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#define TASK_UNMAPPED_BASE PAGE_ALIGN((UL(1) << MMAP_MIN_VA_BITS) / 3)
#else
#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3)
@@ -99,10 +99,10 @@ struct thread_struct {
/* Callee-saved registers */
unsigned long ra;
unsigned long sp; /* Kernel mode stack */
- unsigned long s[12]; /* s[0]: frame pointer */
+ xlen_t s[12]; /* s[0]: frame pointer */
struct __riscv_d_ext_state fstate;
unsigned long bad_cause;
- unsigned long envcfg;
+ xlen_t envcfg;
u32 riscv_v_flags;
u32 vstate_ctrl;
struct __riscv_v_ext_state vstate;
@@ -133,8 +133,8 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset,
((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE \
- ALIGN(sizeof(struct pt_regs), STACK_ALIGN)))
-#define KSTK_EIP(tsk) (task_pt_regs(tsk)->epc)
-#define KSTK_ESP(tsk) (task_pt_regs(tsk)->sp)
+#define KSTK_EIP(tsk) (ulong)(task_pt_regs(tsk)->epc)
+#define KSTK_ESP(tsk) (ulong)(task_pt_regs(tsk)->sp)
/* Do necessary setup to start up a newly executed thread. */
diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h
index b5b0adcc85c1..a0ed27c2346b 100644
--- a/arch/riscv/include/asm/ptrace.h
+++ b/arch/riscv/include/asm/ptrace.h
@@ -13,51 +13,51 @@
#ifndef __ASSEMBLY__
struct pt_regs {
- unsigned long epc;
- unsigned long ra;
- unsigned long sp;
- unsigned long gp;
- unsigned long tp;
- unsigned long t0;
- unsigned long t1;
- unsigned long t2;
- unsigned long s0;
- unsigned long s1;
- unsigned long a0;
- unsigned long a1;
- unsigned long a2;
- unsigned long a3;
- unsigned long a4;
- unsigned long a5;
- unsigned long a6;
- unsigned long a7;
- unsigned long s2;
- unsigned long s3;
- unsigned long s4;
- unsigned long s5;
- unsigned long s6;
- unsigned long s7;
- unsigned long s8;
- unsigned long s9;
- unsigned long s10;
- unsigned long s11;
- unsigned long t3;
- unsigned long t4;
- unsigned long t5;
- unsigned long t6;
+ xlen_t epc;
+ xlen_t ra;
+ xlen_t sp;
+ xlen_t gp;
+ xlen_t tp;
+ xlen_t t0;
+ xlen_t t1;
+ xlen_t t2;
+ xlen_t s0;
+ xlen_t s1;
+ xlen_t a0;
+ xlen_t a1;
+ xlen_t a2;
+ xlen_t a3;
+ xlen_t a4;
+ xlen_t a5;
+ xlen_t a6;
+ xlen_t a7;
+ xlen_t s2;
+ xlen_t s3;
+ xlen_t s4;
+ xlen_t s5;
+ xlen_t s6;
+ xlen_t s7;
+ xlen_t s8;
+ xlen_t s9;
+ xlen_t s10;
+ xlen_t s11;
+ xlen_t t3;
+ xlen_t t4;
+ xlen_t t5;
+ xlen_t t6;
/* Supervisor/Machine CSRs */
- unsigned long status;
- unsigned long badaddr;
- unsigned long cause;
+ xlen_t status;
+ xlen_t badaddr;
+ xlen_t cause;
/* a0 value before the syscall */
- unsigned long orig_a0;
+ xlen_t orig_a0;
};
#define PTRACE_SYSEMU 0x1f
#define PTRACE_SYSEMU_SINGLESTEP 0x20
#ifdef CONFIG_64BIT
-#define REG_FMT "%016lx"
+#define REG_FMT "%016llx"
#else
#define REG_FMT "%08lx"
#endif
@@ -69,12 +69,12 @@ struct pt_regs {
/* Helpers for working with the instruction pointer */
static inline unsigned long instruction_pointer(struct pt_regs *regs)
{
- return regs->epc;
+ return (unsigned long)regs->epc;
}
static inline void instruction_pointer_set(struct pt_regs *regs,
unsigned long val)
{
- regs->epc = val;
+ regs->epc = (xlen_t)val;
}
#define profile_pc(regs) instruction_pointer(regs)
@@ -82,40 +82,40 @@ static inline void instruction_pointer_set(struct pt_regs *regs,
/* Helpers for working with the user stack pointer */
static inline unsigned long user_stack_pointer(struct pt_regs *regs)
{
- return regs->sp;
+ return (unsigned long)regs->sp;
}
static inline void user_stack_pointer_set(struct pt_regs *regs,
unsigned long val)
{
- regs->sp = val;
+ regs->sp = (xlen_t)val;
}
/* Valid only for Kernel mode traps. */
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
{
- return regs->sp;
+ return (unsigned long)regs->sp;
}
/* Helpers for working with the frame pointer */
static inline unsigned long frame_pointer(struct pt_regs *regs)
{
- return regs->s0;
+ return (unsigned long)regs->s0;
}
static inline void frame_pointer_set(struct pt_regs *regs,
unsigned long val)
{
- regs->s0 = val;
+ regs->s0 = (xlen_t)val;
}
static inline unsigned long regs_return_value(struct pt_regs *regs)
{
- return regs->a0;
+ return (unsigned long)regs->a0;
}
static inline void regs_set_return_value(struct pt_regs *regs,
unsigned long val)
{
- regs->a0 = val;
+ regs->a0 = (xlen_t)val;
}
extern int regs_query_register_offset(const char *name);
diff --git a/arch/riscv/include/asm/sparsemem.h b/arch/riscv/include/asm/sparsemem.h
index 2f901a410586..68907698caa6 100644
--- a/arch/riscv/include/asm/sparsemem.h
+++ b/arch/riscv/include/asm/sparsemem.h
@@ -4,7 +4,7 @@
#define _ASM_RISCV_SPARSEMEM_H
#ifdef CONFIG_SPARSEMEM
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#define MAX_PHYSMEM_BITS 56
#else
#define MAX_PHYSMEM_BITS 32
diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h
index 0e71eb82f920..6d01b0fc5a25 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -71,9 +71,9 @@ static __always_inline bool has_fpu(void) { return false; }
#endif
static inline void envcfg_update_bits(struct task_struct *task,
- unsigned long mask, unsigned long val)
+ xlen_t mask, xlen_t val)
{
- unsigned long envcfg;
+ xlen_t envcfg;
envcfg = (task->thread.envcfg & ~mask) | val;
task->thread.envcfg = envcfg;
diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
index f5916a70879a..637a46fc7ed8 100644
--- a/arch/riscv/include/asm/thread_info.h
+++ b/arch/riscv/include/asm/thread_info.h
@@ -71,7 +71,7 @@ struct thread_info {
* Used in handle_exception() to save a0, a1 and a2 before knowing if we
* can access the kernel stack.
*/
- unsigned long a0, a1, a2;
+ xlen_t a0, a1, a2;
#endif
};
diff --git a/arch/riscv/include/asm/timex.h b/arch/riscv/include/asm/timex.h
index a06697846e69..b5ca67b30d0b 100644
--- a/arch/riscv/include/asm/timex.h
+++ b/arch/riscv/include/asm/timex.h
@@ -8,7 +8,7 @@
#include <asm/csr.h>
-typedef unsigned long cycles_t;
+typedef xlen_t cycles_t;
#ifdef CONFIG_RISCV_M_MODE
@@ -84,7 +84,7 @@ static inline u64 get_cycles64(void)
#define ARCH_HAS_READ_CURRENT_TIMER
static inline int read_current_timer(unsigned long *timer_val)
{
- *timer_val = get_cycles();
+ *timer_val = (unsigned long)get_cycles();
return 0;
}
diff --git a/arch/riscv/include/uapi/asm/elf.h b/arch/riscv/include/uapi/asm/elf.h
index 11a71b8533d5..9fc8c2e3556b 100644
--- a/arch/riscv/include/uapi/asm/elf.h
+++ b/arch/riscv/include/uapi/asm/elf.h
@@ -15,7 +15,7 @@
#include <asm/ptrace.h>
/* ELF register definitions */
-typedef unsigned long elf_greg_t;
+typedef xlen_t elf_greg_t;
typedef struct user_regs_struct elf_gregset_t;
#define ELF_NGREG (sizeof(elf_gregset_t) / sizeof(elf_greg_t))
@@ -24,7 +24,7 @@ typedef __u64 elf_fpreg_t;
typedef union __riscv_fp_state elf_fpregset_t;
#define ELF_NFPREG (sizeof(struct __riscv_d_ext_state) / sizeof(elf_fpreg_t))
-#if __riscv_xlen == 64
+#if BITS_PER_LONG == 64
#define ELF_RISCV_R_SYM(r_info) ELF64_R_SYM(r_info)
#define ELF_RISCV_R_TYPE(r_info) ELF64_R_TYPE(r_info)
#else
diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h
index a38268b19c3d..f040a2ba07b0 100644
--- a/arch/riscv/include/uapi/asm/ptrace.h
+++ b/arch/riscv/include/uapi/asm/ptrace.h
@@ -15,6 +15,14 @@
#define PTRACE_GETFDPIC_EXEC 0
#define PTRACE_GETFDPIC_INTERP 1
+#if __riscv_xlen == 64
+typedef u64 xlen_t;
+#endif
+
+#if __riscv_xlen == 32
+typedef ulong xlen_t;
+#endif
+
/*
* User-mode register state for core dumps, ptrace, sigcontext
*
@@ -22,38 +30,38 @@
* struct user_regs_struct must form a prefix of struct pt_regs.
*/
struct user_regs_struct {
- unsigned long pc;
- unsigned long ra;
- unsigned long sp;
- unsigned long gp;
- unsigned long tp;
- unsigned long t0;
- unsigned long t1;
- unsigned long t2;
- unsigned long s0;
- unsigned long s1;
- unsigned long a0;
- unsigned long a1;
- unsigned long a2;
- unsigned long a3;
- unsigned long a4;
- unsigned long a5;
- unsigned long a6;
- unsigned long a7;
- unsigned long s2;
- unsigned long s3;
- unsigned long s4;
- unsigned long s5;
- unsigned long s6;
- unsigned long s7;
- unsigned long s8;
- unsigned long s9;
- unsigned long s10;
- unsigned long s11;
- unsigned long t3;
- unsigned long t4;
- unsigned long t5;
- unsigned long t6;
+ xlen_t pc;
+ xlen_t ra;
+ xlen_t sp;
+ xlen_t gp;
+ xlen_t tp;
+ xlen_t t0;
+ xlen_t t1;
+ xlen_t t2;
+ xlen_t s0;
+ xlen_t s1;
+ xlen_t a0;
+ xlen_t a1;
+ xlen_t a2;
+ xlen_t a3;
+ xlen_t a4;
+ xlen_t a5;
+ xlen_t a6;
+ xlen_t a7;
+ xlen_t s2;
+ xlen_t s3;
+ xlen_t s4;
+ xlen_t s5;
+ xlen_t s6;
+ xlen_t s7;
+ xlen_t s8;
+ xlen_t s9;
+ xlen_t s10;
+ xlen_t s11;
+ xlen_t t3;
+ xlen_t t4;
+ xlen_t t5;
+ xlen_t t6;
};
struct __riscv_f_ext_state {
@@ -98,12 +106,15 @@ union __riscv_fp_state {
};
struct __riscv_v_ext_state {
- unsigned long vstart;
- unsigned long vl;
- unsigned long vtype;
- unsigned long vcsr;
- unsigned long vlenb;
- void *datap;
+ xlen_t vstart;
+ xlen_t vl;
+ xlen_t vtype;
+ xlen_t vcsr;
+ xlen_t vlenb;
+ union {
+ void *datap;
+ xlen_t pad;
+ };
/*
* In signal handler, datap will be set a correct user stack offset
* and vector registers will be copied to the address of datap
@@ -112,11 +123,11 @@ struct __riscv_v_ext_state {
};
struct __riscv_v_regset_state {
- unsigned long vstart;
- unsigned long vl;
- unsigned long vtype;
- unsigned long vcsr;
- unsigned long vlenb;
+ xlen_t vstart;
+ xlen_t vl;
+ xlen_t vtype;
+ xlen_t vcsr;
+ xlen_t vlenb;
char vreg[];
};
diff --git a/arch/riscv/include/uapi/asm/ucontext.h b/arch/riscv/include/uapi/asm/ucontext.h
index 516bd0bb0da5..572b96c3ccf4 100644
--- a/arch/riscv/include/uapi/asm/ucontext.h
+++ b/arch/riscv/include/uapi/asm/ucontext.h
@@ -11,8 +11,11 @@
#include <linux/types.h>
struct ucontext {
- unsigned long uc_flags;
- struct ucontext *uc_link;
+ xlen_t uc_flags;
+ union {
+ struct ucontext *uc_link;
+ xlen_t pad;
+ };
stack_t uc_stack;
sigset_t uc_sigmask;
/*
diff --git a/arch/riscv/include/uapi/asm/unistd.h b/arch/riscv/include/uapi/asm/unistd.h
index 81896bbbf727..e33dd5161b8d 100644
--- a/arch/riscv/include/uapi/asm/unistd.h
+++ b/arch/riscv/include/uapi/asm/unistd.h
@@ -16,7 +16,7 @@
*/
#include <asm/bitsperlong.h>
-#if __BITS_PER_LONG == 64
+#if __riscv_xlen == 64
#include <asm/unistd_64.h>
#else
#include <asm/unistd_32.h>
diff --git a/arch/riscv/kernel/compat_signal.c b/arch/riscv/kernel/compat_signal.c
index 6ec4e34255a9..859104618f34 100644
--- a/arch/riscv/kernel/compat_signal.c
+++ b/arch/riscv/kernel/compat_signal.c
@@ -126,7 +126,7 @@ COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
- frame = (struct compat_rt_sigframe __user *)regs->sp;
+ frame = (struct compat_rt_sigframe __user *)(ulong)regs->sp;
if (!access_ok(frame, sizeof(*frame)))
goto badframe;
@@ -150,7 +150,7 @@ COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
pr_info_ratelimited(
"%s[%d]: bad frame in %s: frame=%p pc=%p sp=%p\n",
task->comm, task_pid_nr(task), __func__,
- frame, (void *)regs->epc, (void *)regs->sp);
+ frame, (void *)(ulong)regs->epc, (void *)(ulong)regs->sp);
}
force_sig(SIGSEGV);
return 0;
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 7c244de77180..5c827761f84b 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -65,8 +65,8 @@ void __show_regs(struct pt_regs *regs)
show_regs_print_info(KERN_DEFAULT);
if (!user_mode(regs)) {
- pr_cont("epc : %pS\n", (void *)regs->epc);
- pr_cont(" ra : %pS\n", (void *)regs->ra);
+ pr_cont("epc : %pS\n", (void *)(ulong)regs->epc);
+ pr_cont(" ra : %pS\n", (void *)(ulong)regs->ra);
}
pr_cont("epc : " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n",
@@ -272,7 +272,7 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg)
unsigned long valid_mask = PR_PMLEN_MASK | PR_TAGGED_ADDR_ENABLE;
struct thread_info *ti = task_thread_info(task);
struct mm_struct *mm = task->mm;
- unsigned long pmm;
+ xlen_t pmm;
u8 pmlen;
if (is_compat_thread(ti))
@@ -352,7 +352,7 @@ long get_tagged_addr_ctrl(struct task_struct *task)
return ret;
}
-static bool try_to_set_pmm(unsigned long value)
+static bool try_to_set_pmm(xlen_t value)
{
csr_set(CSR_ENVCFG, value);
return (csr_read_clear(CSR_ENVCFG, ENVCFG_PMM) & ENVCFG_PMM) == value;
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 94e905eea1de..b3eb4154faf7 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -239,7 +239,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
- frame = (struct rt_sigframe __user *)regs->sp;
+ frame = (struct rt_sigframe __user *)(ulong)regs->sp;
if (!access_ok(frame, frame_size))
goto badframe;
@@ -265,7 +265,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
pr_info_ratelimited(
"%s[%d]: bad frame in %s: frame=%p pc=%p sp=%p\n",
task->comm, task_pid_nr(task), __func__,
- frame, (void *)regs->epc, (void *)regs->sp);
+ frame, (void *)(ulong)regs->epc, (void *)(ulong)regs->sp);
}
force_sig(SIGSEGV);
return 0;
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index 8ff8e8b36524..1fada4c7ddfa 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -118,7 +118,7 @@ void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)
if (show_unhandled_signals && unhandled_signal(tsk, signo)
&& printk_ratelimit()) {
pr_info("%s[%d]: unhandled signal %d code 0x%x at 0x" REG_FMT,
- tsk->comm, task_pid_nr(tsk), signo, code, addr);
+ tsk->comm, task_pid_nr(tsk), signo, code, (xlen_t)addr);
print_vma_addr(KERN_CONT " in ", instruction_pointer(regs));
pr_cont("\n");
__show_regs(regs);
@@ -281,7 +281,7 @@ void handle_break(struct pt_regs *regs)
current->thread.bad_cause = regs->cause;
if (user_mode(regs))
- force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->epc);
+ force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)instruction_pointer(regs));
#ifdef CONFIG_KGDB
else if (notify_die(DIE_TRAP, "EBREAK", regs, 0, regs->cause, SIGTRAP)
== NOTIFY_STOP)
diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 184f780c932d..884edd99e6b0 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(riscv_v_vstate_ctrl_user_allowed);
bool riscv_v_first_use_handler(struct pt_regs *regs)
{
- u32 __user *epc = (u32 __user *)regs->epc;
+ u32 __user *epc = (u32 __user *)(ulong)regs->epc;
u32 insn = (u32)regs->badaddr;
if (!(has_vector() || has_xtheadvector()))
diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 0194324a0c50..fcc23350610e 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -78,7 +78,7 @@ static void die_kernel_fault(const char *msg, unsigned long addr,
{
bust_spinlocks(1);
- pr_alert("Unable to handle kernel %s at virtual address " REG_FMT "\n", msg,
+ pr_alert("Unable to handle kernel %s at virtual address %08lx\n", msg,
addr);
bust_spinlocks(0);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 05/43] rv64ilp32_abi: riscv: crc32: Utilize 64-bit width to improve the performance
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (3 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 04/43] rv64ilp32_abi: riscv: Introduce xlen_t to adapt __riscv_xlen != BITS_PER_LONG guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 06/43] rv64ilp32_abi: riscv: csum: " guoren
` (39 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI, derived from a 64-bit ISA, uses 32-bit
BITS_PER_LONG. Therefore, crc32 algorithm could utilize 64-bit width
to improve the performance.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/lib/crc32-riscv.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/arch/riscv/lib/crc32-riscv.c b/arch/riscv/lib/crc32-riscv.c
index 53d56ab422c7..68dfb0565696 100644
--- a/arch/riscv/lib/crc32-riscv.c
+++ b/arch/riscv/lib/crc32-riscv.c
@@ -8,6 +8,7 @@
#include <asm/hwcap.h>
#include <asm/alternative-macros.h>
#include <asm/byteorder.h>
+#include <asm/csr.h>
#include <linux/types.h>
#include <linux/minmax.h>
@@ -59,12 +60,12 @@
*/
# define CRC32_POLY_QT_BE 0x04d101df481b4e5a
-static inline u64 crc32_le_prep(u32 crc, unsigned long const *ptr)
+static inline u64 crc32_le_prep(u32 crc, u64 const *ptr)
{
return (u64)crc ^ (__force u64)__cpu_to_le64(*ptr);
}
-static inline u32 crc32_le_zbc(unsigned long s, u32 poly, unsigned long poly_qt)
+static inline u32 crc32_le_zbc(u64 s, u32 poly, u64 poly_qt)
{
u32 crc;
@@ -85,7 +86,7 @@ static inline u32 crc32_le_zbc(unsigned long s, u32 poly, unsigned long poly_qt)
return crc;
}
-static inline u64 crc32_be_prep(u32 crc, unsigned long const *ptr)
+static inline u64 crc32_be_prep(u32 crc, u64 const *ptr)
{
return ((u64)crc << 32) ^ (__force u64)__cpu_to_be64(*ptr);
}
@@ -131,7 +132,7 @@ static inline u32 crc32_be_prep(u32 crc, unsigned long const *ptr)
# error "Unexpected __riscv_xlen"
#endif
-static inline u32 crc32_be_zbc(unsigned long s)
+static inline u32 crc32_be_zbc(xlen_t s)
{
u32 crc;
@@ -156,16 +157,16 @@ typedef u32 (*fallback)(u32 crc, unsigned char const *p, size_t len);
static inline u32 crc32_le_unaligned(u32 crc, unsigned char const *p,
size_t len, u32 poly,
- unsigned long poly_qt)
+ xlen_t poly_qt)
{
size_t bits = len * 8;
- unsigned long s = 0;
+ xlen_t s = 0;
u32 crc_low = 0;
for (int i = 0; i < len; i++)
- s = ((unsigned long)*p++ << (__riscv_xlen - 8)) | (s >> 8);
+ s = ((xlen_t)*p++ << (__riscv_xlen - 8)) | (s >> 8);
- s ^= (unsigned long)crc << (__riscv_xlen - bits);
+ s ^= (xlen_t)crc << (__riscv_xlen - bits);
if (__riscv_xlen == 32 || len < sizeof(u32))
crc_low = crc >> bits;
@@ -177,12 +178,12 @@ static inline u32 crc32_le_unaligned(u32 crc, unsigned char const *p,
static inline u32 __pure crc32_le_generic(u32 crc, unsigned char const *p,
size_t len, u32 poly,
- unsigned long poly_qt,
+ xlen_t poly_qt,
fallback crc_fb)
{
size_t offset, head_len, tail_len;
- unsigned long const *p_ul;
- unsigned long s;
+ xlen_t const *p_ul;
+ xlen_t s;
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
RISCV_ISA_EXT_ZBC, 1)
@@ -199,7 +200,7 @@ static inline u32 __pure crc32_le_generic(u32 crc, unsigned char const *p,
tail_len = len & OFFSET_MASK;
len = len >> STEP_ORDER;
- p_ul = (unsigned long const *)p;
+ p_ul = (xlen_t const *)p;
for (int i = 0; i < len; i++) {
s = crc32_le_prep(crc, p_ul);
@@ -236,7 +237,7 @@ static inline u32 crc32_be_unaligned(u32 crc, unsigned char const *p,
size_t len)
{
size_t bits = len * 8;
- unsigned long s = 0;
+ xlen_t s = 0;
u32 crc_low = 0;
s = 0;
@@ -247,7 +248,7 @@ static inline u32 crc32_be_unaligned(u32 crc, unsigned char const *p,
s ^= crc >> (32 - bits);
crc_low = crc << bits;
} else {
- s ^= (unsigned long)crc << (bits - 32);
+ s ^= (xlen_t)crc << (bits - 32);
}
crc = crc32_be_zbc(s);
@@ -259,8 +260,8 @@ static inline u32 crc32_be_unaligned(u32 crc, unsigned char const *p,
u32 __pure crc32_be_arch(u32 crc, const u8 *p, size_t len)
{
size_t offset, head_len, tail_len;
- unsigned long const *p_ul;
- unsigned long s;
+ xlen_t const *p_ul;
+ xlen_t s;
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
RISCV_ISA_EXT_ZBC, 1)
@@ -277,7 +278,7 @@ u32 __pure crc32_be_arch(u32 crc, const u8 *p, size_t len)
tail_len = len & OFFSET_MASK;
len = len >> STEP_ORDER;
- p_ul = (unsigned long const *)p;
+ p_ul = (xlen_t const *)p;
for (int i = 0; i < len; i++) {
s = crc32_be_prep(crc, p_ul);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 06/43] rv64ilp32_abi: riscv: csum: Utilize 64-bit width to improve the performance
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (4 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 05/43] rv64ilp32_abi: riscv: crc32: Utilize 64-bit width to improve the performance guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 07/43] rv64ilp32_abi: riscv: arch_hweight: Adapt cpopw & cpop of zbb extension guoren
` (38 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI, derived from a 64-bit ISA, uses 32-bit
BITS_PER_LONG. Therefore, checksum algorithm could utilize 64-bit
width to improve the performance.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/lib/csum.c | 48 +++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c
index 7fb12c59e571..7139ab855349 100644
--- a/arch/riscv/lib/csum.c
+++ b/arch/riscv/lib/csum.c
@@ -22,17 +22,17 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
__u32 len, __u8 proto, __wsum csum)
{
unsigned int ulen, uproto;
- unsigned long sum = (__force unsigned long)csum;
+ xlen_t sum = (__force xlen_t)csum;
- sum += (__force unsigned long)saddr->s6_addr32[0];
- sum += (__force unsigned long)saddr->s6_addr32[1];
- sum += (__force unsigned long)saddr->s6_addr32[2];
- sum += (__force unsigned long)saddr->s6_addr32[3];
+ sum += (__force xlen_t)saddr->s6_addr32[0];
+ sum += (__force xlen_t)saddr->s6_addr32[1];
+ sum += (__force xlen_t)saddr->s6_addr32[2];
+ sum += (__force xlen_t)saddr->s6_addr32[3];
- sum += (__force unsigned long)daddr->s6_addr32[0];
- sum += (__force unsigned long)daddr->s6_addr32[1];
- sum += (__force unsigned long)daddr->s6_addr32[2];
- sum += (__force unsigned long)daddr->s6_addr32[3];
+ sum += (__force xlen_t)daddr->s6_addr32[0];
+ sum += (__force xlen_t)daddr->s6_addr32[1];
+ sum += (__force xlen_t)daddr->s6_addr32[2];
+ sum += (__force xlen_t)daddr->s6_addr32[3];
ulen = (__force unsigned int)htonl((unsigned int)len);
sum += ulen;
@@ -46,7 +46,7 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
*/
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
- unsigned long fold_temp;
+ xlen_t fold_temp;
/*
* Zbb is likely available when the kernel is compiled with Zbb
@@ -85,12 +85,12 @@ EXPORT_SYMBOL(csum_ipv6_magic);
#define OFFSET_MASK 7
#endif
-static inline __no_sanitize_address unsigned long
-do_csum_common(const unsigned long *ptr, const unsigned long *end,
- unsigned long data)
+static inline __no_sanitize_address xlen_t
+do_csum_common(const xlen_t *ptr, const xlen_t *end,
+ xlen_t data)
{
unsigned int shift;
- unsigned long csum = 0, carry = 0;
+ xlen_t csum = 0, carry = 0;
/*
* Do 32-bit reads on RV32 and 64-bit reads otherwise. This should be
@@ -130,8 +130,8 @@ static inline __no_sanitize_address unsigned int
do_csum_with_alignment(const unsigned char *buff, int len)
{
unsigned int offset, shift;
- unsigned long csum, data;
- const unsigned long *ptr, *end;
+ xlen_t csum, data;
+ const xlen_t *ptr, *end;
/*
* Align address to closest word (double word on rv64) that comes before
@@ -140,7 +140,7 @@ do_csum_with_alignment(const unsigned char *buff, int len)
*/
offset = (unsigned long)buff & OFFSET_MASK;
kasan_check_read(buff, len);
- ptr = (const unsigned long *)(buff - offset);
+ ptr = (const xlen_t *)(buff - offset);
/*
* Clear the most significant bytes that were over-read if buff was not
@@ -153,7 +153,7 @@ do_csum_with_alignment(const unsigned char *buff, int len)
#else
data = (data << shift) >> shift;
#endif
- end = (const unsigned long *)(buff + len);
+ end = (const xlen_t *)(buff + len);
csum = do_csum_common(ptr, end, data);
#ifdef CC_HAS_ASM_GOTO_TIED_OUTPUT
@@ -163,7 +163,7 @@ do_csum_with_alignment(const unsigned char *buff, int len)
*/
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
- unsigned long fold_temp;
+ xlen_t fold_temp;
/*
* Zbb is likely available when the kernel is compiled with Zbb
@@ -233,15 +233,15 @@ do_csum_with_alignment(const unsigned char *buff, int len)
static inline __no_sanitize_address unsigned int
do_csum_no_alignment(const unsigned char *buff, int len)
{
- unsigned long csum, data;
- const unsigned long *ptr, *end;
+ xlen_t csum, data;
+ const xlen_t *ptr, *end;
- ptr = (const unsigned long *)(buff);
+ ptr = (const xlen_t *)(buff);
data = *(ptr++);
kasan_check_read(buff, len);
- end = (const unsigned long *)(buff + len);
+ end = (const xlen_t *)(buff + len);
csum = do_csum_common(ptr, end, data);
/*
@@ -250,7 +250,7 @@ do_csum_no_alignment(const unsigned char *buff, int len)
*/
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
- unsigned long fold_temp;
+ xlen_t fold_temp;
/*
* Zbb is likely available when the kernel is compiled with Zbb
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 07/43] rv64ilp32_abi: riscv: arch_hweight: Adapt cpopw & cpop of zbb extension
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (5 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 06/43] rv64ilp32_abi: riscv: csum: " guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 08/43] rv64ilp32_abi: riscv: bitops: Adapt ctzw & clzw " guoren
` (37 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI is based on 64-bit ISA, but BITS_PER_LONG is 32.
Use cpopw for u32_weight and cpop for u64_weight.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/arch_hweight.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/include/asm/arch_hweight.h b/arch/riscv/include/asm/arch_hweight.h
index 613769b9cdc9..42577965f5bb 100644
--- a/arch/riscv/include/asm/arch_hweight.h
+++ b/arch/riscv/include/asm/arch_hweight.h
@@ -12,7 +12,11 @@
#if (BITS_PER_LONG == 64)
#define CPOPW "cpopw "
#elif (BITS_PER_LONG == 32)
+#ifdef CONFIG_64BIT
+#define CPOPW "cpopw "
+#else
#define CPOPW "cpop "
+#endif
#else
#error "Unexpected BITS_PER_LONG"
#endif
@@ -47,7 +51,7 @@ static inline unsigned int __arch_hweight8(unsigned int w)
return __arch_hweight32(w & 0xff);
}
-#if BITS_PER_LONG == 64
+#ifdef CONFIG_64BIT
static __always_inline unsigned long __arch_hweight64(__u64 w)
{
# ifdef CONFIG_RISCV_ISA_ZBB
@@ -61,7 +65,7 @@ static __always_inline unsigned long __arch_hweight64(__u64 w)
".option pop\n"
: "=r" (w) : "r" (w) :);
- return w;
+ return (unsigned long)w;
legacy:
# endif
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 08/43] rv64ilp32_abi: riscv: bitops: Adapt ctzw & clzw of zbb extension
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (6 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 07/43] rv64ilp32_abi: riscv: arch_hweight: Adapt cpopw & cpop of zbb extension guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 09/43] rv64ilp32_abi: riscv: Reuse LP64 SBI interface guoren
` (36 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI is based on 64-bit ISA, but BITS_PER_LONG is 32.
Use ctzw and clzw for int and long types instead of ctz and clz.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/bitops.h | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitops.h
index c6bd3d8354a9..d041b9e3ba84 100644
--- a/arch/riscv/include/asm/bitops.h
+++ b/arch/riscv/include/asm/bitops.h
@@ -35,14 +35,27 @@
#include <asm/alternative-macros.h>
#include <asm/hwcap.h>
-#if (BITS_PER_LONG == 64)
+#if (__riscv_xlen == 64)
#define CTZW "ctzw "
#define CLZW "clzw "
+
+#if (BITS_PER_LONG == 64)
+#define CTZ "ctz "
+#define CLZ "clz "
#elif (BITS_PER_LONG == 32)
+#define CTZ "ctzw "
+#define CLZ "clzw "
+#else
+#error "Unexpected BITS_PER_LONG"
+#endif
+
+#elif (__riscv_xlen == 32)
#define CTZW "ctz "
#define CLZW "clz "
+#define CTZ "ctz "
+#define CLZ "clz "
#else
-#error "Unexpected BITS_PER_LONG"
+#error "Unexpected __riscv_xlen"
#endif
static __always_inline unsigned long variable__ffs(unsigned long word)
@@ -53,7 +66,7 @@ static __always_inline unsigned long variable__ffs(unsigned long word)
asm volatile (".option push\n"
".option arch,+zbb\n"
- "ctz %0, %1\n"
+ CTZ "%0, %1\n"
".option pop\n"
: "=r" (word) : "r" (word) :);
@@ -82,7 +95,7 @@ static __always_inline unsigned long variable__fls(unsigned long word)
asm volatile (".option push\n"
".option arch,+zbb\n"
- "clz %0, %1\n"
+ CLZ "%0, %1\n"
".option pop\n"
: "=r" (word) : "r" (word) :);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 09/43] rv64ilp32_abi: riscv: Reuse LP64 SBI interface
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (7 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 08/43] rv64ilp32_abi: riscv: bitops: Adapt ctzw & clzw " guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 10/43] rv64ilp32_abi: riscv: Update SATP.MODE.ASID width guoren
` (35 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI leverages the LP64 SBI interface, enabling the
RV64ILP32 Linux kernel to run seamlessly on LP64 OpenSBI or KVM.
Using RV64ILP32 Linux doesn't require changing the bootloader,
firmware, or hypervisor; it could replace the LP64 kernel directly.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/cpu_ops_sbi.h | 4 ++--
arch/riscv/include/asm/sbi.h | 22 +++++++++++-----------
arch/riscv/kernel/cpu_ops_sbi.c | 4 ++--
arch/riscv/kernel/sbi_ecall.c | 22 +++++++++++-----------
4 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/arch/riscv/include/asm/cpu_ops_sbi.h b/arch/riscv/include/asm/cpu_ops_sbi.h
index d6e4665b3195..d967adad6b48 100644
--- a/arch/riscv/include/asm/cpu_ops_sbi.h
+++ b/arch/riscv/include/asm/cpu_ops_sbi.h
@@ -19,8 +19,8 @@ extern const struct cpu_operations cpu_ops_sbi;
* @stack_ptr: A pointer to the hart specific sp
*/
struct sbi_hart_boot_data {
- void *task_ptr;
- void *stack_ptr;
+ xlen_t task_ptr;
+ xlen_t stack_ptr;
};
#endif
diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index 3d250824178b..fd9a9c723ec6 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -138,16 +138,16 @@ enum sbi_ext_pmu_fid {
};
union sbi_pmu_ctr_info {
- unsigned long value;
+ xlen_t value;
struct {
- unsigned long csr:12;
- unsigned long width:6;
+ xlen_t csr:12;
+ xlen_t width:6;
#if __riscv_xlen == 32
- unsigned long reserved:13;
+ xlen_t reserved:13;
#else
- unsigned long reserved:45;
+ xlen_t reserved:45;
#endif
- unsigned long type:1;
+ xlen_t type:1;
};
};
@@ -422,15 +422,15 @@ enum sbi_ext_nacl_feature {
extern unsigned long sbi_spec_version;
struct sbiret {
- long error;
- long value;
+ xlen_t error;
+ xlen_t value;
};
void sbi_init(void);
long __sbi_base_ecall(int fid);
-struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1,
- unsigned long arg2, unsigned long arg3,
- unsigned long arg4, unsigned long arg5,
+struct sbiret __sbi_ecall(xlen_t arg0, xlen_t arg1,
+ xlen_t arg2, xlen_t arg3,
+ xlen_t arg4, xlen_t arg5,
int fid, int ext);
#define sbi_ecall(e, f, a0, a1, a2, a3, a4, a5) \
__sbi_ecall(a0, a1, a2, a3, a4, a5, f, e)
diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sbi.c
index e6fbaaf54956..f9ef3c0155f4 100644
--- a/arch/riscv/kernel/cpu_ops_sbi.c
+++ b/arch/riscv/kernel/cpu_ops_sbi.c
@@ -71,8 +71,8 @@ static int sbi_cpu_start(unsigned int cpuid, struct task_struct *tidle)
/* Make sure tidle is updated */
smp_mb();
- bdata->task_ptr = tidle;
- bdata->stack_ptr = task_pt_regs(tidle);
+ bdata->task_ptr = (ulong)tidle;
+ bdata->stack_ptr = (ulong)task_pt_regs(tidle);
/* Make sure boot data is updated */
smp_mb();
hsm_data = __pa(bdata);
diff --git a/arch/riscv/kernel/sbi_ecall.c b/arch/riscv/kernel/sbi_ecall.c
index 24aabb4fbde3..ee22e69d70da 100644
--- a/arch/riscv/kernel/sbi_ecall.c
+++ b/arch/riscv/kernel/sbi_ecall.c
@@ -17,23 +17,23 @@ long __sbi_base_ecall(int fid)
}
EXPORT_SYMBOL(__sbi_base_ecall);
-struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1,
- unsigned long arg2, unsigned long arg3,
- unsigned long arg4, unsigned long arg5,
+struct sbiret __sbi_ecall(xlen_t arg0, xlen_t arg1,
+ xlen_t arg2, xlen_t arg3,
+ xlen_t arg4, xlen_t arg5,
int fid, int ext)
{
struct sbiret ret;
trace_sbi_call(ext, fid);
- register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0);
- register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1);
- register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2);
- register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3);
- register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4);
- register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5);
- register uintptr_t a6 asm ("a6") = (uintptr_t)(fid);
- register uintptr_t a7 asm ("a7") = (uintptr_t)(ext);
+ register xlen_t a0 asm ("a0") = (xlen_t)(arg0);
+ register xlen_t a1 asm ("a1") = (xlen_t)(arg1);
+ register xlen_t a2 asm ("a2") = (xlen_t)(arg2);
+ register xlen_t a3 asm ("a3") = (xlen_t)(arg3);
+ register xlen_t a4 asm ("a4") = (xlen_t)(arg4);
+ register xlen_t a5 asm ("a5") = (xlen_t)(arg5);
+ register xlen_t a6 asm ("a6") = (xlen_t)(fid);
+ register xlen_t a7 asm ("a7") = (xlen_t)(ext);
asm volatile ("ecall"
: "+r" (a0), "+r" (a1)
: "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7)
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 10/43] rv64ilp32_abi: riscv: Update SATP.MODE.ASID width
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (8 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 09/43] rv64ilp32_abi: riscv: Reuse LP64 SBI interface guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 11/43] rv64ilp32_abi: riscv: Introduce PTR_L and PTR_S guoren
` (34 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV32 employs 9-bit asid_bits due to CSR's xlen=32 constraint,
whereas RV64ILP32 ABI, rooted in RV64 ISA, features a 64-bit
satp CSR. Hence, for rv64ilp32 abi, the exact asid mechanism as
in 64-bit architecture is adopted.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/mm/context.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
index 4abe3de23225..c3f9926d9337 100644
--- a/arch/riscv/mm/context.c
+++ b/arch/riscv/mm/context.c
@@ -226,14 +226,18 @@ static inline void set_mm(struct mm_struct *prev,
static int __init asids_init(void)
{
- unsigned long asid_bits, old;
+ xlen_t asid_bits, old;
/* Figure-out number of ASID bits in HW */
old = csr_read(CSR_SATP);
asid_bits = old | (SATP_ASID_MASK << SATP_ASID_SHIFT);
csr_write(CSR_SATP, asid_bits);
asid_bits = (csr_read(CSR_SATP) >> SATP_ASID_SHIFT) & SATP_ASID_MASK;
- asid_bits = fls_long(asid_bits);
+#if __riscv_xlen == 64
+ asid_bits = fls64(asid_bits);
+#else
+ asid_bits = fls(asid_bits);
+#endif
csr_write(CSR_SATP, old);
/*
@@ -265,9 +269,9 @@ static int __init asids_init(void)
static_branch_enable(&use_asid_allocator);
pr_info("ASID allocator using %lu bits (%lu entries)\n",
- asid_bits, num_asids);
+ (ulong)asid_bits, num_asids);
} else {
- pr_info("ASID allocator disabled (%lu bits)\n", asid_bits);
+ pr_info("ASID allocator disabled (%lu bits)\n", (ulong)asid_bits);
}
return 0;
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 11/43] rv64ilp32_abi: riscv: Introduce PTR_L and PTR_S
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (9 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 10/43] rv64ilp32_abi: riscv: Update SATP.MODE.ASID width guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 12/43] rv64ilp32_abi: riscv: Introduce cmpxchg_double guoren
` (33 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
REG_L and REG_S can't satisfy rv64ilp32 abi requirements, because
BITS_PER_LONG != __riscv_xlen. So we introduce new PTR_L and PTR_S
macro to help head.S and entry.S deal with the pointer data type.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/asm.h | 13 +++++++++----
arch/riscv/include/asm/scs.h | 4 ++--
arch/riscv/kernel/entry.S | 32 ++++++++++++++++----------------
arch/riscv/kernel/head.S | 8 ++++----
4 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
index 776354895b81..e37d73abbedd 100644
--- a/arch/riscv/include/asm/asm.h
+++ b/arch/riscv/include/asm/asm.h
@@ -38,6 +38,7 @@
#define RISCV_SZPTR "8"
#define RISCV_LGPTR "3"
#endif
+#define __PTR_SEL(a, b) __ASM_STR(a)
#elif __SIZEOF_POINTER__ == 4
#ifdef __ASSEMBLY__
#define RISCV_PTR .word
@@ -48,10 +49,14 @@
#define RISCV_SZPTR "4"
#define RISCV_LGPTR "2"
#endif
+#define __PTR_SEL(a, b) __ASM_STR(b)
#else
#error "Unexpected __SIZEOF_POINTER__"
#endif
+#define PTR_L __PTR_SEL(ld, lw)
+#define PTR_S __PTR_SEL(sd, sw)
+
#if (__SIZEOF_INT__ == 4)
#define RISCV_INT __ASM_STR(.word)
#define RISCV_SZINT __ASM_STR(4)
@@ -83,18 +88,18 @@
.endm
#ifdef CONFIG_SMP
-#ifdef CONFIG_32BIT
+#if BITS_PER_LONG == 32
#define PER_CPU_OFFSET_SHIFT 2
#else
#define PER_CPU_OFFSET_SHIFT 3
#endif
.macro asm_per_cpu dst sym tmp
- REG_L \tmp, TASK_TI_CPU_NUM(tp)
+ PTR_L \tmp, TASK_TI_CPU_NUM(tp)
slli \tmp, \tmp, PER_CPU_OFFSET_SHIFT
la \dst, __per_cpu_offset
add \dst, \dst, \tmp
- REG_L \tmp, 0(\dst)
+ PTR_L \tmp, 0(\dst)
la \dst, \sym
add \dst, \dst, \tmp
.endm
@@ -106,7 +111,7 @@
.macro load_per_cpu dst ptr tmp
asm_per_cpu \dst \ptr \tmp
- REG_L \dst, 0(\dst)
+ PTR_L \dst, 0(\dst)
.endm
#ifdef CONFIG_SHADOW_CALL_STACK
diff --git a/arch/riscv/include/asm/scs.h b/arch/riscv/include/asm/scs.h
index 0e45db78b24b..30929afb4e1a 100644
--- a/arch/riscv/include/asm/scs.h
+++ b/arch/riscv/include/asm/scs.h
@@ -20,7 +20,7 @@
/* Load task_scs_sp(current) to gp. */
.macro scs_load_current
- REG_L gp, TASK_TI_SCS_SP(tp)
+ PTR_L gp, TASK_TI_SCS_SP(tp)
.endm
/* Load task_scs_sp(current) to gp, but only if tp has changed. */
@@ -32,7 +32,7 @@
/* Save gp to task_scs_sp(current). */
.macro scs_save_current
- REG_S gp, TASK_TI_SCS_SP(tp)
+ PTR_S gp, TASK_TI_SCS_SP(tp)
.endm
#else /* CONFIG_SHADOW_CALL_STACK */
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 33a5a9f2a0d4..2cf36e3ab6b9 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -117,19 +117,19 @@ SYM_CODE_START(handle_exception)
new_vmalloc_check
#endif
- REG_S sp, TASK_TI_KERNEL_SP(tp)
+ PTR_S sp, TASK_TI_KERNEL_SP(tp)
#ifdef CONFIG_VMAP_STACK
addi sp, sp, -(PT_SIZE_ON_STACK)
srli sp, sp, THREAD_SHIFT
andi sp, sp, 0x1
bnez sp, handle_kernel_stack_overflow
- REG_L sp, TASK_TI_KERNEL_SP(tp)
+ PTR_L sp, TASK_TI_KERNEL_SP(tp)
#endif
.Lsave_context:
- REG_S sp, TASK_TI_USER_SP(tp)
- REG_L sp, TASK_TI_KERNEL_SP(tp)
+ PTR_S sp, TASK_TI_USER_SP(tp)
+ PTR_L sp, TASK_TI_KERNEL_SP(tp)
addi sp, sp, -(PT_SIZE_ON_STACK)
REG_S x1, PT_RA(sp)
REG_S x3, PT_GP(sp)
@@ -145,7 +145,7 @@ SYM_CODE_START(handle_exception)
*/
li t0, SR_SUM | SR_FS_VS
- REG_L s0, TASK_TI_USER_SP(tp)
+ PTR_L s0, TASK_TI_USER_SP(tp)
csrrc s1, CSR_STATUS, t0
csrr s2, CSR_EPC
csrr s3, CSR_TVAL
@@ -193,7 +193,7 @@ SYM_CODE_START(handle_exception)
add t0, t1, t0
/* Check if exception code lies within bounds */
bgeu t0, t2, 3f
- REG_L t1, 0(t0)
+ PTR_L t1, 0(t0)
2: jalr t1
j ret_from_exception
3:
@@ -226,7 +226,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
/* Save unwound kernel stack pointer in thread_info */
addi s0, sp, PT_SIZE_ON_STACK
- REG_S s0, TASK_TI_KERNEL_SP(tp)
+ PTR_S s0, TASK_TI_KERNEL_SP(tp)
/* Save the kernel shadow call stack pointer */
scs_save_current
@@ -301,7 +301,7 @@ SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)
REG_S x5, PT_T0(sp)
save_from_x6_to_x31
- REG_L s0, TASK_TI_KERNEL_SP(tp)
+ PTR_L s0, TASK_TI_KERNEL_SP(tp)
csrr s1, CSR_STATUS
csrr s2, CSR_EPC
csrr s3, CSR_TVAL
@@ -341,8 +341,8 @@ SYM_CODE_END(ret_from_fork)
SYM_FUNC_START(call_on_irq_stack)
/* Create a frame record to save ra and s0 (fp) */
addi sp, sp, -STACKFRAME_SIZE_ON_STACK
- REG_S ra, STACKFRAME_RA(sp)
- REG_S s0, STACKFRAME_FP(sp)
+ PTR_S ra, STACKFRAME_RA(sp)
+ PTR_S s0, STACKFRAME_FP(sp)
addi s0, sp, STACKFRAME_SIZE_ON_STACK
/* Switch to the per-CPU shadow call stack */
@@ -360,8 +360,8 @@ SYM_FUNC_START(call_on_irq_stack)
/* Switch back to the thread stack and restore ra and s0 */
addi sp, s0, -STACKFRAME_SIZE_ON_STACK
- REG_L ra, STACKFRAME_RA(sp)
- REG_L s0, STACKFRAME_FP(sp)
+ PTR_L ra, STACKFRAME_RA(sp)
+ PTR_L s0, STACKFRAME_FP(sp)
addi sp, sp, STACKFRAME_SIZE_ON_STACK
ret
@@ -383,8 +383,8 @@ SYM_FUNC_START(__switch_to)
li a4, TASK_THREAD_RA
add a3, a0, a4
add a4, a1, a4
- REG_S ra, TASK_THREAD_RA_RA(a3)
- REG_S sp, TASK_THREAD_SP_RA(a3)
+ PTR_S ra, TASK_THREAD_RA_RA(a3)
+ PTR_S sp, TASK_THREAD_SP_RA(a3)
REG_S s0, TASK_THREAD_S0_RA(a3)
REG_S s1, TASK_THREAD_S1_RA(a3)
REG_S s2, TASK_THREAD_S2_RA(a3)
@@ -400,8 +400,8 @@ SYM_FUNC_START(__switch_to)
/* Save the kernel shadow call stack pointer */
scs_save_current
/* Restore context from next->thread */
- REG_L ra, TASK_THREAD_RA_RA(a4)
- REG_L sp, TASK_THREAD_SP_RA(a4)
+ PTR_L ra, TASK_THREAD_RA_RA(a4)
+ PTR_L sp, TASK_THREAD_SP_RA(a4)
REG_L s0, TASK_THREAD_S0_RA(a4)
REG_L s1, TASK_THREAD_S1_RA(a4)
REG_L s2, TASK_THREAD_S2_RA(a4)
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 356d5397b2a2..e55a92be12b1 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -42,7 +42,7 @@ SYM_CODE_START(_start)
/* Image load offset (0MB) from start of RAM for M-mode */
.dword 0
#else
-#if __riscv_xlen == 64
+#ifdef CONFIG_64BIT
/* Image load offset(2MB) from start of RAM */
.dword 0x200000
#else
@@ -75,7 +75,7 @@ relocate_enable_mmu:
/* Relocate return address */
la a1, kernel_map
XIP_FIXUP_OFFSET a1
- REG_L a1, KERNEL_MAP_VIRT_ADDR(a1)
+ PTR_L a1, KERNEL_MAP_VIRT_ADDR(a1)
la a2, _start
sub a1, a1, a2
add ra, ra, a1
@@ -349,8 +349,8 @@ SYM_CODE_START(_start_kernel)
*/
.Lwait_for_cpu_up:
/* FIXME: We should WFI to save some energy here. */
- REG_L sp, (a1)
- REG_L tp, (a2)
+ PTR_L sp, (a1)
+ PTR_L tp, (a2)
beqz sp, .Lwait_for_cpu_up
beqz tp, .Lwait_for_cpu_up
fence
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 12/43] rv64ilp32_abi: riscv: Introduce cmpxchg_double
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (10 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 11/43] rv64ilp32_abi: riscv: Introduce PTR_L and PTR_S guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 13/43] rv64ilp32_abi: riscv: Correct stackframe layout guoren
` (32 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 abi has the ability to exclusively load and store
(ld/sd) a pair of words from an address. Then the SLUB can take
advantage of a cmpxchg_double implementation to avoid taking some
locks.
This patch provides an implementation of cmpxchg_double for 32-bit
pairs, and activates the logic required for the SLUB to use these
functions (HAVE_ALIGNED_STRUCT_PAGE and HAVE_CMPXCHG_DOUBLE).
Inspired from the commit: 5284e1b4bc8a ("arm64: xchg: Implement
cmpxchg_double")
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/Kconfig | 1 +
arch/riscv/include/asm/cmpxchg.h | 53 ++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index da2111b0111c..884235cf4092 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -141,6 +141,7 @@ config RISCV
select HAVE_ARCH_USERFAULTFD_MINOR if 64BIT && USERFAULTFD
select HAVE_ARCH_VMAP_STACK if MMU && 64BIT
select HAVE_ASM_MODVERSIONS
+ select HAVE_CMPXCHG_DOUBLE if ABI_RV64ILP32
select HAVE_CONTEXT_TRACKING_USER
select HAVE_DEBUG_KMEMLEAK
select HAVE_DMA_CONTIGUOUS if MMU
diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
index 938d50194dba..944f6d825f78 100644
--- a/arch/riscv/include/asm/cmpxchg.h
+++ b/arch/riscv/include/asm/cmpxchg.h
@@ -7,6 +7,7 @@
#define _ASM_RISCV_CMPXCHG_H
#include <linux/bug.h>
+#include <linux/mmdebug.h>
#include <asm/alternative-macros.h>
#include <asm/fence.h>
@@ -409,6 +410,58 @@ static __always_inline void __cmpwait(volatile void *ptr,
#define __cmpwait_relaxed(ptr, val) \
__cmpwait((ptr), (unsigned long)(val), sizeof(*(ptr)))
+
+#ifdef CONFIG_HAVE_CMPXCHG_DOUBLE
+#define system_has_cmpxchg_double() 1
+
+#define __cmpxchg_double_check(ptr1, ptr2) \
+({ \
+ if (sizeof(*(ptr1)) != 4) \
+ BUILD_BUG(); \
+ if (sizeof(*(ptr2)) != 4) \
+ BUILD_BUG(); \
+ VM_BUG_ON((ulong *)(ptr2) - (ulong *)(ptr1) != 1); \
+ VM_BUG_ON(((ulong)ptr1 & 0x7) != 0); \
+})
+
+#define __cmpxchg_double(old1, old2, new1, new2, ptr) \
+({ \
+ __typeof__(ptr) __ptr = (ptr); \
+ register unsigned int __ret; \
+ u64 __old; \
+ u64 __new; \
+ u64 __tmp; \
+ switch (sizeof(*(ptr))) { \
+ case 4: \
+ __old = ((u64)old2 << 32) | (u64)old1; \
+ __new = ((u64)new2 << 32) | (u64)new1; \
+ __asm__ __volatile__ ( \
+ "0: lr.d %0, %2\n" \
+ " bne %0, %z3, 1f\n" \
+ " sc.d %1, %z4, %2\n" \
+ " bnez %1, 0b\n" \
+ "1:\n" \
+ : "=&r" (__tmp), "=&r" (__ret), "+A" (*__ptr) \
+ : "rJ" (__old), "rJ" (__new) \
+ : "memory"); \
+ __ret = (__old == __tmp); \
+ break; \
+ default: \
+ BUILD_BUG(); \
+ } \
+ __ret; \
+})
+
+#define arch_cmpxchg_double(ptr1, ptr2, o1, o2, n1, n2) \
+({ \
+ int __ret; \
+ __cmpxchg_double_check(ptr1, ptr2); \
+ __ret = __cmpxchg_double((ulong)(o1), (ulong)(o2), \
+ (ulong)(n1), (ulong)(n2), \
+ ptr1); \
+ __ret; \
+})
+#endif
#endif
#endif /* _ASM_RISCV_CMPXCHG_H */
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 13/43] rv64ilp32_abi: riscv: Correct stackframe layout
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (11 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 12/43] rv64ilp32_abi: riscv: Introduce cmpxchg_double guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 14/43] rv64ilp32_abi: riscv: Adapt kernel module code guoren
` (31 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
In RV64ILP32 ABI, the callee saved fp & ra are 64-bit width,
not long size. This patch corrects the layout for the struct
stackframe.
echo c > /proc/sysrq-trigger
Before the patch:
sysrq: Trigger a crash
Kernel panic - not syncing: sysrq triggered crash
CPU: 0 PID: 102 Comm: sh Not tainted ...
Hardware name: riscv-virtio,qemu (DT)
Call Trace:
---[ end Kernel panic - not syncing: sysrq triggered crash ]---
After the patch:
sysrq: Trigger a crash
Kernel panic - not syncing: sysrq triggered crash
CPU: 0 PID: 102 Comm: sh Not tainted ...
Hardware name: riscv-virtio,qemu (DT)
Call Trace:
[<c00050c8>] dump_backtrace+0x1e/0x26
[<c086dcae>] show_stack+0x2e/0x3c
[<c0878e00>] dump_stack_lvl+0x40/0x5a
[<c0878e30>] dump_stack+0x16/0x1e
[<c086df7c>] panic+0x10c/0x2a8
[<c04f4c1e>] sysrq_reset_seq_param_set+0x0/0x76
[<c04f52cc>] __handle_sysrq+0x9c/0x19c
[<c04f5946>] write_sysrq_trigger+0x64/0x78
[<c020c7f6>] proc_reg_write+0x4a/0xa2
[<c01acf0a>] vfs_write+0xac/0x308
[<c01ad2b8>] ksys_write+0x62/0xda
[<c01ad33e>] sys_write+0xe/0x16
[<c0879860>] do_trap_ecall_u+0xd8/0xda
[<c00037de>] ret_from_exception+0x0/0x66
---[ end Kernel panic - not syncing: sysrq triggered crash ]---
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/stacktrace.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/riscv/include/asm/stacktrace.h b/arch/riscv/include/asm/stacktrace.h
index b1495a7e06ce..556655cab09d 100644
--- a/arch/riscv/include/asm/stacktrace.h
+++ b/arch/riscv/include/asm/stacktrace.h
@@ -8,7 +8,13 @@
struct stackframe {
unsigned long fp;
+#if IS_ENABLED(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ unsigned long __fp;
+#endif
unsigned long ra;
+#if IS_ENABLED(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ unsigned long __ra;
+#endif
};
extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 14/43] rv64ilp32_abi: riscv: Adapt kernel module code
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (12 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 13/43] rv64ilp32_abi: riscv: Correct stackframe layout guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 15/43] rv64ilp32_abi: riscv: mm: Adapt MMU_SV39 for 2GiB address space guoren
` (30 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
Because riscv_insn_valid_32bit_offset is always true for ILP32,
use BITS_PER_LONG instead of CONFIG_64BIT.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/kernel/module.c | 2 +-
include/asm-generic/module.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 47d0ebeec93c..d7360878e618 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -45,7 +45,7 @@ struct relocation_handlers {
*/
static bool riscv_insn_valid_32bit_offset(ptrdiff_t val)
{
-#ifdef CONFIG_32BIT
+#if BITS_PER_LONG == 32
return true;
#else
return (-(1L << 31) - (1L << 11)) <= val && val < ((1L << 31) - (1L << 11));
diff --git a/include/asm-generic/module.h b/include/asm-generic/module.h
index 98e1541b72b7..f870171b14a8 100644
--- a/include/asm-generic/module.h
+++ b/include/asm-generic/module.h
@@ -12,7 +12,7 @@ struct mod_arch_specific
};
#endif
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#define Elf_Shdr Elf64_Shdr
#define Elf_Phdr Elf64_Phdr
#define Elf_Sym Elf64_Sym
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 15/43] rv64ilp32_abi: riscv: mm: Adapt MMU_SV39 for 2GiB address space
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (13 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 14/43] rv64ilp32_abi: riscv: Adapt kernel module code guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 16/43] rv64ilp32_abi: riscv: Support physical addresses >= 0x80000000 guoren
` (29 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI has two independent 2GiB address space for
kernel and user.
There is no sv32 mmu mode support in xlen=64 ISA. This commit
enables MMU_SV39 for RV64ILP32 to satisfy the user & kernel 2GiB
mapping requirements. The Sv39 is the mandatory MMU mode when
rv64 satp != bare, so we needn't care about Sv48 & Sv57.
2GiB virtual userspace memory layout (u64lp64 ABI):
55555000-5560c000 r-xp 00000000 fe:00 17 /bin/busybox
5560c000-5560f000 r--p 000b7000 fe:00 17 /bin/busybox
5560f000-55610000 rw-p 000ba000 fe:00 17 /bin/busybox
55610000-55631000 rw-p 00000000 00:00 0 [heap]
77e69000-77e6b000 rw-p 00000000 00:00 0
77e6b000-77fba000 r-xp 00000000 fe:00 140 /lib/libc.so.6
77fba000-77fbd000 r--p 0014f000 fe:00 140 /lib/libc.so.6
77fbd000-77fbf000 rw-p 00152000 fe:00 140 /lib/libc.so.6
77fbf000-77fcb000 rw-p 00000000 00:00 0
77fcb000-77fd5000 r-xp 00000000 fe:00 148 /lib/libresolv.so.2
77fd5000-77fd6000 r--p 0000a000 fe:00 148 /lib/libresolv.so.2
77fd6000-77fd7000 rw-p 0000b000 fe:00 148 /lib/libresolv.so.2
77fd7000-77fd9000 rw-p 00000000 00:00 0
77fd9000-77fdb000 r--p 00000000 00:00 0 [vvar]
77fdb000-77fdc000 r-xp 00000000 00:00 0 [vdso]
77fdc000-77ffc000 r-xp 00000000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
77ffc000-77ffe000 r--p 0001f000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
77ffe000-78000000 rw-p 00021000 fe:00 135 /lib/ld-linux-riscv64-lp64d.so.1
7ffdf000-80000000 rw-p 00000000 00:00 0 [stack]
2GiB virtual kernel memory layout:
fixmap : 0x90a00000 - 0x90ffffff (6144 kB)
pci io : 0x91000000 - 0x91ffffff ( 16 MB)
vmemmap : 0x92000000 - 0x93ffffff ( 32 MB)
vmalloc : 0x94000000 - 0xb3ffffff ( 512 MB)
modules : 0xb4000000 - 0xb7ffffff ( 64 MB)
lowmem : 0xc0000000 - 0xc7ffffff ( 128 MB)
kasan : 0x80000000 - 0x8fffffff ( 256 MB)
kernel : 0xb8000000 - 0xbfffffff ( 128 MB)
For satp=sv39, introduce a double mapping to make the sign-extended
virtual address identical to the zero-extended virtual address:
+--------+ +---------+ +--------+
| | +--| 511:PUD1| | |
| | | +---------+ | |
| | | | 510:PUD0|--+ | |
| | | +---------+ | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | INVALID | | | |
| | | | | | | |
| .... | | | | | | .... |
| | | | | | | |
| | | +---------+ | | |
| | +--| 3:PUD1 | | | |
| | | +---------+ | | |
| | | | 2:PUD0 |--+ | |
| | | +---------+ | | |
| | | |1:USR_PUD| | | |
| | | +---------+ | | |
| | | |0:USR_PUD| | | |
+--------+<--+ +---------+ +-->+--------+
PUD1 ^ PGD PUD0
1GB | 4GB 1GB
|
+----------+
| Sv39 PGDP|
+----------+
SATP
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/Kconfig | 2 +-
arch/riscv/include/asm/page.h | 23 ++++++-----
arch/riscv/include/asm/pgtable-64.h | 55 ++++++++++++++------------
arch/riscv/include/asm/pgtable.h | 60 ++++++++++++++++++++++++-----
arch/riscv/include/asm/processor.h | 2 +-
arch/riscv/kernel/cpu.c | 4 +-
arch/riscv/mm/fault.c | 10 ++---
arch/riscv/mm/init.c | 55 ++++++++++++++++++--------
arch/riscv/mm/pageattr.c | 4 +-
arch/riscv/mm/pgtable.c | 2 +-
10 files changed, 145 insertions(+), 72 deletions(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 884235cf4092..9469cdc51ba4 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -293,7 +293,7 @@ config PAGE_OFFSET
hex
default 0x80000000 if !MMU && RISCV_M_MODE
default 0x80200000 if !MMU
- default 0xc0000000 if 32BIT
+ default 0xc0000000 if 32BIT || ABI_RV64ILP32
default 0xff60000000000000 if 64BIT
config KASAN_SHADOW_OFFSET
diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index 125f5ecd9565..45091a9de0d4 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -24,7 +24,7 @@
* When not using MMU this corresponds to the first free page in
* physical memory (aligned on a page boundary).
*/
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#ifdef CONFIG_MMU
#define PAGE_OFFSET kernel_map.page_offset
#else
@@ -38,7 +38,7 @@
#define PAGE_OFFSET_L3 _AC(0xffffffd600000000, UL)
#else
#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
-#endif /* CONFIG_64BIT */
+#endif /* BITS_PER_LONG == 64 */
#ifndef __ASSEMBLY__
@@ -56,19 +56,24 @@ void clear_page(void *page);
/*
* Use struct definitions to apply C type checking
*/
+#if CONFIG_PGTABLE_LEVELS > 2
+typedef u64 ptval_t;
+#else
+typedef ulong ptval_t;
+#endif
/* Page Global Directory entry */
typedef struct {
- unsigned long pgd;
+ ptval_t pgd;
} pgd_t;
/* Page Table entry */
typedef struct {
- unsigned long pte;
+ ptval_t pte;
} pte_t;
typedef struct {
- unsigned long pgprot;
+ ptval_t pgprot;
} pgprot_t;
typedef struct page *pgtable_t;
@@ -81,13 +86,13 @@ typedef struct page *pgtable_t;
#define __pgd(x) ((pgd_t) { (x) })
#define __pgprot(x) ((pgprot_t) { (x) })
-#ifdef CONFIG_64BIT
-#define PTE_FMT "%016lx"
+#if CONFIG_PGTABLE_LEVELS > 2
+#define PTE_FMT "%016llx"
#else
#define PTE_FMT "%08lx"
#endif
-#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
+#if (CONFIG_PGTABLE_LEVELS > 2) && defined(CONFIG_MMU)
/*
* We override this value as its generic definition uses __pa too early in
* the boot process (before kernel_map.va_pa_offset is set).
@@ -128,7 +133,7 @@ extern unsigned long vmemmap_start_pfn;
((x) >= kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_map.size))
#define is_linear_mapping(x) \
- ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE))
+ ((x) >= PAGE_OFFSET && ((BITS_PER_LONG == 32) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE))
#ifndef CONFIG_DEBUG_VIRTUAL
#define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset))
diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
index 0897dd99ab8d..401c012d0b66 100644
--- a/arch/riscv/include/asm/pgtable-64.h
+++ b/arch/riscv/include/asm/pgtable-64.h
@@ -19,7 +19,12 @@ extern bool pgtable_l5_enabled;
#define PGDIR_SHIFT (pgtable_l5_enabled ? PGDIR_SHIFT_L5 : \
(pgtable_l4_enabled ? PGDIR_SHIFT_L4 : PGDIR_SHIFT_L3))
/* Size of region mapped by a page global directory */
+#if BITS_PER_LONG == 64
#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
+#else
+#define PGDIR_SIZE (_AC(1, ULL) << PGDIR_SHIFT)
+#endif
+
#define PGDIR_MASK (~(PGDIR_SIZE - 1))
/* p4d is folded into pgd in case of 4-level page table */
@@ -28,7 +33,7 @@ extern bool pgtable_l5_enabled;
#define P4D_SHIFT_L5 39
#define P4D_SHIFT (pgtable_l5_enabled ? P4D_SHIFT_L5 : \
(pgtable_l4_enabled ? P4D_SHIFT_L4 : P4D_SHIFT_L3))
-#define P4D_SIZE (_AC(1, UL) << P4D_SHIFT)
+#define P4D_SIZE (_AC(1, ULL) << P4D_SHIFT)
#define P4D_MASK (~(P4D_SIZE - 1))
/* pud is folded into pgd in case of 3-level page table */
@@ -43,7 +48,7 @@ extern bool pgtable_l5_enabled;
/* Page 4th Directory entry */
typedef struct {
- unsigned long p4d;
+ u64 p4d;
} p4d_t;
#define p4d_val(x) ((x).p4d)
@@ -52,7 +57,7 @@ typedef struct {
/* Page Upper Directory entry */
typedef struct {
- unsigned long pud;
+ u64 pud;
} pud_t;
#define pud_val(x) ((x).pud)
@@ -61,7 +66,7 @@ typedef struct {
/* Page Middle Directory entry */
typedef struct {
- unsigned long pmd;
+ u64 pmd;
} pmd_t;
#define pmd_val(x) ((x).pmd)
@@ -74,7 +79,7 @@ typedef struct {
* | 63 | 62 61 | 60 54 | 53 10 | 9 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* N MT RSV PFN reserved for SW D A G U X W R V
*/
-#define _PAGE_PFN_MASK GENMASK(53, 10)
+#define _PAGE_PFN_MASK GENMASK_ULL(53, 10)
/*
* [63] Svnapot definitions:
@@ -82,7 +87,7 @@ typedef struct {
* 1 Svnapot enabled
*/
#define _PAGE_NAPOT_SHIFT 63
-#define _PAGE_NAPOT BIT(_PAGE_NAPOT_SHIFT)
+#define _PAGE_NAPOT BIT_ULL(_PAGE_NAPOT_SHIFT)
/*
* Only 64KB (order 4) napot ptes supported.
*/
@@ -100,9 +105,9 @@ enum napot_cont_order {
#define napot_cont_order(val) (__builtin_ctzl((val.pte >> _PAGE_PFN_SHIFT) << 1))
#define napot_cont_shift(order) ((order) + PAGE_SHIFT)
-#define napot_cont_size(order) BIT(napot_cont_shift(order))
+#define napot_cont_size(order) BIT_ULL(napot_cont_shift(order))
#define napot_cont_mask(order) (~(napot_cont_size(order) - 1UL))
-#define napot_pte_num(order) BIT(order)
+#define napot_pte_num(order) BIT_ULL(order)
#ifdef CONFIG_RISCV_ISA_SVNAPOT
#define HUGE_MAX_HSTATE (2 + (NAPOT_ORDER_MAX - NAPOT_CONT_ORDER_BASE))
@@ -118,8 +123,8 @@ enum napot_cont_order {
* 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory
* 11 - Rsvd Reserved for future standard use
*/
-#define _PAGE_NOCACHE_SVPBMT (1UL << 61)
-#define _PAGE_IO_SVPBMT (1UL << 62)
+#define _PAGE_NOCACHE_SVPBMT (1ULL << 61)
+#define _PAGE_IO_SVPBMT (1ULL << 62)
#define _PAGE_MTMASK_SVPBMT (_PAGE_NOCACHE_SVPBMT | _PAGE_IO_SVPBMT)
/*
@@ -133,10 +138,10 @@ enum napot_cont_order {
* 01110 - PMA Weakly-ordered, Cacheable, Bufferable, Shareable, Non-trustable
* 10010 - IO Strongly-ordered, Non-cacheable, Non-bufferable, Shareable, Non-trustable
*/
-#define _PAGE_PMA_THEAD ((1UL << 62) | (1UL << 61) | (1UL << 60))
-#define _PAGE_NOCACHE_THEAD ((1UL << 61) | (1UL << 60))
-#define _PAGE_IO_THEAD ((1UL << 63) | (1UL << 60))
-#define _PAGE_MTMASK_THEAD (_PAGE_PMA_THEAD | _PAGE_IO_THEAD | (1UL << 59))
+#define _PAGE_PMA_THEAD ((1ULL << 62) | (1ULL << 61) | (1ULL << 60))
+#define _PAGE_NOCACHE_THEAD ((1ULL << 61) | (1ULL << 60))
+#define _PAGE_IO_THEAD ((1ULL << 63) | (1ULL << 60))
+#define _PAGE_MTMASK_THEAD (_PAGE_PMA_THEAD | _PAGE_IO_THEAD | (1ULL << 59))
static inline u64 riscv_page_mtmask(void)
{
@@ -167,7 +172,7 @@ static inline u64 riscv_page_io(void)
#define _PAGE_MTMASK riscv_page_mtmask()
/* Set of bits to preserve across pte_modify() */
-#define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \
+#define _PAGE_CHG_MASK (~(u64)(_PAGE_PRESENT | _PAGE_READ | \
_PAGE_WRITE | _PAGE_EXEC | \
_PAGE_USER | _PAGE_GLOBAL | \
_PAGE_MTMASK))
@@ -208,12 +213,12 @@ static inline void pud_clear(pud_t *pudp)
set_pud(pudp, __pud(0));
}
-static inline pud_t pfn_pud(unsigned long pfn, pgprot_t prot)
+static inline pud_t pfn_pud(u64 pfn, pgprot_t prot)
{
return __pud((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
}
-static inline unsigned long _pud_pfn(pud_t pud)
+static inline u64 _pud_pfn(pud_t pud)
{
return __page_val_to_pfn(pud_val(pud));
}
@@ -248,16 +253,16 @@ static inline bool mm_pud_folded(struct mm_struct *mm)
#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
-static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)
+static inline pmd_t pfn_pmd(u64 pfn, pgprot_t prot)
{
- unsigned long prot_val = pgprot_val(prot);
+ u64 prot_val = pgprot_val(prot);
ALT_THEAD_PMA(prot_val);
return __pmd((pfn << _PAGE_PFN_SHIFT) | prot_val);
}
-static inline unsigned long _pmd_pfn(pmd_t pmd)
+static inline u64 _pmd_pfn(pmd_t pmd)
{
return __page_val_to_pfn(pmd_val(pmd));
}
@@ -265,13 +270,13 @@ static inline unsigned long _pmd_pfn(pmd_t pmd)
#define mk_pmd(page, prot) pfn_pmd(page_to_pfn(page), prot)
#define pmd_ERROR(e) \
- pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
+ pr_err("%s:%d: bad pmd " PTE_FMT ".\n", __FILE__, __LINE__, pmd_val(e))
#define pud_ERROR(e) \
- pr_err("%s:%d: bad pud %016lx.\n", __FILE__, __LINE__, pud_val(e))
+ pr_err("%s:%d: bad pud " PTE_FMT ".\n", __FILE__, __LINE__, pud_val(e))
#define p4d_ERROR(e) \
- pr_err("%s:%d: bad p4d %016lx.\n", __FILE__, __LINE__, p4d_val(e))
+ pr_err("%s:%d: bad p4d " PTE_FMT ".\n", __FILE__, __LINE__, p4d_val(e))
static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
{
@@ -311,12 +316,12 @@ static inline void p4d_clear(p4d_t *p4d)
set_p4d(p4d, __p4d(0));
}
-static inline p4d_t pfn_p4d(unsigned long pfn, pgprot_t prot)
+static inline p4d_t pfn_p4d(u64 pfn, pgprot_t prot)
{
return __p4d((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
}
-static inline unsigned long _p4d_pfn(p4d_t p4d)
+static inline u64 _p4d_pfn(p4d_t p4d)
{
return __page_val_to_pfn(p4d_val(p4d));
}
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 050fdc49b5ad..5f1b48cb3311 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -9,6 +9,7 @@
#include <linux/mmzone.h>
#include <linux/sizes.h>
+#include <asm/bitsperlong.h>
#include <asm/pgtable-bits.h>
#ifndef CONFIG_MMU
@@ -19,8 +20,13 @@
#define ADDRESS_SPACE_END (UL(-1))
#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
/* Leave 2GB for kernel and BPF at the end of the address space */
#define KERNEL_LINK_ADDR (ADDRESS_SPACE_END - SZ_2G + 1)
+#elif BITS_PER_LONG == 32
+/* Leave 64MB for kernel and BPF below PAGE_OFFSET */
+#define KERNEL_LINK_ADDR (PAGE_OFFSET - SZ_64M)
+#endif
#else
#define KERNEL_LINK_ADDR PAGE_OFFSET
#endif
@@ -34,31 +40,45 @@
* Half of the kernel address space (1/4 of the entries of the page global
* directory) is for the direct mapping.
*/
+#if (BITS_PER_LONG == 32) && (CONFIG_PGTABLE_LEVELS > 2)
+#define KERN_VIRT_SIZE (PTRS_PER_PGD * PMD_SIZE)
+#else
#define KERN_VIRT_SIZE ((PTRS_PER_PGD / 2 * PGDIR_SIZE) / 2)
+#endif
#define VMALLOC_SIZE (KERN_VIRT_SIZE >> 1)
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+#define VMALLOC_END MODULES_LOWEST_VADDR
+#else
#define VMALLOC_END PAGE_OFFSET
-#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE)
+#endif
+#define VMALLOC_START (VMALLOC_END - VMALLOC_SIZE)
#define BPF_JIT_REGION_SIZE (SZ_128M)
-#ifdef CONFIG_64BIT
#define BPF_JIT_REGION_START (BPF_JIT_REGION_END - BPF_JIT_REGION_SIZE)
+#if BITS_PER_LONG == 64
#define BPF_JIT_REGION_END (MODULES_END)
#else
-#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END (VMALLOC_END)
#endif
/* Modules always live before the kernel */
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
/* This is used to define the end of the KASAN shadow region */
#define MODULES_LOWEST_VADDR (KERNEL_LINK_ADDR - SZ_2G)
#define MODULES_VADDR (PFN_ALIGN((unsigned long)&_end) - SZ_2G)
#define MODULES_END (PFN_ALIGN((unsigned long)&_start))
#else
+#ifdef CONFIG_64BIT
+#define MODULES_LOWEST_VADDR (KERNEL_LINK_ADDR - SZ_64M)
+#define MODULES_VADDR MODULES_LOWEST_VADDR
+#define MODULES_END KERNEL_LINK_ADDR
+#else
+#define MODULES_LOWEST_VADDR VMALLOC_START
#define MODULES_VADDR VMALLOC_START
#define MODULES_END VMALLOC_END
#endif
+#endif
/*
* Roughly size the vmemmap space to be large enough to fit enough
@@ -66,7 +86,7 @@
* position vmemmap directly below the VMALLOC region.
*/
#define VA_BITS_SV32 32
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 64)
#define VA_BITS_SV39 39
#define VA_BITS_SV48 48
#define VA_BITS_SV57 57
@@ -126,9 +146,14 @@
#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
#define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39)
+#if BITS_PER_LONG == 64
#define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64)
#define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BITS_64)
#else
+#define MMAP_VA_BITS VA_BITS_SV32
+#define MMAP_MIN_VA_BITS VA_BITS_SV32
+#endif
+#else
#include <asm/pgtable-32.h>
#endif /* CONFIG_64BIT */
@@ -252,7 +277,7 @@ static inline void pmd_clear(pmd_t *pmdp)
static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot)
{
- unsigned long prot_val = pgprot_val(prot);
+ ptval_t prot_val = pgprot_val(prot);
ALT_THEAD_PMA(prot_val);
@@ -591,7 +616,11 @@ extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long a
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
unsigned long address, pte_t *ptep)
{
+#if CONFIG_PGTABLE_LEVELS > 2
+ pte_t pte = __pte(atomic64_xchg((atomic64_t *)ptep, 0));
+#else
pte_t pte = __pte(atomic_long_xchg((atomic_long_t *)ptep, 0));
+#endif
page_table_check_pte_clear(mm, pte);
@@ -602,7 +631,11 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
static inline void ptep_set_wrprotect(struct mm_struct *mm,
unsigned long address, pte_t *ptep)
{
+#if CONFIG_PGTABLE_LEVELS > 2
+ atomic64_and(~(u64)_PAGE_WRITE, (atomic64_t *)ptep);
+#else
atomic_long_and(~(unsigned long)_PAGE_WRITE, (atomic_long_t *)ptep);
+#endif
}
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
@@ -636,7 +669,7 @@ static inline pgprot_t pgprot_nx(pgprot_t _prot)
#define pgprot_noncached pgprot_noncached
static inline pgprot_t pgprot_noncached(pgprot_t _prot)
{
- unsigned long prot = pgprot_val(_prot);
+ ptval_t prot = pgprot_val(_prot);
prot &= ~_PAGE_MTMASK;
prot |= _PAGE_IO;
@@ -647,7 +680,7 @@ static inline pgprot_t pgprot_noncached(pgprot_t _prot)
#define pgprot_writecombine pgprot_writecombine
static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
{
- unsigned long prot = pgprot_val(_prot);
+ ptval_t prot = pgprot_val(_prot);
prot &= ~_PAGE_MTMASK;
prot |= _PAGE_NOCACHE;
@@ -905,8 +938,12 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
* and give the kernel the other (upper) half.
*/
#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#define KERN_VIRT_START (-(BIT(VA_BITS)) + TASK_SIZE)
#else
+#define KERN_VIRT_START TASK_SIZE_32
+#endif
+#else
#define KERN_VIRT_START FIXADDR_START
#endif
@@ -915,6 +952,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
* Note that PGDIR_SIZE must evenly divide TASK_SIZE.
* Task size is:
* - 0x9fc00000 (~2.5GB) for RV32.
+ * - 0x80000000 ( 2GB) for RV32_COMPAT & RV64ILP32
* - 0x4000000000 ( 256GB) for RV64 using SV39 mmu
* - 0x800000000000 ( 128TB) for RV64 using SV48 mmu
* - 0x100000000000000 ( 64PB) for RV64 using SV57 mmu
@@ -928,15 +966,19 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
#ifdef CONFIG_64BIT
#define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2)
#define TASK_SIZE_MAX LONG_MAX
+#define TASK_SIZE_32 _AC(0x80000000, UL)
+#if BITS_PER_LONG == 64
#ifdef CONFIG_COMPAT
-#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE)
#define TASK_SIZE (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)
#else
#define TASK_SIZE TASK_SIZE_64
#endif
+#else
+#define TASK_SIZE TASK_SIZE_32
+#endif
#else
#define TASK_SIZE FIXADDR_START
#endif
diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h
index ca57a650c3d2..9f4e0be595fd 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -24,7 +24,7 @@
base; \
})
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1))
#define STACK_TOP_MAX TASK_SIZE_64
#else
diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index f6b13e9f5e6c..ce1440c63606 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -291,9 +291,9 @@ static void print_mmu(struct seq_file *f)
const char *sv_type;
#ifdef CONFIG_MMU
-#if defined(CONFIG_32BIT)
+#if CONFIG_PGTABLE_LEVELS == 2
sv_type = "sv32";
-#elif defined(CONFIG_64BIT)
+#else
if (pgtable_l5_enabled)
sv_type = "sv57";
else if (pgtable_l4_enabled)
diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index fcc23350610e..1e854e9633b3 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -40,25 +40,25 @@ static void show_pte(unsigned long addr)
pgdp = pgd_offset(mm, addr);
pgd = pgdp_get(pgdp);
- pr_alert("[%016lx] pgd=%016lx", addr, pgd_val(pgd));
+ pr_alert("[%016lx] pgd=" REG_FMT, addr, pgd_val(pgd));
if (pgd_none(pgd) || pgd_bad(pgd) || pgd_leaf(pgd))
goto out;
p4dp = p4d_offset(pgdp, addr);
p4d = p4dp_get(p4dp);
- pr_cont(", p4d=%016lx", p4d_val(p4d));
+ pr_cont(", p4d=" REG_FMT, p4d_val(p4d));
if (p4d_none(p4d) || p4d_bad(p4d) || p4d_leaf(p4d))
goto out;
pudp = pud_offset(p4dp, addr);
pud = pudp_get(pudp);
- pr_cont(", pud=%016lx", pud_val(pud));
+ pr_cont(", pud=" REG_FMT, pud_val(pud));
if (pud_none(pud) || pud_bad(pud) || pud_leaf(pud))
goto out;
pmdp = pmd_offset(pudp, addr);
pmd = pmdp_get(pmdp);
- pr_cont(", pmd=%016lx", pmd_val(pmd));
+ pr_cont(", pmd=" REG_FMT, pmd_val(pmd));
if (pmd_none(pmd) || pmd_bad(pmd) || pmd_leaf(pmd))
goto out;
@@ -67,7 +67,7 @@ static void show_pte(unsigned long addr)
goto out;
pte = ptep_get(ptep);
- pr_cont(", pte=%016lx", pte_val(pte));
+ pr_cont(", pte=" REG_FMT, pte_val(pte));
pte_unmap(ptep);
out:
pr_cont("\n");
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 15b2eda4c364..3cdbb033860e 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -46,16 +46,20 @@ EXPORT_SYMBOL(kernel_map);
#define kernel_map (*(struct kernel_mapping *)XIP_FIXUP(&kernel_map))
#endif
-#ifdef CONFIG_64BIT
+#if CONFIG_PGTABLE_LEVELS > 2
+#if BITS_PER_LONG == 64
u64 satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
#else
+u64 satp_mode __ro_after_init = SATP_MODE_39;
+#endif
+#else
u64 satp_mode __ro_after_init = SATP_MODE_32;
#endif
EXPORT_SYMBOL(satp_mode);
#ifdef CONFIG_64BIT
-bool pgtable_l4_enabled __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL);
-bool pgtable_l5_enabled __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL);
+bool pgtable_l4_enabled __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) && (BITS_PER_LONG == 64);
+bool pgtable_l5_enabled __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) && (BITS_PER_LONG == 64);
EXPORT_SYMBOL(pgtable_l4_enabled);
EXPORT_SYMBOL(pgtable_l5_enabled);
#endif
@@ -117,7 +121,7 @@ static inline void print_mlg(char *name, unsigned long b, unsigned long t)
(((t) - (b)) >> LOG2_SZ_1G));
}
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
static inline void print_mlt(char *name, unsigned long b, unsigned long t)
{
pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld TB)\n", name, b, t,
@@ -131,7 +135,7 @@ static inline void print_ml(char *name, unsigned long b, unsigned long t)
{
unsigned long diff = t - b;
- if (IS_ENABLED(CONFIG_64BIT) && (diff >> LOG2_SZ_1T) >= 10)
+ if ((BITS_PER_LONG == 64) && (diff >> LOG2_SZ_1T) >= 10)
print_mlt(name, b, t);
else if ((diff >> LOG2_SZ_1G) >= 10)
print_mlg(name, b, t);
@@ -164,7 +168,9 @@ static void __init print_vm_layout(void)
#endif
print_ml("kernel", (unsigned long)kernel_map.virt_addr,
- (unsigned long)ADDRESS_SPACE_END);
+ (BITS_PER_LONG == 64) ?
+ (unsigned long)ADDRESS_SPACE_END :
+ (unsigned long)PAGE_OFFSET);
}
}
#else
@@ -173,7 +179,8 @@ static void print_vm_layout(void) { }
void __init mem_init(void)
{
- bool swiotlb = max_pfn > PFN_DOWN(dma32_phys_limit);
+ bool swiotlb = (BITS_PER_LONG == 32) ? false:
+ (max_pfn > PFN_DOWN(dma32_phys_limit));
#ifdef CONFIG_FLATMEM
BUG_ON(!mem_map);
#endif /* CONFIG_FLATMEM */
@@ -319,7 +326,7 @@ static void __init setup_bootmem(void)
memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
dma_contiguous_reserve(dma32_phys_limit);
- if (IS_ENABLED(CONFIG_64BIT))
+ if (BITS_PER_LONG == 64)
hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT);
}
@@ -685,16 +692,26 @@ void __meminit create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, phy
pgd_next_t *nextp;
phys_addr_t next_phys;
uintptr_t pgd_idx = pgd_index(va);
+#if (CONFIG_PGTABLE_LEVELS > 2) && (BITS_PER_LONG == 32)
+ uintptr_t pgd_idh = pgd_index(sign_extend64((u64)va, 31));
+#endif
if (sz == PGDIR_SIZE) {
- if (pgd_val(pgdp[pgd_idx]) == 0)
+ if (pgd_val(pgdp[pgd_idx]) == 0) {
pgdp[pgd_idx] = pfn_pgd(PFN_DOWN(pa), prot);
+#if (CONFIG_PGTABLE_LEVELS > 2) && (BITS_PER_LONG == 32)
+ pgdp[pgd_idh] = pfn_pgd(PFN_DOWN(pa), prot);
+#endif
+ }
return;
}
if (pgd_val(pgdp[pgd_idx]) == 0) {
next_phys = alloc_pgd_next(va);
pgdp[pgd_idx] = pfn_pgd(PFN_DOWN(next_phys), PAGE_TABLE);
+#if (CONFIG_PGTABLE_LEVELS > 2) && (BITS_PER_LONG == 32)
+ pgdp[pgd_idh] = pfn_pgd(PFN_DOWN(next_phys), PAGE_TABLE);
+#endif
nextp = get_pgd_next_virt(next_phys);
memset(nextp, 0, PAGE_SIZE);
} else {
@@ -775,7 +792,7 @@ static __meminit pgprot_t pgprot_from_va(uintptr_t va)
}
#endif /* CONFIG_STRICT_KERNEL_RWX */
-#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL)
+#if (BITS_PER_LONG == 64) && !defined(CONFIG_XIP_KERNEL)
u64 __pi_set_satp_mode_from_cmdline(uintptr_t dtb_pa);
static void __init disable_pgtable_l5(void)
@@ -981,8 +998,8 @@ static void __init create_fdt_early_page_table(uintptr_t fix_fdt_va,
/* Make sure the fdt fixmap address is always aligned on PMD size */
BUILD_BUG_ON(FIX_FDT % (PMD_SIZE / PAGE_SIZE));
- /* In 32-bit only, the fdt lies in its own PGD */
- if (!IS_ENABLED(CONFIG_64BIT)) {
+ /* In Sv32 only, the fdt lies in its own PGD */
+ if (CONFIG_PGTABLE_LEVELS == 2) {
create_pgd_mapping(early_pg_dir, fix_fdt_va,
pa, MAX_FDT_SIZE, PAGE_KERNEL);
} else {
@@ -1108,7 +1125,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset;
#ifdef CONFIG_XIP_KERNEL
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
kernel_map.page_offset = PAGE_OFFSET_L3;
#else
kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
@@ -1133,7 +1150,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
#endif
-#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL)
+#if (BITS_PER_LONG == 64) && !defined(CONFIG_XIP_KERNEL)
set_satp_mode(dtb_pa);
set_mmap_rnd_bits_max();
#endif
@@ -1164,7 +1181,11 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
* The last 4K bytes of the addressable memory can not be mapped because
* of IS_ERR_VALUE macro.
*/
+#if BITS_PER_LONG == 64
BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
+#else
+ BUG_ON((kernel_map.virt_addr + kernel_map.size) > PAGE_OFFSET - SZ_4K);
+#endif
#endif
#ifdef CONFIG_RELOCATABLE
@@ -1246,7 +1267,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
fix_bmap_epmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_END))];
if (pmd_val(fix_bmap_spmd) != pmd_val(fix_bmap_epmd)) {
WARN_ON(1);
- pr_warn("fixmap btmap start [%08lx] != end [%08lx]\n",
+ pr_warn("fixmap btmap start [" PTE_FMT "] != end [" PTE_FMT "]\n",
pmd_val(fix_bmap_spmd), pmd_val(fix_bmap_epmd));
pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
fix_to_virt(FIX_BTMAP_BEGIN));
@@ -1336,7 +1357,7 @@ static void __init create_linear_mapping_page_table(void)
static void __init setup_vm_final(void)
{
/* Setup swapper PGD for fixmap */
-#if !defined(CONFIG_64BIT)
+#if CONFIG_PGTABLE_LEVELS == 2
/*
* In 32-bit, the device tree lies in a pgd entry, so it must be copied
* directly in swapper_pg_dir in addition to the pgd entry that points
@@ -1354,7 +1375,7 @@ static void __init setup_vm_final(void)
create_linear_mapping_page_table();
/* Map the kernel */
- if (IS_ENABLED(CONFIG_64BIT))
+ if (CONFIG_PGTABLE_LEVELS > 2)
create_kernel_page_table(swapper_pg_dir, false);
#ifdef CONFIG_KASAN
diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c
index d815448758a1..45927f713cb9 100644
--- a/arch/riscv/mm/pageattr.c
+++ b/arch/riscv/mm/pageattr.c
@@ -15,10 +15,10 @@ struct pageattr_masks {
pgprot_t clear_mask;
};
-static unsigned long set_pageattr_masks(unsigned long val, struct mm_walk *walk)
+static unsigned long set_pageattr_masks(ptval_t val, struct mm_walk *walk)
{
struct pageattr_masks *masks = walk->private;
- unsigned long new_val = val;
+ ptval_t new_val = val;
new_val &= ~(pgprot_val(masks->clear_mask));
new_val |= (pgprot_val(masks->set_mask));
diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c
index 4ae67324f992..564679b4c48e 100644
--- a/arch/riscv/mm/pgtable.c
+++ b/arch/riscv/mm/pgtable.c
@@ -37,7 +37,7 @@ int ptep_test_and_clear_young(struct vm_area_struct *vma,
{
if (!pte_young(ptep_get(ptep)))
return 0;
- return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, &pte_val(*ptep));
+ return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, (unsigned long *)&pte_val(*ptep));
}
EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 16/43] rv64ilp32_abi: riscv: Support physical addresses >= 0x80000000
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (14 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 15/43] rv64ilp32_abi: riscv: mm: Adapt MMU_SV39 for 2GiB address space guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 17/43] rv64ilp32_abi: riscv: Adapt kasan memory layout guoren
` (28 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI has two independent 2GiB address space:
- 0 ~ 0x7fffffff
- 0xffffffff80000000 ~ 0xffffffffffffffff
In the rv64ilp32 ABI, 0x80000000 is illegal; hence, use a
temporary trap handler to zero-extend the address for jalr,
load and store operations.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/kernel/head.S | 112 +++++++++++++++++++++++++++++++++++++++
1 file changed, 112 insertions(+)
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index e55a92be12b1..bd2f30aa6d01 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -170,6 +170,118 @@ secondary_start_sbi:
.align 2
.Lsecondary_park:
+#ifdef CONFIG_ABI_RV64ILP32
+.option push
+.option norelax
+.option norvc
+ addiw sp, sp, -32
+
+ /* zext.w sp */
+ slli sp, sp, 32
+ srli sp, sp, 32
+
+ /* zext.w ra */
+ slli ra, ra, 32
+ srli ra, ra, 32
+
+ /* zext.w fp */
+ slli fp, fp, 32
+ srli fp, fp, 32
+
+ /* zext.w tp */
+ slli tp, tp, 32
+ srli tp, tp, 32
+
+ /* save tmp reg */
+ REG_S ra, 24(sp)
+ REG_S fp, 16(sp)
+ REG_S tp, 8(sp)
+ REG_S gp, 0(sp)
+
+ /* zext.w epc */
+ csrr ra, CSR_EPC
+ slli ra, ra, 32
+ srli ra, ra, 32
+ csrw CSR_SEPC, ra
+
+ csrr gp, CSR_CAUSE
+
+ /* EXC_INST_ACCESS */
+ addiw fp, gp, -1
+ beqz fp, 6f
+
+ /* EXC_LOAD_ACCESS */
+ addiw fp, gp, -5
+ beqz fp, 1f
+
+ /* EXC_STORE_ACCESS */
+ addiw fp, gp, -7
+ beqz fp, 1f
+
+ j 7f
+1:
+ /* get inst */
+ lw ra, 0(ra)
+ andi gp, ra, 0x3
+
+ /* c.(lw/sw/ld/sd)sp */
+ addiw fp, gp, -2
+ beqz fp, 6f
+
+ /* lw/sw/ld/sd */
+ addiw fp, gp, -3
+ beqz fp, 2f
+
+ /* c.(lw/sw/ld/sd) */
+ li fp, 0x7
+ slli fp, fp, 7
+ and ra, fp, ra
+ slli ra, ra, 8
+ j 3f
+
+2:
+ /* get rs1 */
+ li fp, 0x1f
+ slli fp, fp, 15
+ and ra, fp, ra
+
+3:
+ /* copy rs1 to rd */
+ mv fp, ra
+ srli fp, fp, 8
+ or ra, fp, ra
+
+ /* modify slli */
+ la fp, 4f
+ lw tp, 0(fp)
+ mv gp, tp
+ or tp, ra, tp
+ sw tp, 0(fp)
+ fence.i
+4: slli x0, x0, 32
+ sw gp, 0(fp)
+
+ /* modify srli */
+ la fp, 5f
+ lw tp, 0(fp)
+ mv gp, tp
+ or tp, ra, tp
+ sw tp, 0(fp)
+ fence.i
+5: srli x0, x0, 32
+ sw gp, 0(fp)
+
+6:
+ /* restore tmp reg */
+ REG_L ra, 24(sp)
+ REG_L fp, 16(sp)
+ REG_L tp, 8(sp)
+ REG_L gp, 0(sp)
+ addi sp, sp, 32
+ sret
+.option pop
+7:
+#endif
/*
* Park this hart if we:
* - have too many harts on CONFIG_RISCV_BOOT_SPINWAIT
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 17/43] rv64ilp32_abi: riscv: Adapt kasan memory layout
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (15 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 16/43] rv64ilp32_abi: riscv: Support physical addresses >= 0x80000000 guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:15 ` [RFC PATCH V3 18/43] rv64ilp32_abi: riscv: kvm: Initial support guoren
` (27 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
For generic KASAN, the size of each memory granule is 8, which
needs 1/8 address space. The kernel space is 2GiB in rv64ilp32,
so we need 256MiB range (0x80000000 ~ 0x90000000), and the offset
is 0x7000000 for the whole 4GiB address space.
Virtual kernel memory layout:
fixmap : 0x90a00000 - 0x90ffffff (6144 kB)
pci io : 0x91000000 - 0x91ffffff ( 16 MB)
vmemmap : 0x92000000 - 0x93ffffff ( 32 MB)
vmalloc : 0x94000000 - 0xb3ffffff ( 512 MB)
modules : 0xb4000000 - 0xb7ffffff ( 64 MB)
lowmem : 0xc0000000 - 0xc7ffffff ( 128 MB)
kasan : 0x80000000 - 0x8fffffff ( 256 MB) <=
kernel : 0xb8000000 - 0xbfffffff ( 128 MB)
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/kasan.h | 6 +++++-
arch/riscv/mm/kasan_init.c | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/include/asm/kasan.h b/arch/riscv/include/asm/kasan.h
index e6a0071bdb56..dd3a211bc5d0 100644
--- a/arch/riscv/include/asm/kasan.h
+++ b/arch/riscv/include/asm/kasan.h
@@ -21,7 +21,7 @@
* [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual
* addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation:
* KASAN_SHADOW_OFFSET = KASAN_SHADOW_END -
- * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT))
+ * (1ULL << (BITS_PER_LONG - KASAN_SHADOW_SCALE_SHIFT))
*/
#define KASAN_SHADOW_SCALE_SHIFT 3
@@ -31,7 +31,11 @@
* aligned on PGDIR_SIZE, so force its alignment to ease its population.
*/
#define KASAN_SHADOW_START ((KASAN_SHADOW_END - KASAN_SHADOW_SIZE) & PGDIR_MASK)
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+#define KASAN_SHADOW_END 0x90000000UL
+#else
#define KASAN_SHADOW_END MODULES_LOWEST_VADDR
+#endif
#ifdef CONFIG_KASAN
#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
index 41c635d6aca4..1e864598779a 100644
--- a/arch/riscv/mm/kasan_init.c
+++ b/arch/riscv/mm/kasan_init.c
@@ -324,7 +324,7 @@ asmlinkage void __init kasan_early_init(void)
uintptr_t i;
BUILD_BUG_ON(KASAN_SHADOW_OFFSET !=
- KASAN_SHADOW_END - (1UL << (64 - KASAN_SHADOW_SCALE_SHIFT)));
+ KASAN_SHADOW_END - (1UL << (BITS_PER_LONG - KASAN_SHADOW_SCALE_SHIFT)));
for (i = 0; i < PTRS_PER_PTE; ++i)
set_pte(kasan_early_shadow_pte + i,
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 18/43] rv64ilp32_abi: riscv: kvm: Initial support
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (16 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 17/43] rv64ilp32_abi: riscv: Adapt kasan memory layout guoren
@ 2025-03-25 12:15 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 19/43] rv64ilp32_abi: irqchip: irq-riscv-intc: Use xlen_t instead of ulong guoren
` (26 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:15 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
This is the initial support for rv64ilp32 abi, and haven't passed
the kvm self test.
It could support rv64ilp32 & rv64lp64 linux guest kernels.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/kvm_aia.h | 32 ++---
arch/riscv/include/asm/kvm_host.h | 192 ++++++++++++-------------
arch/riscv/include/asm/kvm_nacl.h | 26 ++--
arch/riscv/include/asm/kvm_vcpu_insn.h | 4 +-
arch/riscv/include/asm/kvm_vcpu_pmu.h | 8 +-
arch/riscv/include/asm/kvm_vcpu_sbi.h | 4 +-
arch/riscv/include/asm/sbi.h | 10 +-
arch/riscv/include/uapi/asm/kvm.h | 56 ++++----
arch/riscv/kvm/aia.c | 26 ++--
arch/riscv/kvm/aia_imsic.c | 6 +-
arch/riscv/kvm/main.c | 2 +-
arch/riscv/kvm/mmu.c | 10 +-
arch/riscv/kvm/tlb.c | 76 +++++-----
arch/riscv/kvm/vcpu.c | 10 +-
arch/riscv/kvm/vcpu_exit.c | 4 +-
arch/riscv/kvm/vcpu_insn.c | 12 +-
arch/riscv/kvm/vcpu_onereg.c | 18 +--
arch/riscv/kvm/vcpu_pmu.c | 8 +-
arch/riscv/kvm/vcpu_sbi_base.c | 2 +-
arch/riscv/kvm/vmid.c | 4 +-
20 files changed, 256 insertions(+), 254 deletions(-)
diff --git a/arch/riscv/include/asm/kvm_aia.h b/arch/riscv/include/asm/kvm_aia.h
index 1f37b600ca47..d7dae9128b5e 100644
--- a/arch/riscv/include/asm/kvm_aia.h
+++ b/arch/riscv/include/asm/kvm_aia.h
@@ -50,13 +50,13 @@ struct kvm_aia {
};
struct kvm_vcpu_aia_csr {
- unsigned long vsiselect;
- unsigned long hviprio1;
- unsigned long hviprio2;
- unsigned long vsieh;
- unsigned long hviph;
- unsigned long hviprio1h;
- unsigned long hviprio2h;
+ xlen_t vsiselect;
+ xlen_t hviprio1;
+ xlen_t hviprio2;
+ xlen_t vsieh;
+ xlen_t hviph;
+ xlen_t hviprio1h;
+ xlen_t hviprio2h;
};
struct kvm_vcpu_aia {
@@ -95,8 +95,8 @@ int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu);
#define KVM_RISCV_AIA_IMSIC_TOPEI (ISELECT_MASK + 1)
int kvm_riscv_vcpu_aia_imsic_rmw(struct kvm_vcpu *vcpu, unsigned long isel,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask);
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask);
int kvm_riscv_aia_imsic_rw_attr(struct kvm *kvm, unsigned long type,
bool write, unsigned long *val);
int kvm_riscv_aia_imsic_has_attr(struct kvm *kvm, unsigned long type);
@@ -131,19 +131,19 @@ void kvm_riscv_vcpu_aia_load(struct kvm_vcpu *vcpu, int cpu);
void kvm_riscv_vcpu_aia_put(struct kvm_vcpu *vcpu);
int kvm_riscv_vcpu_aia_get_csr(struct kvm_vcpu *vcpu,
unsigned long reg_num,
- unsigned long *out_val);
+ xlen_t *out_val);
int kvm_riscv_vcpu_aia_set_csr(struct kvm_vcpu *vcpu,
unsigned long reg_num,
- unsigned long val);
+ xlen_t val);
int kvm_riscv_vcpu_aia_rmw_topei(struct kvm_vcpu *vcpu,
unsigned int csr_num,
- unsigned long *val,
- unsigned long new_val,
- unsigned long wr_mask);
+ xlen_t *val,
+ xlen_t new_val,
+ xlen_t wr_mask);
int kvm_riscv_vcpu_aia_rmw_ireg(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask);
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask);
#define KVM_RISCV_VCPU_AIA_CSR_FUNCS \
{ .base = CSR_SIREG, .count = 1, .func = kvm_riscv_vcpu_aia_rmw_ireg }, \
{ .base = CSR_STOPEI, .count = 1, .func = kvm_riscv_vcpu_aia_rmw_topei },
diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
index cc33e35cd628..166cae2c74cf 100644
--- a/arch/riscv/include/asm/kvm_host.h
+++ b/arch/riscv/include/asm/kvm_host.h
@@ -64,8 +64,8 @@ enum kvm_riscv_hfence_type {
struct kvm_riscv_hfence {
enum kvm_riscv_hfence_type type;
- unsigned long asid;
- unsigned long order;
+ xlen_t asid;
+ xlen_t order;
gpa_t addr;
gpa_t size;
};
@@ -102,8 +102,8 @@ struct kvm_vmid {
* Writes to vmid_version and vmid happen with vmid_lock held
* whereas reads happen without any lock held.
*/
- unsigned long vmid_version;
- unsigned long vmid;
+ xlen_t vmid_version;
+ xlen_t vmid;
};
struct kvm_arch {
@@ -122,75 +122,75 @@ struct kvm_arch {
};
struct kvm_cpu_trap {
- unsigned long sepc;
- unsigned long scause;
- unsigned long stval;
- unsigned long htval;
- unsigned long htinst;
+ xlen_t sepc;
+ xlen_t scause;
+ xlen_t stval;
+ xlen_t htval;
+ xlen_t htinst;
};
struct kvm_cpu_context {
- unsigned long zero;
- unsigned long ra;
- unsigned long sp;
- unsigned long gp;
- unsigned long tp;
- unsigned long t0;
- unsigned long t1;
- unsigned long t2;
- unsigned long s0;
- unsigned long s1;
- unsigned long a0;
- unsigned long a1;
- unsigned long a2;
- unsigned long a3;
- unsigned long a4;
- unsigned long a5;
- unsigned long a6;
- unsigned long a7;
- unsigned long s2;
- unsigned long s3;
- unsigned long s4;
- unsigned long s5;
- unsigned long s6;
- unsigned long s7;
- unsigned long s8;
- unsigned long s9;
- unsigned long s10;
- unsigned long s11;
- unsigned long t3;
- unsigned long t4;
- unsigned long t5;
- unsigned long t6;
- unsigned long sepc;
- unsigned long sstatus;
- unsigned long hstatus;
+ xlen_t zero;
+ xlen_t ra;
+ xlen_t sp;
+ xlen_t gp;
+ xlen_t tp;
+ xlen_t t0;
+ xlen_t t1;
+ xlen_t t2;
+ xlen_t s0;
+ xlen_t s1;
+ xlen_t a0;
+ xlen_t a1;
+ xlen_t a2;
+ xlen_t a3;
+ xlen_t a4;
+ xlen_t a5;
+ xlen_t a6;
+ xlen_t a7;
+ xlen_t s2;
+ xlen_t s3;
+ xlen_t s4;
+ xlen_t s5;
+ xlen_t s6;
+ xlen_t s7;
+ xlen_t s8;
+ xlen_t s9;
+ xlen_t s10;
+ xlen_t s11;
+ xlen_t t3;
+ xlen_t t4;
+ xlen_t t5;
+ xlen_t t6;
+ xlen_t sepc;
+ xlen_t sstatus;
+ xlen_t hstatus;
union __riscv_fp_state fp;
struct __riscv_v_ext_state vector;
};
struct kvm_vcpu_csr {
- unsigned long vsstatus;
- unsigned long vsie;
- unsigned long vstvec;
- unsigned long vsscratch;
- unsigned long vsepc;
- unsigned long vscause;
- unsigned long vstval;
- unsigned long hvip;
- unsigned long vsatp;
- unsigned long scounteren;
- unsigned long senvcfg;
+ xlen_t vsstatus;
+ xlen_t vsie;
+ xlen_t vstvec;
+ xlen_t vsscratch;
+ xlen_t vsepc;
+ xlen_t vscause;
+ xlen_t vstval;
+ xlen_t hvip;
+ xlen_t vsatp;
+ xlen_t scounteren;
+ xlen_t senvcfg;
};
struct kvm_vcpu_config {
u64 henvcfg;
u64 hstateen0;
- unsigned long hedeleg;
+ xlen_t hedeleg;
};
struct kvm_vcpu_smstateen_csr {
- unsigned long sstateen0;
+ xlen_t sstateen0;
};
struct kvm_vcpu_arch {
@@ -204,16 +204,16 @@ struct kvm_vcpu_arch {
DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
/* Vendor, Arch, and Implementation details */
- unsigned long mvendorid;
- unsigned long marchid;
- unsigned long mimpid;
+ xlen_t mvendorid;
+ xlen_t marchid;
+ xlen_t mimpid;
/* SSCRATCH, STVEC, and SCOUNTEREN of Host */
- unsigned long host_sscratch;
- unsigned long host_stvec;
- unsigned long host_scounteren;
- unsigned long host_senvcfg;
- unsigned long host_sstateen0;
+ xlen_t host_sscratch;
+ xlen_t host_stvec;
+ xlen_t host_scounteren;
+ xlen_t host_senvcfg;
+ xlen_t host_sstateen0;
/* CPU context of Host */
struct kvm_cpu_context host_context;
@@ -252,8 +252,8 @@ struct kvm_vcpu_arch {
/* HFENCE request queue */
spinlock_t hfence_lock;
- unsigned long hfence_head;
- unsigned long hfence_tail;
+ xlen_t hfence_head;
+ xlen_t hfence_tail;
struct kvm_riscv_hfence hfence_queue[KVM_RISCV_VCPU_MAX_HFENCE];
/* MMIO instruction details */
@@ -305,24 +305,24 @@ static inline void kvm_arch_sync_events(struct kvm *kvm) {}
#define KVM_RISCV_GSTAGE_TLB_MIN_ORDER 12
-void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid,
+void kvm_riscv_local_hfence_gvma_vmid_gpa(xlen_t vmid,
gpa_t gpa, gpa_t gpsz,
- unsigned long order);
-void kvm_riscv_local_hfence_gvma_vmid_all(unsigned long vmid);
+ xlen_t order);
+void kvm_riscv_local_hfence_gvma_vmid_all(xlen_t vmid);
void kvm_riscv_local_hfence_gvma_gpa(gpa_t gpa, gpa_t gpsz,
- unsigned long order);
+ xlen_t order);
void kvm_riscv_local_hfence_gvma_all(void);
-void kvm_riscv_local_hfence_vvma_asid_gva(unsigned long vmid,
- unsigned long asid,
- unsigned long gva,
- unsigned long gvsz,
- unsigned long order);
-void kvm_riscv_local_hfence_vvma_asid_all(unsigned long vmid,
- unsigned long asid);
-void kvm_riscv_local_hfence_vvma_gva(unsigned long vmid,
- unsigned long gva, unsigned long gvsz,
- unsigned long order);
-void kvm_riscv_local_hfence_vvma_all(unsigned long vmid);
+void kvm_riscv_local_hfence_vvma_asid_gva(xlen_t vmid,
+ xlen_t asid,
+ xlen_t gva,
+ xlen_t gvsz,
+ xlen_t order);
+void kvm_riscv_local_hfence_vvma_asid_all(xlen_t vmid,
+ xlen_t asid);
+void kvm_riscv_local_hfence_vvma_gva(xlen_t vmid,
+ xlen_t gva, xlen_t gvsz,
+ xlen_t order);
+void kvm_riscv_local_hfence_vvma_all(xlen_t vmid);
void kvm_riscv_local_tlb_sanitize(struct kvm_vcpu *vcpu);
@@ -332,26 +332,26 @@ void kvm_riscv_hfence_vvma_all_process(struct kvm_vcpu *vcpu);
void kvm_riscv_hfence_process(struct kvm_vcpu *vcpu);
void kvm_riscv_fence_i(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask);
+ xlen_t hbase, xlen_t hmask);
void kvm_riscv_hfence_gvma_vmid_gpa(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
+ xlen_t hbase, xlen_t hmask,
gpa_t gpa, gpa_t gpsz,
- unsigned long order);
+ xlen_t order);
void kvm_riscv_hfence_gvma_vmid_all(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask);
+ xlen_t hbase, xlen_t hmask);
void kvm_riscv_hfence_vvma_asid_gva(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
- unsigned long gva, unsigned long gvsz,
- unsigned long order, unsigned long asid);
+ xlen_t hbase, xlen_t hmask,
+ xlen_t gva, xlen_t gvsz,
+ xlen_t order, xlen_t asid);
void kvm_riscv_hfence_vvma_asid_all(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
- unsigned long asid);
+ xlen_t hbase, xlen_t hmask,
+ xlen_t asid);
void kvm_riscv_hfence_vvma_gva(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
- unsigned long gva, unsigned long gvsz,
- unsigned long order);
+ xlen_t hbase, xlen_t hmask,
+ xlen_t gva, xlen_t gvsz,
+ xlen_t order);
void kvm_riscv_hfence_vvma_all(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask);
+ xlen_t hbase, xlen_t hmask);
int kvm_riscv_gstage_ioremap(struct kvm *kvm, gpa_t gpa,
phys_addr_t hpa, unsigned long size,
@@ -369,7 +369,7 @@ unsigned long __init kvm_riscv_gstage_mode(void);
int kvm_riscv_gstage_gpa_bits(void);
void __init kvm_riscv_gstage_vmid_detect(void);
-unsigned long kvm_riscv_gstage_vmid_bits(void);
+xlen_t kvm_riscv_gstage_vmid_bits(void);
int kvm_riscv_gstage_vmid_init(struct kvm *kvm);
bool kvm_riscv_gstage_vmid_ver_changed(struct kvm_vmid *vmid);
void kvm_riscv_gstage_vmid_update(struct kvm_vcpu *vcpu);
diff --git a/arch/riscv/include/asm/kvm_nacl.h b/arch/riscv/include/asm/kvm_nacl.h
index 4124d5e06a0f..59be64c068fc 100644
--- a/arch/riscv/include/asm/kvm_nacl.h
+++ b/arch/riscv/include/asm/kvm_nacl.h
@@ -68,26 +68,26 @@ int kvm_riscv_nacl_init(void);
#define nacl_shmem() \
this_cpu_ptr(&kvm_riscv_nacl)->shmem
-#define nacl_scratch_read_long(__shmem, __offset) \
+#define nacl_scratch_read_csr(__shmem, __offset) \
({ \
- unsigned long *__p = (__shmem) + \
+ xlen_t *__p = (__shmem) + \
SBI_NACL_SHMEM_SCRATCH_OFFSET + \
(__offset); \
lelong_to_cpu(*__p); \
})
-#define nacl_scratch_write_long(__shmem, __offset, __val) \
+#define nacl_scratch_write_csr(__shmem, __offset, __val) \
do { \
- unsigned long *__p = (__shmem) + \
+ xlen_t *__p = (__shmem) + \
SBI_NACL_SHMEM_SCRATCH_OFFSET + \
(__offset); \
*__p = cpu_to_lelong(__val); \
} while (0)
-#define nacl_scratch_write_longs(__shmem, __offset, __array, __count) \
+#define nacl_scratch_write_csrs(__shmem, __offset, __array, __count) \
do { \
unsigned int __i; \
- unsigned long *__p = (__shmem) + \
+ xlen_t *__p = (__shmem) + \
SBI_NACL_SHMEM_SCRATCH_OFFSET + \
(__offset); \
for (__i = 0; __i < (__count); __i++) \
@@ -100,7 +100,7 @@ do { \
#define nacl_hfence_mkconfig(__type, __order, __vmid, __asid) \
({ \
- unsigned long __c = SBI_NACL_SHMEM_HFENCE_CONFIG_PEND; \
+ xlen_t __c = SBI_NACL_SHMEM_HFENCE_CONFIG_PEND; \
__c |= ((__type) & SBI_NACL_SHMEM_HFENCE_CONFIG_TYPE_MASK) \
<< SBI_NACL_SHMEM_HFENCE_CONFIG_TYPE_SHIFT; \
__c |= (((__order) - SBI_NACL_SHMEM_HFENCE_ORDER_BASE) & \
@@ -168,7 +168,7 @@ __kvm_riscv_nacl_hfence(__shmem, \
#define nacl_csr_read(__shmem, __csr) \
({ \
- unsigned long *__a = (__shmem) + SBI_NACL_SHMEM_CSR_OFFSET; \
+ xlen_t *__a = (__shmem) + SBI_NACL_SHMEM_CSR_OFFSET; \
lelong_to_cpu(__a[SBI_NACL_SHMEM_CSR_INDEX(__csr)]); \
})
@@ -176,7 +176,7 @@ __kvm_riscv_nacl_hfence(__shmem, \
do { \
void *__s = (__shmem); \
unsigned int __i = SBI_NACL_SHMEM_CSR_INDEX(__csr); \
- unsigned long *__a = (__s) + SBI_NACL_SHMEM_CSR_OFFSET; \
+ xlen_t *__a = (__s) + SBI_NACL_SHMEM_CSR_OFFSET; \
u8 *__b = (__s) + SBI_NACL_SHMEM_DBITMAP_OFFSET; \
__a[__i] = cpu_to_lelong(__val); \
__b[__i >> 3] |= 1U << (__i & 0x7); \
@@ -186,9 +186,9 @@ do { \
({ \
void *__s = (__shmem); \
unsigned int __i = SBI_NACL_SHMEM_CSR_INDEX(__csr); \
- unsigned long *__a = (__s) + SBI_NACL_SHMEM_CSR_OFFSET; \
+ xlen_t *__a = (__s) + SBI_NACL_SHMEM_CSR_OFFSET; \
u8 *__b = (__s) + SBI_NACL_SHMEM_DBITMAP_OFFSET; \
- unsigned long __r = lelong_to_cpu(__a[__i]); \
+ xlen_t __r = lelong_to_cpu(__a[__i]); \
__a[__i] = cpu_to_lelong(__val); \
__b[__i >> 3] |= 1U << (__i & 0x7); \
__r; \
@@ -210,7 +210,7 @@ do { \
#define ncsr_read(__csr) \
({ \
- unsigned long __r; \
+ xlen_t __r; \
if (kvm_riscv_nacl_available()) \
__r = nacl_csr_read(nacl_shmem(), __csr); \
else \
@@ -228,7 +228,7 @@ do { \
#define ncsr_swap(__csr, __val) \
({ \
- unsigned long __r; \
+ xlen_t __r; \
if (kvm_riscv_nacl_sync_csr_available()) \
__r = nacl_csr_swap(nacl_shmem(), __csr, __val); \
else \
diff --git a/arch/riscv/include/asm/kvm_vcpu_insn.h b/arch/riscv/include/asm/kvm_vcpu_insn.h
index 350011c83581..a0da75683894 100644
--- a/arch/riscv/include/asm/kvm_vcpu_insn.h
+++ b/arch/riscv/include/asm/kvm_vcpu_insn.h
@@ -11,7 +11,7 @@ struct kvm_run;
struct kvm_cpu_trap;
struct kvm_mmio_decode {
- unsigned long insn;
+ xlen_t insn;
int insn_len;
int len;
int shift;
@@ -19,7 +19,7 @@ struct kvm_mmio_decode {
};
struct kvm_csr_decode {
- unsigned long insn;
+ xlen_t insn;
int return_handled;
};
diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h
index 1d85b6617508..e69b102bde49 100644
--- a/arch/riscv/include/asm/kvm_vcpu_pmu.h
+++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h
@@ -74,8 +74,8 @@ struct kvm_pmu {
int kvm_riscv_vcpu_pmu_incr_fw(struct kvm_vcpu *vcpu, unsigned long fid);
int kvm_riscv_vcpu_pmu_read_hpm(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask);
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask);
int kvm_riscv_vcpu_pmu_num_ctrs(struct kvm_vcpu *vcpu, struct kvm_vcpu_sbi_return *retdata);
int kvm_riscv_vcpu_pmu_ctr_info(struct kvm_vcpu *vcpu, unsigned long cidx,
@@ -106,8 +106,8 @@ struct kvm_pmu {
};
static inline int kvm_riscv_vcpu_pmu_read_legacy(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask)
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask)
{
if (csr_num == CSR_CYCLE || csr_num == CSR_INSTRET) {
*val = 0;
diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h
index 4ed6203cdd30..83d786111450 100644
--- a/arch/riscv/include/asm/kvm_vcpu_sbi.h
+++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h
@@ -27,8 +27,8 @@ struct kvm_vcpu_sbi_context {
};
struct kvm_vcpu_sbi_return {
- unsigned long out_val;
- unsigned long err_val;
+ xlen_t out_val;
+ xlen_t err_val;
struct kvm_cpu_trap *utrap;
bool uexit;
};
diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index fd9a9c723ec6..df73a0eb231b 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -343,7 +343,7 @@ enum sbi_ext_nacl_feature {
#define SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_SHIFT \
(__riscv_xlen - SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_BITS)
#define SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_MASK \
- ((1UL << SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_BITS) - 1)
+ ((_AC(1, UXL) << SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_BITS) - 1)
#define SBI_NACL_SHMEM_HFENCE_CONFIG_PEND \
(SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_MASK << \
SBI_NACL_SHMEM_HFENCE_CONFIG_PEND_SHIFT)
@@ -358,7 +358,7 @@ enum sbi_ext_nacl_feature {
(SBI_NACL_SHMEM_HFENCE_CONFIG_RSVD1_SHIFT - \
SBI_NACL_SHMEM_HFENCE_CONFIG_TYPE_BITS)
#define SBI_NACL_SHMEM_HFENCE_CONFIG_TYPE_MASK \
- ((1UL << SBI_NACL_SHMEM_HFENCE_CONFIG_TYPE_BITS) - 1)
+ ((_AC(1, UXL) << SBI_NACL_SHMEM_HFENCE_CONFIG_TYPE_BITS) - 1)
#define SBI_NACL_SHMEM_HFENCE_TYPE_GVMA 0x0
#define SBI_NACL_SHMEM_HFENCE_TYPE_GVMA_ALL 0x1
@@ -379,7 +379,7 @@ enum sbi_ext_nacl_feature {
(SBI_NACL_SHMEM_HFENCE_CONFIG_RSVD2_SHIFT - \
SBI_NACL_SHMEM_HFENCE_CONFIG_ORDER_BITS)
#define SBI_NACL_SHMEM_HFENCE_CONFIG_ORDER_MASK \
- ((1UL << SBI_NACL_SHMEM_HFENCE_CONFIG_ORDER_BITS) - 1)
+ ((_AC(1, UXL) << SBI_NACL_SHMEM_HFENCE_CONFIG_ORDER_BITS) - 1)
#define SBI_NACL_SHMEM_HFENCE_ORDER_BASE 12
#if __riscv_xlen == 32
@@ -392,9 +392,9 @@ enum sbi_ext_nacl_feature {
#define SBI_NACL_SHMEM_HFENCE_CONFIG_VMID_SHIFT \
SBI_NACL_SHMEM_HFENCE_CONFIG_ASID_BITS
#define SBI_NACL_SHMEM_HFENCE_CONFIG_ASID_MASK \
- ((1UL << SBI_NACL_SHMEM_HFENCE_CONFIG_ASID_BITS) - 1)
+ ((_AC(1, UXL) << SBI_NACL_SHMEM_HFENCE_CONFIG_ASID_BITS) - 1)
#define SBI_NACL_SHMEM_HFENCE_CONFIG_VMID_MASK \
- ((1UL << SBI_NACL_SHMEM_HFENCE_CONFIG_VMID_BITS) - 1)
+ ((_AC(1, UXL) << SBI_NACL_SHMEM_HFENCE_CONFIG_VMID_BITS) - 1)
#define SBI_NACL_SHMEM_AUTOSWAP_FLAG_HSTATUS BIT(0)
#define SBI_NACL_SHMEM_AUTOSWAP_HSTATUS ((__riscv_xlen / 8) * 1)
diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h
index f06bc5efcd79..9001e8081ce2 100644
--- a/arch/riscv/include/uapi/asm/kvm.h
+++ b/arch/riscv/include/uapi/asm/kvm.h
@@ -48,13 +48,13 @@ struct kvm_sregs {
/* CONFIG registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_config {
- unsigned long isa;
- unsigned long zicbom_block_size;
- unsigned long mvendorid;
- unsigned long marchid;
- unsigned long mimpid;
- unsigned long zicboz_block_size;
- unsigned long satp_mode;
+ xlen_t isa;
+ xlen_t zicbom_block_size;
+ xlen_t mvendorid;
+ xlen_t marchid;
+ xlen_t mimpid;
+ xlen_t zicboz_block_size;
+ xlen_t satp_mode;
};
/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -69,33 +69,33 @@ struct kvm_riscv_core {
/* General CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_csr {
- unsigned long sstatus;
- unsigned long sie;
- unsigned long stvec;
- unsigned long sscratch;
- unsigned long sepc;
- unsigned long scause;
- unsigned long stval;
- unsigned long sip;
- unsigned long satp;
- unsigned long scounteren;
- unsigned long senvcfg;
+ xlen_t sstatus;
+ xlen_t sie;
+ xlen_t stvec;
+ xlen_t sscratch;
+ xlen_t sepc;
+ xlen_t scause;
+ xlen_t stval;
+ xlen_t sip;
+ xlen_t satp;
+ xlen_t scounteren;
+ xlen_t senvcfg;
};
/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_aia_csr {
- unsigned long siselect;
- unsigned long iprio1;
- unsigned long iprio2;
- unsigned long sieh;
- unsigned long siph;
- unsigned long iprio1h;
- unsigned long iprio2h;
+ xlen_t siselect;
+ xlen_t iprio1;
+ xlen_t iprio2;
+ xlen_t sieh;
+ xlen_t siph;
+ xlen_t iprio1h;
+ xlen_t iprio2h;
};
/* Smstateen CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_smstateen_csr {
- unsigned long sstateen0;
+ xlen_t sstateen0;
};
/* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -207,8 +207,8 @@ enum KVM_RISCV_SBI_EXT_ID {
/* SBI STA extension registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
struct kvm_riscv_sbi_sta {
- unsigned long shmem_lo;
- unsigned long shmem_hi;
+ xlen_t shmem_lo;
+ xlen_t shmem_hi;
};
/* Possible states for kvm_riscv_timer */
diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
index 19afd1f23537..77f6943292a3 100644
--- a/arch/riscv/kvm/aia.c
+++ b/arch/riscv/kvm/aia.c
@@ -200,31 +200,31 @@ void kvm_riscv_vcpu_aia_put(struct kvm_vcpu *vcpu)
int kvm_riscv_vcpu_aia_get_csr(struct kvm_vcpu *vcpu,
unsigned long reg_num,
- unsigned long *out_val)
+ xlen_t *out_val)
{
struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
- if (reg_num >= sizeof(struct kvm_riscv_aia_csr) / sizeof(unsigned long))
+ if (reg_num >= sizeof(struct kvm_riscv_aia_csr) / sizeof(xlen_t))
return -ENOENT;
*out_val = 0;
if (kvm_riscv_aia_available())
- *out_val = ((unsigned long *)csr)[reg_num];
+ *out_val = ((xlen_t *)csr)[reg_num];
return 0;
}
int kvm_riscv_vcpu_aia_set_csr(struct kvm_vcpu *vcpu,
unsigned long reg_num,
- unsigned long val)
+ xlen_t val)
{
struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
- if (reg_num >= sizeof(struct kvm_riscv_aia_csr) / sizeof(unsigned long))
+ if (reg_num >= sizeof(struct kvm_riscv_aia_csr) / sizeof(xlen_t))
return -ENOENT;
if (kvm_riscv_aia_available()) {
- ((unsigned long *)csr)[reg_num] = val;
+ ((xlen_t *)csr)[reg_num] = val;
#ifdef CONFIG_32BIT
if (reg_num == KVM_REG_RISCV_CSR_AIA_REG(siph))
@@ -237,9 +237,9 @@ int kvm_riscv_vcpu_aia_set_csr(struct kvm_vcpu *vcpu,
int kvm_riscv_vcpu_aia_rmw_topei(struct kvm_vcpu *vcpu,
unsigned int csr_num,
- unsigned long *val,
- unsigned long new_val,
- unsigned long wr_mask)
+ xlen_t *val,
+ xlen_t new_val,
+ xlen_t wr_mask)
{
/* If AIA not available then redirect trap */
if (!kvm_riscv_aia_available())
@@ -271,7 +271,7 @@ static int aia_irq2bitpos[] = {
static u8 aia_get_iprio8(struct kvm_vcpu *vcpu, unsigned int irq)
{
- unsigned long hviprio;
+ xlen_t hviprio;
int bitpos = aia_irq2bitpos[irq];
if (bitpos < 0)
@@ -396,8 +396,8 @@ static int aia_rmw_iprio(struct kvm_vcpu *vcpu, unsigned int isel,
}
int kvm_riscv_vcpu_aia_rmw_ireg(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask)
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask)
{
unsigned int isel;
@@ -408,7 +408,7 @@ int kvm_riscv_vcpu_aia_rmw_ireg(struct kvm_vcpu *vcpu, unsigned int csr_num,
/* First try to emulate in kernel space */
isel = ncsr_read(CSR_VSISELECT) & ISELECT_MASK;
if (isel >= ISELECT_IPRIO0 && isel <= ISELECT_IPRIO15)
- return aia_rmw_iprio(vcpu, isel, val, new_val, wr_mask);
+ return aia_rmw_iprio(vcpu, isel, (ulong *)val, new_val, wr_mask);
else if (isel >= IMSIC_FIRST && isel <= IMSIC_LAST &&
kvm_riscv_aia_initialized(vcpu->kvm))
return kvm_riscv_vcpu_aia_imsic_rmw(vcpu, isel, val, new_val,
diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c
index a8085cd8215e..3c7f13b7a2ba 100644
--- a/arch/riscv/kvm/aia_imsic.c
+++ b/arch/riscv/kvm/aia_imsic.c
@@ -839,8 +839,8 @@ int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu)
}
int kvm_riscv_vcpu_aia_imsic_rmw(struct kvm_vcpu *vcpu, unsigned long isel,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask)
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask)
{
u32 topei;
struct imsic_mrif_eix *eix;
@@ -866,7 +866,7 @@ int kvm_riscv_vcpu_aia_imsic_rmw(struct kvm_vcpu *vcpu, unsigned long isel,
}
} else {
r = imsic_mrif_rmw(imsic->swfile, imsic->nr_eix, isel,
- val, new_val, wr_mask);
+ (ulong *)val, (ulong)new_val, (ulong)wr_mask);
/* Forward unknown IMSIC register to user-space */
if (r)
rc = (r == -ENOENT) ? 0 : KVM_INSN_ILLEGAL_TRAP;
diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c
index 1fa8be5ee509..34d053ae09a9 100644
--- a/arch/riscv/kvm/main.c
+++ b/arch/riscv/kvm/main.c
@@ -152,7 +152,7 @@ static int __init riscv_kvm_init(void)
}
kvm_info("using %s G-stage page table format\n", str);
- kvm_info("VMID %ld bits available\n", kvm_riscv_gstage_vmid_bits());
+ kvm_info("VMID %ld bits available\n", (ulong)kvm_riscv_gstage_vmid_bits());
if (kvm_riscv_aia_available())
kvm_info("AIA available with %d guest external interrupts\n",
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index 1087ea74567b..a89e5701076d 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/riscv/kvm/mmu.c
@@ -20,7 +20,7 @@
#include <asm/pgtable.h>
#ifdef CONFIG_64BIT
-static unsigned long gstage_mode __ro_after_init = (HGATP_MODE_SV39X4 << HGATP_MODE_SHIFT);
+static xlen_t gstage_mode __ro_after_init = (HGATP_MODE_SV39X4 << HGATP_MODE_SHIFT);
static unsigned long gstage_pgd_levels __ro_after_init = 3;
#define gstage_index_bits 9
#else
@@ -30,11 +30,11 @@ static unsigned long gstage_pgd_levels __ro_after_init = 2;
#endif
#define gstage_pgd_xbits 2
-#define gstage_pgd_size (1UL << (HGATP_PAGE_SHIFT + gstage_pgd_xbits))
+#define gstage_pgd_size (_AC(1, UXL) << (HGATP_PAGE_SHIFT + gstage_pgd_xbits))
#define gstage_gpa_bits (HGATP_PAGE_SHIFT + \
(gstage_pgd_levels * gstage_index_bits) + \
gstage_pgd_xbits)
-#define gstage_gpa_size ((gpa_t)(1ULL << gstage_gpa_bits))
+#define gstage_gpa_size ((gpa_t)(_AC(1, UXL) << gstage_gpa_bits))
#define gstage_pte_leaf(__ptep) \
(pte_val(*(__ptep)) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC))
@@ -623,7 +623,7 @@ int kvm_riscv_gstage_map(struct kvm_vcpu *vcpu,
vma_pageshift = huge_page_shift(hstate_vma(vma));
else
vma_pageshift = PAGE_SHIFT;
- vma_pagesize = 1ULL << vma_pageshift;
+ vma_pagesize = _AC(1, UXL) << vma_pageshift;
if (logging || (vma->vm_flags & VM_PFNMAP))
vma_pagesize = PAGE_SIZE;
@@ -725,7 +725,7 @@ void kvm_riscv_gstage_free_pgd(struct kvm *kvm)
void kvm_riscv_gstage_update_hgatp(struct kvm_vcpu *vcpu)
{
- unsigned long hgatp = gstage_mode;
+ xlen_t hgatp = gstage_mode;
struct kvm_arch *k = &vcpu->kvm->arch;
hgatp |= (READ_ONCE(k->vmid.vmid) << HGATP_VMID_SHIFT) & HGATP_VMID;
diff --git a/arch/riscv/kvm/tlb.c b/arch/riscv/kvm/tlb.c
index 2f91ea5f8493..01d581763849 100644
--- a/arch/riscv/kvm/tlb.c
+++ b/arch/riscv/kvm/tlb.c
@@ -18,9 +18,9 @@
#define has_svinval() riscv_has_extension_unlikely(RISCV_ISA_EXT_SVINVAL)
-void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid,
+void kvm_riscv_local_hfence_gvma_vmid_gpa(xlen_t vmid,
gpa_t gpa, gpa_t gpsz,
- unsigned long order)
+ xlen_t order)
{
gpa_t pos;
@@ -42,13 +42,13 @@ void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid,
}
}
-void kvm_riscv_local_hfence_gvma_vmid_all(unsigned long vmid)
+void kvm_riscv_local_hfence_gvma_vmid_all(xlen_t vmid)
{
asm volatile(HFENCE_GVMA(zero, %0) : : "r" (vmid) : "memory");
}
void kvm_riscv_local_hfence_gvma_gpa(gpa_t gpa, gpa_t gpsz,
- unsigned long order)
+ xlen_t order)
{
gpa_t pos;
@@ -75,13 +75,14 @@ void kvm_riscv_local_hfence_gvma_all(void)
asm volatile(HFENCE_GVMA(zero, zero) : : : "memory");
}
-void kvm_riscv_local_hfence_vvma_asid_gva(unsigned long vmid,
- unsigned long asid,
- unsigned long gva,
- unsigned long gvsz,
- unsigned long order)
+void kvm_riscv_local_hfence_vvma_asid_gva(xlen_t vmid,
+ xlen_t asid,
+ xlen_t gva,
+ xlen_t gvsz,
+ xlen_t order)
{
- unsigned long pos, hgatp;
+ xlen_t pos;
+ xlen_t hgatp;
if (PTRS_PER_PTE < (gvsz >> order)) {
kvm_riscv_local_hfence_vvma_asid_all(vmid, asid);
@@ -105,10 +106,10 @@ void kvm_riscv_local_hfence_vvma_asid_gva(unsigned long vmid,
csr_write(CSR_HGATP, hgatp);
}
-void kvm_riscv_local_hfence_vvma_asid_all(unsigned long vmid,
- unsigned long asid)
+void kvm_riscv_local_hfence_vvma_asid_all(xlen_t vmid,
+ xlen_t asid)
{
- unsigned long hgatp;
+ xlen_t hgatp;
hgatp = csr_swap(CSR_HGATP, vmid << HGATP_VMID_SHIFT);
@@ -117,11 +118,12 @@ void kvm_riscv_local_hfence_vvma_asid_all(unsigned long vmid,
csr_write(CSR_HGATP, hgatp);
}
-void kvm_riscv_local_hfence_vvma_gva(unsigned long vmid,
- unsigned long gva, unsigned long gvsz,
- unsigned long order)
+void kvm_riscv_local_hfence_vvma_gva(xlen_t vmid,
+ xlen_t gva, xlen_t gvsz,
+ xlen_t order)
{
- unsigned long pos, hgatp;
+ xlen_t pos;
+ xlen_t hgatp;
if (PTRS_PER_PTE < (gvsz >> order)) {
kvm_riscv_local_hfence_vvma_all(vmid);
@@ -145,9 +147,9 @@ void kvm_riscv_local_hfence_vvma_gva(unsigned long vmid,
csr_write(CSR_HGATP, hgatp);
}
-void kvm_riscv_local_hfence_vvma_all(unsigned long vmid)
+void kvm_riscv_local_hfence_vvma_all(xlen_t vmid)
{
- unsigned long hgatp;
+ xlen_t hgatp;
hgatp = csr_swap(CSR_HGATP, vmid << HGATP_VMID_SHIFT);
@@ -158,7 +160,7 @@ void kvm_riscv_local_hfence_vvma_all(unsigned long vmid)
void kvm_riscv_local_tlb_sanitize(struct kvm_vcpu *vcpu)
{
- unsigned long vmid;
+ xlen_t vmid;
if (!kvm_riscv_gstage_vmid_bits() ||
vcpu->arch.last_exit_cpu == vcpu->cpu)
@@ -188,7 +190,7 @@ void kvm_riscv_fence_i_process(struct kvm_vcpu *vcpu)
void kvm_riscv_hfence_gvma_vmid_all_process(struct kvm_vcpu *vcpu)
{
struct kvm_vmid *v = &vcpu->kvm->arch.vmid;
- unsigned long vmid = READ_ONCE(v->vmid);
+ xlen_t vmid = READ_ONCE(v->vmid);
if (kvm_riscv_nacl_available())
nacl_hfence_gvma_vmid_all(nacl_shmem(), vmid);
@@ -199,7 +201,7 @@ void kvm_riscv_hfence_gvma_vmid_all_process(struct kvm_vcpu *vcpu)
void kvm_riscv_hfence_vvma_all_process(struct kvm_vcpu *vcpu)
{
struct kvm_vmid *v = &vcpu->kvm->arch.vmid;
- unsigned long vmid = READ_ONCE(v->vmid);
+ xlen_t vmid = READ_ONCE(v->vmid);
if (kvm_riscv_nacl_available())
nacl_hfence_vvma_all(nacl_shmem(), vmid);
@@ -258,7 +260,7 @@ static bool vcpu_hfence_enqueue(struct kvm_vcpu *vcpu,
void kvm_riscv_hfence_process(struct kvm_vcpu *vcpu)
{
- unsigned long vmid;
+ xlen_t vmid;
struct kvm_riscv_hfence d = { 0 };
struct kvm_vmid *v = &vcpu->kvm->arch.vmid;
@@ -310,7 +312,7 @@ void kvm_riscv_hfence_process(struct kvm_vcpu *vcpu)
}
static void make_xfence_request(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
+ xlen_t hbase, xlen_t hmask,
unsigned int req, unsigned int fallback_req,
const struct kvm_riscv_hfence *data)
{
@@ -346,16 +348,16 @@ static void make_xfence_request(struct kvm *kvm,
}
void kvm_riscv_fence_i(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask)
+ xlen_t hbase, xlen_t hmask)
{
make_xfence_request(kvm, hbase, hmask, KVM_REQ_FENCE_I,
KVM_REQ_FENCE_I, NULL);
}
void kvm_riscv_hfence_gvma_vmid_gpa(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
+ xlen_t hbase, xlen_t hmask,
gpa_t gpa, gpa_t gpsz,
- unsigned long order)
+ xlen_t order)
{
struct kvm_riscv_hfence data;
@@ -369,16 +371,16 @@ void kvm_riscv_hfence_gvma_vmid_gpa(struct kvm *kvm,
}
void kvm_riscv_hfence_gvma_vmid_all(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask)
+ xlen_t hbase, xlen_t hmask)
{
make_xfence_request(kvm, hbase, hmask, KVM_REQ_HFENCE_GVMA_VMID_ALL,
KVM_REQ_HFENCE_GVMA_VMID_ALL, NULL);
}
void kvm_riscv_hfence_vvma_asid_gva(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
- unsigned long gva, unsigned long gvsz,
- unsigned long order, unsigned long asid)
+ xlen_t hbase, xlen_t hmask,
+ xlen_t gva, xlen_t gvsz,
+ xlen_t order, xlen_t asid)
{
struct kvm_riscv_hfence data;
@@ -392,8 +394,8 @@ void kvm_riscv_hfence_vvma_asid_gva(struct kvm *kvm,
}
void kvm_riscv_hfence_vvma_asid_all(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
- unsigned long asid)
+ xlen_t hbase, xlen_t hmask,
+ xlen_t asid)
{
struct kvm_riscv_hfence data;
@@ -405,9 +407,9 @@ void kvm_riscv_hfence_vvma_asid_all(struct kvm *kvm,
}
void kvm_riscv_hfence_vvma_gva(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask,
- unsigned long gva, unsigned long gvsz,
- unsigned long order)
+ xlen_t hbase, xlen_t hmask,
+ xlen_t gva, xlen_t gvsz,
+ xlen_t order)
{
struct kvm_riscv_hfence data;
@@ -421,7 +423,7 @@ void kvm_riscv_hfence_vvma_gva(struct kvm *kvm,
}
void kvm_riscv_hfence_vvma_all(struct kvm *kvm,
- unsigned long hbase, unsigned long hmask)
+ xlen_t hbase, xlen_t hmask)
{
make_xfence_request(kvm, hbase, hmask, KVM_REQ_HFENCE_VVMA_ALL,
KVM_REQ_HFENCE_VVMA_ALL, NULL);
diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index 60d684c76c58..144e25ead287 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -797,11 +797,11 @@ static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu,
if (kvm_riscv_nacl_autoswap_csr_available()) {
hcntx->hstatus =
nacl_csr_read(nsh, CSR_HSTATUS);
- nacl_scratch_write_long(nsh,
+ nacl_scratch_write_csr(nsh,
SBI_NACL_SHMEM_AUTOSWAP_OFFSET +
SBI_NACL_SHMEM_AUTOSWAP_HSTATUS,
gcntx->hstatus);
- nacl_scratch_write_long(nsh,
+ nacl_scratch_write_csr(nsh,
SBI_NACL_SHMEM_AUTOSWAP_OFFSET,
SBI_NACL_SHMEM_AUTOSWAP_FLAG_HSTATUS);
} else if (kvm_riscv_nacl_sync_csr_available()) {
@@ -811,7 +811,7 @@ static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu,
hcntx->hstatus = csr_swap(CSR_HSTATUS, gcntx->hstatus);
}
- nacl_scratch_write_longs(nsh,
+ nacl_scratch_write_csrs(nsh,
SBI_NACL_SHMEM_SRET_OFFSET +
SBI_NACL_SHMEM_SRET_X(1),
&gcntx->ra,
@@ -821,10 +821,10 @@ static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu,
SBI_EXT_NACL_SYNC_SRET);
if (kvm_riscv_nacl_autoswap_csr_available()) {
- nacl_scratch_write_long(nsh,
+ nacl_scratch_write_csr(nsh,
SBI_NACL_SHMEM_AUTOSWAP_OFFSET,
0);
- gcntx->hstatus = nacl_scratch_read_long(nsh,
+ gcntx->hstatus = nacl_scratch_read_csr(nsh,
SBI_NACL_SHMEM_AUTOSWAP_OFFSET +
SBI_NACL_SHMEM_AUTOSWAP_HSTATUS);
} else {
diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
index 6e0c18412795..0f6b80d87825 100644
--- a/arch/riscv/kvm/vcpu_exit.c
+++ b/arch/riscv/kvm/vcpu_exit.c
@@ -246,11 +246,11 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
/* Print details in-case of error */
if (ret < 0) {
kvm_err("VCPU exit error %d\n", ret);
- kvm_err("SEPC=0x%lx SSTATUS=0x%lx HSTATUS=0x%lx\n",
+ kvm_err("SEPC=0x" REG_FMT "SSTATUS=0x" REG_FMT " HSTATUS=0x" REG_FMT "\n",
vcpu->arch.guest_context.sepc,
vcpu->arch.guest_context.sstatus,
vcpu->arch.guest_context.hstatus);
- kvm_err("SCAUSE=0x%lx STVAL=0x%lx HTVAL=0x%lx HTINST=0x%lx\n",
+ kvm_err("SCAUSE=0x" REG_FMT " STVAL=0x" REG_FMT " HTVAL=0x" REG_FMT " HTINST=0x" REG_FMT "\n",
trap->scause, trap->stval, trap->htval, trap->htinst);
}
diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c
index 97dec18e6989..c25415d63d96 100644
--- a/arch/riscv/kvm/vcpu_insn.c
+++ b/arch/riscv/kvm/vcpu_insn.c
@@ -221,13 +221,13 @@ struct csr_func {
* "struct insn_func".
*/
int (*func)(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask);
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask);
};
static int seed_csr_rmw(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask)
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask)
{
if (!riscv_isa_extension_available(vcpu->arch.isa, ZKR))
return KVM_INSN_ILLEGAL_TRAP;
@@ -275,9 +275,9 @@ static int csr_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
int i, rc = KVM_INSN_ILLEGAL_TRAP;
unsigned int csr_num = insn >> SH_RS2;
unsigned int rs1_num = (insn >> SH_RS1) & MASK_RX;
- ulong rs1_val = GET_RS1(insn, &vcpu->arch.guest_context);
+ xlen_t rs1_val = GET_RS1(insn, &vcpu->arch.guest_context);
const struct csr_func *tcfn, *cfn = NULL;
- ulong val = 0, wr_mask = 0, new_val = 0;
+ xlen_t val = 0, wr_mask = 0, new_val = 0;
/* Decode the CSR instruction */
switch (GET_FUNCT3(insn)) {
diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c
index f6d27b59c641..34e11fbe27e8 100644
--- a/arch/riscv/kvm/vcpu_onereg.c
+++ b/arch/riscv/kvm/vcpu_onereg.c
@@ -448,7 +448,7 @@ static int kvm_riscv_vcpu_set_reg_core(struct kvm_vcpu *vcpu,
static int kvm_riscv_vcpu_general_get_csr(struct kvm_vcpu *vcpu,
unsigned long reg_num,
- unsigned long *out_val)
+ xlen_t *out_val)
{
struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr;
@@ -494,24 +494,24 @@ static inline int kvm_riscv_vcpu_smstateen_set_csr(struct kvm_vcpu *vcpu,
struct kvm_vcpu_smstateen_csr *csr = &vcpu->arch.smstateen_csr;
if (reg_num >= sizeof(struct kvm_riscv_smstateen_csr) /
- sizeof(unsigned long))
+ sizeof(xlen_t))
return -EINVAL;
- ((unsigned long *)csr)[reg_num] = reg_val;
+ ((xlen_t *)csr)[reg_num] = reg_val;
return 0;
}
static int kvm_riscv_vcpu_smstateen_get_csr(struct kvm_vcpu *vcpu,
unsigned long reg_num,
- unsigned long *out_val)
+ xlen_t *out_val)
{
struct kvm_vcpu_smstateen_csr *csr = &vcpu->arch.smstateen_csr;
if (reg_num >= sizeof(struct kvm_riscv_smstateen_csr) /
- sizeof(unsigned long))
+ sizeof(xlen_t))
return -EINVAL;
- *out_val = ((unsigned long *)csr)[reg_num];
+ *out_val = ((xlen_t *)csr)[reg_num];
return 0;
}
@@ -519,12 +519,12 @@ static int kvm_riscv_vcpu_get_reg_csr(struct kvm_vcpu *vcpu,
const struct kvm_one_reg *reg)
{
int rc;
- unsigned long __user *uaddr =
- (unsigned long __user *)(unsigned long)reg->addr;
+ xlen_t __user *uaddr =
+ (xlen_t __user *)(unsigned long)reg->addr;
unsigned long reg_num = reg->id & ~(KVM_REG_ARCH_MASK |
KVM_REG_SIZE_MASK |
KVM_REG_RISCV_CSR);
- unsigned long reg_val, reg_subtype;
+ xlen_t reg_val, reg_subtype;
if (KVM_REG_SIZE(reg->id) != sizeof(unsigned long))
return -EINVAL;
diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c
index 2707a51b082c..3bfecda72150 100644
--- a/arch/riscv/kvm/vcpu_pmu.c
+++ b/arch/riscv/kvm/vcpu_pmu.c
@@ -198,7 +198,7 @@ static int pmu_get_pmc_index(struct kvm_pmu *pmu, unsigned long eidx,
}
static int pmu_fw_ctr_read_hi(struct kvm_vcpu *vcpu, unsigned long cidx,
- unsigned long *out_val)
+ xlen_t *out_val)
{
struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
struct kvm_pmc *pmc;
@@ -228,7 +228,7 @@ static int pmu_fw_ctr_read_hi(struct kvm_vcpu *vcpu, unsigned long cidx,
}
static int pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx,
- unsigned long *out_val)
+ xlen_t *out_val)
{
struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
struct kvm_pmc *pmc;
@@ -354,8 +354,8 @@ int kvm_riscv_vcpu_pmu_incr_fw(struct kvm_vcpu *vcpu, unsigned long fid)
}
int kvm_riscv_vcpu_pmu_read_hpm(struct kvm_vcpu *vcpu, unsigned int csr_num,
- unsigned long *val, unsigned long new_val,
- unsigned long wr_mask)
+ xlen_t *val, xlen_t new_val,
+ xlen_t wr_mask)
{
struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
int cidx, ret = KVM_INSN_CONTINUE_NEXT_SEPC;
diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
index 5bc570b984f4..a243339a73fd 100644
--- a/arch/riscv/kvm/vcpu_sbi_base.c
+++ b/arch/riscv/kvm/vcpu_sbi_base.c
@@ -18,7 +18,7 @@ static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
{
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
const struct kvm_vcpu_sbi_extension *sbi_ext;
- unsigned long *out_val = &retdata->out_val;
+ xlen_t *out_val = &retdata->out_val;
switch (cp->a6) {
case SBI_EXT_BASE_GET_SPEC_VERSION:
diff --git a/arch/riscv/kvm/vmid.c b/arch/riscv/kvm/vmid.c
index ddc98714ce8e..17744dfaf008 100644
--- a/arch/riscv/kvm/vmid.c
+++ b/arch/riscv/kvm/vmid.c
@@ -17,7 +17,7 @@
static unsigned long vmid_version = 1;
static unsigned long vmid_next;
-static unsigned long vmid_bits __ro_after_init;
+static xlen_t vmid_bits __ro_after_init;
static DEFINE_SPINLOCK(vmid_lock);
void __init kvm_riscv_gstage_vmid_detect(void)
@@ -40,7 +40,7 @@ void __init kvm_riscv_gstage_vmid_detect(void)
vmid_bits = 0;
}
-unsigned long kvm_riscv_gstage_vmid_bits(void)
+xlen_t kvm_riscv_gstage_vmid_bits(void)
{
return vmid_bits;
}
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 19/43] rv64ilp32_abi: irqchip: irq-riscv-intc: Use xlen_t instead of ulong
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (17 preceding siblings ...)
2025-03-25 12:15 ` [RFC PATCH V3 18/43] rv64ilp32_abi: riscv: kvm: Initial support guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 20/43] rv64ilp32_abi: drivers/perf: Adapt xlen_t of sbiret guoren
` (25 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI is based on CONFIG_64BIT, so use xlen/xlen_t
instead of BITS_PER_LONG/ulong.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
drivers/irqchip/irq-riscv-intc.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c
index f653c13de62b..4fc7d5704acf 100644
--- a/drivers/irqchip/irq-riscv-intc.c
+++ b/drivers/irqchip/irq-riscv-intc.c
@@ -20,18 +20,19 @@
#include <linux/soc/andes/irq.h>
#include <asm/hwcap.h>
+#include <asm/ptrace.h>
static struct irq_domain *intc_domain;
-static unsigned int riscv_intc_nr_irqs __ro_after_init = BITS_PER_LONG;
-static unsigned int riscv_intc_custom_base __ro_after_init = BITS_PER_LONG;
+static unsigned int riscv_intc_nr_irqs __ro_after_init = __riscv_xlen;
+static unsigned int riscv_intc_custom_base __ro_after_init = __riscv_xlen;
static unsigned int riscv_intc_custom_nr_irqs __ro_after_init;
static void riscv_intc_irq(struct pt_regs *regs)
{
- unsigned long cause = regs->cause & ~CAUSE_IRQ_FLAG;
+ xlen_t cause = regs->cause & ~CAUSE_IRQ_FLAG;
if (generic_handle_domain_irq(intc_domain, cause))
- pr_warn_ratelimited("Failed to handle interrupt (cause: %ld)\n", cause);
+ pr_warn_ratelimited("Failed to handle interrupt (cause: " REG_FMT ")\n", cause);
}
static void riscv_intc_aia_irq(struct pt_regs *regs)
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 20/43] rv64ilp32_abi: drivers/perf: Adapt xlen_t of sbiret
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (18 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 19/43] rv64ilp32_abi: irqchip: irq-riscv-intc: Use xlen_t instead of ulong guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 21/43] rv64ilp32_abi: asm-generic: Add custom BITS_PER_LONG definition guoren
` (24 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
Because rv64ilp32_abi change the sbiret struct,
from:
struct sbiret {
long error;
long value;
};
to:
struct sbiret {
xlen_t error;
xlen_t value;
};
So, use a cast long to prevent compile warning.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
drivers/perf/riscv_pmu_sbi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index 698de8ddf895..e2c4d1bcbc7c 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -638,7 +638,7 @@ static int pmu_sbi_snapshot_setup(struct riscv_pmu *pmu, int cpu)
/* Free up the snapshot area memory and fall back to SBI PMU calls without snapshot */
if (ret.error) {
if (ret.error != SBI_ERR_NOT_SUPPORTED)
- pr_warn("pmu snapshot setup failed with error %ld\n", ret.error);
+ pr_warn("pmu snapshot setup failed with error %ld\n", (long)ret.error);
return sbi_err_map_linux_errno(ret.error);
}
@@ -679,7 +679,7 @@ static u64 pmu_sbi_ctr_read(struct perf_event *event)
val |= ((u64)ret.value << 32);
else
WARN_ONCE(1, "Unable to read upper 32 bits of firmware counter error: %ld\n",
- ret.error);
+ (long)ret.error);
}
} else {
val = riscv_pmu_ctr_read_csr(info.csr);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 21/43] rv64ilp32_abi: asm-generic: Add custom BITS_PER_LONG definition
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (19 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 20/43] rv64ilp32_abi: drivers/perf: Adapt xlen_t of sbiret guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 22/43] rv64ilp32_abi: bpf: Change KERN_ARENA_SZ to 256MiB guoren
` (23 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI linux kernel is based on CONFIG_64BIT, but
BITS_PER_LONG is 32. So, give a custom architectural definition
of BITS_PER_LONG to match the correct macro definition.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/uapi/asm/bitsperlong.h | 6 ++++++
include/asm-generic/bitsperlong.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/arch/riscv/include/uapi/asm/bitsperlong.h b/arch/riscv/include/uapi/asm/bitsperlong.h
index 7d0b32e3b701..fec2ad91597c 100644
--- a/arch/riscv/include/uapi/asm/bitsperlong.h
+++ b/arch/riscv/include/uapi/asm/bitsperlong.h
@@ -9,6 +9,12 @@
#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8)
+#if __BITS_PER_LONG == 64
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif
+
#include <asm-generic/bitsperlong.h>
#endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h
index 1023e2a4bd37..7ccbb7ce6610 100644
--- a/include/asm-generic/bitsperlong.h
+++ b/include/asm-generic/bitsperlong.h
@@ -6,7 +6,9 @@
#ifdef CONFIG_64BIT
+#ifndef BITS_PER_LONG
#define BITS_PER_LONG 64
+#endif
#else
#define BITS_PER_LONG 32
#endif /* CONFIG_64BIT */
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 22/43] rv64ilp32_abi: bpf: Change KERN_ARENA_SZ to 256MiB
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (20 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 21/43] rv64ilp32_abi: asm-generic: Add custom BITS_PER_LONG definition guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 23/43] rv64ilp32_abi: compat: Correct compat_ulong_t cast guoren
` (22 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI limits the vmalloc range to 512MB, hence the
arena kernel range is set to 256MiB instead of 4GiB.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
kernel/bpf/arena.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
index 870aeb51d70a..4eb99f83d4a1 100644
--- a/kernel/bpf/arena.c
+++ b/kernel/bpf/arena.c
@@ -40,7 +40,14 @@
/* number of bytes addressable by LDX/STX insn with 16-bit 'off' field */
#define GUARD_SZ (1ull << sizeof_field(struct bpf_insn, off) * 8)
-#define KERN_VM_SZ (SZ_4G + GUARD_SZ)
+
+#if BITS_PER_LONG == 64
+#define KERN_ARENA_SZ SZ_4G
+#else
+#define KERN_ARENA_SZ SZ_256M
+#endif
+
+#define KERN_VM_SZ (KERN_ARENA_SZ + GUARD_SZ)
struct bpf_arena {
struct bpf_map map;
@@ -115,7 +122,7 @@ static struct bpf_map *arena_map_alloc(union bpf_attr *attr)
return ERR_PTR(-EINVAL);
vm_range = (u64)attr->max_entries * PAGE_SIZE;
- if (vm_range > SZ_4G)
+ if (vm_range > KERN_ARENA_SZ)
return ERR_PTR(-E2BIG);
if ((attr->map_extra >> 32) != ((attr->map_extra + vm_range - 1) >> 32))
@@ -321,7 +328,7 @@ static unsigned long arena_get_unmapped_area(struct file *filp, unsigned long ad
if (pgoff)
return -EINVAL;
- if (len > SZ_4G)
+ if (len > KERN_ARENA_SZ)
return -E2BIG;
/* if user_vm_start was specified at arena creation time */
@@ -337,12 +344,14 @@ static unsigned long arena_get_unmapped_area(struct file *filp, unsigned long ad
ret = mm_get_unmapped_area(current->mm, filp, addr, len * 2, 0, flags);
if (IS_ERR_VALUE(ret))
return ret;
+#if BITS_PER_LONG == 64
if ((ret >> 32) == ((ret + len - 1) >> 32))
return ret;
+#endif
if (WARN_ON_ONCE(arena->user_vm_start))
/* checks at map creation time should prevent this */
return -EFAULT;
- return round_up(ret, SZ_4G);
+ return round_up(ret, KERN_ARENA_SZ);
}
static int arena_map_mmap(struct bpf_map *map, struct vm_area_struct *vma)
@@ -366,7 +375,7 @@ static int arena_map_mmap(struct bpf_map *map, struct vm_area_struct *vma)
return -EBUSY;
/* Earlier checks should prevent this */
- if (WARN_ON_ONCE(vma->vm_end - vma->vm_start > SZ_4G || vma->vm_pgoff))
+ if (WARN_ON_ONCE(vma->vm_end - vma->vm_start > KERN_ARENA_SZ || vma->vm_pgoff))
return -EFAULT;
if (remember_vma(arena, vma))
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 23/43] rv64ilp32_abi: compat: Correct compat_ulong_t cast
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (21 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 22/43] rv64ilp32_abi: bpf: Change KERN_ARENA_SZ to 256MiB guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 24/43] rv64ilp32_abi: compiler_types: Add "long long" into __native_word() guoren
` (21 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
RV64ILP32 ABI systems have BITS_PER_LONG set to 32, matching
sizeof(compat_ulong_t). Adjust code involving compat_ulong_t
accordingly.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/uapi/linux/auto_fs.h | 6 ++++++
kernel/compat.c | 15 ++++++++++++---
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/auto_fs.h b/include/uapi/linux/auto_fs.h
index 8081df849743..7d925ee810b6 100644
--- a/include/uapi/linux/auto_fs.h
+++ b/include/uapi/linux/auto_fs.h
@@ -80,9 +80,15 @@ enum {
#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(AUTOFS_IOCTL, \
AUTOFS_IOC_SETTIMEOUT_CMD, \
compat_ulong_t)
+#if __riscv_xlen == 64
+#define AUTOFS_IOC_SETTIMEOUT _IOWR(AUTOFS_IOCTL, \
+ AUTOFS_IOC_SETTIMEOUT_CMD, \
+ unsigned long long)
+#else
#define AUTOFS_IOC_SETTIMEOUT _IOWR(AUTOFS_IOCTL, \
AUTOFS_IOC_SETTIMEOUT_CMD, \
unsigned long)
+#endif
#define AUTOFS_IOC_EXPIRE _IOR(AUTOFS_IOCTL, \
AUTOFS_IOC_EXPIRE_CMD, \
struct autofs_packet_expire)
diff --git a/kernel/compat.c b/kernel/compat.c
index fb50f29d9b36..46ffdc5e7cc4 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -203,11 +203,17 @@ long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
return -EFAULT;
while (nr_compat_longs > 1) {
- compat_ulong_t l1, l2;
+ compat_ulong_t l1;
unsafe_get_user(l1, umask++, Efault);
+ nr_compat_longs -= 1;
+#if BITS_PER_LONG == 64
+ compat_ulong_t l2;
unsafe_get_user(l2, umask++, Efault);
*mask++ = ((unsigned long)l2 << BITS_PER_COMPAT_LONG) | l1;
- nr_compat_longs -= 2;
+ nr_compat_longs -= 1;
+#else
+ *mask++ = l1;
+#endif
}
if (nr_compat_longs)
unsafe_get_user(*mask, umask++, Efault);
@@ -234,8 +240,11 @@ long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
while (nr_compat_longs > 1) {
unsigned long m = *mask++;
unsafe_put_user((compat_ulong_t)m, umask++, Efault);
+ nr_compat_longs -= 1;
+#if BITS_PER_LONG == 64
unsafe_put_user(m >> BITS_PER_COMPAT_LONG, umask++, Efault);
- nr_compat_longs -= 2;
+ nr_compat_longs -= 1;
+#endif
}
if (nr_compat_longs)
unsafe_put_user((compat_ulong_t)*mask, umask++, Efault);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 24/43] rv64ilp32_abi: compiler_types: Add "long long" into __native_word()
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (22 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 23/43] rv64ilp32_abi: compat: Correct compat_ulong_t cast guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv guoren
` (20 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 abi supports native atomic64 operations. The
atomic64_t is defined by "long long," so add "long long" into
__native_word().
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/compiler_types.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 981cc3d7e3aa..6cf36a8e9570 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -505,9 +505,16 @@ struct ftrace_likely_data {
default: (x)))
/* Is this type a native word size -- useful for atomic operations */
+#ifdef CONFIG_64BIT
+#define __native_word(t) \
+ (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
+ sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long) || \
+ sizeof(t) == sizeof(long long))
+#else
#define __native_word(t) \
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
+#endif
#ifdef __OPTIMIZE__
# define __compiletime_assert(condition, msg, prefix, suffix) \
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (23 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 24/43] rv64ilp32_abi: compiler_types: Add "long long" into __native_word() guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 17:19 ` Sergey Shtylyov
2025-03-25 12:16 ` [RFC PATCH V3 26/43] rv64ilp32_abi: file_ref: Use 32-bit width for refcnt guoren
` (19 subsequent siblings)
44 siblings, 1 reply; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 abi reuses the env and argv memory layout of the
lp64 abi, so leave the space to fit the lp64 struct layout.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
fs/exec.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/exec.c b/fs/exec.c
index 506cd411f4ac..548d18b7ae92 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -424,6 +424,10 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
}
#endif
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ nr = nr * 2;
+#endif
+
if (get_user(native, argv.ptr.native + nr))
return ERR_PTR(-EFAULT);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 26/43] rv64ilp32_abi: file_ref: Use 32-bit width for refcnt
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (24 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 27/43] rv64ilp32_abi: input: Adapt BITS_PER_LONG to dword guoren
` (18 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The sizeof(atomic_t) is 4 in rv64ilp32 abi linux kernel, which
could provide a higher density of cache and a smaller memory
footprint.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/file_ref.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/file_ref.h b/include/linux/file_ref.h
index 9b3a8d9b17ab..ce9b47359e14 100644
--- a/include/linux/file_ref.h
+++ b/include/linux/file_ref.h
@@ -27,7 +27,7 @@
* 0xFFFFFFFFFFFFFFFFUL
*/
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
#define FILE_REF_ONEREF 0x0000000000000000UL
#define FILE_REF_MAXREF 0x7FFFFFFFFFFFFFFFUL
#define FILE_REF_SATURATED 0xA000000000000000UL
@@ -44,7 +44,7 @@
#endif
typedef struct {
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
atomic64_t refcnt;
#else
atomic_t refcnt;
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 27/43] rv64ilp32_abi: input: Adapt BITS_PER_LONG to dword
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (25 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 26/43] rv64ilp32_abi: file_ref: Use 32-bit width for refcnt guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 28/43] rv64ilp32_abi: iov_iter: Resize kvec to match iov_iter's size guoren
` (17 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI linux kernel is based on CONFIG_64BIT, but
BITS_PER_LONG is 32. So, adapt bits to dword with BITS_PER_LONG.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
drivers/input/input.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index c9e3ac64bcd0..7af5e8c66f25 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1006,7 +1006,11 @@ static int input_bits_to_string(char *buf, int buf_size,
int len = 0;
if (in_compat_syscall()) {
+#if BITS_PER_LONG == 64
u32 dword = bits >> 32;
+#else
+ u32 dword = bits;
+#endif
if (dword || !skip_empty)
len += snprintf(buf, buf_size, "%x ", dword);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 28/43] rv64ilp32_abi: iov_iter: Resize kvec to match iov_iter's size
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (26 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 27/43] rv64ilp32_abi: input: Adapt BITS_PER_LONG to dword guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 29/43] rv64ilp32_abi: locking/atomic: Use BITS_PER_LONG for scripts guoren
` (16 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
As drivers/vhost/vringh.c uses BUILD_BUG_ON(sizeof(struct iovec)
!= sizeof(struct kvec)), make them the same.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/uio.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 8ada84e85447..0e1ca023374c 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -17,7 +17,13 @@ typedef unsigned int __bitwise iov_iter_extraction_t;
struct kvec {
void *iov_base; /* and that should *never* hold a userland pointer */
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ u32 __pad1;
+#endif
size_t iov_len;
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ u32 __pad2;
+#endif
};
enum iter_type {
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 29/43] rv64ilp32_abi: locking/atomic: Use BITS_PER_LONG for scripts
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (27 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 28/43] rv64ilp32_abi: iov_iter: Resize kvec to match iov_iter's size guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 30/43] rv64ilp32_abi: kernel/smp: Disable CSD_LOCK_WAIT_DEBUG guoren
` (15 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
In RV64ILP32 ABI systems, BITS_PER_LONG equals 32 and determines
code selection, not CONFIG_64BIT.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/atomic/atomic-long.h | 174 ++++++++++++++---------------
scripts/atomic/gen-atomic-long.sh | 4 +-
2 files changed, 89 insertions(+), 89 deletions(-)
diff --git a/include/linux/atomic/atomic-long.h b/include/linux/atomic/atomic-long.h
index f86b29d90877..e31e0bdf9e26 100644
--- a/include/linux/atomic/atomic-long.h
+++ b/include/linux/atomic/atomic-long.h
@@ -9,7 +9,7 @@
#include <linux/compiler.h>
#include <asm/types.h>
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
typedef atomic64_t atomic_long_t;
#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
#define atomic_long_cond_read_acquire atomic64_cond_read_acquire
@@ -34,7 +34,7 @@ typedef atomic_t atomic_long_t;
static __always_inline long
raw_atomic_long_read(const atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_read(v);
#else
return raw_atomic_read(v);
@@ -54,7 +54,7 @@ raw_atomic_long_read(const atomic_long_t *v)
static __always_inline long
raw_atomic_long_read_acquire(const atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_read_acquire(v);
#else
return raw_atomic_read_acquire(v);
@@ -75,7 +75,7 @@ raw_atomic_long_read_acquire(const atomic_long_t *v)
static __always_inline void
raw_atomic_long_set(atomic_long_t *v, long i)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_set(v, i);
#else
raw_atomic_set(v, i);
@@ -96,7 +96,7 @@ raw_atomic_long_set(atomic_long_t *v, long i)
static __always_inline void
raw_atomic_long_set_release(atomic_long_t *v, long i)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_set_release(v, i);
#else
raw_atomic_set_release(v, i);
@@ -117,7 +117,7 @@ raw_atomic_long_set_release(atomic_long_t *v, long i)
static __always_inline void
raw_atomic_long_add(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_add(i, v);
#else
raw_atomic_add(i, v);
@@ -138,7 +138,7 @@ raw_atomic_long_add(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_add_return(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_return(i, v);
#else
return raw_atomic_add_return(i, v);
@@ -159,7 +159,7 @@ raw_atomic_long_add_return(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_add_return_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_return_acquire(i, v);
#else
return raw_atomic_add_return_acquire(i, v);
@@ -180,7 +180,7 @@ raw_atomic_long_add_return_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_add_return_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_return_release(i, v);
#else
return raw_atomic_add_return_release(i, v);
@@ -201,7 +201,7 @@ raw_atomic_long_add_return_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_add_return_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_return_relaxed(i, v);
#else
return raw_atomic_add_return_relaxed(i, v);
@@ -222,7 +222,7 @@ raw_atomic_long_add_return_relaxed(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_add(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_add(i, v);
#else
return raw_atomic_fetch_add(i, v);
@@ -243,7 +243,7 @@ raw_atomic_long_fetch_add(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_add_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_add_acquire(i, v);
#else
return raw_atomic_fetch_add_acquire(i, v);
@@ -264,7 +264,7 @@ raw_atomic_long_fetch_add_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_add_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_add_release(i, v);
#else
return raw_atomic_fetch_add_release(i, v);
@@ -285,7 +285,7 @@ raw_atomic_long_fetch_add_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_add_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_add_relaxed(i, v);
#else
return raw_atomic_fetch_add_relaxed(i, v);
@@ -306,7 +306,7 @@ raw_atomic_long_fetch_add_relaxed(long i, atomic_long_t *v)
static __always_inline void
raw_atomic_long_sub(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_sub(i, v);
#else
raw_atomic_sub(i, v);
@@ -327,7 +327,7 @@ raw_atomic_long_sub(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_sub_return(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_sub_return(i, v);
#else
return raw_atomic_sub_return(i, v);
@@ -348,7 +348,7 @@ raw_atomic_long_sub_return(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_sub_return_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_sub_return_acquire(i, v);
#else
return raw_atomic_sub_return_acquire(i, v);
@@ -369,7 +369,7 @@ raw_atomic_long_sub_return_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_sub_return_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_sub_return_release(i, v);
#else
return raw_atomic_sub_return_release(i, v);
@@ -390,7 +390,7 @@ raw_atomic_long_sub_return_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_sub_return_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_sub_return_relaxed(i, v);
#else
return raw_atomic_sub_return_relaxed(i, v);
@@ -411,7 +411,7 @@ raw_atomic_long_sub_return_relaxed(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_sub(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_sub(i, v);
#else
return raw_atomic_fetch_sub(i, v);
@@ -432,7 +432,7 @@ raw_atomic_long_fetch_sub(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_sub_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_sub_acquire(i, v);
#else
return raw_atomic_fetch_sub_acquire(i, v);
@@ -453,7 +453,7 @@ raw_atomic_long_fetch_sub_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_sub_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_sub_release(i, v);
#else
return raw_atomic_fetch_sub_release(i, v);
@@ -474,7 +474,7 @@ raw_atomic_long_fetch_sub_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_sub_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_sub_relaxed(i, v);
#else
return raw_atomic_fetch_sub_relaxed(i, v);
@@ -494,7 +494,7 @@ raw_atomic_long_fetch_sub_relaxed(long i, atomic_long_t *v)
static __always_inline void
raw_atomic_long_inc(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_inc(v);
#else
raw_atomic_inc(v);
@@ -514,7 +514,7 @@ raw_atomic_long_inc(atomic_long_t *v)
static __always_inline long
raw_atomic_long_inc_return(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_return(v);
#else
return raw_atomic_inc_return(v);
@@ -534,7 +534,7 @@ raw_atomic_long_inc_return(atomic_long_t *v)
static __always_inline long
raw_atomic_long_inc_return_acquire(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_return_acquire(v);
#else
return raw_atomic_inc_return_acquire(v);
@@ -554,7 +554,7 @@ raw_atomic_long_inc_return_acquire(atomic_long_t *v)
static __always_inline long
raw_atomic_long_inc_return_release(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_return_release(v);
#else
return raw_atomic_inc_return_release(v);
@@ -574,7 +574,7 @@ raw_atomic_long_inc_return_release(atomic_long_t *v)
static __always_inline long
raw_atomic_long_inc_return_relaxed(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_return_relaxed(v);
#else
return raw_atomic_inc_return_relaxed(v);
@@ -594,7 +594,7 @@ raw_atomic_long_inc_return_relaxed(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_inc(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_inc(v);
#else
return raw_atomic_fetch_inc(v);
@@ -614,7 +614,7 @@ raw_atomic_long_fetch_inc(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_inc_acquire(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_inc_acquire(v);
#else
return raw_atomic_fetch_inc_acquire(v);
@@ -634,7 +634,7 @@ raw_atomic_long_fetch_inc_acquire(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_inc_release(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_inc_release(v);
#else
return raw_atomic_fetch_inc_release(v);
@@ -654,7 +654,7 @@ raw_atomic_long_fetch_inc_release(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_inc_relaxed(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_inc_relaxed(v);
#else
return raw_atomic_fetch_inc_relaxed(v);
@@ -674,7 +674,7 @@ raw_atomic_long_fetch_inc_relaxed(atomic_long_t *v)
static __always_inline void
raw_atomic_long_dec(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_dec(v);
#else
raw_atomic_dec(v);
@@ -694,7 +694,7 @@ raw_atomic_long_dec(atomic_long_t *v)
static __always_inline long
raw_atomic_long_dec_return(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_return(v);
#else
return raw_atomic_dec_return(v);
@@ -714,7 +714,7 @@ raw_atomic_long_dec_return(atomic_long_t *v)
static __always_inline long
raw_atomic_long_dec_return_acquire(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_return_acquire(v);
#else
return raw_atomic_dec_return_acquire(v);
@@ -734,7 +734,7 @@ raw_atomic_long_dec_return_acquire(atomic_long_t *v)
static __always_inline long
raw_atomic_long_dec_return_release(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_return_release(v);
#else
return raw_atomic_dec_return_release(v);
@@ -754,7 +754,7 @@ raw_atomic_long_dec_return_release(atomic_long_t *v)
static __always_inline long
raw_atomic_long_dec_return_relaxed(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_return_relaxed(v);
#else
return raw_atomic_dec_return_relaxed(v);
@@ -774,7 +774,7 @@ raw_atomic_long_dec_return_relaxed(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_dec(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_dec(v);
#else
return raw_atomic_fetch_dec(v);
@@ -794,7 +794,7 @@ raw_atomic_long_fetch_dec(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_dec_acquire(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_dec_acquire(v);
#else
return raw_atomic_fetch_dec_acquire(v);
@@ -814,7 +814,7 @@ raw_atomic_long_fetch_dec_acquire(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_dec_release(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_dec_release(v);
#else
return raw_atomic_fetch_dec_release(v);
@@ -834,7 +834,7 @@ raw_atomic_long_fetch_dec_release(atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_dec_relaxed(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_dec_relaxed(v);
#else
return raw_atomic_fetch_dec_relaxed(v);
@@ -855,7 +855,7 @@ raw_atomic_long_fetch_dec_relaxed(atomic_long_t *v)
static __always_inline void
raw_atomic_long_and(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_and(i, v);
#else
raw_atomic_and(i, v);
@@ -876,7 +876,7 @@ raw_atomic_long_and(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_and(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_and(i, v);
#else
return raw_atomic_fetch_and(i, v);
@@ -897,7 +897,7 @@ raw_atomic_long_fetch_and(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_and_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_and_acquire(i, v);
#else
return raw_atomic_fetch_and_acquire(i, v);
@@ -918,7 +918,7 @@ raw_atomic_long_fetch_and_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_and_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_and_release(i, v);
#else
return raw_atomic_fetch_and_release(i, v);
@@ -939,7 +939,7 @@ raw_atomic_long_fetch_and_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_and_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_and_relaxed(i, v);
#else
return raw_atomic_fetch_and_relaxed(i, v);
@@ -960,7 +960,7 @@ raw_atomic_long_fetch_and_relaxed(long i, atomic_long_t *v)
static __always_inline void
raw_atomic_long_andnot(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_andnot(i, v);
#else
raw_atomic_andnot(i, v);
@@ -981,7 +981,7 @@ raw_atomic_long_andnot(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_andnot(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_andnot(i, v);
#else
return raw_atomic_fetch_andnot(i, v);
@@ -1002,7 +1002,7 @@ raw_atomic_long_fetch_andnot(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_andnot_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_andnot_acquire(i, v);
#else
return raw_atomic_fetch_andnot_acquire(i, v);
@@ -1023,7 +1023,7 @@ raw_atomic_long_fetch_andnot_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_andnot_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_andnot_release(i, v);
#else
return raw_atomic_fetch_andnot_release(i, v);
@@ -1044,7 +1044,7 @@ raw_atomic_long_fetch_andnot_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_andnot_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_andnot_relaxed(i, v);
#else
return raw_atomic_fetch_andnot_relaxed(i, v);
@@ -1065,7 +1065,7 @@ raw_atomic_long_fetch_andnot_relaxed(long i, atomic_long_t *v)
static __always_inline void
raw_atomic_long_or(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_or(i, v);
#else
raw_atomic_or(i, v);
@@ -1086,7 +1086,7 @@ raw_atomic_long_or(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_or(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_or(i, v);
#else
return raw_atomic_fetch_or(i, v);
@@ -1107,7 +1107,7 @@ raw_atomic_long_fetch_or(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_or_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_or_acquire(i, v);
#else
return raw_atomic_fetch_or_acquire(i, v);
@@ -1128,7 +1128,7 @@ raw_atomic_long_fetch_or_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_or_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_or_release(i, v);
#else
return raw_atomic_fetch_or_release(i, v);
@@ -1149,7 +1149,7 @@ raw_atomic_long_fetch_or_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_or_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_or_relaxed(i, v);
#else
return raw_atomic_fetch_or_relaxed(i, v);
@@ -1170,7 +1170,7 @@ raw_atomic_long_fetch_or_relaxed(long i, atomic_long_t *v)
static __always_inline void
raw_atomic_long_xor(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
raw_atomic64_xor(i, v);
#else
raw_atomic_xor(i, v);
@@ -1191,7 +1191,7 @@ raw_atomic_long_xor(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_xor(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_xor(i, v);
#else
return raw_atomic_fetch_xor(i, v);
@@ -1212,7 +1212,7 @@ raw_atomic_long_fetch_xor(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_xor_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_xor_acquire(i, v);
#else
return raw_atomic_fetch_xor_acquire(i, v);
@@ -1233,7 +1233,7 @@ raw_atomic_long_fetch_xor_acquire(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_xor_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_xor_release(i, v);
#else
return raw_atomic_fetch_xor_release(i, v);
@@ -1254,7 +1254,7 @@ raw_atomic_long_fetch_xor_release(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_xor_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_xor_relaxed(i, v);
#else
return raw_atomic_fetch_xor_relaxed(i, v);
@@ -1275,7 +1275,7 @@ raw_atomic_long_fetch_xor_relaxed(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_xchg(atomic_long_t *v, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_xchg(v, new);
#else
return raw_atomic_xchg(v, new);
@@ -1296,7 +1296,7 @@ raw_atomic_long_xchg(atomic_long_t *v, long new)
static __always_inline long
raw_atomic_long_xchg_acquire(atomic_long_t *v, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_xchg_acquire(v, new);
#else
return raw_atomic_xchg_acquire(v, new);
@@ -1317,7 +1317,7 @@ raw_atomic_long_xchg_acquire(atomic_long_t *v, long new)
static __always_inline long
raw_atomic_long_xchg_release(atomic_long_t *v, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_xchg_release(v, new);
#else
return raw_atomic_xchg_release(v, new);
@@ -1338,7 +1338,7 @@ raw_atomic_long_xchg_release(atomic_long_t *v, long new)
static __always_inline long
raw_atomic_long_xchg_relaxed(atomic_long_t *v, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_xchg_relaxed(v, new);
#else
return raw_atomic_xchg_relaxed(v, new);
@@ -1361,7 +1361,7 @@ raw_atomic_long_xchg_relaxed(atomic_long_t *v, long new)
static __always_inline long
raw_atomic_long_cmpxchg(atomic_long_t *v, long old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_cmpxchg(v, old, new);
#else
return raw_atomic_cmpxchg(v, old, new);
@@ -1384,7 +1384,7 @@ raw_atomic_long_cmpxchg(atomic_long_t *v, long old, long new)
static __always_inline long
raw_atomic_long_cmpxchg_acquire(atomic_long_t *v, long old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_cmpxchg_acquire(v, old, new);
#else
return raw_atomic_cmpxchg_acquire(v, old, new);
@@ -1407,7 +1407,7 @@ raw_atomic_long_cmpxchg_acquire(atomic_long_t *v, long old, long new)
static __always_inline long
raw_atomic_long_cmpxchg_release(atomic_long_t *v, long old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_cmpxchg_release(v, old, new);
#else
return raw_atomic_cmpxchg_release(v, old, new);
@@ -1430,7 +1430,7 @@ raw_atomic_long_cmpxchg_release(atomic_long_t *v, long old, long new)
static __always_inline long
raw_atomic_long_cmpxchg_relaxed(atomic_long_t *v, long old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_cmpxchg_relaxed(v, old, new);
#else
return raw_atomic_cmpxchg_relaxed(v, old, new);
@@ -1454,7 +1454,7 @@ raw_atomic_long_cmpxchg_relaxed(atomic_long_t *v, long old, long new)
static __always_inline bool
raw_atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_try_cmpxchg(v, (s64 *)old, new);
#else
return raw_atomic_try_cmpxchg(v, (int *)old, new);
@@ -1478,7 +1478,7 @@ raw_atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)
static __always_inline bool
raw_atomic_long_try_cmpxchg_acquire(atomic_long_t *v, long *old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_try_cmpxchg_acquire(v, (s64 *)old, new);
#else
return raw_atomic_try_cmpxchg_acquire(v, (int *)old, new);
@@ -1502,7 +1502,7 @@ raw_atomic_long_try_cmpxchg_acquire(atomic_long_t *v, long *old, long new)
static __always_inline bool
raw_atomic_long_try_cmpxchg_release(atomic_long_t *v, long *old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_try_cmpxchg_release(v, (s64 *)old, new);
#else
return raw_atomic_try_cmpxchg_release(v, (int *)old, new);
@@ -1526,7 +1526,7 @@ raw_atomic_long_try_cmpxchg_release(atomic_long_t *v, long *old, long new)
static __always_inline bool
raw_atomic_long_try_cmpxchg_relaxed(atomic_long_t *v, long *old, long new)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_try_cmpxchg_relaxed(v, (s64 *)old, new);
#else
return raw_atomic_try_cmpxchg_relaxed(v, (int *)old, new);
@@ -1547,7 +1547,7 @@ raw_atomic_long_try_cmpxchg_relaxed(atomic_long_t *v, long *old, long new)
static __always_inline bool
raw_atomic_long_sub_and_test(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_sub_and_test(i, v);
#else
return raw_atomic_sub_and_test(i, v);
@@ -1567,7 +1567,7 @@ raw_atomic_long_sub_and_test(long i, atomic_long_t *v)
static __always_inline bool
raw_atomic_long_dec_and_test(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_and_test(v);
#else
return raw_atomic_dec_and_test(v);
@@ -1587,7 +1587,7 @@ raw_atomic_long_dec_and_test(atomic_long_t *v)
static __always_inline bool
raw_atomic_long_inc_and_test(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_and_test(v);
#else
return raw_atomic_inc_and_test(v);
@@ -1608,7 +1608,7 @@ raw_atomic_long_inc_and_test(atomic_long_t *v)
static __always_inline bool
raw_atomic_long_add_negative(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_negative(i, v);
#else
return raw_atomic_add_negative(i, v);
@@ -1629,7 +1629,7 @@ raw_atomic_long_add_negative(long i, atomic_long_t *v)
static __always_inline bool
raw_atomic_long_add_negative_acquire(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_negative_acquire(i, v);
#else
return raw_atomic_add_negative_acquire(i, v);
@@ -1650,7 +1650,7 @@ raw_atomic_long_add_negative_acquire(long i, atomic_long_t *v)
static __always_inline bool
raw_atomic_long_add_negative_release(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_negative_release(i, v);
#else
return raw_atomic_add_negative_release(i, v);
@@ -1671,7 +1671,7 @@ raw_atomic_long_add_negative_release(long i, atomic_long_t *v)
static __always_inline bool
raw_atomic_long_add_negative_relaxed(long i, atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_negative_relaxed(i, v);
#else
return raw_atomic_add_negative_relaxed(i, v);
@@ -1694,7 +1694,7 @@ raw_atomic_long_add_negative_relaxed(long i, atomic_long_t *v)
static __always_inline long
raw_atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_fetch_add_unless(v, a, u);
#else
return raw_atomic_fetch_add_unless(v, a, u);
@@ -1717,7 +1717,7 @@ raw_atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u)
static __always_inline bool
raw_atomic_long_add_unless(atomic_long_t *v, long a, long u)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_add_unless(v, a, u);
#else
return raw_atomic_add_unless(v, a, u);
@@ -1738,7 +1738,7 @@ raw_atomic_long_add_unless(atomic_long_t *v, long a, long u)
static __always_inline bool
raw_atomic_long_inc_not_zero(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_not_zero(v);
#else
return raw_atomic_inc_not_zero(v);
@@ -1759,7 +1759,7 @@ raw_atomic_long_inc_not_zero(atomic_long_t *v)
static __always_inline bool
raw_atomic_long_inc_unless_negative(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_inc_unless_negative(v);
#else
return raw_atomic_inc_unless_negative(v);
@@ -1780,7 +1780,7 @@ raw_atomic_long_inc_unless_negative(atomic_long_t *v)
static __always_inline bool
raw_atomic_long_dec_unless_positive(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_unless_positive(v);
#else
return raw_atomic_dec_unless_positive(v);
@@ -1801,7 +1801,7 @@ raw_atomic_long_dec_unless_positive(atomic_long_t *v)
static __always_inline long
raw_atomic_long_dec_if_positive(atomic_long_t *v)
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return raw_atomic64_dec_if_positive(v);
#else
return raw_atomic_dec_if_positive(v);
@@ -1809,4 +1809,4 @@ raw_atomic_long_dec_if_positive(atomic_long_t *v)
}
#endif /* _LINUX_ATOMIC_LONG_H */
-// eadf183c3600b8b92b91839dd3be6bcc560c752d
+// 1b27315f1248fc8d43401372db7dd5895889c5be
diff --git a/scripts/atomic/gen-atomic-long.sh b/scripts/atomic/gen-atomic-long.sh
index 9826be3ba986..7667305381fc 100755
--- a/scripts/atomic/gen-atomic-long.sh
+++ b/scripts/atomic/gen-atomic-long.sh
@@ -55,7 +55,7 @@ cat <<EOF
static __always_inline ${ret}
raw_atomic_long_${atomicname}(${params})
{
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
${retstmt}raw_atomic64_${atomicname}(${argscast_64});
#else
${retstmt}raw_atomic_${atomicname}(${argscast_32});
@@ -77,7 +77,7 @@ cat << EOF
#include <linux/compiler.h>
#include <asm/types.h>
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
typedef atomic64_t atomic_long_t;
#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
#define atomic_long_cond_read_acquire atomic64_cond_read_acquire
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 30/43] rv64ilp32_abi: kernel/smp: Disable CSD_LOCK_WAIT_DEBUG
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (28 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 29/43] rv64ilp32_abi: locking/atomic: Use BITS_PER_LONG for scripts guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
` (14 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 abi is based on CONFIG_64BIT, but uses ILP32 for a
smaller cache & memory footprint. So, disable CSD_LOCK_WAIT_DEBUG
to get smaller csd struct.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/smp_types.h | 2 +-
lib/Kconfig.debug | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/smp_types.h b/include/linux/smp_types.h
index 2e8461af8df6..5912b694059f 100644
--- a/include/linux/smp_types.h
+++ b/include/linux/smp_types.h
@@ -61,7 +61,7 @@ struct __call_single_node {
unsigned int u_flags;
atomic_t a_flags;
};
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
u16 src, dst;
#endif
};
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1af972a92d06..f55f0ded826c 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1613,6 +1613,7 @@ config CSD_LOCK_WAIT_DEBUG
depends on DEBUG_KERNEL
depends on SMP
depends on 64BIT
+ depends on !ABI_RV64ILP32
default n
help
This option enables debug prints when CPUs are slow to respond
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (29 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 30/43] rv64ilp32_abi: kernel/smp: Disable CSD_LOCK_WAIT_DEBUG guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 19:09 ` Liam R. Howlett
2025-03-25 12:16 ` [RFC PATCH V3 32/43] rv64ilp32_abi: mm: Remove _folio_nr_pages guoren
` (13 subsequent siblings)
44 siblings, 1 reply; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The Maple tree algorithm uses ulong type for each element. The
number of slots is based on BITS_PER_LONG for RV64ILP32 ABI, so
use BITS_PER_LONG instead of CONFIG_64BIT.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/maple_tree.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h
index cbbcd18d4186..ff6265b6468b 100644
--- a/include/linux/maple_tree.h
+++ b/include/linux/maple_tree.h
@@ -24,7 +24,7 @@
*
* Nodes in the tree point to their parent unless bit 0 is set.
*/
-#if defined(CONFIG_64BIT) || defined(BUILD_VDSO32_64)
+#if (BITS_PER_LONG == 64) || defined(BUILD_VDSO32_64)
/* 64bit sizes */
#define MAPLE_NODE_SLOTS 31 /* 256 bytes including ->parent */
#define MAPLE_RANGE64_SLOTS 16 /* 256 bytes */
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 32/43] rv64ilp32_abi: mm: Remove _folio_nr_pages
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (30 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 33/43] rv64ilp32_abi: mm/auxvec: Adapt mm->saved_auxv[] to Elf64 guoren
` (12 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
BITS_PER_LONG defines the layout of the struct page, and
_folio_nr_pages would conflict with page->_mapcount for RV64ILP32
ABI. Here is problem:
BUG: Bad page state in process kworker/u4:0 pfn:61eed
page: refcount:0 mapcount:5 mapping:00000000 index:0x0 pfn:0x61eed
flags: 0x0(zone=0)
raw: 00000000 00000000 ffffffff 00000000 00000000 00000000 00000004 00000000
raw: 00000000 00000000
page dumped because: nonzero mapcount
Modules linked in:
CPU: 0 UID: 0 PID: 11 Comm: kworker/u4:0 Not tainted 6.13.0-rc4
Hardware name: riscv-virtio,qemu (DT)
Workqueue: async async_run_entry_fn
Call Trace:
[<bc015096>] dump_backtrace+0x1e/0x26
[<bc002330>] show_stack+0x2a/0x38
[<bc00f38c>] dump_stack_lvl+0x4a/0x68
[<bc00f3c0>] dump_stack+0x16/0x1e
[<bc1cadd8>] bad_page+0x120/0x142
[<bc1cf2c2>] free_unref_page+0x510/0x5f8
[<bc17fb16>] __folio_put+0x6a/0xbc
[<bc1d6090>] free_large_kmalloc+0x6a/0xb8
[<bc1d9144>] kfree+0x23c/0x300
[<bcc02834>] unpack_to_rootfs+0x27c/0x2c0
[<bcc02e96>] do_populate_rootfs+0x24/0x12e
[<bc04c80c>] async_run_entry_fn+0x26/0xcc
[<bc03e116>] process_one_work+0x136/0x224
[<bc03e9e4>] worker_thread+0x234/0x30a
[<bc046334>] kthread+0xca/0xe6
[<bca47bea>] ret_from_fork+0xe/0x18
Disabling lock debugging due to kernel taint
So, remove _folio_nr_pages just like CONFIG_32BIT and use
"_flags_1 & 0xff" instead.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/mm.h | 4 ++--
include/linux/mm_types.h | 2 +-
mm/internal.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7b1068ddcbb7..454fb8ca724c 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2058,7 +2058,7 @@ static inline long folio_nr_pages(const struct folio *folio)
{
if (!folio_test_large(folio))
return 1;
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return folio->_folio_nr_pages;
#else
return 1L << (folio->_flags_1 & 0xff);
@@ -2083,7 +2083,7 @@ static inline unsigned long compound_nr(struct page *page)
if (!test_bit(PG_head, &folio->flags))
return 1;
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
return folio->_folio_nr_pages;
#else
return 1L << (folio->_flags_1 & 0xff);
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 6b27db7f9496..da3ba1a79ad5 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -370,7 +370,7 @@ struct folio {
atomic_t _entire_mapcount;
atomic_t _nr_pages_mapped;
atomic_t _pincount;
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
unsigned int _folio_nr_pages;
#endif
/* private: the union with struct page is transitional */
diff --git a/mm/internal.h b/mm/internal.h
index 109ef30fee11..c9372a8552ba 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -682,7 +682,7 @@ static inline void folio_set_order(struct folio *folio, unsigned int order)
return;
folio->_flags_1 = (folio->_flags_1 & ~0xffUL) | order;
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
folio->_folio_nr_pages = 1U << order;
#endif
}
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 33/43] rv64ilp32_abi: mm/auxvec: Adapt mm->saved_auxv[] to Elf64
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (31 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 32/43] rv64ilp32_abi: mm: Remove _folio_nr_pages guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 34/43] rv64ilp32_abi: mm: Adapt vm_flags_t struct guoren
` (11 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
Unable to handle kernel paging request at virtual address 60723de0
Oops [#1]
Modules linked in:
CPU: 0 UID: 0 PID: 1 Comm: init Not tainted 6.13.0-rc4-00031-g01dc3ca797b3-dirty #161
Hardware name: riscv-virtio,qemu (DT)
epc : percpu_counter_add_batch+0x38/0xc4
ra : filemap_map_pages+0x3ec/0x54c
epc : ffffffffbc4ea02e ra : ffffffffbc1722e4 sp : ffffffffc1c4fc60
gp : ffffffffbd6d3918 tp : ffffffffc1c50000 t0 : 0000000000000000
t1 : 000000003fffefff t2 : 0000000000000000 s0 : ffffffffc1c4fca0
s1 : 0000000000000022 a0 : ffffffffc25c8250 a1 : 0000000000000003
a2 : 0000000000000020 a3 : 000000003fffefff a4 : 000000000b1c2000
a5 : 0000000060723de0 a6 : ffffffffbffff000 a7 : 000000003fffffff
s2 : ffffffffc25c8250 s3 : ffffffffc246e240 s4 : ffffffffc2138240
s5 : ffffffffbd70c4d0 s6 : 0000000000000003 s7 : 0000000000000000
s8 : ffffffff9a02d780 s9 : 0000000000000100 s10: ffffffffc1c4fda8
s11: 0000000000000003 t3 : 0000000000000000 t4 : 00000000000004f7
t5 : 0000000000000000 t6 : 0000000000000001
status: 0000000200000100 badaddr: 0000000060723de0 cause: 000000000000000d
[<bc4ea02e>] percpu_counter_add_batch+0x38/0xc4
[<bc1722e4>] filemap_map_pages+0x3ec/0x54c
[<bc1adc86>] handle_mm_fault+0xb6c/0xe9c
[<bc01bb3e>] handle_page_fault+0xd0/0x418
[<bca3e264>] do_page_fault+0x20/0x3a
[<bca4882c>] _new_vmalloc_restore_context_a0+0xb0/0xbc
Code: 8a93 4baa 511c 171b 0027 873b 00ea 4318 2481 9fb9 (aa03) 0007
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/mm_types.h | 4 ++++
kernel/sys.c | 8 ++++++++
2 files changed, 12 insertions(+)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index da3ba1a79ad5..0d436b0217fd 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -962,7 +962,11 @@ struct mm_struct {
unsigned long start_brk, brk, start_stack;
unsigned long arg_start, arg_end, env_start, env_end;
+#ifdef CONFIG_64BIT
+ unsigned long long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
+#else
unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
+#endif
struct percpu_counter rss_stat[NR_MM_COUNTERS];
diff --git a/kernel/sys.c b/kernel/sys.c
index cb366ff8703a..81c0d94ff50d 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2008,7 +2008,11 @@ static int validate_prctl_map_addr(struct prctl_mm_map *prctl_map)
static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data_size)
{
struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, };
+#ifdef CONFIG_64BIT
+ unsigned long long user_auxv[AT_VECTOR_SIZE];
+#else
unsigned long user_auxv[AT_VECTOR_SIZE];
+#endif
struct mm_struct *mm = current->mm;
int error;
@@ -2122,7 +2126,11 @@ static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr,
* up to the caller to provide sane values here, otherwise userspace
* tools which use this vector might be unhappy.
*/
+#ifdef CONFIG_64BIT
+ unsigned long long user_auxv[AT_VECTOR_SIZE] = {};
+#else
unsigned long user_auxv[AT_VECTOR_SIZE] = {};
+#endif
if (len > sizeof(user_auxv))
return -EINVAL;
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 34/43] rv64ilp32_abi: mm: Adapt vm_flags_t struct
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (32 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 33/43] rv64ilp32_abi: mm/auxvec: Adapt mm->saved_auxv[] to Elf64 guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 35/43] rv64ilp32_abi: net: Use BITS_PER_LONG in struct dst_entry guoren
` (10 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
RV64ILP32 ABI linux kernel is based on CONFIG_64BIT, so uses
unsigned long long as vm_flags struct type.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
fs/proc/task_mmu.c | 9 +++++++--
include/linux/mm.h | 10 +++++++---
include/linux/mm_types.h | 4 ++++
mm/debug.c | 4 ++++
mm/memory.c | 4 ++++
5 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index f02cd362309a..6c4eaba794da 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -905,6 +905,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
return 0;
}
+#ifdef CONFIG_64BIT
+#define MNEMONICS_SZ 64
+#else
+#define MNEMONICS_SZ 32
+#endif
static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
{
/*
@@ -917,11 +922,11 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
* -Werror=unterminated-string-initialization warning
* with GCC 15
*/
- static const char mnemonics[BITS_PER_LONG][3] = {
+ static const char mnemonics[MNEMONICS_SZ][3] = {
/*
* In case if we meet a flag we don't know about.
*/
- [0 ... (BITS_PER_LONG-1)] = "??",
+ [0 ... (MNEMONICS_SZ-1)] = "??",
[ilog2(VM_READ)] = "rd",
[ilog2(VM_WRITE)] = "wr",
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 454fb8ca724c..d9735cd7efe9 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -412,7 +412,11 @@ extern unsigned int kobjsize(const void *objp);
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR
# define VM_UFFD_MINOR_BIT 38
+#ifdef CONFIG_64BIT
+# define VM_UFFD_MINOR BIT_ULL(VM_UFFD_MINOR_BIT) /* UFFD minor faults */
+#else
# define VM_UFFD_MINOR BIT(VM_UFFD_MINOR_BIT) /* UFFD minor faults */
+#endif
#else /* !CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */
# define VM_UFFD_MINOR VM_NONE
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */
@@ -426,14 +430,14 @@ extern unsigned int kobjsize(const void *objp);
*/
#ifdef CONFIG_64BIT
#define VM_ALLOW_ANY_UNCACHED_BIT 39
-#define VM_ALLOW_ANY_UNCACHED BIT(VM_ALLOW_ANY_UNCACHED_BIT)
+#define VM_ALLOW_ANY_UNCACHED BIT_ULL(VM_ALLOW_ANY_UNCACHED_BIT)
#else
#define VM_ALLOW_ANY_UNCACHED VM_NONE
#endif
#ifdef CONFIG_64BIT
#define VM_DROPPABLE_BIT 40
-#define VM_DROPPABLE BIT(VM_DROPPABLE_BIT)
+#define VM_DROPPABLE BIT_ULL(VM_DROPPABLE_BIT)
#elif defined(CONFIG_PPC32)
#define VM_DROPPABLE VM_ARCH_1
#else
@@ -442,7 +446,7 @@ extern unsigned int kobjsize(const void *objp);
#ifdef CONFIG_64BIT
/* VM is sealed, in vm_flags */
-#define VM_SEALED _BITUL(63)
+#define VM_SEALED _BITULL(63)
#endif
/* Bits set in the VMA until the stack is in its final location */
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 0d436b0217fd..900665c5eca8 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -571,7 +571,11 @@ static inline void *folio_get_private(struct folio *folio)
return folio->private;
}
+#ifdef CONFIG_64BIT
+typedef unsigned long long vm_flags_t;
+#else
typedef unsigned long vm_flags_t;
+#endif
/*
* A region containing a mapping of a non-memory backed file under NOMMU
diff --git a/mm/debug.c b/mm/debug.c
index 8d2acf432385..0fcb85e6efea 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -181,7 +181,11 @@ void dump_vma(const struct vm_area_struct *vma)
pr_emerg("vma %px start %px end %px mm %px\n"
"prot %lx anon_vma %px vm_ops %px\n"
"pgoff %lx file %px private_data %px\n"
+#ifdef CONFIG_64BIT
+ "flags: %#llx(%pGv)\n",
+#else
"flags: %#lx(%pGv)\n",
+#endif
vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm,
(unsigned long)pgprot_val(vma->vm_page_prot),
vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
diff --git a/mm/memory.c b/mm/memory.c
index 539c0f7c6d54..3c4a9663c094 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -533,7 +533,11 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
(long long)pte_val(pte), (long long)pmd_val(*pmd));
if (page)
dump_page(page, "bad pte");
+#ifdef CONFIG_64BIT
+ pr_alert("addr:%px vm_flags:%08llx anon_vma:%px mapping:%px index:%lx\n",
+#else
pr_alert("addr:%px vm_flags:%08lx anon_vma:%px mapping:%px index:%lx\n",
+#endif
(void *)addr, vma->vm_flags, vma->anon_vma, mapping, index);
pr_alert("file:%pD fault:%ps mmap:%ps read_folio:%ps\n",
vma->vm_file,
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 35/43] rv64ilp32_abi: net: Use BITS_PER_LONG in struct dst_entry
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (33 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 34/43] rv64ilp32_abi: mm: Adapt vm_flags_t struct guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 36/43] rv64ilp32_abi: printf: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
` (9 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 ABI depends on CONFIG_64BIT for its ILP32 data type,
which is smaller. To align with ILP32 requirements, CONFIG_64BIT
was changed to BITS_PER_LONG in struct dts_entry.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/net/dst.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/net/dst.h b/include/net/dst.h
index 78c78cdce0e9..af1c74c4836e 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -65,7 +65,7 @@ struct dst_entry {
* __rcuref wants to be on a different cache line from
* input/output/ops or performance tanks badly
*/
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
rcuref_t __rcuref; /* 64-bit offset 64 */
#endif
int __use;
@@ -74,7 +74,7 @@ struct dst_entry {
short error;
short __pad;
__u32 tclassid;
-#ifndef CONFIG_64BIT
+#if BITS_PER_LONG == 32
struct lwtunnel_state *lwtstate;
rcuref_t __rcuref; /* 32-bit offset 64 */
#endif
@@ -89,7 +89,7 @@ struct dst_entry {
*/
struct list_head rt_uncached;
struct uncached_list *rt_uncached_list;
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
struct lwtunnel_state *lwtstate;
#endif
};
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 36/43] rv64ilp32_abi: printf: Use BITS_PER_LONG instead of CONFIG_64BIT
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (34 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 35/43] rv64ilp32_abi: net: Use BITS_PER_LONG in struct dst_entry guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 37/43] rv64ilp32_abi: random: Adapt fast_pool struct guoren
` (8 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
RV64ILP32 ABI systems have BITS_PER_LONG set to 32. Use
BITS_PER_LONG instead of CONFIG_64BIT.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
lib/vsprintf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 56fe96319292..2d719be86945 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -771,7 +771,7 @@ static inline int __ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
/* Pairs with smp_wmb() after writing ptr_key. */
smp_rmb();
-#ifdef CONFIG_64BIT
+#if BITS_PER_LONG == 64
hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
/*
* Mask off the first 32 bits, this makes explicit that we have
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 37/43] rv64ilp32_abi: random: Adapt fast_pool struct
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (35 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 36/43] rv64ilp32_abi: printf: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 38/43] rv64ilp32_abi: syscall: Use CONFIG_64BIT instead of BITS_PER_LONG guoren
` (7 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
RV64ILP32 ABI systems have BITS_PER_LONG set to 32, matching
sizeof(compat_ulong_t). Adjust code
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
drivers/char/random.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 2581186fa61b..0bfbe02ee255 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1015,7 +1015,11 @@ EXPORT_SYMBOL_GPL(unregister_random_vmfork_notifier);
#endif
struct fast_pool {
+#ifdef CONFIG_64BIT
+ u64 pool[4];
+#else
unsigned long pool[4];
+#endif
unsigned long last;
unsigned int count;
struct timer_list mix;
@@ -1040,7 +1044,11 @@ static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = {
* and therefore this has no security on its own. s represents the
* four-word SipHash state, while v represents a two-word input.
*/
+#ifdef CONFIG_64BIT
+static void fast_mix(u64 s[4], u64 v1, u64 v2)
+#else
static void fast_mix(unsigned long s[4], unsigned long v1, unsigned long v2)
+#endif
{
s[3] ^= v1;
FASTMIX_PERM(s[0], s[1], s[2], s[3]);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 38/43] rv64ilp32_abi: syscall: Use CONFIG_64BIT instead of BITS_PER_LONG
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (36 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 37/43] rv64ilp32_abi: random: Adapt fast_pool struct guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 39/43] rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi guoren
` (6 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI adopts the syscall rules from CONFIG_64BIT and
directly uses 64BIT, replacing BITS_PER_LONG representation.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/include/asm/syscall_table.h | 2 +-
arch/riscv/include/asm/unistd.h | 4 ++--
scripts/checksyscalls.sh | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/include/asm/syscall_table.h b/arch/riscv/include/asm/syscall_table.h
index 0c2d61782813..aab2bc0ddf4e 100644
--- a/arch/riscv/include/asm/syscall_table.h
+++ b/arch/riscv/include/asm/syscall_table.h
@@ -1,6 +1,6 @@
#include <asm/bitsperlong.h>
-#if __BITS_PER_LONG == 64
+#ifdef CONFIG_64BIT
#include <asm/syscall_table_64.h>
#else
#include <asm/syscall_table_32.h>
diff --git a/arch/riscv/include/asm/unistd.h b/arch/riscv/include/asm/unistd.h
index e6d904fa67c5..86b9c1712f24 100644
--- a/arch/riscv/include/asm/unistd.h
+++ b/arch/riscv/include/asm/unistd.h
@@ -16,10 +16,10 @@
#define __ARCH_WANT_COMPAT_FADVISE64_64
#endif
-#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)
+#if defined(CONFIG_64BIT) && !defined(__SYSCALL_COMPAT)
#define __ARCH_WANT_NEW_STAT
#define __ARCH_WANT_SET_GET_RLIMIT
-#endif /* __LP64__ */
+#endif /* CONFIG_64BIT */
#define __ARCH_WANT_MEMFD_SECRET
diff --git a/scripts/checksyscalls.sh b/scripts/checksyscalls.sh
index 1e5d2eeb726d..9cc4f9086dfe 100755
--- a/scripts/checksyscalls.sh
+++ b/scripts/checksyscalls.sh
@@ -76,7 +76,7 @@ cat << EOF
#endif
/* System calls for 32-bit kernels only */
-#if BITS_PER_LONG == 64
+#ifdef CONFIG_64BIT
#define __IGNORE_sendfile64
#define __IGNORE_ftruncate64
#define __IGNORE_truncate64
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 39/43] rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (37 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 38/43] rv64ilp32_abi: syscall: Use CONFIG_64BIT instead of BITS_PER_LONG guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 40/43] rv64ilp32_abi: tracepoint-defs: Using u64 for trace_print_flags.mask guoren
` (5 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RISC-V 64ilp32 ABI leverages LP64 uapi and accommodates LP64
ABI userspace directly, necessitating updates to the sysinfo
struct's unsigned long and array types with u64.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
fs/proc/loadavg.c | 10 +++++++---
include/linux/sched/loadavg.h | 4 ++++
include/uapi/linux/sysinfo.h | 20 ++++++++++++++++++++
kernel/sched/loadavg.c | 4 ++++
4 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/fs/proc/loadavg.c b/fs/proc/loadavg.c
index 817981e57223..643e06de3446 100644
--- a/fs/proc/loadavg.c
+++ b/fs/proc/loadavg.c
@@ -13,14 +13,18 @@
static int loadavg_proc_show(struct seq_file *m, void *v)
{
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+ unsigned long long avnrun[3];
+#else
unsigned long avnrun[3];
+#endif
get_avenrun(avnrun, FIXED_1/200, 0);
seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n",
- LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
- LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
- LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
+ LOAD_INT((ulong)avnrun[0]), LOAD_FRAC((ulong)avnrun[0]),
+ LOAD_INT((ulong)avnrun[1]), LOAD_FRAC((ulong)avnrun[1]),
+ LOAD_INT((ulong)avnrun[2]), LOAD_FRAC((ulong)avnrun[2]),
nr_running(), nr_threads,
idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
return 0;
diff --git a/include/linux/sched/loadavg.h b/include/linux/sched/loadavg.h
index 83ec54b65e79..8f2d6a827ee9 100644
--- a/include/linux/sched/loadavg.h
+++ b/include/linux/sched/loadavg.h
@@ -13,7 +13,11 @@
* 11 bit fractions.
*/
extern unsigned long avenrun[]; /* Load averages */
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+extern void get_avenrun(unsigned long long *loads, unsigned long offset, int shift);
+#else
extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
+#endif
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
diff --git a/include/uapi/linux/sysinfo.h b/include/uapi/linux/sysinfo.h
index 435d5c23f0c0..cd29a3d3cd10 100644
--- a/include/uapi/linux/sysinfo.h
+++ b/include/uapi/linux/sysinfo.h
@@ -5,6 +5,25 @@
#include <linux/types.h>
#define SI_LOAD_SHIFT 16
+
+#if (__riscv_xlen == 64) && (__BITS_PER_LONG == 32)
+struct sysinfo {
+ __s64 uptime; /* Seconds since boot */
+ __u64 loads[3]; /* 1, 5, and 15 minute load averages */
+ __u64 totalram; /* Total usable main memory size */
+ __u64 freeram; /* Available memory size */
+ __u64 sharedram; /* Amount of shared memory */
+ __u64 bufferram; /* Memory used by buffers */
+ __u64 totalswap; /* Total swap space size */
+ __u64 freeswap; /* swap space still available */
+ __u16 procs; /* Number of current processes */
+ __u16 pad; /* Explicit padding for m68k */
+ __u64 totalhigh; /* Total high memory size */
+ __u64 freehigh; /* Available high memory size */
+ __u32 mem_unit; /* Memory unit size in bytes */
+ char _f[20-2*sizeof(__u64)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
+};
+#else
struct sysinfo {
__kernel_long_t uptime; /* Seconds since boot */
__kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */
@@ -21,5 +40,6 @@ struct sysinfo {
__u32 mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
};
+#endif
#endif /* _LINUX_SYSINFO_H */
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index c48900b856a2..f1f5abc64dea 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -68,7 +68,11 @@ EXPORT_SYMBOL(avenrun); /* should be removed */
*
* These values are estimates at best, so no need for locking.
*/
+#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
+void get_avenrun(unsigned long long *loads, unsigned long offset, int shift)
+#else
void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
+#endif
{
loads[0] = (avenrun[0] + offset) << shift;
loads[1] = (avenrun[1] + offset) << shift;
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 40/43] rv64ilp32_abi: tracepoint-defs: Using u64 for trace_print_flags.mask
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (38 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 39/43] rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 41/43] rv64ilp32_abi: tty: Adapt ptr_to_compat guoren
` (4 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The rv64ilp32 ABI relies on CONFIG_64BIT, and mmflags.h defines
VMA flags with BIT_ULL. Consequently, use "unsigned long long"
for trace_print_flags.mask to align with VMAflag's type size.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/tracepoint-defs.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/tracepoint-defs.h b/include/linux/tracepoint-defs.h
index aebf0571c736..3b51ede18e32 100644
--- a/include/linux/tracepoint-defs.h
+++ b/include/linux/tracepoint-defs.h
@@ -14,7 +14,11 @@
struct static_call_key;
struct trace_print_flags {
+#ifdef CONFIG_64BIT
+ unsigned long long mask;
+#else
unsigned long mask;
+#endif
const char *name;
};
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 41/43] rv64ilp32_abi: tty: Adapt ptr_to_compat
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (39 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 40/43] rv64ilp32_abi: tracepoint-defs: Using u64 for trace_print_flags.mask guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 42/43] rv64ilp32_abi: memfd: Use vm_flag_t guoren
` (3 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
The RV64ILP32 ABI is based on 64-bit ISA, but BITS_PER_LONG is 32.
So, the size of unsigned long is the same as compat_ulong_t and
no need "(unsigned long)v.iomem_base >> 32 ? 0xfffffff : ..."
detection.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
drivers/tty/tty_io.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 449dbd216460..75e256e879d0 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2873,8 +2873,12 @@ static int compat_tty_tiocgserial(struct tty_struct *tty,
err = tty->ops->get_serial(tty, &v);
if (!err) {
memcpy(&v32, &v, offsetof(struct serial_struct32, iomem_base));
+#if BITS_PER_LONG == 64
v32.iomem_base = (unsigned long)v.iomem_base >> 32 ?
0xfffffff : ptr_to_compat(v.iomem_base);
+#else
+ v32.iomem_base = ptr_to_compat(v.iomem_base);
+#endif
v32.iomem_reg_shift = v.iomem_reg_shift;
v32.port_high = v.port_high;
if (copy_to_user(ss, &v32, sizeof(v32)))
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 42/43] rv64ilp32_abi: memfd: Use vm_flag_t
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (40 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 41/43] rv64ilp32_abi: tty: Adapt ptr_to_compat guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:16 ` [RFC PATCH V3 43/43] riscv: Fixup address space overlay of print_mlk guoren
` (2 subsequent siblings)
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
RV64ILP32 ABI linux kernel is based on CONFIG_64BIT, and uses
unsigned long long as vm_flags_t. Using unsigned long would
break rv64ilp32 abi.
The definition of vm_flag_t exists, hence its usage is
preferred even if it's not essential.
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
include/linux/memfd.h | 4 ++--
mm/memfd.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/memfd.h b/include/linux/memfd.h
index 246daadbfde8..6f606d9573c3 100644
--- a/include/linux/memfd.h
+++ b/include/linux/memfd.h
@@ -14,7 +14,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx);
* We also update VMA flags if appropriate by manipulating the VMA flags pointed
* to by vm_flags_ptr.
*/
-int memfd_check_seals_mmap(struct file *file, unsigned long *vm_flags_ptr);
+int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr);
#else
static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a)
{
@@ -25,7 +25,7 @@ static inline struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
return ERR_PTR(-EINVAL);
}
static inline int memfd_check_seals_mmap(struct file *file,
- unsigned long *vm_flags_ptr)
+ vm_flags_t *vm_flags_ptr)
{
return 0;
}
diff --git a/mm/memfd.c b/mm/memfd.c
index 37f7be57c2f5..50dad90ffedc 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -332,10 +332,10 @@ static inline bool is_write_sealed(unsigned int seals)
return seals & (F_SEAL_WRITE | F_SEAL_FUTURE_WRITE);
}
-static int check_write_seal(unsigned long *vm_flags_ptr)
+static int check_write_seal(vm_flags_t *vm_flags_ptr)
{
- unsigned long vm_flags = *vm_flags_ptr;
- unsigned long mask = vm_flags & (VM_SHARED | VM_WRITE);
+ vm_flags_t vm_flags = *vm_flags_ptr;
+ vm_flags_t mask = vm_flags & (VM_SHARED | VM_WRITE);
/* If a private matting then writability is irrelevant. */
if (!(mask & VM_SHARED))
@@ -357,7 +357,7 @@ static int check_write_seal(unsigned long *vm_flags_ptr)
return 0;
}
-int memfd_check_seals_mmap(struct file *file, unsigned long *vm_flags_ptr)
+int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr)
{
int err = 0;
unsigned int *seals_ptr = memfd_file_seals_ptr(file);
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* [RFC PATCH V3 43/43] riscv: Fixup address space overlay of print_mlk
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (41 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 42/43] rv64ilp32_abi: memfd: Use vm_flag_t guoren
@ 2025-03-25 12:16 ` guoren
2025-03-25 12:26 ` [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI Peter Zijlstra
2025-03-27 21:06 ` David Laight
44 siblings, 0 replies; 63+ messages in thread
From: guoren @ 2025-03-25 12:16 UTC (permalink / raw)
To: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, guoren, xiao.w.wang,
qingfang.deng, leobras, jszhang, conor.dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
If phyical memory is 1GiB for ilp32 linux, then print_mlk would be:
lowmem : 0xc0000000 - 0x00000000 ( 1024 MB)
After fixup:
lowmem : 0xc0000000 - 0xffffffff ( 1024 MB)
Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
arch/riscv/mm/init.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 3cdbb033860e..e09286d4916a 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -105,26 +105,26 @@ static void __init zone_sizes_init(void)
static inline void print_mlk(char *name, unsigned long b, unsigned long t)
{
- pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld kB)\n", name, b, t,
+ pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld kB)\n", name, b, t - 1,
(((t) - (b)) >> LOG2_SZ_1K));
}
static inline void print_mlm(char *name, unsigned long b, unsigned long t)
{
- pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld MB)\n", name, b, t,
+ pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld MB)\n", name, b, t - 1,
(((t) - (b)) >> LOG2_SZ_1M));
}
static inline void print_mlg(char *name, unsigned long b, unsigned long t)
{
- pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld GB)\n", name, b, t,
+ pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld GB)\n", name, b, t - 1,
(((t) - (b)) >> LOG2_SZ_1G));
}
#if BITS_PER_LONG == 64
static inline void print_mlt(char *name, unsigned long b, unsigned long t)
{
- pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld TB)\n", name, b, t,
+ pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld TB)\n", name, b, t - 1,
(((t) - (b)) >> LOG2_SZ_1T));
}
#else
--
2.40.1
^ permalink raw reply related [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (42 preceding siblings ...)
2025-03-25 12:16 ` [RFC PATCH V3 43/43] riscv: Fixup address space overlay of print_mlk guoren
@ 2025-03-25 12:26 ` Peter Zijlstra
2025-03-25 13:13 ` Guo Ren
` (2 more replies)
2025-03-27 21:06 ` David Laight
44 siblings, 3 replies; 63+ messages in thread
From: Peter Zijlstra @ 2025-03-25 12:26 UTC (permalink / raw)
To: guoren
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, boqun.feng, xiao.w.wang, qingfang.deng, leobras,
jszhang, conor.dooley, samuel.holland, yongxuan.wang, luxu.kernel,
david, ruanjinjie, cuiyunhui, wangkefeng.wang, qiaozhe, ardb, ast,
linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm, linux-crypto,
bpf, linux-input, linux-perf-users, linux-serial, linux-fsdevel,
linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>
> Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
> but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
I'm thinking you're going to be finding a metric ton of assumptions
about 'unsigned long' being 64bit when 64BIT=y throughout the kernel.
I know of a couple of places where 64BIT will result in different math
such that a 32bit 'unsigned long' will trivially overflow.
Please, don't do this. This adds a significant maintenance burden on all
of us.
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 12:26 ` [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI Peter Zijlstra
@ 2025-03-25 13:13 ` Guo Ren
2025-03-25 13:17 ` Arnd Bergmann
2025-03-25 18:51 ` David Hildenbrand
2 siblings, 0 replies; 63+ messages in thread
From: Guo Ren @ 2025-03-25 13:13 UTC (permalink / raw)
To: Peter Zijlstra
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, boqun.feng, xiao.w.wang, qingfang.deng, leobras,
jszhang, conor.dooley, samuel.holland, yongxuan.wang, luxu.kernel,
david, ruanjinjie, cuiyunhui, wangkefeng.wang, qiaozhe, ardb, ast,
linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm, linux-crypto,
bpf, linux-input, linux-perf-users, linux-serial, linux-fsdevel,
linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On Tue, Mar 25, 2025 at 8:27 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
> > From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
> >
> > Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
> > but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
>
> I'm thinking you're going to be finding a metric ton of assumptions
> about 'unsigned long' being 64bit when 64BIT=y throughout the kernel.
Less than you imagined. Most code is compatible with ILP32 ABI due to
the CONFIG_32BIT. In my practice, it's deemed acceptable.
>
> I know of a couple of places where 64BIT will result in different math
> such that a 32bit 'unsigned long' will trivially overflow.
I would be grateful if you could share some with me.
>
> Please, don't do this. This adds a significant maintenance burden on all
> of us.
The 64ILP32 ABI would bear the maintenance burden, not traditional
64-bit or 32-bit ABIs. The patch set won't impact other CONFIG_64BIT
or CONFIG_32BIT. Numerous RV64 chips require the RV64ILP32 ABI to
reduce the memory and cache footprint; we will bear the burden. The
core code maintainers would receive patches that would make them use
BITS_PER_LONG and CONFIG_64BIT more accurately.
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 12:26 ` [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI Peter Zijlstra
2025-03-25 13:13 ` Guo Ren
@ 2025-03-25 13:17 ` Arnd Bergmann
2025-03-26 6:07 ` Guo Ren
2025-03-25 18:51 ` David Hildenbrand
2 siblings, 1 reply; 63+ messages in thread
From: Arnd Bergmann @ 2025-03-25 13:17 UTC (permalink / raw)
To: Peter Zijlstra, guoren
Cc: Greg Kroah-Hartman, Linus Torvalds, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Oleg Nesterov, Kees Cook,
Thomas Gleixner, Will Deacon, Mark Rutland, Christian Brauner,
Andrew Morton, Steven Rostedt, Eric Dumazet, Chen Wang,
Inochi Amaoto, gaohan, shihua, jiawei, wuwei2016, Drew Fustini,
Lad, Prabhakar, ctsai390, wefu, Jakub Kicinski, Paolo Abeni,
Josef Bacik, David Sterba, Ingo Molnar, Boqun Feng, Xiao W Wang,
qingfang.deng, Leonardo Bras, Jisheng Zhang, Conor.Dooley,
Samuel Holland, yongxuan.wang, Xu Lu, David Hildenbrand,
Ruan Jinjie, Yunhui Cui, Kefeng Wang, qiaozhe, Ard Biesheuvel,
Alexei Starovoitov, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, Linux-Arch, maple-tree,
linux-trace-kernel, Netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Tue, Mar 25, 2025, at 13:26, Peter Zijlstra wrote:
> On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
>> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>>
>> Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
>> but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
>
> Please, don't do this. This adds a significant maintenance burden on all
> of us.
It would be easier to this with CONFIG_64BIT disabled and continue
treating CONFIG_64BIT to be the same as BITS_PER_LONG=64, but I still
think it's fundamentally a bad idea to support this in mainline
kernels in any variation, other than supporting regular 32-bit
compat mode tasks on a regular 64-bit kernel.
>> The patchset targets RISC-V and is built on the RV64ILP32 ABI, which
>> was introduced into RISC-V's psABI in January 2025 [1]. This patchset
>> equips an rv64ilp32-abi kernel with all the functionalities of a
>> traditional lp64-abi kernel, yet restricts the address space to 2GiB.
>> Hence, the rv64ilp32-abi kernel simultaneously supports lp64-abi
>> userspace and ilp32-abi (compat) userspace, the same as the
>> traditional lp64-abi kernel.
You declare the syscall ABI to be the native 64-bit ABI, but this
is fundamentally not true because a many uapi structures are
defined in terms of 'long' or pointer values, in particular in
the ioctl call. This might work for an rv64ilp32 userspace that
uses the same headers and the same types, but you explicitly
say that the goal is to run native rv64 or compat rv32 tasks,
not rv64ilp32 (thanks!).
As far as I can tell, there is no way to rectify this design flaw
other than to drop support for 64-bit userspace and only support
regular rv32 userspace. I'm also skeptical that supporting rv64
userspace helps in practice other than for testing, since
generally most memory overhead is in userspace rather than the
kernel, and there is much more to gain from shrinking the larger
userspace by running rv32 compat mode binaries on a 64-bit kernel
than the other way round.
If you remove the CONFIG_64BIT changes that Peter mentioned and
the support for ilp64 userland from your series, you end up
with a kernel that is very similar to a native rv32 kernel
but executes as rv64ilp32 and runs rv32 userspace. I don't have
any objections to that approach, and the same thing has come
up on arm64 as a possible idea as well, but I don't know if
that actually brings any notable advantage over an rv32 kernel.
Are there CPUs that can run rv64 kernels and rv32 userspace
but not rv32 kernels, similar to what we have on Arm Cortex-A76
and Cortex-A510?
Arnd
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv
2025-03-25 12:16 ` [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv guoren
@ 2025-03-25 17:19 ` Sergey Shtylyov
2025-03-26 9:22 ` Guo Ren
0 siblings, 1 reply; 63+ messages in thread
From: Sergey Shtylyov @ 2025-03-25 17:19 UTC (permalink / raw)
To: guoren, arnd, gregkh, torvalds, paul.walmsley, palmer, anup,
atishp, oleg, kees, tglx, will, mark.rutland, brauner, akpm,
rostedt, edumazet, unicorn_wang, inochiama, gaohan, shihua,
jiawei, wuwei2016, drew, prabhakar.mahadev-lad.rj, ctsai390, wefu,
kuba, pabeni, josef, dsterba, mingo, peterz, boqun.feng,
xiao.w.wang, qingfang.deng, leobras, jszhang, conor.dooley,
samuel.holland, yongxuan.wang, luxu.kernel, david, ruanjinjie,
cuiyunhui, wangkefeng.wang, qiaozhe
Cc: ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On 3/25/25 3:16 PM, guoren@kernel.org wrote:
> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>
> The rv64ilp32 abi reuses the env and argv memory layout of the
> lp64 abi, so leave the space to fit the lp64 struct layout.
>
> Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
> ---
> fs/exec.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/fs/exec.c b/fs/exec.c
> index 506cd411f4ac..548d18b7ae92 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -424,6 +424,10 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
> }
> #endif
>
> +#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
Parens don't seem necessary...
> + nr = nr * 2;
Why not nr *= 2?
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 12:26 ` [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI Peter Zijlstra
2025-03-25 13:13 ` Guo Ren
2025-03-25 13:17 ` Arnd Bergmann
@ 2025-03-25 18:51 ` David Hildenbrand
2025-03-25 19:23 ` Liam R. Howlett
2 siblings, 1 reply; 63+ messages in thread
From: David Hildenbrand @ 2025-03-25 18:51 UTC (permalink / raw)
To: Peter Zijlstra, guoren
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, boqun.feng, xiao.w.wang, qingfang.deng, leobras,
jszhang, conor.dooley, samuel.holland, yongxuan.wang, luxu.kernel,
ruanjinjie, cuiyunhui, wangkefeng.wang, qiaozhe, ardb, ast,
linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm, linux-crypto,
bpf, linux-input, linux-perf-users, linux-serial, linux-fsdevel,
linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On 25.03.25 13:26, Peter Zijlstra wrote:
> On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
>> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>>
>> Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
>> but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
>
> I'm thinking you're going to be finding a metric ton of assumptions
> about 'unsigned long' being 64bit when 64BIT=y throughout the kernel.
>
> I know of a couple of places where 64BIT will result in different math
> such that a 32bit 'unsigned long' will trivially overflow.
>
> Please, don't do this. This adds a significant maintenance burden on all
> of us.
>
Fully agreed.
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
2025-03-25 12:16 ` [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
@ 2025-03-25 19:09 ` Liam R. Howlett
2025-03-27 12:47 ` Guo Ren
0 siblings, 1 reply; 63+ messages in thread
From: Liam R. Howlett @ 2025-03-25 19:09 UTC (permalink / raw)
To: guoren
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
* guoren@kernel.org <guoren@kernel.org> [250325 08:24]:
> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>
> The Maple tree algorithm uses ulong type for each element. The
> number of slots is based on BITS_PER_LONG for RV64ILP32 ABI, so
> use BITS_PER_LONG instead of CONFIG_64BIT.
>
> Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
> ---
> include/linux/maple_tree.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h
> index cbbcd18d4186..ff6265b6468b 100644
> --- a/include/linux/maple_tree.h
> +++ b/include/linux/maple_tree.h
> @@ -24,7 +24,7 @@
> *
> * Nodes in the tree point to their parent unless bit 0 is set.
> */
> -#if defined(CONFIG_64BIT) || defined(BUILD_VDSO32_64)
> +#if (BITS_PER_LONG == 64) || defined(BUILD_VDSO32_64)
This will break my userspace testing, if you do not update the testing as
well. This can be found in tools/testing/radix-tree. Please also look
at the Makefile as well since it will generate a build flag for the
userspace.
This raises other concerns as the code is found with a grep command, so
I'm not sure why it was missed and if anything else is missed?
If you consider this email to be the (unasked) question about what to do
here, then please CC me, the maintainer of the files including the one
you are updating here.
Thank you,
Liam
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 18:51 ` David Hildenbrand
@ 2025-03-25 19:23 ` Liam R. Howlett
2025-03-27 16:20 ` Palmer Dabbelt
0 siblings, 1 reply; 63+ messages in thread
From: Liam R. Howlett @ 2025-03-25 19:23 UTC (permalink / raw)
To: David Hildenbrand
Cc: Peter Zijlstra, guoren, arnd, gregkh, torvalds, paul.walmsley,
palmer, anup, atishp, oleg, kees, tglx, will, mark.rutland,
brauner, akpm, rostedt, edumazet, unicorn_wang, inochiama, gaohan,
shihua, jiawei, wuwei2016, drew, prabhakar.mahadev-lad.rj,
ctsai390, wefu, kuba, pabeni, josef, dsterba, mingo, boqun.feng,
xiao.w.wang, qingfang.deng, leobras, jszhang, conor.dooley,
samuel.holland, yongxuan.wang, luxu.kernel, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe, ardb, ast, linux-kernel, linux-riscv,
kvm, kvm-riscv, linux-mm, linux-crypto, bpf, linux-input,
linux-perf-users, linux-serial, linux-fsdevel, linux-arch,
maple-tree, linux-trace-kernel, netdev, linux-atm-general,
linux-btrfs, netfilter-devel, coreteam, linux-nfs, linux-sctp,
linux-usb, linux-media
* David Hildenbrand <david@redhat.com> [250325 14:52]:
> On 25.03.25 13:26, Peter Zijlstra wrote:
> > On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
> > > From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
> > >
> > > Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
> > > but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
> >
> > I'm thinking you're going to be finding a metric ton of assumptions
> > about 'unsigned long' being 64bit when 64BIT=y throughout the kernel.
> >
> > I know of a couple of places where 64BIT will result in different math
> > such that a 32bit 'unsigned long' will trivially overflow.
> >
> > Please, don't do this. This adds a significant maintenance burden on all
> > of us.
> >
>
> Fully agreed.
I would go further and say I do not want this to go in.
The open ended maintenance burden is not worth extending hardware life
of a board with 16mb of ram (If I understand your 2023 LPC slides
correctly).
Thank you,
Liam
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
2025-03-25 12:15 ` [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface guoren
@ 2025-03-25 20:30 ` Jan Engelhardt
2025-03-26 3:35 ` Guo Ren
2025-03-25 20:41 ` Linus Torvalds
1 sibling, 1 reply; 63+ messages in thread
From: Jan Engelhardt @ 2025-03-25 20:30 UTC (permalink / raw)
To: guoren
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Tuesday 2025-03-25 13:15, guoren@kernel.org wrote:
>diff --git a/include/uapi/linux/netfilter/x_tables.h b/include/uapi/linux/netfilter/x_tables.h
>index 796af83a963a..7e02e34c6fad 100644
>--- a/include/uapi/linux/netfilter/x_tables.h
>+++ b/include/uapi/linux/netfilter/x_tables.h
>@@ -18,7 +18,11 @@ struct xt_entry_match {
> __u8 revision;
> } user;
> struct {
>+#if __riscv_xlen == 64
>+ __u64 match_size;
>+#else
> __u16 match_size;
>+#endif
>
> /* Used inside the kernel */
> struct xt_match *match;
The __u16 is the common prefix of the union which is exposed to userspace.
If anything, you need to use __attribute__((aligned(8))) to move
`match` to a fixed location.
However, that sub-struct is only used inside the kernel and never exposed,
so the alignment of `match` should not play a role.
Moreover, change from u16 to u64 would break RISC-V Big-Endian. Even if there
currently is no big-endian variant, let's not introduce such breakage.
>--- a/include/uapi/linux/netfilter_ipv4/ip_tables.h
>+++ b/include/uapi/linux/netfilter_ipv4/ip_tables.h
>@@ -200,7 +200,14 @@ struct ipt_replace {
> /* Number of counters (must be equal to current number of entries). */
> unsigned int num_counters;
> /* The old entries' counters. */
>+#if __riscv_xlen == 64
>+ union {
>+ struct xt_counters __user *counters;
>+ __u64 __counters;
>+ };
>+#else
> struct xt_counters __user *counters;
>+#endif
>
> /* The entries (hang off end: not really an array). */
> struct ipt_entry entries[];
This seems ok, but perhaps there is a better name for __riscv_xlen (ifdef
CONFIG_????ilp32), so it is not strictly tied to riscv,
in case other platform wants to try ilp32-self mode.
>+#if __riscv_xlen == 64
>+ union {
>+ int __user *auth_flavours; /* 1 */
>+ __u64 __auth_flavours;
>+ };
>+#else
> int __user *auth_flavours; /* 1 */
>+#endif
> };
>
> /* bits in the flags field */
>diff --git a/include/uapi/linux/ppp-ioctl.h b/include/uapi/linux/ppp-ioctl.h
>index 1cc5ce0ae062..8d48eab430c1 100644
>--- a/include/uapi/linux/ppp-ioctl.h
>+++ b/include/uapi/linux/ppp-ioctl.h
>@@ -59,7 +59,14 @@ struct npioctl {
>
> /* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
> struct ppp_option_data {
>+#if __riscv_xlen == 64
>+ union {
>+ __u8 __user *ptr;
>+ __u64 __ptr;
>+ };
>+#else
> __u8 __user *ptr;
>+#endif
> __u32 length;
> int transmit;
> };
>diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
>index b7d91d4cf0db..46a06fddcd2f 100644
>--- a/include/uapi/linux/sctp.h
>+++ b/include/uapi/linux/sctp.h
>@@ -1024,6 +1024,9 @@ struct sctp_getaddrs_old {
> #else
> struct sockaddr *addrs;
> #endif
>+#if (__riscv_xlen == 64) && (__SIZEOF_LONG__ == 4)
>+ __u32 unused;
>+#endif
> };
>
> struct sctp_getaddrs {
>diff --git a/include/uapi/linux/sem.h b/include/uapi/linux/sem.h
>index 75aa3b273cd9..de9f441913cd 100644
>--- a/include/uapi/linux/sem.h
>+++ b/include/uapi/linux/sem.h
>@@ -26,10 +26,29 @@ struct semid_ds {
> struct ipc_perm sem_perm; /* permissions .. see ipc.h */
> __kernel_old_time_t sem_otime; /* last semop time */
> __kernel_old_time_t sem_ctime; /* create/last semctl() time */
>+#if __riscv_xlen == 64
>+ union {
>+ struct sem *sem_base; /* ptr to first semaphore in array */
>+ __u64 __sem_base;
>+ };
>+ union {
>+ struct sem_queue *sem_pending; /* pending operations to be processed */
>+ __u64 __sem_pending;
>+ };
>+ union {
>+ struct sem_queue **sem_pending_last; /* last pending operation */
>+ __u64 __sem_pending_last;
>+ };
>+ union {
>+ struct sem_undo *undo; /* undo requests on this array */
>+ __u64 __undo;
>+ };
>+#else
> struct sem *sem_base; /* ptr to first semaphore in array */
> struct sem_queue *sem_pending; /* pending operations to be processed */
> struct sem_queue **sem_pending_last; /* last pending operation */
> struct sem_undo *undo; /* undo requests on this array */
>+#endif
> unsigned short sem_nsems; /* no. of semaphores in array */
> };
>
>@@ -46,10 +65,29 @@ struct sembuf {
> /* arg for semctl system calls. */
> union semun {
> int val; /* value for SETVAL */
>+#if __riscv_xlen == 64
>+ union {
>+ struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
>+ __u64 ___buf;
>+ };
>+ union {
>+ unsigned short __user *array; /* array for GETALL & SETALL */
>+ __u64 __array;
>+ };
>+ union {
>+ struct seminfo __user *__buf; /* buffer for IPC_INFO */
>+ __u64 ____buf;
>+ };
>+ union {
>+ void __user *__pad;
>+ __u64 ____pad;
>+ };
>+#else
> struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
> unsigned short __user *array; /* array for GETALL & SETALL */
> struct seminfo __user *__buf; /* buffer for IPC_INFO */
> void __user *__pad;
>+#endif
> };
>
> struct seminfo {
>diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
>index d3fcd3b5ec53..5f7a83649395 100644
>--- a/include/uapi/linux/socket.h
>+++ b/include/uapi/linux/socket.h
>@@ -22,7 +22,14 @@ struct __kernel_sockaddr_storage {
> /* space to achieve desired size, */
> /* _SS_MAXSIZE value minus size of ss_family */
> };
>+#if __riscv_xlen == 64
>+ union {
>+ void *__align; /* implementation specific desired alignment */
>+ u64 ___align;
>+ };
>+#else
> void *__align; /* implementation specific desired alignment */
>+#endif
> };
> };
>
>diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
>index 8981f00204db..8ed7b29897f9 100644
>--- a/include/uapi/linux/sysctl.h
>+++ b/include/uapi/linux/sysctl.h
>@@ -33,13 +33,45 @@
> member of a struct __sysctl_args to have? */
>
> struct __sysctl_args {
>+#if __riscv_xlen == 64
>+ union {
>+ int __user *name;
>+ __u64 __name;
>+ };
>+#else
> int __user *name;
>+#endif
> int nlen;
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *oldval;
>+ __u64 __oldval;
>+ };
>+#else
> void __user *oldval;
>+#endif
>+#if __riscv_xlen == 64
>+ union {
>+ size_t __user *oldlenp;
>+ __u64 __oldlenp;
>+ };
>+#else
> size_t __user *oldlenp;
>+#endif
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *newval;
>+ __u64 __newval;
>+ };
>+#else
> void __user *newval;
>+#endif
> size_t newlen;
>+#if __riscv_xlen == 64
>+ unsigned long long __unused[4];
>+#else
> unsigned long __unused[4];
>+#endif
> };
>
> /* Define sysctl names first */
>diff --git a/include/uapi/linux/uhid.h b/include/uapi/linux/uhid.h
>index cef7534d2d19..4a774dbd3de8 100644
>--- a/include/uapi/linux/uhid.h
>+++ b/include/uapi/linux/uhid.h
>@@ -130,7 +130,14 @@ struct uhid_create_req {
> __u8 name[128];
> __u8 phys[64];
> __u8 uniq[64];
>+#if __riscv_xlen == 64
>+ union {
>+ __u8 __user *rd_data;
>+ __u64 __rd_data;
>+ };
>+#else
> __u8 __user *rd_data;
>+#endif
> __u16 rd_size;
>
> __u16 bus;
>diff --git a/include/uapi/linux/uio.h b/include/uapi/linux/uio.h
>index 649739e0c404..27dfd6032dc6 100644
>--- a/include/uapi/linux/uio.h
>+++ b/include/uapi/linux/uio.h
>@@ -16,8 +16,19 @@
>
> struct iovec
> {
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
>+ __u64 __iov_base;
>+ };
>+ union {
>+ __kernel_size_t iov_len; /* Must be size_t (1003.1g) */
>+ __u64 __iov_len;
>+ };
>+#else
> void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
> __kernel_size_t iov_len; /* Must be size_t (1003.1g) */
>+#endif
> };
>
> struct dmabuf_cmsg {
>diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
>index d791cc58a7f0..443ec5356caf 100644
>--- a/include/uapi/linux/usb/tmc.h
>+++ b/include/uapi/linux/usb/tmc.h
>@@ -51,7 +51,14 @@ struct usbtmc_request {
>
> struct usbtmc_ctrlrequest {
> struct usbtmc_request req;
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *data; /* pointer to user space */
>+ __u64 __data; /* pointer to user space */
>+ };
>+#else
> void __user *data; /* pointer to user space */
>+#endif
> } __attribute__ ((packed));
>
> struct usbtmc_termchar {
>@@ -70,7 +77,14 @@ struct usbtmc_message {
> __u32 transfer_size; /* size of bytes to transfer */
> __u32 transferred; /* size of received/written bytes */
> __u32 flags; /* bit 0: 0 = synchronous; 1 = asynchronous */
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *message; /* pointer to header and data in user space */
>+ __u64 __message;
>+ };
>+#else
> void __user *message; /* pointer to header and data in user space */
>+#endif
> } __attribute__ ((packed));
>
> /* Request values for USBTMC driver's ioctl entry point */
>diff --git a/include/uapi/linux/usbdevice_fs.h b/include/uapi/linux/usbdevice_fs.h
>index 74a84e02422a..8c8efef74c3c 100644
>--- a/include/uapi/linux/usbdevice_fs.h
>+++ b/include/uapi/linux/usbdevice_fs.h
>@@ -44,14 +44,28 @@ struct usbdevfs_ctrltransfer {
> __u16 wIndex;
> __u16 wLength;
> __u32 timeout; /* in milliseconds */
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *data;
>+ __u64 __data;
>+ };
>+#else
> void __user *data;
>+#endif
> };
>
> struct usbdevfs_bulktransfer {
> unsigned int ep;
> unsigned int len;
> unsigned int timeout; /* in milliseconds */
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *data;
>+ __u64 __data;
>+ };
>+#else
> void __user *data;
>+#endif
> };
>
> struct usbdevfs_setinterface {
>@@ -61,7 +75,14 @@ struct usbdevfs_setinterface {
>
> struct usbdevfs_disconnectsignal {
> unsigned int signr;
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *context;
>+ __u64 __context;
>+ };
>+#else
> void __user *context;
>+#endif
> };
>
> #define USBDEVFS_MAXDRIVERNAME 255
>@@ -119,7 +140,14 @@ struct usbdevfs_urb {
> unsigned char endpoint;
> int status;
> unsigned int flags;
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *buffer;
>+ __u64 __buffer;
>+ };
>+#else
> void __user *buffer;
>+#endif
> int buffer_length;
> int actual_length;
> int start_frame;
>@@ -130,7 +158,14 @@ struct usbdevfs_urb {
> int error_count;
> unsigned int signr; /* signal to be sent on completion,
> or 0 if none should be sent. */
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *usercontext;
>+ __u64 __usercontext;
>+ };
>+#else
> void __user *usercontext;
>+#endif
> struct usbdevfs_iso_packet_desc iso_frame_desc[];
> };
>
>@@ -139,7 +174,14 @@ struct usbdevfs_ioctl {
> int ifno; /* interface 0..N ; negative numbers reserved */
> int ioctl_code; /* MUST encode size + direction of data so the
> * macros in <asm/ioctl.h> give correct values */
>+#if __riscv_xlen == 64
>+ union {
>+ void __user *data; /* param buffer (in, or out) */
>+ __u64 __pad;
>+ };
>+#else
> void __user *data; /* param buffer (in, or out) */
>+#endif
> };
>
> /* You can do most things with hubs just through control messages,
>@@ -195,9 +237,17 @@ struct usbdevfs_streams {
> #define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb)
> #define USBDEVFS_SUBMITURB32 _IOR('U', 10, struct usbdevfs_urb32)
> #define USBDEVFS_DISCARDURB _IO('U', 11)
>+#if __riscv_xlen == 64
>+#define USBDEVFS_REAPURB _IOW('U', 12, __u64)
>+#else
> #define USBDEVFS_REAPURB _IOW('U', 12, void *)
>+#endif
> #define USBDEVFS_REAPURB32 _IOW('U', 12, __u32)
>+#if __riscv_xlen == 64
>+#define USBDEVFS_REAPURBNDELAY _IOW('U', 13, __u64)
>+#else
> #define USBDEVFS_REAPURBNDELAY _IOW('U', 13, void *)
>+#endif
> #define USBDEVFS_REAPURBNDELAY32 _IOW('U', 13, __u32)
> #define USBDEVFS_DISCSIGNAL _IOR('U', 14, struct usbdevfs_disconnectsignal)
> #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
>diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h
>index f86185456dc5..3ccb99039a43 100644
>--- a/include/uapi/linux/uvcvideo.h
>+++ b/include/uapi/linux/uvcvideo.h
>@@ -54,7 +54,14 @@ struct uvc_xu_control_mapping {
> __u32 v4l2_type;
> __u32 data_type;
>
>+#if __riscv_xlen == 64
>+ union {
>+ struct uvc_menu_info __user *menu_info;
>+ __u64 __menu_info;
>+ };
>+#else
> struct uvc_menu_info __user *menu_info;
>+#endif
> __u32 menu_count;
>
> __u32 reserved[4];
>@@ -66,7 +73,14 @@ struct uvc_xu_control_query {
> __u8 query; /* Video Class-Specific Request Code, */
> /* defined in linux/usb/video.h A.8. */
> __u16 size;
>+#if __riscv_xlen == 64
>+ union {
>+ __u8 __user *data;
>+ __u64 __data;
>+ };
>+#else
> __u8 __user *data;
>+#endif
> };
>
> #define UVCIOC_CTRL_MAP _IOWR('u', 0x20, struct uvc_xu_control_mapping)
>diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
>index c8dbf8219c4f..0a1dc2a780fb 100644
>--- a/include/uapi/linux/vfio.h
>+++ b/include/uapi/linux/vfio.h
>@@ -1570,7 +1570,14 @@ struct vfio_iommu_type1_dma_map {
> struct vfio_bitmap {
> __u64 pgsize; /* page size for bitmap in bytes */
> __u64 size; /* in bytes */
>+ #if __riscv_xlen == 64
>+ union {
>+ __u64 __user *data; /* one bit per page */
>+ __u64 __data;
>+ };
>+ #else
> __u64 __user *data; /* one bit per page */
>+ #endif
> };
>
> /**
>diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>index e7c4dce39007..8e5391f07626 100644
>--- a/include/uapi/linux/videodev2.h
>+++ b/include/uapi/linux/videodev2.h
>@@ -1898,7 +1898,14 @@ struct v4l2_ext_controls {
> __u32 error_idx;
> __s32 request_fd;
> __u32 reserved[1];
>+#if __riscv_xlen == 64
>+ union {
>+ struct v4l2_ext_control *controls;
>+ __u64 __controls;
>+ };
>+#else
> struct v4l2_ext_control *controls;
>+#endif
> };
>
> #define V4L2_CTRL_ID_MASK (0x0fffffff)
>--
>2.40.1
>
>
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
2025-03-25 12:15 ` [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface guoren
2025-03-25 20:30 ` Jan Engelhardt
@ 2025-03-25 20:41 ` Linus Torvalds
2025-03-26 6:34 ` Guo Ren
2025-03-27 16:20 ` Palmer Dabbelt
1 sibling, 2 replies; 63+ messages in thread
From: Linus Torvalds @ 2025-03-25 20:41 UTC (permalink / raw)
To: guoren
Cc: arnd, gregkh, paul.walmsley, palmer, anup, atishp, oleg, kees,
tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Tue, 25 Mar 2025 at 05:17, <guoren@kernel.org> wrote:
>
> The rv64ilp32 abi kernel accommodates the lp64 abi userspace and
> leverages the lp64 abi Linux interface. Hence, unify the
> BITS_PER_LONG = 32 memory layout to match BITS_PER_LONG = 64.
No.
This isn't happening.
You can't do crazy things in the RISC-V code and then expect the rest
of the kernel to just go "ok, we'll do crazy things".
We're not doing crazy __riscv_xlen hackery with random structures
containing 64-bit values that the kernel then only looks at the low 32
bits. That's wrong on *so* many levels.
I'm willing to say "big-endian is dead", but I'm not willing to accept
this kind of crazy hackery.
Not today, not ever.
If you want to run a ilp32 kernel on 64-bit hardware (and support
64-bit ABI just in a 32-bit virtual memory size), I would suggest you
(a) treat the kernel as natively 32-bit (obviously you can then tell
the compiler to use the rv64 instructions, which I presume you're
already doing - I didn't look)
(b) look at making the compat stuff do the conversion the "wrong way".
And btw, that (b) implies *not* just ignoring the high bits. If
user-space gives 64-bit pointer, you don't just treat it as a 32-bit
one by dropping the high bits. You add some logic to convert it to an
invalid pointer so that user space gets -EFAULT.
Linus
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
2025-03-25 20:30 ` Jan Engelhardt
@ 2025-03-26 3:35 ` Guo Ren
0 siblings, 0 replies; 63+ messages in thread
From: Guo Ren @ 2025-03-26 3:35 UTC (permalink / raw)
To: Jan Engelhardt
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Wed, Mar 26, 2025 at 4:31 AM Jan Engelhardt <ej@inai.de> wrote:
>
>
> On Tuesday 2025-03-25 13:15, guoren@kernel.org wrote:
>
> >diff --git a/include/uapi/linux/netfilter/x_tables.h b/include/uapi/linux/netfilter/x_tables.h
> >index 796af83a963a..7e02e34c6fad 100644
> >--- a/include/uapi/linux/netfilter/x_tables.h
> >+++ b/include/uapi/linux/netfilter/x_tables.h
> >@@ -18,7 +18,11 @@ struct xt_entry_match {
> > __u8 revision;
> > } user;
> > struct {
> >+#if __riscv_xlen == 64
> >+ __u64 match_size;
> >+#else
> > __u16 match_size;
> >+#endif
> >
> > /* Used inside the kernel */
> > struct xt_match *match;
>
> The __u16 is the common prefix of the union which is exposed to userspace.
> If anything, you need to use __attribute__((aligned(8))) to move
> `match` to a fixed location.
>
> However, that sub-struct is only used inside the kernel and never exposed,
> so the alignment of `match` should not play a role.
>
> Moreover, change from u16 to u64 would break RISC-V Big-Endian. Even if there
> currently is no big-endian variant, let's not introduce such breakage.
You're correct. The __u64 modification is too raw from the proof of
concept. It's not correct, so I would accept your advice.
>
>
> >--- a/include/uapi/linux/netfilter_ipv4/ip_tables.h
> >+++ b/include/uapi/linux/netfilter_ipv4/ip_tables.h
> >@@ -200,7 +200,14 @@ struct ipt_replace {
> > /* Number of counters (must be equal to current number of entries). */
> > unsigned int num_counters;
> > /* The old entries' counters. */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ struct xt_counters __user *counters;
> >+ __u64 __counters;
> >+ };
> >+#else
> > struct xt_counters __user *counters;
> >+#endif
> >
> > /* The entries (hang off end: not really an array). */
> > struct ipt_entry entries[];
>
> This seems ok, but perhaps there is a better name for __riscv_xlen (ifdef
> CONFIG_????ilp32), so it is not strictly tied to riscv,
> in case other platform wants to try ilp32-self mode.
Yes, I want that macro, but Linus has suggested "compat stuff". I
would have to try.
Thx for the reviewing!
>
> >+#if __riscv_xlen == 64
> >+ union {
> >+ int __user *auth_flavours; /* 1 */
> >+ __u64 __auth_flavours;
> >+ };
> >+#else
> > int __user *auth_flavours; /* 1 */
> >+#endif
> > };
> >
> > /* bits in the flags field */
> >diff --git a/include/uapi/linux/ppp-ioctl.h b/include/uapi/linux/ppp-ioctl.h
> >index 1cc5ce0ae062..8d48eab430c1 100644
> >--- a/include/uapi/linux/ppp-ioctl.h
> >+++ b/include/uapi/linux/ppp-ioctl.h
> >@@ -59,7 +59,14 @@ struct npioctl {
> >
> > /* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
> > struct ppp_option_data {
> >+#if __riscv_xlen == 64
> >+ union {
> >+ __u8 __user *ptr;
> >+ __u64 __ptr;
> >+ };
> >+#else
> > __u8 __user *ptr;
> >+#endif
> > __u32 length;
> > int transmit;
> > };
> >diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> >index b7d91d4cf0db..46a06fddcd2f 100644
> >--- a/include/uapi/linux/sctp.h
> >+++ b/include/uapi/linux/sctp.h
> >@@ -1024,6 +1024,9 @@ struct sctp_getaddrs_old {
> > #else
> > struct sockaddr *addrs;
> > #endif
> >+#if (__riscv_xlen == 64) && (__SIZEOF_LONG__ == 4)
> >+ __u32 unused;
> >+#endif
> > };
>
>
> >
> > struct sctp_getaddrs {
> >diff --git a/include/uapi/linux/sem.h b/include/uapi/linux/sem.h
> >index 75aa3b273cd9..de9f441913cd 100644
> >--- a/include/uapi/linux/sem.h
> >+++ b/include/uapi/linux/sem.h
> >@@ -26,10 +26,29 @@ struct semid_ds {
> > struct ipc_perm sem_perm; /* permissions .. see ipc.h */
> > __kernel_old_time_t sem_otime; /* last semop time */
> > __kernel_old_time_t sem_ctime; /* create/last semctl() time */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ struct sem *sem_base; /* ptr to first semaphore in array */
> >+ __u64 __sem_base;
> >+ };
> >+ union {
> >+ struct sem_queue *sem_pending; /* pending operations to be processed */
> >+ __u64 __sem_pending;
> >+ };
> >+ union {
> >+ struct sem_queue **sem_pending_last; /* last pending operation */
> >+ __u64 __sem_pending_last;
> >+ };
> >+ union {
> >+ struct sem_undo *undo; /* undo requests on this array */
> >+ __u64 __undo;
> >+ };
> >+#else
> > struct sem *sem_base; /* ptr to first semaphore in array */
> > struct sem_queue *sem_pending; /* pending operations to be processed */
> > struct sem_queue **sem_pending_last; /* last pending operation */
> > struct sem_undo *undo; /* undo requests on this array */
> >+#endif
> > unsigned short sem_nsems; /* no. of semaphores in array */
> > };
> >
> >@@ -46,10 +65,29 @@ struct sembuf {
> > /* arg for semctl system calls. */
> > union semun {
> > int val; /* value for SETVAL */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
> >+ __u64 ___buf;
> >+ };
> >+ union {
> >+ unsigned short __user *array; /* array for GETALL & SETALL */
> >+ __u64 __array;
> >+ };
> >+ union {
> >+ struct seminfo __user *__buf; /* buffer for IPC_INFO */
> >+ __u64 ____buf;
> >+ };
> >+ union {
> >+ void __user *__pad;
> >+ __u64 ____pad;
> >+ };
> >+#else
> > struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
> > unsigned short __user *array; /* array for GETALL & SETALL */
> > struct seminfo __user *__buf; /* buffer for IPC_INFO */
> > void __user *__pad;
> >+#endif
> > };
> >
> > struct seminfo {
> >diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
> >index d3fcd3b5ec53..5f7a83649395 100644
> >--- a/include/uapi/linux/socket.h
> >+++ b/include/uapi/linux/socket.h
> >@@ -22,7 +22,14 @@ struct __kernel_sockaddr_storage {
> > /* space to achieve desired size, */
> > /* _SS_MAXSIZE value minus size of ss_family */
> > };
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void *__align; /* implementation specific desired alignment */
> >+ u64 ___align;
> >+ };
> >+#else
> > void *__align; /* implementation specific desired alignment */
> >+#endif
> > };
> > };
> >
> >diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
> >index 8981f00204db..8ed7b29897f9 100644
> >--- a/include/uapi/linux/sysctl.h
> >+++ b/include/uapi/linux/sysctl.h
> >@@ -33,13 +33,45 @@
> > member of a struct __sysctl_args to have? */
> >
> > struct __sysctl_args {
> >+#if __riscv_xlen == 64
> >+ union {
> >+ int __user *name;
> >+ __u64 __name;
> >+ };
> >+#else
> > int __user *name;
> >+#endif
> > int nlen;
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *oldval;
> >+ __u64 __oldval;
> >+ };
> >+#else
> > void __user *oldval;
> >+#endif
> >+#if __riscv_xlen == 64
> >+ union {
> >+ size_t __user *oldlenp;
> >+ __u64 __oldlenp;
> >+ };
> >+#else
> > size_t __user *oldlenp;
> >+#endif
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *newval;
> >+ __u64 __newval;
> >+ };
> >+#else
> > void __user *newval;
> >+#endif
> > size_t newlen;
> >+#if __riscv_xlen == 64
> >+ unsigned long long __unused[4];
> >+#else
> > unsigned long __unused[4];
> >+#endif
> > };
> >
> > /* Define sysctl names first */
> >diff --git a/include/uapi/linux/uhid.h b/include/uapi/linux/uhid.h
> >index cef7534d2d19..4a774dbd3de8 100644
> >--- a/include/uapi/linux/uhid.h
> >+++ b/include/uapi/linux/uhid.h
> >@@ -130,7 +130,14 @@ struct uhid_create_req {
> > __u8 name[128];
> > __u8 phys[64];
> > __u8 uniq[64];
> >+#if __riscv_xlen == 64
> >+ union {
> >+ __u8 __user *rd_data;
> >+ __u64 __rd_data;
> >+ };
> >+#else
> > __u8 __user *rd_data;
> >+#endif
> > __u16 rd_size;
> >
> > __u16 bus;
> >diff --git a/include/uapi/linux/uio.h b/include/uapi/linux/uio.h
> >index 649739e0c404..27dfd6032dc6 100644
> >--- a/include/uapi/linux/uio.h
> >+++ b/include/uapi/linux/uio.h
> >@@ -16,8 +16,19 @@
> >
> > struct iovec
> > {
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
> >+ __u64 __iov_base;
> >+ };
> >+ union {
> >+ __kernel_size_t iov_len; /* Must be size_t (1003.1g) */
> >+ __u64 __iov_len;
> >+ };
> >+#else
> > void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
> > __kernel_size_t iov_len; /* Must be size_t (1003.1g) */
> >+#endif
> > };
> >
> > struct dmabuf_cmsg {
> >diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
> >index d791cc58a7f0..443ec5356caf 100644
> >--- a/include/uapi/linux/usb/tmc.h
> >+++ b/include/uapi/linux/usb/tmc.h
> >@@ -51,7 +51,14 @@ struct usbtmc_request {
> >
> > struct usbtmc_ctrlrequest {
> > struct usbtmc_request req;
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *data; /* pointer to user space */
> >+ __u64 __data; /* pointer to user space */
> >+ };
> >+#else
> > void __user *data; /* pointer to user space */
> >+#endif
> > } __attribute__ ((packed));
> >
> > struct usbtmc_termchar {
> >@@ -70,7 +77,14 @@ struct usbtmc_message {
> > __u32 transfer_size; /* size of bytes to transfer */
> > __u32 transferred; /* size of received/written bytes */
> > __u32 flags; /* bit 0: 0 = synchronous; 1 = asynchronous */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *message; /* pointer to header and data in user space */
> >+ __u64 __message;
> >+ };
> >+#else
> > void __user *message; /* pointer to header and data in user space */
> >+#endif
> > } __attribute__ ((packed));
> >
> > /* Request values for USBTMC driver's ioctl entry point */
> >diff --git a/include/uapi/linux/usbdevice_fs.h b/include/uapi/linux/usbdevice_fs.h
> >index 74a84e02422a..8c8efef74c3c 100644
> >--- a/include/uapi/linux/usbdevice_fs.h
> >+++ b/include/uapi/linux/usbdevice_fs.h
> >@@ -44,14 +44,28 @@ struct usbdevfs_ctrltransfer {
> > __u16 wIndex;
> > __u16 wLength;
> > __u32 timeout; /* in milliseconds */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *data;
> >+ __u64 __data;
> >+ };
> >+#else
> > void __user *data;
> >+#endif
> > };
> >
> > struct usbdevfs_bulktransfer {
> > unsigned int ep;
> > unsigned int len;
> > unsigned int timeout; /* in milliseconds */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *data;
> >+ __u64 __data;
> >+ };
> >+#else
> > void __user *data;
> >+#endif
> > };
> >
> > struct usbdevfs_setinterface {
> >@@ -61,7 +75,14 @@ struct usbdevfs_setinterface {
> >
> > struct usbdevfs_disconnectsignal {
> > unsigned int signr;
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *context;
> >+ __u64 __context;
> >+ };
> >+#else
> > void __user *context;
> >+#endif
> > };
> >
> > #define USBDEVFS_MAXDRIVERNAME 255
> >@@ -119,7 +140,14 @@ struct usbdevfs_urb {
> > unsigned char endpoint;
> > int status;
> > unsigned int flags;
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *buffer;
> >+ __u64 __buffer;
> >+ };
> >+#else
> > void __user *buffer;
> >+#endif
> > int buffer_length;
> > int actual_length;
> > int start_frame;
> >@@ -130,7 +158,14 @@ struct usbdevfs_urb {
> > int error_count;
> > unsigned int signr; /* signal to be sent on completion,
> > or 0 if none should be sent. */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *usercontext;
> >+ __u64 __usercontext;
> >+ };
> >+#else
> > void __user *usercontext;
> >+#endif
> > struct usbdevfs_iso_packet_desc iso_frame_desc[];
> > };
> >
> >@@ -139,7 +174,14 @@ struct usbdevfs_ioctl {
> > int ifno; /* interface 0..N ; negative numbers reserved */
> > int ioctl_code; /* MUST encode size + direction of data so the
> > * macros in <asm/ioctl.h> give correct values */
> >+#if __riscv_xlen == 64
> >+ union {
> >+ void __user *data; /* param buffer (in, or out) */
> >+ __u64 __pad;
> >+ };
> >+#else
> > void __user *data; /* param buffer (in, or out) */
> >+#endif
> > };
> >
> > /* You can do most things with hubs just through control messages,
> >@@ -195,9 +237,17 @@ struct usbdevfs_streams {
> > #define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb)
> > #define USBDEVFS_SUBMITURB32 _IOR('U', 10, struct usbdevfs_urb32)
> > #define USBDEVFS_DISCARDURB _IO('U', 11)
> >+#if __riscv_xlen == 64
> >+#define USBDEVFS_REAPURB _IOW('U', 12, __u64)
> >+#else
> > #define USBDEVFS_REAPURB _IOW('U', 12, void *)
> >+#endif
> > #define USBDEVFS_REAPURB32 _IOW('U', 12, __u32)
> >+#if __riscv_xlen == 64
> >+#define USBDEVFS_REAPURBNDELAY _IOW('U', 13, __u64)
> >+#else
> > #define USBDEVFS_REAPURBNDELAY _IOW('U', 13, void *)
> >+#endif
> > #define USBDEVFS_REAPURBNDELAY32 _IOW('U', 13, __u32)
> > #define USBDEVFS_DISCSIGNAL _IOR('U', 14, struct usbdevfs_disconnectsignal)
> > #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
> >diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h
> >index f86185456dc5..3ccb99039a43 100644
> >--- a/include/uapi/linux/uvcvideo.h
> >+++ b/include/uapi/linux/uvcvideo.h
> >@@ -54,7 +54,14 @@ struct uvc_xu_control_mapping {
> > __u32 v4l2_type;
> > __u32 data_type;
> >
> >+#if __riscv_xlen == 64
> >+ union {
> >+ struct uvc_menu_info __user *menu_info;
> >+ __u64 __menu_info;
> >+ };
> >+#else
> > struct uvc_menu_info __user *menu_info;
> >+#endif
> > __u32 menu_count;
> >
> > __u32 reserved[4];
> >@@ -66,7 +73,14 @@ struct uvc_xu_control_query {
> > __u8 query; /* Video Class-Specific Request Code, */
> > /* defined in linux/usb/video.h A.8. */
> > __u16 size;
> >+#if __riscv_xlen == 64
> >+ union {
> >+ __u8 __user *data;
> >+ __u64 __data;
> >+ };
> >+#else
> > __u8 __user *data;
> >+#endif
> > };
> >
> > #define UVCIOC_CTRL_MAP _IOWR('u', 0x20, struct uvc_xu_control_mapping)
> >diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> >index c8dbf8219c4f..0a1dc2a780fb 100644
> >--- a/include/uapi/linux/vfio.h
> >+++ b/include/uapi/linux/vfio.h
> >@@ -1570,7 +1570,14 @@ struct vfio_iommu_type1_dma_map {
> > struct vfio_bitmap {
> > __u64 pgsize; /* page size for bitmap in bytes */
> > __u64 size; /* in bytes */
> >+ #if __riscv_xlen == 64
> >+ union {
> >+ __u64 __user *data; /* one bit per page */
> >+ __u64 __data;
> >+ };
> >+ #else
> > __u64 __user *data; /* one bit per page */
> >+ #endif
> > };
> >
> > /**
> >diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> >index e7c4dce39007..8e5391f07626 100644
> >--- a/include/uapi/linux/videodev2.h
> >+++ b/include/uapi/linux/videodev2.h
> >@@ -1898,7 +1898,14 @@ struct v4l2_ext_controls {
> > __u32 error_idx;
> > __s32 request_fd;
> > __u32 reserved[1];
> >+#if __riscv_xlen == 64
> >+ union {
> >+ struct v4l2_ext_control *controls;
> >+ __u64 __controls;
> >+ };
> >+#else
> > struct v4l2_ext_control *controls;
> >+#endif
> > };
> >
> > #define V4L2_CTRL_ID_MASK (0x0fffffff)
> >--
> >2.40.1
> >
> >
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 13:17 ` Arnd Bergmann
@ 2025-03-26 6:07 ` Guo Ren
2025-03-26 6:55 ` Arnd Bergmann
0 siblings, 1 reply; 63+ messages in thread
From: Guo Ren @ 2025-03-26 6:07 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Peter Zijlstra, Greg Kroah-Hartman, Linus Torvalds, Paul Walmsley,
Palmer Dabbelt, Anup Patel, Atish Patra, Oleg Nesterov, Kees Cook,
Thomas Gleixner, Will Deacon, Mark Rutland, Christian Brauner,
Andrew Morton, Steven Rostedt, Eric Dumazet, Chen Wang,
Inochi Amaoto, gaohan, shihua, jiawei, wuwei2016, Drew Fustini,
Lad, Prabhakar, ctsai390, wefu, Jakub Kicinski, Paolo Abeni,
Josef Bacik, David Sterba, Ingo Molnar, Boqun Feng, Xiao W Wang,
qingfang.deng, Leonardo Bras, Jisheng Zhang, Conor.Dooley,
Samuel Holland, yongxuan.wang, Xu Lu, David Hildenbrand,
Ruan Jinjie, Yunhui Cui, Kefeng Wang, qiaozhe, Ard Biesheuvel,
Alexei Starovoitov, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, Linux-Arch, maple-tree,
linux-trace-kernel, Netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Tue, Mar 25, 2025 at 9:18 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Tue, Mar 25, 2025, at 13:26, Peter Zijlstra wrote:
> > On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
> >> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
> >>
> >> Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
> >> but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
> >
> > Please, don't do this. This adds a significant maintenance burden on all
> > of us.
>
> It would be easier to this with CONFIG_64BIT disabled and continue
> treating CONFIG_64BIT to be the same as BITS_PER_LONG=64, but I still
> think it's fundamentally a bad idea to support this in mainline
> kernels in any variation, other than supporting regular 32-bit
> compat mode tasks on a regular 64-bit kernel.
>
> >> The patchset targets RISC-V and is built on the RV64ILP32 ABI, which
> >> was introduced into RISC-V's psABI in January 2025 [1]. This patchset
> >> equips an rv64ilp32-abi kernel with all the functionalities of a
> >> traditional lp64-abi kernel, yet restricts the address space to 2GiB.
> >> Hence, the rv64ilp32-abi kernel simultaneously supports lp64-abi
> >> userspace and ilp32-abi (compat) userspace, the same as the
> >> traditional lp64-abi kernel.
>
> You declare the syscall ABI to be the native 64-bit ABI, but this
> is fundamentally not true because a many uapi structures are
> defined in terms of 'long' or pointer values, in particular in
> the ioctl call.
I modified uapi with
void __user *msg_name;
->
union {void __user *msg_name; u64 __msg_name;};
to make native 64-bit ABI.
I would look at compat stuff instead of using __riscv_xlen macro.
> This might work for an rv64ilp32 userspace that
> uses the same headers and the same types, but you explicitly
> say that the goal is to run native rv64 or compat rv32 tasks,
> not rv64ilp32 (thanks!).
It's not for rv64ilp32-abi userspace, no rv64ilp32-abi userspace
introduced in the patch set.
It's for native lp64-abi.
Let's discuss this in the first patch thread:
uapi: Reuse lp64 ABI interface
>
> As far as I can tell, there is no way to rectify this design flaw
> other than to drop support for 64-bit userspace and only support
> regular rv32 userspace. I'm also skeptical that supporting rv64
> userspace helps in practice other than for testing, since
> generally most memory overhead is in userspace rather than the
> kernel, and there is much more to gain from shrinking the larger
> userspace by running rv32 compat mode binaries on a 64-bit kernel
> than the other way round.
The lp64-abi userspace rootfs works fine in this patch set, which
proves the technique is valid. But the modification on uapi is raw,
and I'm looking at compat stuff.
Supporting lp64-abi userspace is essential because riscv lp64-abi and
ilp32-abi userspace are hybrid deployments when the target is
ilp32-abi userspace. The lp64-abi provides a good supplement to
ilp32-abi which eases the development.
>
> If you remove the CONFIG_64BIT changes that Peter mentioned and
> the support for ilp64 userland from your series, you end up
> with a kernel that is very similar to a native rv32 kernel
> but executes as rv64ilp32 and runs rv32 userspace. I don't have
> any objections to that approach, and the same thing has come
> up on arm64 as a possible idea as well, but I don't know if
> that actually brings any notable advantage over an rv32 kernel.
>
> Are there CPUs that can run rv64 kernels and rv32 userspace
> but not rv32 kernels, similar to what we have on Arm Cortex-A76
> and Cortex-A510?
Yes, there is, and it only supports rv32 userspace, not rv32 kernel.
https://www.xrvm.com/product/xuantie/C908
Here are the products:
https://developer.canaan-creative.com/k230_canmv/en/dev/userguide/boards/canmv_k230d.html
http://riscv.org/ecosystem-news/2024/07/unpacking-the-canmv-k230-risc-v-board/
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
2025-03-25 20:41 ` Linus Torvalds
@ 2025-03-26 6:34 ` Guo Ren
2025-03-27 16:20 ` Palmer Dabbelt
1 sibling, 0 replies; 63+ messages in thread
From: Guo Ren @ 2025-03-26 6:34 UTC (permalink / raw)
To: Linus Torvalds
Cc: arnd, gregkh, paul.walmsley, palmer, anup, atishp, oleg, kees,
tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Wed, Mar 26, 2025 at 4:41 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Tue, 25 Mar 2025 at 05:17, <guoren@kernel.org> wrote:
> >
> > The rv64ilp32 abi kernel accommodates the lp64 abi userspace and
> > leverages the lp64 abi Linux interface. Hence, unify the
> > BITS_PER_LONG = 32 memory layout to match BITS_PER_LONG = 64.
>
> No.
>
> This isn't happening.
>
> You can't do crazy things in the RISC-V code and then expect the rest
> of the kernel to just go "ok, we'll do crazy things".
>
> We're not doing crazy __riscv_xlen hackery with random structures
> containing 64-bit values that the kernel then only looks at the low 32
> bits. That's wrong on *so* many levels.
>
> I'm willing to say "big-endian is dead", but I'm not willing to accept
> this kind of crazy hackery.
>
> Not today, not ever.
>
> If you want to run a ilp32 kernel on 64-bit hardware (and support
> 64-bit ABI just in a 32-bit virtual memory size), I would suggest you
>
> (a) treat the kernel as natively 32-bit (obviously you can then tell
> the compiler to use the rv64 instructions, which I presume you're
> already doing - I didn't look)
I used CONFIG_32BIT in v1 and v2, but I've abandoned them because,
based on CONFIG_64BIT, I gain more functionality by inheriting the
lp64-abi kernel. I want the full functionality of the CONFIG_64BIT
Linux kernel, which can be equivalent, used interchangeably, and
seamlessly.
>
> (b) look at making the compat stuff do the conversion the "wrong way".
>
> And btw, that (b) implies *not* just ignoring the high bits. If
> user-space gives 64-bit pointer, you don't just treat it as a 32-bit
> one by dropping the high bits. You add some logic to convert it to an
> invalid pointer so that user space gets -EFAULT.
Thanks for the advice. I'm looking at how to make the compat stuff.
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-26 6:07 ` Guo Ren
@ 2025-03-26 6:55 ` Arnd Bergmann
2025-03-27 13:13 ` Guo Ren
0 siblings, 1 reply; 63+ messages in thread
From: Arnd Bergmann @ 2025-03-26 6:55 UTC (permalink / raw)
To: guoren
Cc: Peter Zijlstra, Greg Kroah-Hartman, Linus Torvalds, Paul Walmsley,
Palmer Dabbelt, Anup Patel, Atish Patra, Oleg Nesterov, Kees Cook,
Thomas Gleixner, Will Deacon, Mark Rutland, Christian Brauner,
Andrew Morton, Steven Rostedt, Eric Dumazet, Chen Wang,
Inochi Amaoto, gaohan, shihua, jiawei, wuwei2016, Drew Fustini,
Lad, Prabhakar, ctsai390, wefu, Jakub Kicinski, Paolo Abeni,
Josef Bacik, David Sterba, Ingo Molnar, Boqun Feng, Xiao W Wang,
qingfang.deng, Leonardo Bras, Jisheng Zhang, Conor.Dooley,
Samuel Holland, yongxuan.wang, Xu Lu, David Hildenbrand,
Ruan Jinjie, Yunhui Cui, Kefeng Wang, qiaozhe, Ard Biesheuvel,
Alexei Starovoitov, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, Linux-Arch, maple-tree,
linux-trace-kernel, Netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Wed, Mar 26, 2025, at 07:07, Guo Ren wrote:
> On Tue, Mar 25, 2025 at 9:18 PM Arnd Bergmann <arnd@arndb.de> wrote:
>> On Tue, Mar 25, 2025, at 13:26, Peter Zijlstra wrote:
>> > On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
>>
>> You declare the syscall ABI to be the native 64-bit ABI, but this
>> is fundamentally not true because a many uapi structures are
>> defined in terms of 'long' or pointer values, in particular in
>> the ioctl call.
>
> I modified uapi with
> void __user *msg_name;
> ->
> union {void __user *msg_name; u64 __msg_name;};
> to make native 64-bit ABI.
>
> I would look at compat stuff instead of using __riscv_xlen macro.
The problem I see here is that there are many more drivers
that you did not modify than drivers that you did change this
way. The union is particularly ugly, but even if you find
a nicer method of doing this, you now also put the burden
on future driver writers to do this right for your platform.
>> As far as I can tell, there is no way to rectify this design flaw
>> other than to drop support for 64-bit userspace and only support
>> regular rv32 userspace. I'm also skeptical that supporting rv64
>> userspace helps in practice other than for testing, since
>> generally most memory overhead is in userspace rather than the
>> kernel, and there is much more to gain from shrinking the larger
>> userspace by running rv32 compat mode binaries on a 64-bit kernel
>> than the other way round.
>
> The lp64-abi userspace rootfs works fine in this patch set, which
> proves the technique is valid. But the modification on uapi is raw,
> and I'm looking at compat stuff.
There is a big difference between making it work for a particular
set of userspace binaries and making it correct for the entire
kernel ABI.
I agree that limiting the hacks to the compat side while keeping
the native ABI as ilp32 as in your previous versions is better,
but I also don't think this can be easily done without major
changes to how compat mode works in general, and that still
seems like a show-stopper for two reasons:
- it still puts the burden on driver writers to get it right
for your platform. The scope is a bit smaller than in the
current version because that would be limited to the compat
handlers and not change the native codepath, but that's
still a lot of drivers.
- the way that I would imagine this to be implemented in
practice would require changing the compat code in a way that
allows multiple compat ABIs, so drivers can separate the
normal 32-on-64 handling from the 64-on-32 version you need.
We have discussed something like this in the past, but Linus
has already made it very clear that he doesn't want it done
that way. Whichever way you do it, this is unlikely to
find consensus.
> Supporting lp64-abi userspace is essential because riscv lp64-abi and
> ilp32-abi userspace are hybrid deployments when the target is
> ilp32-abi userspace. The lp64-abi provides a good supplement to
> ilp32-abi which eases the development.
I'm not following here, please clarify. I do understand that
having a mixed 32/64 userspace can help for development, but
that can already be done on a 64-bit kernel and it doesn't
seem to be useful for deployment because having two sets of
support libraries makes this counterproductive for the goal
of saving RAM.
>> If you remove the CONFIG_64BIT changes that Peter mentioned and
>> the support for ilp64 userland from your series, you end up
>> with a kernel that is very similar to a native rv32 kernel
>> but executes as rv64ilp32 and runs rv32 userspace. I don't have
>> any objections to that approach, and the same thing has come
>> up on arm64 as a possible idea as well, but I don't know if
>> that actually brings any notable advantage over an rv32 kernel.
>>
>> Are there CPUs that can run rv64 kernels and rv32 userspace
>> but not rv32 kernels, similar to what we have on Arm Cortex-A76
>> and Cortex-A510?
>
> Yes, there is, and it only supports rv32 userspace, not rv32 kernel.
> https://www.xrvm.com/product/xuantie/C908
Ok, thanks for the link.
Arnd
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv
2025-03-25 17:19 ` Sergey Shtylyov
@ 2025-03-26 9:22 ` Guo Ren
0 siblings, 0 replies; 63+ messages in thread
From: Guo Ren @ 2025-03-26 9:22 UTC (permalink / raw)
To: Sergey Shtylyov
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Wed, Mar 26, 2025 at 1:19 AM Sergey Shtylyov <s.shtylyov@omp.ru> wrote:
>
> On 3/25/25 3:16 PM, guoren@kernel.org wrote:
>
> > From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
> >
> > The rv64ilp32 abi reuses the env and argv memory layout of the
> > lp64 abi, so leave the space to fit the lp64 struct layout.
> >
> > Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
> > ---
> > fs/exec.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/fs/exec.c b/fs/exec.c
> > index 506cd411f4ac..548d18b7ae92 100644
> > --- a/fs/exec.c
> > +++ b/fs/exec.c
> > @@ -424,6 +424,10 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
> > }
> > #endif
> >
> > +#if defined(CONFIG_64BIT) && (BITS_PER_LONG == 32)
okay, #if defined(CONFIG_64BIT) && BITS_PER_LONG == 32
>
> Parens don't seem necessary...
>
> > + nr = nr * 2;
>
> Why not nr *= 2?
okay, nr *= 2;
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
2025-03-25 19:09 ` Liam R. Howlett
@ 2025-03-27 12:47 ` Guo Ren
0 siblings, 0 replies; 63+ messages in thread
From: Guo Ren @ 2025-03-27 12:47 UTC (permalink / raw)
To: Liam R. Howlett, guoren, arnd, gregkh, torvalds, paul.walmsley,
palmer, anup, atishp, oleg, kees, tglx, will, mark.rutland,
brauner, akpm, rostedt, edumazet, unicorn_wang, inochiama, gaohan,
shihua, jiawei, wuwei2016, drew, prabhakar.mahadev-lad.rj,
ctsai390, wefu, kuba, pabeni, josef, dsterba, mingo, peterz,
boqun.feng, xiao.w.wang, qingfang.deng, leobras, jszhang,
conor.dooley, samuel.holland, yongxuan.wang, luxu.kernel, david,
ruanjinjie, cuiyunhui, wangkefeng.wang, qiaozhe, ardb, ast,
linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm, linux-crypto,
bpf, linux-input, linux-perf-users, linux-serial, linux-fsdevel,
linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On Wed, Mar 26, 2025 at 3:10 AM Liam R. Howlett <Liam.Howlett@oracle.com> wrote:
>
> * guoren@kernel.org <guoren@kernel.org> [250325 08:24]:
> > From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
> >
> > The Maple tree algorithm uses ulong type for each element. The
> > number of slots is based on BITS_PER_LONG for RV64ILP32 ABI, so
> > use BITS_PER_LONG instead of CONFIG_64BIT.
> >
> > Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
> > ---
> > include/linux/maple_tree.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h
> > index cbbcd18d4186..ff6265b6468b 100644
> > --- a/include/linux/maple_tree.h
> > +++ b/include/linux/maple_tree.h
> > @@ -24,7 +24,7 @@
> > *
> > * Nodes in the tree point to their parent unless bit 0 is set.
> > */
> > -#if defined(CONFIG_64BIT) || defined(BUILD_VDSO32_64)
> > +#if (BITS_PER_LONG == 64) || defined(BUILD_VDSO32_64)
>
> This will break my userspace testing, if you do not update the testing as
> well. This can be found in tools/testing/radix-tree. Please also look
> at the Makefile as well since it will generate a build flag for the
> userspace.
I think you are talking about the following:
============================================================
../shared/shared.mk:
ifndef LONG_BIT
LONG_BIT := $(shell getconf LONG_BIT)
endif
generated/bit-length.h: FORCE
@mkdir -p generated
@if ! grep -qws CONFIG_$(LONG_BIT)BIT generated/bit-length.h; then \
echo "Generating $@"; \
echo "#define CONFIG_$(LONG_BIT)BIT 1" > $@; \
echo "#define CONFIG_PHYS_ADDR_T_$(LONG_BIT)BIT 1" >> $@; \
fi
$ grep CONFIG_64BIT * -r -A 2
generated/bit-length.h:#define CONFIG_64BIT 1
generated/bit-length.h-#define CONFIG_PHYS_ADDR_T_64BIT 1
--
maple.c:#if defined(CONFIG_64BIT)
maple.c-static noinline void __init check_erase2_testset(struct maple_tree *mt,
maple.c- const unsigned long *set, unsigned long size)
--
maple.c:#if CONFIG_64BIT
maple.c- MT_BUG_ON(mt, data_end != mas_data_end(&mas));
maple.c-#endif
--
maple.c:#if CONFIG_64BIT
maple.c- MT_BUG_ON(mt, data_end - 2 != mas_data_end(&mas));
maple.c-#endif
--
maple.c:#if CONFIG_64BIT
maple.c- MT_BUG_ON(mt, data_end - 4 != mas_data_end(&mas));
maple.c-#endif
--
maple.c:#if defined(CONFIG_64BIT)
maple.c- /* Captures from VMs that found previous errors */
maple.c- mt_init_flags(&tree, 0);
============================================================
First, we don't introduce rv64ilp32-abi user space, which means these
testing codes can't run on rv64ilp32-abi userspace currently. So, the
problem you mentioned doesn't exist.
Second, CONFIG_32BIT is determined by LONG_BIT, so there's no issue in
maple.c with future rv64ilp32-abi userspace.
That means rv64ilp32-abi userspace would use CONFIG_32BIT to test
radix-tree. It's okay.
>
> This raises other concerns as the code is found with a grep command, so
> I'm not sure why it was missed and if anything else is missed?
>
> If you consider this email to be the (unasked) question about what to do
> here, then please CC me, the maintainer of the files including the one
> you are updating here.
>
> Thank you,
> Liam
>
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-26 6:55 ` Arnd Bergmann
@ 2025-03-27 13:13 ` Guo Ren
0 siblings, 0 replies; 63+ messages in thread
From: Guo Ren @ 2025-03-27 13:13 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Peter Zijlstra, Greg Kroah-Hartman, Linus Torvalds, Paul Walmsley,
Palmer Dabbelt, Anup Patel, Atish Patra, Oleg Nesterov, Kees Cook,
Thomas Gleixner, Will Deacon, Mark Rutland, Christian Brauner,
Andrew Morton, Steven Rostedt, Eric Dumazet, Chen Wang,
Inochi Amaoto, gaohan, shihua, jiawei, wuwei2016, Drew Fustini,
Lad, Prabhakar, ctsai390, wefu, Jakub Kicinski, Paolo Abeni,
Josef Bacik, David Sterba, Ingo Molnar, Boqun Feng, Xiao W Wang,
qingfang.deng, Leonardo Bras, Jisheng Zhang, Conor.Dooley,
Samuel Holland, yongxuan.wang, Xu Lu, David Hildenbrand,
Ruan Jinjie, Yunhui Cui, Kefeng Wang, qiaozhe, Ard Biesheuvel,
Alexei Starovoitov, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, Linux-Arch, maple-tree,
linux-trace-kernel, Netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Wed, Mar 26, 2025 at 2:56 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Wed, Mar 26, 2025, at 07:07, Guo Ren wrote:
> > On Tue, Mar 25, 2025 at 9:18 PM Arnd Bergmann <arnd@arndb.de> wrote:
> >> On Tue, Mar 25, 2025, at 13:26, Peter Zijlstra wrote:
> >> > On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
> >>
> >> You declare the syscall ABI to be the native 64-bit ABI, but this
> >> is fundamentally not true because a many uapi structures are
> >> defined in terms of 'long' or pointer values, in particular in
> >> the ioctl call.
> >
> > I modified uapi with
> > void __user *msg_name;
> > ->
> > union {void __user *msg_name; u64 __msg_name;};
> > to make native 64-bit ABI.
> >
> > I would look at compat stuff instead of using __riscv_xlen macro.
>
> The problem I see here is that there are many more drivers
> that you did not modify than drivers that you did change this
> way. The union is particularly ugly, but even if you find
> a nicer method of doing this, you now also put the burden
> on future driver writers to do this right for your platform.
Got it.
>
> >> As far as I can tell, there is no way to rectify this design flaw
> >> other than to drop support for 64-bit userspace and only support
> >> regular rv32 userspace. I'm also skeptical that supporting rv64
> >> userspace helps in practice other than for testing, since
> >> generally most memory overhead is in userspace rather than the
> >> kernel, and there is much more to gain from shrinking the larger
> >> userspace by running rv32 compat mode binaries on a 64-bit kernel
> >> than the other way round.
> >
> > The lp64-abi userspace rootfs works fine in this patch set, which
> > proves the technique is valid. But the modification on uapi is raw,
> > and I'm looking at compat stuff.
>
> There is a big difference between making it work for a particular
> set of userspace binaries and making it correct for the entire
> kernel ABI.
>
> I agree that limiting the hacks to the compat side while keeping
> the native ABI as ilp32 as in your previous versions is better,
> but I also don't think this can be easily done without major
> changes to how compat mode works in general, and that still
> seems like a show-stopper for two reasons:
>
> - it still puts the burden on driver writers to get it right
> for your platform. The scope is a bit smaller than in the
> current version because that would be limited to the compat
> handlers and not change the native codepath, but that's
> still a lot of drivers.
>
> - the way that I would imagine this to be implemented in
> practice would require changing the compat code in a way that
> allows multiple compat ABIs, so drivers can separate the
> normal 32-on-64 handling from the 64-on-32 version you need.
> We have discussed something like this in the past, but Linus
> has already made it very clear that he doesn't want it done
> that way. Whichever way you do it, this is unlikely to
> find consensus.
Got it, thanks for analysing.
>
> > Supporting lp64-abi userspace is essential because riscv lp64-abi and
> > ilp32-abi userspace are hybrid deployments when the target is
> > ilp32-abi userspace. The lp64-abi provides a good supplement to
> > ilp32-abi which eases the development.
>
> I'm not following here, please clarify. I do understand that
> having a mixed 32/64 userspace can help for development, but
> that can already be done on a 64-bit kernel and it doesn't
> seem to be useful for deployment because having two sets of
> support libraries makes this counterproductive for the goal
> of saving RAM.
In my case, most binaries and libraries are based on 32-bit, but a
small part would remain on 64-bit, which may be statically linked.
For RISC-V, the rv64 ecosystem is more complete than the rv32's. So,
rv64-abi is always necessary, and rv32-abi is a supplement.
>
> >> If you remove the CONFIG_64BIT changes that Peter mentioned and
> >> the support for ilp64 userland from your series, you end up
> >> with a kernel that is very similar to a native rv32 kernel
> >> but executes as rv64ilp32 and runs rv32 userspace. I don't have
> >> any objections to that approach, and the same thing has come
> >> up on arm64 as a possible idea as well, but I don't know if
> >> that actually brings any notable advantage over an rv32 kernel.
> >>
> >> Are there CPUs that can run rv64 kernels and rv32 userspace
> >> but not rv32 kernels, similar to what we have on Arm Cortex-A76
> >> and Cortex-A510?
> >
> > Yes, there is, and it only supports rv32 userspace, not rv32 kernel.
> > https://www.xrvm.com/product/xuantie/C908
>
> Ok, thanks for the link.
>
> Arnd
>
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 19:23 ` Liam R. Howlett
@ 2025-03-27 16:20 ` Palmer Dabbelt
0 siblings, 0 replies; 63+ messages in thread
From: Palmer Dabbelt @ 2025-03-27 16:20 UTC (permalink / raw)
To: Liam.Howlett
Cc: david, peterz, guoren, Arnd Bergmann, Greg KH, Linus Torvalds,
Paul Walmsley, anup, atishp, oleg, kees, tglx, Will Deacon,
Mark Rutland, brauner, akpm, rostedt, edumazet, unicorn_wang,
inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, boqun.feng, xiao.w.wang, qingfang.deng, leobras,
jszhang, Conor Dooley, samuel.holland, yongxuan.wang, luxu.kernel,
ruanjinjie, cuiyunhui, wangkefeng.wang, qiaozhe, Ard Biesheuvel,
ast, linux-kernel, linux-riscv, kvm, kvm-riscv, linux-mm,
linux-crypto, bpf, linux-input, linux-perf-users, linux-serial,
linux-fsdevel, linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On Tue, 25 Mar 2025 12:23:39 PDT (-0700), Liam.Howlett@oracle.com wrote:
> * David Hildenbrand <david@redhat.com> [250325 14:52]:
>> On 25.03.25 13:26, Peter Zijlstra wrote:
>> > On Tue, Mar 25, 2025 at 08:15:41AM -0400, guoren@kernel.org wrote:
>> > > From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>> > >
>> > > Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
>> > > but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
>> >
>> > I'm thinking you're going to be finding a metric ton of assumptions
>> > about 'unsigned long' being 64bit when 64BIT=y throughout the kernel.
>> >
>> > I know of a couple of places where 64BIT will result in different math
>> > such that a 32bit 'unsigned long' will trivially overflow.
Ya, I write code that assumes "unsigned long" is the size of a register
pretty regularly.
>> >
>> > Please, don't do this. This adds a significant maintenance burden on all
>> > of us.
>> >
>>
>> Fully agreed.
>
> I would go further and say I do not want this to go in.
Seems reasonable to me, and I think it's also been the general sentiment
when this stuff comes up. This specific implementation seems
particularly clunky, but I agree that it's going to be painful to do
this sort of thing.
> The open ended maintenance burden is not worth extending hardware life
> of a board with 16mb of ram (If I understand your 2023 LPC slides
> correctly).
We can already run full 32-bit kernels on 64-bit hardware. The hardware
needs to support configurable XLEN, but there's systems out there that
do already.
It's not like any of the existing RISC-V stuff ships in meaningful
volumes. So I think it's fine to just say that vendors who want tiny
memories should build hardware that plays nice with those constraints,
and vendors who build hardware that doesn't make any sense get to pick
up the pieces.
I get RISC-V is where people go to have crazy ideas, but there's got to
be a line somewhere...
>
> Thank you,
> Liam
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
2025-03-25 20:41 ` Linus Torvalds
2025-03-26 6:34 ` Guo Ren
@ 2025-03-27 16:20 ` Palmer Dabbelt
1 sibling, 0 replies; 63+ messages in thread
From: Palmer Dabbelt @ 2025-03-27 16:20 UTC (permalink / raw)
To: Linus Torvalds
Cc: guoren, Arnd Bergmann, Greg KH, Paul Walmsley, anup, atishp, oleg,
kees, tglx, Will Deacon, Mark Rutland, brauner, akpm, rostedt,
edumazet, unicorn_wang, inochiama, gaohan, shihua, jiawei,
wuwei2016, drew, prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba,
pabeni, josef, dsterba, mingo, peterz, boqun.feng, xiao.w.wang,
qingfang.deng, leobras, jszhang, Conor Dooley, samuel.holland,
yongxuan.wang, luxu.kernel, david, ruanjinjie, cuiyunhui,
wangkefeng.wang, qiaozhe, Ard Biesheuvel, ast, linux-kernel,
linux-riscv, kvm, kvm-riscv, linux-mm, linux-crypto, bpf,
linux-input, linux-perf-users, linux-serial, linux-fsdevel,
linux-arch, maple-tree, linux-trace-kernel, netdev,
linux-atm-general, linux-btrfs, netfilter-devel, coreteam,
linux-nfs, linux-sctp, linux-usb, linux-media
On Tue, 25 Mar 2025 13:41:30 PDT (-0700), Linus Torvalds wrote:
> On Tue, 25 Mar 2025 at 05:17, <guoren@kernel.org> wrote:
>>
>> The rv64ilp32 abi kernel accommodates the lp64 abi userspace and
>> leverages the lp64 abi Linux interface. Hence, unify the
>> BITS_PER_LONG = 32 memory layout to match BITS_PER_LONG = 64.
>
> No.
>
> This isn't happening.
>
> You can't do crazy things in the RISC-V code and then expect the rest
> of the kernel to just go "ok, we'll do crazy things".
>
> We're not doing crazy __riscv_xlen hackery with random structures
> containing 64-bit values that the kernel then only looks at the low 32
> bits. That's wrong on *so* many levels.
FWIW: this has come up a few times and we've generally said "nobody
wants this", but that doesn't seem to stick...
> I'm willing to say "big-endian is dead", but I'm not willing to accept
> this kind of crazy hackery.
>
> Not today, not ever.
OK, maybe that will stick ;)
> If you want to run a ilp32 kernel on 64-bit hardware (and support
> 64-bit ABI just in a 32-bit virtual memory size), I would suggest you
>
> (a) treat the kernel as natively 32-bit (obviously you can then tell
> the compiler to use the rv64 instructions, which I presume you're
> already doing - I didn't look)
>
> (b) look at making the compat stuff do the conversion the "wrong way".
>
> And btw, that (b) implies *not* just ignoring the high bits. If
> user-space gives 64-bit pointer, you don't just treat it as a 32-bit
> one by dropping the high bits. You add some logic to convert it to an
> invalid pointer so that user space gets -EFAULT.
>
> Linus
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
` (43 preceding siblings ...)
2025-03-25 12:26 ` [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI Peter Zijlstra
@ 2025-03-27 21:06 ` David Laight
44 siblings, 0 replies; 63+ messages in thread
From: David Laight @ 2025-03-27 21:06 UTC (permalink / raw)
To: guoren
Cc: arnd, gregkh, torvalds, paul.walmsley, palmer, anup, atishp, oleg,
kees, tglx, will, mark.rutland, brauner, akpm, rostedt, edumazet,
unicorn_wang, inochiama, gaohan, shihua, jiawei, wuwei2016, drew,
prabhakar.mahadev-lad.rj, ctsai390, wefu, kuba, pabeni, josef,
dsterba, mingo, peterz, boqun.feng, xiao.w.wang, qingfang.deng,
leobras, jszhang, conor.dooley, samuel.holland, yongxuan.wang,
luxu.kernel, david, ruanjinjie, cuiyunhui, wangkefeng.wang,
qiaozhe, ardb, ast, linux-kernel, linux-riscv, kvm, kvm-riscv,
linux-mm, linux-crypto, bpf, linux-input, linux-perf-users,
linux-serial, linux-fsdevel, linux-arch, maple-tree,
linux-trace-kernel, netdev, linux-atm-general, linux-btrfs,
netfilter-devel, coreteam, linux-nfs, linux-sctp, linux-usb,
linux-media
On Tue, 25 Mar 2025 08:15:41 -0400
guoren@kernel.org wrote:
> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>
> Since 2001, the CONFIG_64BIT kernel has been built with the LP64 ABI,
> but this patchset allows the CONFIG_64BIT kernel to use an ILP32 ABI
> for construction to reduce cache & memory footprint (Compared to
> kernel-lp64-abi, kernel-rv64ilp32-abi decreased the used memory by
> about 20%, as shown in "free -h" in the following demo.)
...
Why on earth would you want to run a 64bit application on a 32bit kernel.
IIRC the main justification for 64bit was to get a larger address space.
Now you might want to compile a 32bit (ILP32) system that actually
runs in 64bit mode (c/f x32) so that 64bit maths (long long) is
more efficient - but that is a different issue.
(I suspect you'd need to change the process switch code to save
all 64bits of the registers - but maybe not much else??)
David
^ permalink raw reply [flat|nested] 63+ messages in thread
end of thread, other threads:[~2025-03-27 21:06 UTC | newest]
Thread overview: 63+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25 12:15 [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI guoren
2025-03-25 12:15 ` [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface guoren
2025-03-25 20:30 ` Jan Engelhardt
2025-03-26 3:35 ` Guo Ren
2025-03-25 20:41 ` Linus Torvalds
2025-03-26 6:34 ` Guo Ren
2025-03-27 16:20 ` Palmer Dabbelt
2025-03-25 12:15 ` [RFC PATCH V3 02/43] rv64ilp32_abi: riscv: Adapt Makefile and Kconfig guoren
2025-03-25 12:15 ` [RFC PATCH V3 03/43] rv64ilp32_abi: riscv: Adapt ULL & UL definition guoren
2025-03-25 12:15 ` [RFC PATCH V3 04/43] rv64ilp32_abi: riscv: Introduce xlen_t to adapt __riscv_xlen != BITS_PER_LONG guoren
2025-03-25 12:15 ` [RFC PATCH V3 05/43] rv64ilp32_abi: riscv: crc32: Utilize 64-bit width to improve the performance guoren
2025-03-25 12:15 ` [RFC PATCH V3 06/43] rv64ilp32_abi: riscv: csum: " guoren
2025-03-25 12:15 ` [RFC PATCH V3 07/43] rv64ilp32_abi: riscv: arch_hweight: Adapt cpopw & cpop of zbb extension guoren
2025-03-25 12:15 ` [RFC PATCH V3 08/43] rv64ilp32_abi: riscv: bitops: Adapt ctzw & clzw " guoren
2025-03-25 12:15 ` [RFC PATCH V3 09/43] rv64ilp32_abi: riscv: Reuse LP64 SBI interface guoren
2025-03-25 12:15 ` [RFC PATCH V3 10/43] rv64ilp32_abi: riscv: Update SATP.MODE.ASID width guoren
2025-03-25 12:15 ` [RFC PATCH V3 11/43] rv64ilp32_abi: riscv: Introduce PTR_L and PTR_S guoren
2025-03-25 12:15 ` [RFC PATCH V3 12/43] rv64ilp32_abi: riscv: Introduce cmpxchg_double guoren
2025-03-25 12:15 ` [RFC PATCH V3 13/43] rv64ilp32_abi: riscv: Correct stackframe layout guoren
2025-03-25 12:15 ` [RFC PATCH V3 14/43] rv64ilp32_abi: riscv: Adapt kernel module code guoren
2025-03-25 12:15 ` [RFC PATCH V3 15/43] rv64ilp32_abi: riscv: mm: Adapt MMU_SV39 for 2GiB address space guoren
2025-03-25 12:15 ` [RFC PATCH V3 16/43] rv64ilp32_abi: riscv: Support physical addresses >= 0x80000000 guoren
2025-03-25 12:15 ` [RFC PATCH V3 17/43] rv64ilp32_abi: riscv: Adapt kasan memory layout guoren
2025-03-25 12:15 ` [RFC PATCH V3 18/43] rv64ilp32_abi: riscv: kvm: Initial support guoren
2025-03-25 12:16 ` [RFC PATCH V3 19/43] rv64ilp32_abi: irqchip: irq-riscv-intc: Use xlen_t instead of ulong guoren
2025-03-25 12:16 ` [RFC PATCH V3 20/43] rv64ilp32_abi: drivers/perf: Adapt xlen_t of sbiret guoren
2025-03-25 12:16 ` [RFC PATCH V3 21/43] rv64ilp32_abi: asm-generic: Add custom BITS_PER_LONG definition guoren
2025-03-25 12:16 ` [RFC PATCH V3 22/43] rv64ilp32_abi: bpf: Change KERN_ARENA_SZ to 256MiB guoren
2025-03-25 12:16 ` [RFC PATCH V3 23/43] rv64ilp32_abi: compat: Correct compat_ulong_t cast guoren
2025-03-25 12:16 ` [RFC PATCH V3 24/43] rv64ilp32_abi: compiler_types: Add "long long" into __native_word() guoren
2025-03-25 12:16 ` [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv guoren
2025-03-25 17:19 ` Sergey Shtylyov
2025-03-26 9:22 ` Guo Ren
2025-03-25 12:16 ` [RFC PATCH V3 26/43] rv64ilp32_abi: file_ref: Use 32-bit width for refcnt guoren
2025-03-25 12:16 ` [RFC PATCH V3 27/43] rv64ilp32_abi: input: Adapt BITS_PER_LONG to dword guoren
2025-03-25 12:16 ` [RFC PATCH V3 28/43] rv64ilp32_abi: iov_iter: Resize kvec to match iov_iter's size guoren
2025-03-25 12:16 ` [RFC PATCH V3 29/43] rv64ilp32_abi: locking/atomic: Use BITS_PER_LONG for scripts guoren
2025-03-25 12:16 ` [RFC PATCH V3 30/43] rv64ilp32_abi: kernel/smp: Disable CSD_LOCK_WAIT_DEBUG guoren
2025-03-25 12:16 ` [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
2025-03-25 19:09 ` Liam R. Howlett
2025-03-27 12:47 ` Guo Ren
2025-03-25 12:16 ` [RFC PATCH V3 32/43] rv64ilp32_abi: mm: Remove _folio_nr_pages guoren
2025-03-25 12:16 ` [RFC PATCH V3 33/43] rv64ilp32_abi: mm/auxvec: Adapt mm->saved_auxv[] to Elf64 guoren
2025-03-25 12:16 ` [RFC PATCH V3 34/43] rv64ilp32_abi: mm: Adapt vm_flags_t struct guoren
2025-03-25 12:16 ` [RFC PATCH V3 35/43] rv64ilp32_abi: net: Use BITS_PER_LONG in struct dst_entry guoren
2025-03-25 12:16 ` [RFC PATCH V3 36/43] rv64ilp32_abi: printf: Use BITS_PER_LONG instead of CONFIG_64BIT guoren
2025-03-25 12:16 ` [RFC PATCH V3 37/43] rv64ilp32_abi: random: Adapt fast_pool struct guoren
2025-03-25 12:16 ` [RFC PATCH V3 38/43] rv64ilp32_abi: syscall: Use CONFIG_64BIT instead of BITS_PER_LONG guoren
2025-03-25 12:16 ` [RFC PATCH V3 39/43] rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi guoren
2025-03-25 12:16 ` [RFC PATCH V3 40/43] rv64ilp32_abi: tracepoint-defs: Using u64 for trace_print_flags.mask guoren
2025-03-25 12:16 ` [RFC PATCH V3 41/43] rv64ilp32_abi: tty: Adapt ptr_to_compat guoren
2025-03-25 12:16 ` [RFC PATCH V3 42/43] rv64ilp32_abi: memfd: Use vm_flag_t guoren
2025-03-25 12:16 ` [RFC PATCH V3 43/43] riscv: Fixup address space overlay of print_mlk guoren
2025-03-25 12:26 ` [RFC PATCH V3 00/43] rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI Peter Zijlstra
2025-03-25 13:13 ` Guo Ren
2025-03-25 13:17 ` Arnd Bergmann
2025-03-26 6:07 ` Guo Ren
2025-03-26 6:55 ` Arnd Bergmann
2025-03-27 13:13 ` Guo Ren
2025-03-25 18:51 ` David Hildenbrand
2025-03-25 19:23 ` Liam R. Howlett
2025-03-27 16:20 ` Palmer Dabbelt
2025-03-27 21:06 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).