Received: by 10.192.165.148 with SMTP id m20csp774381imm; Fri, 27 Apr 2018 07:19:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo3vipZI4BPJw6HbijwH724SuLHdiywiwwalAbMWX454VEMLIJq2Urn0fng8FfXiyY4fZjf X-Received: by 2002:a17:902:7d95:: with SMTP id a21-v6mr2555997plm.12.1524838773337; Fri, 27 Apr 2018 07:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524838773; cv=none; d=google.com; s=arc-20160816; b=uVwDbQUVIpUJ1EDqk26rHGcPckwPXxq+qzwKAOTDQTOpafRf0qjty21oLy/JC6PUTb Qz7iwCbkbZWOhmAZNfZEpibDEpHJ3ct8AoikyJxPvqA9YjtW8hpxpCNH44Cq3kYud4fR 9RUq0kbyBbH5Kv1MgfWTQusmtbl1XVt5B19wUmiULcui1gWrIGYxnJ4XvpOwfiE1mtE5 hW2UEzxH0SPbVcaUpHc3QW49wXJOkdQyAnuvKcM93uhLjoWFKLidhS6mepXUdtj1gD7B kwud3dA/nz2xjYX4nOuL5+zvg6jzl2JalIIo6DmPzB1vGgnOhMdP8XPXryhmeGYFtI6R 4dmg== 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=nklotQVx0T5ukgtMt8cHEhZ0XLO7AdOtp0ruLnIqElc=; b=MWdoOg8mF1B4EjRqoOhqmQ8M4XjrSnF8xY73fYPET9q1qZEDT+PCCNpl2gPXDRc9DE k1szTE8XucpepATb0Rv6O9gkjytmqAk2Th+cdC8AmMMZAEGTI4t2skDqSb7GQPYrvmBl 9Dj26mQ+Tcs6aKzXT0RKdojXJD446BErwiEF6hlSM36kXG38DZnPloAZXzDKCHMIdso9 7Gnf29x34Pk3ghE6PdXrSgV1MFeMP2RxYCdjbK0lBQXK42Pi+1eA1W2KAWy53XudJZ1c vWzPGcmSmlG6VMYKR6Nkh134PKYj5FgkyMsPcJe0CrB1Bsbg6kgeNWRs9GcuXVPSsQdQ WHsw== 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 e12-v6si1360900plj.143.2018.04.27.07.19.19; Fri, 27 Apr 2018 07:19:33 -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 S935518AbeD0ORa (ORCPT + 99 others); Fri, 27 Apr 2018 10:17:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59222 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935318AbeD0OP0 (ORCPT ); Fri, 27 Apr 2018 10:15:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB36C402333B; Fri, 27 Apr 2018 14:15:25 +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 F2C67AB581; Fri, 27 Apr 2018 14:15:23 +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 v4 06/12] KVM: arm/arm64: Adapt vgic_v3_check_base to multiple rdist regions Date: Fri, 27 Apr 2018 16:14:59 +0200 Message-Id: <1524838505-3823-7-git-send-email-eric.auger@redhat.com> In-Reply-To: <1524838505-3823-1-git-send-email-eric.auger@redhat.com> References: <1524838505-3823-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 27 Apr 2018 14:15:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 27 Apr 2018 14:15:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 infered, 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 --- 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