• Like Xu's avatar
    perf/x86: Keep LBR records unchanged in host context for guest usage · e1ad1ac2
    Like Xu authored
    When a guest wants to use the LBR registers, its hypervisor creates a guest
    LBR event and let host perf schedules it. The LBR records msrs are
    accessible to the guest when its guest LBR event is scheduled on
    by the perf subsystem.
    
    Before scheduling this event out, we should avoid host changes on
    IA32_DEBUGCTLMSR or LBR_SELECT. Otherwise, some unexpected branch
    operations may interfere with guest behavior, pollute LBR records, and even
    cause host branches leakage. In addition, the read operation
    on host is also avoidable.
    
    To ensure that guest LBR records are not lost during the context switch,
    the guest LBR event would enable the callstack mode which could
    save/restore guest unread LBR records with the help of
    intel_pmu_lbr_sched_task() naturally.
    
    However, the guest LBR_SELECT may changes for its own use and the host
    LBR event doesn't save/restore it. To ensure that we doesn't lost the guest
    LBR_SELECT value when the guest LBR event is running, the vlbr_constraint
    is bound up with a new constraint flag PERF_X86_EVENT_LBR_SELECT.
    Signed-off-by: default avatarLike Xu <like.xu@linux.intel.com>
    Signed-off-by: default avatarWei Wang <wei.w.wang@intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20200514083054.62538-6-like.xu@linux.intel.com
    e1ad1ac2
lbr.c 35.1 KB