All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Peter Collingbourne <pcc@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Will Deacon <will@kernel.org>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Evgenii Stepanov <eugenis@google.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm64: kasan: mte: move GCR_EL1 switch to task switch when KASAN disabled
Date: Thu, 9 Sep 2021 18:39:51 +0100	[thread overview]
Message-ID: <YTpG5xT+sotOsjTD@arm.com> (raw)
In-Reply-To: <20210827030748.587710-1-pcc@google.com>

On Thu, Aug 26, 2021 at 08:07:48PM -0700, Peter Collingbourne wrote:
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 923ee2ac85fd..e12ed892cde8 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -178,9 +178,9 @@ alternative_else_nop_endif
>  
>  	.macro mte_set_kernel_gcr, tmp, tmp2
>  #ifdef CONFIG_KASAN_HW_TAGS
> -alternative_if_not ARM64_MTE
> +alternative_cb	kasan_hw_tags_enable
>  	b	1f
> -alternative_else_nop_endif
> +alternative_cb_end
>  	mov	\tmp, KERNEL_GCR_EL1
>  	msr_s	SYS_GCR_EL1, \tmp
>  1:
> @@ -188,10 +188,10 @@ alternative_else_nop_endif
>  	.endm
>  
>  	.macro mte_set_user_gcr, tsk, tmp, tmp2
> -#ifdef CONFIG_ARM64_MTE
> -alternative_if_not ARM64_MTE
> +#ifdef CONFIG_KASAN_HW_TAGS
> +alternative_cb	kasan_hw_tags_enable
>  	b	1f
> -alternative_else_nop_endif
> +alternative_cb_end
>  	ldr	\tmp, [\tsk, #THREAD_MTE_CTRL]
>  
>  	mte_set_gcr \tmp, \tmp2
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index 9d314a3bad3b..0e8edb5d5861 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -162,7 +162,7 @@ void mte_check_tfsr_el1(void)
>  }
>  #endif
>  
> -static void mte_update_sctlr_user(struct task_struct *task)
> +static void mte_update_sctlr_user_and_gcr_excl(struct task_struct *task)
>  {
>  	/*
>  	 * This must be called with preemption disabled and can only be called
> @@ -182,6 +182,24 @@ static void mte_update_sctlr_user(struct task_struct *task)
>  	else if (resolved_mte_tcf & MTE_CTRL_TCF_SYNC)
>  		sctlr |= SCTLR_EL1_TCF0_SYNC;
>  	task->thread.sctlr_user = sctlr;
> +
> +	/*
> +	 * SYS_GCR_EL1 will be set to current->thread.mte_ctrl value by
> +	 * mte_set_user_gcr() in kernel_exit, but only if KASAN is enabled.
> +	 */
> +	if (!kasan_hw_tags_enabled())
> +		write_sysreg_s(((mte_ctrl >> MTE_CTRL_GCR_USER_EXCL_SHIFT) &
> +				SYS_GCR_EL1_EXCL_MASK) | SYS_GCR_EL1_RRND,
> +			       SYS_GCR_EL1);
> +}
> +
> +void __init kasan_hw_tags_enable(struct alt_instr *alt, __le32 *origptr,
> +				 __le32 *updptr, int nr_inst)
> +{
> +	BUG_ON(nr_inst != 1); /* Branch -> NOP */
> +
> +	if (kasan_hw_tags_enabled())
> +		*updptr = cpu_to_le32(aarch64_insn_gen_nop());
>  }

A bit confusing: kasan_hw_tags_enabled() checks the kasan_flag_enabled
static label. This is initialised via kasan_init_hw_tags() which is
called from smp_prepare_boot_cpu() _after_ apply_boot_alternatives().
Does this work when kasan is indeed enabled? Maybe I miss something.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-09-09 17:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27  3:07 [PATCH] arm64: kasan: mte: move GCR_EL1 switch to task switch when KASAN disabled Peter Collingbourne
2021-08-29 14:10 ` Andrey Konovalov
2021-09-03 22:12   ` Peter Collingbourne
2021-09-06 17:58 ` Catalin Marinas
2021-09-07 23:20   ` Peter Collingbourne
2021-09-09 17:39 ` Catalin Marinas [this message]
2021-09-10  2:12   ` Peter Collingbourne
2021-09-14 21:54 ` Peter Collingbourne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YTpG5xT+sotOsjTD@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=andreyknvl@gmail.com \
    --cc=eugenis@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=pcc@google.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.