@@ -77,14 +77,20 @@ configurable behaviours:
77
77
address is unknown).
78
78
79
79
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 ``
82
82
bit-field:
83
83
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)
85
86
- ``PR_MTE_TCF_SYNC `` - *Synchronous * tag check fault mode
86
87
- ``PR_MTE_TCF_ASYNC `` - *Asynchronous * tag check fault mode
87
88
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
+
88
94
The current tag check fault mode can be read using the
89
95
``prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) `` system call.
90
96
@@ -120,13 +126,39 @@ in the ``PR_MTE_TAG_MASK`` bit-field.
120
126
interface provides an include mask. An include mask of ``0 `` (exclusion
121
127
mask ``0xffff ``) results in the CPU always generating tag ``0 ``.
122
128
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
+
123
155
Initial process state
124
156
---------------------
125
157
126
158
On ``execve() ``, the new process has the following configuration:
127
159
128
160
- ``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)
130
162
- ``PR_MTE_TAG_MASK `` set to 0 (all tags excluded)
131
163
- ``PSTATE.TCO `` set to 0
132
164
- ``PROT_MTE `` not set on any of the initial memory maps
@@ -251,11 +283,13 @@ Example of correct usage
251
283
return EXIT_FAILURE;
252
284
253
285
/*
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.
256
289
*/
257
290
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),
259
293
0, 0, 0)) {
260
294
perror("prctl() failed");
261
295
return EXIT_FAILURE;
0 commit comments