Skip to content

Commit 80c7c36

Browse files
pccctmarinas
authored andcommitted
Documentation: document the preferred tag checking mode feature
Document the functionality added in the previous patches. Link: https://linux-review.googlesource.com/id/I48217cc3e8b8da33abc08cbaddc11cf4360a1b86 Signed-off-by: Peter Collingbourne <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Will Deacon <[email protected]> [[email protected]: clarify that the change happens on task scheduling] Signed-off-by: Catalin Marinas <[email protected]>
1 parent dd06161 commit 80c7c36

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,20 @@ Description: SPURR ticks for cpuX when it was idle.
640640

641641
This sysfs interface exposes the number of SPURR ticks
642642
for cpuX when it was idle.
643+
644+
What: /sys/devices/system/cpu/cpuX/mte_tcf_preferred
645+
Date: July 2021
646+
Contact: Linux ARM Kernel Mailing list <[email protected]>
647+
Description: Preferred MTE tag checking mode
648+
649+
When a user program specifies more than one MTE tag checking
650+
mode, this sysfs node is used to specify which mode should
651+
be preferred when scheduling a task on that CPU. Possible
652+
values:
653+
654+
================ ==============================================
655+
"sync" Prefer synchronous mode
656+
"async" Prefer asynchronous mode
657+
================ ==============================================
658+
659+
See also: Documentation/arm64/memory-tagging-extension.rst

Documentation/arm64/memory-tagging-extension.rst

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,20 @@ configurable behaviours:
7777
address is unknown).
7878

7979
The user can select the above modes, per thread, using the
80-
``prctl(PR_SET_TAGGED_ADDR_CTRL, flags, 0, 0, 0)`` system call where
81-
``flags`` contain one of the following values in the ``PR_MTE_TCF_MASK``
80+
``prctl(PR_SET_TAGGED_ADDR_CTRL, flags, 0, 0, 0)`` system call where ``flags``
81+
contains any number of the following values in the ``PR_MTE_TCF_MASK``
8282
bit-field:
8383

84-
- ``PR_MTE_TCF_NONE`` - *Ignore* tag check faults
84+
- ``PR_MTE_TCF_NONE``  - *Ignore* tag check faults
85+
(ignored if combined with other options)
8586
- ``PR_MTE_TCF_SYNC`` - *Synchronous* tag check fault mode
8687
- ``PR_MTE_TCF_ASYNC`` - *Asynchronous* tag check fault mode
8788

89+
If no modes are specified, tag check faults are ignored. If a single
90+
mode is specified, the program will run in that mode. If multiple
91+
modes are specified, the mode is selected as described in the "Per-CPU
92+
preferred tag checking modes" section below.
93+
8894
The current tag check fault mode can be read using the
8995
``prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)`` system call.
9096

@@ -120,13 +126,39 @@ in the ``PR_MTE_TAG_MASK`` bit-field.
120126
interface provides an include mask. An include mask of ``0`` (exclusion
121127
mask ``0xffff``) results in the CPU always generating tag ``0``.
122128

129+
Per-CPU preferred tag checking mode
130+
-----------------------------------
131+
132+
On some CPUs the performance of MTE in stricter tag checking modes
133+
is similar to that of less strict tag checking modes. This makes it
134+
worthwhile to enable stricter checks on those CPUs when a less strict
135+
checking mode is requested, in order to gain the error detection
136+
benefits of the stricter checks without the performance downsides. To
137+
support this scenario, a privileged user may configure a stricter
138+
tag checking mode as the CPU's preferred tag checking mode.
139+
140+
The preferred tag checking mode for each CPU is controlled by
141+
``/sys/devices/system/cpu/cpu<N>/mte_tcf_preferred``, to which a
142+
privileged user may write the value ``async`` or ``sync``. The default
143+
preferred mode for each CPU is ``async``.
144+
145+
To allow a program to potentially run in the CPU's preferred tag
146+
checking mode, the user program may set multiple tag check fault mode
147+
bits in the ``flags`` argument to the ``prctl(PR_SET_TAGGED_ADDR_CTRL,
148+
flags, 0, 0, 0)`` system call. If the CPU's preferred tag checking
149+
mode is in the task's set of provided tag checking modes (this will
150+
always be the case at present because the kernel only supports two
151+
tag checking modes, but future kernels may support more modes), that
152+
mode will be selected. Otherwise, one of the modes in the task's mode
153+
set will be selected in a currently unspecified manner.
154+
123155
Initial process state
124156
---------------------
125157

126158
On ``execve()``, the new process has the following configuration:
127159

128160
- ``PR_TAGGED_ADDR_ENABLE`` set to 0 (disabled)
129-
- Tag checking mode set to ``PR_MTE_TCF_NONE``
161+
- No tag checking modes are selected (tag check faults ignored)
130162
- ``PR_MTE_TAG_MASK`` set to 0 (all tags excluded)
131163
- ``PSTATE.TCO`` set to 0
132164
- ``PROT_MTE`` not set on any of the initial memory maps
@@ -251,11 +283,13 @@ Example of correct usage
251283
return EXIT_FAILURE;
252284
253285
/*
254-
* Enable the tagged address ABI, synchronous MTE tag check faults and
255-
* allow all non-zero tags in the randomly generated set.
286+
* Enable the tagged address ABI, synchronous or asynchronous MTE
287+
* tag check faults (based on per-CPU preference) and allow all
288+
* non-zero tags in the randomly generated set.
256289
*/
257290
if (prctl(PR_SET_TAGGED_ADDR_CTRL,
258-
PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | (0xfffe << PR_MTE_TAG_SHIFT),
291+
PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC |
292+
(0xfffe << PR_MTE_TAG_SHIFT),
259293
0, 0, 0)) {
260294
perror("prctl() failed");
261295
return EXIT_FAILURE;

0 commit comments

Comments
 (0)