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