Blame man2/subpage_prot.2

Packit 7cfc04
.\" Copyright (c) 2010 Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\" based on a proposal from Stephan Mueller <smueller@atsec.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of
Packit 7cfc04
.\" this manual under the conditions for verbatim copying, provided that
Packit 7cfc04
.\" the entire resulting derived work is distributed under the terms of
Packit 7cfc04
.\" a permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume
Packit 7cfc04
.\" no responsibility for errors or omissions, or for damages resulting
Packit 7cfc04
.\" from the use of the information contained herein.  The author(s) may
Packit 7cfc04
.\" not have taken the same level of care in the production of this
Packit 7cfc04
.\" manual, which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Various pieces of text taken from the kernel source and the commentary
Packit 7cfc04
.\" in kernel commit fa28237cfcc5827553044cbd6ee52e33692b0faa
Packit 7cfc04
.\" both written by Paul Mackerras <paulus@samba.org>
Packit 7cfc04
.\"
Packit 7cfc04
.TH SUBPAGE_PROT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
subpage_prot \- define a subpage protection for an address range
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.BI "long subpage_prot(unsigned long " addr ", unsigned long " len ,
Packit 7cfc04
.BI "                  uint32_t *" map ");
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There is no glibc wrapper for this system call; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The PowerPC-specific
Packit 7cfc04
.BR subpage_prot ()
Packit 7cfc04
system call provides the facility to control the access
Packit 7cfc04
permissions on individual 4\ kB subpages on systems configured with
Packit 7cfc04
a page size of 64\ kB.
Packit 7cfc04
.PP
Packit 7cfc04
The protection map is applied to the memory pages in the region starting at
Packit 7cfc04
.I addr
Packit 7cfc04
and continuing for
Packit 7cfc04
.I len
Packit 7cfc04
bytes.
Packit 7cfc04
Both of these arguments must be aligned to a 64-kB boundary.
Packit 7cfc04
.PP
Packit 7cfc04
The protection map is specified in the buffer pointed to by
Packit 7cfc04
.IR map .
Packit 7cfc04
The map has 2 bits per 4\ kB subpage;
Packit 7cfc04
thus each 32-bit word specifies the protections of 16 4\ kB subpages
Packit 7cfc04
inside a 64\ kB page
Packit 7cfc04
(so, the number of 32-bit words pointed to by
Packit 7cfc04
.I map
Packit 7cfc04
should equate to the number of 64-kB pages specified by
Packit 7cfc04
.IR len ).
Packit 7cfc04
Each 2-bit field in the protection map is either 0 to allow any access,
Packit 7cfc04
1 to prevent writes, or 2 or 3 to prevent all accesses.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR subpage_prot ()
Packit 7cfc04
returns 0.
Packit 7cfc04
Otherwise, one of the error codes specified below is returned.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
The buffer referred to by
Packit 7cfc04
.I map
Packit 7cfc04
is not accessible.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
The
Packit 7cfc04
.I addr
Packit 7cfc04
or
Packit 7cfc04
.I len
Packit 7cfc04
arguments are incorrect.
Packit 7cfc04
Both of these arguments must be aligned to a multiple of the system page size,
Packit 7cfc04
and they must not refer to a region outside of the
Packit 7cfc04
address space of the process or to a region that consists of huge pages.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
Out of memory.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
This system call is provided on the PowerPC architecture
Packit 7cfc04
since Linux 2.6.25.
Packit 7cfc04
The system call is provided only if the kernel is configured with
Packit 7cfc04
.BR CONFIG_PPC_64K_PAGES .
Packit 7cfc04
No library support is provided.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
This system call is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Glibc does not provide a wrapper for this system call; call it using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
.PP
Packit 7cfc04
Normal page protections (at the 64-kB page level) also apply;
Packit 7cfc04
the subpage protection mechanism is an additional constraint,
Packit 7cfc04
so putting 0 in a 2-bit field won't allow writes to a page that is otherwise
Packit 7cfc04
write-protected.
Packit 7cfc04
.SS Rationale
Packit 7cfc04
This system call is provided to assist writing emulators that
Packit 7cfc04
operate using 64-kB pages on PowerPC systems.
Packit 7cfc04
When emulating systems such as x86, which uses a smaller page size,
Packit 7cfc04
the emulator can no longer use the memory-management unit (MMU)
Packit 7cfc04
and normal system calls for controlling page protections.
Packit 7cfc04
(The emulator could emulate the MMU by checking and possibly remapping
Packit 7cfc04
the address for each memory access in software, but that is slow.)
Packit 7cfc04
The idea is that the emulator supplies an array of protection masks
Packit 7cfc04
to apply to a specified range of virtual addresses.
Packit 7cfc04
These masks are applied at the level where hardware page-table entries (PTEs)
Packit 7cfc04
are inserted into the hardware page table based on the Linux PTEs,
Packit 7cfc04
so the Linux PTEs are not affected.
Packit 7cfc04
Implicit in this is that the regions of the address space that are
Packit 7cfc04
protected are switched to use 4-kB hardware pages rather than 64-kB
Packit 7cfc04
hardware pages (on machines with hardware 64-kB page support).
Packit 7cfc04
.\" In the initial implementation, it was the case that:
Packit 7cfc04
.\"     In fact the whole process is switched to use 4 kB hardware pages when the
Packit 7cfc04
.\"     subpage_prot system call is used, but this could be improved in future
Packit 7cfc04
.\"     to switch only the affected segments.
Packit 7cfc04
.\" But Paul Mackerass says (Oct 2010): I'm pretty sure we now only switch
Packit 7cfc04
.\" the affected segment, not the whole process.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR mprotect (2),
Packit 7cfc04
.BR syscall (2)
Packit 7cfc04
.PP
Packit 7cfc04
.IR Documentation/vm/hugetlbpage.txt
Packit 7cfc04
in the Linux kernel source tree
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.