Nested uses of kpkeys guards are about to be introduced, which means that kpkeys_set_level() may not actually need to change the value of POR_EL1. Since updating POR_EL1 requires an expensive ISB, let's skip the write if the value is unchanged, by returning KPKEYS_PKEY_REG_INVAL. This will cause the matching kpkeys_restore_pkey_reg() call to bail out without calling arch_kpkeys_restore_pkey_reg(). Signed-off-by: Kevin Brodsky --- arch/arm64/include/asm/kpkeys.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/include/asm/kpkeys.h b/arch/arm64/include/asm/kpkeys.h index 64d6e22740ec..70e21df84252 100644 --- a/arch/arm64/include/asm/kpkeys.h +++ b/arch/arm64/include/asm/kpkeys.h @@ -43,6 +43,9 @@ static __always_inline int arch_kpkeys_set_level(int level) u64 prev_por = read_sysreg_s(SYS_POR_EL1); u64 new_por = por_set_kpkeys_level(prev_por, level); + if (new_por == prev_por) + return KPKEYS_PKEY_REG_INVAL; + __kpkeys_set_pkey_reg_nosync(new_por); isb(); -- 2.47.0