From patchwork Mon May 8 11:54:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9716139 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 D9DBC60387 for ; Mon, 8 May 2017 11:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C342E223C7 for ; Mon, 8 May 2017 11:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3DA826E5D; Mon, 8 May 2017 11:55:53 +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 535E4268AE for ; Mon, 8 May 2017 11:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754466AbdEHLzH (ORCPT ); Mon, 8 May 2017 07:55:07 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:33697 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752942AbdEHLzF (ORCPT ); Mon, 8 May 2017 07:55:05 -0400 Received: by mail-wm0-f42.google.com with SMTP id n198so16480577wmg.0 for ; Mon, 08 May 2017 04:55:05 -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=r+xhNsI0TyCi8zn8qOTx9EXnpSb1ccjjkcKW8DQDsrg=; b=Z7c+bxoeNFo/xyzPSFFLTpqXtzsmGzjJhBJyYY3NxG0UJR6LA5+KP9Hpm/96s5HEa8 gM08ZnnXq+6/aSJF+JideSv6mOhVwN1/e9RWLXmOy+T1nTIjj1rUS7rDUgRAZriZd8+s vqHtHrdZmdv8uktep4olqYLG1KyuSgeE/Rq9k= 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=r+xhNsI0TyCi8zn8qOTx9EXnpSb1ccjjkcKW8DQDsrg=; b=JEj23jEnkd8KVcNKt7Tz2rdHEwp+bRBYCoAZOGsWNkNHIy+ag5Ema24ml0ZT4VXqzk bDiEq0JXKM6t3XBwjmea4WvEwMLVsGk/huDcQfnoBMOJsYOkPm6ufhEBU2OH3Vqubeqd 8MB1TFruhI3q9qNYs/EJpHtQL/q0GySb5WXNfvFBa7pjAPEpVmNbgLUPUCw9q+lkEiXN VdFSxji6OuNsmPHV/DkvIBEn5DJUSJx8jsSZORhKb6pPsd+hGiLFZjMMwWAyZm5tW29A DN1X3hzBsQ65f3Epg17uxF3jPzZpvYAmUDZvKxHmiJITm6/TUkXnzvsSwIFg5aGz8fw2 KmQA== X-Gm-Message-State: AN3rC/6shFygS1wS5rwTcXC7Eve0lHapSzDRWXudARleBfUfpuPekcAP 7J6M67L286dTBGDm X-Received: by 10.80.174.36 with SMTP id c33mr44727616edd.103.1494244504293; Mon, 08 May 2017 04:55:04 -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.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 04:55:03 -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 4/8] KVM: arm/arm64: Make vgic_v3_check_base more broadly usable Date: Mon, 8 May 2017 13:54:50 +0200 Message-Id: <20170508115454.5075-5-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 fiddle with the io device registration mechanism let's be a little more careful in verifying the addresses we can ealier on to provide error messages to the user at time related to him/her setting overlapping addresses. We still want to check a consistent system before actually running the VM for the first time, so 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 --- virt/kvm/arm/vgic/vgic-v3.c | 18 ++++++++++++++---- virt/kvm/arm/vgic/vgic.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 12e52a0..b934e78 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -329,19 +329,29 @@ 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; + 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);