Add yangtiezhu@loongson.cn
Hi :
On 2025/12/23 上午10:46, Huacai Chen wrote:
On Tue, Dec 23, 2025 at 9:27 AM Bibo Mao maobibo@loongson.cn wrote:
On 2025/12/22 下午7:34, Xianglai Li wrote:
Insert the appropriate UNWIND macro definition into the kvm_exc_entry in the assembly function to guide the generation of correct ORC table entries, thereby solving the timeout problem of loading the livepatch-sample module on a physical machine running multiple vcpus virtual machines.
While solving the above problems, we have gained an additional benefit, that is, we can obtain more call stack information
Stack information that can be obtained before the problem is fixed: [<0>] kvm_vcpu_block+0x88/0x120 [kvm] [<0>] kvm_vcpu_halt+0x68/0x580 [kvm] [<0>] kvm_emu_idle+0xd4/0xf0 [kvm] [<0>] kvm_handle_gspr+0x7c/0x700 [kvm] [<0>] kvm_handle_exit+0x160/0x270 [kvm] [<0>] kvm_exc_entry+0x100/0x1e0
Stack information that can be obtained after the problem is fixed: [<0>] kvm_vcpu_block+0x88/0x120 [kvm] [<0>] kvm_vcpu_halt+0x68/0x580 [kvm] [<0>] kvm_emu_idle+0xd4/0xf0 [kvm] [<0>] kvm_handle_gspr+0x7c/0x700 [kvm] [<0>] kvm_handle_exit+0x160/0x270 [kvm] [<0>] kvm_exc_entry+0x100/0x1e0 [<0>] kvm_arch_vcpu_ioctl_run+0x260/0x488 [kvm] [<0>] kvm_vcpu_ioctl+0x200/0xcd8 [kvm] [<0>] sys_ioctl+0x498/0xf00 [<0>] do_syscall+0x94/0x190 [<0>] handle_syscall+0xb8/0x158
Cc: stable@vger.kernel.org Signed-off-by: Xianglai Li lixianglai@loongson.cn
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
arch/loongarch/kvm/switch.S | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/arch/loongarch/kvm/switch.S b/arch/loongarch/kvm/switch.S index 93845ce53651..e3ecb24a3bc5 100644 --- a/arch/loongarch/kvm/switch.S +++ b/arch/loongarch/kvm/switch.S @@ -170,6 +170,7 @@ SYM_CODE_START(kvm_exc_entry) /* restore per cpu register */ ld.d u0, a2, KVM_ARCH_HPERCPU addi.d sp, sp, -PT_SIZE + UNWIND_HINT_REGS
/* Prepare handle exception */ or a0, s0, zero @@ -214,6 +215,7 @@ SYM_FUNC_START(kvm_enter_guest) addi.d a2, sp, -PT_SIZE /* Save host GPRs */ kvm_save_host_gpr a2 + st.d ra, a2, PT_ERA
Had better add some comments here to show that it is special for unwind usage since there is "st.d ra, a2, PT_R1" already in macro kvm_save_host_gpr().
Then there is a new problem, why can unwinder not recognize the instruction in kvm_save_host_gpr()?
maybe it need unwinder owner to answer this question.
kvm_save_host_gpr() is an assembler macro that has already been executed and is no longer normal on the stack. Am I explaining correctly? @tiezhu
I guess you might be wondering why unwinder didn't recognize kvm_enter_guest().
There's something wrong with the logic that we're implementing here that we should put the current pc in era instead of ra. This will allow unwind to identify the symbol kvm_enter_guest.
So I will fix it in the next version like this:
@@ -214,6 +215,7 @@ SYM_FUNC_START(kvm_enter_guest) addi.d a2, sp, -PT_SIZE /* Save host GPRs */ kvm_save_host_gpr a2
+ /* + * The csr_era member variable of the pt_regs structure is required + * for unwinding orc to perform stack traceback, so we need to put + * pc into csr_era member variable here. + */ + pcaddi t0, 0 + st.d t0, a2, PT_ERA +
Thanks, Xianglai.
Huacai
Regards Bibo Mao
addi.d a2, a1, KVM_VCPU_ARCH st.d sp, a2, KVM_ARCH_HSP