Skip to content

Comments

Collect guest/host statistics during the redirected traps#116

Merged
sterling-teng merged 4 commits intoRVCK-Project:rvck-6.6from
yechao-w:rvck-6.6-statistics
Sep 27, 2025
Merged

Collect guest/host statistics during the redirected traps#116
sterling-teng merged 4 commits intoRVCK-Project:rvck-6.6from
yechao-w:rvck-6.6-statistics

Conversation

@yechao-w
Copy link
Contributor

@yechao-w yechao-w commented Sep 2, 2025

对应的issue:#115

【验证方法】

debugfs下新增如下的exits统计

[root@localhost vms]# ll /sys/kernel/debug/kvm/*exits
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/exits
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/instr_illegal_exits   <new>
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/load_access_exits  <new>
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/load_misaligned_exits  <new>
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/signal_exits
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/store_access_exits  <new>
-rw-r--r-- 1 root root 0 Aug 22 20:24 /sys/kernel/debug/kvm/store_misaligned_exits  <new>

mainline inclusion
from Linux 6.13
commit e325618
category: feature
bugzilla: RVCK-Project#115

--------------------------------

The KVM RISC-V does not delegate AMO load/store access fault traps to
VS-mode (hedeleg) so typically M-mode takes these traps and redirects
them back to HS-mode. However, upon returning from M-mode, the KVM
RISC-V running in HS-mode terminates VS-mode software.

The KVM RISC-V should redirect AMO load/store access fault traps back
to VS-mode and let the VS-mode trap handler determine the next steps.

Signed-off-by: Yu-Wei Hsu <betterman5240@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20240429092113.70695-1-betterman5240@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: yechao-w <wang.yechao255@zte.com.cn>
mainline inclusion
from Linux 6.13
commit 51c5895
category: feature
bugzilla: RVCK-Project#115

--------------------------------

The M-mode redirects an unhandled instruction access
fault trap back to S-mode when not delegating it to
VS-mode(hedeleg). However, KVM running in HS-mode
terminates the VS-mode software when back from M-mode.

The KVM should redirect the trap back to VS-mode, and
let VS-mode trap handler decide the next step.

Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20241224-kvm_guest_stat-v2-1-08a77ac36b02@rivosinc.com
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: yechao-w <wang.yechao255@zte.com.cn>
mainline inclusion
from Linux 6.13
commit 2f15b5e
category: feature
bugzilla: RVCK-Project#115

--------------------------------

SBI PMU specification defines few firmware counters which can be
used by the guests to collect the statstics about various traps
occurred in the host.

Update these counters whenever a corresponding trap is taken

Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20241224-kvm_guest_stat-v2-2-08a77ac36b02@rivosinc.com
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: yechao-w <wang.yechao255@zte.com.cn>
mainline inclusion
from Linux 6.13
commit af79caa
category: feature
bugzilla: RVCK-Project#115

--------------------------------

Currently, kvm doesn't delegate the few traps such as misaligned
load/store, illegal instruction and load/store access faults because it
is not expected to occur in the guest very frequently. Thus, kvm gets a
chance to act upon it or collect statistics about it before redirecting
the traps to the guest.

Collect both guest and host visible statistics during the traps.
Enable them so that both guest and host can collect the stats about
them if required.

Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20241224-kvm_guest_stat-v2-3-08a77ac36b02@rivosinc.com
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: yechao-w <wang.yechao255@zte.com.cn>
@oervci
Copy link

oervci commented Sep 2, 2025

开始测试

@oervci
Copy link

oervci commented Sep 2, 2025

@oervci
Copy link

oervci commented Sep 2, 2025

Kernel build success!

@oervci
Copy link

oervci commented Sep 2, 2025

@oervci
Copy link

oervci commented Sep 3, 2025

Lava check done! result url: https://lava.oerv.ac.cn/results/623/0_rvck_common-test_qemu

@sterling-teng
Copy link
Contributor

backport自6.13,补丁格式正确,开始进行物理机测试。

note:该pr需要关联/引用对应的issue。

@yechao-w
Copy link
Contributor Author

backport自6.13,补丁格式正确,开始进行物理机测试。

note:该pr需要关联/引用对应的issue。

已在描述中引用对应的issue

@sterling-teng sterling-teng merged commit e0272cf into RVCK-Project:rvck-6.6 Sep 27, 2025
1 check failed
cp0613 pushed a commit to cp0613/rvck that referenced this pull request Feb 2, 2026
[ Upstream commit 1ca52c0 ]

Enabling runtime PM before attaching the QPHY instance as driver data
can lead to a NULL pointer dereference in runtime PM callbacks that
expect valid driver data. There is a small window where the suspend
callback may run after PM runtime enabling and before runtime forbid.
This causes a sporadic crash during boot:

```
Unable to handle kernel NULL pointer dereference at virtual address 00000000000000a1
[...]
CPU: 0 UID: 0 PID: 11 Comm: kworker/0:1 Not tainted 6.16.7+ RVCK-Project#116 PREEMPT
Workqueue: pm pm_runtime_work
pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : qusb2_phy_runtime_suspend+0x14/0x1e0 [phy_qcom_qusb2]
lr : pm_generic_runtime_suspend+0x2c/0x44
[...]
```

Attach the QPHY instance as driver data before enabling runtime PM to
prevent NULL pointer dereference in runtime PM callbacks.

Reorder pm_runtime_enable() and pm_runtime_forbid() to prevent a
short window where an unnecessary runtime suspend can occur.

Use the devres-managed version to ensure PM runtime is symmetrically
disabled during driver removal for proper cleanup.

Fixes: 891a96f ("phy: qcom-qusb2: Add support for runtime PM")
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
Link: https://patch.msgid.link/20251219085640.114473-1-loic.poulain@oss.qualcomm.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants