Received: by 10.192.165.148 with SMTP id m20csp3553660imm; Mon, 30 Apr 2018 02:11:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpm3eZFzHD53xpi6T15K+KqetHilKM+/uPORu1F/Q2tXje9bsi9C8pIFKEo6YMxnQCkF4Rl X-Received: by 10.98.47.2 with SMTP id v2mr11297200pfv.239.1525079471888; Mon, 30 Apr 2018 02:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525079471; cv=none; d=google.com; s=arc-20160816; b=SwlXW2ei5IcmXhc8Aw1Yx7NtD/l+WFXyWhALS61inwbhxCNTBv8BPs0dOxm7YTZr4h 8hOsx87FN38UEma1vcd2hdXtKvT4AG4N/g7ucuGqDOyaE8wwq8zXZpg1R8E5Eeuo0mrV 59t5h5N5SoK+nnUuF72uS9yVeIJXpEE2QpPmXmCBb6kdDKhu/jhgwAT9bhue0Ei2ZhRG DII4WvQSnbJSv/KQ/5iFB5FEeC3GdlLhzjT5rmAoWpp1PdgfSK3XhN67C4sX/F+cnP+5 wuZtjicGT6mKfoKaCwmk2q06RZdoe7SBwcl5yyfZ8IfPKH+9XZh+O4YSA3a5UIYIC3AF sT9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=0lWPqWy4AmESMP//ndY1R4hHQ9KtloYSkWQHAIh5wWo=; b=X80R+ZU2xCl6O1eIvGtzPDTlKKqcS2ql+UJdQ3ihays9Y29vuXuqjNuFQzBP0vW9/8 DRx5L9PJdDgaxYh1+TNa+uTo/qjJe5Iy1iFDQyq1OVD5tHnb3cf9nF6SO9+lLMiz0WIk Pv3CZxeNezeN21tNK/eoDHS4CFhib4pLecXd4sEjnja72GzludjqPsCVKe5ejA+tEYlk M27eN+2aecMqI7WJ683Os0cDbE/9RiiyCHsGeA1/h+ggicXr2ic/yUx8yE3JZQiiDoyu mNsqzfdQoyX27Tw378HX46UJZzz7SlQxJtyf6cEtQLvSNroq34KoEj2TdFmbfMLg110J A3lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si6864089pff.301.2018.04.30.02.10.58; Mon, 30 Apr 2018 02:11:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753542AbeD3JKG (ORCPT + 99 others); Mon, 30 Apr 2018 05:10:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49514 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752653AbeD3JIB (ORCPT ); Mon, 30 Apr 2018 05:08:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C95AC4023457; Mon, 30 Apr 2018 09:08:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-57.ams2.redhat.com [10.36.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 245002024CA1; Mon, 30 Apr 2018 09:07:59 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, cdall@kernel.org, peter.maydell@linaro.org Cc: andre.przywara@arm.com, drjones@redhat.com, wei@redhat.com Subject: [PATCH v5 06/12] KVM: arm/arm64: Adapt vgic_v3_check_base to multiple rdist regions Date: Mon, 30 Apr 2018 11:07:38 +0200 Message-Id: <1525079264-25533-7-git-send-email-eric.auger@redhat.com> In-Reply-To: <1525079264-25533-1-git-send-email-eric.auger@redhat.com> References: <1525079264-25533-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 30 Apr 2018 09:08:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 30 Apr 2018 09:08:00 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vgic_v3_check_base() currently only handles the case of a unique legacy redistributor region whose size is not explicitly set but inferred, instead, from the number of online vcpus. We adapt it to handle the case of multiple redistributor regions with explicitly defined size. We rely on two new helpers: - vgic_v3_rdist_overlap() is used to detect overlap with the dist region if defined - vgic_v3_rd_region_size computes the size of the redist region, would it be a legacy unique region or a new explicitly sized region. Signed-off-by: Eric Auger Reviewed-by: Christoffer Dall --- v4 -> v5: - s/infered/inferred in the commit msg - Added Christoffer's R-b v3 -> v4: - squash vgic_v3_check_base adaptation and vgic_v3_rdist_overlap + vgic_v3_rd_region_size introduction and put this patch before v3 patch 6 --- virt/kvm/arm/vgic/vgic-v3.c | 49 +++++++++++++++++++++++++++++---------------- virt/kvm/arm/vgic/vgic.h | 10 +++++++++ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index f81a63a..c4a2a46 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -410,6 +410,29 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) return 0; } +/** + * vgic_v3_rdist_overlap - check if a region overlaps with any + * existing redistributor region + * + * @kvm: kvm handle + * @base: base of the region + * @size: size of region + * + * Return: true if there is an overlap + */ +bool vgic_v3_rdist_overlap(struct kvm *kvm, gpa_t base, size_t size) +{ + struct vgic_dist *d = &kvm->arch.vgic; + struct vgic_redist_region *rdreg; + + list_for_each_entry(rdreg, &d->rd_regions, list) { + if ((base + size > rdreg->base) && + (base < rdreg->base + vgic_v3_rd_region_size(kvm, rdreg))) + return true; + } + return false; +} + /* * Check for overlapping regions and for regions crossing the end of memory * for base addresses which have already been set. @@ -417,31 +440,23 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) bool vgic_v3_check_base(struct kvm *kvm) { struct vgic_dist *d = &kvm->arch.vgic; - gpa_t redist_size = KVM_VGIC_V3_REDIST_SIZE; - struct vgic_redist_region *rdreg = - list_first_entry(&d->rd_regions, - struct vgic_redist_region, list); - - redist_size *= atomic_read(&kvm->online_vcpus); + struct vgic_redist_region *rdreg; 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 (rdreg && (rdreg->base + redist_size < rdreg->base)) - return false; + list_for_each_entry(rdreg, &d->rd_regions, list) { + if (rdreg->base + vgic_v3_rd_region_size(kvm, rdreg) < + rdreg->base) + return false; + } - /* Both base addresses must be set to check if they overlap */ - if (IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) || !rdreg) + if (IS_VGIC_ADDR_UNDEF(d->vgic_dist_base)) return true; - if (d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE <= rdreg->base) - return true; - - if (rdreg->base + redist_size <= d->vgic_dist_base) - return true; - - return false; + return !vgic_v3_rdist_overlap(kvm, d->vgic_dist_base, + KVM_VGIC_V3_DIST_SIZE); } /** diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index fea32cb..e6e3ae9 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -262,6 +262,16 @@ vgic_v3_redist_region_full(struct vgic_redist_region *region) struct vgic_redist_region *vgic_v3_rdist_free_slot(struct list_head *rdregs); +static inline size_t +vgic_v3_rd_region_size(struct kvm *kvm, struct vgic_redist_region *rdreg) +{ + if (!rdreg->count) + return atomic_read(&kvm->online_vcpus) * KVM_VGIC_V3_REDIST_SIZE; + else + return rdreg->count * KVM_VGIC_V3_REDIST_SIZE; +} +bool vgic_v3_rdist_overlap(struct kvm *kvm, gpa_t base, size_t size); + int vgic_its_resolve_lpi(struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid, struct vgic_irq **irq); struct vgic_its *vgic_msi_to_its(struct kvm *kvm, struct kvm_msi *msi); -- 2.5.5