On 6/9/19 3:37 PM, Jan Kiszka wrote:
> On 03.01.19 19:06, Ralf Ramsauer wrote:
>> by discovering its features.
>>
>> The first step is to check the PSCI version. Don't even try to do any
>> SMCCC calls without having checked the proper PSCI version (current QEMU
>> horribly crashes).
>>
>> Probe if SMCCC_ARCH_FEATURES is available. If so, probe for
>> SMCCC_ARCH_WORKAROUND_1 and expose its availability by setting a flag
>> inside the percpu structure.
>>
>> The availability is stored per-cpu, as we might have big.LITTLE systems,
>> where only a subset of cores need mitigations.
>>
>> Signed-off-by: Ralf Ramsauer <[email protected]>
>> ---
>> .../arch/arm-common/include/asm/percpu.h | 3 ++
>> .../arch/arm-common/include/asm/smccc.h | 5 +++
>> hypervisor/arch/arm-common/setup.c | 3 ++
>> hypervisor/arch/arm-common/smccc.c | 32 +++++++++++++++++++
>> .../arch/arm/include/asm/percpu_fields.h | 1 +
>> .../arch/arm64/include/asm/percpu_fields.h | 1 +
>> 6 files changed, 45 insertions(+)
>>
>> diff --git a/hypervisor/arch/arm-common/include/asm/percpu.h
>> b/hypervisor/arch/arm-common/include/asm/percpu.h
>> index b9278117..4b37e1be 100644
>> --- a/hypervisor/arch/arm-common/include/asm/percpu.h
>> +++ b/hypervisor/arch/arm-common/include/asm/percpu.h
>> @@ -15,6 +15,9 @@
>>
>> #define STACK_SIZE PAGE_SIZE
>>
>> +#define ARM_PERCPU_FIELDS \
>> + bool smccc_has_workaround_1;
>> +
>> #define ARCH_PUBLIC_PERCPU_FIELDS \
>> unsigned long mpidr; \
>> \
>> diff --git a/hypervisor/arch/arm-common/include/asm/smccc.h
>> b/hypervisor/arch/arm-common/include/asm/smccc.h
>> index 563ab9ef..6c490fad 100644
>> --- a/hypervisor/arch/arm-common/include/asm/smccc.h
>> +++ b/hypervisor/arch/arm-common/include/asm/smccc.h
>> @@ -12,6 +12,8 @@
>>
>> #define SMCCC_VERSION 0x80000000
>> #define SMCCC_ARCH_FEATURES 0x80000001
>> +#define SMCCC_ARCH_WORKAROUND_1 0x80008000
>> +#define SMCCC_ARCH_WORKAROUND_2 0x80007fff
>>
>> #define ARM_SMCCC_OWNER_MASK BIT_MASK(29, 24)
>> #define ARM_SMCCC_OWNER_SHIFT 24
>> @@ -33,4 +35,7 @@
>>
>> #define SMCCC_IS_CONV_64(function_id) !!(function_id & (1 << 30))
>>
>> +struct trap_context;
>> +
>> +void smccc_discover(void);
>> enum trap_return handle_smc(struct trap_context *ctx);
>> diff --git a/hypervisor/arch/arm-common/setup.c
>> b/hypervisor/arch/arm-common/setup.c
>> index 4cc045ec..2a04cdb7 100644
>> --- a/hypervisor/arch/arm-common/setup.c
>> +++ b/hypervisor/arch/arm-common/setup.c
>> @@ -14,6 +14,7 @@
>> #include <jailhouse/paging.h>
>> #include <jailhouse/processor.h>
>> #include <asm/setup.h>
>> +#include <asm/smccc.h>
>>
>> static u32 __attribute__((aligned(PAGE_SIZE)))
>> parking_code[PAGE_SIZE / 4] = {
>> ARM_PARKING_CODE
>> @@ -42,5 +43,7 @@ int arm_cpu_init(struct per_cpu *cpu_data)
>>
>> arm_paging_vcpu_init(&root_cell.arch.mm);
>>
>> + smccc_discover();
>> +
>> return irqchip_cpu_init(cpu_data);
>> }
>> diff --git a/hypervisor/arch/arm-common/smccc.c
>> b/hypervisor/arch/arm-common/smccc.c
>> index 211d6cd7..37c05b42 100644
>> --- a/hypervisor/arch/arm-common/smccc.c
>> +++ b/hypervisor/arch/arm-common/smccc.c
>> @@ -11,10 +11,42 @@
>> */
>>
>> #include <jailhouse/control.h>
>> +#include <jailhouse/printk.h>
>> #include <asm/psci.h>
>> #include <asm/traps.h>
>> +#include <asm/smc.h>
>> #include <asm/smccc.h>
>>
>> +void smccc_discover(void)
>> +{
>> + int ret;
>> +
>> + ret = smc(PSCI_0_2_FN_VERSION);
>> + > + /* We need >=PSCIv1.0 for SMCCC */
>> + if (PSCI_VERSION_MAJOR(ret) < 1)
>> + return;
>> +
>
> This breaks on ARMv7, at least on sunxi (Orange Pi Zero). I first
> thought it was
> because U-Boot returning -1, instead "0.2". But then it turns out that
> the smc
> itself does not return. I'm starting to believe we do not get the call
> through
> the hyp stub of the kernel, which is still active during smccc_discover
> on ARMv7
> (in contrast to ARMv8, where we take over first).
>
> Do we support fixing on ARMv7 at all? Otherwise, the invocation of this
> should
> be moved to ARMv8 only.
Not yet. I have to check if mitigations are already supported/available
on ARMv7. I'll try to find some time to implement mitigations if available.
>
> Jan
>
> PS: This change was untested on the Orange Pi until today and my attempt to
> demonstrate jailhouse next during a live demo at MiniDebConf...
Too bad, I'm sorry. I hope you were able to jump over to a working
checkout. But you took the risk of an untested next. Which reminds us of
the lack of continuous testing...
Ralf
--
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/d48f69f1-77d0-a76c-6883-52de524a178d%40oth-regensburg.de.
For more options, visit https://groups.google.com/d/optout.