Skip to content

Commit

Permalink
arm-common: Return original SMCCC_ARCH_WORKAROUND_* feature queries c…
Browse files Browse the repository at this point in the history
…odes

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 <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Jan 4, 2021
1 parent 4d759c5 commit 66bd394
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions hypervisor/arch/arm-common/include/asm/percpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
19 changes: 12 additions & 7 deletions hypervisor/arch/arm-common/smccc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion hypervisor/arch/arm64/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 66bd394

Please sign in to comment.