Re: [PATCH 15/17] KVM: retpolines: x86: eliminate retpoline from vmx.c exit handlers

Paolo Bonzini
2019-09-23T09:58:02Z

On 23/09/19 11:31, Vitaly Kuznetsov wrote:
> +#ifdef CONFIG_RETPOLINE
> + if (exit_reason == EXIT_REASON_MSR_WRITE)
> + return handle_wrmsr(vcpu);
> + else if (exit_reason == EXIT_REASON_PREEMPTION_TIMER)
> + return handle_preemption_timer(vcpu);
> + else if (exit_reason == EXIT_REASON_PENDING_INTERRUPT)
> + return handle_interrupt_window(vcpu);
> + else if (exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
> + return handle_external_interrupt(vcpu);
> + else if (exit_reason == EXIT_REASON_HLT)
> + return handle_halt(vcpu);
> + else if (exit_reason == EXIT_REASON_PAUSE_INSTRUCTION)
> + return handle_pause(vcpu);
> + else if (exit_reason == EXIT_REASON_MSR_READ)
> + return handle_rdmsr(vcpu);
> + else if (exit_reason == EXIT_REASON_CPUID)
> + return handle_cpuid(vcpu);
> + else if (exit_reason == EXIT_REASON_EPT_MISCONFIG)
> + return handle_ept_misconfig(vcpu);
> +#endif
> return kvm_vmx_exit_handlers[exit_reason](vcpu);

Most of these, while frequent, are already part of slow paths.

I would keep only EXIT_REASON_MSR_WRITE, EXIT_REASON_PREEMPTION_TIMER,
EXIT_REASON_EPT_MISCONFIG and add EXIT_REASON_IO_INSTRUCTION.

If you make kvm_vmx_exit_handlers const, can the compiler substitute for
instance kvm_vmx_exit_handlers[EXIT_REASON_MSR_WRITE] with handle_wrmsr?
Just thinking out loud, not sure if it's an improvement code-wise.

Paolo

Paolo