From patchwork Thu Jun 8 13:34:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9775467 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 469A560350 for ; Thu, 8 Jun 2017 14:06:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376C328543 for ; Thu, 8 Jun 2017 14:06:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C41E28558; Thu, 8 Jun 2017 14:06:20 +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 AF86228543 for ; Thu, 8 Jun 2017 14:06:19 +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=p6AhGj8mL4WLI2KgGPu0ouLrPwAadEBpFDsnoAYhUtA=; b=eCevQW3Fwqqp8QD0gialj003+H GZ311E0be553mTUVKNaRxo3xzCgjAe6XmR9KCwUnpenO60/sINPlmdhMXFsQi4dgZLDE3FmH2xAPg TH39tL+9E+G4PUyyVJsZj9bBaagtC86KyLHD3uRFEVXj+XR3yAxbF0acPodNI5NPNGyJK8p37BiN8 5RWGiw2l81xNV2iMNxGgbaoTC7HQgo+EnqwCUuQzoeJZzQTdK4w48r8tJH98z5vxhbkw91lDrvZCj GmTJgWdUHRsAoO7jiwv7bcR71CMONomgFHxIDGjwEXynxZhMMcjswkNJuWnVpVmPhJ+egroynmDRh FEr0JBxw==; 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 1dIy4o-0006s5-AV; Thu, 08 Jun 2017 14:06:18 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIy4A-0005xk-PU for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Jun 2017 14:05:38 +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=BwtSlN8W3EILyEDlcKhP7VXxaI1J28wsNKT3FS4oJCc=; b=xZ9t1RXruX2gWbkaQp6mPZsFT LPPK9HJ2t+F3VJQYa9oT9RF30eTACmODGI35gHQ8FzcAsBA8TrrlHjdo/DWk6lOn7Fgl4MgLmMg06 FD903YvjSfnnH/OW2ISDuMOBQoHK4eIkfgcHHaYkTAzqY+k+DSaED4vo/a0wiyLI+ikNLXuAnSKR2 8gMEpUJjHpZZnng6iRrIip5L7NUYnydGnDBjoW7Cd6HhWbHNRt3A05k9kj91+Ou5O5u4qOThrST+U UrbFnIxewcbGBIhOxSm23e9TWiOXPd8ocjDUBQXk9AvSaA1AAMCXhpnH0xEX9CkQXbP5ywz8HQnPv S+Jp+AULg==; Received: from mail-wm0-f46.google.com ([74.125.82.46]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIxbl-0006o7-BF for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2017 13:36:18 +0000 Received: by mail-wm0-f46.google.com with SMTP id 7so138097108wmo.1 for ; Thu, 08 Jun 2017 06:35:57 -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=BwtSlN8W3EILyEDlcKhP7VXxaI1J28wsNKT3FS4oJCc=; b=X9SKtEHq+S1wcSya0wocKdgHCaer5E69EcFgeIL3JiU+SxpzM1MCUtxRow4pDW+yAr geJsTsTpOmZlWnwwWKPgeKdrIR7UevrqCVcPoAs55ceO0d1MT3LfJWtGeztIwj74qi9X eLAiWfkgp4Uq3psKB3mxjJ0vU60YCUWl24jEU= 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=BwtSlN8W3EILyEDlcKhP7VXxaI1J28wsNKT3FS4oJCc=; b=YXlj88MrfK8SfDOQJr5YxrTDr+715HzlWMDhsGy70dVbR4cX0gVFPPRX95GOlKYMIr UChhuAxnQzhrhA/3z8pIKuYVbHk3FIsYpwZxAsSJxOGQCdUB2Swp04IsGjMi1hpDAe5T zMMGbnyyEzA7mtP47JD+bfXYuo/ySVSlO2MNfqC+Xz7jTr9V0PxtZpdAynNnxoc2m2X3 wlVWN+8kwndhNDPq2akdoIOzpdqx2FFjFhrKuF9fVQsNTIo6PIIDnRAWTyX/4e6bEOL8 sVaw7/QfNaU6JFyxf9J/Ytzx0n4H0wCV6jPu+1qJEPAdRF75E9h8gQvU0ltMZGYwm4Kn VdVg== X-Gm-Message-State: AODbwcBor6C/J5hA048f270e+sC1mb00Sb4hWkFcw8D5nKQD15LdVlKF 4/pyCGTKM7OWD197 X-Received: by 10.80.173.220 with SMTP id b28mr29270914edd.110.1496928895379; Thu, 08 Jun 2017 06:34:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 06:34:54 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 6/9] KVM: arm/arm64: Introduce an allocator for in-kernel irq lines Date: Thu, 8 Jun 2017 15:34:43 +0200 Message-Id: <20170608133446.3875-7-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_093617_506694_A5B01506 X-CRM114-Status: GOOD ( 16.83 ) 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 Having multiple devices being able to signal the same interrupt line is very confusing and almost certainly guarantees a configuration error. Therefore, introduce a very simple allocator which allows a device to claim an interrupt line from the vgic for a given VM. Signed-off-by: Christoffer Dall Acked-by: Marc Zyngier --- include/kvm/arm_vgic.h | 5 +++++ virt/kvm/arm/vgic/vgic.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index dde59fb..5d5b345 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -121,6 +121,9 @@ struct vgic_irq { u8 source; /* GICv2 SGIs only */ u8 priority; enum vgic_irq_config config; /* Level or edge */ + + void *owner; /* Opaque pointer to reserve an interrupt + for in-kernel devices. */ }; struct vgic_register_region; @@ -340,4 +343,6 @@ int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi); */ int kvm_vgic_setup_default_irq_routing(struct kvm *kvm); +int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner); + #endif /* __KVM_ARM_VGIC_H */ diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index c66feac..9628945 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -435,6 +435,39 @@ int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int virt_irq) } /** + * kvm_vgic_set_owner - Set the owner of an interrupt for a VM + * + * @vcpu: Pointer to the VCPU (used for PPIs) + * @intid: The virtual INTID identifying the interrupt (PPI or SPI) + * @owner: Opaque pointer to the owner + * + * Returns 0 if intid is not already used by another in-kernel device and the + * owner is set, otherwise returns an error code. + */ +int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner) +{ + struct vgic_irq *irq; + int ret = 0; + + if (!vgic_initialized(vcpu->kvm)) + return -EAGAIN; + + /* SGIs and LPIs cannot be wired up to any device */ + if (!irq_is_ppi(intid) && !vgic_valid_spi(vcpu->kvm, intid)) + return -EINVAL; + + irq = vgic_get_irq(vcpu->kvm, vcpu, intid); + spin_lock(&irq->irq_lock); + if (irq->owner && irq->owner != owner) + ret = -EEXIST; + else + irq->owner = owner; + spin_unlock(&irq->irq_lock); + + return ret; +} + +/** * vgic_prune_ap_list - Remove non-relevant interrupts from the list * * @vcpu: The VCPU pointer