]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: vgic: Constify struct irq_ops usage
authorMarc Zyngier <maz@kernel.org>
Wed, 20 May 2026 09:19:36 +0000 (10:19 +0100)
committerMarc Zyngier <maz@kernel.org>
Fri, 22 May 2026 09:04:49 +0000 (10:04 +0100)
vgic-v5 has introduced much more prevalent usage of the struct
irq_ops mechanism.

In the process, it becomes evident that suffers from two related
problems:

- it contains flags, rather than only callbacks
- it is mutable, because we need to update the above flags

Swap the flags for a helper retrieving the flags, and make all
irq_ops const, something that is slightly satisfying.

Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Link: https://lore.kernel.org/r/20260520091949.542365-6-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/arch_timer.c
arch/arm64/kvm/vgic/vgic-v5.c
arch/arm64/kvm/vgic/vgic.c
include/kvm/arm_vgic.h

index cbea4d9ee95522f8d0946b15f84754a54f225c4d..f003df76fdda7caa2933851625c8cf14fdf6768b 100644 (file)
@@ -52,11 +52,17 @@ static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu,
                              enum kvm_arch_timer_regs treg);
 static bool kvm_arch_timer_get_input_level(int vintid);
 
-static struct irq_ops arch_timer_irq_ops = {
+static unsigned long kvm_arch_timer_get_irq_flags(void)
+{
+       return kvm_vgic_global_state.no_hw_deactivation ? VGIC_IRQ_SW_RESAMPLE : 0;
+}
+
+static const struct irq_ops arch_timer_irq_ops = {
+       .get_flags       = kvm_arch_timer_get_irq_flags,
        .get_input_level = kvm_arch_timer_get_input_level,
 };
 
-static struct irq_ops arch_timer_irq_ops_vgic_v5 = {
+static const struct irq_ops arch_timer_irq_ops_vgic_v5 = {
        .get_input_level = kvm_arch_timer_get_input_level,
        .queue_irq_unlock = vgic_v5_ppi_queue_irq_unlock,
        .set_direct_injection = vgic_v5_set_ppi_dvi,
@@ -1392,8 +1398,6 @@ static int kvm_irq_init(struct arch_timer_kvm_info *info)
                        return -ENOMEM;
                }
 
-               if (kvm_vgic_global_state.no_hw_deactivation)
-                       arch_timer_irq_ops.flags |= VGIC_IRQ_SW_RESAMPLE;
                WARN_ON(irq_domain_push_irq(domain, host_vtimer_irq,
                                            (void *)TIMER_VTIMER));
        }
@@ -1591,8 +1595,8 @@ static bool kvm_arch_timer_get_input_level(int vintid)
 int kvm_timer_enable(struct kvm_vcpu *vcpu)
 {
        struct arch_timer_cpu *timer = vcpu_timer(vcpu);
+       const struct irq_ops *ops;
        struct timer_map map;
-       struct irq_ops *ops;
        int ret;
 
        if (timer->enabled)
index 0101ec3f55283da27f202a84a2f6154c2dfd34e1..757484d2493b2176ccaa552dc4b383a655c2dee3 100644 (file)
@@ -285,7 +285,7 @@ void vgic_v5_set_ppi_dvi(struct kvm_vcpu *vcpu, struct vgic_irq *irq, bool dvi)
        __assign_bit(ppi, cpu_if->vgic_ppi_dvir, dvi);
 }
 
-static struct irq_ops vgic_v5_ppi_irq_ops = {
+static const struct irq_ops vgic_v5_ppi_irq_ops = {
        .queue_irq_unlock = vgic_v5_ppi_queue_irq_unlock,
        .set_direct_injection = vgic_v5_set_ppi_dvi,
 };
index 1e9fe8764584de17c295f8b4fbca01617f8a4716..3ac6d49bc4876a6bb4bfdb4b4c896dff13b8759c 100644 (file)
@@ -573,7 +573,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
 }
 
 void kvm_vgic_set_irq_ops(struct kvm_vcpu *vcpu, u32 vintid,
-                         struct irq_ops *ops)
+                         const struct irq_ops *ops)
 {
        struct vgic_irq *irq = vgic_get_vcpu_irq(vcpu, vintid);
 
index ea793479ab25450bd15cbabca9a043209f638572..fe49fb56dc3c92f0b2a7e6cefef369f187add7fe 100644 (file)
@@ -205,7 +205,7 @@ struct vgic_irq;
  */
 struct irq_ops {
        /* Per interrupt flags for special-cased interrupts */
-       unsigned long flags;
+       unsigned long (*get_flags)(void);
 
 #define VGIC_IRQ_SW_RESAMPLE   BIT(0)  /* Clear the active state for resampling */
 
@@ -271,7 +271,7 @@ struct vgic_irq {
        u8 priority;
        u8 group;                       /* 0 == group 0, 1 == group 1 */
 
-       struct irq_ops *ops;
+       const struct irq_ops *ops;
 
        void *owner;                    /* Opaque pointer to reserve an interrupt
                                           for in-kernel devices. */
@@ -279,7 +279,8 @@ struct vgic_irq {
 
 static inline bool vgic_irq_needs_resampling(struct vgic_irq *irq)
 {
-       return irq->ops && (irq->ops->flags & VGIC_IRQ_SW_RESAMPLE);
+       return irq->ops && irq->ops->get_flags &&
+              (irq->ops->get_flags() & VGIC_IRQ_SW_RESAMPLE);
 }
 
 struct vgic_register_region;
@@ -557,7 +558,7 @@ void kvm_vgic_init_cpu_hardware(void);
 int kvm_vgic_inject_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
                        unsigned int intid, bool level, void *owner);
 void kvm_vgic_set_irq_ops(struct kvm_vcpu *vcpu, u32 vintid,
-                         struct irq_ops *ops);
+                         const struct irq_ops *ops);
 void kvm_vgic_clear_irq_ops(struct kvm_vcpu *vcpu, u32 vintid);
 int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
                          u32 vintid);