1. 29 1月, 2018 1 次提交
  2. 17 1月, 2018 2 次提交
    • D
      target/ppc: Clean up probing of VMX, VSX and DFP availability on KVM · 3f2ca480
      David Gibson 提交于
      When constructing the "host" cpu class we modify whether the VMX and VSX
      vector extensions and DFP (Decimal Floating Point) are available
      based on whether KVM can support those instructions.  This can depend on
      policy in the host kernel as well as on the actual host cpu capabilities.
      
      However, the way we probe for this is not very nice: we explicitly check
      the host's device tree.  That works in practice, but it's not really
      correct, since the device tree is a property of the host kernel's platform
      which we don't really know about.  We get away with it because the only
      modern POWER platforms happen to encode VMX, VSX and DFP availability in
      the device tree in the same way.
      
      Arguably we should have an explicit KVM capability for this, but we haven't
      needed one so far.  Barring specific KVM policies which don't yet exist,
      each of these instruction classes will be available in the guest if and
      only if they're available in the qemu userspace process.  We can determine
      that from the ELF AUX vector we're supplied with.
      
      Once reworked like this, there are no more callers for kvmppc_get_vmx() and
      kvmppc_get_dfp() so remove them.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      3f2ca480
    • A
      target/ppc: Yet another fix for KVM-HV HPTE accessors · a36593e1
      Alexey Kardashevskiy 提交于
      As stated in the 1ad9f0a4 commit log, the returned entries are not
      a whole PTEG. It was not a problem before 1ad9f0a4 as it would read
      a single record assuming it contains a whole PTEG but now the code tries
      reading the entire PTEG and "if ((n - i) < invalid)" produces negative
      values which then are converted to size_t for memset() and that throws
      seg fault.
      
      This fixes the math.
      
      While here, fix the last @i increment as well.
      
      Fixes: 1ad9f0a4 "target/ppc: Fix KVM-HV HPTE accessors"
      Signed-off-by: NAlexey Kardashevskiy <aik@ozlabs.ru>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      a36593e1
  3. 18 12月, 2017 1 次提交
  4. 17 10月, 2017 3 次提交
  5. 27 9月, 2017 5 次提交
    • G
      spapr: fix the value of SDR1 in kvmppc_put_books_sregs() · 1ec26c75
      Greg Kurz 提交于
      When running with KVM PR, if a new HPT is allocated we need to inform
      KVM about the HPT address and size. This is currently done by hacking
      the value of SDR1 and pushing it to KVM in several places.
      
      Also, migration breaks the guest since it is very unlikely the HPT has
      the same address in source and destination, but we push the incoming
      value of SDR1 to KVM anyway.
      
      This patch introduces a new virtual hypervisor hook so that the spapr
      code can provide the correct value of SDR1 to be pushed to KVM each
      time kvmppc_put_books_sregs() is called.
      
      It allows to get rid of all the hacking in the spapr/kvmppc code and
      it fixes migration of nested KVM PR.
      Suggested-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      1ec26c75
    • G
      ppc/kvm: generalize the use of kvmppc_get_htab_fd() · 14b0d748
      Greg Kurz 提交于
      The use of KVM_PPC_GET_HTAB_FD is open-coded in kvmppc_read_hptes()
      and kvmppc_write_hpte().
      
      This patch modifies kvmppc_get_htab_fd() so that it can be used
      everywhere we need to access the in-kernel htab:
      - add an index argument
        => only kvmppc_read_hptes() passes an actual index, all other users
           pass 0
      - add an errp argument to propagate error messages to the caller.
        => spapr migration code prints the error
        => hpte helpers pass &error_abort to keep the current behavior
           of hw_error()
      
      While here, this also fixes a bug in kvmppc_write_hpte() so that it
      opens the htab fd for writing instead of reading as it currently does.
      This never broke anything because we currently never call this code,
      as explained in the changelog of commit c1385933:
      
      "This support updating htab managed by the hypervisor. Currently
       we don't have any user for this feature. This actually bring the
       store_hpte interface in-line with the load_hpte one. We may want
       to use this when we want to emulate henter hcall in qemu for HV
       kvm."
      
      The above is still true today.
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      14b0d748
    • G
      ppc/kvm: change kvmppc_get_htab_fd() to return -errno on error · 82be8e73
      Greg Kurz 提交于
      When kvmppc_get_htab_fd() fails, its return value is propagated up to
      qemu_savevm_state_iterate() or to qemu_savevm_state_complete_precopy().
      All savevm handlers expect to receive a negative errno on error.
      
      Let's patch kvmppc_get_htab_fd() accordingly.
      
      While here, let's change htab_load() in the spapr code to also
      propagate the error, since it doesn't make sense to abort() if
      we couldn't get the htab fd from KVM.
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      82be8e73
    • G
      ppc/kvm: drop kvmppc_has_cap_htab_fd() · 712b25c4
      Greg Kurz 提交于
      It never got used since its introduction (commit 7c43bca0).
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      712b25c4
    • G
      ppc/kvm: check some capabilities with kvm_vm_check_extension() · 6977afda
      Greg Kurz 提交于
      The following capabilities are VM specific:
      - KVM_CAP_PPC_SMT_POSSIBLE
      - KVM_CAP_PPC_HTAB_FD
      - KVM_CAP_PPC_ALLOC_HTAB
      
      If both KVM HV and KVM PR are present, checking them always return
      the HV value, even if we explicitely requested to use PR.
      
      This has no visible effect for KVM_CAP_PPC_ALLOC_HTAB, because we also
      try the KVM_PPC_ALLOCATE_HTAB ioctl which is only suppored by HV. As
      a consequence, the spapr code doesn't even check KVM_CAP_PPC_HTAB_FD.
      
      However, this will cause kvmppc_hint_smt_possible(), introduced by
      commit fa98fbfc, to report several VSMT modes (eg, Available
      VSMT modes: 8 4 2 1) whereas PR only support mode 1.
      
      This patch fixes all three anyway to use kvm_vm_check_extension(). It
      is okay since the VM is already created at the time kvm_arch_init() or
      kvmppc_reset_htab() is called.
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Reviewed-by: NThomas Huth <thuth@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      6977afda
  6. 15 9月, 2017 1 次提交
    • G
      ppc/kvm: use kvm_vm_check_extension() in kvmppc_is_pr() · 70a0c19e
      Greg Kurz 提交于
      If the host has both KVM PR and KVM HV loaded and we pass:
      
      	-machine pseries,accel=kvm,kvm-type=PR
      
      the kvmppc_is_pr() returns false instead of true. Since the helper
      is mostly used as fallback, it doesn't have any real impact with
      recent kernels. A notable exception is the workaround to allow
      migration between compatible hosts with different PVRs (eg, POWER8
      and POWER8E), since KVM still doesn't provide a way to check if a
      specific PVR is supported (see commit c363a37a for details).
      
      According to the official KVM API documentation [1], KVM_PPC_GET_PVINFO
      is "vm ioctl", but we check it as a global ioctl. The following function
      in KVM is hence called with kvm == NULL and considers we're in HV mode.
      
      int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
      {
      	int r;
      	/* Assume we're using HV mode when the HV module is loaded */
      	int hv_enabled = kvmppc_hv_ops ? 1 : 0;
      
      	if (kvm) {
      		/*
      		 * Hooray - we know which VM type we're running on. Depend on
      		 * that rather than the guess above.
      		 */
      		hv_enabled = is_kvmppc_hv_enabled(kvm);
      	}
      
      Let's use kvm_vm_check_extension() to fix the issue.
      
      [1] https://www.kernel.org/doc/Documentation/virtual/kvm/api.txtSigned-off-by: NGreg Kurz <groug@kaod.org>
      Reviewed-by: NThomas Huth <thuth@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      70a0c19e
  7. 08 9月, 2017 6 次提交
    • I
      ppc: drop caching ObjectClass from PowerPCCPUAlias · 2527cb91
      Igor Mammedov 提交于
      Caching there practically doesn't give any benefits
      and that at slow path druring querying supported CPU list.
      But it introduces non conventional path of where from
      comes used CPU type name (kvm_ppc_register_host_cpu_type).
      
      Taking in account that kvm_ppc_register_host_cpu_type()
      fixes up models the aliases point to, it's sufficient to
      make ppc_cpu_class_by_name() translate cpu alias to
      correct cpu type name.
      So drop PowerPCCPUAlias::oc field + ppc_cpu_class_by_alias()
      and let ppc_cpu_class_by_name() do conversion to cpu type name,
      which simplifies code a little bit saving ~20LOC and trouble
      wondering why ppc_cpu_class_by_alias() is necessary.
      Signed-off-by: NIgor Mammedov <imammedo@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      2527cb91
    • I
      ppc: make cpu_model translation to type consistent · c5354f54
      Igor Mammedov 提交于
      PPC handles -cpu FOO rather incosistently,
      i.e. it does case-insensitive matching of FOO to
      a CPU type (see: ppc_cpu_compare_class_name) but
      handles alias names as case-sensitive, as result:
      
       # qemu-system-ppc64 -M mac99 -cpu g3
       qemu-system-ppc64: unable to find CPU model ' kN�U'
      
       # qemu-system-ppc64 -cpu 970MP_V1.1
       qemu-system-ppc64: Unable to find sPAPR CPU Core definition
      
      while
      
       # qemu-system-ppc64 -M mac99 -cpu G3
       # qemu-system-ppc64 -cpu 970MP_v1.1
      
      start up just fine.
      
      Considering we can't take case-insensitive matching away,
      make it case-insensitive for  all alias/type/core_type
      lookups.
      
      As side effect it allows to remove duplicate core types
      which are the same except of using different cased letters in name.
      Signed-off-by: NIgor Mammedov <imammedo@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      c5354f54
    • I
      ppc: use macros to make cpu type name from string literal · c9137065
      Igor Mammedov 提交于
      Replace
        "-" TYPE_POWERPC_CPU
      when composing cpu type name from cpu model string literal
      and the same pattern in format strings with
       POWERPC_CPU_TYPE_SUFFIX and POWERPC_CPU_TYPE_NAME(model)
      macroses like we do in x86.
      
      Later POWERPC_CPU_TYPE_NAME() will be used to define default
      cpu type per machine type and as bonus it will be consistent
      and easy grep-able pattern across all other targets that I'm
      plannig to treat the same way.
      Signed-off-by: NIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      c9137065
    • S
      PPC: KVM: Support machine option to set VSMT mode · fa98fbfc
      Sam Bobroff 提交于
      KVM now allows writing to KVM_CAP_PPC_SMT which has previously been
      read only. Doing so causes KVM to act, for that VM, as if the host's
      SMT mode was the given value. This is particularly important on Power
      9 systems because their default value is 1, but they are able to
      support values up to 8.
      
      This patch introduces a way to control this capability via a new
      machine property called VSMT ("Virtual SMT"). If the value is not set
      on the command line a default is chosen that is, when possible,
      compatible with legacy systems.
      
      Note that the intialization of KVM_CAP_PPC_SMT has changed slightly
      because it has changed (in KVM) from a global capability to a
      VM-specific one. This won't cause a problem on older KVMs because VM
      capabilities fall back to global ones.
      Signed-off-by: NSam Bobroff <sam.bobroff@au1.ibm.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      fa98fbfc
    • S
      ppc: spapr: Make VCPU ID handling private to SPAPR · 2e886fb3
      Sam Bobroff 提交于
      The concept of a VCPU ID that differs from the CPU's index
      (cpu->cpu_index) exists only within SPAPR machines so, move the
      functions ppc_get_vcpu_id() and ppc_get_cpu_by_vcpu_id() into spapr.c
      and rename them appropriately.
      Signed-off-by: NSam Bobroff <sam.bobroff@au1.ibm.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      2e886fb3
    • S
      ppc: spapr: Rename cpu_dt_id to vcpu_id · 81210c20
      Sam Bobroff 提交于
      This field actually records the VCPU ID used by KVM and, although the
      value is also used in the device tree it is primarily the VCPU ID so
      rename it as such.
      Signed-off-by: NSam Bobroff <sam.bobroff@au1.ibm.com>
      [dwg: Updated comment missed in cpu.h]
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      81210c20
  8. 22 8月, 2017 1 次提交
    • D
      target/ppc: 'PVR != host PVR' in KVM_SET_SREGS workaround · c363a37a
      Daniel Henrique Barboza 提交于
      Commit d5fc133e ("ppc: Rework CPU compatibility testing
      across migration") changed the way cpu_post_load behaves with
      the PVR setting, causing an unexpected bug in KVM-HV migrations
      between hosts that are compatible (POWER8 and POWER8E, for example).
      Even with pvr_match() returning true, the guest freezes right after
      cpu_post_load. The reason is that the guest kernel can't handle a
      different PVR value other that the running host in KVM_SET_SREGS.
      
      In [1] it was discussed the possibility of a new KVM capability
      that would indicate that the guest kernel can handle a different
      PVR in KVM_SET_SREGS. Even if such feature is implemented, there is
      still the problem with older kernels that will not have this capability
      and will fail to migrate.
      
      This patch implements a workaround for that scenario. If running
      with KVM, check if the guest kernel does not have the capability
      (named here as 'cap_ppc_pvr_compat'). If it doesn't, calls
      kvmppc_is_pr() to see if the guest is running in KVM-HV. If all this
      happens, set env->spr[SPR_PVR] to the same value as the current
      host PVR. This ensures that we allow migrations with 'close enough'
      PVRs to still work in KVM-HV but also makes the code ready for
      this new KVM capability when it is done.
      
      A new function called 'kvmppc_pvr_workaround_required' was created
      to encapsulate the conditions said above and to avoid calling too
      many kvm.c internals inside cpu_post_load.
      
      [1] https://lists.gnu.org/archive/html/qemu-ppc/2017-06/msg00503.htmlSigned-off-by: NDaniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
      [dwg: Fix for the case of using TCG on a PPC host]
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      c363a37a
  9. 17 7月, 2017 2 次提交
    • D
      pseries: Allow HPT resizing with KVM · b55d295e
      David Gibson 提交于
      So far, qemu implements the PAPR Hash Page Table (HPT) resizing extension
      with TCG.  The same implementation will work with KVM PR, but we don't
      currently allow that.  For KVM HV we can only implement resizing with the
      assistance of the host kernel, which needs a new capability and ioctl()s.
      
      This patch adds support for testing the new KVM capability and implementing
      the resize in terms of KVM facilities when necessary.  If we're running on
      a kernel which doesn't have the new capability flag at all, we fall back to
      testing for PR vs. HV KVM using the same hack that we already use in a
      number of places for older kernels.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      b55d295e
    • D
      pseries: Stubs for HPT resizing · 30f4b05b
      David Gibson 提交于
      This introduces stub implementations of the H_RESIZE_HPT_PREPARE and
      H_RESIZE_HPT_COMMIT hypercalls which we hope to add in a PAPR
      extension to allow run time resizing of a guest's hash page table.  It
      also adds a new machine property for controlling whether this new
      facility is available.
      
      For now we only allow resizing with TCG, allowing it with KVM will require
      kernel changes as well.
      
      Finally, it adds a new string to the hypertas property in the device
      tree, advertising to the guest the availability of the HPT resizing
      hypercalls.  This is a tentative suggested value, and would need to be
      standardized by PAPR before being merged.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: NSuraj Jitindar Singh <sjitindarsingh@gmail.com>
      Reviewed-by: NLaurent Vivier <lvivier@redhat.com>
      30f4b05b
  10. 11 7月, 2017 1 次提交
    • G
      ppc/kvm: have the "family" CPU alias to point to TYPE_HOST_POWERPC_CPU · 92e926e1
      Greg Kurz 提交于
      When running KVM on POWER, we allow the user to pass "-cpu POWERx" instead
      of "-cpu host". This is achieved by patching the ppc_cpu_aliases[] array
      so that "POWERx" points to the CPU class with the same PVR as the host CPU.
      This causes CPUs to be instantiated from this CPU class instead of the
      TYPE_HOST_POWERPC_CPU class which is used with "-cpu host". These CPUs thus
      miss all the KVM specific tuning from kvmppc_host_cpu_class_init().
      
      This currently causes QEMU with "-cpu POWER9" to fail when running KVM on a
      POWER9 DD1 host:
      
      qemu-system-ppc64: Register sync failed... If you're using kvm-hv.ko, only
       "-cpu host" is possible
      kvm_init_vcpu failed: Invalid argument
      
      Let's have the "POWERx" alias to point to TYPE_HOST_POWERPC_CPU directly,
      so that "-cpu POWERx" instantiates CPUs from the same class as "-cpu host".
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Tested-by: NLaurent Vivier <lvivier@redhat.com>
      Reviewed-by: NLaurent Vivier <lvivier@redhat.com>
      Reviewed-by: NThomas Huth <thuth@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      92e926e1
  11. 08 6月, 2017 2 次提交
  12. 11 5月, 2017 2 次提交
    • T
      target/ppc: Avoid printing wrong aliases in CPU help text · e9edd931
      Thomas Huth 提交于
      When running with KVM, we update the "family" CPU alias to point
      to the right host CPU type, so that it for example possible to
      use "-cpu POWER8" on a POWER8NVL host. However, the function for
      printing the list of available CPU models is called earlier than
      the KVM setup code, so the output of "-cpu help" is wrong in that
      case. Since it would be somewhat ugly anyway to have different
      help texts depending on whether "-enable-kvm" has been specified
      or not, we should better always print the same text, so fix this
      issue by printing "alias for preferred XXX CPU" instead.
      Reviewed-by: NEduardo Habkost <ehabkost@redhat.com>
      Signed-off-by: NThomas Huth <thuth@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      e9edd931
    • D
      target/ppc: Allow workarounds for POWER9 DD1 · 5f3066d8
      David Gibson 提交于
      POWER9 DD1 silicon has some bugs which mean it a) isn't really compliant
      with the ISA v3.00 and b) require a number of special workarounds in the
      kernel.
      
      At the moment, qemu isn't aware of DD1.  For TCG we don't really want it to
      be (why bother emulating buggy silicon).  But with KVM, the guest does need
      to be aware of DD1 so it can apply the necessary workarounds.
      
      Meanwhile, the feature negotiation between qemu and the guest strongly
      favours architected compatibility modes to "raw" CPU modes.  In combination
      with the above, this means the guest sees architected POWER9 mode, and
      doesn't apply the DD1 workarounds.  Well, unless it has yet another
      workaround to partially ignore what qemu tells it.
      
      This patch addresses this by disabling support for compatibility modes when
      using KVM on a POWER9 DD1 host.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      5f3066d8
  13. 26 4月, 2017 6 次提交
  14. 21 4月, 2017 1 次提交
  15. 03 3月, 2017 4 次提交
  16. 01 3月, 2017 2 次提交
    • D
      target/ppc: Manage external HPT via virtual hypervisor · e57ca75c
      David Gibson 提交于
      The pseries machine type implements the behaviour of a PAPR compliant
      hypervisor, without actually executing such a hypervisor on the virtual
      CPU.  To do this we need some hooks in the CPU code to make hypervisor
      facilities get redirected to the machine instead of emulated internally.
      
      For hypercalls this is managed through the cpu->vhyp field, which points
      to a QOM interface with a method implementing the hypercall.
      
      For the hashed page table (HPT) - also a hypervisor resource - we use an
      older hack.  CPUPPCState has an 'external_htab' field which when non-NULL
      indicates that the HPT is stored in qemu memory, rather than within the
      guest's address space.
      
      For consistency - and to make some future extensions easier - this merges
      the external HPT mechanism into the vhyp mechanism.  Methods are added
      to vhyp for the basic operations the core hash MMU code needs: map_hptes()
      and unmap_hptes() for reading the HPT, store_hpte() for updating it and
      hpt_mask() to retrieve its size.
      
      To match this, the pseries machine now sets these vhyp fields in its
      existing vhyp class, rather than reaching into the cpu object to set the
      external_htab field.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: NSuraj Jitindar Singh <sjitindarsingh@gmail.com>
      e57ca75c
    • D
      target/ppc: Fix KVM-HV HPTE accessors · 1ad9f0a4
      David Gibson 提交于
      When a 'pseries' guest is running with KVM-HV, the guest's hashed page
      table (HPT) is stored within the host kernel, so it is not directly
      accessible to qemu.  Most of the time, qemu doesn't need to access it:
      we're using the hardware MMU, and KVM itself implements the guest
      hypercalls for manipulating the HPT.
      
      However, qemu does need access to the in-KVM HPT to implement
      get_phys_page_debug() for the benefit of the gdbstub, and maybe for
      other debug operations.
      
      To allow this, 7c43bca0 "target-ppc: Fix page table lookup with kvm
      enabled" added kvmppc_hash64_read_pteg() to target/ppc/kvm.c to read
      in a batch of HPTEs from the KVM table.  Unfortunately, there are a
      couple of problems with this:
      
      First, the name of the function implies it always reads a whole PTEG
      from the HPT, but in fact in some cases it's used to grab individual
      HPTEs (which ends up pulling 8 HPTEs, not aligned to a PTEG from the
      kernel).
      
      Second, and more importantly, the code to read the HPTEs from KVM is
      simply wrong, in general.  The data from the fd that KVM provides is
      designed mostly for compact migration rather than this sort of one-off
      access, and so needs some decoding for this purpose.  The current code
      will work in some cases, but if there are invalid HPTEs then it will
      not get sane results.
      
      This patch rewrite the HPTE reading function to have a simpler
      interface (just read n HPTEs into a caller provided buffer), and to
      correctly decode the stream from the kernel.
      
      For consistency we also clean up the similar function for altering
      HPTEs within KVM (introduced in c1385933 "target-ppc: Update
      ppc_hash64_store_hpte to support updating in-kernel htab").
      
      Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      1ad9f0a4