ARM: KVM: Enable in-kernel PMU with user space gic
cover ARM: KVM: Enable in-kernel PMU with user space gic
Andrew Jones (3):
hw/arm/virt: add pmu interrupt state target/arm/kvm: split pmu init from creation hw/arm/virt: allow pmu instantiation with userspace irqchip
hw/arm/virt.c | 13 +++++++++++-- target/arm/cpu.c | 2 ++ target/arm/cpu.h | 2 ++ target/arm/kvm.c | 6 +++++- target/arm/kvm32.c | 6 ++++++ target/arm/kvm64.c | 55 +++++++++++++++++++++++++--------------------------- target/arm/kvm_arm.h | 6 ++++++ 7 files changed, 58 insertions(+), 32 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/3 hw/arm/virt: add pmu interrupt state
Mimicking gicv3-maintenance-interrupt, add the PMU's interrupt to CPU state.
--- hw/arm/virt.c | 3 +++ target/arm/cpu.c | 2 ++ target/arm/cpu.h | 2 ++ 3 files changed, 7 insertions(+)
hw/arm/virt.c +3 -0
@@ -610,6 +610,9 @@ static void create_gic(VirtMachineState *vms, qemu_irq *pic)qdev_connect_gpio_out_named (cpudev,"gicv3-maintenance-interrupt" ,0 ,qdev_get_gpio_in (gicdev, ppibase +ARCH_GICV3_MAINT_IRQ )); +qdev_connect_gpio_out_named (cpudev,"pmu-interrupt" ,0 , +qdev_get_gpio_in (gicdev, ppibase + +VIRTUAL_PMU_IRQ ));sysbus_connect_irq (gicbusdev, i,qdev_get_gpio_in (cpudev,ARM_CPU_IRQ )); sysbus_connect_irq(gicbusdev, i + smp_cpus,
target/arm/cpu.c +2 -0
@@ -499,6 +499,8 @@ static void arm_cpu_initfn(Object *obj)qdev_init_gpio_out_named (DEVICE (cpu), &cpu->gicv3_maintenance_interrupt,"gicv3-maintenance-interrupt" ,1 ); +qdev_init_gpio_out_named (DEVICE (cpu), &cpu->pmu_interrupt, +"pmu-interrupt" ,1 );#endif /* DTB consumers generally don't in fact care what the 'compatible'
target/arm/cpu.h +2 -0
@@ -584,6 +584,8 @@ struct ARMCPU {qemu_irq gt_timer_outputs[NUM_GTIMERS ];/* GPIO output for GICv3 maintenance interrupt signal */ qemu_irq gicv3_maintenance_interrupt; +/* GPIO output for the PMU interrupt */ +qemu_irq pmu_interrupt;/* MemoryRegion to use for secure physical accesses */ MemoryRegion *secure_memory;
Signature · 1 line
1.8.3.1
Re: [Qemu-arm] [PATCH 1/3] hw/arm/virt: add pmu interrupt state
Quoted 4 lines · Andrew Jones
Mimicking gicv3-maintenance-interrupt, add the PMU's interrupt to CPU state.
Signed-off-by Andrew Jones <[email protected]>
thanks
-- PMM
PATCH 2/3 target/arm/kvm: split pmu init from creation
In reply to Andrew JonesWhen adding a PMU with a userspace irqchip we only do the INIT stage of the device creation.
--- hw/arm/virt.c | 10 ++++++++-- target/arm/kvm32.c | 6 ++++++ target/arm/kvm64.c | 52 +++++++++++++++++++++++++--------------------------- target/arm/kvm_arm.h | 6 ++++++ 4 files changed, 45 insertions(+), 29 deletions(-)
hw/arm/virt.c +8 -2
@@ -492,8 +492,14 @@ static void fdt_add_pmu_nodes(const VirtMachineState *vms)CPU_FOREACH (cpu) { armcpu =ARM_CPU (cpu); -if (!arm_feature (&armcpu->env,ARM_FEATURE_PMU ) || - (kvm_enabled () && !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ )))) { +if (!arm_feature (&armcpu->env,ARM_FEATURE_PMU )) { +return ; + } +if (kvm_enabled () && + !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) { +return ; + } +if (kvm_enabled () && !kvm_arm_pmu_init (cpu)) {return ; } }
target/arm/kvm32.c +6 -0
@@ -527,3 +527,9 @@ int kvm_arm_pmu_create(CPUState *cs, int irq)qemu_log_mask (LOG_UNIMP ,"%s: not implemented\n" , __func__);return 0 ; } + +int kvm_arm_pmu_init (CPUState *cs) +{ +qemu_log_mask (LOG_UNIMP ,"%s: not implemented\n" , __func__); +return 0 ; +}
target/arm/kvm64.c +25 -27
71 lines not on this page · raw message
target/arm/kvm_arm.h +6 -0
@@ -196,6 +196,7 @@ int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);int kvm_arm_vgic_probe (void );int kvm_arm_pmu_create (CPUState *cs,int irq); +int kvm_arm_pmu_init (CPUState *cs);#else
@@ -209,6 +210,11 @@ static inline int kvm_arm_pmu_create(CPUState *cs, int irq) return 0; } +static inline int kvm_arm_pmu_init (CPUState *cs) +{ +return 0 ; +} +#endif static inline const char *gic_class_name (void )
Signature · 1 line
1.8.3.1
Re: [Qemu-arm] [PATCH 2/3] target/arm/kvm: split pmu init from creation
Quoted 2 lines · Andrew Jones
When adding a PMU with a userspace irqchip we only do the INIT stage of the device creation.
Can you explain why? My assumption would be that either
(a) we don't need the kernel's PMU, in which case don't create it at all, or
(b) we do need the kernel's PMU, so we should both create and INIT it.
If we do one but not the other then we've left a half created and unusable PMU device in the kernel, haven't we?
thanks
-- PMM
Re: [Qemu-arm] [Qemu-devel] [PATCH 2/3] target/arm/kvm: split pmu init from creation
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Andrew Jones
When adding a PMU with a userspace irqchip we only do the INIT stage of the device creation.
Quoted 9 lines
Can you explain why? My assumption would be that either
(a) we don't need the kernel's PMU, in which case don't create it at all, or
(b) we do need the kernel's PMU, so we should both create and INIT it.If we do one but not the other then we've left a half created and unusable PMU device in the kernel, haven't we?
I should have renamed the 'create' function to 'set_irq', then it would make sense, because after the split done by this patch 'create' only sets the irq, which can only be done with an in-kernel irqchip. Both irqchip types still require INIT though, see kernel doc Documentation/virtual/kvm/devices/vcpu.txt.
I'll send a v2 that renames the create function. But, before I do, assuming the rename, do you have another comments on this or the next patch? We might as well batch all the changes :-)
Thanks,
drew
Re: [Qemu-devel] [PATCH 2/3] target/arm/kvm: split pmu init from creation
Quoted 15 lines · Andrew Jones
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Andrew Jones
When adding a PMU with a userspace irqchip we only do the INIT stage of the device creation.
Quoted 9 lines
Can you explain why? My assumption would be that either
(a) we don't need the kernel's PMU, in which case don't create it at all, or
(b) we do need the kernel's PMU, so we should both create and INIT it.If we do one but not the other then we've left a half created and unusable PMU device in the kernel, haven't we?
Quoted 5 lines
I should have renamed the 'create' function to '
set_irq', then it would make sense, because after the split done by this patch 'create' only sets the irq, which can only be done with an in-kernel irqchip. Both irqchip types still require INIT though, see kernel docDocumentation/virtual/kvm/devices/vcpu.txt.
Oh, I see, I read the commit message as "we only do the INIT stage when adding a PMU with a userspace irqchip", which isn't the same meaning as what you actually wrote. (perhaps "When adding a PMU with a userspace irqchip we skip the set-irq stage of device creation" would be clearer?)
Quoted 3 lines
I'll send a v2 that renames the create function. But, before I do, assuming the rename, do you have another comments on this or the next patch? We might as well batch all the changes :-)
I think they looked mostly OK. A minor nit:
+ if (kvm_enabled() &&
+ !kvm_arm_pmu_create(cpu, PPI(VIRTUAL_PMU_IRQ))) {
+ return;
+ }
+ if (kvm_enabled() && !kvm_arm_pmu_init(cpu)) {
return;
}might be better as
if (kvm_enabled()) {
if (!kvm_arm_pmu_create(...)) {
/* error handling */
}
if (!kvm_arm_pmu_init(...)) {
/* error handling */
}
}(and I'm not sure "silently return" is really the right error handling, but that is what we do currently, so whatever.)
thanks
-- PMM
Re: [Qemu-arm] [Qemu-devel] [PATCH 2/3] target/arm/kvm: split pmu init from creation
Quoted 43 lines · Peter Maydell
Quoted 15 lines · Andrew Jones
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Andrew Jones
When adding a PMU with a userspace irqchip we only do the INIT stage of the device creation.
Quoted 9 lines
Can you explain why? My assumption would be that either
(a) we don't need the kernel's PMU, in which case don't create it at all, or
(b) we do need the kernel's PMU, so we should both create and INIT it.If we do one but not the other then we've left a half created and unusable PMU device in the kernel, haven't we?
Quoted 5 lines
I should have renamed the 'create' function to '
set_irq', then it would make sense, because after the split done by this patch 'create' only sets the irq, which can only be done with an in-kernel irqchip. Both irqchip types still require INIT though, see kernel docDocumentation/virtual/kvm/devices/vcpu.txt.Oh, I see, I read the commit message as "we only do the INIT stage when adding a PMU with a userspace irqchip", which isn't the same meaning as what you actually wrote. (perhaps "When adding a PMU with a userspace irqchip we skip the set-irq stage of device creation" would be clearer?)
Quoted 3 lines
I'll send a v2 that renames the create function. But, before I do, assuming the rename, do you have another comments on this or the next patch? We might as well batch all the changes :-)
I think they looked mostly OK. A minor nit:
hw/arm/virt.c +5
-0+if (kvm_enabled () && + !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) { +return ; + } +if (kvm_enabled () && !kvm_arm_pmu_init (cpu)) {return ; }might be better as
Quoted 8 lines
if (kvm_enabled()) {
if (!kvm_arm_pmu_create(...)) {
/* error handling */
}
if (!kvm_arm_pmu_init(...)) {
/* error handling */
}
}With the top version I was setting things up for a one-liner change in the next patch, as only the first condition needs to have s/kvm_enabled/kvm_irqchip_in_kernel/ done to it.
Quoted 3 lines
(and I'm not sure "silently return" is really the right error handling, but that is what we do currently, so whatever.)
I'll give the error handling a bit of thought before respinning.
Thanks,
drew
PATCH 3/3 hw/arm/virt: allow pmu instantiation with userspace irqchip
In reply to Andrew JonesMove the in-kernel-irqchip test to only guard the creation, not the init'ing of the PMU. Also add the PMU to the KVM device irq line synchronization to enable its use.
--- hw/arm/virt.c | 2 +- target/arm/kvm.c | 6 +++++- target/arm/kvm64.c | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-)
hw/arm/virt.c +1 -1
@@ -495,7 +495,7 @@ static void fdt_add_pmu_nodes(const VirtMachineState *vms)if (!arm_feature (&armcpu->env,ARM_FEATURE_PMU )) {return ; } -if (kvm_enabled () && +if (kvm_irqchip_in_kernel () && !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) {return ; }
target/arm/kvm.c +5 -1
@@ -567,7 +567,11 @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) switched_level &= ~KVM_ARM_DEV_EL1_PTIMER ; } -/* XXX PMU IRQ is missing */ +if (switched_level &KVM_ARM_DEV_PMU ) { +qemu_set_irq (cpu->pmu_interrupt, + !!(run->s.regs.device_irq_level &KVM_ARM_DEV_PMU )); + switched_level &= ~KVM_ARM_DEV_PMU ; + }if (switched_level) { qemu_log_mask(LOG_UNIMP, "%s: unhandled in-kernel device IRQ %x\n",
target/arm/kvm64.c +1 -2
@@ -506,8 +506,7 @@ int kvm_arch_init_vcpu(CPUState *cs)if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_EL1_32BIT ; } -if (!kvm_irqchip_in_kernel () || - !kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { +if (!kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { cpu->has_pmu = false; }if (cpu->has_pmu) {
Signature · 1 line
1.8.3.1