[PATCH V4 0/2] LoongArch: KVM: fix "unreliable stack" issue

Xianglai Li posted 2 patches 1 day, 6 hours ago
arch/loongarch/Kbuild                       |  2 +-
arch/loongarch/include/asm/asm-prototypes.h | 21 +++++++++++++
arch/loongarch/include/asm/kvm_host.h       |  3 --
arch/loongarch/kvm/Makefile                 |  2 +-
arch/loongarch/kvm/main.c                   | 35 ++-------------------
arch/loongarch/kvm/switch.S                 | 29 ++++++++++++-----
6 files changed, 47 insertions(+), 45 deletions(-)
[PATCH V4 0/2] LoongArch: KVM: fix "unreliable stack" issue
Posted by Xianglai Li 1 day, 6 hours ago
When starting multi-core loongarch virtualization on loongarch physical
machine, loading livepatch on the physical machine will cause an error
similar to the following:
[  411.686289] livepatch: klp_try_switch_task: CPU 31/KVM:3116 has an
unreliable stack

The specific test steps are as follows:
1.Start a multi-core virtual machine on a physical machine

2.Enter the following command on the physical machine to turn on the debug
switch:
  echo "file kernel/livepatch/transition.c +p"  > /sys/kernel/debug/\
dynamic_debug/control 


3.Load livepatch:
 modprobe  livepatch-sample 

Through the above steps, similar prints can be viewed in dmesg.

The reason for this issue is that the code of the kvm_exc_entry function
was copied in the function kvm_loongarch_env_init. When the cpu needs to
execute kvm_exc_entry, it will switch to the copied address for execution.
The new address of the kvm_exc_entry function cannot be recognized in ORC,
which eventually leads to the arch_stack_walk_reliable function returning
an error and printing an exception message.

To solve the above problems, we directly compile the switch.S file into
the kernel instead of the module. In this way, the function kvm_exc_entry
will no longer need to be copied.

changlog:
V4<-V3:
1.Use SYM_CODE_START to modify the kvm_enter_guest function

2.Replace the EXPORT_SYMBOL macro with EXPORT_SYMBOL_FOR_KVM

3.Simplify the modification of the "unreliable stack" issue,At the entry
point of the function kvm_exc_entry, by using the UNWIND_HINT_END_OF_STACK
macro, the subsequent translation of the orc call stack can be terminated.

V3<-V2:
1.Replace the EXPORT_SYMBOL macro declaration symbol with the
EXPORT_SYMBOL_FOR_KVM macro

2.Add some comments in kvm_enter_guest

3.Place the correct pc address in era

4.Move .p2align after .text

V2<-V1:
1.Rollback the modification of function parameter types such as
kvm_save_fpu. In the asm-prototypes.h header file, only the parameter types
it depends on are included

Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Tianrui Zhao <zhaotianrui@loongson.cn>
Cc: Bibo Mao <maobibo@loongson.cn>

Xianglai Li (2):
  LoongArch: KVM: Compile the switch.S file directly into the kernel
  LoongArch: KVM: fix "unreliable stack" issue

 arch/loongarch/Kbuild                       |  2 +-
 arch/loongarch/include/asm/asm-prototypes.h | 21 +++++++++++++
 arch/loongarch/include/asm/kvm_host.h       |  3 --
 arch/loongarch/kvm/Makefile                 |  2 +-
 arch/loongarch/kvm/main.c                   | 35 ++-------------------
 arch/loongarch/kvm/switch.S                 | 29 ++++++++++++-----
 6 files changed, 47 insertions(+), 45 deletions(-)


base-commit: d60bc140158342716e13ff0f8aa65642f43ba053
-- 
2.39.1