Changes.old: tfix
[man-pages.git] / man2 / subpage_prot.2
blobc006821c10dec94f16a55a2ead0fdcd55c80d3dc
1 .\" Copyright (c) 2010 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" based on a proposal from Stephan Mueller <smueller@atsec.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" Various pieces of text taken from the kernel source and the commentary
7 .\" in Linux commit fa28237cfcc5827553044cbd6ee52e33692b0faa
8 .\" both written by Paul Mackerras <paulus@samba.org>
9 .\"
10 .TH subpage_prot 2 (date) "Linux man-pages (unreleased)"
11 .SH NAME
12 subpage_prot \- define a subpage protection for an address range
13 .SH LIBRARY
14 Standard C library
15 .RI ( libc ", " \-lc )
16 .SH SYNOPSIS
17 .nf
18 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
19 .B #include <unistd.h>
21 .BI "int syscall(SYS_subpage_prot, unsigned long " addr ", unsigned long " len ,
22 .BI "            uint32_t *" map );
23 .fi
25 .IR Note :
26 glibc provides no wrapper for
27 .BR subpage_prot (),
28 necessitating the use of
29 .BR syscall (2).
30 .SH DESCRIPTION
31 The PowerPC-specific
32 .BR subpage_prot ()
33 system call provides the facility to control the access
34 permissions on individual 4\ kB subpages on systems configured with
35 a page size of 64\ kB.
37 The protection map is applied to the memory pages in the region starting at
38 .I addr
39 and continuing for
40 .I len
41 bytes.
42 Both of these arguments must be aligned to a 64-kB boundary.
44 The protection map is specified in the buffer pointed to by
45 .IR map .
46 The map has 2 bits per 4\ kB subpage;
47 thus each 32-bit word specifies the protections of 16 4\ kB subpages
48 inside a 64\ kB page
49 (so, the number of 32-bit words pointed to by
50 .I map
51 should equate to the number of 64-kB pages specified by
52 .IR len ).
53 Each 2-bit field in the protection map is either 0 to allow any access,
54 1 to prevent writes, or 2 or 3 to prevent all accesses.
55 .SH RETURN VALUE
56 On success,
57 .BR subpage_prot ()
58 returns 0.
59 Otherwise, one of the error codes specified below is returned.
60 .SH ERRORS
61 .TP
62 .B EFAULT
63 The buffer referred to by
64 .I map
65 is not accessible.
66 .TP
67 .B EINVAL
68 The
69 .I addr
71 .I len
72 arguments are incorrect.
73 Both of these arguments must be aligned to a multiple of the system page size,
74 and they must not refer to a region outside of the
75 address space of the process or to a region that consists of huge pages.
76 .TP
77 .B ENOMEM
78 Out of memory.
79 .SH STANDARDS
80 Linux.
81 .SH HISTORY
82 Linux 2.6.25 (PowerPC).
84 The system call is provided only if the kernel is configured with
85 .BR CONFIG_PPC_64K_PAGES .
86 .SH NOTES
87 Normal page protections (at the 64-kB page level) also apply;
88 the subpage protection mechanism is an additional constraint,
89 so putting 0 in a 2-bit field won't allow writes to a page that is otherwise
90 write-protected.
91 .SS Rationale
92 This system call is provided to assist writing emulators that
93 operate using 64-kB pages on PowerPC systems.
94 When emulating systems such as x86, which uses a smaller page size,
95 the emulator can no longer use the memory-management unit (MMU)
96 and normal system calls for controlling page protections.
97 (The emulator could emulate the MMU by checking and possibly remapping
98 the address for each memory access in software, but that is slow.)
99 The idea is that the emulator supplies an array of protection masks
100 to apply to a specified range of virtual addresses.
101 These masks are applied at the level where hardware page-table entries (PTEs)
102 are inserted into the hardware page table based on the Linux PTEs,
103 so the Linux PTEs are not affected.
104 Implicit in this is that the regions of the address space that are
105 protected are switched to use 4-kB hardware pages rather than 64-kB
106 hardware pages (on machines with hardware 64-kB page support).
107 .\" In the initial implementation, it was the case that:
108 .\"     In fact the whole process is switched to use 4 kB hardware pages when the
109 .\"     subpage_prot system call is used, but this could be improved in future
110 .\"     to switch only the affected segments.
111 .\" But Paul Mackerass says (Oct 2010): I'm pretty sure we now only switch
112 .\" the affected segment, not the whole process.
113 .SH SEE ALSO
114 .BR mprotect (2),
115 .BR syscall (2)
117 .I Documentation/admin\-guide/mm/hugetlbpage.rst
118 in the Linux kernel source tree