From: Christoffer Dall <cdall@linaro.org>
To: Andrew Jones <drjones@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
peter.maydell@linaro.org, agraf@suse.de
Subject: Re: [Qemu-devel] [PATCH v2 4/4] target/arm/kvm: pmu: improve error handling
Date: Fri, 21 Jul 2017 13:29:29 +0200 [thread overview]
Message-ID: <20170721112929.GD16350@cbox> (raw)
In-Reply-To: <1500471597-2517-5-git-send-email-drjones@redhat.com>
On Wed, Jul 19, 2017 at 09:39:57AM -0400, Andrew Jones wrote:
> If a KVM PMU init or set-irq attr call fails we just silently stop
> the PMU DT node generation. The only way they could fail, though,
> is if the attr's respective KVM has-attr call fails. But that should
> never happen if KVM advertises the PMU capability, because both
> attrs have been available since the capability was introduced. Let's
> just abort if this should-never-happen stuff does happen, because,
> if it does, then something is obviously horribly wrong.
>
> Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
> ---
> hw/arm/virt.c | 9 +++------
> target/arm/kvm32.c | 3 +--
> target/arm/kvm64.c | 28 ++++++++++++++++++++--------
> target/arm/kvm_arm.h | 15 ++++-----------
> 4 files changed, 28 insertions(+), 27 deletions(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index a215330444da..4bc50964d52b 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -496,13 +496,10 @@ static void fdt_add_pmu_nodes(const VirtMachineState *vms)
> return;
> }
> if (kvm_enabled()) {
> - if (kvm_irqchip_in_kernel() &&
> - !kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ))) {
> - return;
> - }
> - if (!kvm_arm_pmu_init(cpu)) {
> - return;
> + if (kvm_irqchip_in_kernel()) {
> + kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ));
> }
> + kvm_arm_pmu_init(cpu);
> }
> }
>
> diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
> index e3aab89a1a94..717a2562670b 100644
> --- a/target/arm/kvm32.c
> +++ b/target/arm/kvm32.c
> @@ -522,10 +522,9 @@ bool kvm_arm_hw_debug_active(CPUState *cs)
> return false;
> }
>
> -int kvm_arm_pmu_set_irq(CPUState *cs, int irq)
> +void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
> {
> qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
> - return 0;
> }
>
> int kvm_arm_pmu_init(CPUState *cs)
> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
> index ec7d85314acc..6554c30007a4 100644
> --- a/target/arm/kvm64.c
> +++ b/target/arm/kvm64.c
> @@ -387,30 +387,36 @@ static bool kvm_arm_pmu_set_attr(CPUState *cs, struct kvm_device_attr *attr)
>
> err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr);
> if (err != 0) {
> + error_report("PMU: KVM_HAS_DEVICE_ATTR: %s", strerror(-err));
> return false;
> }
>
> err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr);
> - if (err < 0) {
> - fprintf(stderr, "KVM_SET_DEVICE_ATTR failed: %s\n",
> - strerror(-err));
> - abort();
> + if (err != 0) {
> + error_report("PMU: KVM_SET_DEVICE_ATTR: %s", strerror(-err));
> + return false;
> }
>
> return true;
> }
>
> -int kvm_arm_pmu_init(CPUState *cs)
> +void kvm_arm_pmu_init(CPUState *cs)
> {
> struct kvm_device_attr attr = {
> .group = KVM_ARM_VCPU_PMU_V3_CTRL,
> .attr = KVM_ARM_VCPU_PMU_V3_INIT,
> };
>
> - return kvm_arm_pmu_set_attr(cs, &attr);
> + if (!ARM_CPU(cs)->has_pmu) {
> + return;
> + }
> + if (!kvm_arm_pmu_set_attr(cs, &attr)) {
> + error_report("failed to init PMU");
> + abort();
> + }
> }
>
> -int kvm_arm_pmu_set_irq(CPUState *cs, int irq)
> +void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
> {
> struct kvm_device_attr attr = {
> .group = KVM_ARM_VCPU_PMU_V3_CTRL,
> @@ -418,7 +424,13 @@ int kvm_arm_pmu_set_irq(CPUState *cs, int irq)
> .attr = KVM_ARM_VCPU_PMU_V3_IRQ,
> };
>
> - return kvm_arm_pmu_set_attr(cs, &attr);
> + if (!ARM_CPU(cs)->has_pmu) {
> + return;
> + }
> + if (!kvm_arm_pmu_set_attr(cs, &attr)) {
> + error_report("failed to set irq for PMU");
> + abort();
> + }
> }
>
> static inline void set_feature(uint64_t *features, int feature)
> diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
> index cab5ea9be55c..ff53e9fafb7a 100644
> --- a/target/arm/kvm_arm.h
> +++ b/target/arm/kvm_arm.h
> @@ -195,8 +195,8 @@ int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);
>
> int kvm_arm_vgic_probe(void);
>
> -int kvm_arm_pmu_set_irq(CPUState *cs, int irq);
> -int kvm_arm_pmu_init(CPUState *cs);
> +void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
> +void kvm_arm_pmu_init(CPUState *cs);
>
> #else
>
> @@ -205,15 +205,8 @@ static inline int kvm_arm_vgic_probe(void)
> return 0;
> }
>
> -static inline int kvm_arm_pmu_set_irq(CPUState *cs, int irq)
> -{
> - return 0;
> -}
> -
> -static inline int kvm_arm_pmu_init(CPUState *cs)
> -{
> - return 0;
> -}
> +static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq) {}
> +static inline void kvm_arm_pmu_init(CPUState *cs) {}
>
> #endif
>
> --
> 1.8.3.1
>
next prev parent reply other threads:[~2017-07-21 11:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-19 13:39 [Qemu-devel] [PATCH v2 0/4] ARM: KVM: Enable in-kernel PMU with user space gic Andrew Jones
2017-07-19 13:39 ` [Qemu-devel] [PATCH v2 1/4] hw/arm/virt: add pmu interrupt state Andrew Jones
2017-07-21 11:16 ` Christoffer Dall
2017-07-21 11:35 ` Andrew Jones
2017-07-21 12:01 ` Christoffer Dall
2017-07-19 13:39 ` [Qemu-devel] [PATCH v2 2/4] target/arm/kvm: pmu: split init and set-irq stages Andrew Jones
2017-07-21 11:25 ` Christoffer Dall
2017-07-19 13:39 ` [Qemu-devel] [PATCH v2 3/4] hw/arm/virt: allow pmu instantiation with userspace irqchip Andrew Jones
2017-07-21 11:28 ` Christoffer Dall
2017-07-19 13:39 ` [Qemu-devel] [PATCH v2 4/4] target/arm/kvm: pmu: improve error handling Andrew Jones
2017-07-21 11:29 ` Christoffer Dall [this message]
2017-09-04 14:17 ` Peter Maydell
2017-09-05 14:44 ` Andrew Jones
2017-07-19 15:14 ` [Qemu-devel] [PATCH v2 0/4] ARM: KVM: Enable in-kernel PMU with user space gic no-reply
2017-08-08 13:23 ` Andrew Jones
2017-08-17 10:41 ` Peter Maydell
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=20170721112929.GD16350@cbox \
--to=cdall@linaro.org \
--cc=agraf@suse.de \
--cc=drjones@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).