From: Jinyang He <hejinyang@loongson.cn>
To: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Huacai Chen <chenhuacai@kernel.org>,
Xi Zhang <zhangxi@kylinos.cn>,
Xianglai Li <lixianglai@loongson.cn>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] LoongArch: Handle special PC in unwind_next_frame()
Date: Tue, 25 Nov 2025 18:52:24 +0800 [thread overview]
Message-ID: <658bb477-b3f1-97c1-ab37-5dafcb6215f5@loongson.cn> (raw)
In-Reply-To: <20251125063327.31586-1-yangtiezhu@loongson.cn>
On 2025-11-25 14:33, Tiezhu Yang wrote:
> When running virtual machine before testing the kernel live patching with
> "modprobe livepatch-sample", there is a timeout over 15 seconds, the dmesg
> command shows "unreliable stack" for user tasks in debug mode.
>
> The "unreliable stack" is because it can not unwind from kvm_handle_exit()
> to its previous frame kvm_exc_entry() due to the PC is not a valid kernel
> address, the root cause is that the code of kvm_exc_entry() was copied to
> the DMW area in kvm_loongarch_env_init(), so it should check the PC range
> and then finish unwinding for this special case.
Hi, Tiezhu,
Since kvm_loongarch_env_init copies kvm_exc_entry which similar to how
trap_init copies the exception handler. We should apply the same
offset-based adjustment to compute the shadow PC address:
shadow_pc = kvm_exc_entry + (cur_pc − copied_base_address)
This allows the ORC unwinder to correctly locate the corresponding
unwind info.
On the other hand, the address range [_end, XKVRANGE) is unreliable.
If an immediate value is in this range and pushed into the stack,
unwinder might mistakenly interpret once it get this value as pc.
Jinyang
>
> How to test:
>
> (1) Update kernel with LIVEPATCH
>
> git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> cd linux && make mrproper defconfig
> scripts/config -e FTRACE -e FUNCTION_TRACER \
> -e LIVEPATCH -e SAMPLES -m SAMPLE_LIVEPATCH
> make olddefconfig all -j"$(nproc)"
> sudo make modules_install
> sudo make install
> sudo reboot
>
> (2) Set up a VM with "-accel kvm", no need to specify kernel and initrd
>
> sudo yum -y install edk2-loongarch64 qemu
> qemu-system-loongarch64 -serial stdio \
> -machine virt -cpu la464 -smp 8 -m 4G \
> -bios /usr/share/edk2/loongarch64/QEMU_EFI.fd \
> -nodefaults -no-reboot -nographic -accel kvm
>
> (3) Test the kernel live patching
>
> cat /proc/cmdline
> sudo modprobe livepatch-sample
> cat /proc/cmdline
> sudo sh -c "echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled"
> sudo rmmod livepatch_sample
> cat /proc/cmdline
> dmesg -T
>
> Cc: stable@vger.kernel.org # v6.9+
> Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
> Reported-by: Xi Zhang <zhangxi@kylinos.cn>
> Reported-by: Xianglai Li <lixianglai@loongson.cn>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
> arch/loongarch/kernel/unwind_orc.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/loongarch/kernel/unwind_orc.c b/arch/loongarch/kernel/unwind_orc.c
> index 0d5fa64a2225..1d60a593479a 100644
> --- a/arch/loongarch/kernel/unwind_orc.c
> +++ b/arch/loongarch/kernel/unwind_orc.c
> @@ -506,6 +506,9 @@ bool unwind_next_frame(struct unwind_state *state)
> goto err;
> }
>
> + if (pc >= (unsigned long)_end && pc < (unsigned long)XKVRANGE)
> + goto end;
> +
> state->pc = bt_address(pc);
> if (!state->pc) {
> pr_err("cannot find unwind pc at %p\n", (void *)pc);
next prev parent reply other threads:[~2025-11-25 10:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-25 6:33 Tiezhu Yang
2025-11-25 8:08 ` Huacai Chen
2025-11-25 8:54 ` Tiezhu Yang
2025-11-25 9:05 ` Huacai Chen
2025-11-26 5:36 ` Tiezhu Yang
2025-11-25 10:52 ` Jinyang He [this message]
2025-11-26 6:08 ` Tiezhu Yang
2025-11-26 6:28 ` Tiezhu Yang
2025-11-26 9:09 ` Tiezhu Yang
2025-11-26 9:27 ` Huacai Chen
2025-11-27 1:32 ` Tiezhu Yang
2025-11-26 9:56 ` Bibo Mao
2025-11-27 1:39 ` Tiezhu Yang
2025-11-27 1:53 ` Bibo Mao
2025-11-27 2:53 ` Jinyang He
2025-11-27 2:58 ` Bibo Mao
2025-12-09 2:08 ` Tiezhu Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=658bb477-b3f1-97c1-ab37-5dafcb6215f5@loongson.cn \
--to=hejinyang@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixianglai@loongson.cn \
--cc=loongarch@lists.linux.dev \
--cc=yangtiezhu@loongson.cn \
--cc=zhangxi@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®