summaryrefslogtreecommitdiffstats
path: root/Documentation/x86
diff options
context:
space:
mode:
authorChangbin Du <changbin.du@gmail.com>2019-05-08 11:21:26 -0400
committerJonathan Corbet <corbet@lwn.net>2019-05-08 16:34:10 -0400
commit28e21eac94a2ee2512ae6c21f04a0b41fb26cb0b (patch)
tree454cf1033cb288d76f32edad35103434155a5b8f /Documentation/x86
parent2f6eae4730120fd6459f55e47b750cd3570e9349 (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.rst1
-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======================
4Memory Protection Keys
5======================
6
1Memory Protection Keys for Userspace (PKU aka PKEYs) is a feature 7Memory Protection Keys for Userspace (PKU aka PKEYs) is a feature
2which is found on Intel's Skylake "Scalable Processor" Server CPUs. 8which is found on Intel's Skylake "Scalable Processor" Server CPUs.
3It will be avalable in future non-server parts. 9It will be avalable in future non-server parts.
@@ -23,9 +29,10 @@ even though there is theoretically space in the PAE PTEs. These
23permissions are enforced on data access only and have no effect on 29permissions are enforced on data access only and have no effect on
24instruction fetches. 30instruction fetches.
25 31
26=========================== Syscalls =========================== 32Syscalls
33========
27 34
28There are 3 system calls which directly interact with pkeys: 35There 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
37directly in order to change access permissions to memory covered 44directly in order to change access permissions to memory covered
38with a key. In this example WRPKRU is wrapped by a C function 45with a key. In this example WRPKRU is wrapped by a C function
39called pkey_set(). 46called 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
47Now, if the application needs to update the data at 'ptr', it can 55Now, if the application needs to update the data at 'ptr', it can
48gain access, do the update, then remove its write access: 56gain 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
54Now when it frees the memory, it will also free the pkey since it 62Now when it frees the memory, it will also free the pkey since it
55is no longer in use: 63is 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 =========================== 72Behavior
73========
65 74
66The kernel attempts to make protection keys consistent with the 75The kernel attempts to make protection keys consistent with the
67behavior of a plain mprotect(). For instance if you do this: 76behavior 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
72you can expect the same effects with protection keys when doing this: 81you 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
78That should be true whether something() is a direct access to 'ptr' 87That should be true whether something() is a direct access to 'ptr'
79like: 88like::
80 89
81 *ptr = foo; 90 *ptr = foo;
82 91
83or when the kernel does the access on the application's behalf like 92or when the kernel does the access on the application's behalf like
84with a read(): 93with a read()::
85 94
86 read(fd, ptr, 1); 95 read(fd, ptr, 1);
87 96