LoongArch: KVM: Advertise already-supported capabilities
Subsystems (3)
PATCH 1/1 LoongArch: KVM: Advertise already-supported capabilities
Several LoongArch KVM features are fully implemented but were never reported through their standard KVM_CHECK_EXTENSION probes, so userspace cannot discover them and either ignores them or takes a slower path. Advertise the ones that already work:
- KVM_CAP_STEAL_TIME: steal time is fully implemented (host-side record plus guest paravirt), gated on kvm_pvtime_supported().
- KVM_CAP_IRQFD_RESAMPLE: the resampler is generic code backed by the in-kernel irqchip; advertise it so userspace can use irqfd with resample for level-triggered interrupts.
- KVM_CAP_VM_GPA_BITS: the guest physical address width is already computed as BIT(cpu_vabits), so return cpu_vabits directly.
- KVM_CAP_VCPU_ATTRIBUTES: per-vCPU device-attribute ioctls are implemented (CPUCFG, PVTIME control); advertise the discovery cap.
This adds no new functionality; it only makes existing features discoverable via the standard probe.
--- arch/loongarch/kvm/vm.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/loongarch/kvm/vm.c +8 -0
@@ -120,8 +120,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_READONLY_MEM :case KVM_CAP_IMMEDIATE_EXIT :case KVM_CAP_IOEVENTFD : +case KVM_CAP_IRQFD_RESAMPLE :case KVM_CAP_MP_STATE :case KVM_CAP_SET_GUEST_DEBUG : +case KVM_CAP_VCPU_ATTRIBUTES : r =1 ;break ;case KVM_CAP_NR_VCPUS :
@@ -136,6 +138,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_NR_MEMSLOTS : r =KVM_USER_MEM_SLOTS ;break ; +case KVM_CAP_STEAL_TIME : + r =kvm_pvtime_supported (); +break ; +case KVM_CAP_VM_GPA_BITS : + r = cpu_vabits; +break ;default : r =0 ;break ;
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Falsely advertising KVM_CAP_IRQFD_RESAMPLE without underlying architecture support leads to broken…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Falsely advertising KVM_CAP_IRQFD_RESAMPLE without underlying architecture support leads to broken level-triggered interrupts (e.g., VFIO INTx pass-through). --
--- Patch [1]: [PATCH] LoongArch: KVM: Advertise already-supported capabilities --- commit 09ee78983007b60953a55e2354d4d1971a9bc4c7
Author: Tao Cui <[email protected]>
LoongArch: KVM: Advertise already-supported capabilities
This commit advertises several KVM capabilities for LoongArch to userspace that are noted as already supported. It enables discovery for KVM_CAP_STEAL_TIME, KVM_CAP_IRQFD_RESAMPLE, KVM_CAP_VM_GPA_BITS, and KVM_CAP_VCPU_ATTRIBUTES.
Quoted 3 lines
arch/loongarch/kvm/vm.c +0
-0
[ ... ]
arch/loongarch/kvm/vm.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 123
Quoted 5 lines
arch/loongarch/kvm/vm.c +1
-0@@ -120,8 +120,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_READONLY_MEM :case KVM_CAP_IMMEDIATE_EXIT :case KVM_CAP_IOEVENTFD : +case KVM_CAP_IRQFD_RESAMPLE :
[Severity: High]
Does the underlying architecture actually support IRQFD resamplers?
The commit message states the resampler is generic code backed by the in-kernel irqchip. However, the generic irqfd resampler relies entirely on the architecture's in-kernel irqchip explicitly calling kvm_notify_acked_irq(), kvm_notify_acked_gsi(), or similar hooks when the guest acknowledges the interrupt.
If the LoongArch irqchip implementations do not call any of these notification hooks, the resampler will never trigger. Will this cause physical interrupts to remain permanently masked after their first injection, potentially hanging passed-through devices that rely on level-triggered interrupts (such as VFIO INTx pass-through)?
Quoted 2 lines
arch/loongarch/kvm/vm.c +0
-0case KVM_CAP_MP_STATE :case KVM_CAP_SET_GUEST_DEBUG :
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Bibo Mao
maintainerQuoted 31 lines · Tao Cui
Several LoongArch KVM features are fully implemented but were never reported through their standard
KVM_CHECK_EXTENSIONprobes, so userspace cannot discover them and either ignores them or takes a slower path. Advertise the ones that already work:-
KVM_CAP_STEAL_TIME: steal time is fully implemented (host-side record plus guest paravirt), gated onkvm_pvtime_supported().-
KVM_CAP_IRQFD_RESAMPLE: the resampler is generic code backed by the in-kernel irqchip; advertise it so userspace can use irqfd with resample for level-triggered interrupts.-
KVM_CAP_VM_GPA_BITS: the guest physical address width is already computed asBIT(cpu_vabits), so returncpu_vabitsdirectly.-
KVM_CAP_VCPU_ATTRIBUTES: per-vCPU device-attribute ioctls are implemented (CPUCFG, PVTIME control); advertise the discovery cap.This adds no new functionality; it only makes existing features discoverable via the standard probe.
Signed-off-by Tao Cui <[email protected]>--- arch/loongarch/kvm/vm.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/loongarch/kvm/vm.c +0
-0
arch/loongarch/kvm/vm.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 123
Quoted 4 lines
arch/loongarch/kvm/vm.c +1
-0@@ -120,8 +120,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_READONLY_MEM :case KVM_CAP_IMMEDIATE_EXIT :case KVM_CAP_IOEVENTFD : +case KVM_CAP_IRQFD_RESAMPLE :
By my understanding, KVM_CAP_IRQFD_RESAMPLE is used for VFIO intx irqline interrupt injection, is that true? now IOMMU and VFIO is not supported on LoongArch.
arch/loongarch/kvm/vm.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 126
Quoted 3 lines
arch/loongarch/kvm/vm.c +1
-0case KVM_CAP_MP_STATE :case KVM_CAP_SET_GUEST_DEBUG : +case KVM_CAP_VCPU_ATTRIBUTES :
this is ok.
arch/loongarch/kvm/vm.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 143
Quoted 10 lines
arch/loongarch/kvm/vm.c +3
-0r =1 ;break ;case KVM_CAP_NR_VCPUS :@@ -136,6 +138,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_NR_MEMSLOTS : r =KVM_USER_MEM_SLOTS ;break ; +case KVM_CAP_STEAL_TIME : + r =kvm_pvtime_supported (); +break ;
this is ok.
arch/loongarch/kvm/vm.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 145
Quoted 2 lines
arch/loongarch/kvm/vm.c +2
-0+case KVM_CAP_VM_GPA_BITS : + r = cpu_vabits;
Feature KVM_CAP_VM_GPA_BITS is also to control max supported GPA bit of VM, only only max supported PA bit on host. For example max PA bit is 48 on host, it is ok to set GPA bit with 40 or 48, only if it is smaller than one on host. If my understanding is correct, it is not supported on LoongArch now.
Regards
Bibo Mao
Quoted 5 lines
arch/loongarch/kvm/vm.c +1
-0+break ;default : r =0 ;break ;
Hi Bibo,
Quoted 16 lines · Bibo Mao
Quoted 15 lines · Tao Cui
Several LoongArch KVM features are fully implemented but were never reported through their standard
KVM_CHECK_EXTENSIONprobes, so userspace cannot discover them and either ignores them or takes a slower path. Advertise the ones that already work:-
KVM_CAP_STEAL_TIME: steal time is fully implemented (host-side record plus guest paravirt), gated onkvm_pvtime_supported().-
KVM_CAP_IRQFD_RESAMPLE: the resampler is generic code backed by the in-kernel irqchip; advertise it so userspace can use irqfd with resample for level-triggered interrupts.-
KVM_CAP_VM_GPA_BITS: the guest physical address width is already computed asBIT(cpu_vabits), so returncpu_vabitsdirectly.
Quoted 6 lines
Quoted 6 lines
-
KVM_CAP_VCPU_ATTRIBUTES: per-vCPU device-attribute ioctls are implemented (CPUCFG, PVTIME control); advertise the discovery cap.This adds no new functionality; it only makes existing features discoverable via the standard probe.
Thanks for the careful review — you are right on both points.
I must admit I was a bit hasty here. I only verified that the probes returned nonzero on a 3A6000 and didn't dig into what the capabilities actually guarantee or who consumes them. The return values looked fine, so the details you raised slipped through.
Quoted 5 lines
Quoted 5 lines
Signed-off-by Tao Cui <[email protected]>---
arch/loongarch/kvm/vm.c| 8 ++++++++1 file changed, 8 insertions(+)
Quoted 11 lines
Quoted 9 lines
arch/loongarch/kvm/vm.c +0
-0@@ -120,8 +120,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case
KVM_CAP_READONLY_MEM:
caseKVM_CAP_IMMEDIATE_EXIT:
caseKVM_CAP_IOEVENTFD:
+ caseKVM_CAP_IRQFD_RESAMPLE:By my understanding,
KVM_CAP_IRQFD_RESAMPLEis used for VFIO intx irqline interrupt injection, is that true? now IOMMU and VFIO is not supported on LoongArch.
You're right. The real consumer is VFIO INTx level-interrupt passthrough, and without IOMMU/VFIO there is no current LoongArch userspace that would use irqfd + resample. I'll drop it for now and revisit it together with VFIO/IOMMU support.
Quoted 16 lines
Quoted 3 lines
case
KVM_CAP_MP_STATE:
caseKVM_CAP_SET_GUEST_DEBUG:
+ caseKVM_CAP_VCPU_ATTRIBUTES:this is ok.
Quoted 10 lines
r = 1;
break;
caseKVM_CAP_NR_VCPUS:arch/loongarch/kvm/vm.c +0
-0@@ -136,6 +138,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case
KVM_CAP_NR_MEMSLOTS:
r =KVM_USER_MEM_SLOTS;
break;
+ caseKVM_CAP_STEAL_TIME:
+ r =kvm_pvtime_supported();
+ break;this is ok.
Quoted 5 lines
Quoted 2 lines
+ case
KVM_CAP_VM_GPA_BITS:
+ r =cpu_vabits;Feature
KVM_CAP_VM_GPA_BITSis also to control max supported GPA bit of VM, only only max supported PA bit on host. For example max PA bit is 48 on host, it is ok to set GPA bit with 40 or 48, only if it is smaller than one on host. If my understanding is correct, it is not supported on LoongArch now.
Agreed, and thanks for catching this. I overlooked that the capability is paired with a setter — on riscv, cap->args[0] lets userspace choose the VM GPA width by selecting the stage-2 pgd levels. LoongArch's GPA width is fixed at BIT(cpu_vabits) and that configurability is not implemented, so advertising the cap would be misleading. Dropped.
v2 advertises only KVM_CAP_STEAL_TIME and KVM_CAP_VCPU_ATTRIBUTES (both sanity-checked on 3A6000: they go 0 -> 1).
Thanks,
Tao
Quoted 8 lines
Regards
Bibo MaoQuoted 5 lines
+ break;
default:
r = 0;
break;