From: Richard Henderson Date: Wed, 8 Oct 2025 21:56:04 +0000 (-0700) Subject: linux-user/aarch64: Allocate new gcs stack on clone X-Git-Tag: v10.2.0-rc1~67^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f57359b3f0c85482c35f6668b0815c350ff5d451;p=thirdparty%2Fqemu.git linux-user/aarch64: Allocate new gcs stack on clone Allocate the new stack early, so that error reporting need not clean up other objects. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson Message-id: 20251008215613.300150-65-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 56695de680..dffe6c2016 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6686,6 +6686,21 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, ts = g_new0(TaskState, 1); init_task_state(ts); +#ifdef TARGET_AARCH64 + /* + * If GCS is enabled in the parent thread, it is also enabled + * in the child thread, but with a newly allocated stack. + */ + abi_long new_gcspr = 0; + if (env->cp15.gcscr_el[0] & GCSCR_PCRSEL) { + new_gcspr = gcs_new_stack(ts); + if (new_gcspr == -1) { + g_free(ts); + return -TARGET_ENOMEM; + } + } +#endif + /* Grab a mutex so that thread setup appears atomic. */ pthread_mutex_lock(&clone_lock); @@ -6707,6 +6722,11 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, ts->info = parent_ts->info; ts->signal_mask = parent_ts->signal_mask; +#ifdef TARGET_AARCH64 + ts->gcs_el0_locked = parent_ts->gcs_el0_locked; + new_env->cp15.gcspr_el[0] = new_gcspr; +#endif + if (flags & CLONE_CHILD_CLEARTID) { ts->child_tidptr = child_tidptr; }