lkml.org 
[lkml]   [2021]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v6 12/12] KVM: x86/cpuid: Advise Arch LBR feature in CPUID
    Date
    Add Arch LBR feature bit in CPU cap-mask to expose the feature.
    Currently only max LBR depth is available for guest, and it's
    consistent with host Arch LBR settings.

    Co-developed-by: Like Xu <like.xu@linux.intel.com>
    Signed-off-by: Like Xu <like.xu@linux.intel.com>
    Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
    ---
    arch/x86/kvm/cpuid.c | 33 ++++++++++++++++++++++++++++++++-
    1 file changed, 32 insertions(+), 1 deletion(-)

    diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
    index d6e343809b25..9b80d265c4c4 100644
    --- a/arch/x86/kvm/cpuid.c
    +++ b/arch/x86/kvm/cpuid.c
    @@ -202,6 +202,16 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
    best->ecx |= XFEATURE_MASK_FPSSE;
    }

    + best = kvm_find_cpuid_entry(vcpu, 0x1c, 0);
    + if (best) {
    + unsigned int eax, ebx, ecx, edx;
    +
    + /* Make sure guest only sees the supported arch lbr depth. */
    + cpuid_count(0x1c, 0, &eax, &ebx, &ecx, &edx);
    + best->eax &= ~0xff;
    + best->eax |= BIT(fls(eax & 0xff) - 1);
    + }
    +
    kvm_update_pv_runtime(vcpu);

    vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
    @@ -490,7 +500,7 @@ void kvm_set_cpu_caps(void)
    F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
    F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES) | F(INTEL_STIBP) |
    F(MD_CLEAR) | F(AVX512_VP2INTERSECT) | F(FSRM) |
    - F(SERIALIZE) | F(TSXLDTRK) | F(AVX512_FP16)
    + F(SERIALIZE) | F(TSXLDTRK) | F(AVX512_FP16) | F(ARCH_LBR)
    );

    /* TSC_ADJUST and ARCH_CAPABILITIES are emulated in software. */
    @@ -902,6 +912,27 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
    goto out;
    }
    break;
    + /* Architectural LBR */
    + case 0x1c: {
    + u32 lbr_depth_mask = entry->eax & 0xff;
    +
    + if (!lbr_depth_mask ||
    + !kvm_cpu_cap_has(X86_FEATURE_ARCH_LBR)) {
    + entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
    + break;
    + }
    + /*
    + * KVM only exposes the maximum supported depth, which is the
    + * fixed value used on the host side.
    + * KVM doesn't allow VMM userspace to adjust LBR depth because
    + * guest LBR emulation depends on the configuration of host LBR
    + * driver.
    + */
    + lbr_depth_mask = BIT((fls(lbr_depth_mask) - 1));
    + entry->eax &= ~0xff;
    + entry->eax |= lbr_depth_mask;
    + break;
    + }
    case KVM_CPUID_SIGNATURE: {
    static const char signature[12] = "KVMKVMKVM\0\0";
    const u32 *sigptr = (const u32 *)signature;
    --
    2.21.1
    \
     
     \ /
      Last update: 2021-07-16 10:38    [W:3.357 / U:0.240 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site