From patchwork Tue Aug 29 09:39:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9927005 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 A400F603B4 for ; Tue, 29 Aug 2017 09:40:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A564288C5 for ; Tue, 29 Aug 2017 09:40:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D3B7288D0; Tue, 29 Aug 2017 09:40: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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0779B288B1 for ; Tue, 29 Aug 2017 09:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751572AbdH2JjS (ORCPT ); Tue, 29 Aug 2017 05:39:18 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:34804 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186AbdH2JjL (ORCPT ); Tue, 29 Aug 2017 05:39:11 -0400 Received: by mail-wm0-f41.google.com with SMTP id f13so18695041wme.1 for ; Tue, 29 Aug 2017 02:39:11 -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=euKk5Hs/8/adWl6GVMOJeQQEBVwjxFRh2ED3TzMkrNE=; b=h4y9qgSLZHLktKL7GYAVv7NoYRlBpcJCdUYIQW1yGbnyVkQr3pnxd11lzIzVS6Jy5s +T5QEF7UR0punIHDOMi03cMTx/OrP9TylUeJLJoxrQl2wJYuPmNO+WCxrqeq0Wp+VM1X dGAY45BY84lO6vbaB3DiUKrD8IICqVEcyc2qA= 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=euKk5Hs/8/adWl6GVMOJeQQEBVwjxFRh2ED3TzMkrNE=; b=VnZpEZkfZRTDO5H9ENhuIbDMQaqBn4FDnhBhscUfDaR4KeOVXRwjH76kPyB5KXD1Ro NVwFE+9O8lGXC+KgbaS4OPN52hDVSEdyT7jTDMM5hQWmWwVIRp0DtSHLookT4z1jk9Zz PsSYJ9Eop1K/gcCVszv/8OAI/2jeuambEX3vhZYvEnpL/t7fEgaBUUiOiV2vhWckssms DIpW5ZTjvCTZRPlTmMT5N+MphJTCfuNguUREfWh9hcEa3TRZfdWYjlHvT50W0+v3gH+b K3uT51S+VOMd2pWdUZxQsfzUI8qqNsDLltycAtqIBzn9U1ZoGIc8Cdy+2wf3yXx1K4q0 +kKA== X-Gm-Message-State: AHYfb5hD3SUBkNS7+raLKzk1Mf10I8ABfHmV9sSUZOVE2nFPO4T6PcxE VvMBhxPXbNleJExv X-Received: by 10.80.184.117 with SMTP id k50mr2929896ede.293.1503999550589; Tue, 29 Aug 2017 02:39:10 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id k34sm1149879edc.2.2017.08.29.02.39.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Aug 2017 02:39:10 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Eric Auger , Marc Zyngier Cc: Andre Przywara , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Christoffer Dall Subject: [RFC PATCH 3/4] KVM: arm/arm64: Rearrange kvm_vgic_[un]map_phys code in vgic.c Date: Tue, 29 Aug 2017 11:39:01 +0200 Message-Id: <20170829093902.15379-4-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170829093902.15379-1-cdall@linaro.org> References: <20170829093902.15379-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The small indirection of a static function made the locking very obvious but becomes pretty ugly as we start passing function pointer around. Let's inline these two functions first to make the following patch more readable. Signed-off-by: Christoffer Dall Acked-by: Marc Zyngier --- virt/kvm/arm/vgic/vgic.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 2691a0a..e3ce2fa 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -428,12 +428,17 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, return 0; } -/* @irq->irq_lock must be held */ -static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq, - unsigned int host_irq) +int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, + u32 vintid) { + struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid); struct irq_desc *desc; struct irq_data *data; + int ret = 0; + + BUG_ON(!irq); + + spin_lock(&irq->irq_lock); /* * Find the physical IRQ number corresponding to @host_irq @@ -441,7 +446,8 @@ static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq, desc = irq_to_desc(host_irq); if (!desc) { kvm_err("%s: no interrupt descriptor\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto out; } data = irq_desc_get_irq_data(desc); while (data->parent_data) @@ -450,29 +456,10 @@ static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq, irq->hw = true; irq->host_irq = host_irq; irq->hwintid = data->hwirq; - return 0; -} - -/* @irq->irq_lock must be held */ -static inline void kvm_vgic_unmap_irq(struct vgic_irq *irq) -{ - irq->hw = false; - irq->hwintid = 0; -} - -int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, - u32 vintid) -{ - struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid); - int ret; - BUG_ON(!irq); - - spin_lock(&irq->irq_lock); - ret = kvm_vgic_map_irq(vcpu, irq, host_irq); +out: spin_unlock(&irq->irq_lock); vgic_put_irq(vcpu->kvm, irq); - return ret; } @@ -487,7 +474,8 @@ int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid) BUG_ON(!irq); spin_lock(&irq->irq_lock); - kvm_vgic_unmap_irq(irq); + irq->hw = false; + irq->hwintid = 0; spin_unlock(&irq->irq_lock); vgic_put_irq(vcpu->kvm, irq);