From nobody Tue Feb 10 20:28:43 2026 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=1697047127; cv=none; d=zohomail.com; s=zohoarc; b=knP9HlojkefM7osrLoQM2WIydSSG6wEeB8t1B2dRIuvkQc6jhM9H66jSAubyS4QW8R+OfijY89ZfCnCsyFQjGrggsZYq/1I2m8CxDJf7qkauIB7wPTib7g4hY3cYf0I10BlwEyhzdIUTP78r0rz0PedkA+IZfwufe+egSxEu7pw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697047127; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eTb6rdcl+c32NyMHVVUXgOQyn1VA7MoA9elnMO3rTDY=; b=LLjVv0nsy8x+ypKKkN+nsbDHcuKiFBEmAFDNdSu+62WacffdQVCQtrUtr5ZwccArnnb6cd+/IPr3tDJPlvY5dLt29iqb9CHqK+hXpZSpNH9qTiNXNwzgdZaNxdOoOBeJtRl95KSuTQBk5neazZeOSfBP3UWzgoYT7U+ZYBeZTVg= 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 1697047127066577.042196384358; Wed, 11 Oct 2023 10:58:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqdRh-0001jD-SK; Wed, 11 Oct 2023 13:56:33 -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 1qqdRN-0001NZ-3n for qemu-devel@nongnu.org; Wed, 11 Oct 2023 13:56:16 -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 1qqdRL-0006iI-Id for qemu-devel@nongnu.org; Wed, 11 Oct 2023 13:56:12 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-Qj_Vg2HyNrafNrrQ8z_QBw-1; Wed, 11 Oct 2023 13:55:56 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3F0728237C4; Wed, 11 Oct 2023 17:55:55 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FFFE492C3E; Wed, 11 Oct 2023 17:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697046970; 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=eTb6rdcl+c32NyMHVVUXgOQyn1VA7MoA9elnMO3rTDY=; b=DGM5b0pkF6uk7A9ls3tRHRk3DPn3VX8Ey24xaE4+GCsTzccd5HUUT5kiXbESt0Ib6OUWM4 M9LBUEkk45+KYGLwxTHyXP75G2vTO5U30t1WOorAD/AOPFE0ci4kgt7eOMQ3KzPR7RGHVv rBP/XLZCKL7rclr5lDN/lKvxXx81Vls= X-MC-Unique: Qj_Vg2HyNrafNrrQ8z_QBw-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, zhenzhong.duan@intel.com, yi.l.liu@intel.com Subject: [PATCH v3 07/13] virtio-iommu: Introduce per IOMMUDevice reserved regions Date: Wed, 11 Oct 2023 19:52:23 +0200 Message-ID: <20231011175516.541374-8-eric.auger@redhat.com> In-Reply-To: <20231011175516.541374-1-eric.auger@redhat.com> References: <20231011175516.541374-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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: 1697047127312100007 Content-Type: text/plain; charset="utf-8" For the time being the per device reserved regions are just a duplicate of IOMMU wide reserved regions. Subsequent patches will combine those with host reserved regions, if any. Signed-off-by: Eric Auger --- v2 -> v3: - do the initialization of the GList when creating the IOMMUDevice instead of in virtio_iommu_fill_resv_mem_prop(), which is called conditionnally in driver's probe. Also use resv_region_list_insert() --- include/hw/virtio/virtio-iommu.h | 1 + hw/virtio/virtio-iommu.c | 37 +++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-io= mmu.h index eea4564782..70b8ace34d 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -39,6 +39,7 @@ typedef struct IOMMUDevice { AddressSpace as; MemoryRegion root; /* The root container of the device */ MemoryRegion bypass_mr; /* The alias of shared memory MR */ + GList *resv_regions; } IOMMUDevice; =20 typedef struct IOMMUPciBus { diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 979cdb5648..0e2370663d 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -26,6 +26,7 @@ #include "sysemu/kvm.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" +#include "qemu/reserved-region.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "trace.h" @@ -378,6 +379,19 @@ static void virtio_iommu_put_domain(gpointer data) g_free(domain); } =20 +static void add_prop_resv_regions(IOMMUDevice *sdev) +{ + VirtIOIOMMU *s =3D sdev->viommu; + int i; + + for (i =3D 0; i < s->nr_prop_resv_regions; i++) { + ReservedRegion *reg =3D g_new0(ReservedRegion, 1); + + *reg =3D s->prop_resv_regions[i]; + sdev->resv_regions =3D resv_region_list_insert(sdev->resv_regions,= reg); + } +} + static AddressSpace *virtio_iommu_find_add_as(PCIBus *bus, void *opaque, int devfn) { @@ -408,6 +422,7 @@ static AddressSpace *virtio_iommu_find_add_as(PCIBus *b= us, void *opaque, =20 memory_region_init(&sdev->root, OBJECT(s), name, UINT64_MAX); address_space_init(&sdev->as, &sdev->root, TYPE_VIRTIO_IOMMU); + add_prop_resv_regions(sdev); =20 /* * Build the IOMMU disabled container with aliases to the @@ -629,17 +644,23 @@ static ssize_t virtio_iommu_fill_resv_mem_prop(VirtIO= IOMMU *s, uint32_t ep, { struct virtio_iommu_probe_resv_mem prop =3D {}; size_t size =3D sizeof(prop), length =3D size - sizeof(prop.head), tot= al; - int i; + IOMMUDevice *sdev; + GList *l; =20 - total =3D size * s->nr_prop_resv_regions; + sdev =3D container_of(virtio_iommu_mr(s, ep), IOMMUDevice, iommu_mr); + if (!sdev) { + return -EINVAL; + } =20 + total =3D size * g_list_length(sdev->resv_regions); if (total > free) { return -ENOSPC; } =20 - for (i =3D 0; i < s->nr_prop_resv_regions; i++) { - unsigned subtype =3D s->prop_resv_regions[i].type; - Range *range =3D &s->prop_resv_regions[i].range; + for (l =3D sdev->resv_regions; l; l =3D l->next) { + ReservedRegion *reg =3D l->data; + unsigned subtype =3D reg->type; + Range *range =3D ®->range; =20 assert(subtype =3D=3D VIRTIO_IOMMU_RESV_MEM_T_RESERVED || subtype =3D=3D VIRTIO_IOMMU_RESV_MEM_T_MSI); @@ -857,7 +878,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemory= Region *mr, hwaddr addr, bool bypass_allowed; int granule; bool found; - int i; + GList *l; =20 interval.low =3D addr; interval.high =3D addr + 1; @@ -895,8 +916,8 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemory= Region *mr, hwaddr addr, goto unlock; } =20 - for (i =3D 0; i < s->nr_prop_resv_regions; i++) { - ReservedRegion *reg =3D &s->prop_resv_regions[i]; + for (l =3D sdev->resv_regions; l; l =3D l->next) { + ReservedRegion *reg =3D l->data; =20 if (range_contains(®->range, addr)) { switch (reg->type) { --=20 2.41.0