From: Jan Kiszka <[email protected]> This adds full support for SMCCC_ARCH_WORKAROUND_2 and ensures that there is no deviation between features reported before and after enabling Jailhouse.
Signed-off-by: Jan Kiszka <[email protected]> --- .../arch/arm-common/include/asm/percpu.h | 4 ++-- hypervisor/arch/arm-common/smccc.c | 19 ++++++++++++------- hypervisor/arch/arm64/setup.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/hypervisor/arch/arm-common/include/asm/percpu.h b/hypervisor/arch/arm-common/include/asm/percpu.h index a3e38fa0..a3697641 100644 --- a/hypervisor/arch/arm-common/include/asm/percpu.h +++ b/hypervisor/arch/arm-common/include/asm/percpu.h @@ -16,8 +16,8 @@ #define STACK_SIZE PAGE_SIZE #define ARM_PERCPU_FIELDS \ - bool smccc_has_workaround_1; \ - bool smccc_has_workaround_2; + int smccc_feat_workaround_1; \ + int smccc_feat_workaround_2; #define ARCH_PUBLIC_PERCPU_FIELDS \ unsigned long mpidr; \ diff --git a/hypervisor/arch/arm-common/smccc.c b/hypervisor/arch/arm-common/smccc.c index 363cda1a..0f80ac9e 100644 --- a/hypervisor/arch/arm-common/smccc.c +++ b/hypervisor/arch/arm-common/smccc.c @@ -19,8 +19,12 @@ void smccc_discover(void) { + struct per_cpu *cpu_data = this_cpu_data(); int ret; + cpu_data->smccc_feat_workaround_1 = ARM_SMCCC_NOT_SUPPORTED; + cpu_data->smccc_feat_workaround_2 = ARM_SMCCC_NOT_SUPPORTED; + ret = smc(PSCI_0_2_FN_VERSION); /* We need >=PSCIv1.0 for SMCCC. Against the spec, U-Boot may also @@ -43,11 +47,11 @@ void smccc_discover(void) if (ret != ARM_SMCCC_SUCCESS) return; - ret = smc_arg1(SMCCC_ARCH_FEATURES, SMCCC_ARCH_WORKAROUND_1); - this_cpu_data()->smccc_has_workaround_1 = ret >= ARM_SMCCC_SUCCESS; + cpu_data->smccc_feat_workaround_1 = + smc_arg1(SMCCC_ARCH_FEATURES, SMCCC_ARCH_WORKAROUND_1); - ret = smc_arg1(SMCCC_ARCH_FEATURES, SMCCC_ARCH_WORKAROUND_2); - this_cpu_data()->smccc_has_workaround_2 = ret >= ARM_SMCCC_SUCCESS; + cpu_data->smccc_feat_workaround_2 = + smc_arg1(SMCCC_ARCH_FEATURES, SMCCC_ARCH_WORKAROUND_2); } static inline long handle_arch_features(u32 id) @@ -57,8 +61,9 @@ static inline long handle_arch_features(u32 id) return ARM_SMCCC_SUCCESS; case SMCCC_ARCH_WORKAROUND_1: - return this_cpu_data()->smccc_has_workaround_1 ? - ARM_SMCCC_SUCCESS : ARM_SMCCC_NOT_SUPPORTED; + return this_cpu_data()->smccc_feat_workaround_1; + case SMCCC_ARCH_WORKAROUND_2: + return this_cpu_data()->smccc_feat_workaround_2; default: return ARM_SMCCC_NOT_SUPPORTED; @@ -80,7 +85,7 @@ static enum trap_return handle_arch(struct trap_context *ctx) break; case SMCCC_ARCH_WORKAROUND_2: - if (!this_cpu_data()->smccc_has_workaround_2) + if (this_cpu_data()->smccc_feat_workaround_2 < 0) return ARM_SMCCC_NOT_SUPPORTED; return smc_arg1(SMCCC_ARCH_WORKAROUND_2, ctx->regs[1]); diff --git a/hypervisor/arch/arm64/setup.c b/hypervisor/arch/arm64/setup.c index 57b25dbc..a24bf1d7 100644 --- a/hypervisor/arch/arm64/setup.c +++ b/hypervisor/arch/arm64/setup.c @@ -66,7 +66,7 @@ int arch_cpu_init(struct per_cpu *cpu_data) return err; /* Conditionally switch to hardened vectors */ - if (this_cpu_data()->smccc_has_workaround_1) + if (this_cpu_data()->smccc_feat_workaround_1 >= ARM_SMCCC_SUCCESS) arm_write_sysreg(vbar_el2, &hyp_vectors_hardened); return 0; -- 2.26.2 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/66bd3948cc4efe112778c32d70b81fd131f6bbf8.1609774199.git.jan.kiszka%40web.de.
