Skip to content

Commit e6644c9

Browse files
mjeansonIngo Molnar
authored andcommitted
rseq/selftests: Ensure the rseq ABI TLS is actually 1024 bytes
Adding the aligned(1024) attribute to the definition of __rseq_abi did not increase its size to 1024, for this attribute to impact the size of __rseq_abi it would need to be added to the declaration of 'struct rseq_abi'. We only want to increase the size of the TLS allocation to ensure registration will succeed with future extended ABI. Use a union with a dummy member to ensure we allocate 1024 bytes. Signed-off-by: Michael Jeanson <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fd881d0 commit e6644c9

File tree

1 file changed

+16
-5
lines changed
  • tools/testing/selftests/rseq

1 file changed

+16
-5
lines changed

tools/testing/selftests/rseq/rseq.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,20 @@ static int rseq_ownership;
7171
/* Original struct rseq allocation size is 32 bytes. */
7272
#define ORIG_RSEQ_ALLOC_SIZE 32
7373

74+
/*
75+
* Use a union to ensure we allocate a TLS area of 1024 bytes to accomodate an
76+
* rseq registration that is larger than the current rseq ABI.
77+
*/
78+
union rseq {
79+
struct rseq_abi abi;
80+
char dummy[RSEQ_THREAD_AREA_ALLOC_SIZE];
81+
};
82+
7483
static
75-
__thread struct rseq_abi __rseq_abi __attribute__((tls_model("initial-exec"), aligned(RSEQ_THREAD_AREA_ALLOC_SIZE))) = {
76-
.cpu_id = RSEQ_ABI_CPU_ID_UNINITIALIZED,
84+
__thread union rseq __rseq __attribute__((tls_model("initial-exec"))) = {
85+
.abi = {
86+
.cpu_id = RSEQ_ABI_CPU_ID_UNINITIALIZED,
87+
},
7788
};
7889

7990
static int sys_rseq(struct rseq_abi *rseq_abi, uint32_t rseq_len,
@@ -149,7 +160,7 @@ int rseq_register_current_thread(void)
149160
/* Treat libc's ownership as a successful registration. */
150161
return 0;
151162
}
152-
rc = sys_rseq(&__rseq_abi, get_rseq_min_alloc_size(), 0, RSEQ_SIG);
163+
rc = sys_rseq(&__rseq.abi, get_rseq_min_alloc_size(), 0, RSEQ_SIG);
153164
if (rc) {
154165
/*
155166
* After at least one thread has registered successfully
@@ -183,7 +194,7 @@ int rseq_unregister_current_thread(void)
183194
/* Treat libc's ownership as a successful unregistration. */
184195
return 0;
185196
}
186-
rc = sys_rseq(&__rseq_abi, get_rseq_min_alloc_size(), RSEQ_ABI_FLAG_UNREGISTER, RSEQ_SIG);
197+
rc = sys_rseq(&__rseq.abi, get_rseq_min_alloc_size(), RSEQ_ABI_FLAG_UNREGISTER, RSEQ_SIG);
187198
if (rc)
188199
return -1;
189200
return 0;
@@ -249,7 +260,7 @@ void rseq_init(void)
249260
rseq_ownership = 1;
250261

251262
/* Calculate the offset of the rseq area from the thread pointer. */
252-
rseq_offset = (void *)&__rseq_abi - rseq_thread_pointer();
263+
rseq_offset = (void *)&__rseq.abi - rseq_thread_pointer();
253264

254265
/* rseq flags are deprecated, always set to 0. */
255266
rseq_flags = 0;

0 commit comments

Comments
 (0)