Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sebastian Ene and committed by
Greg Kroah-Hartman
d2b88700 173c0447

+29 -2
+29 -2
drivers/misc/vcpu_stall_detector.c
··· 32 32 struct vcpu_stall_detect_config { 33 33 u32 clock_freq_hz; 34 34 u32 stall_timeout_sec; 35 + int ppi_irq; 35 36 36 37 void __iomem *membase; 37 38 struct platform_device *dev; ··· 76 75 ms_to_ktime(ping_timeout_ms)); 77 76 78 77 return HRTIMER_RESTART; 78 + } 79 + 80 + static irqreturn_t vcpu_stall_detector_irq(int irq, void *dev) 81 + { 82 + panic("vCPU stall detector"); 83 + return IRQ_HANDLED; 79 84 } 80 85 81 86 static int start_stall_detector_cpu(unsigned int cpu) ··· 139 132 140 133 static int vcpu_stall_detect_probe(struct platform_device *pdev) 141 134 { 142 - int ret; 135 + int ret, irq; 143 136 struct resource *r; 144 137 void __iomem *membase; 145 138 u32 clock_freq_hz = VCPU_STALL_DEFAULT_CLOCK_HZ; ··· 176 169 vcpu_stall_config = (struct vcpu_stall_detect_config) { 177 170 .membase = membase, 178 171 .clock_freq_hz = clock_freq_hz, 179 - .stall_timeout_sec = stall_timeout_sec 172 + .stall_timeout_sec = stall_timeout_sec, 173 + .ppi_irq = -1, 180 174 }; 175 + 176 + irq = platform_get_irq_optional(pdev, 0); 177 + if (irq > 0) { 178 + ret = request_percpu_irq(irq, 179 + vcpu_stall_detector_irq, 180 + "vcpu_stall_detector", 181 + vcpu_stall_detectors); 182 + if (ret) 183 + goto err; 184 + 185 + vcpu_stall_config.ppi_irq = irq; 186 + } 181 187 182 188 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, 183 189 "virt/vcpu_stall_detector:online", ··· 204 184 vcpu_stall_config.hp_online = ret; 205 185 return 0; 206 186 err: 187 + if (vcpu_stall_config.ppi_irq > 0) 188 + free_percpu_irq(vcpu_stall_config.ppi_irq, 189 + vcpu_stall_detectors); 207 190 return ret; 208 191 } 209 192 ··· 215 192 int cpu; 216 193 217 194 cpuhp_remove_state(vcpu_stall_config.hp_online); 195 + 196 + if (vcpu_stall_config.ppi_irq > 0) 197 + free_percpu_irq(vcpu_stall_config.ppi_irq, 198 + vcpu_stall_detectors); 218 199 219 200 for_each_possible_cpu(cpu) 220 201 stop_stall_detector_cpu(cpu);