| 92963759 | 04-Sep-2026 |
Tao Cui <cuitao@kylinos.cn> |
LoongArch: KVM: Fix TOCTOU race on pv_features
In kvm_loongarch_cpucfg_set_attr() the check-then-set on kvm->arch.pv_features is lockless, so two vCPUs can race past the validation and set different
LoongArch: KVM: Fix TOCTOU race on pv_features
In kvm_loongarch_cpucfg_set_attr() the check-then-set on kvm->arch.pv_features is lockless, so two vCPUs can race past the validation and set different values. Add a spinlock to protect it.
Cc: stable@vger.kernel.org Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Tao Cui <cuitao@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 501514d6 | 04-Sep-2026 |
Zeng Chi <zengchi@kylinos.cn> |
LoongArch: KVM: Validate MSI data before routing it to EIOINTC
pch_msi_set_irq() passes e->msi.data straight into eiointc_set_irq() as the irq number. The MSI data comes from userspace, that either
LoongArch: KVM: Validate MSI data before routing it to EIOINTC
pch_msi_set_irq() passes e->msi.data straight into eiointc_set_irq() as the irq number. The MSI data comes from userspace, that either via a KVM_IRQ_ROUTING_MSI entry set with KVM_SET_GSI_ROUTING (used by irqfd and KVM_IRQ_LINE) or directly via KVM_SIGNAL_MSI, and is never checked against EIOINTC_IRQS.
eiointc_set_irq() uses the value with __set_bit()/__clear_bit() on the 256-bit isr bitmap, eiointc_update_irq() then indexes sw_coremap[] and the per-cpu coreisr/sw_coreisr bitmaps with it. Therefore a data value >= 256 reads and writes memory past the end of those arrays, i.e. any process holding a VM fd can corrupt kernel memory beyond the allocation of loongarch_eiointc.
Reject MSI data that doesn't fit in the EIOINTC irq space. The DMSINTC path is unaffected as it decodes the vector from the address and masks it.
Cc: stable@vger.kernel.org Fixes: 1928254c5ccb ("LoongArch: KVM: Add irqfd support") Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://lore.kernel.org/all/20260531140921.1B1181F00893@smtp.kernel.org/ Reviewed-by: Tao Cui <cuitao@kylinos.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Zeng Chi <zengchi@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 27a9bfee | 04-Sep-2026 |
Zeng Chi <zengchi@kylinos.cn> |
LoongArch: KVM: Preserve memslot arch flags on KVM_MR_FLAGS_ONLY
kvm_arch_prepare_memory_region() computes new->arch.flags, i.e. whether a memslot is KVM_MEM_HUGEPAGE_CAPABLE or KVM_MEM_HUGEPAGE_INC
LoongArch: KVM: Preserve memslot arch flags on KVM_MR_FLAGS_ONLY
kvm_arch_prepare_memory_region() computes new->arch.flags, i.e. whether a memslot is KVM_MEM_HUGEPAGE_CAPABLE or KVM_MEM_HUGEPAGE_INCAPABLE, only for KVM_MR_CREATE and KVM_MR_MOVE, and returns early for every other change. But the generic code allocates a zeroed memslot for every change and never copies old->arch, so after a KVM_MR_FLAGS_ONLY update, e.g. toggling KVM_MEM_LOG_DIRTY_PAGES for live migration, the active memslot has arch.flags == 0.
With both flags clear, fault_supports_huge_mapping() falls through to the alignment check on the HVA range alone, which no longer verifies that the GPA and HVA have the same offset within a PMD. A memslot that was marked KVM_MEM_HUGEPAGE_INCAPABLE because of a GPA/HVA offset mismatch can then be mapped with PMD entries on read faults, and since kvm_map_page() aligns the gfn and the pfn independently, the guest ends up accessing the wrong host pages, exactly the "d -> f, e -> g" case described in the comment above the check.
Carry the arch flags over from the old memslot for KVM_MR_FLAGS_ONLY, as the GPA, HVA and size are guaranteed to be unchanged for that case.
Cc: stable@vger.kernel.org Fixes: 7ab6fb505b2a ("LoongArch: KVM: Optimization for memslot hugepage checking") Tested-by: Tao Cui <cuitao@kylinos.cn> Reviewed-by: Tao Cui <cuitao@kylinos.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Zeng Chi <zengchi@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 40bdbb4b | 04-Sep-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Remove unused function kvm_arch_flush_remote_tlbs_memslot()
Function kvm_arch_flush_remote_tlbs_memslot() is not called any more, so remove this API.
Reviewed-by: Tao Cui <cuitao@ky
LoongArch: KVM: Remove unused function kvm_arch_flush_remote_tlbs_memslot()
Function kvm_arch_flush_remote_tlbs_memslot() is not called any more, so remove this API.
Reviewed-by: Tao Cui <cuitao@kylinos.cn> Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 910132bc | 04-Sep-2026 |
Chaithanya Lagisetty <nagachaithanya9911@gmail.com> |
LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error path
kvm_loongarch_env_init() allocates the per-CPU kvm_context (vmcs) and kvm_loongarch_ops, registers the perf callbacks, and th
LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error path
kvm_loongarch_env_init() allocates the per-CPU kvm_context (vmcs) and kvm_loongarch_ops, registers the perf callbacks, and then registers the IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices. If any of those device registrations fails, the function returned the error directly, leaving everything acquired so far in place: vmcs and kvm_loongarch_ops are never freed, the perf callbacks stay registered, and all previously registered KVM device operations remain registered. kvm_loongarch_init() propagates the errors without calling kvm_loongarch_env_exit(), so nothing else cleans up either.
Unwind the error path in reverse order of registration, so that each failure only undoes what had actually been set up. Use the same helpers in kvm_loongarch_env_exit() to remove the device registrations during normal teardown as well.
Cc: stable@vger.kernel.org Fixes: c532de5a67a7 ("LoongArch: KVM: Add IPI device support") Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Chaithanya Lagisetty <nagachaithanya9911@gmail.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 4af22177 | 04-Sep-2026 |
Chaithanya Lagisetty <nagachaithanya9911@gmail.com> |
LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
The IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices each have a helper that registers their kvm_device_ops, but there is no counterpart t
LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
The IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices each have a helper that registers their kvm_device_ops, but there is no counterpart to remove them, so a caller that needs to undo a registration has to open-code kvm_unregister_device_ops() with the matching device type.
Add kvm_loongarch_unregister_{ipi,eiointc,pch_pic,dmsintc}_device() next to the existing register helpers. kvm_unregister_device_ops() is a no-op when the corresponding device type is not currently registered.
No functional change, as there are no callers yet.
Cc: stable@vger.kernel.org Suggested-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Chaithanya Lagisetty <nagachaithanya9911@gmail.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 9b61ad97 | 10-Aug-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Replace kvm_err() with kvm_pr_unimpl()
Since guest kernel and ioctl() parameter from user mode is untrusted, there may be noise kernel log output in host hypervisor with abnormal sta
LoongArch: KVM: Replace kvm_err() with kvm_pr_unimpl()
Since guest kernel and ioctl() parameter from user mode is untrusted, there may be noise kernel log output in host hypervisor with abnormal state. Here replace kvm_err() with kvm_pr_unimpl() to reduce this kind of noise kernel log, and there is no function change.
Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| ab382eae | 10-Aug-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Use internal API to deliver interrupt in kernel mode
API kvm_vcpu_ioctl_interrupt() is mainly to used to deliver interrupt from user mode, and internal APIs kvm_queue_irq() and kvm_d
LoongArch: KVM: Use internal API to deliver interrupt in kernel mode
API kvm_vcpu_ioctl_interrupt() is mainly to used to deliver interrupt from user mode, and internal APIs kvm_queue_irq() and kvm_dequeue_irq() are used in kernel mode.
Also move IPI inject and ack within lock protection to avoid contention in ipi_set() and ipi_clear().
Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 81aa3a58 | 10-Aug-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Fix uninitialized stack variable issue with dmsintc
Variable vector[] is declared on stack in function dmsintc_inject_irq() and sometimes it is used without initialized. Here fix thi
LoongArch: KVM: Fix uninitialized stack variable issue with dmsintc
Variable vector[] is declared on stack in function dmsintc_inject_irq() and sometimes it is used without initialized. Here fix this issue.
Cc: stable@vger.kernel.org Fixes: 03de5eecb0f0 ("LoongArch: KVM: Add DMSINTC inject msi to vCPU") Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 5af8b70f | 10-Aug-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Return directly when IPI address is not aligned
When IPI address is not aligned with its access size, it should return directly in read/write operations, rather than only print a mes
LoongArch: KVM: Return directly when IPI address is not aligned
When IPI address is not aligned with its access size, it should return directly in read/write operations, rather than only print a message with WARN_ON_ONCE(). The method is the same with in kernel EIOINTC and PCHPIC operations.
Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| a068c37c | 10-Aug-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Set default MAILBOX access size with 8
With IOCSR instruction emulation in function kvm_emu_iocsr(), possible size combination is 1/2/4/8 and no other combinations. Here remove the o
LoongArch: KVM: Set default MAILBOX access size with 8
With IOCSR instruction emulation in function kvm_emu_iocsr(), possible size combination is 1/2/4/8 and no other combinations. Here remove the old default case and replace the default case with 8 in read_mailbox() and write_mailbox().
Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 32d05564 | 10-Aug-2026 |
Bibo Mao <maobibo@loongson.cn> |
LoongArch: KVM: Set vcpu->cpu before IN_GUEST_MODE is set
In function kvm_make_vcpu_request(), it will send IPI to physical CPU when vCPU is in IN_GUEST_MODE mode. And physical CPU is set in functio
LoongArch: KVM: Set vcpu->cpu before IN_GUEST_MODE is set
In function kvm_make_vcpu_request(), it will send IPI to physical CPU when vCPU is in IN_GUEST_MODE mode. And physical CPU is set in function kvm_check_vpid(), thus it should be called before IN_GUEST_MODE is set. Otherwise IPI will send to wrong old physical CPU where vCPU is running.
Cc: stable@vger.kernel.org Fixes: 2fc3bd86db4b ("LoongArch: KVM: Implement basic vcpu interfaces") Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| fd402152 | 10-Aug-2026 |
Zeng Chi <zengchi@kylinos.cn> |
LoongArch: KVM: Fix PC double advance in kernel MMIO read fast path
In the in-kernel MMIO read fast path of kvm_emu_mmio_read(), kvm_complete_mmio_read() already advances the guest PC via update_pc(
LoongArch: KVM: Fix PC double advance in kernel MMIO read fast path
In the in-kernel MMIO read fast path of kvm_emu_mmio_read(), kvm_complete_mmio_read() already advances the guest PC via update_pc(). The explicit update_pc() call right after it advances the PC a second time, so PC moves forward by 8 bytes instead of 4, and the instruction following the MMIO read is silently skipped.
The user space MMIO read completion path in kvm_arch_vcpu_ioctl_run() calls kvm_complete_mmio_read() only once, and the MMIO write fast path advances the PC exactly once as well.
Here remove the redundant update_pc() so the kernel MMIO read fast path advances the PC by a single instruction.
Cc: stable@vger.kernel.org Fixes: 80edf90831a2 ("LoongArch: KVM: Add sign extension with kernel MMIO read emulation") Reviewed-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Tao Cui <cuitao@kylinos.cn> Signed-off-by: Zeng Chi <zengchi@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 01c823f1 | 10-Aug-2026 |
Tao Cui <cuitao@kylinos.cn> |
LoongArch: KVM: Prevent division by zero in periodic timer restore
A guest can write CSR.TCFG with the periodic bit set but a period value of zero. When kvm_restore_timer() later enters the periodic
LoongArch: KVM: Prevent division by zero in periodic timer restore
A guest can write CSR.TCFG with the periodic bit set but a period value of zero. When kvm_restore_timer() later enters the periodic branch, period = cfg & CSR_TCFG_VAL evaluates to 0, causing (delta % period) to trigger a division by zero and crash the host kernel.
Clamp the period to 1 to avoid the panic.
Fixes: a5857b9ff6e0 ("LoongArch: KVM: Implement vcpu timer operations") Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Tao Cui <cuitao@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| fe41c075 | 10-Aug-2026 |
Tao Cui <cuitao@kylinos.cn> |
LoongArch: KVM: Reload one-shot TVAL on migration destination
kvm_restore_timer() rebuilds the remaining timer countdown value from vcpu->arch.expire, which is host-internal and is not part of the m
LoongArch: KVM: Reload one-shot TVAL on migration destination
kvm_restore_timer() rebuilds the remaining timer countdown value from vcpu->arch.expire, which is host-internal and is not part of the migrated vCPU state. On the migration destination it is still 0, so for a one-shot timer that has not expired yet the computed delta is 0 and write_gcsr_timertick(0) injects the timer interrupt immediately instead of after the remaining time.
The expired one-shot case (TVAL = -1) is already handled earlier. When expire has not been set (i.e. on the migration destination), reload the remaining countdown value from the migrated TVAL. This covers both one- shot and periodic timers. The regular preempt/resume path on the source, where expire is valid, is unchanged.
Fixes: a5857b9ff6e0 ("LoongArch: KVM: Implement vcpu timer operations") Suggested-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Tao Cui <cuitao@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| aeded601 | 11-Jun-2026 |
Zeng Chi <zengchi@kylinos.cn> |
LoongArch: KVM: Add missing slots_lock for device register/unregister
kvm_io_bus_register_dev() and kvm_io_bus_unregister_dev() should be called under kvm->slots_lock. The unregister calls in ipi.c,
LoongArch: KVM: Add missing slots_lock for device register/unregister
kvm_io_bus_register_dev() and kvm_io_bus_unregister_dev() should be called under kvm->slots_lock. The unregister calls in ipi.c, eiointc.c and pch_pic.c were also missing this protection. Add it to match the register side.
Cc: stable@vger.kernel.org Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Zeng Chi <zengchi@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| 34740379 | 11-Jun-2026 |
Yanfei Xu <yanfei.xu@bytedance.com> |
LoongArch: KVM: Validate irqchip index in irqfd routing
Sashiko reported that the irqchip index is not validated for LoongArch. Add validation and reject out-of-range irqchip indexes to avoid indexi
LoongArch: KVM: Validate irqchip index in irqfd routing
Sashiko reported that the irqchip index is not validated for LoongArch. Add validation and reject out-of-range irqchip indexes to avoid indexing past the routing table's chip array.
Cc: stable@vger.kernel.org Fixes: 1928254c5ccb ("LoongArch: KVM: Add irqfd support") Closes: https://lore.kernel.org/kvm/20260525051714.485D51F000E9@smtp.kernel.org/ Reported-by: Sashiko <sashiko-bot@kernel.org> Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Yanfei Xu <yanfei.xu@bytedance.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| ebd50de1 | 11-Jun-2026 |
Qiang Ma <maqianga@uniontech.com> |
LoongArch: KVM: Return full old CSR value from kvm_emu_xchg_csr()
The LoongArch CSRXCHG instruction returns the full old CSR value in rd after applying the masked update. kvm_emu_xchg_csr() currentl
LoongArch: KVM: Return full old CSR value from kvm_emu_xchg_csr()
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: stable@vger.kernel.org Fixes: da50f5a693ff ("LoongArch: KVM: Implement handle csr exception") Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Qiang Ma <maqianga@uniontech.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|
| fb89e0fe | 11-Jun-2026 |
Qiang Ma <maqianga@uniontech.com> |
LoongArch: KVM: Check the return values for put_user()
put_user() may return -EFAULT, so, when the user space address is invalid, the caller should return -EFAULT.
Cc: stable@vger.kernel.org Review
LoongArch: KVM: Check the return values for put_user()
put_user() may return -EFAULT, so, when the user space address is invalid, the caller should return -EFAULT.
Cc: stable@vger.kernel.org Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Qiang Ma <maqianga@uniontech.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
show more ...
|