[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] Sync LoongArch KVM bugfixes from upstream - #2112
Conversation
Function kvm_vcpu_ioctl_interrupt() can be called from userspace, here add irq validility cheking in kvm_vcpu_ioctl_interrupt(). Cc: [email protected] Fixes: f45ad5b ("LoongArch: KVM: Implement vcpu interrupt operations") Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]> (cherry picked from commit 09b318a) Signed-off-by: Wentao Guan <[email protected]>
At the beginning, only 64 bit FPU is supported. With FPU register get interface, 64 bit FPU data is copied to user space, the same with FPU register set API. However with LSX and LASX supported in later, there should be FPU data copied with bigger width. So here fixes this issue, copy the whole 256 bit FPU data from/to user space. Cc: [email protected] Fixes: db1ecca ("LoongArch: KVM: Add LSX (128bit SIMD) support") Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]> (cherry picked from commit f4caaac) Signed-off-by: Wentao Guan <[email protected]>
The LoongArch CSRXCHG instruction returns the full old CSR value in rd after applying the masked update. kvm_emu_xchg_csr() currently masks the saved value before returning it to the guest, so rd receives only the bits selected by the write mask. That breaks the architectural behavior and makes a zero mask return 0 instead of the previous CSR value. So, keep the masked CSR update, but return the unmodified old CSR value. Cc: [email protected] Fixes: da50f5a ("LoongArch: KVM: Implement handle csr exception") Reviewed-by: Bibo Mao <[email protected]> Signed-off-by: Qiang Ma <[email protected]> Signed-off-by: Huacai Chen <[email protected]> (cherry picked from commit ebd50de) Signed-off-by: Wentao Guan <[email protected]>
put_user() may return -EFAULT, so, when the user space address is invalid, the caller should return -EFAULT. Cc: [email protected] Reviewed-by: Bibo Mao <[email protected]> Signed-off-by: Qiang Ma <[email protected]> Signed-off-by: Huacai Chen <[email protected]> (cherry picked from commit fb89e0f) Signed-off-by: Wentao Guan <[email protected]>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideSyncs LoongArch KVM upstream fixes by correcting software CSR exchange results, handling userspace and FPU data transfers safely, and validating interrupt vectors before injection. Sequence diagram for validated LoongArch KVM interrupt injectionsequenceDiagram
participant Userspace
participant KVM
participant VCPU
Userspace->>KVM: kvm_vcpu_ioctl_interrupt
KVM->>KVM: abs
alt vector >= EXCCODE_INT_NUM
KVM-->>Userspace: -EINVAL
else valid vector
KVM->>VCPU: kvm_queue_irq
KVM-->>Userspace: success
end
Sequence diagram for safe LoongArch KVM userspace data transfersequenceDiagram
participant Userspace
participant KVM
Userspace->>KVM: kvm_loongarch_cpucfg_get_attr
KVM->>Userspace: put_user
alt put_user fails
KVM-->>Userspace: -EFAULT
else put_user succeeds
KVM-->>Userspace: result
end
Userspace->>KVM: kvm_arch_vcpu_ioctl_get_fpu
KVM->>KVM: memcpy sizeof(union fpureg)
KVM-->>Userspace: FPU state
Userspace->>KVM: kvm_arch_vcpu_ioctl_set_fpu
KVM->>KVM: memcpy sizeof(union fpureg)
KVM-->>Userspace: success
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[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 |
There was a problem hiding this comment.
Pull request overview
Backports four upstream LoongArch KVM correctness fixes.
Changes:
- Correct CSR exchange return values.
- Propagate userspace write failures and copy full 256-bit FPU registers.
- Reject invalid interrupt vectors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
arch/loongarch/kvm/exit.c |
Returns the complete previous CSR value. |
arch/loongarch/kvm/vcpu.c |
Fixes CPUCFG, FPU, and interrupt handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary by Sourcery
Bug Fixes: