Skip to content

Commit e1cb399

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: selftests: aarch64: Abstract the injection functions in vgic_irq
Build an abstraction around the injection functions, so the preparation and checking around the actual injection can be shared between tests. All functions are stored as pointers in arrays of kvm_inject_desc's which include the pointer and what kind of interrupts they can inject. Signed-off-by: Ricardo Koller <[email protected]> Acked-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 50b020c commit e1cb399

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

tools/testing/selftests/kvm/aarch64/vgic_irq.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,28 @@ struct kvm_inject_args {
5757
/* Used on the guest side to perform the hypercall. */
5858
static void kvm_inject_call(kvm_inject_cmd cmd, uint32_t intid);
5959

60+
#define KVM_INJECT(cmd, intid) \
61+
kvm_inject_call(cmd, intid)
62+
6063
/* Used on the host side to get the hypercall info. */
6164
static void kvm_inject_get_call(struct kvm_vm *vm, struct ucall *uc,
6265
struct kvm_inject_args *args);
6366

67+
struct kvm_inject_desc {
68+
kvm_inject_cmd cmd;
69+
/* can inject PPIs, PPIs, and/or SPIs. */
70+
bool sgi, ppi, spi;
71+
};
72+
73+
static struct kvm_inject_desc inject_edge_fns[] = {
74+
/* sgi ppi spi */
75+
{ KVM_INJECT_EDGE_IRQ_LINE, false, false, true },
76+
{ 0, },
77+
};
78+
79+
#define for_each_inject_fn(t, f) \
80+
for ((f) = (t); (f)->cmd; (f)++)
81+
6482
/* Shared between the guest main thread and the IRQ handlers. */
6583
volatile uint64_t irq_handled;
6684
volatile uint32_t irqnr_received[MAX_SPI + 1];
@@ -120,12 +138,12 @@ do { \
120138
GUEST_ASSERT(_intid == 0 || _intid == IAR_SPURIOUS); \
121139
} while (0)
122140

123-
static void test_kvm_irq_line(uint32_t intid)
141+
static void guest_inject(uint32_t intid, kvm_inject_cmd cmd)
124142
{
125143
reset_stats();
126144

127145
asm volatile("msr daifset, #2" : : : "memory");
128-
kvm_inject_call(KVM_INJECT_EDGE_IRQ_LINE, intid);
146+
KVM_INJECT(cmd, intid);
129147

130148
while (irq_handled < 1) {
131149
asm volatile("wfi\n"
@@ -141,10 +159,23 @@ static void test_kvm_irq_line(uint32_t intid)
141159
GUEST_ASSERT_IAR_EMPTY();
142160
}
143161

162+
static void test_injection(struct kvm_inject_desc *f)
163+
{
164+
if (f->sgi)
165+
guest_inject(MIN_SGI, f->cmd);
166+
167+
if (f->ppi)
168+
guest_inject(MIN_PPI, f->cmd);
169+
170+
if (f->spi)
171+
guest_inject(MIN_SPI, f->cmd);
172+
}
173+
144174
static void guest_code(void)
145175
{
146176
uint32_t i;
147177
uint32_t nr_irqs = 64; /* absolute minimum number of IRQs supported. */
178+
struct kvm_inject_desc *f;
148179

149180
gic_init(GIC_V3, 1, dist, redist);
150181

@@ -157,7 +188,9 @@ static void guest_code(void)
157188

158189
local_irq_enable();
159190

160-
test_kvm_irq_line(MIN_SPI);
191+
/* Start the tests. */
192+
for_each_inject_fn(inject_edge_fns, f)
193+
test_injection(f);
161194

162195
GUEST_DONE();
163196
}

0 commit comments

Comments
 (0)