Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: mte: initialize RGSR_EL1.SEED in __cpu_setup

A valid implementation choice for the ChooseRandomNonExcludedTag()
pseudocode function used by IRG is to behave in the same way as with
GCR_EL1.RRND=0. This would mean that RGSR_EL1.SEED is used as an LFSR
which must have a non-zero value in order for IRG to properly produce
pseudorandom numbers. However, RGSR_EL1 is reset to an UNKNOWN value
on soft reset and thus may reset to 0. Therefore we must initialize
RGSR_EL1.SEED to a non-zero value in order to ensure that IRG behaves
as expected.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Fixes: 3b714d24ef17 ("arm64: mte: CPU feature detection and initial sysreg configuration")
Cc: <stable@vger.kernel.org> # 5.10
Link: https://linux-review.googlesource.com/id/I2b089b6c7d6f17ee37e2f0db7df5ad5bcc04526c
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20210507185905.1745402-1-pcc@google.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Peter Collingbourne and committed by
Catalin Marinas
37a8024d a1bed090

+12
+12
arch/arm64/mm/proc.S
··· 447 447 mov x10, #(SYS_GCR_EL1_RRND | SYS_GCR_EL1_EXCL_MASK) 448 448 msr_s SYS_GCR_EL1, x10 449 449 450 + /* 451 + * If GCR_EL1.RRND=1 is implemented the same way as RRND=0, then 452 + * RGSR_EL1.SEED must be non-zero for IRG to produce 453 + * pseudorandom numbers. As RGSR_EL1 is UNKNOWN out of reset, we 454 + * must initialize it. 455 + */ 456 + mrs x10, CNTVCT_EL0 457 + ands x10, x10, #SYS_RGSR_EL1_SEED_MASK 458 + csinc x10, x10, xzr, ne 459 + lsl x10, x10, #SYS_RGSR_EL1_SEED_SHIFT 460 + msr_s SYS_RGSR_EL1, x10 461 + 450 462 /* clear any pending tag check faults in TFSR*_EL1 */ 451 463 msr_s SYS_TFSR_EL1, xzr 452 464 msr_s SYS_TFSRE0_EL1, xzr