From patchwork Wed Apr 5 09:28:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9663607 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 7A66960353 for ; Wed, 5 Apr 2017 09:48:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AF8E28573 for ; Wed, 5 Apr 2017 09:48:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E37428595; Wed, 5 Apr 2017 09:48:59 +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 ECBCF28573 for ; Wed, 5 Apr 2017 09:48:58 +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=dhuMzRAbnHxiCS3N3nArKxxdS6ecsh5ypAU/hByNi2c=; b=EEPt8RpGvXdrvNWu4O3Vmyz/s5 VfUqR5byfGFEXJKEZBLVrNeNnfMBOcQzA7OYRkzur7MKa3bhdzpcxWCi269xdy6MlAYb6cjc0WRJK FSwLxMGHJFpddLgdPsxRF7FBCkIhugdjUHQYVV3IHX6QhVWGH+EIjrUniT75ZcZmZSCBpOf+I7K9/ 8+jtfcIFfKCwTwBrOK/N2kx6c0H/Ip2AnEdHhJf1DhNaI9saRZYXQe7VFPOdofO+8lqNNw3A8Hmlv Tq+tXC8Nxu0GTXQB5MMP8uaPMKPUhiA09On7ZCVb++0A+Oe6CSRN7OLZ7DyogYcc2yDzx6rQZk3pf k8wGetdA==; 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 1cvhYg-0003t3-Di; Wed, 05 Apr 2017 09:48:58 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvhYW-0003cg-PD for linux-arm-kernel@bombadil.infradead.org; Wed, 05 Apr 2017 09:48:48 +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=cwIrYuYG5Q4CCM/pNgkTZTo1Gz8uC3UViJaNRXeB7nQ=; b=wcTIPCw4+LDHx8/nu5rxnJACM U6VQO+FSetzWTIGxnJEbgDiM2Lkh8lvA/DKu/G6TN93oYpdSZKcHNiuXtC7oKdg0QqxtBEjDdXZ80 /Iq75qUE7J//BJPX/CnP7eBgK+hVv1ZHg/D83hF40bF0+NwRBUBt+mL92Tu1v6n6HHx+VOQ4YxHaJ CSc8RN8JhxZem/XthI6SoSKxm/a5zCrUF1i8g+9+f39zHv+/JXMnpfYGhw+6YkzwoIMlfMhYNt+lB /dhgjqicYEKQ9/QXoCRtD+vYkmGqls+uO6Vt22gHDG7MICvWtpxuBdNPzPRP4OJWfJIdRvIAgZnw4 xbvVQ8QHA==; Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvhF3-0003kM-Uf for linux-arm-kernel@lists.infradead.org; Wed, 05 Apr 2017 09:28:43 +0000 Received: by mail-wm0-x234.google.com with SMTP id y22so45043843wmh.0 for ; Wed, 05 Apr 2017 02:28:21 -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=cwIrYuYG5Q4CCM/pNgkTZTo1Gz8uC3UViJaNRXeB7nQ=; b=gVIDW8tTBsMViVHSZOZiDNHTw+ktd+ZGxGYgWS+N+6wOmxNSSeCVf5RAlxSvO7O0g8 iRySsD7ShO5O5YPACDmXOb+5P4CSttiz4BWukezlb1gkXkXRTZUa2JpFPI7a8usRMZuh eDO5jrX/qHrIvNHtl94UM44e+mz6S9zLTl+A8= 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=cwIrYuYG5Q4CCM/pNgkTZTo1Gz8uC3UViJaNRXeB7nQ=; b=efkqnI1x1GAeizb3n0BRnb+TSo98w6jsMsLg/0tDxIK9QXNirWzFAxT0PAKodW7fi0 MkAlk6gu3z+0xB7+HYZVMWnKvNwkPu+5ax4zPnyEElMlCsXBL0mpvwo1PDeGuYk6pDRp JPo7pXkyKPUMkZ7Hez62ZdCuWgjqIjmJeD1dmsiDTuM5AhEzf0wsU6K1mrcj2JRXu9aO hwzVTUraeofZiBaAxZGC3nl4XQAkeQAu0suElZhTI6LNSBBgPu5uvwVnlfXgxeEXN6Vk vWUndv5mOcK9Ak1WwkPBwE30hcv5aE78k7HsF3m903fGDnHFqg++DKNdjVoTn+C+PD7U JVCg== X-Gm-Message-State: AFeK/H2CqO61eCpSzO9LLypdpZ5AlO4xLBDiKZKQBVkXJDBUjTngs8z1o7ZTFEVAU+XUUSgd X-Received: by 10.28.24.79 with SMTP id 76mr18396457wmy.111.1491384499447; Wed, 05 Apr 2017 02:28:19 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id g23sm21578135wme.8.2017.04.05.02.28.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Apr 2017 02:28:18 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 4/5] KVM: arm/arm64: Report PMU overflow interrupts to userspace irqchip Date: Wed, 5 Apr 2017 11:28:14 +0200 Message-Id: <20170405092815.22503-5-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170405092815.22503-1-cdall@linaro.org> References: <20170405092815.22503-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170405_052842_173607_7A4D07A8 X-CRM114-Status: GOOD ( 16.55 ) 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: Peter Maydell , kvm@vger.kernel.org, Marc Zyngier , Alexander Graf , Pekka Enberg , 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 From: Christoffer Dall When not using an in-kernel VGIC, but instead emulating an interrupt controller in userspace, we should report the PMU overflow status to that userspace interrupt controller using the KVM_CAP_ARM_USER_IRQ feature. Signed-off-by: Christoffer Dall --- arch/arm/kvm/arm.c | 9 ++++++--- include/kvm/arm_pmu.h | 7 +++++++ virt/kvm/arm/pmu.c | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index efb16e5..f935383 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -635,11 +635,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) /* * If we have a singal pending, or need to notify a userspace - * irqchip about timer level changes, then we exit (and update - * the timer level state in kvm_timer_update_run below). + * irqchip about timer or PMU level changes, then we exit (and + * update the timer level state in kvm_timer_update_run + * below). */ if (signal_pending(current) || - kvm_timer_should_notify_user(vcpu)) { + kvm_timer_should_notify_user(vcpu) || + kvm_pmu_should_notify_user(vcpu)) { ret = -EINTR; run->exit_reason = KVM_EXIT_INTR; } @@ -713,6 +715,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) /* Tell userspace about in-kernel device output levels */ kvm_timer_update_run(vcpu); + kvm_pmu_update_run(vcpu); if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &sigsaved, NULL); diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 92e7e97..1ab4633 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -50,6 +50,8 @@ void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val); void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val); void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu); void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu); +bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu); +void kvm_pmu_update_run(struct kvm_vcpu *vcpu); void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val); void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val); void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data, @@ -85,6 +87,11 @@ static inline void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val) {} static inline void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val) {} static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {} static inline void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) {} +static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu) +{ + return false; +} +static inline void kvm_pmu_update_run(struct kvm_vcpu *vcpu) {} static inline void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) {} static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {} static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 69ccce3..51218be 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -230,13 +230,47 @@ static void kvm_pmu_update_state(struct kvm_vcpu *vcpu) return; overflow = !!kvm_pmu_overflow_status(vcpu); - if (pmu->irq_level != overflow) { - pmu->irq_level = overflow; - kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, - pmu->irq_num, overflow); + if (pmu->irq_level == overflow) + return; + + pmu->irq_level = overflow; + + if (likely(irqchip_in_kernel(vcpu->kvm))) { + int ret; + ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, + pmu->irq_num, overflow); + WARN_ON(ret); } } +bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu) +{ + struct kvm_pmu *pmu = &vcpu->arch.pmu; + struct kvm_sync_regs *sregs = &vcpu->run->s.regs; + bool run_level = sregs->device_irq_level & KVM_ARM_DEV_PMU; + + if (likely(irqchip_in_kernel(vcpu->kvm))) + return false; + + return pmu->irq_level != run_level; +} + +/* + * Reflect the PMU overflow interrupt output level into the kvm_run structure + */ +void kvm_pmu_update_run(struct kvm_vcpu *vcpu) +{ + struct kvm_sync_regs *regs = &vcpu->run->s.regs; + + if (likely(irqchip_in_kernel(vcpu->kvm))) + return; + + /* Populate the timer bitmap for user space */ + regs->device_irq_level &= ~KVM_ARM_DEV_PMU; + if (vcpu->arch.pmu.irq_level) + regs->device_irq_level |= KVM_ARM_DEV_PMU; +} + /** * kvm_pmu_flush_hwstate - flush pmu state to cpu * @vcpu: The vcpu pointer