Skip to content

Commit fb21cb0

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Use standard seq_file iterator for vgic-debug debugfs
The current implementation uses `vgic_state_iter` in `struct vgic_dist` to track the sequence position. This effectively makes the iterator shared across all open file descriptors for the VM. This approach has significant drawbacks: - It enforces mutual exclusion, preventing concurrent reads of the debugfs file (returning -EBUSY). - It relies on storing transient iterator state in the long-lived VM structure (`vgic_dist`). Refactor the implementation to use the standard `seq_file` iterator. Instead of storing state in `kvm_arch`, rely on the `pos` argument passed to the `start` and `next` callbacks, which tracks the logical index specific to the file descriptor. This change enables concurrent access and eliminates the `vgic_state_iter` field from `struct vgic_dist`. Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://patch.msgid.link/20260202085721.3954942-4-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 5ab2496 commit fb21cb0

2 files changed

Lines changed: 12 additions & 31 deletions

File tree

arch/arm64/kvm/vgic/vgic-debug.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -104,58 +104,42 @@ static void *vgic_debug_start(struct seq_file *s, loff_t *pos)
104104
struct kvm *kvm = s->private;
105105
struct vgic_state_iter *iter;
106106

107-
mutex_lock(&kvm->arch.config_lock);
108-
iter = kvm->arch.vgic.iter;
109-
if (iter) {
110-
iter = ERR_PTR(-EBUSY);
111-
goto out;
112-
}
113-
114107
iter = kmalloc(sizeof(*iter), GFP_KERNEL);
115-
if (!iter) {
116-
iter = ERR_PTR(-ENOMEM);
117-
goto out;
118-
}
108+
if (!iter)
109+
return ERR_PTR(-ENOMEM);
119110

120111
iter_init(kvm, iter, *pos);
121-
kvm->arch.vgic.iter = iter;
122112

123-
if (end_of_vgic(iter))
113+
if (end_of_vgic(iter)) {
114+
kfree(iter);
124115
iter = NULL;
125-
out:
126-
mutex_unlock(&kvm->arch.config_lock);
116+
}
117+
127118
return iter;
128119
}
129120

130121
static void *vgic_debug_next(struct seq_file *s, void *v, loff_t *pos)
131122
{
132123
struct kvm *kvm = s->private;
133-
struct vgic_state_iter *iter = kvm->arch.vgic.iter;
124+
struct vgic_state_iter *iter = v;
134125

135126
++*pos;
136127
iter_next(kvm, iter);
137-
if (end_of_vgic(iter))
128+
if (end_of_vgic(iter)) {
129+
kfree(iter);
138130
iter = NULL;
131+
}
139132
return iter;
140133
}
141134

142135
static void vgic_debug_stop(struct seq_file *s, void *v)
143136
{
144-
struct kvm *kvm = s->private;
145-
struct vgic_state_iter *iter;
137+
struct vgic_state_iter *iter = v;
146138

147-
/*
148-
* If the seq file wasn't properly opened, there's nothing to clearn
149-
* up.
150-
*/
151-
if (IS_ERR(v))
139+
if (IS_ERR_OR_NULL(v))
152140
return;
153141

154-
mutex_lock(&kvm->arch.config_lock);
155-
iter = kvm->arch.vgic.iter;
156142
kfree(iter);
157-
kvm->arch.vgic.iter = NULL;
158-
mutex_unlock(&kvm->arch.config_lock);
159143
}
160144

161145
static void print_dist_state(struct seq_file *s, struct vgic_dist *dist,

include/kvm/arm_vgic.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ struct vgic_dist {
302302

303303
struct xarray lpi_xa;
304304

305-
/* used by vgic-debug */
306-
struct vgic_state_iter *iter;
307-
308305
/*
309306
* GICv4 ITS per-VM data, containing the IRQ domain, the VPE
310307
* array, the property table pointer as well as allocation

0 commit comments

Comments
 (0)