Skip to content

Commit 71b3ec5

Browse files
David BrazdilMarc Zyngier
authored andcommitted
KVM: arm64: Clean up cpu_init_hyp_mode()
Pull bits of code to the only place where it is used. Remove empty function __cpu_init_stage2(). Remove redundant has_vhe() check since this function is nVHE-only. No functional changes intended. Signed-off-by: David Brazdil <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5107000 commit 71b3ec5

File tree

3 files changed

+29
-40
lines changed

3 files changed

+29
-40
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ extern int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu);
7070

7171
extern int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu);
7272

73+
extern void __kvm_enable_ssbs(void);
74+
7375
extern u64 __vgic_v3_get_ich_vtr_el2(void);
7476
extern u64 __vgic_v3_read_vmcr(void);
7577
extern void __vgic_v3_write_vmcr(u32 vmcr);

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -533,39 +533,6 @@ static inline void kvm_init_host_cpu_context(struct kvm_cpu_context *cpu_ctxt)
533533
cpu_ctxt->sys_regs[MPIDR_EL1] = read_cpuid_mpidr();
534534
}
535535

536-
void __kvm_enable_ssbs(void);
537-
538-
static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
539-
unsigned long hyp_stack_ptr,
540-
unsigned long vector_ptr)
541-
{
542-
/*
543-
* Calculate the raw per-cpu offset without a translation from the
544-
* kernel's mapping to the linear mapping, and store it in tpidr_el2
545-
* so that we can use adr_l to access per-cpu variables in EL2.
546-
*/
547-
u64 tpidr_el2 = ((u64)this_cpu_ptr(&kvm_host_data) -
548-
(u64)kvm_ksym_ref(kvm_host_data));
549-
550-
/*
551-
* Call initialization code, and switch to the full blown HYP code.
552-
* If the cpucaps haven't been finalized yet, something has gone very
553-
* wrong, and hyp will crash and burn when it uses any
554-
* cpus_have_const_cap() wrapper.
555-
*/
556-
BUG_ON(!system_capabilities_finalized());
557-
__kvm_call_hyp((void *)pgd_ptr, hyp_stack_ptr, vector_ptr, tpidr_el2);
558-
559-
/*
560-
* Disabling SSBD on a non-VHE system requires us to enable SSBS
561-
* at EL2.
562-
*/
563-
if (!has_vhe() && this_cpu_has_cap(ARM64_SSBS) &&
564-
arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) {
565-
kvm_call_hyp(__kvm_enable_ssbs);
566-
}
567-
}
568-
569536
static inline bool kvm_arch_requires_vhe(void)
570537
{
571538
/*
@@ -601,8 +568,6 @@ int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu,
601568
int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu,
602569
struct kvm_device_attr *attr);
603570

604-
static inline void __cpu_init_stage2(void) {}
605-
606571
/* Guest/host FPSIMD coordination helpers */
607572
int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu);
608573
void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu);

arch/arm64/kvm/arm.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,19 +1273,41 @@ static void cpu_init_hyp_mode(void)
12731273
{
12741274
phys_addr_t pgd_ptr;
12751275
unsigned long hyp_stack_ptr;
1276-
unsigned long stack_page;
12771276
unsigned long vector_ptr;
1277+
unsigned long tpidr_el2;
12781278

12791279
/* Switch from the HYP stub to our own HYP init vector */
12801280
__hyp_set_vectors(kvm_get_idmap_vector());
12811281

1282+
/*
1283+
* Calculate the raw per-cpu offset without a translation from the
1284+
* kernel's mapping to the linear mapping, and store it in tpidr_el2
1285+
* so that we can use adr_l to access per-cpu variables in EL2.
1286+
*/
1287+
tpidr_el2 = ((unsigned long)this_cpu_ptr(&kvm_host_data) -
1288+
(unsigned long)kvm_ksym_ref(kvm_host_data));
1289+
12821290
pgd_ptr = kvm_mmu_get_httbr();
1283-
stack_page = __this_cpu_read(kvm_arm_hyp_stack_page);
1284-
hyp_stack_ptr = stack_page + PAGE_SIZE;
1291+
hyp_stack_ptr = __this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE;
12851292
vector_ptr = (unsigned long)kvm_get_hyp_vector();
12861293

1287-
__cpu_init_hyp_mode(pgd_ptr, hyp_stack_ptr, vector_ptr);
1288-
__cpu_init_stage2();
1294+
/*
1295+
* Call initialization code, and switch to the full blown HYP code.
1296+
* If the cpucaps haven't been finalized yet, something has gone very
1297+
* wrong, and hyp will crash and burn when it uses any
1298+
* cpus_have_const_cap() wrapper.
1299+
*/
1300+
BUG_ON(!system_capabilities_finalized());
1301+
__kvm_call_hyp((void *)pgd_ptr, hyp_stack_ptr, vector_ptr, tpidr_el2);
1302+
1303+
/*
1304+
* Disabling SSBD on a non-VHE system requires us to enable SSBS
1305+
* at EL2.
1306+
*/
1307+
if (this_cpu_has_cap(ARM64_SSBS) &&
1308+
arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) {
1309+
kvm_call_hyp(__kvm_enable_ssbs);
1310+
}
12891311
}
12901312

12911313
static void cpu_hyp_reset(void)

0 commit comments

Comments
 (0)