Received: by 10.192.165.148 with SMTP id m20csp3552881imm; Mon, 30 Apr 2018 02:10:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrs6NiA3TmRzrmMBui+AZslv6JiqrgHqlB7ZlDL9lkA9PBhde8ZJWfetXGyENRSK9AykjPU X-Received: by 2002:a63:60c1:: with SMTP id u184-v6mr9338938pgb.122.1525079416025; Mon, 30 Apr 2018 02:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525079415; cv=none; d=google.com; s=arc-20160816; b=a7ePrLQ6occn8yCNbtrxvUzRfD3mrtrtn78mWazeEcaeG7Ny9ypEuXb3MwxDj4MlJn yClRZpfG3cNCdt7/LLFy9LPe/VTrKqy7/ygS6Z/1iA5x3CojYeT0ft5X0lUN48tQ3ld2 wIfqNt9JENDYtk5y4HXDdqNlTwxKRhbzWGFtBrarqLduOKHUGDJiY/fOMfnapoFGsOpl /BK9gpUiKO3vca1AYh4BOm7h9ZeFGj4KD1ZvCXONSCDfPItagct4MfSzZQkGqog4cRUT lk6sIyBG9aPUJLzlV78JDxGms+KWdrmFi6tnWy5p90Fl0dbSqpwXsgNPv/bVTd/sClZK 9Wrg== 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=4ePKR7VyQ1Hm/dk11UCQaPLXgHgKxaErHXoFd7k5Cfk=; b=ubhxHvbUWponE3+sArny2wWuIKtAYhhqjBkOBEDAicE/PZmxCeB+lKcTEwQEufO5Or o31Qqvar7zFj+TU2RL4ZLqOUJfIBG3xMQ3T3Nwdp1TwoNgmVMJQKHkp/BhRyb3X/L2RN p7jnyxRfIGvt5daLMMYVDpRLuQp10oAW9XF6Wrdm7lxtOVK5sURZHjB+soV5uyGgt5ak 3Lc7AEzGj/2mCv4cSug6EhFIPOXx//J0HPUPMtcBrvX9H5c+g1TcRUwfmf7DvhPYaji3 AXfZmQY+t40yRT9LhisqGMjlHfOoadz4KWkLltxVkAVZBIi9C8oYgNB5km9hJVTnzJNb fk/g== 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 u18si555133pfn.213.2018.04.30.02.10.02; Mon, 30 Apr 2018 02:10:15 -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 S1753026AbeD3JIE (ORCPT + 99 others); Mon, 30 Apr 2018 05:08:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40752 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752877AbeD3JH5 (ORCPT ); Mon, 30 Apr 2018 05:07:57 -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 076D94182D58; Mon, 30 Apr 2018 09:07:57 +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 544232024CA1; Mon, 30 Apr 2018 09:07:55 +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 04/12] KVM: arm/arm64: Helper to locate free rdist index Date: Mon, 30 Apr 2018 11:07:36 +0200 Message-Id: <1525079264-25533-5-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.7]); Mon, 30 Apr 2018 09:07:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 30 Apr 2018 09:07:57 +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 We introduce vgic_v3_rdist_free_slot to help identifying where we can place a new 2x64KB redistributor. Signed-off-by: Eric Auger Reviewed-by: Christoffer Dall --- v3 -> v4: - add details to vgic_v3_rdist_free_slot kernel doc comment - Added Christoffer's R-b --- virt/kvm/arm/vgic/vgic-mmio-v3.c | 3 +-- virt/kvm/arm/vgic/vgic-v3.c | 23 +++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 11 +++++++++++ 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 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..f81a63a 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -444,6 +444,29 @@ 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 region. + * + * @rd_regions: redistributor region list head + * + * A redistributor regions maps n redistributors, n = region size / (2 x 64kB). + * Stride between redistributors is 0 and regions are filled in the index order. + * + * Return: the redist region handle, if any, that has space to map a new rdist + * region. + */ +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