From nobody Thu Nov 28 08:52:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693814823; cv=none; d=zohomail.com; s=zohoarc; b=VWa7ZmlAkgCw5DPhhRefynUINkcV8gdqr557v5NhhL2Jq+PucN4uocJ89ZUiIuXt13Z0LS0YwF6IiOEMWmLIZgGU5x6gu9QrX4T3xVP+EK7AGVbYgldBwVVjsP0hN37jZTK0m8g+UQOxx4MAE0K6NPkcUgyELimXjYZqmyt6Qj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693814823; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=deUtT+oz+1XIYevIMg+Drga7A61AlvVs6/MjQyLPDyM=; b=G2Fbfi+618dVMScAZu/6NF8pjk2iQqUxQmj3us/h1DKQqW+8IAqPd9mCdMTriHBoSXA/gVIdm/vwJ6obDsDUiNYblgReyETfhI0+7MnfwL6AhQPU3qkNnC4fUQ4yS2jPTzqOa3cuOMwcZ5gjyaF/5Ly36TjM6fZxkYPx+gQQ2J4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693814822999412.64173928190905; Mon, 4 Sep 2023 01:07:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qd4bV-00013Y-SM; Mon, 04 Sep 2023 04:06:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd4bR-00011S-Ri for qemu-devel@nongnu.org; Mon, 04 Sep 2023 04:06:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd4bD-0006El-3w for qemu-devel@nongnu.org; Mon, 04 Sep 2023 04:06:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-0hZ-OyfcMQCV7dXXmd4C1A-1; Mon, 04 Sep 2023 04:05:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CDE8B8008A4; Mon, 4 Sep 2023 08:05:04 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4826840C1258; Mon, 4 Sep 2023 08:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693814776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=deUtT+oz+1XIYevIMg+Drga7A61AlvVs6/MjQyLPDyM=; b=Q6JPubzNh+cliw7S8BA2lPPFgACaO1pcAtxMXLHPozpNlTt7vFCtOhgCf1UBtF4Aq1ZhzA vfCNZaY2wRTYVjDfmpOeqEnUE8ZeNzyOQtUEvN8zDuTiA9FPvX28c3CA1W0ObBMfFVRd3E i2R8gNP6wCLLN0JamqW4HrpSbHvJUX8= X-MC-Unique: 0hZ-OyfcMQCV7dXXmd4C1A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, alex.williamson@redhat.com, clg@redhat.com, jean-philippe@linaro.org, mst@redhat.com, pbonzini@redhat.com Cc: peter.maydell@linaro.org, peterx@redhat.com, david@redhat.com, philmd@linaro.org Subject: [PATCH 03/13] vfio: Collect container iova range info Date: Mon, 4 Sep 2023 10:03:46 +0200 Message-ID: <20230904080451.424731-4-eric.auger@redhat.com> In-Reply-To: <20230904080451.424731-1-eric.auger@redhat.com> References: <20230904080451.424731-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693814824117100003 Content-Type: text/plain; charset="utf-8" Collect iova range information if VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE capability is supported. This allows to propagate the information though the IOMMU MR set_iova_ranges() callback so that virtual IOMMUs get aware of those aperture constraints. Signed-off-by: Eric Auger --- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/common.c | 45 +++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index da43d27352..74b9b27270 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -98,6 +98,8 @@ typedef struct VFIOContainer { QLIST_HEAD(, VFIOGroup) group_list; QLIST_HEAD(, VFIORamDiscardListener) vrdl_list; QLIST_ENTRY(VFIOContainer) next; + unsigned nr_iovas; + struct vfio_iova_range *iova_ranges; } VFIOContainer; =20 typedef struct VFIOGuestIOMMU { diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 9aac21abb7..26da38de05 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1157,6 +1157,14 @@ static void vfio_listener_region_add(MemoryListener = *listener, goto fail; } =20 + ret =3D memory_region_iommu_set_iova_ranges(giommu->iommu_mr, + container->nr_iovas, (struct Range *)container->iova_range= s, + &err); + if (ret) { + g_free(giommu); + goto fail; + } + ret =3D memory_region_register_iommu_notifier(section->mr, &giommu= ->n, &err); if (ret) { @@ -1981,6 +1989,29 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1= _info *info, return true; } =20 +static void vfio_get_info_iova_range(struct vfio_iommu_type1_info *info, + unsigned int *nr_iovas, + struct vfio_iova_range **iova_ranges) +{ + struct vfio_info_cap_header *hdr; + struct vfio_iommu_type1_info_cap_iova_range *cap; + + hdr =3D vfio_get_iommu_type1_info_cap(info, + VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RAN= GE); + if (hdr =3D=3D NULL) { + return; + } + + cap =3D (void *)hdr; + *nr_iovas =3D cap->nr_iovas; + + if (*nr_iovas =3D=3D 0) { + return; + } + *iova_ranges =3D g_memdup2(cap->iova_ranges, + *nr_iovas * sizeof(struct vfio_iova_range)); +} + static int vfio_setup_region_sparse_mmaps(VFIORegion *region, struct vfio_region_info *info) { @@ -2433,6 +2464,12 @@ static void vfio_get_iommu_info_migration(VFIOContai= ner *container, } } =20 +static void vfio_free_container(VFIOContainer *container) +{ + g_free(container->iova_ranges); + g_free(container); +} + static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, Error **errp) { @@ -2550,6 +2587,10 @@ static int vfio_connect_container(VFIOGroup *group, = AddressSpace *as, if (!vfio_get_info_dma_avail(info, &container->dma_max_mappings)) { container->dma_max_mappings =3D 65535; } + + vfio_get_info_iova_range(info, &container->nr_iovas, + &container->iova_ranges); + vfio_get_iommu_info_migration(container, info); g_free(info); =20 @@ -2663,7 +2704,7 @@ enable_discards_exit: vfio_ram_block_discard_disable(container, false); =20 free_container_exit: - g_free(container); + vfio_free_container(container); =20 close_fd_exit: close(fd); @@ -2717,7 +2758,7 @@ static void vfio_disconnect_container(VFIOGroup *grou= p) =20 trace_vfio_disconnect_container(container->fd); close(container->fd); - g_free(container); + vfio_free_container(container); =20 vfio_put_address_space(space); } --=20 2.41.0