Debian Codegraph @

vmtest/patches/riscv-fix-vmemmap-and-vmalloc-offsets-in-proc-kcore.patch

raw
1 From 5273041dacfde780bbc917660537783c354e0598 Mon Sep 17 00:00:00 2001
2 Message-ID: <5273041dacfde780bbc917660537783c354e0598.1770674552.git.osandov@osandov.com>
3 From: Omar Sandoval <[email protected]>
4 Date: Thu, 5 Feb 2026 10:21:02 -0800
5 Subject: [PATCH] riscv: fix vmemmap and vmalloc offsets in /proc/kcore
6
7 kc_vaddr_to_offset() maps a kernel virtual address to its file offset in
8 /proc/kcore. The default definition is (address - PAGE_OFFSET). However, on
9 RISC-V, the vmemmap and vmalloc regions are below PAGE_OFFSET, so the computed
10 offsets for those regions are negative and wrap around to a large u64:
11
12 # readelf -l /proc/kcore
13 ...
14 Program Headers:
15 Type Offset VirtAddr PhysAddr
16 FileSiz MemSiz Flags Align
17 ...
18 LOAD 0xffc0000000002000 0xff20000000000000 0xffffffffffffffff
19 0x0040000000000000 0x0040000000000000 RWE 0x1000
20 ...
21
22 When userspace applications like drgn attempt to read from that offset, it
23 overflows an loff_t and results in EINVAL.
24
25 Fix it by defining an alternate kc_vaddr_to_offset() that masks off the
26 high bits, which is what x86-64 does, too.
27
28 Fixes: 07037db5d479 ("RISC-V: Paging and MMU")
29 Cc: [email protected]
30 Signed-off-by: Omar Sandoval <[email protected]>
31 ---
32 arch/riscv/include/asm/pgtable-64.h | 3 +++
33 1 file changed, 3 insertions(+)
34
35 diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
36 index 6e789fa58514c..a52d60dd80fc6 100644
37 --- a/arch/riscv/include/asm/pgtable-64.h
38 +++ b/arch/riscv/include/asm/pgtable-64.h
39 @@ -404,3 +404,6 @@ static inline pte_t pud_pte(pud_t pud);
40 #endif
41
42 +#define kc_vaddr_to_offset(v) ((v) & ((1UL << VA_BITS) - 1))
43 +#define kc_offset_to_vaddr(o) ((o) | ~((1UL << VA_BITS) - 1))
44 +
45 #endif /* _ASM_RISCV_PGTABLE_64_H */
46 --
47 2.47.3
48