From: Andrew Jones <drjones@redhat.com>
To: Shannon Zhao <zhaoshenglong@huawei.com>
Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org,
qemu-devel@nongnu.org, peter.huangpeng@huawei.com,
shannon.zhao@linaro.org
Subject: Re: [Qemu-devel] [PATCH v2 2/3] hw/arm/virt: Add PMU node for virt machine
Date: Sun, 24 Apr 2016 19:28:27 +0200 [thread overview]
Message-ID: <20160424172827.x5pmdjnsgdkivktc@hawk.localdomain> (raw)
In-Reply-To: <1461405855-15576-3-git-send-email-zhaoshenglong@huawei.com>
On Sat, Apr 23, 2016 at 06:04:14PM +0800, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
>
> Add a virtual PMU device for virt machine while use PPI 7 for PMU
> overflow interrupt number.
>
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> ---
> hw/arm/virt.c | 31 +++++++++++++++++++++++++++++++
> include/hw/arm/virt.h | 4 ++++
> include/sysemu/kvm.h | 1 +
> stubs/kvm.c | 5 +++++
> target-arm/kvm64.c | 39 +++++++++++++++++++++++++++++++++++++++
> 5 files changed, 80 insertions(+)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 56d35c7..d77b314 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -428,6 +428,35 @@ static void fdt_add_gic_node(VirtBoardInfo *vbi, int type)
> qemu_fdt_setprop_cell(vbi->fdt, "/intc", "phandle", vbi->gic_phandle);
> }
>
> +static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi)
> +{
> + CPUState *cpu;
> + ARMCPU *armcpu;
> + uint32_t irqflags = GIC_FDT_IRQ_FLAGS_LEVEL_HI;
> +
> + CPU_FOREACH(cpu) {
> + armcpu = ARM_CPU(cpu);
> + if (!armcpu->has_pmu) {
> + return;
> + }
> +
> + kvm_arm_pmu_create(cpu, PPI(VIRTUAL_PMU_IRQ));
> + }
> +
> + irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
> + GIC_FDT_IRQ_PPI_CPU_WIDTH, (1 << vbi->smp_cpus) - 1);
The shift will overflow when configuring a machine to have more than
32 cpus. You should confirm smp_cpus is <= GIC_FDT_IRQ_PPI_CPU_WIDTH
before generating a mask this way, otherwise you can just pass in 0xff.
> +
> + armcpu = ARM_CPU(qemu_get_cpu(0));
> + qemu_fdt_add_subnode(vbi->fdt, "/pmu");
> + if (arm_feature(&armcpu->env, ARM_FEATURE_V8)) {
> + const char compat[] = "arm,armv8-pmuv3";
> + qemu_fdt_setprop(vbi->fdt, "/pmu", "compatible",
> + compat, sizeof(compat));
> + qemu_fdt_setprop_cells(vbi->fdt, "/pmu", "interrupts",
> + GIC_FDT_IRQ_TYPE_PPI, VIRTUAL_PMU_IRQ, irqflags);
> + }
> +}
> +
> static void create_v2m(VirtBoardInfo *vbi, qemu_irq *pic)
> {
> int i;
> @@ -1246,6 +1275,8 @@ static void machvirt_init(MachineState *machine)
>
> create_gic(vbi, pic, gic_version, vms->secure);
>
> + fdt_add_pmu_nodes(vbi);
> +
> create_uart(vbi, pic, VIRT_UART, sysmem);
>
> if (vms->secure) {
> diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
> index ecd8589..b50f095 100644
> --- a/include/hw/arm/virt.h
> +++ b/include/hw/arm/virt.h
> @@ -40,6 +40,10 @@
> #define ARCH_TIMER_NS_EL1_IRQ 14
> #define ARCH_TIMER_NS_EL2_IRQ 10
>
> +#define VIRTUAL_PMU_IRQ 7
> +
> +#define PPI(irq) ((irq) + 16)
> +
> enum {
> VIRT_FLASH,
> VIRT_MEM,
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 0e18f15..90c2c54 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -523,4 +523,5 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);
> * Returns: 0 on success, or a negative errno on failure.
> */
> int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target);
> +void kvm_arm_pmu_create(CPUState *cs, int irq);
> #endif
> diff --git a/stubs/kvm.c b/stubs/kvm.c
> index ddd6204..58a348a 100644
> --- a/stubs/kvm.c
> +++ b/stubs/kvm.c
> @@ -6,3 +6,8 @@ int kvm_arch_irqchip_create(MachineState *ms, KVMState *s)
> {
> return 0;
> }
> +
> +void kvm_arm_pmu_create(CPUState *cs, int irq)
> +{
> + return;
> +}
> diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c
> index b364789..faec4fa 100644
> --- a/target-arm/kvm64.c
> +++ b/target-arm/kvm64.c
> @@ -382,6 +382,45 @@ static CPUWatchpoint *find_hw_watchpoint(CPUState *cpu, target_ulong addr)
> return NULL;
> }
>
> +static bool kvm_arm_pmu_support_ctrl(CPUState *cs, struct kvm_device_attr *attr)
> +{
> + return kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr) == 0;
> +}
> +
> +void kvm_arm_pmu_create(CPUState *cs, int irq)
> +{
> + int err;
> +
> + struct kvm_device_attr attr = {
> + .group = KVM_ARM_VCPU_PMU_V3_CTRL,
> + .addr = (intptr_t)&irq,
> + .attr = KVM_ARM_VCPU_PMU_V3_IRQ,
> + .flags = 0,
> + };
> +
> + if (!kvm_arm_pmu_support_ctrl(cs, &attr)) {
> + return;
> + }
> +
> + err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, &attr);
> + if (err < 0) {
> + fprintf(stderr, "KVM_{SET/GET}_DEVICE_ATTR failed: %s\n",
You know it's a KVM_SET_DEVICE_ATTR here, so why report SET/GET?
> + strerror(-err));
> + abort();
> + }
> +
> + attr.group = KVM_ARM_VCPU_PMU_V3_CTRL;
> + attr.attr = KVM_ARM_VCPU_PMU_V3_INIT;
> + attr.addr = 0;
> + attr.flags = 0;
> +
> + err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, &attr);
> + if (err < 0) {
> + fprintf(stderr, "KVM_{SET/GET}_DEVICE_ATTR failed: %s\n",
Same SET comment as above.
> + strerror(-err));
> + abort();
> + }
> +}
>
> static inline void set_feature(uint64_t *features, int feature)
> {
> --
> 2.0.4
>
>
Thanks,
drew
next prev parent reply other threads:[~2016-04-24 17:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-23 10:04 [Qemu-devel] [PATCH v2 0/3] Add guest PMU in machine virt Shannon Zhao
2016-04-23 10:04 ` [Qemu-devel] [PATCH v2 1/3] target-arm: kvm64: set guest PMUv3 feature bit if supported Shannon Zhao
2016-04-24 17:17 ` Andrew Jones
2016-04-23 10:04 ` [Qemu-devel] [PATCH v2 2/3] hw/arm/virt: Add PMU node for virt machine Shannon Zhao
2016-04-24 17:28 ` Andrew Jones [this message]
2016-04-25 6:52 ` Shannon Zhao
2016-04-25 9:05 ` Andrew Jones
2016-04-23 10:04 ` [Qemu-devel] [PATCH v2 3/3] hw/arm/virt-acpi-build: Add PMU IRQ number in ACPI table Shannon Zhao
2016-04-24 17:29 ` Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160424172827.x5pmdjnsgdkivktc@hawk.localdomain \
--to=drjones@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=shannon.zhao@linaro.org \
--cc=zhaoshenglong@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).