From patchwork Wed May 3 18:32:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9710267 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 ECF206021C for ; Wed, 3 May 2017 18:33:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFD9028414 for ; Wed, 3 May 2017 18:33:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB3B62861E; Wed, 3 May 2017 18:33:55 +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 455BD20243 for ; Wed, 3 May 2017 18:33:55 +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=Cf1x9xwIXSQfgLG5LfKR8u+eMcJXiaumBm9R7R93fjI=; b=BMNt8YIRFJnT6x98NDY1p5rPv+ 6183Cu01xuWH/k1fC9qNDWwmiiilCen3J7eZFzHZngKSelElvFVDn9YKwrjeOIHuhc6wCY0AYzxqM AMkk0PAMSye+4opAfzL/Wzv6kDDBktxtkMYZB0pHkty9fzBYOUm9XvhDUssWdUD46yd4uyBdLDbTe e6eCcJ35o4/2RaYT8dqcXiQgOGDKuyGy4rWOxTAM2MdBEeqmjXUgz/wLN78HRzYwjdfU19u2XcOf4 fQO1+fJtg755fRCr1wX6wxL2c5Fgf+3H0xQjuNN/Rtp+nUkXZ29BOIAslc8YHvMONWVIt8N9o+sZT cXmHyQjQ==; 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 1d5z62-0004Tp-Hp; Wed, 03 May 2017 18:33:54 +0000 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5z5Y-0003vq-So for linux-arm-kernel@lists.infradead.org; Wed, 03 May 2017 18:33:28 +0000 Received: by mail-wm0-x230.google.com with SMTP id w64so155890091wma.0 for ; Wed, 03 May 2017 11:33:04 -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=j+un1CFbAQCXhmbQBeedwyK3usYQNGONkfR5XT8xrGg=; b=K/rD5Y/Pcsj1EMytck8699/TQl0RA8+kFHj9zROxhIQGnJX08g41GukRUKoDLKg4vr Q1tPPtdCg0cif3MneznqKooOLun7ni4QF3yx/m9cXc12sE9Wz6Cww+BXYRqcuyqNw7OG lGc9/XHKn1dlXEf/DLiSP7GUY54UGw71uVw4k= 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=j+un1CFbAQCXhmbQBeedwyK3usYQNGONkfR5XT8xrGg=; b=F2Y1Gtta02HGNPypZvJXtutTc1c1NojYm4KP+ig9ePEMnAYEWYUPOmZpF1mGUBV0Ac e6+EbVnxz3FLoNTDCvNUTeTo55keqKeC07lQovQm28UZgjv/PJt9hVaoIyGp5vFQmcGL VpJMp3GL11d9wA7fp4N6/iEVsaPwqVRVBTd4sARqeJoNRW4M7JpVdG4BY+gUcfGV0o1d +eUkUHrPJVHudG17E3zT85QKIL1nsQZ1Xfa0/2VkifhM7qeE5qEx+9IjEgmZ1zaEAT53 RHQv4E2XXFTnSrlZZGcWDzWxLyBra+ZKpk0mhzdxOg04F8Y+2uBFNGA7OLjIg1r+6bwy QGtw== X-Gm-Message-State: AN3rC/579WriPdrwtx6sEn/d5wUQ3X5PFa3MTtmI2Am4iY0nb8f9ZiTO Ga4scXDqPclXsQgk X-Received: by 10.80.167.100 with SMTP id h91mr1339871edc.35.1493836382865; Wed, 03 May 2017 11:33:02 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id x2sm10666038edb.49.2017.05.03.11.33.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 May 2017 11:33:02 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/5] KVM: arm64: Allow creating the PMU without the in-kernel GIC Date: Wed, 3 May 2017 20:32:56 +0200 Message-Id: <20170503183300.4618-2-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170503183300.4618-1-cdall@linaro.org> References: <20170503183300.4618-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170503_113325_084310_14EB2CDB X-CRM114-Status: GOOD ( 16.63 ) 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 , Alexander Graf , 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 +++++++++------- virt/kvm/arm/pmu.c | 27 +++++++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Documentation/virtual/kvm/devices/vcpu.txt b/Documentation/virtual/kvm/devices/vcpu.txt index 02f5068..352af6e 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 + conigured 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/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 4b43e7f..f046b08 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -456,21 +456,25 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) if (!kvm_arm_support_pmu_v3()) return -ENODEV; - /* - * We currently require an in-kernel VGIC to use the PMU emulation, - * because we do not support forwarding PMU overflow interrupts to - * userspace yet. - */ - if (!irqchip_in_kernel(vcpu->kvm) || !vgic_initialized(vcpu->kvm)) - 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)) return -EBUSY; + 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; + } + kvm_pmu_vcpu_reset(vcpu); vcpu->arch.pmu.ready = true; @@ -512,6 +516,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;