Skip to content

Commit 391ca7c

Browse files
LeviYeoReumctmarinas
authored andcommitted
kselftest/arm64/mte: Preparation for mte store only test
Since ARMv8.9, FEAT_MTE_STORE_ONLY can be used to restrict raise of tag check fault on store operation only. This patch is preparation for testing FEAT_MTE_STORE_ONLY It shouldn't change test result. Signed-off-by: Yeoreum Yun <[email protected]> Reviewed-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 964a074 commit 391ca7c

File tree

9 files changed

+33
-22
lines changed

9 files changed

+33
-22
lines changed

tools/testing/selftests/arm64/mte/check_buffer_fill.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int check_buffer_by_byte(int mem_type, int mode)
3131
int i, j, item;
3232
bool err;
3333

34-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
34+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
3535
item = ARRAY_SIZE(sizes);
3636

3737
for (i = 0; i < item; i++) {
@@ -68,7 +68,7 @@ static int check_buffer_underflow_by_byte(int mem_type, int mode,
6868
bool err;
6969
char *und_ptr = NULL;
7070

71-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
71+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
7272
item = ARRAY_SIZE(sizes);
7373
for (i = 0; i < item; i++) {
7474
ptr = (char *)mte_allocate_memory_tag_range(sizes[i], mem_type, 0,
@@ -164,7 +164,7 @@ static int check_buffer_overflow_by_byte(int mem_type, int mode,
164164
size_t tagged_size, overflow_size;
165165
char *over_ptr = NULL;
166166

167-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
167+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
168168
item = ARRAY_SIZE(sizes);
169169
for (i = 0; i < item; i++) {
170170
ptr = (char *)mte_allocate_memory_tag_range(sizes[i], mem_type, 0,
@@ -337,7 +337,7 @@ static int check_buffer_by_block(int mem_type, int mode)
337337
{
338338
int i, item, result = KSFT_PASS;
339339

340-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
340+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
341341
item = ARRAY_SIZE(sizes);
342342
cur_mte_cxt.fault_valid = false;
343343
for (i = 0; i < item; i++) {
@@ -368,7 +368,7 @@ static int check_memory_initial_tags(int mem_type, int mode, int mapping)
368368
int run, fd;
369369
int total = ARRAY_SIZE(sizes);
370370

371-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
371+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
372372
for (run = 0; run < total; run++) {
373373
/* check initial tags for anonymous mmap */
374374
ptr = (char *)mte_allocate_memory(sizes[run], mem_type, mapping, false);

tools/testing/selftests/arm64/mte/check_child_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int check_child_memory_mapping(int mem_type, int mode, int mapping)
8888
int item = ARRAY_SIZE(sizes);
8989

9090
item = ARRAY_SIZE(sizes);
91-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
91+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
9292
for (run = 0; run < item; run++) {
9393
ptr = (char *)mte_allocate_memory_tag_range(sizes[run], mem_type, mapping,
9494
UNDERFLOW, OVERFLOW);
@@ -109,7 +109,7 @@ static int check_child_file_mapping(int mem_type, int mode, int mapping)
109109
int run, fd, map_size, result = KSFT_PASS;
110110
int total = ARRAY_SIZE(sizes);
111111

112-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
112+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
113113
for (run = 0; run < total; run++) {
114114
fd = create_temp_file();
115115
if (fd == -1)

tools/testing/selftests/arm64/mte/check_hugetlb_options.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int check_hugetlb_memory_mapping(int mem_type, int mode, int mapping, int
151151

152152
map_size = default_huge_page_size();
153153

154-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
154+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
155155
map_ptr = (char *)mte_allocate_memory(map_size, mem_type, mapping, false);
156156
if (check_allocated_memory(map_ptr, map_size, mem_type, false) != KSFT_PASS)
157157
return KSFT_FAIL;
@@ -180,7 +180,7 @@ static int check_clear_prot_mte_flag(int mem_type, int mode, int mapping)
180180
unsigned long map_size;
181181

182182
prot_flag = PROT_READ | PROT_WRITE;
183-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
183+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
184184
map_size = default_huge_page_size();
185185
map_ptr = (char *)mte_allocate_memory_tag_range(map_size, mem_type, mapping,
186186
0, 0);
@@ -210,7 +210,7 @@ static int check_child_hugetlb_memory_mapping(int mem_type, int mode, int mappin
210210

211211
map_size = default_huge_page_size();
212212

213-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
213+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
214214
ptr = (char *)mte_allocate_memory_tag_range(map_size, mem_type, mapping,
215215
0, 0);
216216
if (check_allocated_memory_range(ptr, map_size, mem_type,

tools/testing/selftests/arm64/mte/check_ksm_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int check_madvise_options(int mem_type, int mode, int mapping)
106106
return err;
107107
}
108108

109-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
109+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
110110
ptr = mte_allocate_memory(TEST_UNIT * page_sz, mem_type, mapping, true);
111111
if (check_allocated_memory(ptr, TEST_UNIT * page_sz, mem_type, false) != KSFT_PASS)
112112
return KSFT_FAIL;

tools/testing/selftests/arm64/mte/check_mmap_options.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int check_anonymous_memory_mapping(int mem_type, int mode, int mapping, i
9090
int run, result, map_size;
9191
int item = ARRAY_SIZE(sizes);
9292

93-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
93+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
9494
for (run = 0; run < item; run++) {
9595
map_size = sizes[run] + OVERFLOW + UNDERFLOW;
9696
map_ptr = (char *)mte_allocate_memory(map_size, mem_type, mapping, false);
@@ -122,7 +122,7 @@ static int check_file_memory_mapping(int mem_type, int mode, int mapping, int ta
122122
int total = ARRAY_SIZE(sizes);
123123
int result = KSFT_PASS;
124124

125-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
125+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
126126
for (run = 0; run < total; run++) {
127127
fd = create_temp_file();
128128
if (fd == -1)
@@ -161,7 +161,7 @@ static int check_clear_prot_mte_flag(int mem_type, int mode, int mapping, int at
161161
int total = ARRAY_SIZE(sizes);
162162

163163
prot_flag = PROT_READ | PROT_WRITE;
164-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
164+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
165165
for (run = 0; run < total; run++) {
166166
map_size = sizes[run] + OVERFLOW + UNDERFLOW;
167167
ptr = (char *)mte_allocate_memory_tag_range(sizes[run], mem_type, mapping,

tools/testing/selftests/arm64/mte/check_tags_inclusion.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int check_single_included_tags(int mem_type, int mode)
5757
return KSFT_FAIL;
5858

5959
for (tag = 0; (tag < MT_TAG_COUNT) && (result == KSFT_PASS); tag++) {
60-
ret = mte_switch_mode(mode, MT_INCLUDE_VALID_TAG(tag));
60+
ret = mte_switch_mode(mode, MT_INCLUDE_VALID_TAG(tag), false);
6161
if (ret != 0)
6262
result = KSFT_FAIL;
6363
/* Try to catch a excluded tag by a number of tries. */
@@ -91,7 +91,7 @@ static int check_multiple_included_tags(int mem_type, int mode)
9191

9292
for (tag = 0; (tag < MT_TAG_COUNT - 1) && (result == KSFT_PASS); tag++) {
9393
excl_mask |= 1 << tag;
94-
mte_switch_mode(mode, MT_INCLUDE_VALID_TAGS(excl_mask));
94+
mte_switch_mode(mode, MT_INCLUDE_VALID_TAGS(excl_mask), false);
9595
/* Try to catch a excluded tag by a number of tries. */
9696
for (run = 0; (run < RUNS) && (result == KSFT_PASS); run++) {
9797
ptr = mte_insert_tags(ptr, BUFFER_SIZE);
@@ -120,7 +120,7 @@ static int check_all_included_tags(int mem_type, int mode)
120120
mem_type, false) != KSFT_PASS)
121121
return KSFT_FAIL;
122122

123-
ret = mte_switch_mode(mode, MT_INCLUDE_TAG_MASK);
123+
ret = mte_switch_mode(mode, MT_INCLUDE_TAG_MASK, false);
124124
if (ret != 0)
125125
return KSFT_FAIL;
126126
/* Try to catch a excluded tag by a number of tries. */
@@ -145,7 +145,7 @@ static int check_none_included_tags(int mem_type, int mode)
145145
if (check_allocated_memory(ptr, BUFFER_SIZE, mem_type, false) != KSFT_PASS)
146146
return KSFT_FAIL;
147147

148-
ret = mte_switch_mode(mode, MT_EXCLUDE_TAG_MASK);
148+
ret = mte_switch_mode(mode, MT_EXCLUDE_TAG_MASK, false);
149149
if (ret != 0)
150150
return KSFT_FAIL;
151151
/* Try to catch a excluded tag by a number of tries. */

tools/testing/selftests/arm64/mte/check_user_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping,
4444

4545
err = KSFT_PASS;
4646
len = 2 * page_sz;
47-
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
47+
mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG, false);
4848
fd = create_temp_file();
4949
if (fd == -1)
5050
return KSFT_FAIL;

tools/testing/selftests/arm64/mte/mte_common_util.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
struct mte_fault_cxt cur_mte_cxt;
3030
bool mtefar_support;
31+
bool mtestonly_support;
3132
static unsigned int mte_cur_mode;
3233
static unsigned int mte_cur_pstate_tco;
34+
static bool mte_cur_stonly;
3335

3436
void mte_default_handler(int signum, siginfo_t *si, void *uc)
3537
{
@@ -314,7 +316,7 @@ void mte_initialize_current_context(int mode, uintptr_t ptr, ssize_t range)
314316
cur_mte_cxt.trig_si_code = 0;
315317
}
316318

317-
int mte_switch_mode(int mte_option, unsigned long incl_mask)
319+
int mte_switch_mode(int mte_option, unsigned long incl_mask, bool stonly)
318320
{
319321
unsigned long en = 0;
320322

@@ -346,6 +348,9 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask)
346348
break;
347349
}
348350

351+
if (mtestonly_support && stonly)
352+
en |= PR_MTE_STORE_ONLY;
353+
349354
en |= (incl_mask << PR_MTE_TAG_SHIFT);
350355
/* Enable address tagging ABI, mte error reporting mode and tag inclusion mask. */
351356
if (prctl(PR_SET_TAGGED_ADDR_CTRL, en, 0, 0, 0) != 0) {
@@ -370,6 +375,9 @@ int mte_default_setup(void)
370375

371376
mtefar_support = !!(hwcaps3 & HWCAP3_MTE_FAR);
372377

378+
if (hwcaps3 & HWCAP3_MTE_STORE_ONLY)
379+
mtestonly_support = true;
380+
373381
/* Get current mte mode */
374382
ret = prctl(PR_GET_TAGGED_ADDR_CTRL, en, 0, 0, 0);
375383
if (ret < 0) {
@@ -383,6 +391,8 @@ int mte_default_setup(void)
383391
else if (ret & PR_MTE_TCF_NONE)
384392
mte_cur_mode = MTE_NONE_ERR;
385393

394+
mte_cur_stonly = (ret & PR_MTE_STORE_ONLY) ? true : false;
395+
386396
mte_cur_pstate_tco = mte_get_pstate_tco();
387397
/* Disable PSTATE.TCO */
388398
mte_disable_pstate_tco();
@@ -391,7 +401,7 @@ int mte_default_setup(void)
391401

392402
void mte_restore_setup(void)
393403
{
394-
mte_switch_mode(mte_cur_mode, MTE_ALLOW_NON_ZERO_TAG);
404+
mte_switch_mode(mte_cur_mode, MTE_ALLOW_NON_ZERO_TAG, mte_cur_stonly);
395405
if (mte_cur_pstate_tco == MT_PSTATE_TCO_EN)
396406
mte_enable_pstate_tco();
397407
else if (mte_cur_pstate_tco == MT_PSTATE_TCO_DIS)

tools/testing/selftests/arm64/mte/mte_common_util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct mte_fault_cxt {
3838

3939
extern struct mte_fault_cxt cur_mte_cxt;
4040
extern bool mtefar_support;
41+
extern bool mtestonly_support;
4142

4243
/* MTE utility functions */
4344
void mte_default_handler(int signum, siginfo_t *si, void *uc);
@@ -60,7 +61,7 @@ void *mte_insert_atag(void *ptr);
6061
void *mte_clear_atag(void *ptr);
6162
int mte_default_setup(void);
6263
void mte_restore_setup(void);
63-
int mte_switch_mode(int mte_option, unsigned long incl_mask);
64+
int mte_switch_mode(int mte_option, unsigned long incl_mask, bool stonly);
6465
void mte_initialize_current_context(int mode, uintptr_t ptr, ssize_t range);
6566

6667
/* Common utility functions */

0 commit comments

Comments
 (0)