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: 9936955 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 AA02360237 for ; Mon, 4 Sep 2017 10:25:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B238287B8 for ; Mon, 4 Sep 2017 10:25:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90053287BA; Mon, 4 Sep 2017 10:25:17 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 17D49287B8 for ; Mon, 4 Sep 2017 10:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753452AbdIDKZP (ORCPT ); Mon, 4 Sep 2017 06:25:15 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:34955 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753433AbdIDKZL (ORCPT ); Mon, 4 Sep 2017 06:25:11 -0400 Received: by mail-wm0-f52.google.com with SMTP id v2so2227319wmf.0 for ; Mon, 04 Sep 2017 03:25: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=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=RnnzEg42o1Z1kd5YExgGyCKdqzPxmPTVj6j5Cre+T9SGfLmJT1MW5TnVccb2mj+L6H lAhK2741b6JCQ+w78DCB8ARNehKxlY6WoecKtHB29lBfrs7kYBwfSWpn/rDDsMOesAk+ vYktLaTIZEuKzKCAzkjM/hqM8rKV7UqtiLIjMhiKhM3QlWCRXLFDkTylN++dIb1YLA4j i3ZEjVOBzcMBecvhU2ICn9G0xfvh0hAeuosBG3BQC7LlThTnNGAXBTm+f7Nmb1MR5XDw sajH2lf0kIGEnWYKftSi2aiZP079MvtT+zjZp4JtbSdsy6oUPmANoJSFjsU1iIWQ+aOa X0Sg== X-Gm-Message-State: AHPjjUgxYoZ45EyRJB5nRvW/mn7AcyaMgY3CziXaOs5NqYzaNg8GV7Hr LSrRsW5+FcQ2y57UDf9WwQ== 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 Cc: Andre Przywara , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Christoffer Dall 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> 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 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);