mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
UPSTREAM: KVM: arm64: Create nVHE copy of cpu_logical_map
When KVM starts validating host's PSCI requests, it will need to map
MPIDR back to the CPU ID. To this end, copy cpu_logical_map into nVHE
hyp memory when KVM is initialized.
Only copy the information for CPUs that are online at the point of KVM
initialization so that KVM rejects CPUs whose features were not checked
against the finalized capabilities.
Signed-off-by: David Brazdil <dbrazdil@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20201202184122.26046-15-dbrazdil@google.com
(cherry picked from commit 94f5e8a464)
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: I43164f3d58d96bc996a536c106e4ff0a2c60c851
Bug: 178098380
Test: atest VirtualizationHostTestCases on an EL2-enabled device
This commit is contained in:
committed by
Will Deacon
parent
8e8ba3df6a
commit
258b9fad02
@@ -63,6 +63,8 @@ static bool vgic_present;
|
||||
static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled);
|
||||
DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use);
|
||||
|
||||
extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS];
|
||||
|
||||
int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
|
||||
@@ -1584,6 +1586,20 @@ static inline void hyp_cpu_pm_exit(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_cpu_logical_map(void)
|
||||
{
|
||||
unsigned int cpu;
|
||||
|
||||
/*
|
||||
* Copy the MPIDR <-> logical CPU ID mapping to hyp.
|
||||
* Only copy the set of online CPUs whose features have been chacked
|
||||
* against the finalized system capabilities. The hypervisor will not
|
||||
* allow any other CPUs from the `possible` set to boot.
|
||||
*/
|
||||
for_each_online_cpu(cpu)
|
||||
kvm_nvhe_sym(__cpu_logical_map)[cpu] = cpu_logical_map(cpu);
|
||||
}
|
||||
|
||||
static int init_common_resources(void)
|
||||
{
|
||||
return kvm_set_ipa_limit();
|
||||
@@ -1756,6 +1772,9 @@ static int init_hyp_mode(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (is_protected_kvm_enabled())
|
||||
init_cpu_logical_map();
|
||||
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
|
||||
@@ -8,6 +8,22 @@
|
||||
#include <asm/kvm_hyp.h>
|
||||
#include <asm/kvm_mmu.h>
|
||||
|
||||
/*
|
||||
* nVHE copy of data structures tracking available CPU cores.
|
||||
* Only entries for CPUs that were online at KVM init are populated.
|
||||
* Other CPUs should not be allowed to boot because their features were
|
||||
* not checked against the finalized system capabilities.
|
||||
*/
|
||||
u64 __ro_after_init __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
|
||||
|
||||
u64 cpu_logical_map(unsigned int cpu)
|
||||
{
|
||||
if (cpu >= ARRAY_SIZE(__cpu_logical_map))
|
||||
hyp_panic();
|
||||
|
||||
return __cpu_logical_map[cpu];
|
||||
}
|
||||
|
||||
unsigned long __hyp_per_cpu_offset(unsigned int cpu)
|
||||
{
|
||||
unsigned long *cpu_base_array;
|
||||
|
||||
Reference in New Issue
Block a user