Received: by 10.213.65.68 with SMTP id h4csp1377809imn; Mon, 19 Mar 2018 02:25:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELt9xuUFHrsAYwn+8IocMZzuplsS7Lly07X5K6XHS9K4063ob99ikQ4uabG1FB9Cc6SN5lol X-Received: by 2002:a17:902:c6b:: with SMTP id 98-v6mr11588973pls.267.1521451514349; Mon, 19 Mar 2018 02:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521451514; cv=none; d=google.com; s=arc-20160816; b=HrL0wJP/IrbZbMmMLHE0XTuLomsT3Afp0HqJ4QPi/fGGulifX7dzwpaygibqo81Blj F9J0B2OZgsqS/SxufDJ5T1f82y271czeIjAZ2TVVPyJZgD5TjHhFx3/ByhBJa+KkXrg+ cvkRe1BqtTCYpT/rfYwwU6CqpN+t/zu6/3yfy8pATNdx2wsPsm1oJr6YWOunUUbnr3xF kQniR4f4SVKBUK4dcytQua41beGDJ8i+YNmT0cNVl0L/W16ZEMlrgVYrfrQXI80qOPue f5nqWhlm+44maYfhz9nE+Bbd/WZ5ScJ12d+6gzKhRtlLt399QD1BTzWa3m0G6OXaLfb8 5GRw== 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=Nxo8dJswLvDI0jgnAJiSa0vwgFmEIJ4AvkisLyDTZsQ=; b=AyhG4VZbE12+bloCCC2hzV6j7PilpRn/BoigDDREujxyRbRGq1+VAF+uXI8aftU26Z 9JhdvkcNhqfxXkXUrdrUWVwOWe0oroCjy4Zto1vDKJPDAixaU80w0LRTXf47ZnpbLoLp aySywQ1RGgsWFk8qffeslUG1leyEyVwv1g6p+yYNBKidvy3GzmkztvkR6WKd1EwfWAm0 Rb7vjIlD8/ejUkyA9eeEV5Cy3UH6Y0YCO8qIJO8AyllcpuXgh84O/GAp0Txw5kBBRWKX sUsnleqBAQVPacMx5C9d16yKsSOFfrqZSio7ZzUOQFqw+FgZ0SBsGIb34pejY134LOPX l8YA== 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 z11-v6si11750077pln.732.2018.03.19.02.25.00; Mon, 19 Mar 2018 02:25:14 -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 S933219AbeCSJUw (ORCPT + 99 others); Mon, 19 Mar 2018 05:20:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43706 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932973AbeCSJUo (ORCPT ); Mon, 19 Mar 2018 05:20:44 -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 4652A4023BB3; Mon, 19 Mar 2018 09:20:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BFD26353D; Mon, 19 Mar 2018 09:20:41 +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: [RFC 05/12] KVM: arm/arm64: Helper to locate free rdist space Date: Mon, 19 Mar 2018 10:20:13 +0100 Message-Id: <1521451220-27754-6-git-send-email-eric.auger@redhat.com> In-Reply-To: <1521451220-27754-1-git-send-email-eric.auger@redhat.com> References: <1521451220-27754-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.7]); Mon, 19 Mar 2018 09:20:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 19 Mar 2018 09:20:43 +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 We introduce vgic_v3_rdist_free_slot to help identifying where we can place a new 2x64KB redistributor. Signed-off-by: Eric Auger --- virt/kvm/arm/vgic/vgic-mmio-v3.c | 4 ++-- virt/kvm/arm/vgic/vgic-v3.c | 21 +++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 12 ++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index c9dc08f..227b8b6 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c @@ -586,6 +586,7 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu) struct vgic_io_device *sgi_dev = &vcpu->arch.vgic_cpu.sgi_iodev; struct vgic_redist_region *rdreg; gpa_t rd_base, sgi_base; + uint32_t free_pfn_offset; int ret; /* @@ -594,8 +595,7 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu) * function for all VCPUs when the base address is set. Just return * without doing any work for now. */ - rdreg = list_first_entry(&vgic->rd_regions, - struct vgic_redist_region, list); + rdreg = vgic_v3_rdist_free_slot(&vgic->rd_regions, &free_pfn_offset); if (!rdreg) return 0; diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 14dabda..68cae0e 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -431,6 +431,27 @@ bool vgic_v3_check_base(struct kvm *kvm) return false; } +/** + * vgic_v3_rdist_free_slot - Lookup registered rdist regions and identify one + * which has free space to put a new rdist regions + * + * If any, return this redist region handle and the pfn offset to the free slot. + * Otherwise, returns NULL. + */ +struct vgic_redist_region *vgic_v3_rdist_free_slot(struct list_head *rd_regions, + uint32_t *free_pfn_offset) +{ + struct vgic_redist_region *rdreg; + + list_for_each_entry(rdreg, rd_regions, list) { + if (!vgic_v3_redist_region_full(rdreg)) { + *free_pfn_offset = rdreg->free_pfn_offset; + return rdreg; + } + } + return NULL; +} + int vgic_v3_map_resources(struct kvm *kvm) { int ret = 0; diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index 12c37b8..38b2406 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -245,6 +245,18 @@ static inline int vgic_v3_max_apr_idx(struct kvm_vcpu *vcpu) } } +static inline bool +vgic_v3_redist_region_full(struct vgic_redist_region *region) +{ + if (!region->pfns) + return false; + + return (region->free_pfn_offset > region->pfns - 2); +} + +struct vgic_redist_region *vgic_v3_rdist_free_slot(struct list_head *rd_regions, + uint32_t *free_pfn_offset); + 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