From patchwork Tue May 9 10:45: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: 9717621 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 82AB560237 for ; Tue, 9 May 2017 10:54:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7759D22701 for ; Tue, 9 May 2017 10:54:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ABEC28329; Tue, 9 May 2017 10:54:00 +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 E307B22701 for ; Tue, 9 May 2017 10:53:59 +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=m3YnbMINpP2q1yItSfyjdQ4ej68qYdtBHBvWCwSwELg=; b=eGQQWaQW0CmJ30QK6Qb5PkYfAZ 7rVU/KIQFa557ToTT5zlHOXi7UqR3ViKwzCTVy7JIeo0w/pVvg9IcEfUzgbMWikeY8NSC+/E4U4LB I3hL5MoWte3v7VcDS18DjeSKT0Xe7gTnfKPxVaghXjklVdyi0cVYpTJdoYeoDAPj7F1qwj8YkA57J DCwnJrdknKsh+ueqVehL8DfHzxxF68PjEqq4afrCdn+vIZPny8vYzCoDcErrCATLCPrKan3gfeoWX Gc/euUgU3U+/VxNjm0LR4C1BbpHt/BnII0mZvrTeBDGGfI/mfLjdCBrF8tKSkfoGnMGuWJjMiBLeq 2OM2x/NA==; 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 1d82mE-0004pz-LD; Tue, 09 May 2017 10:53:58 +0000 Received: from mail-qk0-f170.google.com ([209.85.220.170]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d82ea-0002yH-HU for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 10:46:08 +0000 Received: by mail-qk0-f170.google.com with SMTP id y201so42669404qka.0 for ; Tue, 09 May 2017 03:45:44 -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=ggHn0V3Q5j4einQZpPdd7k0D6VThqIE9+B5ws0B6lKA=; b=DLjWCQuZHEsBakJ0chw8u7e3UzHDIbHz29jJBCP4hVHChWWbjy/jlLckXMAffKvCwh XJRzs0gCTTEKXkYQGxLBqVzd6FXyuWoH9BNqx37f/IenjaIRbyeIKLHYfc6/zTfvEcDc 2OnsjMsk6J1WYB9JU0RKNTi6daOIzBIhS0t28= 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=ggHn0V3Q5j4einQZpPdd7k0D6VThqIE9+B5ws0B6lKA=; b=b/DIBgHdchSNwlCYDk4bDY3eBZ+goJEbuCCjOitBCWh+ANaffFKNz6lQOeeL0SNyn8 DHbW9pKfBYGZL2KZRMMd8oAfqSvUl1pt1gtghap8AcgUd2/4cG5lo+Imeujk0rJ8u8sE QCVqMI3U4AMxejwrsF07gJobrewYmwmXR8BisiJuU3Bk44/pOrSgLzKAk+61ExXZcoAs B6wuvPUYHzdCSdJwdiDgLNnIEsj5nOzSqVKXceCOr9WwdVvlEdtsdg80n8Z4tGzTwzQd ReDcVsm+szK+PZ38NpVERFXWrOX565biGuQU2M26bJGl8iZBCjWAivubbeSjg713efLO Kskw== X-Gm-Message-State: AN3rC/7z6GJvTEKnAgXW9dK9hvN3fjUjkAkBo1W4ZI+qkqbrHs81yTU8 DkyUK14AQHAtU2dkpnDZwA== X-Received: by 10.80.176.5 with SMTP id i5mr46820086edd.134.1494326742977; Tue, 09 May 2017 03:45:42 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id o30sm2331510edc.42.2017.05.09.03.45.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 03:45:42 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 32/37] KVM: arm/arm64: Slightly rework kvm_vgic_addr Date: Tue, 9 May 2017 12:45:01 +0200 Message-Id: <20170509104506.30929-33-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170509104506.30929-1-cdall@linaro.org> References: <20170509104506.30929-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_034604_969014_35D4EF9F X-CRM114-Status: GOOD ( 12.27 ) 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: Christoffer Dall , kvm@vger.kernel.org, Marc Zyngier , Eric Auger , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.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 As we are about to handle setting the address for the redistributor base region separately from some of the other base addresses, let's rework this function to leave a little more room for being flexible in what each type of base address does. Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- virt/kvm/arm/vgic/vgic-kvm-device.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-kvm-device.c b/virt/kvm/arm/vgic/vgic-kvm-device.c index d48743c..69ccfd5 100644 --- a/virt/kvm/arm/vgic/vgic-kvm-device.c +++ b/virt/kvm/arm/vgic/vgic-kvm-device.c @@ -37,6 +37,14 @@ int vgic_check_ioaddr(struct kvm *kvm, phys_addr_t *ioaddr, return 0; } +static int vgic_check_type(struct kvm *kvm, int type_needed) +{ + if (kvm->arch.vgic.vgic_model != type_needed) + return -ENODEV; + else + return 0; +} + /** * kvm_vgic_addr - set or get vgic VM base addresses * @kvm: pointer to the vm struct @@ -57,40 +65,36 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) { int r = 0; struct vgic_dist *vgic = &kvm->arch.vgic; - int type_needed; phys_addr_t *addr_ptr, alignment; mutex_lock(&kvm->lock); switch (type) { case KVM_VGIC_V2_ADDR_TYPE_DIST: - type_needed = KVM_DEV_TYPE_ARM_VGIC_V2; + r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V2); addr_ptr = &vgic->vgic_dist_base; alignment = SZ_4K; break; case KVM_VGIC_V2_ADDR_TYPE_CPU: - type_needed = KVM_DEV_TYPE_ARM_VGIC_V2; + r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V2); addr_ptr = &vgic->vgic_cpu_base; alignment = SZ_4K; break; case KVM_VGIC_V3_ADDR_TYPE_DIST: - type_needed = KVM_DEV_TYPE_ARM_VGIC_V3; + r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V3); addr_ptr = &vgic->vgic_dist_base; alignment = SZ_64K; break; case KVM_VGIC_V3_ADDR_TYPE_REDIST: - type_needed = KVM_DEV_TYPE_ARM_VGIC_V3; + r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V3); addr_ptr = &vgic->vgic_redist_base; alignment = SZ_64K; break; default: r = -ENODEV; - goto out; } - if (vgic->vgic_model != type_needed) { - r = -ENODEV; + if (r) goto out; - } if (write) { r = vgic_check_ioaddr(kvm, addr_ptr, *addr, alignment);