1 | /* Test TLSDESC relocation with AMX. |
2 | Copyright (C) 2024 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <stdbool.h> |
20 | #include <asm/prctl.h> |
21 | #include <support/check.h> |
22 | #include "tst-gnu2-tls2-amx.h" |
23 | |
24 | extern int arch_prctl (int, ...); |
25 | |
26 | #define X86_XSTATE_TILECFG_ID 17 |
27 | #define X86_XSTATE_TILEDATA_ID 18 |
28 | |
29 | /* Initialize tile config. */ |
30 | __attribute__ ((noinline, noclone)) |
31 | static void |
32 | init_tile_config (__tilecfg *tileinfo) |
33 | { |
34 | int i; |
35 | tileinfo->palette_id = 1; |
36 | tileinfo->start_row = 0; |
37 | |
38 | tileinfo->colsb[0] = MAX_ROWS; |
39 | tileinfo->rows[0] = MAX_ROWS; |
40 | |
41 | for (i = 1; i < 4; ++i) |
42 | { |
43 | tileinfo->colsb[i] = MAX_COLS; |
44 | tileinfo->rows[i] = MAX_ROWS; |
45 | } |
46 | |
47 | _tile_loadconfig (config: tileinfo); |
48 | } |
49 | |
50 | static bool |
51 | enable_amx (void) |
52 | { |
53 | uint64_t bitmask; |
54 | if (arch_prctl (ARCH_GET_XCOMP_PERM, &bitmask) != 0) |
55 | return false; |
56 | |
57 | if ((bitmask & (1 << X86_XSTATE_TILECFG_ID)) == 0) |
58 | return false; |
59 | |
60 | if (arch_prctl (ARCH_REQ_XCOMP_PERM, X86_XSTATE_TILEDATA_ID) != 0) |
61 | return false; |
62 | |
63 | /* Load tile configuration. */ |
64 | __tilecfg tile_data = { 0 }; |
65 | init_tile_config (tileinfo: &tile_data); |
66 | |
67 | return true; |
68 | } |
69 | |
70 | /* An architecture can define it to clobber caller-saved registers in |
71 | malloc below to verify that the implicit TLSDESC call won't change |
72 | caller-saved registers. */ |
73 | static void |
74 | clear_tile_register (void) |
75 | { |
76 | _tile_zero (2); |
77 | } |
78 | |
79 | #define MOD(i) "tst-gnu2-tls2-amx-mod" #i ".so" |
80 | #define IS_SUPPORTED() enable_amx () |
81 | #define PREPARE_MALLOC() clear_tile_register () |
82 | |
83 | #include <elf/tst-gnu2-tls2.c> |
84 | |