From nobody Sun Nov 16 02:26:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1744366899; cv=none; d=zohomail.com; s=zohoarc; b=DFNcsg9qUcSg+lE3S0c10/b/2jaX8bDq+iSpE6ORHQ6RrAYPKAuaVItm3fJvOxtQR4ykHSH34fyxleYPO/SXakuAeE8idB2dX+A9A0zcXVgXfGN0QlIVxhgngIIT1amPlwb/P+AqM6T+ExBRr8O8vEZcAF+MgF9oHzrnKzpoHDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744366899; 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=Am0H1qD07jOx0tThaTj09aCmjk9xY+aSucsYPnRh/SI=; b=ddr6lnn6z0SVPX1dEFJy3GQmK2nYigp4+RlQRLkihtfzq00rjee8MWGNgdKlLTEwveVkJWV6bhXbQNtov8SShBIgEer1LyI5K0lzt6vrNfaj+umiVfxCehT4gAqKq21sotcl/kqPSCCA9aqGVXu1QvkY6L2v6YfXgb6Axhus3H4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=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 1744366899211147.0957231442851; Fri, 11 Apr 2025 03:21:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u3BVo-0002nM-W6; Fri, 11 Apr 2025 06:21:29 -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 1u3BVh-0002fE-J8 for qemu-devel@nongnu.org; Fri, 11 Apr 2025 06:21:21 -0400 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u3BVe-0005Op-F7 for qemu-devel@nongnu.org; Fri, 11 Apr 2025 06:21:20 -0400 Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 03:20:53 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 03:20:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744366878; x=1775902878; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pognV82UVdHK8qT+B92vH8V1D8/ilicX35LTb3dliZA=; b=Th5rqfua5bRnQ/FBbJYbgvGX/TOFJfyzempPvvOLGLW9AESL9P3bZXx/ mQ87WwGsgiIpMGuelX8CUVZIji9EDUw5mwPp+Rl7jj22yFyZa+G6nxI0d 3L5E1FwHatRahL/FdTW1bGvgu0lR13Q1LA2alDfHEqQJ1XnXoAns1jRLF NuELsHc8wWDTbTQ4EbSvWpsjyZKmiFjDeH/sDR+lyVHoJXz1TKWUpNNAk dJfJ8caPHmotu2ZrNJVGFz0cH3qTbPyZv1Gg09hf5VGWmNQ5L5GD8vhRJ 7BmzUV0lu7Vnai5IOUJGQQpcw+HMlTsETsutqNMWvY/6RH7GBaJR90H3i A==; X-CSE-ConnectionGUID: fwWKyU7jQ/O3SWT2EmUygg== X-CSE-MsgGUID: oqFqfiSmScGYBklweoJqbQ== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="49566798" X-IronPort-AV: E=Sophos;i="6.15,205,1739865600"; d="scan'208";a="49566798" X-CSE-ConnectionGUID: SdcHZi/MQeOse6DGf1o+4A== X-CSE-MsgGUID: rC2gTDqzRQe+XxHFcn7dmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,205,1739865600"; d="scan'208";a="133917417" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Liu Subject: [PATCH 3/5] vfio/iommufd: Implement .get_cap() in TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO sub-class Date: Fri, 11 Apr 2025 18:17:05 +0800 Message-Id: <20250411101707.3460429-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250411101707.3460429-1-zhenzhong.duan@intel.com> References: <20250411101707.3460429-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.593, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.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 @intel.com) X-ZM-MESSAGEID: 1744366900362019000 Content-Type: text/plain; charset="utf-8" Now we have saved a copy of host iommu capabilities in VFIODevice, implemen= ted hiod_iommufd_vfio_get_cap() by querying the caps copy in sub-class. This overrides .get_cap() implementation hiod_iommufd_vfio_get_cap() in TYPE_HOST_IOMMU_DEVICE_IOMMUFD parent class. Vendor caps are checked for a specific capability, e.g., for vtd, checking code will be in hiod_iommufd_get_vtd_cap(). This also fixes an issue that calling vfio_device_get_aw_bits() in TYPE_HOST_IOMMU_DEVICE_IOMMUFD parent class .get_cap(). Signed-off-by: Zhenzhong Duan --- include/system/iommufd.h | 4 ++++ backends/iommufd.c | 40 ++++++++++++++++++++++++++++++++++++++++ hw/vfio/iommufd.c | 16 ++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 0f337585c9..baba5ec1d8 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -85,4 +85,8 @@ typedef struct HostIOMMUDeviceIOMMUFDCaps { uint64_t hw_caps; VendorCaps vendor_caps; } HostIOMMUDeviceIOMMUFDCaps; + +int hiod_iommufd_get_common_cap(HostIOMMUDevice *hiod, + HostIOMMUDeviceIOMMUFDCaps *caps, + int cap, Error **errp); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 9587e4d99b..54fa3174d0 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -355,3 +355,43 @@ static const TypeInfo types[] =3D { }; =20 DEFINE_TYPES(types) + +static int hiod_iommufd_get_vtd_cap(HostIOMMUDevice *hiod, + struct iommu_hw_info_vtd *vtd, + int cap, Error **errp) +{ + /* TODO: Check vtd->cap_reg/ecap_reg for capability */ + error_setg(errp, "%s: unsupported capability %x", hiod->name, cap); + return -EINVAL; +} + +static int hiod_iommufd_get_vendor_cap(HostIOMMUDevice *hiod, + HostIOMMUDeviceIOMMUFDCaps *caps, + int cap, Error **errp) +{ + enum iommu_hw_info_type type =3D caps->type; + + switch (type) { + case IOMMU_HW_INFO_TYPE_INTEL_VTD: + return hiod_iommufd_get_vtd_cap(hiod, &caps->vendor_caps.vtd, + cap, errp); + case IOMMU_HW_INFO_TYPE_ARM_SMMUV3: + case IOMMU_HW_INFO_TYPE_NONE: + break; + } + + error_setg(errp, "%s: unsupported capability type %x", hiod->name, typ= e); + return -EINVAL; +} + +int hiod_iommufd_get_common_cap(HostIOMMUDevice *hiod, + HostIOMMUDeviceIOMMUFDCaps *caps, + int cap, Error **errp) +{ + switch (cap) { + case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE: + return caps->type; + default: + return hiod_iommufd_get_vendor_cap(hiod, caps, cap, errp); + } +} diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index e05b472e35..e7ca92f81f 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -833,6 +833,21 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice = *hiod, void *opaque, return true; } =20 +static int hiod_iommufd_vfio_get_cap(HostIOMMUDevice *hiod, int cap, + Error **errp) +{ + VFIODevice *vdev =3D hiod->agent; + HostIOMMUDeviceIOMMUFDCaps *caps =3D &vdev->caps; + + /* VFIO has its own way to get aw_bits which may be different from VDP= A */ + switch (cap) { + case HOST_IOMMU_DEVICE_CAP_AW_BITS: + return vfio_device_get_aw_bits(hiod->agent); + default: + return hiod_iommufd_get_common_cap(hiod, caps, cap, errp); + } +} + static GList * hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hiod) { @@ -857,6 +872,7 @@ static void hiod_iommufd_vfio_class_init(ObjectClass *o= c, void *data) HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 hiodc->realize =3D hiod_iommufd_vfio_realize; + hiodc->get_cap =3D hiod_iommufd_vfio_get_cap; hiodc->get_iova_ranges =3D hiod_iommufd_vfio_get_iova_ranges; hiodc->get_page_size_mask =3D hiod_iommufd_vfio_get_page_size_mask; }; --=20 2.34.1