• Nicholas Piggin's avatar
    KVM: PPC: Book3S HV P9: Stop handling hcalls in real-mode in the P9 path · 9dc2babc
    Nicholas Piggin authored
    In the interest of minimising the amount of code that is run in
    "real-mode", don't handle hcalls in real mode in the P9 path. This
    requires some new handlers for H_CEDE and xics-on-xive to be added
    before xive is pulled or cede logic is checked.
    
    This introduces a change in radix guest behaviour where radix guests
    that execute 'sc 1' in userspace now get a privilege fault whereas
    previously the 'sc 1' would be reflected as a syscall interrupt to the
    guest kernel. That reflection is only required for hash guests that run
    PR KVM.
    
    Background:
    
    In POWER8 and earlier processors, it is very expensive to exit from the
    HV real mode context of a guest hypervisor interrupt, and switch to host
    virtual mode. On those processors, guest->HV interrupts reach the
    hypervisor with the MMU off because the MMU is loaded with guest context
    (LPCR, SDR1, SLB), and the other threads in the sub-core need to be
    pulled out of the guest too. Then the primary must save off guest state,
    invalidate SLB and ERAT, and load up host state before the MMU can be
    enabled to run in host virtual mode (~= regular Linux mode).
    
    Hash guests also require a lot of hcalls to run due to the nature of the
    MMU architecture and paravirtualisation design. The XICS interrupt
    controller requires hcalls to run.
    
    So KVM traditionally tries hard to avoid the full exit, by handling
    hcalls and other interrupts in real mode as much as possible.
    
    By contrast, POWER9 has independent MMU context per-thread, and in radix
    mode the hypervisor is in host virtual memory mode when the HV interrupt
    is taken. Radix guests do not require significant hcalls to manage their
    translations, and xive guests don't need hcalls to handle interrupts. So
    it's much less important for performance to handle hcalls in real mode on
    POWER9.
    
    One caveat is that the TCE hcalls are performance critical, real-mode
    variants introduced for POWER8 in order to achieve 10GbE performance.
    Real mode TCE hcalls were found to be less important on POWER9, which
    was able to drive 40GBe networking without them (using the virt mode
    hcalls) but performance is still important. These hcalls will benefit
    from subsequent guest entry/exit optimisation including possibly a
    faster "partial exit" that does not entirely switch to host context to
    handle the hcall.
    Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
    Reviewed-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
    Reviewed-by: default avatarCédric Le Goater <clg@kaod.org>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/20210528090752.3542186-14-npiggin@gmail.com
    9dc2babc
kvm_ppc.h 36.2 KB