Skip to content

Commit 71bdea6

Browse files
committed
parisc: Align parisc MADV_XXX constants with all other architectures
Adjust some MADV_XXX constants to be in sync what their values are on all other platforms. There is currently no reason to have an own numbering on parisc, but it requires workarounds in many userspace sources (e.g. glibc, qemu, ...) - which are often forgotten and thus introduce bugs and different behaviour on parisc. A wrapper avoids an ABI breakage for existing userspace applications by translating any old values to the new ones, so this change allows us to move over all programs to the new ABI over time. Signed-off-by: Helge Deller <[email protected]>
1 parent 41f563a commit 71bdea6

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed

arch/parisc/include/uapi/asm/mman.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@
4949
#define MADV_DONTFORK 10 /* don't inherit across fork */
5050
#define MADV_DOFORK 11 /* do inherit across fork */
5151

52+
#define MADV_MERGEABLE 12 /* KSM may merge identical pages */
53+
#define MADV_UNMERGEABLE 13 /* KSM may not merge identical pages */
54+
55+
#define MADV_HUGEPAGE 14 /* Worth backing with hugepages */
56+
#define MADV_NOHUGEPAGE 15 /* Not worth backing with hugepages */
57+
58+
#define MADV_DONTDUMP 16 /* Explicity exclude from the core dump,
59+
overrides the coredump filter bits */
60+
#define MADV_DODUMP 17 /* Clear the MADV_NODUMP flag */
61+
62+
#define MADV_WIPEONFORK 18 /* Zero memory on fork, child only */
63+
#define MADV_KEEPONFORK 19 /* Undo MADV_WIPEONFORK */
64+
5265
#define MADV_COLD 20 /* deactivate these pages */
5366
#define MADV_PAGEOUT 21 /* reclaim these pages */
5467

@@ -57,27 +70,13 @@
5770

5871
#define MADV_DONTNEED_LOCKED 24 /* like DONTNEED, but drop locked pages too */
5972

60-
#define MADV_MERGEABLE 65 /* KSM may merge identical pages */
61-
#define MADV_UNMERGEABLE 66 /* KSM may not merge identical pages */
62-
63-
#define MADV_HUGEPAGE 67 /* Worth backing with hugepages */
64-
#define MADV_NOHUGEPAGE 68 /* Not worth backing with hugepages */
65-
66-
#define MADV_DONTDUMP 69 /* Explicity exclude from the core dump,
67-
overrides the coredump filter bits */
68-
#define MADV_DODUMP 70 /* Clear the MADV_NODUMP flag */
69-
70-
#define MADV_WIPEONFORK 71 /* Zero memory on fork, child only */
71-
#define MADV_KEEPONFORK 72 /* Undo MADV_WIPEONFORK */
72-
73-
#define MADV_COLLAPSE 73 /* Synchronous hugepage collapse */
73+
#define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */
7474

7575
#define MADV_HWPOISON 100 /* poison a page for testing */
7676
#define MADV_SOFT_OFFLINE 101 /* soft offline page for testing */
7777

7878
/* compatibility flags */
7979
#define MAP_FILE 0
80-
#define MAP_VARIABLE 0
8180

8281
#define PKEY_DISABLE_ACCESS 0x1
8382
#define PKEY_DISABLE_WRITE 0x2

arch/parisc/kernel/sys_parisc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,31 @@ asmlinkage long parisc_inotify_init1(int flags)
465465
flags = FIX_O_NONBLOCK(flags);
466466
return sys_inotify_init1(flags);
467467
}
468+
469+
/*
470+
* madvise() wrapper
471+
*
472+
* Up to kernel v6.1 parisc has different values than all other
473+
* platforms for the MADV_xxx flags listed below.
474+
* To keep binary compatibility with existing userspace programs
475+
* translate the former values to the new values.
476+
*
477+
* XXX: Remove this wrapper in year 2025 (or later)
478+
*/
479+
480+
asmlinkage notrace long parisc_madvise(unsigned long start, size_t len_in, int behavior)
481+
{
482+
switch (behavior) {
483+
case 65: behavior = MADV_MERGEABLE; break;
484+
case 66: behavior = MADV_UNMERGEABLE; break;
485+
case 67: behavior = MADV_HUGEPAGE; break;
486+
case 68: behavior = MADV_NOHUGEPAGE; break;
487+
case 69: behavior = MADV_DONTDUMP; break;
488+
case 70: behavior = MADV_DODUMP; break;
489+
case 71: behavior = MADV_WIPEONFORK; break;
490+
case 72: behavior = MADV_KEEPONFORK; break;
491+
case 73: behavior = MADV_COLLAPSE; break;
492+
}
493+
494+
return sys_madvise(start, len_in, behavior);
495+
}

arch/parisc/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
116 common sysinfo sys_sysinfo compat_sys_sysinfo
132132
117 common shutdown sys_shutdown
133133
118 common fsync sys_fsync
134-
119 common madvise sys_madvise
134+
119 common madvise parisc_madvise
135135
120 common clone sys_clone_wrapper
136136
121 common setdomainname sys_setdomainname
137137
122 common sendfile sys_sendfile compat_sys_sendfile

tools/arch/parisc/include/uapi/asm/mman.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22
#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
33
#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
4-
#define MADV_DODUMP 70
4+
#define MADV_DODUMP 17
55
#define MADV_DOFORK 11
6-
#define MADV_DONTDUMP 69
6+
#define MADV_DONTDUMP 16
77
#define MADV_DONTFORK 10
88
#define MADV_DONTNEED 4
99
#define MADV_FREE 8
10-
#define MADV_HUGEPAGE 67
11-
#define MADV_MERGEABLE 65
12-
#define MADV_NOHUGEPAGE 68
10+
#define MADV_HUGEPAGE 14
11+
#define MADV_MERGEABLE 12
12+
#define MADV_NOHUGEPAGE 15
1313
#define MADV_NORMAL 0
1414
#define MADV_RANDOM 1
1515
#define MADV_REMOVE 9
1616
#define MADV_SEQUENTIAL 2
17-
#define MADV_UNMERGEABLE 66
17+
#define MADV_UNMERGEABLE 13
1818
#define MADV_WILLNEED 3
1919
#define MAP_ANONYMOUS 0x10
2020
#define MAP_DENYWRITE 0x0800

tools/perf/bench/bench.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,13 @@ extern struct timeval bench__start, bench__end, bench__runtime;
1010
* The madvise transparent hugepage constants were added in glibc
1111
* 2.13. For compatibility with older versions of glibc, define these
1212
* tokens if they are not already defined.
13-
*
14-
* PA-RISC uses different madvise values from other architectures and
15-
* needs to be special-cased.
1613
*/
17-
#ifdef __hppa__
18-
# ifndef MADV_HUGEPAGE
19-
# define MADV_HUGEPAGE 67
20-
# endif
21-
# ifndef MADV_NOHUGEPAGE
22-
# define MADV_NOHUGEPAGE 68
23-
# endif
24-
#else
2514
# ifndef MADV_HUGEPAGE
2615
# define MADV_HUGEPAGE 14
2716
# endif
2817
# ifndef MADV_NOHUGEPAGE
2918
# define MADV_NOHUGEPAGE 15
3019
# endif
31-
#endif
3220

3321
int bench_numa(int argc, const char **argv);
3422
int bench_sched_messaging(int argc, const char **argv);

0 commit comments

Comments
 (0)