From nobody Fri Apr 4 21:28:19 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=1739953632; cv=none; d=zohomail.com; s=zohoarc; b=Tesd61VAtqkjdaGu/BPMBU5IKJvawTgr3uYV+6cPabRPGZj3qSW51PR9ibc4peL0E/5A2n4eB9VWhZuXjGr+gf0cL0dN5K8K2QZEESBsh5HW/HUyknLXozHIF/4gvBXb2me8wG1c/HDkheJsxsrLvVRm5RSm+gu7DB+ScJABYQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739953632; 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=auXY46p1nR7fkvrigGugTaUMMLA7lGdZ2E/sNfx5Y+0=; b=j9TfUotCl9lF1cxGgQQFHhHyC26Rkr1r2cL5SlE8Hj/589SpBu2zG8bxs/WBZPcTATj82N9vrqKf1Th6rxe1KDDlWNwC8bUnTH7LCcKSzzp1X1ghV4fg8RjOQO7FxjWoABvx8qSxtNVgk7bvSPztMPsDM8R4ZCq6PDjCp438vKM= 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 1739953632298215.01121224840153; Wed, 19 Feb 2025 00:27:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkfPU-0005Ra-0a; Wed, 19 Feb 2025 03:26:24 -0500 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 1tkfPR-0005R0-R9 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 03:26:22 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkfPP-0004Za-Ic for qemu-devel@nongnu.org; Wed, 19 Feb 2025 03:26:21 -0500 Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2025 00:26:09 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2025 00:26:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739953580; x=1771489580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BBos9TMEnyoSZ/PC59m1etHG0x5EWREqcsDCxiYnHsk=; b=jkayOLn/ILNYCQ+cIG9oLtKnSucCFnmXPBMbRjpLUodt1IIcypdgZxUf /tVdZtzh2cXOgQBagj7+XiSm3TkEKy9/gcqEH0SsUHJG1l5eHqvdAjshv ffn3a9LFetGTSnR7LHhx4NxCGBpq0iofn8xpByMzyUy8cIBZu0l+SNVaG xSyPSovKYGWu8I2JuxzlWecj1LMifUg7nG93pKACtec9H1fH9azmvyDVN hCaID0BulwlWJNco/Yy3Mh6S0eo8NtXt+uqA2C5L5bsMejS0WeudSyLuw +9IOiS5mOSokyMMuNyBiAGj2/Tpw66o1PdmXDApvKuwJgq7W45vnRlzYL A==; X-CSE-ConnectionGUID: QAMNEVJTQD6xP3WyVUofxw== X-CSE-MsgGUID: q/mo3sKyQIuyUMN7Xal9kw== X-IronPort-AV: E=McAfee;i="6700,10204,11348"; a="40544042" X-IronPort-AV: E=Sophos;i="6.13,298,1732608000"; d="scan'208";a="40544042" X-CSE-ConnectionGUID: uGqC7U+UTVq/HngNGwYrhw== X-CSE-MsgGUID: rTyTWlLASpCovG4yNCQEtQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="119850808" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, shameerali.kolothum.thodi@huawei.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH rfcv2 01/20] backends/iommufd: Add helpers for invalidating user-managed HWPT Date: Wed, 19 Feb 2025 16:22:09 +0800 Message-Id: <20250219082228.3303163-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250219082228.3303163-1-zhenzhong.duan@intel.com> References: <20250219082228.3303163-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=192.198.163.17; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.423, 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: 1739953635585019100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Nicolin Chen Signed-off-by: Zhenzhong Duan --- include/system/iommufd.h | 3 +++ backends/iommufd.c | 30 ++++++++++++++++++++++++++++++ backends/trace-events | 1 + 3 files changed, 34 insertions(+) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index cbab75bfbf..5d02e9d148 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -61,6 +61,9 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,= uint32_t hwpt_id, uint64_t iova, ram_addr_t size, uint64_t page_size, uint64_t *data, Error **errp); +int iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t hwpt_id, + uint32_t data_type, uint32_t entry_le= n, + uint32_t *entry_num, void *data_ptr); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index d57da44755..fc32aad5cb 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -311,6 +311,36 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *b= e, uint32_t devid, return true; } =20 +int iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t hwpt_id, + uint32_t data_type, uint32_t entry_le= n, + uint32_t *entry_num, void *data_ptr) +{ + int ret, fd =3D be->fd; + struct iommu_hwpt_invalidate cache =3D { + .size =3D sizeof(cache), + .hwpt_id =3D hwpt_id, + .data_type =3D data_type, + .entry_len =3D entry_len, + .entry_num =3D *entry_num, + .data_uptr =3D (uintptr_t)data_ptr, + }; + + ret =3D ioctl(fd, IOMMU_HWPT_INVALIDATE, &cache); + + trace_iommufd_backend_invalidate_cache(fd, hwpt_id, data_type, entry_l= en, + *entry_num, cache.entry_num, + (uintptr_t)data_ptr, ret); + if (ret) { + *entry_num =3D cache.entry_num; + error_report("IOMMU_HWPT_INVALIDATE failed: %s", strerror(errno)); + ret =3D -errno; + } else { + g_assert(*entry_num =3D=3D cache.entry_num); + } + + return ret; +} + static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **er= rp) { HostIOMMUDeviceCaps *caps =3D &hiod->caps; diff --git a/backends/trace-events b/backends/trace-events index 40811a3162..5a23db6c8a 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -18,3 +18,4 @@ iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, = uint32_t pt_id, uint32_ iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int r= et) " iommufd=3D%d hwpt=3D%u enable=3D%d (%d)" iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t i= ova, uint64_t size, uint64_t page_size, int ret) " iommufd=3D%d hwpt=3D%u i= ova=3D0x%"PRIx64" size=3D0x%"PRIx64" page_size=3D0x%"PRIx64" (%d)" +iommufd_backend_invalidate_cache(int iommufd, uint32_t hwpt_id, uint32_t d= ata_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num, uint64= _t data_ptr, int ret) " iommufd=3D%d hwpt_id=3D%u data_type=3D%u entry_len= =3D%u entry_num=3D%u done_num=3D%u data_ptr=3D0x%"PRIx64" (%d)" --=20 2.34.1