1. 21 6月, 2018 19 次提交
  2. 22 5月, 2018 12 次提交
    • G
      spapr: register dummy ICPs later · 72cc467a
      Greg Kurz 提交于
      Some older machine types create more ICPs than needed. We hence
      need to register up to xics_max_server_number() dummy ICPs to
      accomodate the migration of these machine types.
      
      Recent VSMT rework changed xics_max_server_number() to return
      
          DIV_ROUND_UP(max_cpus * spapr->vsmt, smp_threads)
      
      instead of
      
          DIV_ROUND_UP(max_cpus * kvmppc_smt_threads(), smp_threads);
      
      The change is okay but it requires spapr->vsmt to be set, which
      isn't the case with the current code. This causes the formula to
      return zero and we don't create dummy ICPs. This breaks migration
      of older guests as reported here:
      
          https://bugzilla.redhat.com/show_bug.cgi?id=1549087
      
      The dummy ICP workaround doesn't really have a dependency on XICS
      itself. But it does depend on proper VCPU id numbering and it must
      be applied before creating vCPUs (ie, creating real ICPs). So this
      patch moves the workaround to spapr_init_cpus(), which already
      assumes VSMT to be set.
      
      Fixes: 72194664 ("spapr: use spapr->vsmt to compute VCPU ids")
      Reported-by: NLukas Doktor <ldoktor@redhat.com>
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      (cherry picked from commit 72fdd4de)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      72cc467a
    • G
      spapr: fix missing CPU core nodes in DT when running with TCG · 184da186
      Greg Kurz 提交于
      Commit 5d0fb150 "spapr: consolidate the VCPU id numbering logic
      in a single place" introduced a helper to detect thread0 of a virtual
      core based on its VCPU id. This is used to create CPU core nodes in
      the DT, but it is broken in TCG.
      
      $ qemu-system-ppc64 -nographic -accel tcg -machine dumpdtb=dtb.bin \
                          -smp cores=16,maxcpus=16,threads=1
      $ dtc -f -O dts dtb.bin | grep POWER8
                      PowerPC,POWER8@0 {
                      PowerPC,POWER8@8 {
      
      instead of the expected 16 cores that we get with KVM:
      
      $ dtc -f -O dts dtb.bin | grep POWER8
                      PowerPC,POWER8@0 {
                      PowerPC,POWER8@8 {
                      PowerPC,POWER8@10 {
                      PowerPC,POWER8@18 {
                      PowerPC,POWER8@20 {
                      PowerPC,POWER8@28 {
                      PowerPC,POWER8@30 {
                      PowerPC,POWER8@38 {
                      PowerPC,POWER8@40 {
                      PowerPC,POWER8@48 {
                      PowerPC,POWER8@50 {
                      PowerPC,POWER8@58 {
                      PowerPC,POWER8@60 {
                      PowerPC,POWER8@68 {
                      PowerPC,POWER8@70 {
                      PowerPC,POWER8@78 {
      
      This happens because spapr_get_vcpu_id() maps VCPU ids to
      cs->cpu_index in TCG mode. This confuses the code in
      spapr_is_thread0_in_vcore(), since it assumes thread0 VCPU
      ids to have a spapr->vsmt spacing.
      
          spapr_get_vcpu_id(cpu) % spapr->vsmt == 0
      
      Actually, there's no real reason to expose cs->cpu_index instead
      of the VCPU id, since we also generate it with TCG. Also we already
      set it explicitly in spapr_set_vcpu_id(), so there's no real reason
      either to call kvm_arch_vcpu_id() with KVM.
      
      This patch unifies spapr_get_vcpu_id() to always return the computed
      VCPU id both in TCG and KVM. This is one step forward towards KVM<->TCG
      migration.
      
      Fixes: 5d0fb150Reported-by: NCédric Le Goater <clg@kaod.org>
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      (cherry picked from commit b1a568c1)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      184da186
    • G
      spapr: consolidate the VCPU id numbering logic in a single place · e676038e
      Greg Kurz 提交于
      Several places in the code need to calculate a VCPU id:
      
          (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads
          (core_id / smp_threads) * spapr->vsmt (1 user)
          index * spapr->vsmt (2 users)
      
      or guess that the VCPU id of a given VCPU is the first thread of a virtual
      core:
      
          index % spapr->vsmt != 0
      
      Even if the numbering logic isn't that complex, it is rather fragile to
      have these assumptions open-coded in several places. FWIW this was
      proved with recent issues related to VSMT.
      
      This patch moves the VCPU id formula to a single function to be called
      everywhere the code needs to compute one. It also adds an helper to
      guess if a VCPU is the first thread of a VCORE.
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      [dwg: Rename spapr_is_vcore() to spapr_is_thread0_in_vcore() for clarity]
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      (cherry picked from commit 5d0fb150)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      e676038e
    • G
      spapr: rename spapr_vcpu_id() to spapr_get_vcpu_id() · 094706e6
      Greg Kurz 提交于
      The spapr_vcpu_id() function is an accessor actually. Let's rename it
      for symmetry with the recently added spapr_set_vcpu_id() helper.
      
      The motivation behind this is that a later patch will consolidate
      the VCPU id formula in a function and spapr_vcpu_id looks like an
      appropriate name.
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      (cherry picked from commit 14bb4486)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      094706e6
    • D
      target/ppc: Clarify compat mode max_threads value · 8c0ec3c3
      David Gibson 提交于
      We recently had some discussions that were sidetracked for a while, because
      nearly everyone misapprehended the purpose of the 'max_threads' field in
      the compatiblity modes table.  It's all about guest expectations, not host
      expectations or support (that's handled elsewhere).
      
      In an attempt to avoid a repeat of that confusion, rename the field to
      'max_vthreads' and add an explanatory comment.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: NLaurent Vivier <lvivier@redhat.com>
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      Reviewed-by: NJose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
      (cherry picked from commit abbc1247)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      8c0ec3c3
    • G
      spapr: move VCPU calculation to core machine code · a8074a58
      Greg Kurz 提交于
      The VCPU ids are currently computed and assigned to each individual
      CPU threads in spapr_cpu_core_realize(). But the numbering logic
      of VCPU ids is actually a machine-level concept, and many places
      in hw/ppc/spapr.c also have to compute VCPU ids out of CPU indexes.
      
      The current formula used in spapr_cpu_core_realize() is:
      
          vcpu_id = (cc->core_id * spapr->vsmt / smp_threads) + i
      
      where:
      
          cc->core_id is a multiple of smp_threads
          cpu_index = cc->core_id + i
          0 <= i < smp_threads
      
      So we have:
      
          cpu_index % smp_threads == i
          cc->core_id / smp_threads == cpu_index / smp_threads
      
      hence:
      
          vcpu_id =
              (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads;
      
      This formula was used before VSMT at the time VCPU ids where computed
      at the target emulation level. It has the advantage of being useable
      to derive a VPCU id out of a CPU index only. It is fitted for all the
      places where the machine code has to compute a VCPU id.
      
      This patch introduces an accessor to set the VCPU id in a PowerPCCPU object
      using the above formula. It is a first step to consolidate all the VCPU id
      logic in a single place.
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      (cherry picked from commit 648edb64)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      a8074a58
    • G
      spapr: use spapr->vsmt to compute VCPU ids · cc86c467
      Greg Kurz 提交于
      Since the introduction of VSMT in 2.11, the spacing of VCPU ids
      between cores is controllable through a machine property instead
      of being only dictated by the SMT mode of the host:
      
          cpu->vcpu_id = (cc->core_id * spapr->vsmt / smp_threads) + i
      
      Until recently, the machine code would try to change the SMT mode
      of the host to be equal to VSMT or exit. This allowed the rest of
      the code to assume that kvmppc_smt_threads() == spapr->vsmt is
      always true.
      
      Recent commit "8904e5a7 spapr: Adjust default VSMT value for
      better migration compatibility" relaxed the rule. If the VSMT
      mode cannot be set in KVM for some reasons, but the requested
      CPU topology is compatible with the current SMT mode, then we
      let the guest run with  kvmppc_smt_threads() != spapr->vsmt.
      
      This breaks quite a few places in the code, in particular when
      calculating DRC indexes.
      
      This is what happens on a POWER host with subcores-per-core=2 (ie,
      supports up to SMT4) when passing the following topology:
      
          -smp threads=4,maxcpus=16 \
          -device host-spapr-cpu-core,core-id=4,id=core1 \
          -device host-spapr-cpu-core,core-id=8,id=core2
      
      qemu-system-ppc64: warning: Failed to set KVM's VSMT mode to 8 (errno -22)
      
      This is expected since KVM is limited to SMT4, but the guest is started
      anyway because this topology can run on SMT4 even with a VSMT8 spacing.
      
      But when we look at the DT, things get nastier:
      
      cpus {
              ...
              ibm,drc-indexes = <0x4 0x10000000 0x10000004 0x10000008 0x1000000c>;
      
      This means that we have the following association:
      
       CPU core device |     DRC    | VCPU id
      -----------------+------------+---------
         boot core     | 0x10000000 | 0
         core1         | 0x10000004 | 4
         core2         | 0x10000008 | 8
         core3         | 0x1000000c | 12
      
      But since the spacing of VCPU ids is 8, the DRC for core1 points to a
      VCPU that doesn't exist, the DRC for core2 points to the first VCPU of
      core1 and and so on...
      
              ...
      
              PowerPC,POWER8@0 {
                      ...
                      ibm,my-drc-index = <0x10000000>;
                      ...
              };
      
              PowerPC,POWER8@8 {
                      ...
                      ibm,my-drc-index = <0x10000008>;
                      ...
              };
      
              PowerPC,POWER8@10 {
                      ...
      
      No ibm,my-drc-index property for this core since 0x10000010 doesn't
      exist in ibm,drc-indexes above.
      
                      ...
              };
      };
      
      ...
      
      interrupt-controller {
              ...
              ibm,interrupt-server-ranges = <0x0 0x10>;
      
      With a spacing of 8, the highest VCPU id for the given topology should be:
              16 * 8 / 4 = 32 and not 16
      
              ...
              linux,phandle = <0x7e7323b8>;
              interrupt-controller;
      };
      
      And CPU hot-plug/unplug is broken:
      
      (qemu) device_del core1
      pseries-hotplug-cpu: Cannot find CPU (drc index 10000004) to remove
      
      (qemu) device_del core2
      cpu 4 (hwid 8) Ready to die...
      cpu 5 (hwid 9) Ready to die...
      cpu 6 (hwid 10) Ready to die...
      cpu 7 (hwid 11) Ready to die...
      
      These are the VCPU ids of core1 actually
      
      (qemu) device_add host-spapr-cpu-core,core-id=12,id=core3
      (qemu) device_del core3
      pseries-hotplug-cpu: Cannot find CPU (drc index 1000000c) to remove
      
      This patches all the code in hw/ppc/spapr.c to assume the VSMT
      spacing when manipulating VCPU ids.
      
      Fixes: 8904e5a7Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      
      (cherry picked from commit 72194664)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      cc86c467
    • L
      spapr: set vsmt to MAX(8, smp_threads) · c30b366d
      Laurent Vivier 提交于
      We ignore silently the value of smp_threads when we set
      the default VSMT value, and if smp_threads is greater than VSMT
      kernel is going into trouble later.
      
      Fixes: 8904e5a7
      ("spapr: Adjust default VSMT value for better migration compatibility")
      Signed-off-by: NLaurent Vivier <lvivier@redhat.com>
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      (cherry picked from commit 4ad64cbd)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      c30b366d
    • D
      spapr: Adjust default VSMT value for better migration compatibility · af65bce4
      David Gibson 提交于
      fa98fbfc "PC: KVM: Support machine option to set VSMT mode" introduced the
      "vsmt" parameter for the pseries machine type, which controls the spacing
      of the vcpu ids of thread 0 for each virtual core.  This was done to bring
      some consistency and stability to how that was done, while still allowing
      backwards compatibility for migration and otherwise.
      
      The default value we used for vsmt was set to the max of the host's
      advertised default number of threads and the number of vthreads per vcore
      in the guest.  This was done to continue running without extra parameters
      on older KVM versions which don't allow the VSMT value to be changed.
      
      Unfortunately, even that smaller than before leakage of host configuration
      into guest visible configuration still breaks things.  Specifically a guest
      with 4 (or less) vthread/vcore will get a different vsmt value when
      running on a POWER8 (vsmt==8) and POWER9 (vsmt==4) host.  That means the
      vcpu ids don't line up so you can't migrate between them, though you should
      be able to.
      
      Long term we really want to make vsmt == smp_threads for sufficiently
      new machine types.  However, that means that qemu will then require a
      sufficiently recent KVM (one which supports changing VSMT) - that's still
      not widely enough deployed to be really comfortable to do.
      
      In the meantime we need some default that will work as often as
      possible.  This patch changes that default to 8 in all circumstances.
      This does change guest visible behaviour (including for existing
      machine versions) for many cases - just not the most common/important
      case.
      
      Following is case by case justification for why this is still the least
      worst option.  Note that any of the old behaviours can still be duplicated
      after this patch, it's just that it requires manual intervention by
      setting the vsmt property on the command line.
      
      KVM HV on POWER8 host:
         This is the overwhelmingly common case in production setups, and is
         unchanged by design.  POWER8 hosts will advertise a default VSMT mode
         of 8, and > 8 vthreads/vcore isn't permitted
      
      KVM HV on POWER7 host:
         Will break, but POWER7s allowing KVM were never released to the public.
      
      KVM HV on POWER9 host:
         Not yet released to the public, breaking this now will reduce other
         breakage later.
      
      KVM HV on PowerPC 970:
         Will theoretically break it, but it was barely supported to begin with
         and already required various user visible hacks to work.  Also so old
         that I just don't care.
      
      TCG:
         This is the nastiest one; it means migration of TCG guests (without
         manual vsmt setting) will break.  Since TCG is rarely used in production
         I think this is worth it for the other benefits.  It does also remove
         one more barrier to TCG<->KVM migration which could be interesting for
         debugging applications.
      
      KVM PR:
         As with TCG, this will break migration of existing configurations,
         without adding extra manual vsmt options.  As with TCG, it is rare in
         production so I think the benefits outweigh breakages.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: NLaurent Vivier <lvivier@redhat.com>
      Reviewed-by: NJose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      (cherry picked from commit 8904e5a7)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      af65bce4
    • D
      spapr: Allow some cases where we can't set VSMT mode in the kernel · ad484114
      David Gibson 提交于
      At present if we require a vsmt mode that's not equal to the kernel's
      default, and the kernel doesn't let us change it (e.g. because it's an old
      kernel without support) then we always fail.
      
      But in fact we can cope with the kernel having a different vsmt as long as
        a) it's >= the actual number of vthreads/vcore (so that guest threads
           that are supposed to be on the same core act like it)
        b) it's a submultiple of the requested vsmt mode (so that guest threads
           spaced by the vsmt value will act like they're on different cores)
      
      Allowing this case gives us a bit more freedom to adjust the vsmt behaviour
      without breaking existing cases.
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: NLaurent Vivier <lvivier@redhat.com>
      Tested-by: NGreg Kurz <groug@kaod.org>
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      (cherry picked from commit 1f20f2e0)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      ad484114
    • G
      sdl: workaround bug in sdl 2.0.8 headers · 0a30cae5
      Gerd Hoffmann 提交于
      https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=892087Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      Message-id: 20180307154258.9313-1-kraxel@redhat.com
      (cherry picked from commit 2ca5c430)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      0a30cae5
    • P
      memfd: fix configure test · 5892b5a9
      Paolo Bonzini 提交于
      Recent glibc added memfd_create in sys/mman.h.  This conflicts with
      the definition in util/memfd.c:
      
          /builddir/build/BUILD/qemu-2.11.0-rc1/util/memfd.c:40:12: error: static declaration of memfd_create follows non-static declaration
      
      Fix the configure test, and remove the sys/memfd.h inclusion since the
      file actually does not exist---it is a typo in the memfd_create(2) man
      page.
      
      Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      (cherry picked from commit 75e5b70e)
      Signed-off-by: NGreg Kurz <groug@kaod.org>
      5892b5a9
  3. 15 2月, 2018 1 次提交
  4. 13 2月, 2018 8 次提交