From nobody Sun Feb 8 18:09:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1591880259; cv=none; d=zohomail.com; s=zohoarc; b=EYcVIwo8dfFkY6A9oYQAeIP23XViyELkcnsvuEpPpLuytbQJOy8RARQTlhC8FzlhsCc9bQJ0rCjZok9RjdYhUFh0X/0PII1vD8xVJtpGQCcARiyjShiqL2JJfOwqOWeorjI1/Hkmv2wzVT90rkIObYEEa9m3r/E+7A6j6+yVcfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591880259; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fPgMf4dUzSXISMRpXuAYY2THvaG8MIbmi3h4PqwfSzI=; b=ItLa3vgdHWnmk4q458klSZmo+d078R5AWHwyprUmZWQyAQropmZiMB20whrm6KcZ7mTxR6gw7Hg2mnhkWkqUUu/yqKUTzXVea+55prWWZlIAm7k8dM41ufyvKLp6A7QC7k0uMR5Q0XtP5ymjdQM17cviBOOScCJnQjo8deGe0D8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591880259385114.04510027405263; Thu, 11 Jun 2020 05:57:39 -0700 (PDT) Received: from localhost ([::1]:47324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjMm2-00022h-3h for importer@patchew.org; Thu, 11 Jun 2020 08:57:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjMd3-0002rB-FH for qemu-devel@nongnu.org; Thu, 11 Jun 2020 08:48:21 -0400 Received: from mga05.intel.com ([192.55.52.43]:42686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjMcy-0007zN-Ts for qemu-devel@nongnu.org; Thu, 11 Jun 2020 08:48:21 -0400 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2020 05:48:01 -0700 Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga005.jf.intel.com with ESMTP; 11 Jun 2020 05:48:00 -0700 IronPort-SDR: HrGRWe3L6a/PSw1IvbmvciUwC8adGrdjf2WWwRjDHWkYafHvU6n878Hr5/JrrfhYA/SjEPN6pn q8P7qyffrwjQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: 1CrkBE0Z9ARVwYSdZa+Cqjw2QayRuxKXjomx0h896QrO4T8IK/f7BnnogDcyCaRA+dVOh+ARWK u7DSShGx2iNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,499,1583222400"; d="scan'208";a="447911247" From: Liu Yi L To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Subject: [RFC v6 11/25] vfio/common: provide PASID alloc/free hooks Date: Thu, 11 Jun 2020 05:54:10 -0700 Message-Id: <1591880064-30638-12-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591880064-30638-1-git-send-email-yi.l.liu@intel.com> References: <1591880064-30638-1-git-send-email-yi.l.liu@intel.com> 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=192.55.52.43; envelope-from=yi.l.liu@intel.com; helo=mga05.intel.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 08:48:00 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, kevin.tian@intel.com, yi.l.liu@intel.com, Yi Sun , kvm@vger.kernel.org, mst@redhat.com, jun.j.tian@intel.com, eric.auger@redhat.com, yi.y.sun@intel.com, Jacob Pan , pbonzini@redhat.com, hao.wu@intel.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch defines vfio_host_iommu_context_info, implements the PASID alloc/free hooks defined in HostIOMMUContextClass. Cc: Kevin Tian Cc: Jacob Pan Cc: Peter Xu Cc: Eric Auger Cc: Yi Sun Cc: David Gibson Cc: Alex Williamson Signed-off-by: Liu Yi L --- hw/vfio/common.c | 66 +++++++++++++++++++++++++++++++= ++++ include/hw/iommu/host_iommu_context.h | 3 ++ include/hw/vfio/vfio-common.h | 4 +++ 3 files changed, 73 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b85fbcf..f650ad1 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1184,6 +1184,50 @@ static int vfio_get_iommu_type(VFIOContainer *contai= ner, return ret; } =20 +static int vfio_host_iommu_ctx_pasid_alloc(HostIOMMUContext *iommu_ctx, + uint32_t min, uint32_t max, + uint32_t *pasid) +{ + VFIOContainer *container =3D container_of(iommu_ctx, + VFIOContainer, iommu_ctx); + struct vfio_iommu_type1_pasid_request req; + int ret =3D 0; + + req.argsz =3D sizeof(req); + req.flags =3D VFIO_IOMMU_ALLOC_PASID; + req.range.min =3D min; + req.range.max =3D max; + + ret =3D ioctl(container->fd, VFIO_IOMMU_PASID_REQUEST, &req); + if (ret < 0) { + error_report("%s: alloc failed (%m)", __func__); + return ret; + } + *pasid =3D ret; + return 0; +} + +static int vfio_host_iommu_ctx_pasid_free(HostIOMMUContext *iommu_ctx, + uint32_t pasid) +{ + VFIOContainer *container =3D container_of(iommu_ctx, + VFIOContainer, iommu_ctx); + struct vfio_iommu_type1_pasid_request req; + + int ret =3D 0; + + req.argsz =3D sizeof(req); + req.flags =3D VFIO_IOMMU_FREE_PASID; + req.range.min =3D pasid; + req.range.max =3D pasid + 1; + + ret =3D ioctl(container->fd, VFIO_IOMMU_PASID_REQUEST, &req); + if (ret) { + error_report("%s: free failed (%m)", __func__); + } + return ret; +} + static int vfio_init_container(VFIOContainer *container, int group_fd, bool want_nested, Error **errp) { @@ -1797,3 +1841,25 @@ int vfio_eeh_as_op(AddressSpace *as, uint32_t op) } return vfio_eeh_container_op(container, op); } + +static void vfio_host_iommu_context_class_init(ObjectClass *klass, + void *data) +{ + HostIOMMUContextClass *hicxc =3D HOST_IOMMU_CONTEXT_CLASS(klass); + + hicxc->pasid_alloc =3D vfio_host_iommu_ctx_pasid_alloc; + hicxc->pasid_free =3D vfio_host_iommu_ctx_pasid_free; +} + +static const TypeInfo vfio_host_iommu_context_info =3D { + .parent =3D TYPE_HOST_IOMMU_CONTEXT, + .name =3D TYPE_VFIO_HOST_IOMMU_CONTEXT, + .class_init =3D vfio_host_iommu_context_class_init, +}; + +static void vfio_register_types(void) +{ + type_register_static(&vfio_host_iommu_context_info); +} + +type_init(vfio_register_types) diff --git a/include/hw/iommu/host_iommu_context.h b/include/hw/iommu/host_= iommu_context.h index 35c4861..227c433 100644 --- a/include/hw/iommu/host_iommu_context.h +++ b/include/hw/iommu/host_iommu_context.h @@ -33,6 +33,9 @@ #define TYPE_HOST_IOMMU_CONTEXT "qemu:host-iommu-context" #define HOST_IOMMU_CONTEXT(obj) \ OBJECT_CHECK(HostIOMMUContext, (obj), TYPE_HOST_IOMMU_CONTEXT) +#define HOST_IOMMU_CONTEXT_CLASS(klass) \ + OBJECT_CLASS_CHECK(HostIOMMUContextClass, (klass), \ + TYPE_HOST_IOMMU_CONTEXT) #define HOST_IOMMU_CONTEXT_GET_CLASS(obj) \ OBJECT_GET_CLASS(HostIOMMUContextClass, (obj), \ TYPE_HOST_IOMMU_CONTEXT) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index a77d0ed..f8694d6 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -26,12 +26,15 @@ #include "qemu/notify.h" #include "ui/console.h" #include "hw/display/ramfb.h" +#include "hw/iommu/host_iommu_context.h" #ifdef CONFIG_LINUX #include #endif =20 #define VFIO_MSG_PREFIX "vfio %s: " =20 +#define TYPE_VFIO_HOST_IOMMU_CONTEXT "qemu:vfio-host-iommu-context" + enum { VFIO_DEVICE_TYPE_PCI =3D 0, VFIO_DEVICE_TYPE_PLATFORM =3D 1, @@ -71,6 +74,7 @@ typedef struct VFIOContainer { MemoryListener listener; MemoryListener prereg_listener; unsigned iommu_type; + HostIOMMUContext iommu_ctx; Error *error; bool initialized; unsigned long pgsizes; --=20 2.7.4