From nobody Mon Feb 9 02:14:29 2026 Delivered-To: importer@patchew.org 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; 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=1585542551; cv=none; d=zohomail.com; s=zohoarc; b=mIyjKXivaQRgshwcdjacA9GjhfCN1D8wraWMZwyHkQqrdxoGADzH6Xb9VaHBRoEZNESKjFYRQpVruX3CBWkD2w13auL5xaOjRqh53Ae+A9mxSrS7b/eve3FiVRxjSofocYJKbeTk7+NhhmXLtkrt/t65vGyDZed5t8NBfl/qYmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585542551; 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=c4NNlja+C6tVyzy3hGnQvkkOlnL+5Wp9TohNWwM+gWo=; b=C0BScmV7BudWSWeBkpMx62bn3WgxAuoVrUT9u1dt9t3XNp0Mg+TeqWJeV1sP1hs8ntQkqUrDkMzk66VLT0Ft3qEZG4Lv8G5Z7lKpTi0Pfs2wXZvefxO0NGgjV2vFyuh7rf5VaPGztcmYzEmJbiQn0tw+Bk1hNk7F3DctvM766Io= 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 1585542551912952.1905731245289; Sun, 29 Mar 2020 21:29:11 -0700 (PDT) Received: from localhost ([::1]:44768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIm2w-0001Ws-Oz for importer@patchew.org; Mon, 30 Mar 2020 00:29:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37819) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIltT-0000qm-4f for qemu-devel@nongnu.org; Mon, 30 Mar 2020 00:19:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIltR-0007qp-GV for qemu-devel@nongnu.org; Mon, 30 Mar 2020 00:19:23 -0400 Received: from mga07.intel.com ([134.134.136.100]:12574) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIltR-0007ph-71 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 00:19:21 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2020 21:19:15 -0700 Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga001.jf.intel.com with ESMTP; 29 Mar 2020 21:19:15 -0700 IronPort-SDR: wO3kMvN3Kxwj9DNkQ6ahF2qsv8V/w3mFlQitxPUWn/wlHlqO6dtlQoMqPkMAYQwrmPamqsyu0k LElSoz3uM9Qg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: nwyJtzTxoH0dzO+5cbtTfpjy5b6k1j6xyEnyqeddOqiFJrT/hHpbBEjUXXudkYHShVm3FA1yqp wwPDx9YevpLQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,322,1580803200"; d="scan'208";a="327632033" From: Liu Yi L To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Subject: [PATCH v2 08/22] vfio/common: provide PASID alloc/free hooks Date: Sun, 29 Mar 2020 21:24:47 -0700 Message-Id: <1585542301-84087-9-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1585542301-84087-1-git-send-email-yi.l.liu@intel.com> References: <1585542301-84087-1-git-send-email-yi.l.liu@intel.com> X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 134.134.136.100 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 | 69 +++++++++++++++++++++++++++++++= ++++ include/hw/iommu/host_iommu_context.h | 3 ++ include/hw/vfio/vfio-common.h | 4 ++ 3 files changed, 76 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index c276732..5f3534d 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1179,6 +1179,53 @@ static int vfio_get_iommu_type(VFIOContainer *contai= ner, return -EINVAL; } =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; + unsigned long argsz; + int ret; + + argsz =3D sizeof(req); + req.argsz =3D argsz; + req.flags =3D VFIO_IOMMU_PASID_ALLOC; + req.alloc_pasid.min =3D min; + req.alloc_pasid.max =3D max; + + if (ioctl(container->fd, VFIO_IOMMU_PASID_REQUEST, &req)) { + ret =3D -errno; + error_report("%s: %d, alloc failed", __func__, ret); + return ret; + } + *pasid =3D req.alloc_pasid.result; + 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; + unsigned long argsz; + int ret; + + argsz =3D sizeof(req); + req.argsz =3D argsz; + req.flags =3D VFIO_IOMMU_PASID_FREE; + req.free_pasid =3D pasid; + + if (ioctl(container->fd, VFIO_IOMMU_PASID_REQUEST, &req)) { + ret =3D -errno; + error_report("%s: %d, free failed", __func__, ret); + return ret; + } + return 0; +} + static int vfio_init_container(VFIOContainer *container, int group_fd, Error **errp) { @@ -1791,3 +1838,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 fd56420..0b07303 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