^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2016 Linaro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Christoffer Dall <christoffer.dall@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kvm_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <kvm/arm_vgic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/kvm_mmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "vgic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Structure to control looping through the entire vgic state. We start at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * zero for each field and move upwards. So, if dist_id is 0 we print the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * distributor info. When dist_id is 1, we have already printed it and move
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * When vcpu_id < nr_cpus we print the vcpu info until vcpu_id == nr_cpus and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct vgic_state_iter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int nr_spis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int nr_lpis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int dist_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int vcpu_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int intid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int lpi_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) u32 *lpi_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static void iter_next(struct vgic_state_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (iter->dist_id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) iter->dist_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) iter->intid++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (iter->intid == VGIC_NR_PRIVATE_IRQS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ++iter->vcpu_id < iter->nr_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) iter->intid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (iter->intid >= (iter->nr_spis + VGIC_NR_PRIVATE_IRQS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (iter->lpi_idx < iter->nr_lpis)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) iter->intid = iter->lpi_array[iter->lpi_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) iter->lpi_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void iter_init(struct kvm *kvm, struct vgic_state_iter *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) loff_t pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int nr_cpus = atomic_read(&kvm->online_vcpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) memset(iter, 0, sizeof(*iter));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) iter->nr_cpus = nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) iter->nr_spis = kvm->arch.vgic.nr_spis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) iter->nr_lpis = vgic_copy_lpi_list(kvm, NULL, &iter->lpi_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (iter->nr_lpis < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) iter->nr_lpis = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Fast forward to the right position if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) while (pos--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) iter_next(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static bool end_of_vgic(struct vgic_state_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return iter->dist_id > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) iter->vcpu_id == iter->nr_cpus &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) iter->intid >= (iter->nr_spis + VGIC_NR_PRIVATE_IRQS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) iter->lpi_idx > iter->nr_lpis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void *vgic_debug_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct kvm *kvm = (struct kvm *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct vgic_state_iter *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) mutex_lock(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) iter = kvm->arch.vgic.iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) iter = ERR_PTR(-EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) iter = kmalloc(sizeof(*iter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (!iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) iter = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) iter_init(kvm, iter, *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) kvm->arch.vgic.iter = iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (end_of_vgic(iter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) iter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) mutex_unlock(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void *vgic_debug_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct kvm *kvm = (struct kvm *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct vgic_state_iter *iter = kvm->arch.vgic.iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) iter_next(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (end_of_vgic(iter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) iter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void vgic_debug_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct kvm *kvm = (struct kvm *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct vgic_state_iter *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * If the seq file wasn't properly opened, there's nothing to clearn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (IS_ERR(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) mutex_lock(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) iter = kvm->arch.vgic.iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) kfree(iter->lpi_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) kfree(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) kvm->arch.vgic.iter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) mutex_unlock(&kvm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void print_dist_state(struct seq_file *s, struct vgic_dist *dist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) bool v3 = dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) seq_printf(s, "Distributor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) seq_printf(s, "===========\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) seq_printf(s, "vgic_model:\t%s\n", v3 ? "GICv3" : "GICv2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) seq_printf(s, "nr_spis:\t%d\n", dist->nr_spis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (v3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) seq_printf(s, "nr_lpis:\t%d\n", dist->lpi_list_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) seq_printf(s, "enabled:\t%d\n", dist->enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) seq_printf(s, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) seq_printf(s, "P=pending_latch, L=line_level, A=active\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) seq_printf(s, "E=enabled, H=hw, C=config (level=1, edge=0)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) seq_printf(s, "G=group\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void print_header(struct seq_file *s, struct vgic_irq *irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) char *hdr = "SPI ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (vcpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) hdr = "VCPU";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) id = vcpu->vcpu_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) seq_printf(s, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) seq_printf(s, "%s%2d TYP ID TGT_ID PLAEHCG HWID TARGET SRC PRI VCPU_ID\n", hdr, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) seq_printf(s, "----------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static void print_irq_state(struct seq_file *s, struct vgic_irq *irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct kvm_vcpu *vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) char *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) bool pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (irq->intid < VGIC_NR_SGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) type = "SGI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) else if (irq->intid < VGIC_NR_PRIVATE_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) type = "PPI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) else if (irq->intid < VGIC_MAX_SPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) type = "SPI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) type = "LPI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (irq->intid ==0 || irq->intid == VGIC_NR_PRIVATE_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) print_header(s, irq, vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) pending = irq->pending_latch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) err = irq_get_irqchip_state(irq->host_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) IRQCHIP_STATE_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) &pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) WARN_ON_ONCE(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) seq_printf(s, " %s %4d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) " %2d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) "%d%d%d%d%d%d%d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) "%8d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) "%8x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) " %2x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) "%3d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) " %2d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) "\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) type, irq->intid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) (irq->target_vcpu) ? irq->target_vcpu->vcpu_id : -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) irq->line_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) irq->active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) irq->enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) irq->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) irq->config == VGIC_CONFIG_LEVEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) irq->group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) irq->hwintid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) irq->mpidr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) irq->source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) irq->priority,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) (irq->vcpu) ? irq->vcpu->vcpu_id : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int vgic_debug_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct kvm *kvm = (struct kvm *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct vgic_state_iter *iter = (struct vgic_state_iter *)v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct vgic_irq *irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct kvm_vcpu *vcpu = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (iter->dist_id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) print_dist_state(s, &kvm->arch.vgic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (!kvm->arch.vgic.initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (iter->vcpu_id < iter->nr_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) vcpu = kvm_get_vcpu(kvm, iter->vcpu_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) irq = vgic_get_irq(kvm, vcpu, iter->intid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) seq_printf(s, " LPI %4d freed\n", iter->intid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) raw_spin_lock_irqsave(&irq->irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) print_irq_state(s, irq, vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) vgic_put_irq(kvm, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct seq_operations vgic_debug_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .start = vgic_debug_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .next = vgic_debug_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .stop = vgic_debug_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .show = vgic_debug_show
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) DEFINE_SEQ_ATTRIBUTE(vgic_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) void vgic_debug_init(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) debugfs_create_file("vgic-state", 0444, kvm->debugfs_dentry, kvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) &vgic_debug_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) void vgic_debug_destroy(struct kvm *kvm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }