xref: /openbmc/qemu/tests/tcg/aarch64/mte-7.c (revision 7d87775f)
1 /*
2  * Memory tagging, unaligned access crossing pages.
3  * https://gitlab.com/qemu-project/qemu/-/issues/403
4  *
5  * Copyright (c) 2021 Linaro Ltd
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "mte.h"
10 
11 int main(int ac, char **av)
12 {
13     void *p;
14 
15     enable_mte(PR_MTE_TCF_SYNC);
16     p = alloc_mte_mem(2 * 0x1000);
17 
18     /* Tag the pointer. */
19     p = (void *)((unsigned long)p | (1ul << 56));
20 
21     /* Store tag in sequential granules. */
22     asm("stz2g %0, [%0]" : : "r"(p + 0x0ff0));
23 
24     /*
25      * Perform an unaligned store with tag 1 crossing the pages.
26      * Failure dies with SIGSEGV.
27      */
28     asm("str %0, [%0]" : : "r"(p + 0x0ffc));
29     return 0;
30 }
31