readv2: Note preadv2(..., RWF_NOWAIT) bug in BUGS section
[man-pages.git] / man2 / subpage_prot.2
blob91bb789e1fc9fc539390249647aea5e50e1ec2c7
1 .\" Copyright (c) 2010 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" based on a proposal from Stephan Mueller <smueller@atsec.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of
10 .\" this manual under the conditions for verbatim copying, provided that
11 .\" the entire resulting derived work is distributed under the terms of
12 .\" a permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume
16 .\" no responsibility for errors or omissions, or for damages resulting
17 .\" from the use of the information contained herein.  The author(s) may
18 .\" not have taken the same level of care in the production of this
19 .\" manual, which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Various pieces of text taken from the kernel source and the commentary
27 .\" in kernel commit fa28237cfcc5827553044cbd6ee52e33692b0faa
28 .\" both written by Paul Mackerras <paulus@samba.org>
29 .\"
30 .TH SUBPAGE_PROT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 subpage_prot \- define a subpage protection for an address range
33 .SH SYNOPSIS
34 .nf
35 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
36 .B #include <unistd.h>
37 .PP
38 .BI "int syscall(SYS_subpage_prot, unsigned long " addr ", unsigned long " len ,
39 .BI "            uint32_t *" map );
40 .fi
41 .PP
42 .IR Note :
43 glibc provides no wrapper for
44 .BR subpage_prot (),
45 necessitating the use of
46 .BR syscall (2).
47 .SH DESCRIPTION
48 The PowerPC-specific
49 .BR subpage_prot ()
50 system call provides the facility to control the access
51 permissions on individual 4\ kB subpages on systems configured with
52 a page size of 64\ kB.
53 .PP
54 The protection map is applied to the memory pages in the region starting at
55 .I addr
56 and continuing for
57 .I len
58 bytes.
59 Both of these arguments must be aligned to a 64-kB boundary.
60 .PP
61 The protection map is specified in the buffer pointed to by
62 .IR map .
63 The map has 2 bits per 4\ kB subpage;
64 thus each 32-bit word specifies the protections of 16 4\ kB subpages
65 inside a 64\ kB page
66 (so, the number of 32-bit words pointed to by
67 .I map
68 should equate to the number of 64-kB pages specified by
69 .IR len ).
70 Each 2-bit field in the protection map is either 0 to allow any access,
71 1 to prevent writes, or 2 or 3 to prevent all accesses.
72 .SH RETURN VALUE
73 On success,
74 .BR subpage_prot ()
75 returns 0.
76 Otherwise, one of the error codes specified below is returned.
77 .SH ERRORS
78 .TP
79 .B EFAULT
80 The buffer referred to by
81 .I map
82 is not accessible.
83 .TP
84 .B EINVAL
85 The
86 .I addr
88 .I len
89 arguments are incorrect.
90 Both of these arguments must be aligned to a multiple of the system page size,
91 and they must not refer to a region outside of the
92 address space of the process or to a region that consists of huge pages.
93 .TP
94 .B ENOMEM
95 Out of memory.
96 .SH VERSIONS
97 This system call is provided on the PowerPC architecture
98 since Linux 2.6.25.
99 The system call is provided only if the kernel is configured with
100 .BR CONFIG_PPC_64K_PAGES .
101 No library support is provided.
102 .SH CONFORMING TO
103 This system call is Linux-specific.
104 .SH NOTES
105 Normal page protections (at the 64-kB page level) also apply;
106 the subpage protection mechanism is an additional constraint,
107 so putting 0 in a 2-bit field won't allow writes to a page that is otherwise
108 write-protected.
109 .SS Rationale
110 This system call is provided to assist writing emulators that
111 operate using 64-kB pages on PowerPC systems.
112 When emulating systems such as x86, which uses a smaller page size,
113 the emulator can no longer use the memory-management unit (MMU)
114 and normal system calls for controlling page protections.
115 (The emulator could emulate the MMU by checking and possibly remapping
116 the address for each memory access in software, but that is slow.)
117 The idea is that the emulator supplies an array of protection masks
118 to apply to a specified range of virtual addresses.
119 These masks are applied at the level where hardware page-table entries (PTEs)
120 are inserted into the hardware page table based on the Linux PTEs,
121 so the Linux PTEs are not affected.
122 Implicit in this is that the regions of the address space that are
123 protected are switched to use 4-kB hardware pages rather than 64-kB
124 hardware pages (on machines with hardware 64-kB page support).
125 .\" In the initial implementation, it was the case that:
126 .\"     In fact the whole process is switched to use 4 kB hardware pages when the
127 .\"     subpage_prot system call is used, but this could be improved in future
128 .\"     to switch only the affected segments.
129 .\" But Paul Mackerass says (Oct 2010): I'm pretty sure we now only switch
130 .\" the affected segment, not the whole process.
131 .SH SEE ALSO
132 .BR mprotect (2),
133 .BR syscall (2)
135 .IR Documentation/admin\-guide/mm/hugetlbpage.rst
136 in the Linux kernel source tree