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

Sean Christopherson
2019-09-23T18:16:01Z

On Mon, Sep 23, 2019 at 01:42:44PM -0400, Andrea Arcangeli wrote:
> On Mon, Sep 23, 2019 at 06:53:10PM +0200, Paolo Bonzini wrote:
> > On 23/09/19 18:37, Sean Christopherson wrote:
> > >> Would it be too much if we get rid of
> > >> kvm_vmx_exit_handlers completely replacing this code with one switch()?
> > > Hmm, that'd require redirects for nVMX functions since they are set at
> > > runtime. That isn't necessarily a bad thing. The approach could also be
> > > used if Paolo's idea of making kvm_vmx_max_exit_handlers const allows the
> > > compiler to avoid retpoline.
> >
> > But aren't switch statements also retpolin-ized if they use a jump table?
>
> See commit a9d57ef15cbe327fe54416dd194ee0ea66ae53a4.
>
> We disabled that feature or the kernel would potentially suffer the
> downsides of the exit handlers through pointer to functions for every
> switch statement in the kernel.
>
> In turn you can't make it run any faster by converting my "if" to a
> "switch" at least the "if" can deterministic control the order of what
> is more likely that we should also re-review, but the order of secondary
> effect, the important thing is to reduce the retpolines to zero during
> normal hrtimer guest runtime.

On the flip side, using a switch for the fast-path handlers gives the
compiler more flexibility to rearrange and combine checks. Of course that
doesn't mean the compiler will actually generate faster code for our
purposes :-)

Anyways, getting rid of the retpolines is much more important.