From b699af9b37a284630f4b936ecbef1b250474dbea Mon Sep 17 00:00:00 2001 From: yezengruan Date: Wed, 8 Feb 2023 16:03:04 +0800 Subject: [PATCH] kvm: arm64: fix some pvsched bugs virt inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I6WRGD -------------------------------------------- 1. Clear kvm_vcpu_arch::pvsched::base on vcpu reset The guest memory will otherwise be corrupted by KVM if we reboot into an old guest kernel which is **not** aware of the pvsched feature. 2. Fix boot cpu pvsched init abnormal The pv_sched_init was called too early in the boot in setup_arch, hence pvsched_vcpu_state was not initializedfo vcpu 0. Signed-off-by: Zenghui Yu Signed-off-by: yezengruan Signed-off-by: jiaofenfang --- arch/arm64/kernel/paravirt.c | 1 + arch/arm64/kernel/setup.c | 2 -- virt/kvm/arm/arm.c | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/paravirt.c b/arch/arm64/kernel/paravirt.c index c4f98834bf0d..c14cc6f63cb4 100644 --- a/arch/arm64/kernel/paravirt.c +++ b/arch/arm64/kernel/paravirt.c @@ -140,3 +140,4 @@ int __init pv_sched_init(void) return 0; } +early_initcall(pv_sched_init); diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 12424d6818cb..c2ccaf6fa9ed 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -395,8 +395,6 @@ void __init setup_arch(char **cmdline_p) smp_init_cpus(); smp_build_mpidr_hash(); - pv_sched_init(); - #ifdef CONFIG_ARM64_SW_TTBR0_PAN /* * Make sure init_thread_info.ttbr0 always generates translation diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index f12efc694f90..0ab79ed498a5 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1121,6 +1121,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, else vcpu->arch.power_off = false; + kvm_arm_pvsched_vcpu_init(&vcpu->arch); + return 0; } -- Gitee