1. 29 11月, 2022 4 次提交
    • C
      x86: KVM: Advertise AMX-FP16 CPUID to user space · af2872f6
      Chang S. Bae 提交于
      Latest Intel platform Granite Rapids has introduced a new instruction -
      AMX-FP16, which performs dot-products of two FP16 tiles and accumulates
      the results into a packed single precision tile. AMX-FP16 adds FP16
      capability and also allows a FP16 GPU trained model to run faster
      without loss of accuracy or added SW overhead.
      
      The bit definition:
      CPUID.(EAX=7,ECX=1):EAX[bit 21]
      
      AMX-FP16 is on an expected-dense CPUID leaf and some other bits on this
      leaf have kernel usages. Given that, define this feature bit like
      X86_FEATURE_<name> in kernel. Considering AMX-FP16 itself has no truly
      kernel usages and /proc/cpuinfo has too much unreadable flags, hide this
      one in /proc/cpuinfo.
      
      Advertise AMX-FP16 to KVM userspace. This is safe because there are no
      new VMX controls or additional host enabling required for guests to use
      this feature.
      Signed-off-by: NChang S. Bae <chang.seok.bae@intel.com>
      Signed-off-by: NJiaxi Chen <jiaxi.chen@linux.intel.com>
      Acked-by: NBorislav Petkov <bp@suse.de>
      Message-Id: <20221125125845.1182922-5-jiaxi.chen@linux.intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      af2872f6
    • J
      x86: KVM: Advertise CMPccXADD CPUID to user space · 6a19d7aa
      Jiaxi Chen 提交于
      CMPccXADD is a new set of instructions in the latest Intel platform
      Sierra Forest. This new instruction set includes a semaphore operation
      that can compare and add the operands if condition is met, which can
      improve database performance.
      
      The bit definition:
      CPUID.(EAX=7,ECX=1):EAX[bit 7]
      
      CMPccXADD is on an expected-dense CPUID leaf and some other bits on this
      leaf have kernel usages. Given that, define this feature bit like
      X86_FEATURE_<name> in kernel. Considering CMPccXADD itself has no truly
      kernel usages and /proc/cpuinfo has too much unreadable flags, hide this
      one in /proc/cpuinfo.
      
      Advertise CMPCCXADD to KVM userspace. This is safe because there are no
      new VMX controls or additional host enabling required for guests to use
      this feature.
      Signed-off-by: NJiaxi Chen <jiaxi.chen@linux.intel.com>
      Acked-by: NBorislav Petkov <bp@suse.de>
      Message-Id: <20221125125845.1182922-4-jiaxi.chen@linux.intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      6a19d7aa
    • S
      KVM: x86: Update KVM-only leaf handling to allow for 100% KVM-only leafs · 047c7229
      Sean Christopherson 提交于
      Rename kvm_cpu_cap_init_scattered() to kvm_cpu_cap_init_kvm_defined() in
      anticipation of adding KVM-only CPUID leafs that aren't recognized by the
      kernel and thus not scattered, i.e. for leafs that are 100% KVM-defined.
      
      Adjust/add comments to kvm_only_cpuid_leafs and KVM_X86_FEATURE to
      document how to create new kvm_only_cpuid_leafs entries for scattered
      features as well as features that are entirely unknown to the kernel.
      
      No functional change intended.
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20221125125845.1182922-3-jiaxi.chen@linux.intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      047c7229
    • S
      KVM: x86: Add BUILD_BUG_ON() to detect bad usage of "scattered" flags · c4690d01
      Sean Christopherson 提交于
      Add a compile-time assert in the SF() macro to detect improper usage,
      i.e. to detect passing in an X86_FEATURE_* flag that isn't actually
      scattered by the kernel.  Upcoming feature flags will be 100% KVM-only
      and will have X86_FEATURE_* macros that point at a kvm_only_cpuid_leafs
      word, not a kernel-defined word.  Using SF() and thus boot_cpu_has() for
      such feature flags would access memory beyond x86_capability[NCAPINTS]
      and at best incorrectly hide a feature, and at worst leak kernel state to
      userspace.
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20221125125845.1182922-2-jiaxi.chen@linux.intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c4690d01
  2. 10 11月, 2022 1 次提交
  3. 03 11月, 2022 1 次提交
  4. 27 10月, 2022 1 次提交
  5. 22 10月, 2022 4 次提交
  6. 30 9月, 2022 1 次提交
  7. 27 9月, 2022 1 次提交
  8. 23 9月, 2022 2 次提交
    • D
      KVM: x86: Always enable legacy FP/SSE in allowed user XFEATURES · a1020a25
      Dr. David Alan Gilbert 提交于
      Allow FP and SSE state to be saved and restored via KVM_{G,SET}_XSAVE on
      XSAVE-capable hosts even if their bits are not exposed to the guest via
      XCR0.
      
      Failing to allow FP+SSE first showed up as a QEMU live migration failure,
      where migrating a VM from a pre-XSAVE host, e.g. Nehalem, to an XSAVE
      host failed due to KVM rejecting KVM_SET_XSAVE.  However, the bug also
      causes problems even when migrating between XSAVE-capable hosts as
      KVM_GET_SAVE won't set any bits in user_xfeatures if XSAVE isn't exposed
      to the guest, i.e. KVM will fail to actually migrate FP+SSE.
      
      Because KVM_{G,S}ET_XSAVE are designed to allowing migrating between
      hosts with and without XSAVE, KVM_GET_XSAVE on a non-XSAVE (by way of
      fpu_copy_guest_fpstate_to_uabi()) always sets the FP+SSE bits in the
      header so that KVM_SET_XSAVE will work even if the new host supports
      XSAVE.
      
      Fixes: ad856280 ("x86/kvm/fpu: Limit guest user_xfeatures to supported bits of XCR0")
      bz: https://bugzilla.redhat.com/show_bug.cgi?id=2079311
      Cc: stable@vger.kernel.org
      Cc: Leonardo Bras <leobras@redhat.com>
      Signed-off-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
      [sean: add comment, massage changelog]
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20220824033057.3576315-3-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      a1020a25
    • S
      KVM: x86: Reinstate kvm_vcpu_arch.guest_supported_xcr0 · ee519b3a
      Sean Christopherson 提交于
      Reinstate the per-vCPU guest_supported_xcr0 by partially reverting
      commit 988896bb; the implicit assessment that guest_supported_xcr0 is
      always the same as guest_fpu.fpstate->user_xfeatures was incorrect.
      
      kvm_vcpu_after_set_cpuid() isn't the only place that sets user_xfeatures,
      as user_xfeatures is set to fpu_user_cfg.default_features when guest_fpu
      is allocated via fpu_alloc_guest_fpstate() => __fpstate_reset().
      guest_supported_xcr0 on the other hand is zero-allocated.  If userspace
      never invokes KVM_SET_CPUID2, supported XCR0 will be '0', whereas the
      allowed user XFEATURES will be non-zero.
      
      Practically speaking, the edge case likely doesn't matter as no sane
      userspace will live migrate a VM without ever doing KVM_SET_CPUID2. The
      primary motivation is to prepare for KVM intentionally and explicitly
      setting bits in user_xfeatures that are not set in guest_supported_xcr0.
      
      Because KVM_{G,S}ET_XSAVE can be used to svae/restore FP+SSE state even
      if the host doesn't support XSAVE, KVM needs to set the FP+SSE bits in
      user_xfeatures even if they're not allowed in XCR0, e.g. because XCR0
      isn't exposed to the guest.  At that point, the simplest fix is to track
      the two things separately (allowed save/restore vs. allowed XCR0).
      
      Fixes: 988896bb ("x86/kvm/fpu: Remove kvm_vcpu_arch.guest_supported_xcr0")
      Cc: stable@vger.kernel.org
      Cc: Leonardo Bras <leobras@redhat.com>
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20220824033057.3576315-2-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ee519b3a
  9. 14 7月, 2022 1 次提交
  10. 08 6月, 2022 2 次提交
  11. 03 5月, 2022 1 次提交
    • S
      kvm: x86/cpuid: Only provide CPUID leaf 0xA if host has architectural PMU · 5a1bde46
      Sandipan Das 提交于
      On some x86 processors, CPUID leaf 0xA provides information
      on Architectural Performance Monitoring features. It
      advertises a PMU version which Qemu uses to determine the
      availability of additional MSRs to manage the PMCs.
      
      Upon receiving a KVM_GET_SUPPORTED_CPUID ioctl request for
      the same, the kernel constructs return values based on the
      x86_pmu_capability irrespective of the vendor.
      
      This leaf and the additional MSRs are not supported on AMD
      and Hygon processors. If AMD PerfMonV2 is detected, the PMU
      version is set to 2 and guest startup breaks because of an
      attempt to access a non-existent MSR. Return zeros to avoid
      this.
      
      Fixes: a6c06ed1 ("KVM: Expose the architectural performance monitoring CPUID leaf")
      Reported-by: NVasant Hegde <vasant.hegde@amd.com>
      Signed-off-by: NSandipan Das <sandipan.das@amd.com>
      Message-Id: <3fef83d9c2b2f7516e8ff50d60851f29a4bcb716.1651058600.git.sandipan.das@amd.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      5a1bde46
  12. 30 4月, 2022 1 次提交
    • P
      KVM: x86: work around QEMU issue with synthetic CPUID leaves · f751d8ea
      Paolo Bonzini 提交于
      Synthesizing AMD leaves up to 0x80000021 caused problems with QEMU,
      which assumes the *host* CPUID[0x80000000].EAX is higher or equal
      to what KVM_GET_SUPPORTED_CPUID reports.
      
      This causes QEMU to issue bogus host CPUIDs when preparing the input
      to KVM_SET_CPUID2.  It can even get into an infinite loop, which is
      only terminated by an abort():
      
         cpuid_data is full, no space for cpuid(eax:0x8000001d,ecx:0x3e)
      
      To work around this, only synthesize those leaves if 0x8000001d exists
      on the host.  The synthetic 0x80000021 leaf is mostly useful on Zen2,
      which satisfies the condition.
      
      Fixes: f144c49e ("KVM: x86: synthesize CPUID leaf 0x80000021h if useful")
      Reported-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f751d8ea
  13. 07 4月, 2022 1 次提交
  14. 30 3月, 2022 1 次提交
    • N
      KVM: x86: Fix clang -Wimplicit-fallthrough in do_host_cpuid() · 07ea4ab1
      Nathan Chancellor 提交于
      Clang warns:
      
        arch/x86/kvm/cpuid.c:739:2: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
                default:
                ^
        arch/x86/kvm/cpuid.c:739:2: note: insert 'break;' to avoid fall-through
                default:
                ^
                break;
        1 error generated.
      
      Clang is a little more pedantic than GCC, which does not warn when
      falling through to a case that is just break or return. Clang's version
      is more in line with the kernel's own stance in deprecated.rst, which
      states that all switch/case blocks must end in either break,
      fallthrough, continue, goto, or return. Add the missing break to silence
      the warning.
      
      Fixes: f144c49e ("KVM: x86: synthesize CPUID leaf 0x80000021h if useful")
      Reported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NNathan Chancellor <nathan@kernel.org>
      Message-Id: <20220322152906.112164-1-nathan@kernel.org>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      07ea4ab1
  15. 21 3月, 2022 3 次提交
  16. 17 2月, 2022 2 次提交
    • L
      x86/kvm/fpu: Remove kvm_vcpu_arch.guest_supported_xcr0 · 988896bb
      Leonardo Bras 提交于
      kvm_vcpu_arch currently contains the guest supported features in both
      guest_supported_xcr0 and guest_fpu.fpstate->user_xfeatures field.
      
      Currently both fields are set to the same value in
      kvm_vcpu_after_set_cpuid() and are not changed anywhere else after that.
      
      Since it's not good to keep duplicated data, remove guest_supported_xcr0.
      
      To keep the code more readable, introduce kvm_guest_supported_xcr()
      and kvm_guest_supported_xfd() to replace the previous usages of
      guest_supported_xcr0.
      Signed-off-by: NLeonardo Bras <leobras@redhat.com>
      Message-Id: <20220217053028.96432-3-leobras@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      988896bb
    • L
      x86/kvm/fpu: Limit guest user_xfeatures to supported bits of XCR0 · ad856280
      Leonardo Bras 提交于
      During host/guest switch (like in kvm_arch_vcpu_ioctl_run()), the kernel
      swaps the fpu between host/guest contexts, by using fpu_swap_kvm_fpstate().
      
      When xsave feature is available, the fpu swap is done by:
      - xsave(s) instruction, with guest's fpstate->xfeatures as mask, is used
        to store the current state of the fpu registers to a buffer.
      - xrstor(s) instruction, with (fpu_kernel_cfg.max_features &
        XFEATURE_MASK_FPSTATE) as mask, is used to put the buffer into fpu regs.
      
      For xsave(s) the mask is used to limit what parts of the fpu regs will
      be copied to the buffer. Likewise on xrstor(s), the mask is used to
      limit what parts of the fpu regs will be changed.
      
      The mask for xsave(s), the guest's fpstate->xfeatures, is defined on
      kvm_arch_vcpu_create(), which (in summary) sets it to all features
      supported by the cpu which are enabled on kernel config.
      
      This means that xsave(s) will save to guest buffer all the fpu regs
      contents the cpu has enabled when the guest is paused, even if they
      are not used.
      
      This would not be an issue, if xrstor(s) would also do that.
      
      xrstor(s)'s mask for host/guest swap is basically every valid feature
      contained in kernel config, except XFEATURE_MASK_PKRU.
      Accordingto kernel src, it is instead switched in switch_to() and
      flush_thread().
      
      Then, the following happens with a host supporting PKRU starts a
      guest that does not support it:
      1 - Host has XFEATURE_MASK_PKRU set. 1st switch to guest,
      2 - xsave(s) fpu regs to host fpustate (buffer has XFEATURE_MASK_PKRU)
      3 - xrstor(s) guest fpustate to fpu regs (fpu regs have XFEATURE_MASK_PKRU)
      4 - guest runs, then switch back to host,
      5 - xsave(s) fpu regs to guest fpstate (buffer now have XFEATURE_MASK_PKRU)
      6 - xrstor(s) host fpstate to fpu regs.
      7 - kvm_vcpu_ioctl_x86_get_xsave() copy guest fpstate to userspace (with
          XFEATURE_MASK_PKRU, which should not be supported by guest vcpu)
      
      On 5, even though the guest does not support PKRU, it does have the flag
      set on guest fpstate, which is transferred to userspace via vcpu ioctl
      KVM_GET_XSAVE.
      
      This becomes a problem when the user decides on migrating the above guest
      to another machine that does not support PKRU: the new host restores
      guest's fpu regs to as they were before (xrstor(s)), but since the new
      host don't support PKRU, a general-protection exception ocurs in xrstor(s)
      and that crashes the guest.
      
      This can be solved by making the guest's fpstate->user_xfeatures hold
      a copy of guest_supported_xcr0. This way, on 7 the only flags copied to
      userspace will be the ones compatible to guest requirements, and thus
      there will be no issue during migration.
      
      As a bonus, it will also fail if userspace tries to set fpu features
      (with the KVM_SET_XSAVE ioctl) that are not compatible to the guest
      configuration.  Such features will never be returned by KVM_GET_XSAVE
      or KVM_GET_XSAVE2.
      
      Also, since kvm_vcpu_after_set_cpuid() now sets fpstate->user_xfeatures,
      there is not need to set it in kvm_check_cpuid(). So, change
      fpstate_realloc() so it does not touch fpstate->user_xfeatures if a
      non-NULL guest_fpu is passed, which is the case when kvm_check_cpuid()
      calls it.
      Signed-off-by: NLeonardo Bras <leobras@redhat.com>
      Message-Id: <20220217053028.96432-2-leobras@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ad856280
  17. 11 2月, 2022 1 次提交
  18. 04 2月, 2022 1 次提交
    • J
      KVM: x86: Report deprecated x87 features in supported CPUID · e3bcfda0
      Jim Mattson 提交于
      CPUID.(EAX=7,ECX=0):EBX.FDP_EXCPTN_ONLY[bit 6] and
      CPUID.(EAX=7,ECX=0):EBX.ZERO_FCS_FDS[bit 13] are "defeature"
      bits. Unlike most of the other CPUID feature bits, these bits are
      clear if the features are present and set if the features are not
      present. These bits should be reported in KVM_GET_SUPPORTED_CPUID,
      because if these bits are set on hardware, they cannot be cleared in
      the guest CPUID. Doing so would claim guest support for a feature that
      the hardware doesn't support and that can't be efficiently emulated.
      
      Of course, any software (e.g WIN87EM.DLL) expecting these features to
      be present likely predates these CPUID feature bits and therefore
      doesn't know to check for them anyway.
      
      Aaron Lewis added the corresponding X86_FEATURE macros in
      commit cbb99c0f ("x86/cpufeatures: Add FDP_EXCPTN_ONLY and
      ZERO_FCS_FDS"), with the intention of reporting these bits in
      KVM_GET_SUPPORTED_CPUID, but I was unable to find a proposed patch on
      the kvm list.
      
      Opportunistically reordered the CPUID_7_0_EBX capability bits from
      least to most significant.
      
      Cc: Aaron Lewis <aaronlewis@google.com>
      Signed-off-by: NJim Mattson <jmattson@google.com>
      Message-Id: <20220204001348.2844660-1-jmattson@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e3bcfda0
  19. 02 2月, 2022 1 次提交
  20. 27 1月, 2022 3 次提交
    • S
      KVM: x86: Free kvm_cpuid_entry2 array on post-KVM_RUN KVM_SET_CPUID{,2} · 811f95ff
      Sean Christopherson 提交于
      Free the "struct kvm_cpuid_entry2" array on successful post-KVM_RUN
      KVM_SET_CPUID{,2} to fix a memory leak, the callers of kvm_set_cpuid()
      free the array only on failure.
      
       BUG: memory leak
       unreferenced object 0xffff88810963a800 (size 2048):
        comm "syz-executor025", pid 3610, jiffies 4294944928 (age 8.080s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00  ................
          47 65 6e 75 6e 74 65 6c 69 6e 65 49 00 00 00 00  GenuntelineI....
        backtrace:
          [<ffffffff814948ee>] kmalloc_node include/linux/slab.h:604 [inline]
          [<ffffffff814948ee>] kvmalloc_node+0x3e/0x100 mm/util.c:580
          [<ffffffff814950f2>] kvmalloc include/linux/slab.h:732 [inline]
          [<ffffffff814950f2>] vmemdup_user+0x22/0x100 mm/util.c:199
          [<ffffffff8109f5ff>] kvm_vcpu_ioctl_set_cpuid2+0x8f/0xf0 arch/x86/kvm/cpuid.c:423
          [<ffffffff810711b9>] kvm_arch_vcpu_ioctl+0xb99/0x1e60 arch/x86/kvm/x86.c:5251
          [<ffffffff8103e92d>] kvm_vcpu_ioctl+0x4ad/0x950 arch/x86/kvm/../../../virt/kvm/kvm_main.c:4066
          [<ffffffff815afacc>] vfs_ioctl fs/ioctl.c:51 [inline]
          [<ffffffff815afacc>] __do_sys_ioctl fs/ioctl.c:874 [inline]
          [<ffffffff815afacc>] __se_sys_ioctl fs/ioctl.c:860 [inline]
          [<ffffffff815afacc>] __x64_sys_ioctl+0xfc/0x140 fs/ioctl.c:860
          [<ffffffff844a3335>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
          [<ffffffff844a3335>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
          [<ffffffff84600068>] entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      Fixes: c6617c61 ("KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN")
      Cc: stable@vger.kernel.org
      Reported-by: syzbot+be576ad7655690586eec@syzkaller.appspotmail.com
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20220125210445.2053429-1-seanjc@google.com>
      Reviewed-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      811f95ff
    • V
      KVM: x86: Check .flags in kvm_cpuid_check_equal() too · 033a3ea5
      Vitaly Kuznetsov 提交于
      kvm_cpuid_check_equal() checks for the (full) equality of the supplied
      CPUID data so .flags need to be checked too.
      Reported-by: NSean Christopherson <seanjc@google.com>
      Fixes: c6617c61 ("KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN")
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20220126131804.2839410-1-vkuznets@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      033a3ea5
    • L
      KVM: x86/cpuid: Exclude unpermitted xfeatures sizes at KVM_GET_SUPPORTED_CPUID · 1ffce092
      Like Xu 提交于
      With the help of xstate_get_guest_group_perm(), KVM can exclude unpermitted
      xfeatures in cpuid.0xd.0.eax, in which case the corresponding xfeatures
      sizes should also be matched to the permitted xfeatures.
      
      To fix this inconsistency, the permitted_xcr0 and permitted_xss are defined
      consistently, which implies 'supported' plus certain permissions for this
      task, and it also fixes cpuid.0xd.1.ebx and later leaf-by-leaf queries.
      
      Fixes: 445ecdf7 ("kvm: x86: Exclude unpermitted xfeatures at KVM_GET_SUPPORTED_CPUID")
      Signed-off-by: NLike Xu <likexu@tencent.com>
      Message-Id: <20220125115223.33707-1-likexu@tencent.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      1ffce092
  21. 25 1月, 2022 1 次提交
  22. 20 1月, 2022 1 次提交
    • L
      KVM: x86/cpuid: Clear XFD for component i if the base feature is missing · e9737468
      Like Xu 提交于
      According to Intel extended feature disable (XFD) spec, the sub-function i
      (i > 1) of CPUID function 0DH enumerates "details for state component i.
      ECX[2] enumerates support for XFD support for this state component."
      
      If KVM does not report F(XFD) feature (e.g. due to CONFIG_X86_64),
      then the corresponding XFD support for any state component i
      should also be removed. Translate this dependency into KVM terms.
      
      Fixes: 690a757d ("kvm: x86: Add CPUID support for Intel AMX")
      Signed-off-by: NLike Xu <likexu@tencent.com>
      Message-Id: <20220117074531.76925-1-likexu@tencent.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e9737468
  23. 18 1月, 2022 3 次提交
    • L
      KVM: x86: Making the module parameter of vPMU more common · 4732f244
      Like Xu 提交于
      The new module parameter to control PMU virtualization should apply
      to Intel as well as AMD, for situations where userspace is not trusted.
      If the module parameter allows PMU virtualization, there could be a
      new KVM_CAP or guest CPUID bits whereby userspace can enable/disable
      PMU virtualization on a per-VM basis.
      
      If the module parameter does not allow PMU virtualization, there
      should be no userspace override, since we have no precedent for
      authorizing that kind of override. If it's false, other counter-based
      profiling features (such as LBR including the associated CPUID bits
      if any) will not be exposed.
      
      Change its name from "pmu" to "enable_pmu" as we have temporary
      variables with the same name in our code like "struct kvm_pmu *pmu".
      
      Fixes: b1d66dad ("KVM: x86/svm: Add module param to control PMU virtualization")
      Suggested-by : Jim Mattson <jmattson@google.com>
      Signed-off-by: NLike Xu <likexu@tencent.com>
      Message-Id: <20220111073823.21885-1-likexu@tencent.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      4732f244
    • V
      KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN · c6617c61
      Vitaly Kuznetsov 提交于
      Commit feb627e8 ("KVM: x86: Forbid KVM_SET_CPUID{,2} after KVM_RUN")
      forbade changing CPUID altogether but unfortunately this is not fully
      compatible with existing VMMs. In particular, QEMU reuses vCPU fds for
      CPU hotplug after unplug and it calls KVM_SET_CPUID2. Instead of full ban,
      check whether the supplied CPUID data is equal to what was previously set.
      Reported-by: NIgor Mammedov <imammedo@redhat.com>
      Fixes: feb627e8 ("KVM: x86: Forbid KVM_SET_CPUID{,2} after KVM_RUN")
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20220117150542.2176196-3-vkuznets@redhat.com>
      Cc: stable@vger.kernel.org
      [Do not call kvm_find_cpuid_entry repeatedly. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c6617c61
    • V
      KVM: x86: Do runtime CPUID update before updating vcpu->arch.cpuid_entries · ee3a5f9e
      Vitaly Kuznetsov 提交于
      kvm_update_cpuid_runtime() mangles CPUID data coming from userspace
      VMM after updating 'vcpu->arch.cpuid_entries', this makes it
      impossible to compare an update with what was previously
      supplied. Introduce __kvm_update_cpuid_runtime() version which can be
      used to tweak the input before it goes to 'vcpu->arch.cpuid_entries'
      so the upcoming update check can compare tweaked data.
      
      No functional change intended.
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20220117150542.2176196-2-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ee3a5f9e
  24. 15 1月, 2022 2 次提交