Skip to content

Commit d2b8870

Browse files
Sebastian Enegregkh
authored andcommitted
misc: Register a PPI for the vcpu stall detection virtual device
Request a PPI for each vCPU during probe which will be used by the host to communicate a stall detected event on the vCPU. When the host raises this interrupt from the virtual machine monitor, the guest is expected to handle the interrupt and panic. Signed-off-by: Sebastian Ene <sebastianene@google.com> Link: https://lore.kernel.org/r/20240703153732.3214238-3-sebastianene@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 173c044 commit d2b8870

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

drivers/misc/vcpu_stall_detector.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
struct vcpu_stall_detect_config {
3333
u32 clock_freq_hz;
3434
u32 stall_timeout_sec;
35+
int ppi_irq;
3536

3637
void __iomem *membase;
3738
struct platform_device *dev;
@@ -77,6 +78,12 @@ vcpu_stall_detect_timer_fn(struct hrtimer *hrtimer)
7778
return HRTIMER_RESTART;
7879
}
7980

81+
static irqreturn_t vcpu_stall_detector_irq(int irq, void *dev)
82+
{
83+
panic("vCPU stall detector");
84+
return IRQ_HANDLED;
85+
}
86+
8087
static int start_stall_detector_cpu(unsigned int cpu)
8188
{
8289
u32 ticks, ping_timeout_ms;
@@ -132,7 +139,7 @@ static int stop_stall_detector_cpu(unsigned int cpu)
132139

133140
static int vcpu_stall_detect_probe(struct platform_device *pdev)
134141
{
135-
int ret;
142+
int ret, irq;
136143
struct resource *r;
137144
void __iomem *membase;
138145
u32 clock_freq_hz = VCPU_STALL_DEFAULT_CLOCK_HZ;
@@ -169,9 +176,22 @@ static int vcpu_stall_detect_probe(struct platform_device *pdev)
169176
vcpu_stall_config = (struct vcpu_stall_detect_config) {
170177
.membase = membase,
171178
.clock_freq_hz = clock_freq_hz,
172-
.stall_timeout_sec = stall_timeout_sec
179+
.stall_timeout_sec = stall_timeout_sec,
180+
.ppi_irq = -1,
173181
};
174182

183+
irq = platform_get_irq_optional(pdev, 0);
184+
if (irq > 0) {
185+
ret = request_percpu_irq(irq,
186+
vcpu_stall_detector_irq,
187+
"vcpu_stall_detector",
188+
vcpu_stall_detectors);
189+
if (ret)
190+
goto err;
191+
192+
vcpu_stall_config.ppi_irq = irq;
193+
}
194+
175195
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
176196
"virt/vcpu_stall_detector:online",
177197
start_stall_detector_cpu,
@@ -184,6 +204,9 @@ static int vcpu_stall_detect_probe(struct platform_device *pdev)
184204
vcpu_stall_config.hp_online = ret;
185205
return 0;
186206
err:
207+
if (vcpu_stall_config.ppi_irq > 0)
208+
free_percpu_irq(vcpu_stall_config.ppi_irq,
209+
vcpu_stall_detectors);
187210
return ret;
188211
}
189212

@@ -193,6 +216,10 @@ static void vcpu_stall_detect_remove(struct platform_device *pdev)
193216

194217
cpuhp_remove_state(vcpu_stall_config.hp_online);
195218

219+
if (vcpu_stall_config.ppi_irq > 0)
220+
free_percpu_irq(vcpu_stall_config.ppi_irq,
221+
vcpu_stall_detectors);
222+
196223
for_each_possible_cpu(cpu)
197224
stop_stall_detector_cpu(cpu);
198225
}

0 commit comments

Comments
 (0)