From patchwork Tue May 16 18:45:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9729517 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 92DD560386 for ; Tue, 16 May 2017 18:48:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84C5728749 for ; Tue, 16 May 2017 18:48:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 798D4287C6; Tue, 16 May 2017 18:48:11 +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 072C328749 for ; Tue, 16 May 2017 18:48: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=ajz5JllvSk8+1RxD/oOIx5opOeZ8LX6PlqdtWZoeVTg=; b=KUFoDRuzZKlz1M2zZs1GhD3+lJ gqc/M8Yp/40LqjeCLHvhSotcSWwFnnZ9phCzqCwRFnA4MMcveBXGOr7Ijp6+8d8LNTcnJurfH18c0 7IpR7PHVaK13a0403mZ3uICVxqPrf/U29Py3XcUYib9dhdgmQr9aMSh/uY2pnpLPgqwYqiTlj95EG N+ycknIN0hurguxGRr9L7UFQYJUTG8wgZ9yHFKk23A9DXuvSWngnAip2C4yclGZzlnmdDINTW+cF2 A3zOtHXzwcx9z283a54loiJEAVcxKrpcpra6THCBp28PBJk4NwHsZ4LSDsOnoYGL36Ujc8JvjfHuW hiE0CMqA==; 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 1dAhVx-0004AN-E9; Tue, 16 May 2017 18:48:09 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dAhUZ-0002OO-PO for linux-arm-kernel@lists.infradead.org; Tue, 16 May 2017 18:46:49 +0000 Received: by mail-wm0-x22c.google.com with SMTP id u65so131014429wmu.1 for ; Tue, 16 May 2017 11:46:23 -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=9UnmZL/r0/2l6qJ6c3+Swtp/X/p/RV4w9dylPR8P/9Q=; b=eM7ruA0BBPypmUxGGk79+Aj4zQttu3bixsjCxa2gI13KL/3avwgAbqeir5jCHNNIk1 4UJJCc4ba+vr7cDyaCT+dBzzmsWwOXR3stmHZHVBmX525e0mCH4WGNm4BqTpcCYdB8Nx 0QwvHJGuKhWxFZIET2kH58dH0pxC3+Q7ViMf0= 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=9UnmZL/r0/2l6qJ6c3+Swtp/X/p/RV4w9dylPR8P/9Q=; b=RxNGu9XVSkNreuoy0xeRY+tU/+AfM3L1+eWZLdnXlGvUbhhFE+eYf+52tKvrLJWE3j 2VHVfdHIP5/yBXp9XGEpb691hvQAxLMh0VKLmH4xmZC5aIfI60f1dyPtfQER5HDJ7AUO sWZJ69eloypKTEZw7Hu95XNRpkNeg4V3R9zp4QqksYl8ACX6O5ircunXDnm8bmgh+hsZ 4yN2UxCZnIusJdLQJ37Wb7Z/9t7xImzViDcSu9x7DaIMO8GX/tVus7cSdYLPb120qOW+ XhgG2Vc6tREMkgHt+ocMjmsWzKig3mkjMs/Xq03FCqpxWA7QXQtd1cKHIiRFS1/AWb+0 OYxA== X-Gm-Message-State: AODbwcA0hvXyUxC9/rEeQDEByrwqlH6FmShS1AMmS5domsbP0yTir7Ig zAqj9yWc0XVEMOPU X-Received: by 10.80.181.57 with SMTP id y54mr75333edd.109.1494960382061; Tue, 16 May 2017 11:46:22 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id c2sm25102edc.34.2017.05.16.11.46.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 May 2017 11:46:21 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 6/9] KVM: arm/arm64: Introduce an allocator for in-kernel irq lines Date: Tue, 16 May 2017 20:45:53 +0200 Message-Id: <20170516184556.26785-7-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170516184556.26785-1-cdall@linaro.org> References: <20170516184556.26785-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170516_114644_180228_DE53091A X-CRM114-Status: GOOD ( 14.92 ) 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 , Christoffer Dall , Alexander Graf , kvm@vger.kernel.org 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 --- 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 83b24d2..e9e46f1 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -431,6 +431,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