Re: [PATCH v7 20/39] arm64/gcs: Context switch GCS state for EL0

From: Deepak Gupta
Date: Wed Dec 13 2023 - 15:00:02 EST


On Wed, Nov 22, 2023 at 1:45 AM Mark Brown <broonie@xxxxxxxxxx> wrote:
> +
> +/*
> + * Apply the GCS mode configured for the specified task to the
> + * hardware.
> + */
> +void gcs_set_el0_mode(struct task_struct *task)
> +{
> + u64 gcscre0_el1 = GCSCRE0_EL1_nTR;
> +
> + if (task->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE)
> + gcscre0_el1 |= GCSCRE0_EL1_RVCHKEN | GCSCRE0_EL1_PCRSEL;

If the intent is to disable, is the GCS stack freed or kept around?
I expect if libc is taking the decision to disable, kernel should free it up.
Is it freed in some other flow?

> +
> + if (task->thread.gcs_el0_mode & PR_SHADOW_STACK_WRITE)
> + gcscre0_el1 |= GCSCRE0_EL1_STREn;
> +
> + if (task->thread.gcs_el0_mode & PR_SHADOW_STACK_PUSH)
> + gcscre0_el1 |= GCSCRE0_EL1_PUSHMEn;
> +
> + write_sysreg_s(gcscre0_el1, SYS_GCSCRE0_EL1);
> +}