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