• Alexey Kardashevskiy's avatar
    x86/amd: Cache debug register values in percpu variables · 79146957
    Alexey Kardashevskiy authored
    Reading DR[0-3]_ADDR_MASK MSRs takes about 250 cycles which is going to
    be noticeable with the AMD KVM SEV-ES DebugSwap feature enabled.  KVM is
    going to store host's DR[0-3] and DR[0-3]_ADDR_MASK before switching to
    a guest; the hardware is going to swap these on VMRUN and VMEXIT.
    
    Store MSR values passed to set_dr_addr_mask() in percpu variables
    (when changed) and return them via new amd_get_dr_addr_mask().
    The gain here is about 10x.
    
    As set_dr_addr_mask() uses the array too, change the @dr type to
    unsigned to avoid checking for <0. And give it the amd_ prefix to match
    the new helper as the whole DR_ADDR_MASK feature is AMD-specific anyway.
    
    While at it, replace deprecated boot_cpu_has() with cpu_feature_enabled()
    in set_dr_addr_mask().
    Signed-off-by: default avatarAlexey Kardashevskiy <aik@amd.com>
    Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20230120031047.628097-2-aik@amd.com
    79146957
amd.c 31 KB