From patchwork Tue May 9 08:56:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717349 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 527FD60365 for ; Tue, 9 May 2017 08:58:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4681A28389 for ; Tue, 9 May 2017 08:58:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B146283CA; Tue, 9 May 2017 08:58:04 +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 E219D28389 for ; Tue, 9 May 2017 08:58: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=m3YnbMINpP2q1yItSfyjdQ4ej68qYdtBHBvWCwSwELg=; b=YLLRFGqLlK3PEZuJIVpnFxa78o Sbp5qH70DCedzcjqWIw8KFgKwHsB29cMameYnSiAVA/mOBofG1J4rZGytG7yTFXuOJ7Rz8/jN4+RA VD6mkftVBC+rIB3hskRobbULn20Lh2TMYSMxDZb5c4gHedXR3RAPbdGQtgz7w2ss1gE3zbZIHuY6E 7L3Ckx4My0IxoiAYYZNMFsMIbgrOuNNhP+DqVLXwnf84lwH0EXUF+PaSnyEjDzM3AB3jGf77NffJS DKQtP16eU+ZjCLlGRSMCf0zZh9Wx8ZkisZsNmj89MQ63Bb0kbFVZrGOHa4mNGKrEs6HKAFDW7K8q3 EBE3pgIw==; 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 1d80y2-0003rW-2m; Tue, 09 May 2017 08:58:02 +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 1d80ws-0002Ic-VT for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 08:56:54 +0000 Received: by mail-wm0-x22a.google.com with SMTP id m123so92391415wma.0 for ; Tue, 09 May 2017 01:56:31 -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=JekaH6mASTMK7hvSOdU83kAN6uSNcqrlnf0TP5iGH57D8dB6ttpMVROQApAlNrQ15N l6A6W5t31cercgtvRdXWl6hY2DfQKm3IEPikStuDaxOWP9Y0AeEcJ6DR8EVvRTjUQ80K oJAmLB9M+wVdBYfBEyXpnLM0J2fvyErliVs14= 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=dlQM2TlQ9gGhlyJq5gNVVm9Ipi/odQ6ZhZWE67+FdHhJV5hkSCci2xU9AcEBdyPsiw 8fKRHiDT553V7HN0ySwsDJ6b87LQS79l8N74iwLkvmejYdzD9u/vzRgXcz1iY/oZisUg LWDHxtsB855LI47WxqpHgqrtA+L0kNRIJj3+SHaqgO2B8bSzJsbxvU8GRyPNfefKbr+m c6Xyjzolmy2zxHkXJFSQJOB8ICI6hvEth3LjChg7b36dLIgAJjxHQT/x7vvJlF7tlCbL eLMBLZxgknlf8vnfjXt0TYKpVnp0SlK9S+kOqMbihVIfX6QFbAAxW2PwpuXtIej07id6 hfGg== X-Gm-Message-State: AN3rC/6vyorVHNpvpFpRLL3vi747WE0DfMFJFRMTlusPlRMkl/UPPRwZ 7YcDzuDc4IX2VoWQ X-Received: by 10.80.211.7 with SMTP id g7mr46681662edh.0.1494320189981; Tue, 09 May 2017 01:56:29 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id f40sm8376265edb.7.2017.05.09.01.56.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 01:56:29 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 06/11] KVM: arm/arm64: Slightly rework kvm_vgic_addr Date: Tue, 9 May 2017 10:56:13 +0200 Message-Id: <20170509085618.28311-7-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170509085618.28311-1-cdall@linaro.org> References: <20170509085618.28311-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_015651_267791_CAC5568B X-CRM114-Status: GOOD ( 12.91 ) 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: Marc Zyngier , Eric Auger , kvm@vger.kernel.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 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);