On Mon, Jan 13, 2025, Adrian Hunter wrote: > On 9/01/25 21:11, Sean Christopherson wrote: > > My vote would to KVM_BUG_ON() before entering the guest. > > I notice if KVM_BUG_ON() is called with interrupts disabled > smp_call_function_many_cond() generates a warning: > > WARNING: CPU: 223 PID: 4213 at kernel/smp.c:807 smp_call_function_many_cond+0x421/0x560 > > static void smp_call_function_many_cond(const struct cpumask *mask, > smp_call_func_t func, void *info, > unsigned int scf_flags, > smp_cond_func_t cond_func) > { > int cpu, last_cpu, this_cpu = smp_processor_id(); > struct call_function_data *cfd; > bool wait = scf_flags & SCF_WAIT; > int nr_cpus = 0; > bool run_remote = false; > bool run_local = false; > > lockdep_assert_preemption_disabled(); > > /* > * Can deadlock when called with interrupts disabled. > * We allow cpu's that are not yet online though, as no one else can > * send smp call function interrupt to this cpu and as such deadlocks > * can't happen. > */ > if (cpu_online(this_cpu) && !oops_in_progress && > !early_boot_irqs_disabled) > lockdep_assert_irqs_enabled(); <------------- here > > Do we need to care about that? Ugh, yes. E.g. the deadlock mentioned in the comment would occur if two vCPUs hit the KVM_BUG_ON() at the same time (they'd both wait for the other to respond to *their* IPI). Since the damage is limited to the current vCPU, i.e. letting userspace run other vCPUs is unlikely to put KVM in harm's way, a not-awful alternative would be to WARN_ON_ONCE() and return KVM_EXIT_INTERNAL_ERROR.