1. 29 9月, 2020 2 次提交
    • M
      KVM: arm64: Use event mask matching architecture revision · fd65a3b5
      Marc Zyngier 提交于
      The PMU code suffers from a small defect where we assume that the event
      number provided by the guest is always 16 bit wide, even if the CPU only
      implements the ARMv8.0 architecture. This isn't really problematic in
      the sense that the event number ends up in a system register, cropping
      it to the right width, but still this needs fixing.
      
      In order to make it work, let's probe the version of the PMU that the
      guest is going to use. This is done by temporarily creating a kernel
      event and looking at the PMUVer field that has been saved at probe time
      in the associated arm_pmu structure. This in turn gets saved in the kvm
      structure, and subsequently used to compute the event mask that gets
      used throughout the PMU code.
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      fd65a3b5
    • M
      KVM: arm64: Refactor PMU attribute error handling · 42223fb1
      Marc Zyngier 提交于
      The PMU emulation error handling is pretty messy when dealing with
      attributes. Let's refactor it so that we have less duplication,
      and that it is easy to extend later on.
      
      A functional change is that kvm_arm_pmu_v3_init() used to return
      -ENXIO when the PMU feature wasn't set. The error is now reported
      as -ENODEV, matching the documentation. -ENXIO is still returned
      when the interrupt isn't properly configured.
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      42223fb1
  2. 16 5月, 2020 1 次提交
  3. 28 1月, 2020 4 次提交
  4. 20 10月, 2019 3 次提交
    • M
      KVM: arm64: pmu: Reset sample period on overflow handling · 8c3252c0
      Marc Zyngier 提交于
      The PMU emulation code uses the perf event sample period to trigger
      the overflow detection. This works fine  for the *first* overflow
      handling, but results in a huge number of interrupts on the host,
      unrelated to the number of interrupts handled in the guest (a x20
      factor is pretty common for the cycle counter). On a slow system
      (such as a SW model), this can result in the guest only making
      forward progress at a glacial pace.
      
      It turns out that the clue is in the name. The sample period is
      exactly that: a period. And once the an overflow has occured,
      the following period should be the full width of the associated
      counter, instead of whatever the guest had initially programed.
      
      Reset the sample period to the architected value in the overflow
      handler, which now results in a number of host interrupts that is
      much closer to the number of interrupts in the guest.
      
      Fixes: b02386eb ("arm64: KVM: Add PMU overflow interrupt routing")
      Reviewed-by: NAndrew Murray <andrew.murray@arm.com>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      8c3252c0
    • M
      KVM: arm64: pmu: Set the CHAINED attribute before creating the in-kernel event · 725ce669
      Marc Zyngier 提交于
      The current convention for KVM to request a chained event from the
      host PMU is to set bit[0] in attr.config1 (PERF_ATTR_CFG1_KVM_PMU_CHAINED).
      
      But as it turns out, this bit gets set *after* we create the kernel
      event that backs our virtual counter, meaning that we never get
      a 64bit counter.
      
      Moving the setting to an earlier point solves the problem.
      
      Fixes: 80f393a2 ("KVM: arm/arm64: Support chained PMU counters")
      Reviewed-by: NAndrew Murray <andrew.murray@arm.com>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      725ce669
    • M
      KVM: arm64: pmu: Fix cycle counter truncation · f4e23cf9
      Marc Zyngier 提交于
      When a counter is disabled, its value is sampled before the event
      is being disabled, and the value written back in the shadow register.
      
      In that process, the value gets truncated to 32bit, which is adequate
      for any counter but the cycle counter (defined as a 64bit counter).
      
      This obviously results in a corrupted counter, and things like
      "perf record -e cycles" not working at all when run in a guest...
      A similar, but less critical bug exists in kvm_pmu_get_counter_value.
      
      Make the truncation conditional on the counter not being the cycle
      counter, which results in a minor code reorganisation.
      
      Fixes: 80f393a2 ("KVM: arm/arm64: Support chained PMU counters")
      Reviewed-by: NAndrew Murray <andrew.murray@arm.com>
      Reported-by: NJulien Thierry <julien.thierry.kdev@gmail.com>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      f4e23cf9
  5. 23 7月, 2019 1 次提交
  6. 05 7月, 2019 5 次提交
  7. 19 6月, 2019 1 次提交
  8. 19 3月, 2018 1 次提交
    • C
      KVM: arm64: Rewrite system register accessors to read/write functions · 8d404c4c
      Christoffer Dall 提交于
      Currently we access the system registers array via the vcpu_sys_reg()
      macro.  However, we are about to change the behavior to some times
      modify the register file directly, so let's change this to two
      primitives:
      
       * Accessor macros vcpu_write_sys_reg() and vcpu_read_sys_reg()
       * Direct array access macro __vcpu_sys_reg()
      
      The accessor macros should be used in places where the code needs to
      access the currently loaded VCPU's state as observed by the guest.  For
      example, when trapping on cache related registers, a write to a system
      register should go directly to the VCPU version of the register.
      
      The direct array access macro can be used in places where the VCPU is
      known to never be running (for example userspace access) or for
      registers which are never context switched (for example all the PMU
      system registers).
      
      This rewrites all users of vcpu_sys_regs to one of the macros described
      above.
      
      No functional change.
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NChristoffer Dall <cdall@cs.columbia.edu>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      8d404c4c
  9. 25 7月, 2017 1 次提交
    • A
      KVM: arm/arm64: PMU: Fix overflow interrupt injection · d9f89b4e
      Andrew Jones 提交于
      kvm_pmu_overflow_set() is called from perf's interrupt handler,
      making the call of kvm_vgic_inject_irq() from it introduced with
      "KVM: arm/arm64: PMU: remove request-less vcpu kick" a really bad
      idea, as it's quite easy to try and retake a lock that the
      interrupted context is already holding. The fix is to use a vcpu
      kick, leaving the interrupt injection to kvm_pmu_sync_hwstate(),
      like it was doing before the refactoring. We don't just revert,
      though, because before the kick was request-less, leaving the vcpu
      exposed to the request-less vcpu kick race, and also because the
      kick was used unnecessarily from register access handlers.
      Reviewed-by: NChristoffer Dall <cdall@linaro.org>
      Signed-off-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      d9f89b4e
  10. 08 6月, 2017 5 次提交
  11. 04 6月, 2017 1 次提交
  12. 09 4月, 2017 1 次提交
  13. 18 11月, 2016 1 次提交
    • W
      KVM: arm64: Fix the issues when guest PMCCFILTR is configured · b112c84a
      Wei Huang 提交于
      KVM calls kvm_pmu_set_counter_event_type() when PMCCFILTR is configured.
      But this function can't deals with PMCCFILTR correctly because the evtCount
      bits of PMCCFILTR, which is reserved 0, conflits with the SW_INCR event
      type of other PMXEVTYPER<n> registers. To fix it, when eventsel == 0, this
      function shouldn't return immediately; instead it needs to check further
      if select_idx is ARMV8_PMU_CYCLE_IDX.
      
      Another issue is that KVM shouldn't copy the eventsel bits of PMCCFILTER
      blindly to attr.config. Instead it ought to convert the request to the
      "cpu cycle" event type (i.e. 0x11).
      
      To support this patch and to prevent duplicated definitions, a limited
      set of ARMv8 perf event types were relocated from perf_event.c to
      asm/perf_event.h.
      
      Cc: stable@vger.kernel.org # 4.6+
      Acked-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NWei Huang <wei@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      b112c84a
  14. 28 9月, 2016 1 次提交
  15. 20 5月, 2016 1 次提交
  16. 01 4月, 2016 1 次提交
    • W
      arm64: KVM: Add braces to multi-line if statement in virtual PMU code · 7d4bd1d2
      Will Deacon 提交于
      The kernel is written in C, not python, so we need braces around
      multi-line if statements. GCC 6 actually warns about this, thanks to the
      fantastic new "-Wmisleading-indentation" flag:
      
       | virt/kvm/arm/pmu.c: In function ‘kvm_pmu_overflow_status’:
       | virt/kvm/arm/pmu.c:198:3: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
       |    reg &= vcpu_sys_reg(vcpu, PMCNTENSET_EL0);
       |    ^~~
       | arch/arm64/kvm/../../../virt/kvm/arm/pmu.c:196:2: note: ...this ‘if’ clause, but it is not
       |   if ((vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E))
       |   ^~
      
      As it turns out, this particular case is harmless (we just do some &=
      operations with 0), but worth fixing nonetheless.
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      7d4bd1d2
  17. 01 3月, 2016 10 次提交