Received: by 10.192.165.148 with SMTP id m20csp2720235imm; Sun, 29 Apr 2018 05:35:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqSwPyLIsgreF2N8tCUcbpm/QQdmr+JmIMpATSmQ26akp39dM3pZKGQbC4jp71QcIaF4pJz X-Received: by 2002:a17:902:8343:: with SMTP id z3-v6mr9114789pln.71.1525005331641; Sun, 29 Apr 2018 05:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525005331; cv=none; d=google.com; s=arc-20160816; b=eU+y51o6AD+w/npSEh5F70ArQbsc8sDHt6HyHaRixk7QEpTCdOObYW0HRN3cajKYmY ZncJ27/qpt587cl2giCigbAgTandyxXFVIhrTXPkFCAQmVizpZHcuFKOJ6sW+fopispz vtLZHSZuf1dd1f9uAXniRGg9KjhnKVmfcH+JiL4t6KMhmsq5nFxGOvM898iABpVZFCoI SrHT9USfumKPsVH/ijlwXMcGcKMqMNey4L1TKOi1eMVhzKt1ydp3b83b8dE6Nf7LfWXU +RVv4mt1bRFhHbEpQ4CFuOKDUA2ZywrQYaGQ326LUA7ybdHsNFogLQjJtnqkcn9ttcty 6ptQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=SMn69ESPwfYCKZ0w+JOHcO1mSoJSBBamJtq6xNarQtI=; b=GShmNCVl3kuJ1OX/ujx9mLisQ65CchklbJkryxTrMW2Mmur01Tyj6w7/6Mw9yPEVfe gVj68xnBtTQnSaUxbgNzHtyaIVPjoWQLCkNqsdcXoEufkh5CQO4HH2lccZtLT/oEWEsq mm7DXn2IeGYg1IxaddtSN0PT9FSIgueHn0UoDdrkHsVbwFmsBlANmOy+cs84nbAIMkom ozW3qCXQ/XDJSiW5lGYsGFypeZ7MvPF1PjKenrGSCY/FvfRHFQ63A0wfosg1IAaezh3I 6TqTIn3BQPV9KlJUlh7peExOOshMYFl6P6w3zB4YlIga3aOEu9My/mJAKF7UQDZRynZN 442w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si5627833plq.136.2018.04.29.05.35.17; Sun, 29 Apr 2018 05:35:31 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753450AbeD2MfF (ORCPT + 99 others); Sun, 29 Apr 2018 08:35:05 -0400 Received: from foss.arm.com ([217.140.101.70]:52416 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752895AbeD2MfE (ORCPT ); Sun, 29 Apr 2018 08:35:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 034A21529; Sun, 29 Apr 2018 05:35:04 -0700 (PDT) Received: from localhost (unknown [10.37.8.121]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66B7C3F25D; Sun, 29 Apr 2018 05:35:03 -0700 (PDT) Date: Sun, 29 Apr 2018 14:35:01 +0200 From: Christoffer Dall To: Eric Auger Cc: eric.auger.pro@gmail.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, andre.przywara@arm.com Subject: Re: [PATCH v4 06/12] KVM: arm/arm64: Adapt vgic_v3_check_base to multiple rdist regions Message-ID: <20180429123500.GC7512@C02W217FHV2R.local> References: <1524838505-3823-1-git-send-email-eric.auger@redhat.com> <1524838505-3823-7-git-send-email-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1524838505-3823-7-git-send-email-eric.auger@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 27, 2018 at 04:14:59PM +0200, Eric Auger wrote: > 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. nit: inferred > > 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 > Reviewed-by: Christoffer Dall