* [PATCH v2] KVM: arm64: Register irq_bypass consumers only when direct MSIs are possible
@ 2026-11-13 9:38 Jinqian Yang
2026-11-13 10:01 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jinqian Yang @ 2026-11-13 9:38 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, kvmarm
Cc: maz, oupton, fuad.tabba, yuzenghui, joey.gouly, seiden,
suzuki.poulose, yangjinqian1, liuyonglong, wangzhou1, prime.zeng,
tangchengchang, zhengtian10, linuxarm, liujian222
kvm_arch_has_irq_bypass() on arm64 returns true unconditionally, so
every irqfd assignment registers an irq_bypass consumer even when KVM
cannot do direct MSI forwarding for the VM. In that case
kvm_vgic_v4_set_forwarding() bails out at its very first check, since
vgic_supports_direct_msis() is false, and the registration becomes pure
overhead: every KVM_IRQFD ioctl takes the global irq_bypass mutex, which
becomes a contention point when many VMs boot concurrently.
Pass struct kvm to kvm_arch_has_irq_bypass() and gate the registration
on vgic_supports_direct_msis(kvm), like x86 gates on
enable_device_posted_irqs. Reading the per-VM vgic state is safe here,
as kvm_irqfd_assign() requires an initialized irqchip.
Functionally this is a no-op: without direct MSI support the consumer
registration never did anything beyond acquiring the lock. On a
GICv3-only host booting 100 microVMs concurrently this cuts the average
boot time by ~5 ms, matching the gain observed with
CONFIG_HAVE_KVM_IRQ_BYPASS=n.
Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com>
---
v1 -> v2:
- Gate on vgic_supports_direct_msis(kvm) instead of the global
kvm_vgic_global_state.has_gicv4 flag, This requires passing struct
kvm to kvm_arch_has_irq_bypass() and updating the x86 and PPC callers.
v1: https://lore.kernel.org/linux-arm-kernel/20261109112018.241298-1-yangjinqian1@huawei.com/
arch/arm64/include/asm/kvm_host.h | 4 ++--
arch/arm64/kvm/vgic/vgic.h | 1 -
arch/powerpc/kvm/powerpc.c | 2 +-
arch/x86/include/asm/kvm_host.h | 2 +-
arch/x86/kvm/irq.c | 2 +-
arch/x86/kvm/vmx/posted_intr.c | 2 +-
include/kvm/arm_vgic.h | 1 +
include/linux/kvm_host.h | 2 +-
virt/kvm/eventfd.c | 2 +-
9 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 97332ffcb130..da86646b6709 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1742,9 +1742,9 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val);
#define kvm_has_sctlr2(k) \
(kvm_has_feat((k), ID_AA64MMFR3_EL1, SCTLRX, IMP))
-static inline bool kvm_arch_has_irq_bypass(void)
+static inline bool kvm_arch_has_irq_bypass(struct kvm *kvm)
{
- return true;
+ return vgic_supports_direct_msis(kvm);
}
void kvm_idregs_enforce_dependencies(struct kvm *kvm);
diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h
index 97fc3bdf520e..3c128e4d9afa 100644
--- a/arch/arm64/kvm/vgic/vgic.h
+++ b/arch/arm64/kvm/vgic/vgic.h
@@ -521,7 +521,6 @@ static inline bool vgic_host_has_gicv5(void)
}
bool system_supports_direct_sgis(void);
-bool vgic_supports_direct_msis(struct kvm *kvm);
bool vgic_supports_direct_sgis(struct kvm *kvm);
static inline bool vgic_supports_direct_irqs(struct kvm *kvm)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 9194cf492d1c..74c0d457f4ca 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -875,7 +875,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
* irq_bypass_stop and irq_bypass_start are not needed and so
* kvm_ops are not defined for them.
*/
-bool kvm_arch_has_irq_bypass(void)
+bool kvm_arch_has_irq_bypass(struct kvm *kvm)
{
return ((kvmppc_hv_ops && kvmppc_hv_ops->irq_bypass_add_producer) ||
(kvmppc_pr_ops && kvmppc_pr_ops->irq_bypass_add_producer));
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 1ee4b127004d..8b6f5b72fea5 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1919,7 +1919,7 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)
kvm_x86_call(vcpu_unblocking)(vcpu);
}
-static inline bool kvm_arch_has_irq_bypass(void)
+static inline bool kvm_arch_has_irq_bypass(struct kvm *kvm)
{
return enable_device_posted_irqs;
}
diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index 871977288272..81eeecc614ef 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -439,7 +439,7 @@ static int kvm_pi_update_irte(struct kvm_kernel_irqfd *irqfd,
struct kvm_lapic_irq irq;
int r;
- if (WARN_ON_ONCE(!irqchip_in_kernel(kvm) || !kvm_arch_has_irq_bypass()))
+ if (WARN_ON_ONCE(!irqchip_in_kernel(kvm) || !kvm_arch_has_irq_bypass(kvm)))
return -EINVAL;
if (entry && entry->type == KVM_IRQ_ROUTING_MSI) {
diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
index 2644add54b76..15d7a97fd7f6 100644
--- a/arch/x86/kvm/vmx/posted_intr.c
+++ b/arch/x86/kvm/vmx/posted_intr.c
@@ -153,7 +153,7 @@ static bool vt_can_use_vtd_pi(struct kvm *kvm)
* bypass IRQ being attached to the VM. vt_pi_start_bypass() ensures
* blockng vCPUs will see an elevated count or get KVM_REQ_UNBLOCK.
*/
- return irqchip_in_kernel(kvm) && kvm_arch_has_irq_bypass() &&
+ return irqchip_in_kernel(kvm) && kvm_arch_has_irq_bypass(kvm) &&
READ_ONCE(kvm->arch.nr_possible_bypass_irqs);
}
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index 4b2c41917b77..39c69d861060 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -215,6 +215,7 @@ struct vgic_global {
};
extern struct vgic_global kvm_vgic_global_state;
+bool vgic_supports_direct_msis(struct kvm *kvm);
#define VGIC_V2_MAX_LRS (1 << 6)
#define VGIC_V3_MAX_LRS 16
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index e7fc94e2910a..bdf002a62686 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2458,7 +2458,7 @@ struct kvm_vcpu * __percpu *kvm_get_running_vcpus(void);
#if IS_ENABLED(CONFIG_HAVE_KVM_IRQ_BYPASS)
struct kvm_kernel_irqfd;
-bool kvm_arch_has_irq_bypass(void);
+bool kvm_arch_has_irq_bypass(struct kvm *kvm);
int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *,
struct irq_bypass_producer *);
void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *,
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index f43b8b25bc85..07a7c8fc3bbe 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -488,7 +488,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
schedule_work(&irqfd->inject);
#if IS_ENABLED(CONFIG_HAVE_KVM_IRQ_BYPASS)
- if (kvm_arch_has_irq_bypass()) {
+ if (kvm_arch_has_irq_bypass(kvm)) {
irqfd->consumer.add_producer = kvm_arch_irq_bypass_add_producer;
irqfd->consumer.del_producer = kvm_arch_irq_bypass_del_producer;
irqfd->consumer.stop = kvm_arch_irq_bypass_stop;
--
2.33.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] KVM: arm64: Register irq_bypass consumers only when direct MSIs are possible
2026-11-13 9:38 [PATCH v2] KVM: arm64: Register irq_bypass consumers only when direct MSIs are possible Jinqian Yang
@ 2026-11-13 10:01 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-13 10:01 UTC (permalink / raw)
To: Jinqian Yang, kvmarm; +Cc: Oliver Upton, Marc Zyngier
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: arm64: irq_bypass skipped if vITS is created after
KVM_IRQFD
--
commit 3a0bd42f42a6d2802fe72bb1bc5c8b719382be8f
Author: Jinqian Yang <yangjinqian1@huawei.com>
KVM: arm64: Register irq_bypass consumers only when direct MSIs are possible
This commit passes struct kvm to kvm_arch_has_irq_bypass() and gates
arm64 irq_bypass consumer registration on vgic_supports_direct_msis(kvm).
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index 97332ffcb1300..da86646b67097 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -1742,9 +1742,9 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val);
> #define kvm_has_sctlr2(k) \
> (kvm_has_feat((k), ID_AA64MMFR3_EL1, SCTLRX, IMP))
>
> -static inline bool kvm_arch_has_irq_bypass(void)
> +static inline bool kvm_arch_has_irq_bypass(struct kvm *kvm)
> {
> - return true;
> + return vgic_supports_direct_msis(kvm);
> }
>
> void kvm_idregs_enforce_dependencies(struct kvm *kvm);
[Severity: Medium]
Can kvm_irqfd_assign() skip irq_bypass_register_consumer() when userspace
creates the virtual ITS after initializing the VGICv3 distributor and
assigning irqfds?
kvm_irqfd_assign() only requires kvm_arch_intc_initialized(kvm)
(vgic_initialized(kvm)) and evaluates kvm_arch_has_irq_bypass(kvm) once
without holding kvm->arch.config_lock. vgic_supports_direct_msis(kvm)
checks vgic_has_its(kvm), which tests dist->its_model, but vgic_its_create()
explicitly allows creating a KVM_DEV_TYPE_ARM_VGIC_ITS device after the
VGIC is already initialized:
arch/arm64/kvm/vgic/vgic-its.c:vgic_its_create() {
...
if (vgic_initialized(dev->kvm)) {
ret = vgic_v4_init(dev->kvm);
...
dev->kvm->arch.vgic.msis_require_devid = true;
dev->kvm->arch.vgic.its_model = KVM_DEV_TYPE_ARM_VGIC_V3;
}
If userspace initializes the VGICv3 distributor, assigns an irqfd via
KVM_IRQFD, and then creates the ITS and configures MSI routing,
vgic_supports_direct_msis(kvm) returns false during kvm_irqfd_assign().
Because vgic_its_create() does not register existing irqfds as irq_bypass
consumers, GICv4 direct vLPI forwarding is never enabled for those irqfds
and interrupts silently fall back to software injection.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261113093840.1034795-1-yangjinqian1@huawei.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-13 10:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 9:38 [PATCH v2] KVM: arm64: Register irq_bypass consumers only when direct MSIs are possible Jinqian Yang
2026-11-13 10:01 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.