1. 20 4月, 2021 4 次提交
  2. 17 4月, 2021 2 次提交
  3. 15 3月, 2021 8 次提交
  4. 06 3月, 2021 1 次提交
  5. 03 3月, 2021 2 次提交
  6. 26 2月, 2021 1 次提交
  7. 19 2月, 2021 5 次提交
  8. 17 2月, 2021 1 次提交
  9. 09 2月, 2021 9 次提交
    • V
      KVM: x86: hyper-v: Allocate Hyper-V context lazily · fc08b628
      Vitaly Kuznetsov 提交于
      Hyper-V context is only needed for guests which use Hyper-V emulation in
      KVM (e.g. Windows/Hyper-V guests) so we don't actually need to allocate
      it in kvm_arch_vcpu_create(), we can postpone the action until Hyper-V
      specific MSRs are accessed or SynIC is enabled.
      
      Once allocated, let's keep the context alive for the lifetime of the vCPU
      as an attempt to free it would require additional synchronization with
      other vCPUs and normally it is not supposed to happen.
      
      Note, Hyper-V style hypercall enablement is done by writing to
      HV_X64_MSR_GUEST_OS_ID so we don't need to worry about allocating Hyper-V
      context from kvm_hv_hypercall().
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-15-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      fc08b628
    • V
      KVM: x86: hyper-v: Make Hyper-V emulation enablement conditional · 8f014550
      Vitaly Kuznetsov 提交于
      Hyper-V emulation is enabled in KVM unconditionally. This is bad at least
      from security standpoint as it is an extra attack surface. Ideally, there
      should be a per-VM capability explicitly enabled by VMM but currently it
      is not the case and we can't mandate one without breaking backwards
      compatibility. We can, however, check guest visible CPUIDs and only enable
      Hyper-V emulation when "Hv#1" interface was exposed in
      HYPERV_CPUID_INTERFACE.
      
      Note, VMMs are free to act in any sequence they like, e.g. they can try
      to set MSRs first and CPUIDs later so we still need to allow the host
      to read/write Hyper-V specific MSRs unconditionally.
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-14-vkuznets@redhat.com>
      [Add selftest vcpu_set_hv_cpuid API to avoid breaking xen_vmcall_test. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      8f014550
    • V
      KVM: x86: hyper-v: Allocate 'struct kvm_vcpu_hv' dynamically · 4592b7ea
      Vitaly Kuznetsov 提交于
      Hyper-V context is only needed for guests which use Hyper-V emulation in
      KVM (e.g. Windows/Hyper-V guests). 'struct kvm_vcpu_hv' is, however, quite
      big, it accounts for more than 1/4 of the total 'struct kvm_vcpu_arch'
      which is also quite big already. This all looks like a waste.
      
      Allocate 'struct kvm_vcpu_hv' dynamically. This patch does not bring any
      (intentional) functional change as we still allocate the context
      unconditionally but it paves the way to doing that only when needed.
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-13-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      4592b7ea
    • V
      KVM: x86: hyper-v: Prepare to meet unallocated Hyper-V context · f2bc14b6
      Vitaly Kuznetsov 提交于
      Currently, Hyper-V context is part of 'struct kvm_vcpu_arch' and is always
      available. As a preparation to allocating it dynamically, check that it is
      not NULL at call sites which can normally proceed without it i.e. the
      behavior is identical to the situation when Hyper-V emulation is not being
      used by the guest.
      
      When Hyper-V context for a particular vCPU is not allocated, we may still
      need to get 'vp_index' from there. E.g. in a hypothetical situation when
      Hyper-V emulation was enabled on one CPU and wasn't on another, Hyper-V
      style send-IPI hypercall may still be used. Luckily, vp_index is always
      initialized to kvm_vcpu_get_idx() and can only be changed when Hyper-V
      context is present. Introduce kvm_hv_get_vpindex() helper for
      simplification.
      
      No functional change intended.
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-12-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f2bc14b6
    • V
      KVM: x86: hyper-v: Always use to_hv_vcpu() accessor to get to 'struct kvm_vcpu_hv' · 9ff5e030
      Vitaly Kuznetsov 提交于
      As a preparation to allocating Hyper-V context dynamically, make it clear
      who's the user of the said context.
      
      No functional change intended.
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-11-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      9ff5e030
    • V
      KVM: x86: hyper-v: Introduce to_kvm_hv() helper · 05f04ae4
      Vitaly Kuznetsov 提交于
      Spelling '&kvm->arch.hyperv' correctly is hard. Also, this makes the code
      more consistent with vmx/svm where to_kvm_vmx()/to_kvm_svm() are already
      being used.
      
      Opportunistically change kvm_hv_msr_{get,set}_crash_{data,ctl}() and
      kvm_hv_msr_set_crash_data() to take 'kvm' instead of 'vcpu' as these
      MSRs are partition wide.
      
      No functional change intended.
      Suggested-by: NSean Christopherson <seanjc@google.com>
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-9-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      05f04ae4
    • V
      KVM: x86: hyper-v: Rename vcpu_to_synic()/synic_to_vcpu() · e0121fa2
      Vitaly Kuznetsov 提交于
      vcpu_to_synic()'s argument is almost always 'vcpu' so there's no need to
      have an additional prefix. Also, as this is used outside of hyper-v
      emulation code, add '_hv_' part to make it clear what this s. This makes
      the naming more consistent with to_hv_vcpu().
      
      Rename synic_to_vcpu() to hv_synic_to_vcpu() for consistency.
      
      No functional change intended.
      Suggested-by: NSean Christopherson <seanjc@google.com>
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20210126134816.1880136-6-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e0121fa2
    • P
      KVM: x86: move kvm_inject_gp up from kvm_set_dr to callers · 996ff542
      Paolo Bonzini 提交于
      Push the injection of #GP up to the callers, so that they can just use
      kvm_complete_insn_gp. __kvm_set_dr is pretty much what the callers can use
      together with kvm_complete_insn_gp, so rename it to kvm_set_dr and drop
      the old kvm_set_dr wrapper.
      
      This also allows nested VMX code, which really wanted to use __kvm_set_dr,
      to use the right function.
      
      While at it, remove the kvm_require_dr() check from the SVM interception.
      The APM states:
      
        All normal exception checks take precedence over the SVM intercepts.
      
      which includes the CR4.DE=1 #UD.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      996ff542
    • P
      KVM: x86: reading DR cannot fail · 29d6ca41
      Paolo Bonzini 提交于
      kvm_get_dr and emulator_get_dr except an in-range value for the register
      number so they cannot fail.  Change the return type to void.
      Suggested-by: NSean Christopherson <seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      29d6ca41
  10. 05 2月, 2021 1 次提交
  11. 04 2月, 2021 6 次提交
    • S
      KVM: x86: Add helper to consolidate "raw" reserved GPA mask calculations · a8ac864a
      Sean Christopherson 提交于
      Add a helper to generate the mask of reserved GPA bits _without_ any
      adjustments for repurposed bits, and use it to replace a variety of
      open coded variants in the MTRR and APIC_BASE flows.
      
      No functional change intended.
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20210204000117.3303214-11-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      a8ac864a
    • S
      KVM: x86: Use reserved_gpa_bits to calculate reserved PxE bits · 5b7f575c
      Sean Christopherson 提交于
      Use reserved_gpa_bits, which accounts for exceptions to the maxphyaddr
      rule, e.g. SEV's C-bit, for the page {table,directory,etc...} entry (PxE)
      reserved bits checks.  For SEV, the C-bit is ignored by hardware when
      walking pages tables, e.g. the APM states:
      
        Note that while the guest may choose to set the C-bit explicitly on
        instruction pages and page table addresses, the value of this bit is a
        don't-care in such situations as hardware always performs these as
        private accesses.
      
      Such behavior is expected to hold true for other features that repurpose
      GPA bits, e.g. KVM could theoretically emulate SME or MKTME, which both
      allow non-zero repurposed bits in the page tables.  Conceptually, KVM
      should apply reserved GPA checks universally, and any features that do
      not adhere to the basic rule should be explicitly handled, i.e. if a GPA
      bit is repurposed but not allowed in page tables for whatever reason.
      
      Refactor __reset_rsvds_bits_mask() to take the pre-generated reserved
      bits mask, and opportunistically clean up its code, e.g. to align lines
      and comments.
      
      Practically speaking, this is change is a likely a glorified nop given
      the current KVM code base.  SEV's C-bit is the only repurposed GPA bit,
      and KVM doesn't support shadowing encrypted page tables (which is
      theoretically possible via SEV debug APIs).
      
      Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20210204000117.3303214-9-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      5b7f575c
    • S
      KVM: x86: SEV: Treat C-bit as legal GPA bit regardless of vCPU mode · ca29e145
      Sean Christopherson 提交于
      Rename cr3_lm_rsvd_bits to reserved_gpa_bits, and use it for all GPA
      legality checks.  AMD's APM states:
      
        If the C-bit is an address bit, this bit is masked from the guest
        physical address when it is translated through the nested page tables.
      
      Thus, any access that can conceivably be run through NPT should ignore
      the C-bit when checking for validity.
      
      For features that KVM emulates in software, e.g. MTRRs, there is no
      clear direction in the APM for how the C-bit should be handled.  For
      such cases, follow the SME behavior inasmuch as possible, since SEV is
      is essentially a VM-specific variant of SME.  For SME, the APM states:
      
        In this case the upper physical address bits are treated as reserved
        when the feature is enabled except where otherwise indicated.
      
      Collecting the various relavant SME snippets in the APM and cross-
      referencing the omissions with Linux kernel code, this leaves MTTRs and
      APIC_BASE as the only flows that KVM emulates that should _not_ ignore
      the C-bit.
      
      Note, this means the reserved bit checks in the page tables are
      technically broken.  This will be remedied in a future patch.
      
      Although the page table checks are technically broken, in practice, it's
      all but guaranteed to be irrelevant.  NPT is required for SEV, i.e.
      shadowing page tables isn't needed in the common case.  Theoretically,
      the checks could be in play for nested NPT, but it's extremely unlikely
      that anyone is running nested VMs on SEV, as doing so would require L1
      to expose sensitive data to L0, e.g. the entire VMCB.  And if anyone is
      running nested VMs, L0 can't read the guest's encrypted memory, i.e. L1
      would need to put its NPT in shared memory, in which case the C-bit will
      never be set.  Or, L1 could use shadow paging, but again, if L0 needs to
      read page tables, e.g. to load PDPTRs, the memory can't be encrypted if
      L1 has any expectation of L0 doing the right thing.
      
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20210204000117.3303214-8-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ca29e145
    • S
      KVM: x86: Set so called 'reserved CR3 bits in LM mask' at vCPU reset · f156abec
      Sean Christopherson 提交于
      Set cr3_lm_rsvd_bits, which is effectively an invalid GPA mask, at vCPU
      reset.  The reserved bits check needs to be done even if userspace never
      configures the guest's CPUID model.
      
      Cc: stable@vger.kernel.org
      Fixes: 0107973a ("KVM: x86: Introduce cr3_lm_rsvd_bits in kvm_vcpu_arch")
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20210204000117.3303214-2-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f156abec
    • D
      KVM: x86: declare Xen HVM shared info capability and add test case · 8d4e7e80
      David Woodhouse 提交于
      Instead of adding a plethora of new KVM_CAP_XEN_FOO capabilities, just
      add bits to the return value of KVM_CAP_XEN_HVM.
      Signed-off-by: NDavid Woodhouse <dwmw@amazon.co.uk>
      8d4e7e80
    • D
      KVM: x86/xen: Add event channel interrupt vector upcall · 40da8ccd
      David Woodhouse 提交于
      It turns out that we can't handle event channels *entirely* in userspace
      by delivering them as ExtINT, because KVM is a bit picky about when it
      accepts ExtINT interrupts from a legacy PIC. The in-kernel local APIC
      has to have LVT0 configured in APIC_MODE_EXTINT and unmasked, which
      isn't necessarily the case for Xen guests especially on secondary CPUs.
      
      To cope with this, add kvm_xen_get_interrupt() which checks the
      evtchn_pending_upcall field in the Xen vcpu_info, and delivers the Xen
      upcall vector (configured by KVM_XEN_ATTR_TYPE_UPCALL_VECTOR) if it's
      set regardless of LAPIC LVT0 configuration. This gives us the minimum
      support we need for completely userspace-based implementation of event
      channels.
      
      This does mean that vcpu_enter_guest() needs to check for the
      evtchn_pending_upcall flag being set, because it can't rely on someone
      having set KVM_REQ_EVENT unless we were to add some way for userspace to
      do so manually.
      Signed-off-by: NDavid Woodhouse <dwmw@amazon.co.uk>
      40da8ccd