Received: by 10.192.165.156 with SMTP id m28csp428181imm; Fri, 13 Apr 2018 01:28:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/t61rAbyO2KhKkJ0cFW3DuY8KDsY9ddQyvzwrDYTr3Ouiem7KbKkJWTDPwvESqS6q78ZH+ X-Received: by 10.99.179.3 with SMTP id i3mr3337301pgf.434.1523608094431; Fri, 13 Apr 2018 01:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523608094; cv=none; d=google.com; s=arc-20160816; b=fIOLwHICNvd/iWHpQMFgLOCXX5P6Qr2MsOQkZtTk7d6gT8Wa2Rb/PqB9Vx+wkQ1jch xC1D5DWdkmFTi/TCWsUZ1BP2TW3blNQbwhcrEi0y5aneaW8B2YDeKxyPeTuttXentrfP 8PQe7Ga6As9FBPcCz2MfWGtGwo8Suu7fZNneMCSqjg0nuCzTewWo0NJSgoJUrr9wcAZC YLKm8VMBcsQ/44MqtBvvC4xoPQAPsMN17gbndti7XVcU2z3CXEYgafBBYxJ9sDwf8qFq HzHFsImz7aMIIAKk9q85baejNg1wgNEVzVxdAE77g4+02SG2EZv2uupRd63BTHIQ8ejG NlNg== 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=S2H/cHrSch7kiAyi9Bt8LuyjC9Pq6rqags/p0EmwSp4=; b=JVlI1Ta04uLmC4gl0FoIc74HeAKsj6N4ks7I4BXsZAzJC78NbQ5rtOrCYzfeMEhLys DFO9JuEFMk7UIYeYyzOyKR6AYJXJyAidEw8y6jaYOv1gaf95z8mne02s2mokE/pVmLfj Rcszk84IhMjGm9kmqNZFbL7Rg1Qmnfk8kTLLjvf0ea0POsQsZhFtLm0zAtNzLw6yZ1NA UtqQdZdZoAyeQVRaBUtMdgjyY6660ejRaXwBAG2aIyfOFQi66HfNTJqw/zh+KmlMPVGD N2THOVYFX9EqG+vvErKYgLvJLbaE6bLEfxFFMXbwWKbOj70KisIqx4ySxsCo7GXiH4Ms wXMg== 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 h34-v6si5235430pld.360.2018.04.13.01.28.00; Fri, 13 Apr 2018 01:28: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 S1754045AbeDMIYf (ORCPT + 99 others); Fri, 13 Apr 2018 04:24:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54074 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753117AbeDMIVM (ORCPT ); Fri, 13 Apr 2018 04:21:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AF6C9BA4B; Fri, 13 Apr 2018 08:21:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-192.ams2.redhat.com [10.36.116.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 090ED215CDCF; Fri, 13 Apr 2018 08:21:09 +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 v3 04/12] KVM: arm/arm64: Helper to locate free rdist index Date: Fri, 13 Apr 2018 10:20:50 +0200 Message-Id: <1523607658-9166-5-git-send-email-eric.auger@redhat.com> In-Reply-To: <1523607658-9166-1-git-send-email-eric.auger@redhat.com> References: <1523607658-9166-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 13 Apr 2018 08:21:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 13 Apr 2018 08:21:12 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 | 3 +-- virt/kvm/arm/vgic/vgic-v3.c | 17 +++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 11 +++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index d1aab18..49ca176 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c @@ -593,8 +593,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); if (!rdreg) return 0; diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 94de6cd..820012a 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -444,6 +444,23 @@ bool vgic_v3_check_base(struct kvm *kvm) return false; } +/** + * vgic_v3_rdist_free_slot - Look up registered rdist regions and identify one + * which has free space to put a new rdist regions + * + * If any, return this redist region handle, otherwise returns NULL. + */ +struct vgic_redist_region *vgic_v3_rdist_free_slot(struct list_head *rd_regions) +{ + struct vgic_redist_region *rdreg; + + list_for_each_entry(rdreg, rd_regions, list) { + if (!vgic_v3_redist_region_full(rdreg)) + 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 830e815..fea32cb 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -251,6 +251,17 @@ 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->count) + return false; + + return (region->free_index >= region->count); +} + +struct vgic_redist_region *vgic_v3_rdist_free_slot(struct list_head *rdregs); + 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