From nobody Sun Feb 8 23:42:33 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=1594553312; cv=none; d=zohomail.com; s=zohoarc; b=Y5Ef3Sn1FnISCSuUh8fayY8B7V9/1ZqQ3zHo81xYsOLbriBKg9W5z6A4bP5d9pt1WiujjMvt8IJ8FhwFHbfl5jXqZUJT5FvrTLw6Vi5vxrX4ziFQ0Dm37HWbjPIVdNmaea27A6A2JgSTJiQ7U/5nfAjrjUM9sAv0xlzpQjMuklo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594553312; 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=iYF1wYYodQRRVQWGFWFofEhZTQEz7Mce3bYNugFfjX0=; b=Sj1VcRBGXHP3OPsdcFM7L4Q3ynYyDKdjUKEP/vl6e2Ed5D6ZKutOZnq/V6LFdzzfrNufNKsbJNy4qWiEd563aBp5twUueFh9cSpGQz1WewPegwXoq7jmJPuPcV9pvKJ1C6goXuQHujt0oFIHh7dl5yYs5hDQNTQL4+g8tfQAI9A= 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 1594553312673420.92882680471996; Sun, 12 Jul 2020 04:28:32 -0700 (PDT) Received: from localhost ([::1]:58558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jua9n-0007ZF-DL for importer@patchew.org; Sun, 12 Jul 2020 07:28:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jua1k-00036N-0g for qemu-devel@nongnu.org; Sun, 12 Jul 2020 07:20:12 -0400 Received: from mga03.intel.com ([134.134.136.65]:51221) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jua1e-0004uc-Om for qemu-devel@nongnu.org; Sun, 12 Jul 2020 07:20:11 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2020 04:19:47 -0700 Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by fmsmga004.fm.intel.com with ESMTP; 12 Jul 2020 04:19:46 -0700 IronPort-SDR: JRzXk1Nb6mVh65BzPW7XXboN7OCPWvdEP6wXOwMHyzLkx6wVVfW6vWypj8viof9ziqyBlouqxY SODHJ0NEO69Q== X-IronPort-AV: E=McAfee;i="6000,8403,9679"; a="148490167" X-IronPort-AV: E=Sophos;i="5.75,343,1589266800"; d="scan'208";a="148490167" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: nL1UE1U+tRV3/Inbe61tKFh0jVACDfiA1gnTnmtc0plq4UaacrqYRFnftVTt345fQtFj21yt9T RqgLZHCnLO1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,343,1589266800"; d="scan'208";a="307121413" From: Liu Yi L To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Subject: [RFC v8 11/25] vfio/common: provide PASID alloc/free hooks Date: Sun, 12 Jul 2020 04:26:07 -0700 Message-Id: <1594553181-55810-12-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594553181-55810-1-git-send-email-yi.l.liu@intel.com> References: <1594553181-55810-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=134.134.136.65; envelope-from=yi.l.liu@intel.com; helo=mga03.intel.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/12 07:19:41 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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, jasowang@redhat.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..7b92a58 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_FLAG_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_FLAG_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