From patchwork Tue May 9 08:56:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717347 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 9188060365 for ; Tue, 9 May 2017 08:57:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 857E928389 for ; Tue, 9 May 2017 08:57:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78BF6283CA; Tue, 9 May 2017 08:57:46 +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 0C2E828389 for ; Tue, 9 May 2017 08:57:46 +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=aWuHq2VN11w/oZy8wAe0T4ZJNaLaVX5MsyD+njT/HWU=; b=Gf+rw9E2WrTpKfrcpDHjrd8Eg1 i4d5cN9eMnbZzTBrpKOJeIm/Pd2tqDhgwc87XcYJNj06DnYrIgShLf+H6KmEo3j93h+4GTc54AMmR ciUeQoZyoqtpIbQYkfekMjAyiAIviKSGlVGbNqFLDs0N/Och89MWQ7+nB8zM4OxbdqBdnlBikd8XM uZISDyzzJQ4/nZfC5/XnVL/XkGN9wLnzCeCVd2x7H2OtsFfQvtQK5IvjprDaQWnQLBvGtW0WRpXNh L+DBuBYrIXz8n2oVbIADqxO5BgnWhxe8dSEpesgMZycLUo3JrBvwz4hR1UaJip08cf9vHUb2YFjvC T+f19YXg==; 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 1d80xl-0003ZN-Hd; Tue, 09 May 2017 08:57:45 +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-0002IP-VO 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 m123so92391022wma.0 for ; Tue, 09 May 2017 01:56:30 -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=bntLv/zY+/JVyBdF3ZyVAfmql7Qp6pTv1DcK8iSoyH4=; b=GKGDJB9C3zzZaCxNeXdqVv8ANhjxigX3Va6tu4c30KhaNdKTnaCLxtZF/8Iyfhx77n Y7g4uqfC2311LJohfkLXtLLfB5X6jlN7nd03zHFmcGPkbjfebTEkgrgiCAcgmdZMBtfN j3WTUdU+jnToPPnwEptYS54aPM6QNUTvjwYco= 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=bntLv/zY+/JVyBdF3ZyVAfmql7Qp6pTv1DcK8iSoyH4=; b=U93MN4KpLPmw+WX54v7VNbq1M36qF/o9sHP4lTKge3ZtG9xElqO9MFGHFoFe9NOksF JZecaZwR1WhNJl6Q/GJks8344l/3v/2aSy162CkhLqh+trI70/iEd53RTBtPSaz/glZ8 /GFLffi0FiMOc/IlojPT70VfMfqqZgF8VTGHVbUzCaaLM5A5TakWwVQKwVSVZ10GxOcj HceCqeOuE5OW3Dmq3g2j7T5D5nWDdcEeM6yaYPdQdJ/Mzlm9W/VId/IkJAyP5en2RjcD sbb3OR/9WbY82onlm6gOCqBTciHhaJ/zwKbBBp6Q8KnzgbtWQI9nXjHtxK0NESArEKjU BNuQ== X-Gm-Message-State: AODbwcAgJJnyAHDMvXC5voze+a3NVbt6FJ2S9KAN9yusIRouIS3hJAlr 5GCH8nuhCgi6LIgb X-Received: by 10.80.138.145 with SMTP id j17mr11232899edj.141.1494320189154; 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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 01:56:28 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 05/11] KVM: arm/arm64: Make vgic_v3_check_base more broadly usable Date: Tue, 9 May 2017 10:56:12 +0200 Message-Id: <20170509085618.28311-6-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_376886_49F34971 X-CRM114-Status: GOOD ( 16.82 ) 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 fiddle with the IO device registration mechanism, let's be a little more careful when setting base addresses as early as possible. When setting a base address, we can check that there's address space enough for its scope and when the last of the two base addresses (dist and redist) get set, we can also check if the regions overlap at that time. This allows us to provide error messages to the user at time when trying to set the base address, as opposed to later when trying to run the VM. To do this, we make vgic_v3_check_base available in the core vgic-v3 code as well as in the other parts of the GICv3 code, namely the MMIO config code. We also return true for undefined base addresses so that the function can be used before all base addresses are set; all callers already check for uninitialized addresses before calling this function. Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- virt/kvm/arm/vgic/vgic-v3.c | 19 +++++++++++++++---- virt/kvm/arm/vgic/vgic.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 12e52a0..2d53d7a 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -329,19 +329,30 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) return 0; } -/* check for overlapping regions and for regions crossing the end of memory */ -static bool vgic_v3_check_base(struct kvm *kvm) +/* + * Check for overlapping regions and for regions crossing the end of memory + * for base addresses which have already been set. + */ +bool vgic_v3_check_base(struct kvm *kvm) { struct vgic_dist *d = &kvm->arch.vgic; gpa_t redist_size = KVM_VGIC_V3_REDIST_SIZE; redist_size *= atomic_read(&kvm->online_vcpus); - if (d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE < d->vgic_dist_base) + if (!IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) && + d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE < d->vgic_dist_base) return false; - if (d->vgic_redist_base + redist_size < d->vgic_redist_base) + + if (!IS_VGIC_ADDR_UNDEF(d->vgic_redist_base) && + d->vgic_redist_base + redist_size < d->vgic_redist_base) return false; + /* Both base addresses must be set to check if they overlap */ + if (IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) || + IS_VGIC_ADDR_UNDEF(d->vgic_redist_base)) + return true; + if (d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE <= d->vgic_redist_base) return true; if (d->vgic_redist_base + redist_size <= d->vgic_dist_base) diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index a2aeaa8..89eb935 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -175,6 +175,7 @@ int vgic_v3_map_resources(struct kvm *kvm); int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq); int vgic_v3_save_pending_tables(struct kvm *kvm); int vgic_register_redist_iodevs(struct kvm *kvm); +bool vgic_v3_check_base(struct kvm *kvm); void vgic_v3_load(struct kvm_vcpu *vcpu); void vgic_v3_put(struct kvm_vcpu *vcpu);