Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: x86: convert protection-keys.txt to reST

This converts the plain text documentation to reStructuredText format and
add it to Sphinx TOC tree. No essential content change.

Signed-off-by: Changbin Du <changbin.du@gmail.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>

authored by

Changbin Du and committed by
Jonathan Corbet
28e21eac 2f6eae47

+22 -12
+1
Documentation/x86/index.rst
··· 18 18 tlb 19 19 mtrr 20 20 pat 21 + protection-keys
+21 -12
Documentation/x86/protection-keys.txt Documentation/x86/protection-keys.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ====================== 4 + Memory Protection Keys 5 + ====================== 6 + 1 7 Memory Protection Keys for Userspace (PKU aka PKEYs) is a feature 2 8 which is found on Intel's Skylake "Scalable Processor" Server CPUs. 3 9 It will be avalable in future non-server parts. ··· 29 23 permissions are enforced on data access only and have no effect on 30 24 instruction fetches. 31 25 32 - =========================== Syscalls =========================== 26 + Syscalls 27 + ======== 33 28 34 - There are 3 system calls which directly interact with pkeys: 29 + There are 3 system calls which directly interact with pkeys:: 35 30 36 31 int pkey_alloc(unsigned long flags, unsigned long init_access_rights) 37 32 int pkey_free(int pkey); ··· 44 37 directly in order to change access permissions to memory covered 45 38 with a key. In this example WRPKRU is wrapped by a C function 46 39 called pkey_set(). 40 + :: 47 41 48 42 int real_prot = PROT_READ|PROT_WRITE; 49 43 pkey = pkey_alloc(0, PKEY_DISABLE_WRITE); ··· 53 45 ... application runs here 54 46 55 47 Now, if the application needs to update the data at 'ptr', it can 56 - gain access, do the update, then remove its write access: 48 + gain access, do the update, then remove its write access:: 57 49 58 50 pkey_set(pkey, 0); // clear PKEY_DISABLE_WRITE 59 51 *ptr = foo; // assign something 60 52 pkey_set(pkey, PKEY_DISABLE_WRITE); // set PKEY_DISABLE_WRITE again 61 53 62 54 Now when it frees the memory, it will also free the pkey since it 63 - is no longer in use: 55 + is no longer in use:: 64 56 65 57 munmap(ptr, PAGE_SIZE); 66 58 pkey_free(pkey); 67 59 68 - (Note: pkey_set() is a wrapper for the RDPKRU and WRPKRU instructions. 69 - An example implementation can be found in 70 - tools/testing/selftests/x86/protection_keys.c) 60 + .. note:: pkey_set() is a wrapper for the RDPKRU and WRPKRU instructions. 61 + An example implementation can be found in 62 + tools/testing/selftests/x86/protection_keys.c. 71 63 72 - =========================== Behavior =========================== 64 + Behavior 65 + ======== 73 66 74 67 The kernel attempts to make protection keys consistent with the 75 - behavior of a plain mprotect(). For instance if you do this: 68 + behavior of a plain mprotect(). For instance if you do this:: 76 69 77 70 mprotect(ptr, size, PROT_NONE); 78 71 something(ptr); 79 72 80 - you can expect the same effects with protection keys when doing this: 73 + you can expect the same effects with protection keys when doing this:: 81 74 82 75 pkey = pkey_alloc(0, PKEY_DISABLE_WRITE | PKEY_DISABLE_READ); 83 76 pkey_mprotect(ptr, size, PROT_READ|PROT_WRITE, pkey); 84 77 something(ptr); 85 78 86 79 That should be true whether something() is a direct access to 'ptr' 87 - like: 80 + like:: 88 81 89 82 *ptr = foo; 90 83 91 84 or when the kernel does the access on the application's behalf like 92 - with a read(): 85 + with a read():: 93 86 94 87 read(fd, ptr, 1); 95 88