RE: [PATCH 5/6] KVM: x86/VMX: add kvm_vmx_reinject_nmi_irq() for NMI/IRQ reinjection

Li, Xin3
2022-11-14T02:18:54Z

> > > > + * call thus the values in the pt_regs structure are not used in
> > > > + * executing NMI/IRQ handlers,
> > >
> > > Won't this break stack traces to some extent?
> > >
> >
> > The pt_regs structure, and its IP/CS, is NOT part of the call stack,
> > thus I don't see a problem. No?
>
> bool nmi_cpu_backtrace(struct pt_regs *regs)
> {
> int cpu = smp_processor_id();
> unsigned long flags;
>
> if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
> /*
> * Allow nested NMI backtraces while serializing
> * against other CPUs.
> */
> printk_cpu_sync_get_irqsave(flags);
> if (!READ_ONCE(backtrace_idle) && regs &&
> cpu_in_idle(instruction_pointer(regs))) {
> pr_warn("NMI backtrace for cpu %d skipped: idling at
> %pS\n",
> cpu, (void *)instruction_pointer(regs));
> } else {
> pr_warn("NMI backtrace for cpu %d\n", cpu);
> if (regs)
> show_regs(regs);
> <============================== HERE!!!
> else
> dump_stack();
> }
> printk_cpu_sync_put_irqrestore(flags);
> cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
> return true;
> }
>
> return false;
> }

Right, this is an example in which pt_regs's usage gets broken with my patch.

However a bigger problem emerges, how NMI handlers should get called when VMX
is running. If we could address it, we will probably be okay with pt_regs's
usage.