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: 9927015 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 2D1216022E for ; Tue, 29 Aug 2017 09:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22FFC288B1 for ; Tue, 29 Aug 2017 09:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18194288B2; Tue, 29 Aug 2017 09:41:10 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW 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 9373B288B6 for ; Tue, 29 Aug 2017 09:41:06 +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=Cd7gGE5TuW5AQ1SKOwBKXNUtBfk8+GpUG/a+ZoL4MkU=; b=EWqqEveQvT3dZh023aV0K3xbAb W8nSV4xKOocHiuj0gzX/ljj74JHvp01ZyevQHSeZs5O13wgmFM1JvbxAc232UaadTZE0YVJP4lEVs 3M8kuNO6Gu+l/B0OxUXkt0grdbZ2cXIfb+CUUSphc6ad18/rSGioAJbxk1CWq7As0y8kUWbNUyEC2 Nz2wHlK6O0E2ouozesC+MFmTPQkFapUXvHfW6AzO8HMVSomSS0I9s4oFep9IcO0FBiNnAdvlv36zx UoXOHzaSiTh7nqBw+ZcpOhLps8o/7kvl4v1z8MuwGODcNWSl+TTRR5FTci1c1oDSwhs48B8V4SDGM NKYXQ0QQ==; 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 1dmd11-0000AH-4c; Tue, 29 Aug 2017 09:40:59 +0000 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dmczg-0006G2-QP for linux-arm-kernel@lists.infradead.org; Tue, 29 Aug 2017 09:39:40 +0000 Received: by mail-wm0-x22f.google.com with SMTP id f13so18695042wme.1 for ; Tue, 29 Aug 2017 02:39:13 -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=msOfXooezs3RrXLjhFyoHIDZ8d0Zk9fWTYqR4SEc6Q1UJ5ICURuIeBvyi4/nEKH2Q4 R5gQL9kvM2/PmZ5AXJU5auAUr0d80+rKcCdUINxi1GtO05uooekLMGqRc38tqmW9Jb3x /lhsLNq/rQpHGNjl309N3hAKy7jmNDZUyWtuIKt7iQDuntUd+rxJbeaDN6RmCeHv4Yu0 A6V8VgIJjqTHFc4/7iyElMOVfencJjMTeY2j4XCxyP+l+xZ6ptwN6ZEUFh5qtcIxKqtz /4smM3ItahqnUHY2BiPgx4onsCOymZVpzjBlv913r4hvJd4MMKa/doh2EvWwd3VWMw3c xz9A== X-Gm-Message-State: AHYfb5iL1gOtRtEtlSKE5S6HxslDc2S9IzV0Gj7HBdHFzChBmdQCkvMM hOm1yw0CB/GlSSst 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170829_023937_140307_3A5C085C X-CRM114-Status: GOOD ( 12.66 ) 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: Andre Przywara , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.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 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);