From nobody Sun May 5 15:32:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500472252499719.8256803367638; Wed, 19 Jul 2017 06:50:52 -0700 (PDT) Received: from localhost ([::1]:33539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpNL-0003su-8X for importer@patchew.org; Wed, 19 Jul 2017 09:50:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpLO-0002Bn-4q for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:48:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXpLN-0008Jx-Bk for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:48:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44124) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXpLI-0008Hn-UF; Wed, 19 Jul 2017 09:48:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EDF47CB84; Wed, 19 Jul 2017 13:39:59 +0000 (UTC) Received: from cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com (cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com [10.16.185.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBDA860606; Wed, 19 Jul 2017 13:39:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9EDF47CB84 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=drjones@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9EDF47CB84 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Wed, 19 Jul 2017 09:39:54 -0400 Message-Id: <1500471597-2517-2-git-send-email-drjones@redhat.com> In-Reply-To: <1500471597-2517-1-git-send-email-drjones@redhat.com> References: <1500471597-2517-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 19 Jul 2017 13:39:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/4] hw/arm/virt: add pmu interrupt state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, agraf@suse.de, cdall@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Mimicking gicv3-maintenance-interrupt, add the PMU's interrupt to CPU state. Signed-off-by: Andrew Jones Reviewed-by: Peter Maydell --- hw/arm/virt.c | 3 +++ target/arm/cpu.c | 2 ++ target/arm/cpu.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 31739d75a3e0..ea26f0c473c2 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -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_IR= Q)); + qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, + qdev_get_gpio_in(gicdev, ppibase + + VIRTUAL_PMU_IRQ)); =20 sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_= IRQ)); sysbus_connect_irq(gicbusdev, i + smp_cpus, diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 96d1f840301f..fd82c7944840 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -499,6 +499,8 @@ static void arm_cpu_initfn(Object *obj) =20 qdev_init_gpio_out_named(DEVICE(cpu), &cpu->gicv3_maintenance_interrup= t, "gicv3-maintenance-interrupt", 1); + qdev_init_gpio_out_named(DEVICE(cpu), &cpu->pmu_interrupt, + "pmu-interrupt", 1); #endif =20 /* DTB consumers generally don't in fact care what the 'compatible' diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 102c58afac52..8d91166eb97b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -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; =20 /* MemoryRegion to use for secure physical accesses */ MemoryRegion *secure_memory; --=20 1.8.3.1 From nobody Sun May 5 15:32:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500472129916440.2705910146766; Wed, 19 Jul 2017 06:48:49 -0700 (PDT) Received: from localhost ([::1]:33528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpLL-0001od-Da for importer@patchew.org; Wed, 19 Jul 2017 09:48:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpK7-0001IN-0Z for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:47:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXpK5-00081W-Vm for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:47:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXpK0-000804-Cx; Wed, 19 Jul 2017 09:47:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72419C04B938; Wed, 19 Jul 2017 13:40:00 +0000 (UTC) Received: from cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com (cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com [10.16.185.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF58553CE3; Wed, 19 Jul 2017 13:39:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72419C04B938 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=drjones@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 72419C04B938 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Wed, 19 Jul 2017 09:39:55 -0400 Message-Id: <1500471597-2517-3-git-send-email-drjones@redhat.com> In-Reply-To: <1500471597-2517-1-git-send-email-drjones@redhat.com> References: <1500471597-2517-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 19 Jul 2017 13:40:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/4] target/arm/kvm: pmu: split init and set-irq stages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, agraf@suse.de, cdall@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When adding a PMU with a userspace irqchip we skip the set-irq stage of device creation. Split the 'create' function into two functions 'init' and 'set-irq' so they may be called separately. Signed-off-by: Andrew Jones Reviewed-by: Christoffer Dall --- hw/arm/virt.c | 11 +++++++++-- target/arm/kvm32.c | 8 +++++++- target/arm/kvm64.c | 52 +++++++++++++++++++++++++-----------------------= ---- target/arm/kvm_arm.h | 10 ++++++++-- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ea26f0c473c2..7157a028adce 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -492,10 +492,17 @@ static void fdt_add_pmu_nodes(const VirtMachineState = *vms) =20 CPU_FOREACH(cpu) { armcpu =3D 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()) { + if (!kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ))) { + return; + } + if (!kvm_arm_pmu_init(cpu)) { + return; + } + } } =20 if (vms->gic_version =3D=3D 2) { diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c index 069da0c5fd10..e3aab89a1a94 100644 --- a/target/arm/kvm32.c +++ b/target/arm/kvm32.c @@ -522,7 +522,13 @@ bool kvm_arm_hw_debug_active(CPUState *cs) return false; } =20 -int kvm_arm_pmu_create(CPUState *cs, int irq) +int 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) { qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__); return 0; diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index a16abc8d129e..e26638a6fac1 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -381,46 +381,44 @@ static CPUWatchpoint *find_hw_watchpoint(CPUState *cp= u, target_ulong addr) return NULL; } =20 -static bool kvm_arm_pmu_support_ctrl(CPUState *cs, struct kvm_device_attr = *attr) -{ - return kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr) =3D=3D 0; -} - -int kvm_arm_pmu_create(CPUState *cs, int irq) +static bool kvm_arm_pmu_set_attr(CPUState *cs, struct kvm_device_attr *att= r) { int err; =20 - struct kvm_device_attr attr =3D { - .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, - .addr =3D (intptr_t)&irq, - .attr =3D KVM_ARM_VCPU_PMU_V3_IRQ, - .flags =3D 0, - }; - - if (!kvm_arm_pmu_support_ctrl(cs, &attr)) { - return 0; + err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); + if (err !=3D 0) { + return false; } =20 - err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, &attr); + err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr); if (err < 0) { fprintf(stderr, "KVM_SET_DEVICE_ATTR failed: %s\n", strerror(-err)); abort(); } =20 - attr.group =3D KVM_ARM_VCPU_PMU_V3_CTRL; - attr.attr =3D KVM_ARM_VCPU_PMU_V3_INIT; - attr.addr =3D 0; - attr.flags =3D 0; + return true; +} =20 - err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, &attr); - if (err < 0) { - fprintf(stderr, "KVM_SET_DEVICE_ATTR failed: %s\n", - strerror(-err)); - abort(); - } +int kvm_arm_pmu_init(CPUState *cs) +{ + struct kvm_device_attr attr =3D { + .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, + .attr =3D KVM_ARM_VCPU_PMU_V3_INIT, + }; + + return kvm_arm_pmu_set_attr(cs, &attr); +} + +int kvm_arm_pmu_set_irq(CPUState *cs, int irq) +{ + struct kvm_device_attr attr =3D { + .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, + .addr =3D (intptr_t)&irq, + .attr =3D KVM_ARM_VCPU_PMU_V3_IRQ, + }; =20 - return 1; + return kvm_arm_pmu_set_attr(cs, &attr); } =20 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 633d08828a5d..cab5ea9be55c 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -195,7 +195,8 @@ int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu); =20 int kvm_arm_vgic_probe(void); =20 -int kvm_arm_pmu_create(CPUState *cs, int irq); +int kvm_arm_pmu_set_irq(CPUState *cs, int irq); +int kvm_arm_pmu_init(CPUState *cs); =20 #else =20 @@ -204,7 +205,12 @@ static inline int kvm_arm_vgic_probe(void) return 0; } =20 -static inline int kvm_arm_pmu_create(CPUState *cs, int irq) +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; } --=20 1.8.3.1 From nobody Sun May 5 15:32:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500472246516219.94273682394737; Wed, 19 Jul 2017 06:50:46 -0700 (PDT) Received: from localhost ([::1]:33534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpMr-0003PU-9P for importer@patchew.org; Wed, 19 Jul 2017 09:50:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpKn-0001iL-7L for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXpKm-00089j-A2 for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:48:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXpKg-00087u-0B; Wed, 19 Jul 2017 09:48:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 914812FFC2A; Wed, 19 Jul 2017 13:40:01 +0000 (UTC) Received: from cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com (cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com [10.16.185.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id 944DA17DE8; Wed, 19 Jul 2017 13:40:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 914812FFC2A Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=drjones@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 914812FFC2A From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Wed, 19 Jul 2017 09:39:56 -0400 Message-Id: <1500471597-2517-4-git-send-email-drjones@redhat.com> In-Reply-To: <1500471597-2517-1-git-send-email-drjones@redhat.com> References: <1500471597-2517-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 19 Jul 2017 13:40:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/4] hw/arm/virt: allow pmu instantiation with userspace irqchip X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, agraf@suse.de, cdall@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the in-kernel-irqchip test to only guard the set-irq stage, not the init stage of the PMU. Also add the PMU to the KVM device irq line synchronization to enable its use. Signed-off-by: Andrew Jones Reviewed-by: Christoffer Dall --- hw/arm/virt.c | 3 ++- target/arm/kvm.c | 6 +++++- target/arm/kvm64.c | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 7157a028adce..a215330444da 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -496,7 +496,8 @@ static void fdt_add_pmu_nodes(const VirtMachineState *v= ms) return; } if (kvm_enabled()) { - if (!kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ))) { + if (kvm_irqchip_in_kernel() && + !kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ))) { return; } if (!kvm_arm_pmu_init(cpu)) { diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 7c17f0d629d7..211a7bf7befd 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -567,7 +567,11 @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_= run *run) switched_level &=3D ~KVM_ARM_DEV_EL1_PTIMER; } =20 - /* 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 &=3D ~KVM_ARM_DEV_PMU; + } =20 if (switched_level) { qemu_log_mask(LOG_UNIMP, "%s: unhandled in-kernel device IRQ %= x\n", diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index e26638a6fac1..ec7d85314acc 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -506,8 +506,7 @@ int kvm_arch_init_vcpu(CPUState *cs) if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { cpu->kvm_init_features[0] |=3D 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 =3D false; } if (cpu->has_pmu) { --=20 1.8.3.1 From nobody Sun May 5 15:32:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500473439040417.98508867672206; Wed, 19 Jul 2017 07:10:39 -0700 (PDT) Received: from localhost ([::1]:33543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpO7-0004Rw-0C for importer@patchew.org; Wed, 19 Jul 2017 09:51:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXpKL-0001Qb-Mi for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:47:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXpKK-000839-LM for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:47:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXpKH-00082g-VP; Wed, 19 Jul 2017 09:47:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6812883F3D; Wed, 19 Jul 2017 13:40:05 +0000 (UTC) Received: from cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com (cav-thunderx1s-cn88xx-03.khw.lab.eng.bos.redhat.com [10.16.185.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C61653CE3; Wed, 19 Jul 2017 13:40:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6812883F3D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=drjones@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6812883F3D From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Wed, 19 Jul 2017 09:39:57 -0400 Message-Id: <1500471597-2517-5-git-send-email-drjones@redhat.com> In-Reply-To: <1500471597-2517-1-git-send-email-drjones@redhat.com> References: <1500471597-2517-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 19 Jul 2017 13:40:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/4] target/arm/kvm: pmu: improve error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, agraf@suse.de, cdall@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Christoffer Dall --- 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); } } =20 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; } =20 -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; } =20 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) =20 err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); if (err !=3D 0) { + error_report("PMU: KVM_HAS_DEVICE_ATTR: %s", strerror(-err)); return false; } =20 err =3D 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 !=3D 0) { + error_report("PMU: KVM_SET_DEVICE_ATTR: %s", strerror(-err)); + return false; } =20 return true; } =20 -int kvm_arm_pmu_init(CPUState *cs) +void kvm_arm_pmu_init(CPUState *cs) { struct kvm_device_attr attr =3D { .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, .attr =3D KVM_ARM_VCPU_PMU_V3_INIT, }; =20 - 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(); + } } =20 -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 =3D { .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, @@ -418,7 +424,13 @@ int kvm_arm_pmu_set_irq(CPUState *cs, int irq) .attr =3D KVM_ARM_VCPU_PMU_V3_IRQ, }; =20 - 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(); + } } =20 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); =20 int kvm_arm_vgic_probe(void); =20 -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); =20 #else =20 @@ -205,15 +205,8 @@ static inline int kvm_arm_vgic_probe(void) return 0; } =20 -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) {} =20 #endif =20 --=20 1.8.3.1