Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/devicetree/bindings/arm/pmu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ properties:
- apple,blizzard-pmu
- apple,firestorm-pmu
- apple,icestorm-pmu
- apple,t8140-pmu
- arm,armv8-pmuv3 # Only for s/w models
- arm,arm1136-pmu
- arm,arm1176-pmu
Expand Down
6 changes: 6 additions & 0 deletions arch/arm64/boot/dts/apple/t8140.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@
<AIC_FIQ AIC_TMR_HV_VIRT IRQ_TYPE_LEVEL_HIGH>;
};

pmu {
compatible = "apple,t8140-pmu";
interrupt-parent = <&aic>;
interrupts = <AIC_FIQ AIC_CPU_PMU_P IRQ_TYPE_LEVEL_HIGH>;
};

clkref: clock-ref {
compatible = "fixed-clock";
#clock-cells = <0>;
Expand Down
7 changes: 3 additions & 4 deletions arch/arm64/kernel/cpu_errata.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ static const struct midr_range apple_cpus[] = {
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_PRO),
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_MAX),
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_MAX),
MIDR_ALL_VERSIONS(MIDR_APPLE_TAHITI_E),
MIDR_ALL_VERSIONS(MIDR_APPLE_TAHITI_P),
{},
};

Expand All @@ -307,10 +309,7 @@ static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int sco
return is_midr_in_range_list(apple_cpus);
}

/*
* Apple cores with the same vGIC as M1/M2 that aren't in apple_cpus yet:
* that list also turns on the IMPDEF PMUv3 traps, unverified here.
*/
/* Apple cores with the same vGIC as M1/M2 that are not in apple_cpus. */
static const struct midr_range apple_broken_seis_cpus[] = {
MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_E),
MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_P),
Expand Down
40 changes: 33 additions & 7 deletions arch/arm64/kvm/hyp/pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,19 @@ static bool stage2_unmap_defer_tlb_flush(struct kvm_pgtable *pgt)
return system_supports_tlb_range() && cpus_have_final_cap(ARM64_HAS_STAGE2_FWB);
}

struct stage2_unmap_data {
struct kvm_pgtable *pgt;

/* IPA span of the leaves whose TLB invalidation was deferred */
u64 flush_start;
u64 flush_end;
};

static void stage2_unmap_put_pte(const struct kvm_pgtable_visit_ctx *ctx,
struct kvm_s2_mmu *mmu,
struct kvm_pgtable_mm_ops *mm_ops)
{
struct kvm_pgtable *pgt = ctx->arg;
struct stage2_unmap_data *data = ctx->arg;

/*
* Clear the existing PTE, and perform break-before-make if it was
Expand All @@ -908,9 +916,15 @@ static void stage2_unmap_put_pte(const struct kvm_pgtable_visit_ctx *ctx,
if (kvm_pte_table(ctx->old, ctx->level)) {
kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, ctx->addr,
TLBI_TTL_UNKNOWN);
} else if (!stage2_unmap_defer_tlb_flush(pgt)) {
} else if (!stage2_unmap_defer_tlb_flush(data->pgt)) {
kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, ctx->addr,
ctx->level);
} else {
u64 granule = kvm_granule_size(ctx->level);
u64 start = ALIGN_DOWN(ctx->addr, granule);

data->flush_start = min(data->flush_start, start);
data->flush_end = max(data->flush_end, start + granule);
}
}

Expand Down Expand Up @@ -1155,7 +1169,8 @@ int kvm_pgtable_stage2_annotate(struct kvm_pgtable *pgt, u64 addr, u64 size,
static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx,
enum kvm_pgtable_walk_flags visit)
{
struct kvm_pgtable *pgt = ctx->arg;
struct stage2_unmap_data *data = ctx->arg;
struct kvm_pgtable *pgt = data->pgt;
struct kvm_s2_mmu *mmu = pgt->mmu;
struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops;
kvm_pte_t *childp = NULL;
Expand Down Expand Up @@ -1198,16 +1213,27 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx,
int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size)
{
int ret;
struct stage2_unmap_data data = {
.pgt = pgt,
.flush_start = U64_MAX,
};
struct kvm_pgtable_walker walker = {
.cb = stage2_unmap_walker,
.arg = pgt,
.arg = &data,
.flags = KVM_PGTABLE_WALK_LEAF | KVM_PGTABLE_WALK_TABLE_POST,
};

ret = kvm_pgtable_walk(pgt, addr, size, &walker);
if (stage2_unmap_defer_tlb_flush(pgt))
/* Perform the deferred TLB invalidations */
kvm_tlb_flush_vmid_range(pgt->mmu, addr, size);

/*
* Perform the deferred TLB invalidations, for the leaves the walk
* actually cleared: a walk over an unmapped range, such as the
* whole-IPA-space unmap of a sparse nested stage 2 on every MMU
* notifier event, needs none.
*/
if (data.flush_end > data.flush_start)
kvm_tlb_flush_vmid_range(pgt->mmu, data.flush_start,
data.flush_end - data.flush_start);

return ret;
}
Expand Down
82 changes: 79 additions & 3 deletions drivers/perf/apple_m1_cpu_pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@ static const u16 m1_pmu_pmceid_map[ARMV8_PMUV3_MAX_COMMON_EVENTS] = {
M1_PMUV3_EVENT_MAP(BR_MIS_PRED_RETIRED, BRANCH_MISPRED_NONSPEC),
};

/*
* A18 Pro (T8140) cores: PMC0 and PMC1 count cycles and instructions like
* the M1/M2 fixed counters, all ten counters are 64 bits wide and PMCR0 has
* the M2 layout (measured on hardware). The event numbers of the
* programmable counters are not known for these cores, so only the two fixed
* counters are offered. A single PMU instance covers both clusters so perf
* events (including KVM's backing events) keep counting when a task migrates.
* This does not establish compatibility for any programmable events.
*/
static const u16 tahiti_pmu_event_affinity[M1_PMU_PERFCTR_LAST + 1] = {
[M1_PMU_PERFCTR_CORE_ACTIVE_CYCLE] = BIT(0),
[M1_PMU_PERFCTR_INST_ALL] = BIT(1),
};

static const unsigned int tahiti_pmu_perf_map[PERF_COUNT_HW_MAX] = {
PERF_MAP_ALL_UNSUPPORTED,
[PERF_COUNT_HW_CPU_CYCLES] = M1_PMU_PERFCTR_CORE_ACTIVE_CYCLE,
[PERF_COUNT_HW_INSTRUCTIONS] = M1_PMU_PERFCTR_INST_ALL,
};

/* sysfs definitions */
static ssize_t m1_pmu_events_sysfs_show(struct device *dev,
struct device_attribute *attr,
Expand Down Expand Up @@ -493,11 +513,12 @@ static void m1_pmu_write_counter(struct perf_event *event, u64 value)
isb();
}

static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
struct perf_event *event)
static int __m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
struct perf_event *event,
const u16 *event_affinity)
{
unsigned long evtype = event->hw.config_base & M1_PMU_CFG_EVENT;
unsigned long affinity = m1_pmu_event_affinity[evtype];
unsigned long affinity = event_affinity[evtype];
int idx;

/*
Expand All @@ -516,6 +537,18 @@ static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
return -EAGAIN;
}

static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
struct perf_event *event)
{
return __m1_pmu_get_event_idx(cpuc, event, m1_pmu_event_affinity);
}

static int tahiti_pmu_get_event_idx(struct pmu_hw_events *cpuc,
struct perf_event *event)
{
return __m1_pmu_get_event_idx(cpuc, event, tahiti_pmu_event_affinity);
}

static void m1_pmu_clear_event_idx(struct pmu_hw_events *cpuc,
struct perf_event *event)
{
Expand Down Expand Up @@ -565,6 +598,18 @@ static int m2_pmu_map_event(struct perf_event *event)
return armpmu_map_event(event, &m1_pmu_perf_map, NULL, M1_PMU_CFG_EVENT);
}

static int tahiti_pmu_map_event(struct perf_event *event)
{
int ret;

event->hw.flags |= ARMPMU_EVT_63BIT;
ret = armpmu_map_event(event, &tahiti_pmu_perf_map, NULL, M1_PMU_CFG_EVENT);
if (ret >= 0 && !tahiti_pmu_event_affinity[ret])
return -ENOENT;

return ret;
}

static int m1_pmu_map_pmuv3_event(unsigned int eventsel)
{
u16 m1_event = HW_OP_UNSUPPORTED;
Expand All @@ -575,6 +620,18 @@ static int m1_pmu_map_pmuv3_event(unsigned int eventsel)
return m1_event == HW_OP_UNSUPPORTED ? -EOPNOTSUPP : m1_event;
}

static int tahiti_pmu_map_pmuv3_event(unsigned int eventsel)
{
switch (eventsel) {
case ARMV8_PMUV3_PERFCTR_CPU_CYCLES:
return M1_PMU_PERFCTR_CORE_ACTIVE_CYCLE;
case ARMV8_PMUV3_PERFCTR_INST_RETIRED:
return M1_PMU_PERFCTR_INST_ALL;
default:
return -EOPNOTSUPP;
}
}

static void m1_pmu_init_pmceid(struct arm_pmu *pmu)
{
unsigned int event;
Expand Down Expand Up @@ -679,7 +736,26 @@ static int m2_pmu_blizzard_init(struct arm_pmu *cpu_pmu)
return m1_pmu_init(cpu_pmu, ARMPMU_EVT_63BIT);
}

static int tahiti_pmu_init(struct arm_pmu *cpu_pmu)
{
int ret = m1_pmu_init(cpu_pmu, ARMPMU_EVT_63BIT);

if (ret)
return ret;

/* Both clusters share only the verified fixed-counter interface. */
cpu_pmu->name = "apple_t8140_pmu";
cpu_pmu->get_event_idx = tahiti_pmu_get_event_idx;
cpu_pmu->map_event = tahiti_pmu_map_event;
cpu_pmu->map_pmuv3_event = tahiti_pmu_map_pmuv3_event;
bitmap_zero(cpu_pmu->pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
set_bit(ARMV8_PMUV3_PERFCTR_CPU_CYCLES, cpu_pmu->pmceid_bitmap);
set_bit(ARMV8_PMUV3_PERFCTR_INST_RETIRED, cpu_pmu->pmceid_bitmap);
return 0;
}

static const struct of_device_id m1_pmu_of_device_ids[] = {
{ .compatible = "apple,t8140-pmu", .data = tahiti_pmu_init, },
{ .compatible = "apple,avalanche-pmu", .data = m2_pmu_avalanche_init, },
{ .compatible = "apple,blizzard-pmu", .data = m2_pmu_blizzard_init, },
{ .compatible = "apple,icestorm-pmu", .data = m1_pmu_ice_init, },
Expand Down