Received: by 2002:a17:906:641:b0:a6f:1bf6:7fc1 with SMTP id t1csp191628ejb; Thu, 13 Jun 2024 02:24:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVEqErCTXNvFxfSTRmdjke2Xxu8x3qj16Fopto1Q9JBZTnQlwtyLFK4gV+GdTwiHmfQ5d60hIm9jnloZ404sZhC2e1U+qQb X-Google-Smtp-Source: AGHT+IECsguTqJZr3GPEfZEGCIawzEXBzw6ouYiAAKC4EM5tIPaPYdoywJKEKRDgxD60hjKiL350 X-Received: by 2002:a05:620a:2990:b0:78d:3b3f:50cd with SMTP id af79cd13be357-797f61f70e8mr448643285a.65.1718270691834; Thu, 13 Jun 2024 02:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718270691; cv=none; d=google.com; s=arc-20160816; b=CSsveWreCed+xqVNW/vPpMIRSVMwU12n4eEZBmU72/uR7jPXOUcexofJ57DSzpSIE9 vOjY/xBX54OjmjKqxUhiLQo8iB90uuAZRnuoKuf915dQHXbEVnbtU1yRgRKLbYsQ7cZs UlFD49GzRheezCeGl1UCZOaQ/Bk/LYunkqbCaGMAhYmw7H0UEpHVKEhWB5zwC/OYBw9v dWYaoDwgkdz92u4f7tjsAn5kCEZ16mm956O0Kn8dpC+91CyD09vPeFHlNtEIqjNHFWpo 9HDZHmrFjLQW9ul6UwQNh5rAUbmDI6xTTUGeH/C/iI6KZZ6MBBgaN4K5geTevGZi3GQP NkNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=87mOr6p+QHnpMpdhUiG49G5WeCvYei66RFnDldjidRM=; fh=NBkbC8z0yxZVnBu5+T/osSPCS2NzeZu/yHpj5pv7NrY=; b=FddtIXdVvF4CmW5Z2Wb5ql4poJNa3tuKJ7mlJLOKVnmEAph4ld/EJbrttgKJP4sBEj 2TsBwawDCJitKec1lbl4J7kdc0jbzIq3S4gB5/U7UFGcc04Pav0BhU1d3ZOePr0HKVRu oPExDPj+qUSkLnhpPCb5LdieDgsSrqDYddPXcoFTzp6leZeFyHFrqgmoj8t7SRZWmRMv Z+0gFDpbJMPOrhvILXoUtWEvEGT3phI8mBFXUR7GtkhZlD0ztyfvdtecE4g40tNk6nT4 cd7kPefXTCh4JzgA+Y7Ua5uXNz2MR5Hlogbkx0HBpp0uRD5L3/xi8q8FldOUJASp+Gn4 MqiA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TM2nFNR8; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-798ab902c63si92962285a.328.2024.06.13.02.24.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2024 02:24:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TM2nFNR8; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHgh7-0004By-FS; Thu, 13 Jun 2024 05:24: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 1sHgh4-0004BE-JI for qemu-devel@nongnu.org; Thu, 13 Jun 2024 05:24:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHgh3-0005W7-3K for qemu-devel@nongnu.org; Thu, 13 Jun 2024 05:24:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718270668; 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=87mOr6p+QHnpMpdhUiG49G5WeCvYei66RFnDldjidRM=; b=TM2nFNR8YSyfbI4evftplCCnvDC1rLeDjAENWa4W7bOfUEjFXyjJt/SHBofnmArYJc5Nfr 8G5ZzSCNJP/ZSmVmWGvLG5TImfuyMaNq+ox0kWxzUe55PqtYYAihIrlfZZ9x+Wir0PLVAl weX46zz96c50nWJywP1lYy/imosLpaM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-428-WltddxogO-iSOJk02OwAwg-1; Thu, 13 Jun 2024 05:24:26 -0400 X-MC-Unique: WltddxogO-iSOJk02OwAwg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04E1719560B4; Thu, 13 Jun 2024 09:24:25 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 314171956050; Thu, 13 Jun 2024 09:24:19 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [PATCH v3 3/7] HostIOMMUDevice: Introduce get_iova_ranges callback Date: Thu, 13 Jun 2024 11:20:05 +0200 Message-ID: <20240613092359.847145-4-eric.auger@redhat.com> In-Reply-To: <20240613092359.847145-1-eric.auger@redhat.com> References: <20240613092359.847145-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: MzTaUCGIO56E Introduce a new HostIOMMUDevice callback that allows to retrieve the usable IOVA ranges. Implement this callback in the legacy VFIO and IOMMUFD VFIO host iommu devices. This relies on the VFIODevice agent's base container iova_ranges resource. Signed-off-by: Eric Auger --- v2 -> v3: - add g_assert(vdev) --- include/sysemu/host_iommu_device.h | 8 ++++++++ hw/vfio/container.c | 16 ++++++++++++++++ hw/vfio/iommufd.c | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu_device.h index 3e5f058e7b..40e0fa13ef 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -80,6 +80,14 @@ struct HostIOMMUDeviceClass { * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. */ int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); + /** + * @get_iova_ranges: Return the list of usable iova_ranges along with + * @hiod Host IOMMU device + * + * @hiod: handle to the host IOMMU device + * @errp: error handle + */ + GList* (*get_iova_ranges)(HostIOMMUDevice *hiod, Error **errp); }; /* diff --git a/hw/vfio/container.c b/hw/vfio/container.c index b728b978a2..c48749c089 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1164,12 +1164,28 @@ static int hiod_legacy_vfio_get_cap(HostIOMMUDevice *hiod, int cap, } } +static GList * +hiod_legacy_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) +{ + VFIODevice *vdev = hiod->agent; + GList *l = NULL; + + g_assert(vdev); + + if (vdev->bcontainer) { + l = g_list_copy(vdev->bcontainer->iova_ranges); + } + + return l; +} + static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) { HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc); hioc->realize = hiod_legacy_vfio_realize; hioc->get_cap = hiod_legacy_vfio_get_cap; + hioc->get_iova_ranges = hiod_legacy_vfio_get_iova_ranges; }; static const TypeInfo types[] = { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index dbdae1adbb..e502081c2a 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -645,11 +645,27 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, return true; } +static GList * +hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) +{ + VFIODevice *vdev = hiod->agent; + GList *l = NULL; + + g_assert(vdev); + + if (vdev->bcontainer) { + l = g_list_copy(vdev->bcontainer->iova_ranges); + } + + return l; +} + static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data) { HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_CLASS(oc); hiodc->realize = hiod_iommufd_vfio_realize; + hiodc->get_iova_ranges = hiod_iommufd_vfio_get_iova_ranges; }; static const TypeInfo types[] = { -- 2.41.0