rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
Subsystems (48)
v3 cover rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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 ---
Quoted 1 line
CONFIG_PAGE_OFFSET=0xc0000000
308c308
< CONFIG_ILLEGAL_POINTER_VALUE=0xdead000000000000
---
Quoted 1 line
CONFIG_ILLEGAL_POINTER_VALUE=0
352c352
< # CONFIG_ABI_RV64ILP32 is not set
---
Quoted 1 line
CONFIG_ABI_RV64ILP32=y
609a610
Quoted 1 line
CONFIG_HAVE_CMPXCHG_DOUBLE=y
837d837
< CONFIG_ZONE_DMA32=y7240d7239
< # 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 ([email protected]) (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 ---
Quoted 1 line
Linux version 6.14.0-rc1-00041-g804ac3b4d679 ([email protected]) (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
---
Quoted 1 line
Normal [mem 0x0000000060000000-0x0000000067ffffff]
31c28
< percpu: Embedded 22 pages/cpu s49384 r8192 d32536 u90112
---
Quoted 1 line
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)
---
Quoted 4 lines
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)
---
Quoted 1 line
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)
---
Quoted 7 lines
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)
---
Quoted 2 lines
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)
---
Quoted 1 line
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
---
Quoted 1 line
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
---
Quoted 1 line
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)
---
Quoted 1 line
tcp_listen_portaddr_hashhash 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)
---
Quoted 2 lines
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)
---
Quoted 2 lines
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
---
Quoted 1 line
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)
---
Quoted 1 line
goldfish_rtc101000.rtc: setting system clock to 2025-03-15T08:51:36 UTC (1742028696)
191c188
< Freeing unused kernel image (initmem) memory: 2304K
---
Quoted 1 line
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/[email protected]/
- Add u64ilp32 support
- Rebase v6.5-rc1
- Enable 64ilp32 vgettimeofday for benchmarking
v1:
https://lore.kernel.org/linux-riscv/[email protected]/
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
Signature · 1 line
2.40.1
RFC PATCH v3 1/43 rv64ilp32_abi: uapi: Reuse lp64 ABI interface
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- 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(+)
include/linux/socket.h +35 -0
@@ -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 */ };
include/uapi/asm-generic/siginfo.h +50 -0
92 lines not on this page · raw message
include/uapi/asm-generic/signal.h +35 -0
@@ -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__ */
include/uapi/asm-generic/stat.h +25 -0
@@ -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)
include/uapi/linux/atm.h +7 -0
@@ -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 };
include/uapi/linux/atmdev.h +7 -0
@@ -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 */
include/uapi/linux/blkpg.h +7 -0
@@ -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) */
include/uapi/linux/btrfs.h +19 -0
@@ -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. *
include/uapi/linux/capi.h +11 -0
@@ -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 ;/*
include/uapi/linux/fs.h +12 -0
@@ -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 };
include/uapi/linux/futex.h +18 -0
@@ -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 };/*
include/uapi/linux/if.h +6 -0
@@ -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 */
include/uapi/linux/netfilter/x_tables.h +8 -0
@@ -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;
include/uapi/linux/netfilter_ipv4/ip_tables.h +7 -0
@@ -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[];
include/uapi/linux/nfs4_mount.h +14 -0
@@ -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 */
include/uapi/linux/ppp-ioctl.h +7 -0
@@ -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; };
include/uapi/linux/sctp.h +3 -0
@@ -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 {
include/uapi/linux/sem.h +38 -0
@@ -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 {
include/uapi/linux/socket.h +7 -0
@@ -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 }; };
include/uapi/linux/sysctl.h +32 -0
@@ -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 */
include/uapi/linux/uhid.h +7 -0
@@ -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;
include/uapi/linux/uio.h +11 -0
@@ -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 {
include/uapi/linux/usb/tmc.h +14 -0
@@ -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 */
include/uapi/linux/usbdevice_fs.h +50 -0
101 lines not on this page · raw message
include/uapi/linux/uvcvideo.h +14 -0
@@ -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)
include/uapi/linux/vfio.h +7 -0
@@ -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 };/**
include/uapi/linux/videodev2.h +7 -0
@@ -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)
Signature · 1 line
2.40.1
RFC PATCH v3 2/43 rv64ilp32_abi: riscv: Adapt Makefile and Kconfig
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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
--- 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
arch/riscv/Kconfig +10 -2
@@ -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.
arch/riscv/Makefile +17 -0
@@ -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)'
arch/riscv/configs/rv64ilp32.config new file +1 -0
@@ -0,0 +1 @@ +CONFIG_ABI_RV64ILP32=y
Signature · 1 line
2.40.1
RFC PATCH v3 3/43 rv64ilp32_abi: riscv: Adapt ULL & UL definition
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- 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(-)
arch/riscv/include/asm/cmpxchg.h +2 -2
@@ -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; \
arch/riscv/include/asm/csr.h +110 -102
307 lines not on this page · raw message
arch/riscv/net/bpf_jit_comp64.c +3 -3
@@ -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 */
Signature · 1 line
2.40.1
RFC PATCH v3 4/43 rv64ilp32_abi: riscv: Introduce xlen_t to adapt __riscv_xlen != BITS_PER_LONG
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- 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(-)
arch/riscv/include/asm/checksum.h +4 -0
@@ -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 {
arch/riscv/include/asm/csr.h +8 -7
@@ -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"); \
arch/riscv/include/asm/processor.h +5 -5
@@ -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. */
arch/riscv/include/asm/ptrace.h +46 -46
149 lines not on this page · raw message
arch/riscv/include/asm/sparsemem.h +1 -1
@@ -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
arch/riscv/include/asm/switch_to.h +2 -2
@@ -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;
arch/riscv/include/asm/thread_info.h +1 -1
@@ -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 };
arch/riscv/include/asm/timex.h +2 -2
@@ -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 ; }
arch/riscv/include/uapi/asm/elf.h +2 -2
@@ -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
arch/riscv/include/uapi/asm/ptrace.h +54 -43
121 lines not on this page · raw message
arch/riscv/include/uapi/asm/ucontext.h +5 -2
@@ -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;/*
arch/riscv/include/uapi/asm/unistd.h +1 -1
@@ -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>
arch/riscv/kernel/compat_signal.c +2 -2
@@ -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 ;
arch/riscv/kernel/process.c +4 -4
@@ -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;
arch/riscv/kernel/signal.c +2 -2
@@ -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 ;
arch/riscv/kernel/traps.c +2 -2
@@ -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)
arch/riscv/kernel/vector.c +1 -1
@@ -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 ()))
arch/riscv/mm/fault.c +1 -1
@@ -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 );
Signature · 1 line
2.40.1
RFC PATCH v3 5/43 rv64ilp32_abi: riscv: crc32: Utilize 64-bit width to improve the performance
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/lib/crc32-riscv.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
arch/riscv/lib/crc32-riscv.c +18 -17
@@ -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);
Signature · 1 line
2.40.1
RFC PATCH v3 6/43 rv64ilp32_abi: riscv: csum: Utilize 64-bit width to improve the performance
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/lib/csum.c | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-)
arch/riscv/lib/csum.c +24 -24
@@ -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 intdo_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
Signature · 1 line
2.40.1
RFC PATCH v3 7/43 rv64ilp32_abi: riscv: arch_hweight: Adapt cpopw & cpop of zbb extension
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/include/asm/arch_hweight.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/riscv/include/asm/arch_hweight.h +6 -2
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 8/43 rv64ilp32_abi: riscv: bitops: Adapt ctzw & clzw of zbb extension
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/include/asm/bitops.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
arch/riscv/include/asm/bitops.h +17 -4
@@ -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) asmvolatile (".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) asmvolatile (".option push\n" ".option arch,+zbb\n" -"clz %0, %1\n" +CLZ "%0, %1\n" ".option pop\n" :"=r" (word) :"r" (word) :);
Signature · 1 line
2.40.1
RFC PATCH v3 9/43 rv64ilp32_abi: riscv: Reuse LP64 SBI interface
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- 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(-)
arch/riscv/include/asm/cpu_ops_sbi.h +2 -2
@@ -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
arch/riscv/include/asm/sbi.h +11 -11
@@ -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)
arch/riscv/kernel/cpu_ops_sbi.c +2 -2
@@ -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);
arch/riscv/kernel/sbi_ecall.c +11 -11
@@ -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); asmvolatile ("ecall" :"+r" (a0),"+r" (a1) : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7)
Signature · 1 line
2.40.1
RFC PATCH v3 10/43 rv64ilp32_abi: riscv: Update SATP.MODE.ASID width
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/mm/context.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/riscv/mm/context.c +8 -4
@@ -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 ;
Signature · 1 line
2.40.1
RFC PATCH v3 11/43 rv64ilp32_abi: riscv: Introduce PTR_L and PTR_S
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- 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(-)
arch/riscv/include/asm/asm.h +9 -4
@@ -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
arch/riscv/include/asm/scs.h +2 -2
@@ -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 */
arch/riscv/kernel/entry.S +16 -16
@@ -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)
arch/riscv/kernel/head.S +4 -4
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 12/43 rv64ilp32_abi: riscv: Introduce cmpxchg_double
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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")
--- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/cmpxchg.h | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
arch/riscv/Kconfig +1 -0
@@ -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
arch/riscv/include/asm/cmpxchg.h +53 -0
65 lines not on this page · raw message
Signature · 1 line
2.40.1
RFC PATCH v3 13/43 rv64ilp32_abi: riscv: Correct stackframe layout
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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 ]---
--- arch/riscv/include/asm/stacktrace.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/riscv/include/asm/stacktrace.h +6 -0
@@ -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,
Signature · 1 line
2.40.1
RFC PATCH v3 14/43 rv64ilp32_abi: riscv: Adapt kernel module code
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Because riscv_insn_valid_32bit_offset is always true for ILP32, use BITS_PER_LONG instead of CONFIG_64BIT.
--- arch/riscv/kernel/module.c | 2 +- include/asm-generic/module.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/module.c +1 -1
@@ -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 ));
include/asm-generic/module.h +1 -1
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 15/43 rv64ilp32_abi: riscv: mm: Adapt MMU_SV39 for 2GiB address space
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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
--- 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(-)
arch/riscv/Kconfig +1 -1
@@ -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
arch/riscv/include/asm/page.h +14 -9
@@ -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))
arch/riscv/include/asm/pgtable-64.h +30 -25
166 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h +51 -9
176 lines not on this page · raw message
arch/riscv/include/asm/processor.h +1 -1
@@ -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
arch/riscv/kernel/cpu.c +2 -2
@@ -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)
arch/riscv/mm/fault.c +5 -5
@@ -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" );
arch/riscv/mm/init.c +38 -17
162 lines not on this page · raw message
arch/riscv/mm/pageattr.c +2 -2
@@ -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));
arch/riscv/mm/pgtable.c +1 -1
@@ -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);
Signature · 1 line
2.40.1
RFC PATCH v3 16/43 rv64ilp32_abi: riscv: Support physical addresses >= 0x80000000
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/kernel/head.S | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
arch/riscv/kernel/head.S +112 -0
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 17/43 rv64ilp32_abi: riscv: Adapt kasan memory layout
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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)--- arch/riscv/include/asm/kasan.h | 6 +++++- arch/riscv/mm/kasan_init.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
arch/riscv/include/asm/kasan.h +5 -1
@@ -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)
arch/riscv/mm/kasan_init.c +1 -1
@@ -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,
Signature · 1 line
2.40.1
RFC PATCH v3 18/43 rv64ilp32_abi: riscv: kvm: Initial support
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
This is the initial support for rv64ilp32 abi, and haven't passed the kvm self test.
It could support rv64ilp32 & rv64lp64 linux guest kernels.
--- 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(-)
arch/riscv/include/asm/kvm_aia.h +16 -16
@@ -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 },
arch/riscv/include/asm/kvm_host.h +96 -96
268 lines not on this page · raw message
arch/riscv/include/asm/kvm_nacl.h +13 -13
@@ -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 \
arch/riscv/include/asm/kvm_vcpu_insn.h +2 -2
@@ -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; };
arch/riscv/include/asm/kvm_vcpu_pmu.h +4 -4
@@ -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 ;
arch/riscv/include/asm/kvm_vcpu_sbi.h +2 -2
@@ -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; };
arch/riscv/include/asm/sbi.h +5 -5
@@ -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)
arch/riscv/include/uapi/asm/kvm.h +28 -28
82 lines not on this page · raw message
arch/riscv/kvm/aia.c +13 -13
@@ -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,
arch/riscv/kvm/aia_imsic.c +3 -3
@@ -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 ;
arch/riscv/kvm/main.c +1 -1
@@ -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",
arch/riscv/kvm/mmu.c +5 -5
@@ -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 ;
arch/riscv/kvm/tlb.c +39 -37
195 lines not on this page · raw message
arch/riscv/kvm/vcpu.c +5 -5
@@ -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 {
arch/riscv/kvm/vcpu_exit.c +2 -2
@@ -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); }
arch/riscv/kvm/vcpu_insn.c +6 -6
@@ -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)) {
arch/riscv/kvm/vcpu_onereg.c +9 -9
@@ -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 ;
arch/riscv/kvm/vcpu_pmu.c +4 -4
@@ -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 ;
arch/riscv/kvm/vcpu_sbi_base.c +1 -1
@@ -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 :
arch/riscv/kvm/vmid.c +2 -2
@@ -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; }
Signature · 1 line
2.40.1
RFC PATCH v3 19/43 rv64ilp32_abi: irqchip: irq-riscv-intc: Use xlen_t instead of ulong
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The RV64ILP32 ABI is based on CONFIG_64BIT, so use xlen/xlen_t instead of BITS_PER_LONG/ulong.
--- drivers/irqchip/irq-riscv-intc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/irqchip/irq-riscv-intc.c +5 -4
@@ -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)
Signature · 1 line
2.40.1
RFC PATCH v3 20/43 rv64ilp32_abi: drivers/perf: Adapt xlen_t of sbiret
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- drivers/perf/riscv_pmu_sbi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/perf/riscv_pmu_sbi.c +2 -2
@@ -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);
Signature · 1 line
2.40.1
RFC PATCH v3 21/43 rv64ilp32_abi: asm-generic: Add custom BITS_PER_LONG definition
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- arch/riscv/include/uapi/asm/bitsperlong.h | 6 ++++++ include/asm-generic/bitsperlong.h | 2 ++ 2 files changed, 8 insertions(+)
arch/riscv/include/uapi/asm/bitsperlong.h +6 -0
@@ -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 */
include/asm-generic/bitsperlong.h +2 -0
@@ -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 */
Signature · 1 line
2.40.1
RFC PATCH v3 22/43 rv64ilp32_abi: bpf: Change KERN_ARENA_SZ to 256MiB
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The RV64ILP32 ABI limits the vmalloc range to 512MB, hence the arena kernel range is set to 256MiB instead of 4GiB.
--- kernel/bpf/arena.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
kernel/bpf/arena.c +14 -5
@@ -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 adif (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))
Signature · 1 line
2.40.1
RFC PATCH v3 23/43 rv64ilp32_abi: compat: Correct compat_ulong_t cast
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
RV64ILP32 ABI systems have BITS_PER_LONG set to 32, matching sizeof(compat_ulong_t). Adjust code involving compat_ulong_t accordingly.
--- include/uapi/linux/auto_fs.h | 6 ++++++ kernel/compat.c | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)
include/uapi/linux/auto_fs.h +6 -0
@@ -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)
kernel/compat.c +12 -3
@@ -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);
Signature · 1 line
2.40.1
RFC PATCH v3 24/43 rv64ilp32_abi: compiler_types: Add "long long" into __native_word()
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The rv64ilp32 abi supports native atomic64 operations. The atomic64_t is defined by "long long," so add "long long" into __native_word().
--- include/linux/compiler_types.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/compiler_types.h +7 -0
@@ -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) \
Signature · 1 line
2.40.1
RFC PATCH v3 25/43 rv64ilp32_abi: exec: Adapt 64lp64 env and argv
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The rv64ilp32 abi reuses the env and argv memory layout of the lp64 abi, so leave the space to fit the lp64 struct layout.
--- fs/exec.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/exec.c +4 -0
@@ -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 );
Signature · 1 line
2.40.1
RFC PATCH v3 26/43 rv64ilp32_abi: file_ref: Use 32-bit width for refcnt
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The sizeof(atomic_t) is 4 in rv64ilp32 abi linux kernel, which could provide a higher density of cache and a smaller memory footprint.
--- include/linux/file_ref.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/file_ref.h +2 -2
@@ -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;
Signature · 1 line
2.40.1
RFC PATCH v3 27/43 rv64ilp32_abi: input: Adapt BITS_PER_LONG to dword
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- drivers/input/input.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/input/input.c +4 -0
@@ -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);
Signature · 1 line
2.40.1
RFC PATCH v3 28/43 rv64ilp32_abi: iov_iter: Resize kvec to match iov_iter's size
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
As drivers/vhost/vringh.c uses BUILD_BUG_ON(sizeof(struct iovec) != sizeof(struct kvec)), make them the same.
--- include/linux/uio.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/uio.h +6 -0
@@ -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 {
Signature · 1 line
2.40.1
RFC PATCH v3 29/43 rv64ilp32_abi: locking/atomic: Use BITS_PER_LONG for scripts
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
In RV64ILP32 ABI systems, BITS_PER_LONG equals 32 and determines code selection, not CONFIG_64BIT.
--- include/linux/atomic/atomic-long.h | 174 ++++++++++++++--------------- scripts/atomic/gen-atomic-long.sh | 4 +- 2 files changed, 89 insertions(+), 89 deletions(-)
include/linux/atomic/atomic-long.h +87 -87
@@ -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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 voidraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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 boolraw_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
scripts/atomic/gen-atomic-long.sh +2 -2
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 30/43 rv64ilp32_abi: kernel/smp: Disable CSD_LOCK_WAIT_DEBUG
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- include/linux/smp_types.h | 2 +- lib/Kconfig.debug | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/smp_types.h +1 -1
@@ -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 };
lib/Kconfig.debug +1 -0
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 31/43 rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- include/linux/maple_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/maple_tree.h +1 -1
@@ -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 */
Signature · 1 line
2.40.1
RFC PATCH v3 32/43 rv64ilp32_abi: mm: Remove _folio_nr_pages
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- include/linux/mm.h | 4 ++-- include/linux/mm_types.h | 2 +- mm/internal.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/mm.h +2 -2
@@ -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 );
include/linux/mm_types.h +1 -1
@@ -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 */
mm/internal.h +1 -1
@@ -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 }
Signature · 1 line
2.40.1
RFC PATCH v3 33/43 rv64ilp32_abi: mm/auxvec: Adapt mm->saved_auxv[] to Elf64
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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
--- include/linux/mm_types.h | 4 ++++ kernel/sys.c | 8 ++++++++ 2 files changed, 12 insertions(+)
include/linux/mm_types.h +4 -0
@@ -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 ];
kernel/sys.c +8 -0
@@ -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 ;
Signature · 1 line
2.40.1
RFC PATCH v3 34/43 rv64ilp32_abi: mm: Adapt vm_flags_t struct
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
RV64ILP32 ABI linux kernel is based on CONFIG_64BIT, so uses unsigned long long as vm_flags struct type.
--- 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(-)
fs/proc/task_mmu.c +7 -2
@@ -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" ,
include/linux/mm.h +7 -3
@@ -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 */
include/linux/mm_types.h +4 -0
@@ -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
mm/debug.c +4 -0
@@ -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,
mm/memory.c +4 -0
@@ -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,
Signature · 1 line
2.40.1
RFC PATCH v3 35/43 rv64ilp32_abi: net: Use BITS_PER_LONG in struct dst_entry
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- include/net/dst.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/net/dst.h +3 -3
@@ -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 };
Signature · 1 line
2.40.1
RFC PATCH v3 36/43 rv64ilp32_abi: printf: Use BITS_PER_LONG instead of CONFIG_64BIT
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
RV64ILP32 ABI systems have BITS_PER_LONG set to 32. Use BITS_PER_LONG instead of CONFIG_64BIT.
--- lib/vsprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vsprintf.c +1 -1
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 37/43 rv64ilp32_abi: random: Adapt fast_pool struct
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
RV64ILP32 ABI systems have BITS_PER_LONG set to 32, matching sizeof(compat_ulong_t). Adjust code
--- drivers/char/random.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/char/random.c +8 -0
@@ -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 ]);
Signature · 1 line
2.40.1
RFC PATCH v3 38/43 rv64ilp32_abi: syscall: Use CONFIG_64BIT instead of BITS_PER_LONG
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The RV64ILP32 ABI adopts the syscall rules from CONFIG_64BIT and directly uses 64BIT, replacing BITS_PER_LONG representation.
--- 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(-)
arch/riscv/include/asm/syscall_table.h +1 -1
@@ -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>
arch/riscv/include/asm/unistd.h +2 -2
@@ -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
scripts/checksyscalls.sh +1 -1
@@ -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
Signature · 1 line
2.40.1
RFC PATCH v3 39/43 rv64ilp32_abi: sysinfo: Adapt sysinfo structure to lp64 uapi
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- 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(-)
fs/proc/loadavg.c +7 -3
@@ -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 ;
include/linux/sched/loadavg.h +4 -0
@@ -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 */
include/uapi/linux/sysinfo.h +20 -0
@@ -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 */
kernel/sched/loadavg.c +4 -0
@@ -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;
Signature · 1 line
2.40.1
RFC PATCH v3 40/43 rv64ilp32_abi: tracepoint-defs: Using u64 for trace_print_flags.mask
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- include/linux/tracepoint-defs.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/tracepoint-defs.h +4 -0
@@ -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; };
Signature · 1 line
2.40.1
RFC PATCH v3 41/43 rv64ilp32_abi: tty: Adapt ptr_to_compat
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- drivers/tty/tty_io.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/tty/tty_io.c +4 -0
@@ -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)))
Signature · 1 line
2.40.1
Peter Zijlstra
maintainerQuoted 4 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel 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.
RFC PATCH v3 42/43 rv64ilp32_abi: memfd: Use vm_flag_t
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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.
--- include/linux/memfd.h | 4 ++-- mm/memfd.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/memfd.h +2 -2
@@ -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 ; }
mm/memfd.c +4 -4
@@ -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);
Signature · 1 line
2.40.1
RFC PATCH v3 43/43 riscv: Fixup address space overlay of print_mlk
In reply to [email protected]From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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)
--- arch/riscv/mm/init.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/mm/init.c +4 -4
@@ -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
Signature · 1 line
2.40.1
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel to use an ILP32 ABII'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.
Quoted 3 lines
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.
Quoted 3 lines
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.
Signature · 2 lines
Best Regards Guo Ren
Arnd Bergmann
maintainerQuoted 8 lines · Peter Zijlstra
Quoted 4 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel to use an ILP32 ABIPlease, 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.
Quoted 7 lines
Quoted 7 lines
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
Re: [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv
In reply to [email protected]Quoted 15 lines · On 3/25/25 3:16 PM, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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) <[email protected]>--- fs/exec.c | 4 ++++ 1 file changed, 4 insertions(+)fs/exec.c +0
-0
fs/exec.c static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr) · line 427
Quoted 4 lines
fs/exec.c +1
-0@@ -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...
fs/exec.c static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr) · line 428
Quoted 1 line
fs/exec.c +1
-0+ nr = nr *2 ;
Why not nr *= 2?
[...]
MBR, Sergey
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel to use an ILP32 ABI
Quoted 9 lines
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.
Signature · 3 lines
Cheers, David / dhildenb
Re: [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
In reply to [email protected]Quoted 16 lines · * [email protected] <[email protected]> [250325 08:24]:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The Maple tree algorithm uses ulong type for each element. The number of slots is based on
BITS_PER_LONGfor RV64ILP32 ABI, so useBITS_PER_LONGinstead ofCONFIG_64BIT.Signed-off-by Guo Ren (Alibaba DAMO Academy) <[email protected]>--- include/linux/maple_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/maple_tree.h +0
-0
include/linux/maple_tree.h line 27
Quoted 5 lines
include/linux/maple_tree.h +1
-1@@ -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
Quoted 10 lines · David Hildenbrand
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel to use an ILP32 ABII'm thinking you're going to be finding a metric ton of assumptions about 'unsigned long' being 64bit when 64BIT=y throughout the kernel.
Quoted 8 lines
Quoted 6 lines
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
Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
In reply to [email protected]Quoted 6 lines · On Tuesday 2025-03-25 13:15, [email protected] wrote:
include/uapi/linux/netfilter/x_tables.h +0
-0@@ -18,7 +18,11 @@ struct xt_entry_match {__u8 revision;
include/uapi/linux/netfilter/x_tables.h struct xt_entry_match { · line 28
Quoted 10 lines
include/uapi/linux/netfilter/x_tables.h +4
-0} 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.
Quoted 7 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h +1
-0@@ -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
include/uapi/linux/netfilter_ipv4/ip_tables.h struct ipt_replace { · line 213
Quoted 10 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h +6
-0+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.
Quoted 443 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h +6
-0+#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 */
include/uapi/linux/ppp-ioctl.h +7
-0@@ -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; };include/uapi/linux/sctp.h +3
-0@@ -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{include/uapi/linux/sem.h +38
-0@@ -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 {include/uapi/linux/socket.h +7
-0@@ -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 }; };include/uapi/linux/sysctl.h +32
-0@@ -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 */ include/uapi/linux/uhid.h +7
-0@@ -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;include/uapi/linux/uio.h +0
-0@@ -16,8 +16,19 @@struct iovec
{include/uapi/linux/uio.h +10
-0+#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{include/uapi/linux/usb/tmc.h +14
-0@@ -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 */ include/uapi/linux/usbdevice_fs.h +50
-0@@ -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)include/uapi/linux/uvcvideo.h +14
-0@@ -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)include/uapi/linux/vfio.h +7
-0@@ -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 };/** include/uapi/linux/videodev2.h +7
-0@@ -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)Signature · 1 line
2.40.1
Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
In reply to [email protected]Quoted 4 lines · On Tue, 25 Mar 2025 at 05:17, <[email protected]> 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 matchBITS_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
Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
In reply to Jan EngelhardtQuoted 25 lines · Jan Engelhardt
Quoted 6 lines · On Tuesday 2025-03-25 13:15, [email protected] wrote:
include/uapi/linux/netfilter/x_tables.h +0
-0@@ -18,7 +18,11 @@ struct xt_entry_match {__u8 revision;include/uapi/linux/netfilter/x_tables.h struct xt_entry_match { · line 28
Quoted 10 lines
include/uapi/linux/netfilter/x_tables.h +4
-0} user;struct { +#if __riscv_xlen ==64 +__u64 match_size; +#else __u16 match_size; +#endif /* Used inside the kernel */ struct xt_match *match;The
__u16is the common prefix of the union which is exposed to userspace. If anything, you need to use __attribute__((aligned(8))) to movematchto a fixed location.
Quoted 5 lines
However, that sub-struct is only used inside the kernel and never exposed, so the alignment of
matchshould 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.
Quoted 17 lines
Quoted 17 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h +7
-0@@ -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
Quoted 6 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h struct ipt_replace { · line 213
Quoted 2 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h +0
-0/* 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!
Quoted 444 lines
Quoted 444 lines
include/uapi/linux/netfilter_ipv4/ip_tables.h +7
-0+#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 */
include/uapi/linux/ppp-ioctl.h +7
-0@@ -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; };include/uapi/linux/sctp.h +3
-0@@ -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{include/uapi/linux/sem.h +38
-0@@ -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 {include/uapi/linux/socket.h +7
-0@@ -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 }; };include/uapi/linux/sysctl.h +32
-0@@ -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 */ include/uapi/linux/uhid.h +7
-0@@ -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;include/uapi/linux/uio.h +0
-0@@ -16,8 +16,19 @@struct iovec
{include/uapi/linux/uio.h +11
-0+#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{include/uapi/linux/usb/tmc.h +14
-0@@ -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 */ include/uapi/linux/usbdevice_fs.h +50
-0@@ -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)include/uapi/linux/uvcvideo.h +14
-0@@ -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)include/uapi/linux/vfio.h +7
-0@@ -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 };/** include/uapi/linux/videodev2.h +7
-1@@ -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
Signature · 2 lines
Best Regards Guo Ren
Quoted 25 lines · Arnd Bergmann
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel to use an ILP32 ABIPlease, don't do this. This adds a significant maintenance burden on all of us.
It would be easier to this with
CONFIG_64BITdisabled and continue treatingCONFIG_64BITto 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.Quoted 7 lines
Quoted 7 lines
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.
Quoted 4 lines
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.
Quoted 4 lines
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
Quoted 9 lines
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.
Quoted 9 lines
If you remove the
CONFIG_64BITchanges 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.
Quoted 3 lines
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/
Signature · 2 lines
Best Regards Guo Ren
Re: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
In reply to Linus TorvaldsQuoted 21 lines · Linus Torvalds
Quoted 4 lines · On Tue, 25 Mar 2025 at 05:17, <[email protected]> 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 matchBITS_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_xlenhackery 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.
Quoted 8 lines
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.
Quoted 7 lines
(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.
Signature · 2 lines
Best Regards Guo Ren
Arnd Bergmann
maintainerQuoted 9 lines · Guo Ren
Quoted 7 lines · Arnd Bergmann
Quoted 1 line · Peter Zijlstra
On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] 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.
Quoted 7 lines
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_xlenmacro.
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.
Quoted 9 lines
Quoted 8 lines
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.
Quoted 3 lines
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.
Quoted 4 lines
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.
Quoted 8 lines
Quoted 8 lines
If you remove the
CONFIG_64BITchanges 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.
Quoted 6 lines
Quoted 3 lines
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
Re: [RFC PATCH V3 25/43] rv64ilp32_abi: exec: Adapt 64lp64 env and argv
In reply to Sergey ShtylyovQuoted 21 lines · Sergey Shtylyov
Quoted 18 lines · On 3/25/25 3:16 PM, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
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) <[email protected]>--- fs/exec.c | 4 ++++ 1 file changed, 4 insertions(+)fs/exec.c +0
-0@@ -424,6 +424,10 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr) }#endif
Quoted 1 line
fs/exec.c static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr) · line 427
Quoted 1 line
fs/exec.c +1
-0+#if defined(CONFIG_64BIT ) && (BITS_PER_LONG ==32 )
okay, #if defined(CONFIG_64BIT) && BITS_PER_LONG == 32
Quoted 6 lines
Parens don't seem necessary...
fs/exec.c static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr) · line 428
Quoted 1 line
fs/exec.c +1
-0+ nr = nr *2 ;Why not nr *= 2?
okay, nr *= 2;
Signature · 2 lines
Best Regards Guo Ren
Re: [RFC PATCH V3 31/43] rv64ilp32_abi: maple_tree: Use BITS_PER_LONG instead of CONFIG_64BIT
In reply to Liam R. HowlettQuoted 13 lines · Liam R. Howlett
Quoted 11 lines · * [email protected] <[email protected]> [250325 08:24]:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
The Maple tree algorithm uses ulong type for each element. The number of slots is based on
BITS_PER_LONGfor RV64ILP32 ABI, so useBITS_PER_LONGinstead ofCONFIG_64BIT.Signed-off-by Guo Ren (Alibaba DAMO Academy) <[email protected]>--- include/linux/maple_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
include/linux/maple_tree.h line 27
Quoted 10 lines
include/linux/maple_tree.h +1
-1@@ -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 theMakefileas well since it will generate a build flag for the userspace.
I think you are talking about the following:
============================================================../shared/shared.mk:
ifndef LONG_BITLONG_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.
Quoted 11 lines
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
Signature · 2 lines
Best Regards Guo Ren
Quoted 17 lines · Arnd Bergmann
Quoted 15 lines · Guo Ren
Quoted 7 lines · Arnd Bergmann
Quoted 1 line · Peter Zijlstra
On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] 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.
Quoted 7 lines
Quoted 1 line
I would look at compat stuff instead of using
__riscv_xlenmacro.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.
Quoted 30 lines
Quoted 10 lines
Quoted 9 lines
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.
Quoted 3 lines
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.
Quoted 8 lines
- 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.
Quoted 6 lines
Quoted 5 lines
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.
Quoted 6 lines
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.
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines
If you remove the
CONFIG_64BITchanges 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.Quoted 6 lines
Quoted 3 lines
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/C908Ok, thanks for the link.
Arnd
Signature · 2 lines
Best Regards Guo Ren
Palmer Dabbelt
maintainerQuoted 5 lines · On Tue, 25 Mar 2025 12:23:39 PDT (-0700), [email protected] wrote:
Quoted 4 lines · David Hildenbrand
Quoted 3 lines · Peter Zijlstra
Quoted 2 lines · On Tue, Mar 25, 2025 at 08:15:41AM -0400, [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel to use an ILP32 ABII'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.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
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.
Quoted 3 lines
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...
Quoted 3 lines
Thank you,
Liam
Palmer Dabbelt
maintainerRe: [RFC PATCH V3 01/43] rv64ilp32_abi: uapi: Reuse lp64 ABI interface
In reply to Linus TorvaldsQuoted 8 lines · Linus Torvalds
Quoted 4 lines · On Tue, 25 Mar 2025 at 05:17, <[email protected]> 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 matchBITS_PER_LONG= 64.No.
Quoted 8 lines
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_xlenhackery 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...
Quoted 4 lines
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 ;)
Quoted 15 lines
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
Quoted 7 lines · On Tue, 25 Mar 2025 08:15:41 -0400 [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel 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
Quoted 11 lines · David Laight
Quoted 7 lines · On Tue, 25 Mar 2025 08:15:41 -0400 [email protected] wrote:
From: "Guo Ren (Alibaba DAMO Academy)" <[email protected]>
Since 2001, the
CONFIG_64BITkernel has been built with the LP64 ABI, but this patchset allows theCONFIG_64BITkernel 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.)
Quoted 4 lines
...
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.
Because the below chips have built the Linux ecosystem with LP64-ABI:
- allwinner/sun20i-d1-lichee (128MB~1GB)
- allwinner/sun20i-d1s-mangopi (64MB)
- bouffalo/bl808 (64MB)
- canaan/k230 (512MB)
- canaan/k230d (128MB)
- renesas/rzfive-smarc (256MB~1GB DDR)
- sophgo/cv1800b (64MB DDR)
- sophgo/cv1812h (256MB DDR)
- sophgo/sg2002 (64/256MB DDR)
- https://docs.banana-pi.org/en/BPI-RV2/BananaPi_BPI-RV2 (512MB DDR)
By swapping the rv64ilp32-abi Linux kernel, we could immediately reduce the 5~10% memory footprint without modifying the bootloader, firmware, or rootfs binaries.
The userspace ilp32-abi porting requires substantial effort, and customers want the porting step by step.
Quoted 4 lines
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.
We don't introduce any x32 userspace ABI here, only for the kernel self.
Quoted 2 lines
(I suspect you'd need to change the process switch code to save all 64bits of the registers - but maybe not much else??)
Indeed, the pt_regs & context regs are the same as CONFIG_64BIT (64-bit width).
Best Regards
Guo Ren