-
Notifications
You must be signed in to change notification settings - Fork 105
[Deepin-Kernel-SIG] [linux 6.12-y] [Upstream] sync some patch about kvm from upstream #1432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Deepin-Kernel-SIG] [linux 6.12-y] [Upstream] sync some patch about kvm from upstream #1432
Conversation
We need to switch SFB (Store Fill Buffer) and TSO (Total Store Order) state at runtime to debug memory management and KVM virtualization, so add two debugfs entries "sfb_state" and "tso_state" under the directory /sys/kernel/debug/loongarch. Query SFB: cat /sys/kernel/debug/loongarch/sfb_state Enable SFB: echo 1 > /sys/kernel/debug/loongarch/sfb_state Disable SFB: echo 0 > /sys/kernel/debug/loongarch/sfb_state Query TSO: cat /sys/kernel/debug/loongarch/tso_state Switch TSO: echo [TSO] > /sys/kernel/debug/loongarch/tso_state Available [TSO] states: 0 (No Load No Store) 1 (All Load No Store) 3 (Same Load No Store) 4 (No Load All Store) 5 (All Load All Store) 7 (Same Load All Store) Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> (cherry picked from commit 04816c1) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Some VMMs provides special hypercall service in usermode, KVM should not handle the usermode hypercall service, thus pass it to usermode, let the usermode VMM handle it. Here a new code KVM_HCALL_CODE_USER_SERVICE is added for the user-mode hypercall service, KVM lets all six registers visible to usermode VMM. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> (cherry picked from commit 2737dee) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
LLBCTL is a separated guest CSR register from host, host exception ERET
instruction will clear the host LLBCTL CSR register, and guest exception
will clear the guest LLBCTL CSR register.
VCPU0 atomic64_fetch_add_unless VCPU1 atomic64_fetch_add_unless
ll.d %[p], %[c]
beq %[p], %[u], 1f
Here secondary mmu mapping is changed, host hpa page is replaced with a
new page. And VCPU1 will execute atomic instruction on the new page.
ll.d %[p], %[c]
beq %[p], %[u], 1f
add.d %[rc], %[p], %[a]
sc.d %[rc], %[c]
add.d %[rc], %[p], %[a]
sc.d %[rc], %[c]
LLBCTL is set on VCPU0 and it represents the memory is not modified by
other VCPUs, sc.d will modify the memory directly.
So clear WCLLB of the guest LLBCTL register when mapping is the changed.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
(cherry picked from commit 4d38d04)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review这段代码主要是为 LoongArch 架构的 KVM 添加了用户态超调用(user hypercall)支持、内存排序(memory ordering)相关的 debugfs 接口,以及修复了 LL/SC 指令在 vCPU 迁移时的潜在问题。以下是对代码的详细审查和改进建议: 1. 代码逻辑与功能审查1.1 用户态超调用支持 (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request synchronizes upstream KVM patches for the LoongArch architecture in Linux 6.12. The changes add support for user-space hypercall handling, fix LLBCTL register handling for atomic operations across VCPU migrations, and consolidate debugfs infrastructure.
Changes:
- Add support for user-space hypercall handling (KVM_HCALL_USER_SERVICE) allowing VMMs to handle custom hypercalls
- Fix LLBCTL register clearing on VCPU migration to prevent LL/SC pair issues with changed MMU mappings
- Consolidate debugfs directory creation into a centralized kdebugfs.c module
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| arch/loongarch/kvm/vcpu.c | Convert if statement to switch for handling multiple exit reasons including new KVM_EXIT_HYPERCALL |
| arch/loongarch/kvm/main.c | Add LLBCTL register clearing on VCPU migration to fix atomic operation issues |
| arch/loongarch/kvm/exit.c | Implement user-space hypercall handler and completion function |
| arch/loongarch/kernel/unaligned.c | Update to use centralized arch_debugfs_dir instead of local directory |
| arch/loongarch/kernel/kdebugfs.c | New centralized debugfs infrastructure with SFB and TSO state controls |
| arch/loongarch/kernel/Makefile | Add kdebugfs.o to build system |
| arch/loongarch/include/uapi/asm/kvm_para.h | Define KVM_FEATURE_USER_HCALL feature flag |
| arch/loongarch/include/asm/loongarch.h | Add CPU config bits and CSR definitions for TSO ordering |
| arch/loongarch/include/asm/kvm_vcpu.h | Declare kvm_complete_user_service function |
| arch/loongarch/include/asm/kvm_para.h | Define KVM_HCALL_USER_SERVICE hypercall code |
| arch/loongarch/include/asm/kvm_host.h | Add KVM_FEATURE_USER_HCALL to feature mask |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| debugfs_create_u32("unaligned_instructions_user", | ||
| S_IRUGO, d, &unaligned_instructions_user); | ||
| S_IRUGO, arch_debugfs_dir, &unaligned_instructions_user); | ||
| debugfs_create_u32("unaligned_instructions_kernel", | ||
| S_IRUGO, d, &unaligned_instructions_kernel); | ||
| S_IRUGO, arch_debugfs_dir, &unaligned_instructions_kernel); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable arch_debugfs_dir is used here but is not declared in the current file or included headers. Since this variable is defined and exported in kdebugfs.c (added in this PR), it needs an extern declaration, likely in an appropriate header file (such as asm/loongarch.h or a new debugfs-related header) so that this file can use it. Without the declaration, this will cause a compilation error.
| ret = RESUME_HOST; | ||
| break; | ||
| case KVM_HCALL_SWDBG: | ||
| /* KVM_HCALL_SWDBG only in effective when SW_BP is enabled */ |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment contains a grammatical error. "in effective" should be "effective" or "in effect".
| /* KVM_HCALL_SWDBG only in effective when SW_BP is enabled */ | |
| /* KVM_HCALL_SWDBG only effective when SW_BP is enabled */ |
#1412