From patchwork Thu Jun 8 13:34:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9775473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2778560350 for ; Thu, 8 Jun 2017 14:07:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 178B928543 for ; Thu, 8 Jun 2017 14:07:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C1A82855A; Thu, 8 Jun 2017 14:07:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0EB6428543 for ; Thu, 8 Jun 2017 14:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iQHl8+LlQ9oK9LejeEQpnHQaZj1/nBtiVOu3l4+KlwA=; b=FzWDdgIWCZydcbqqaylpmYxkke IuazgJJzRO5CUutV8UpnR0kXcx1U8+GgLWbxgmmo5fYg9fCqFOFJOQhC9L3X4/d8OnJRdMbyb7off SNn5RpxDmKAwHkWu4g3hivDogyI4Eb6mHgjUya4vQJ69qzYQn2XrZX5H31D5b0SdUnjWDLTQaUpC3 ewWUxPfeDoShKRBG1paLz6PWKWEWa+WBeNUr3SJUoA1mdSXjXDnZIz1LzGDYStvpHufhLRmbCp1gt h1ruT8nm4WhTjwe8GQbk+DgEg3dkqfZA7/sCv5vevsoZ9LoDG4VBVSXwImYiZNH/OLLWxQqD1ZT+D 3qRIpWmA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIy5d-0007yf-Km; Thu, 08 Jun 2017 14:07:09 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIy4C-0005xk-FU for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Jun 2017 14:05:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ezn5bpLZKNYkbZvqHTeJ0iml/1xXZDKB0nehTV69l0M=; b=b9868W4lpsuDdNB8PkS/xs+23 SLTO+eqZdjfrhWEE8LXtCxd+R/byOqBWHoWxrysWHTQwcqilGXwfKrJGDDEhS/lv+bI67ttTj1zk1 KF2ke7zNtjr/ho1C5KOln6O6ePuyFxnk/Ql9SUOs59szUmt0tAXRD+HM8Rw1yRgNVHaNDQb7neBBz CVHLjz40iWvlmYe806fG3tZ7hHJyCz0JWzkC5J3h3SkBwhwi7nb4N9isjnXjkE2t3U8gQupuu7oq/ 1iNnOqSZEsqm9+N5Lo11Kmn0chzPW2bZZY7SL8YNmr3rUQi2NLEpyYashuCws3nxZc3kRjoqMtfnP XDZrl/MlQ==; Received: from mail-wm0-f53.google.com ([74.125.82.53]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIxbg-0006nw-L4 for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2017 13:36:13 +0000 Received: by mail-wm0-f53.google.com with SMTP id d73so31212916wma.0 for ; Thu, 08 Jun 2017 06:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ezn5bpLZKNYkbZvqHTeJ0iml/1xXZDKB0nehTV69l0M=; b=frBEDEBhEVb/qvfu8BX+J93s0wkVaHhSkp0rVWUonJtlc3U6ei3OmgpzIbEDP8mSmr A8lY3VC+Tw0zIMPfKamwrpcwbx1QdSM6SMKgZiSTLMmYUdCB5PzLPFnb8ZrdAP8wXyou UvFUnPaTDpEgsoTH5gzANI2FUnK5IJ5XjtcEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ezn5bpLZKNYkbZvqHTeJ0iml/1xXZDKB0nehTV69l0M=; b=XHr6eIHVIQfPcdE500PmfQ3YXEJUmLTeYKKMNdfM9dDo158+seLE7D+R+kuO493iid 1jBROHcMVUZcdAlCu0M2ZnJJDkf6iJ8K64pKrFQCgBNgbsScTOxWj5Edm7LyWofn0yfe km9QeB7CuDos2aisbOE76T2/8niw0gXwmmQTOsOBvuG1+SBIOa3qljMbJk1vL4Etc3Zv LTIljjSsY/ayk6Zk1tC5JEpcNLL65pj70yjXG4pEqP48g+V6bHTKP6ze/QPPDkmdVLzn jaodJYLotOVI+yf9OiRaGsC1Ui/4N+Vv0xjmcbG4zI0ZRPwINnzOYwCQiefNtyhpi73P QDCg== X-Gm-Message-State: AODbwcDu7jVoaNKSjRoo4OZEKbj/qFG4SlUtql/hdNqRwWMxnPe1o1rW 0hgws1Tchb6K3/E0v0j64w== X-Received: by 10.80.173.220 with SMTP id b28mr29270661edd.110.1496928890187; Thu, 08 Jun 2017 06:34:50 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id i38sm3981285eda.18.2017.06.08.06.34.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 06:34:49 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/9] KVM: arm64: Allow creating the PMU without the in-kernel GIC Date: Thu, 8 Jun 2017 15:34:38 +0200 Message-Id: <20170608133446.3875-2-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170608133446.3875-1-cdall@linaro.org> References: <20170608133446.3875-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170608_093612_843981_C54E78A1 X-CRM114-Status: GOOD ( 21.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Peter Maydell , kvm@vger.kernel.org, Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since we got support for devices in userspace which allows reporting the PMU overflow output status to userspace, we should actually allow creating the PMU on systems without an in-kernel irqchip, which in turn requires us to slightly clarify error codes for the ABI and move things around for the initialization phase. Signed-off-by: Christoffer Dall --- Documentation/virtual/kvm/devices/vcpu.txt | 16 ++++++---- include/kvm/arm_pmu.h | 6 ++++ virt/kvm/arm/arm.c | 4 +++ virt/kvm/arm/pmu.c | 51 +++++++++++++++++++++++------- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Documentation/virtual/kvm/devices/vcpu.txt b/Documentation/virtual/kvm/devices/vcpu.txt index 02f5068..d7236a3 100644 --- a/Documentation/virtual/kvm/devices/vcpu.txt +++ b/Documentation/virtual/kvm/devices/vcpu.txt @@ -16,7 +16,9 @@ Parameters: in kvm_device_attr.addr the address for PMU overflow interrupt is a Returns: -EBUSY: The PMU overflow interrupt is already set -ENXIO: The overflow interrupt not set when attempting to get it -ENODEV: PMUv3 not supported - -EINVAL: Invalid PMU overflow interrupt number supplied + -EINVAL: Invalid PMU overflow interrupt number supplied or + trying to set the IRQ number without using an in-kernel + irqchip. A value describing the PMUv3 (Performance Monitor Unit v3) overflow interrupt number for this vcpu. This interrupt could be a PPI or SPI, but the interrupt @@ -25,11 +27,11 @@ all vcpus, while as an SPI it must be a separate number per vcpu. 1.2 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_INIT Parameters: no additional parameter in kvm_device_attr.addr -Returns: -ENODEV: PMUv3 not supported - -ENXIO: PMUv3 not properly configured as required prior to calling this - attribute +Returns: -ENODEV: PMUv3 not supported or GIC not initialized + -ENXIO: PMUv3 not properly configured or in-kernel irqchip not + configured as required prior to calling this attribute -EBUSY: PMUv3 already initialized -Request the initialization of the PMUv3. This must be done after creating the -in-kernel irqchip. Creating a PMU with a userspace irqchip is currently not -supported. +Request the initialization of the PMUv3. If using the PMUv3 with an in-kernel +virtual GIC implementation, this must be done after initializing the in-kernel +irqchip. diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 1ab4633..f6e0306 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -35,6 +35,7 @@ struct kvm_pmu { int irq_num; struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS]; bool ready; + bool created; bool irq_level; }; @@ -63,6 +64,7 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); +int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu); #else struct kvm_pmu { }; @@ -112,6 +114,10 @@ static inline int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, { return -ENXIO; } +static inline int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu) +{ + return 0; +} #endif #endif diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index cac5c2f..72816d3 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -527,6 +527,10 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) } ret = kvm_timer_enable(vcpu); + if (ret) + return ret; + + ret = kvm_arm_pmu_v3_enable(vcpu); return ret; } diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 2451607..96a9cab 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -449,29 +449,50 @@ bool kvm_arm_support_pmu_v3(void) return (perf_num_counters() > 0); } -static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) +int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu) { - if (!kvm_arm_support_pmu_v3()) - return -ENODEV; + if (!vcpu->arch.pmu.created) + return 0; /* - * We currently require an in-kernel VGIC to use the PMU emulation, - * because we do not support forwarding PMU overflow interrupts to - * userspace yet. + * A valid interrupt configuration for the PMU is either to have a + * properly configured interrupt number and using an in-kernel + * irqchip, or to neither set an IRQ nor create an in-kernel irqchip. */ - if (!irqchip_in_kernel(vcpu->kvm) || !vgic_initialized(vcpu->kvm)) + if (kvm_arm_pmu_irq_initialized(vcpu) != irqchip_in_kernel(vcpu->kvm)) + return -EINVAL; + + kvm_pmu_vcpu_reset(vcpu); + vcpu->arch.pmu.ready = true; + + return 0; +} + +static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) +{ + if (!kvm_arm_support_pmu_v3()) return -ENODEV; - if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features) || - !kvm_arm_pmu_irq_initialized(vcpu)) + if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features)) return -ENXIO; - if (kvm_arm_pmu_v3_ready(vcpu)) + if (vcpu->arch.pmu.created) return -EBUSY; - kvm_pmu_vcpu_reset(vcpu); - vcpu->arch.pmu.ready = true; + if (irqchip_in_kernel(vcpu->kvm)) { + /* + * If using the PMU with an in-kernel virtual GIC + * implementation, we require the GIC to be already + * initialized when initializing the PMU. + */ + if (!vgic_initialized(vcpu->kvm)) + return -ENODEV; + + if (!kvm_arm_pmu_irq_initialized(vcpu)) + return -ENXIO; + } + vcpu->arch.pmu.created = true; return 0; } @@ -510,6 +531,9 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) int __user *uaddr = (int __user *)(long)attr->addr; int irq; + if (!irqchip_in_kernel(vcpu->kvm)) + return -EINVAL; + if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features)) return -ENODEV; @@ -544,6 +568,9 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) int __user *uaddr = (int __user *)(long)attr->addr; int irq; + if (!irqchip_in_kernel(vcpu->kvm)) + return -EINVAL; + if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features)) return -ENODEV;