1. 08 12月, 2016 13 次提交
    • L
      KVM: nVMX: introduce nested_vmx_load_cr3 and call it on vmentry · 9ed38ffa
      Ladi Prosek 提交于
      Loading CR3 as part of emulating vmentry is different from regular CR3 loads,
      as implemented in kvm_set_cr3, in several ways.
      
      * different rules are followed to check CR3 and it is desirable for the caller
      to distinguish between the possible failures
      * PDPTRs are not loaded if PAE paging and nested EPT are both enabled
      * many MMU operations are not necessary
      
      This patch introduces nested_vmx_load_cr3 suitable for CR3 loads as part of
      nested vmentry and vmexit, and makes use of it on the nested vmentry path.
      Signed-off-by: NLadi Prosek <lprosek@redhat.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      9ed38ffa
    • L
      KVM: nVMX: propagate errors from prepare_vmcs02 · ee146c1c
      Ladi Prosek 提交于
      It is possible that prepare_vmcs02 fails to load the guest state. This
      patch adds the proper error handling for such a case. L1 will receive
      an INVALID_STATE vmexit with the appropriate exit qualification if it
      happens.
      
      A failure to set guest CR3 is the only error propagated from prepare_vmcs02
      at the moment.
      Signed-off-by: NLadi Prosek <lprosek@redhat.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      ee146c1c
    • L
      KVM: nVMX: fix CR3 load if L2 uses PAE paging and EPT · 7ca29de2
      Ladi Prosek 提交于
      KVM does not correctly handle L1 hypervisors that emulate L2 real mode with
      PAE and EPT, such as Hyper-V. In this mode, the L1 hypervisor populates guest
      PDPTE VMCS fields and leaves guest CR3 uninitialized because it is not used
      (see 26.3.2.4 Loading Page-Directory-Pointer-Table Entries). KVM always
      dereferences CR3 and tries to load PDPTEs if PAE is on. This leads to two
      related issues:
      
      1) On the first nested vmentry, the guest PDPTEs, as populated by L1, are
      overwritten in ept_load_pdptrs because the registers are believed to have
      been loaded in load_pdptrs as part of kvm_set_cr3. This is incorrect. L2 is
      running with PAE enabled but PDPTRs have been set up by L1.
      
      2) When L2 is about to enable paging and loads its CR3, we, again, attempt
      to load PDPTEs in load_pdptrs called from kvm_set_cr3. There are no guarantees
      that this will succeed (it's just a CR3 load, paging is not enabled yet) and
      if it doesn't, kvm_set_cr3 returns early without persisting the CR3 which is
      then lost and L2 crashes right after it enables paging.
      
      This patch replaces the kvm_set_cr3 call with a simple register write if PAE
      and EPT are both on. CR3 is not to be interpreted in this case.
      Signed-off-by: NLadi Prosek <lprosek@redhat.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      7ca29de2
    • D
      KVM: nVMX: load GUEST_EFER after GUEST_CR0 during emulated VM-entry · 5a6a9748
      David Matlack 提交于
      vmx_set_cr0() modifies GUEST_EFER and "IA-32e mode guest" in the current
      VMCS. Call vmx_set_efer() after vmx_set_cr0() so that emulated VM-entry
      is more faithful to VMCS12.
      
      This patch correctly causes VM-entry to fail when "IA-32e mode guest" is
      1 and GUEST_CR0.PG is 0. Previously this configuration would succeed and
      "IA-32e mode guest" would silently be disabled by KVM.
      Signed-off-by: NDavid Matlack <dmatlack@google.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      5a6a9748
    • D
      KVM: nVMX: generate MSR_IA32_CR{0,4}_FIXED1 from guest CPUID · 8322ebbb
      David Matlack 提交于
      MSR_IA32_CR{0,4}_FIXED1 define which bits in CR0 and CR4 are allowed to
      be 1 during VMX operation. Since the set of allowed-1 bits is the same
      in and out of VMX operation, we can generate these MSRs entirely from
      the guest's CPUID. This lets userspace avoiding having to save/restore
      these MSRs.
      
      This patch also initializes MSR_IA32_CR{0,4}_FIXED1 from the CPU's MSRs
      by default. This is a saner than the current default of -1ull, which
      includes bits that the host CPU does not support.
      Signed-off-by: NDavid Matlack <dmatlack@google.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      8322ebbb
    • D
      KVM: nVMX: fix checks on CR{0,4} during virtual VMX operation · 3899152c
      David Matlack 提交于
      KVM emulates MSR_IA32_VMX_CR{0,4}_FIXED1 with the value -1ULL, meaning
      all CR0 and CR4 bits are allowed to be 1 during VMX operation.
      
      This does not match real hardware, which disallows the high 32 bits of
      CR0 to be 1, and disallows reserved bits of CR4 to be 1 (including bits
      which are defined in the SDM but missing according to CPUID). A guest
      can induce a VM-entry failure by setting these bits in GUEST_CR0 and
      GUEST_CR4, despite MSR_IA32_VMX_CR{0,4}_FIXED1 indicating they are
      valid.
      
      Since KVM has allowed all bits to be 1 in CR0 and CR4, the existing
      checks on these registers do not verify must-be-0 bits. Fix these checks
      to identify must-be-0 bits according to MSR_IA32_VMX_CR{0,4}_FIXED1.
      
      This patch should introduce no change in behavior in KVM, since these
      MSRs are still -1ULL.
      Signed-off-by: NDavid Matlack <dmatlack@google.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      3899152c
    • D
      KVM: nVMX: support restore of VMX capability MSRs · 62cc6b9d
      David Matlack 提交于
      The VMX capability MSRs advertise the set of features the KVM virtual
      CPU can support. This set of features varies across different host CPUs
      and KVM versions. This patch aims to addresses both sources of
      differences, allowing VMs to be migrated across CPUs and KVM versions
      without guest-visible changes to these MSRs. Note that cross-KVM-
      version migration is only supported from this point forward.
      
      When the VMX capability MSRs are restored, they are audited to check
      that the set of features advertised are a subset of what KVM and the
      CPU support.
      
      Since the VMX capability MSRs are read-only, they do not need to be on
      the default MSR save/restore lists. The userspace hypervisor can set
      the values of these MSRs or read them from KVM at VCPU creation time,
      and restore the same value after every save/restore.
      Signed-off-by: NDavid Matlack <dmatlack@google.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      62cc6b9d
    • D
      KVM: nVMX: generate non-true VMX MSRs based on true versions · 0115f9cb
      David Matlack 提交于
      The "non-true" VMX capability MSRs can be generated from their "true"
      counterparts, by OR-ing the default1 bits. The default1 bits are fixed
      and defined in the SDM.
      
      Since we can generate the non-true VMX MSRs from the true versions,
      there's no need to store both in struct nested_vmx. This also lets
      userspace avoid having to restore the non-true MSRs.
      
      Note this does not preclude emulating MSR_IA32_VMX_BASIC[55]=0. To do so,
      we simply need to set all the default1 bits in the true MSRs (such that
      the true MSRs and the generated non-true MSRs are equal).
      Signed-off-by: NDavid Matlack <dmatlack@google.com>
      Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      0115f9cb
    • K
      KVM: x86: Do not clear RFLAGS.TF when a singlestep trap occurs. · ea07e42d
      Kyle Huey 提交于
      The trap flag stays set until software clears it.
      Signed-off-by: NKyle Huey <khuey@kylehuey.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      ea07e42d
    • K
      KVM: x86: Add kvm_skip_emulated_instruction and use it. · 6affcbed
      Kyle Huey 提交于
      kvm_skip_emulated_instruction calls both
      kvm_x86_ops->skip_emulated_instruction and kvm_vcpu_check_singlestep,
      skipping the emulated instruction and generating a trap if necessary.
      
      Replacing skip_emulated_instruction calls with
      kvm_skip_emulated_instruction is straightforward, except for:
      
      - ICEBP, which is already inside a trap, so avoid triggering another trap.
      - Instructions that can trigger exits to userspace, such as the IO insns,
        MOVs to CR8, and HALT. If kvm_skip_emulated_instruction does trigger a
        KVM_GUESTDBG_SINGLESTEP exit, and the handling code for
        IN/OUT/MOV CR8/HALT also triggers an exit to userspace, the latter will
        take precedence. The singlestep will be triggered again on the next
        instruction, which is the current behavior.
      - Task switch instructions which would require additional handling (e.g.
        the task switch bit) and are instead left alone.
      - Cases where VMLAUNCH/VMRESUME do not proceed to the next instruction,
        which do not trigger singlestep traps as mentioned previously.
      Signed-off-by: NKyle Huey <khuey@kylehuey.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      6affcbed
    • K
      KVM: VMX: Move skip_emulated_instruction out of nested_vmx_check_vmcs12 · eb277562
      Kyle Huey 提交于
      We can't return both the pass/fail boolean for the vmcs and the upcoming
      continue/exit-to-userspace boolean for skip_emulated_instruction out of
      nested_vmx_check_vmcs, so move skip_emulated_instruction out of it instead.
      
      Additionally, VMENTER/VMRESUME only trigger singlestep exceptions when
      they advance the IP to the following instruction, not when they a) succeed,
      b) fail MSR validation or c) throw an exception. Add a separate call to
      skip_emulated_instruction that will later not be converted to the variant
      that checks the singlestep flag.
      Signed-off-by: NKyle Huey <khuey@kylehuey.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      eb277562
    • K
      KVM: VMX: Reorder some skip_emulated_instruction calls · 09ca3f20
      Kyle Huey 提交于
      The functions being moved ahead of skip_emulated_instruction here don't
      need updated IPs, and skipping the emulated instruction at the end will
      make it easier to return its value.
      Signed-off-by: NKyle Huey <khuey@kylehuey.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      09ca3f20
    • K
      KVM: x86: Add a return value to kvm_emulate_cpuid · 6a908b62
      Kyle Huey 提交于
      Once skipping the emulated instruction can potentially trigger an exit to
      userspace (via KVM_GUESTDBG_SINGLESTEP) kvm_emulate_cpuid will need to
      propagate a return value.
      Signed-off-by: NKyle Huey <khuey@kylehuey.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      6a908b62
  2. 25 11月, 2016 2 次提交
    • T
      kvm: svm: Add kvm_fast_pio_in support · 8370c3d0
      Tom Lendacky 提交于
      Update the I/O interception support to add the kvm_fast_pio_in function
      to speed up the in instruction similar to the out instruction.
      Signed-off-by: NTom Lendacky <thomas.lendacky@amd.com>
      Reviewed-by: NBorislav Petkov <bp@suse.de>
      Signed-off-by: NBrijesh Singh <brijesh.singh@amd.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      8370c3d0
    • T
      kvm: svm: Add support for additional SVM NPF error codes · 14727754
      Tom Lendacky 提交于
      AMD hardware adds two additional bits to aid in nested page fault handling.
      
      Bit 32 - NPF occurred while translating the guest's final physical address
      Bit 33 - NPF occurred while translating the guest page tables
      
      The guest page tables fault indicator can be used as an aid for nested
      virtualization. Using V0 for the host, V1 for the first level guest and
      V2 for the second level guest, when both V1 and V2 are using nested paging
      there are currently a number of unnecessary instruction emulations. When
      V2 is launched shadow paging is used in V1 for the nested tables of V2. As
      a result, KVM marks these pages as RO in the host nested page tables. When
      V2 exits and we resume V1, these pages are still marked RO.
      
      Every nested walk for a guest page table is treated as a user-level write
      access and this causes a lot of NPFs because the V1 page tables are marked
      RO in the V0 nested tables. While executing V1, when these NPFs occur KVM
      sees a write to a read-only page, emulates the V1 instruction and unprotects
      the page (marking it RW). This patch looks for cases where we get a NPF due
      to a guest page table walk where the page was marked RO. It immediately
      unprotects the page and resumes the guest, leading to far fewer instruction
      emulations when nested virtualization is used.
      Signed-off-by: NTom Lendacky <thomas.lendacky@amd.com>
      Reviewed-by: NBorislav Petkov <bp@suse.de>
      Signed-off-by: NBrijesh Singh <brijesh.singh@amd.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      14727754
  3. 23 11月, 2016 3 次提交
  4. 22 11月, 2016 1 次提交
  5. 17 11月, 2016 10 次提交
  6. 16 11月, 2016 2 次提交
  7. 12 11月, 2016 2 次提交
    • A
      crypto: aesni: shut up -Wmaybe-uninitialized warning · beae2c9e
      Arnd Bergmann 提交于
      The rfc4106 encrypy/decrypt helper functions cause an annoying
      false-positive warning in allmodconfig if we turn on
      -Wmaybe-uninitialized warnings again:
      
        arch/x86/crypto/aesni-intel_glue.c: In function ‘helper_rfc4106_decrypt’:
        include/linux/scatterlist.h:67:31: warning: ‘dst_sg_walk.sg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
      
      The problem seems to be that the compiler doesn't track the state of the
      'one_entry_in_sg' variable across the kernel_fpu_begin/kernel_fpu_end
      section.
      
      This takes the easy way out by adding a bogus initialization, which
      should be harmless enough to get the patch into v4.9 so we can turn on
      this warning again by default without producing useless output.  A
      follow-up patch for v4.10 rearranges the code to make the warning go
      away.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      beae2c9e
    • A
      x86: apm: avoid uninitialized data · 3a6d8676
      Arnd Bergmann 提交于
      apm_bios_call() can fail, and return a status in its argument structure.
      If that status however is zero during a call from
      apm_get_power_status(), we end up using data that may have never been
      set, as reported by "gcc -Wmaybe-uninitialized":
      
        arch/x86/kernel/apm_32.c: In function ‘apm’:
        arch/x86/kernel/apm_32.c:1729:17: error: ‘bx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
        arch/x86/kernel/apm_32.c:1835:5: error: ‘cx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
        arch/x86/kernel/apm_32.c:1730:17: note: ‘cx’ was declared here
        arch/x86/kernel/apm_32.c:1842:27: error: ‘dx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
        arch/x86/kernel/apm_32.c:1731:17: note: ‘dx’ was declared here
      
      This changes the function to return "APM_NO_ERROR" here, which makes the
      code more robust to broken BIOS versions, and avoids the warning.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Reviewed-by: NJiri Kosina <jkosina@suse.cz>
      Reviewed-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3a6d8676
  8. 04 11月, 2016 3 次提交
  9. 03 11月, 2016 4 次提交
    • P
      kvm: x86: avoid atomic operations on APICv vmentry · ad361091
      Paolo Bonzini 提交于
      On some benchmarks (e.g. netperf with ioeventfd disabled), APICv
      posted interrupts turn out to be slower than interrupt injection via
      KVM_REQ_EVENT.
      
      This patch optimizes a bit the IRR update, avoiding expensive atomic
      operations in the common case where PI.ON=0 at vmentry or the PIR vector
      is mostly zero.  This saves at least 20 cycles (1%) per vmexit, as
      measured by kvm-unit-tests' inl_from_qemu test (20 runs):
      
                    | enable_apicv=1  |  enable_apicv=0
                    | mean     stdev  |  mean     stdev
          ----------|-----------------|------------------
          before    | 5826     32.65  |  5765     47.09
          after     | 5809     43.42  |  5777     77.02
      
      Of course, any change in the right column is just placebo effect. :)
      The savings are bigger if interrupts are frequent.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ad361091
    • P
      KVM: nVMX: support descriptor table exits · 1b07304c
      Paolo Bonzini 提交于
      These are never used by the host, but they can still be reflected to
      the guest.
      Tested-by: NLadi Prosek <lprosek@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      1b07304c
    • P
      KVM: x86: use ktime_get instead of seeking the hrtimer_clock_base · 5587859f
      Paolo Bonzini 提交于
      The base clock for the LAPIC timer is always CLOCK_MONOTONIC.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      5587859f
    • W
      KVM: LAPIC: add APIC Timer periodic/oneshot mode VMX preemption timer support · 8003c9ae
      Wanpeng Li 提交于
      Most windows guests still utilize APIC Timer periodic/oneshot mode
      instead of tsc-deadline mode, and the APIC Timer periodic/oneshot
      mode are still emulated by high overhead hrtimer on host. This patch
      converts the expected expire time of the periodic/oneshot mode to
      guest deadline tsc in order to leverage VMX preemption timer logic
      for APIC Timer tsc-deadline mode. After each preemption timer vmexit
      preemption timer is restarted to emulate LVTT current-count register
      is automatically reloaded from the initial-count register when the
      count reaches 0. This patch reduces ~5600 cycles for each APIC Timer
      periodic mode operation virtualization.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Radim Krčmář <rkrcmar@redhat.com>
      Cc: Yunhong Jiang <yunhong.jiang@intel.com>
      Signed-off-by: NWanpeng Li <wanpeng.li@hotmail.com>
      [Squashed with my fixes that were reviewed-by Paolo.]
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      8003c9ae