From patchwork Mon May 8 11:54:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9716127 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 D4FBA60234 for ; Mon, 8 May 2017 11:55:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCADD26224 for ; Mon, 8 May 2017 11:55:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B19DE26B41; Mon, 8 May 2017 11:55:28 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 30EF126224 for ; Mon, 8 May 2017 11:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754646AbdEHLzT (ORCPT ); Mon, 8 May 2017 07:55:19 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:37303 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754459AbdEHLzQ (ORCPT ); Mon, 8 May 2017 07:55:16 -0400 Received: by mail-wm0-f54.google.com with SMTP id m123so61991570wma.0 for ; Mon, 08 May 2017 04:55:10 -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=ejmzfHmdGAGf+R+glKm+SpxkYdGfhq1i/LdcCrEOCDA=; b=ftTqmkSmV6Fr5r/GF7R1e1dbtJIQCtUk4UZ/psTuP1756qgcFDk9I6Hk01beVpj5ES keNL9hcZLJue7zQ84QEIF0cGiqmGt9M+0/VZQ6N9JE3szjlj/ADrJO3joVRF9Y4vgcLJ c6YO0uWU5IkydTbtXJcgsqsqfaD6bLTIhWPKU= 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=ejmzfHmdGAGf+R+glKm+SpxkYdGfhq1i/LdcCrEOCDA=; b=EA+jjIifhc2eypU9N+Dgq4GEhdtZuK4aS4eFDNJGDli8dErqcutfMRZXcZLnk54Huj aivtDyZRKv23yM7K2Ve1YJNMSxXLBnyYic7/YSNeAmlUacqhl9xbCd8XoaDYxchtIuFS XyVdjrFUIv2Vugy19teFZkoQacx7Q488Ez2kOz4DqmZjQWOS4P0OKTUE6JwE66neYDQC i+0K71+aIV2DsMEbKHQyfwAyQl1XMqR2+vv8MjJmoByh6ST65jWbJEBxYmKz2xZgnPyM GSoc4nbL+e/+GK5245M3mbO/TJLwr7lxa/j7p9JxjmXx5AM1KW+88jee7N/pkO4iNzTP cIoQ== X-Gm-Message-State: AN3rC/7p5oDuRSHrYZMzPzIKiIYSWYagoVRjcs81WXHyD9pWYjOXpI9u TgPZgoKT/fn3qGiMJ4Vi6g== X-Received: by 10.80.146.71 with SMTP id j7mr12991871eda.17.1494244505095; Mon, 08 May 2017 04:55:05 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id k43sm3483411ede.1.2017.05.08.04.55.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 04:55:04 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Eric Auger , Christoffer Dall Subject: [PATCH 5/8] KVM: arm/arm64: Slightly rework kvm_vgic_addr Date: Mon, 8 May 2017 13:54:51 +0200 Message-Id: <20170508115454.5075-6-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170508115454.5075-1-cdall@linaro.org> References: <20170508115454.5075-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 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);