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: 9716143 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 3938D6035D for ; Mon, 8 May 2017 11:56:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2159C223C7 for ; Mon, 8 May 2017 11:56:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 163A7268AE; Mon, 8 May 2017 11:56:18 +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 A77DA223C7 for ; Mon, 8 May 2017 11:56:17 +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=yvwo3kX2QsijBX34EAVLZQkW5acvk/m8cUfXWQcRsmQ=; b=Qi/sN9q1R/HSm7kvLWqwbO4Y4Y fxoi2XQdknQhiITAsrY2dhAMeAzBHIe/t7aw875Kbu4TCAuEsaa0EO7fSAZzJnZkeCJkAvEYqAtSI O8qzzelrDs/acs4UNxG3HEt8MxX+mMiys/KL+egIfusjqnqnqs96cq9d5RA1yyST+j1qgYQ72+IVt S0J8CW0h1lz+xCLmcznOJHUonHu2hTt2u/KmfAlC9JPfFqb0BMtyqSEpqLVYp0HSqmWXbFbTQn9dZ 5lGpRcsDMoGXN6xzZlEzjqRVpaGMh1jhnOt4ZTVm4iTSE2PeRMAKkM1IrP9IciZDTtW9F5p8sLvqJ IUWduaDQ==; 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 1d7hGy-0007Wo-Mw; Mon, 08 May 2017 11:56:16 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d7hGA-0005ow-Pj for linux-arm-kernel@lists.infradead.org; Mon, 08 May 2017 11:55:30 +0000 Received: by mail-wm0-x234.google.com with SMTP id m123so61991569wma.0 for ; Mon, 08 May 2017 04:55:06 -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=ia6nw4Nu6u9dVs9GrVjz13bvpZowZma7GKLCf8EetoAnh1+1DVjEDAnUc0U6bfE00u uvdTXkllXpA6srLC6icHfwmXFqWUaOqaiMyJPDR0eisgP834EFT1dUC33n2dkfiFkQlo 4vQaKX+QXz9n1zSVmcX2MaV06iumu9juNY2/MNAkJ+t1qqnj6YPT6YbDN+nUdy+OzFAq MvlaGEDQv7nTSETiJHGAbkkzWElT5bmRo9qIXCUdfX4CCPt9HkzgUIBTeUamMyYf7YWB KLvtZLGc1lpZqeFixGnFQfmJ/ix2MfwBhmbqoF2Q56BXyWFCOQFbkdQGA248G5tbO3A1 63CA== X-Gm-Message-State: AN3rC/4yUy77l5ZDs0gBw1Z+1r1CqBafDu3LoCaVw6wEagKyyETaPpn0 KsAA6qXGcj/60g0E 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170508_045527_164252_28038C16 X-CRM114-Status: GOOD ( 12.84 ) 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);