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

Xianglai Li posted 2 patches 1 day, 10 hours ago
arch/loongarch/Kbuild                       |  2 +-
arch/loongarch/include/asm/asm-prototypes.h | 16 ++++++++++
arch/loongarch/include/asm/kvm_host.h       |  5 +--
arch/loongarch/include/asm/kvm_vcpu.h       | 20 ++++++------
arch/loongarch/kvm/Makefile                 |  2 +-
arch/loongarch/kvm/main.c                   | 35 ++-------------------
arch/loongarch/kvm/switch.S                 | 24 +++++++++++---
7 files changed, 51 insertions(+), 53 deletions(-)
[PATCH 0/2] LoongArch: KVM: fix "unreliable stack" issue
Posted by Xianglai Li 1 day, 10 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.

Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Tianrui Zhao <zhaotianrui@loongson.cn>
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: Charlie Jenkins <charlie@rivosinc.com>
Cc: Xianglai Li <lixianglai@loongson.cn>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org

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 | 16 ++++++++++
 arch/loongarch/include/asm/kvm_host.h       |  5 +--
 arch/loongarch/include/asm/kvm_vcpu.h       | 20 ++++++------
 arch/loongarch/kvm/Makefile                 |  2 +-
 arch/loongarch/kvm/main.c                   | 35 ++-------------------
 arch/loongarch/kvm/switch.S                 | 24 +++++++++++---
 7 files changed, 51 insertions(+), 53 deletions(-)


base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
-- 
2.39.1