arm: enable PMU partitioning
RFC PATCH 1/1 arm: enable PMU partitioning
This sets the vCPU device attribute to unconditionally enable partitioning when a PMU is available on an ARM host.
Note that this patch is experimental to demonstrate the API. That is why it aborts immediately if the call does not succeed.
For the call to succeed, the host must be running a kernel with the ARM64 PMU Partitioning feature [1] and set the kernel command line arm_pmuv3.reserved_host_counters=n where n is between 0 and the number of counters on the system, inclusive.
[1] https://lore.kernel.org/kvmarm/[email protected]/
Signed-off-by Colton Lewis <[email protected]>
--- hw/arm/virt.c | 1 + linux-headers/asm-arm64/kvm.h | 2 ++ target/arm/kvm-stub.c | 5 +++++ target/arm/kvm.c | 18 ++++++++++++++++++ target/arm/kvm_arm.h | 1 + 5 files changed, 27 insertions(+)
hw/arm/virt.c +1 -0
@@ -2234,6 +2234,7 @@ static void virt_post_cpus_gic_realized(VirtMachineState *vms,if (kvm_irqchip_in_kernel ()) {kvm_arm_pmu_set_irq (ARM_CPU (cpu),VIRTUAL_PMU_IRQ ); } +kvm_arm_pmu_set_partition (ARM_CPU (cpu), true);kvm_arm_pmu_init (ARM_CPU (cpu)); }if (steal_time) {
linux-headers/asm-arm64/kvm.h +2 -0
@@ -424,6 +424,8 @@ enum {#define KVM_ARM_VCPU_PMU_V3_FILTER 2#define KVM_ARM_VCPU_PMU_V3_SET_PMU 3#define KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS 4 +#define KVM_ARM_VCPU_PMU_V3_ENABLE_PARTITION 5 +#define KVM_ARM_VCPU_TIMER_CTRL 1#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
target/arm/kvm-stub.c +5 -0
@@ -80,6 +80,11 @@ void kvm_arm_pmu_set_irq(ARMCPU *cpu, int irq)g_assert_not_reached (); } +void kvm_arm_pmu_set_partition (ARMCPU *cpu,bool partition) +{ +g_assert_not_reached (); +} +void kvm_arm_pmu_init (ARMCPU *cpu) {g_assert_not_reached ();
target/arm/kvm.c +18 -0
@@ -1817,6 +1817,24 @@ void kvm_arm_pmu_set_irq(ARMCPU *cpu, int irq) } } +void kvm_arm_pmu_set_partition (ARMCPU *cpu,bool partition) +{ +struct kvm_device_attr part_attr = { + .group =KVM_ARM_VCPU_PMU_V3_CTRL , + .attr =KVM_ARM_VCPU_PMU_V3_ENABLE_PARTITION , + .addr = (uint64_t )&partition + }; + +if (!cpu->has_pmu) { +return ; + } + +if (!kvm_arm_set_device_attr (cpu, &part_attr,"PMU partition" )) { +error_report ("failed to set PMU partition" ); +abort (); + } +} +void kvm_arm_pvtime_init (ARMCPU *cpu,uint64_t ipa) {struct kvm_device_attr attr = {
target/arm/kvm_arm.h +1 -0
@@ -248,6 +248,7 @@ int kvm_arm_vgic_probe(void);void kvm_arm_pmu_init (ARMCPU *cpu);void kvm_arm_pmu_set_irq (ARMCPU *cpu,int irq); +void kvm_arm_pmu_set_partition (ARMCPU *cpu,bool partition);/** * kvm_arm_pvtime_init:
base-commit: afe653676dc6dfd49f0390239ff90b2f0052c2b8
Signature · 1 line
2.53.0.414.gf7e9f6c205-goog