From patchwork Mon Sep 4 10:24:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9936971 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 19A2560237 for ; Mon, 4 Sep 2017 10:27:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08A5C287B8 for ; Mon, 4 Sep 2017 10:27:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFB18287BA; Mon, 4 Sep 2017 10:27:03 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 72C79287B8 for ; Mon, 4 Sep 2017 10:27:03 +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=r2UjYYc0XXQV/9yQSBzgjSOrahWl1TLQyF/+M4Pmsvk=; b=pb9IiFrHU0wIZ1uIHLP15sCqHT o7kv8kApsz657UrKLTRPjZiXlK++Vp0OYf7Dv7IZ2SUs0Uyvzqlss8TIWH9p+hfKDKQfhbOCvvXUQ K5u4aYupDt+4gi9NWXeAeNqiWgPTrcttnZ4DSLVWIliSWmiFxV3H3Tl4yci97uKeRv50iT4i2BpUl CdiPN7Uwgu9nCljTWSQoYE9/5rBuHQqzOyIVORBXOeBbqyvqNchSPqOIfFV1KnLWhGFXLtTh84WaU YRG1yGi6H5oPnAdDhY1RJLQMCcSSMzWcM2n9e5HqJ00Vpy4PbH2SCCZzjZt884sDErzypCjJdS7hd 1XvqP/dg==; 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 1dooan-0003WG-BL; Mon, 04 Sep 2017 10:26:57 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dooZO-00020N-KF for linux-arm-kernel@lists.infradead.org; Mon, 04 Sep 2017 10:25:38 +0000 Received: by mail-wm0-x22a.google.com with SMTP id v2so2227318wmf.0 for ; Mon, 04 Sep 2017 03:25:12 -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=0dd0Dps62WO/b17pgYbFxV0jCq3z/j3fuA2jfKtQdDE=; b=L5ySEYOb1Bs9tG/3iBFEp3FZUAX29oSmAsJFiRx65VaOcMdLrlTmKQOZhzp5GYyNtV ttLKj9guRTwtQFv08frBInH7jrnDX+mOOVG2lJYTP1Rw9U0xFi7ykxRN6JHFJjOAkT+A fWZlmwfgTaJLUobSHA4BFhe0it4kP/tnjujtY= 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=0dd0Dps62WO/b17pgYbFxV0jCq3z/j3fuA2jfKtQdDE=; b=LjQ4RaAsUKrBhKp7Jy7igOyxzOrkIii4SgXaMox9C/Ixu9xy2sMCFgZCe5xPYaJU6M zzfGA1th41UuBCvBIn/vmfT0Lfs+SLUYYUrnaopqA7zErPxOHalAZfxnuQSkKo4w9Q5X +zMz9WaoDdI/JSEQgGjEnksqUqxfNxsK2miLsEam1nHpRrTLpnsMiDipxyds0fbQ7aq9 QE5yxLoHxRIGyVg/+iQQ2G4fpO8lPChENSNJXeLqCNWPaYI09O/W7hJehYHc84fVzEWA UhkeY2j8Yz83hE3JUS5xvTa25+kE7tHL8D4mg0VW2f3a+WslqbQA+xSKycvDwUzqmJah KUMA== X-Gm-Message-State: AHPjjUjuoDr1+F79nht/p5rS1TKRxjDN2herJwkNIDvSTOJPj1Z76OA3 8Vw50rm5vjF5l5vg X-Google-Smtp-Source: ADKCNb6Z7rzInlyeUmKl36VEGXOmbJ6mdxPhBQiHZ89Eg3RlAyfsDIynCQAHt5QAF/k6KFsLneOCsA== X-Received: by 10.80.174.244 with SMTP id f49mr156251edd.8.1504520710764; Mon, 04 Sep 2017 03:25:10 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id h64sm3406924edc.67.2017.09.04.03.25.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 03:25:10 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Eric Auger , Marc Zyngier Subject: [PATCH v2 5/6] KVM: arm/arm64: Rearrange kvm_vgic_[un]map_phys code in vgic.c Date: Mon, 4 Sep 2017 12:24:55 +0200 Message-Id: <20170904102456.9025-6-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170904102456.9025-1-cdall@linaro.org> References: <20170904102456.9025-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170904_032530_852928_DA7B6220 X-CRM114-Status: GOOD ( 12.81 ) 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 7aec730..b704ff5 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -435,12 +435,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 @@ -448,7 +453,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) @@ -457,29 +463,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; } @@ -494,7 +481,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);