kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com,
	kevin.tian@intel.com, robin.murphy@arm.com,
	baolu.lu@linux.intel.com
Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com,
	kvm@vger.kernel.org, mjrosato@linux.ibm.com,
	chao.p.peng@linux.intel.com, yi.l.liu@intel.com,
	yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com,
	shameerali.kolothum.thodi@huawei.com, lulu@redhat.com,
	suravee.suthikulpanit@amd.com, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	zhenzhong.duan@intel.com, joao.m.martins@oracle.com,
	xin.zeng@intel.com, yan.y.zhao@intel.com
Subject: [PATCH v6 1/6] iommu: Add cache_invalidate_user op
Date: Fri, 17 Nov 2023 05:07:12 -0800	[thread overview]
Message-ID: <20231117130717.19875-2-yi.l.liu@intel.com> (raw)
In-Reply-To: <20231117130717.19875-1-yi.l.liu@intel.com>

From: Lu Baolu <baolu.lu@linux.intel.com>

The updates of the PTEs in the nested page table will be propagated to the
hardware caches on both IOMMU (IOTLB) and devices (DevTLB/ATC).

Add a new domain op cache_invalidate_user for the userspace to flush the
hardware caches for a nested domain through iommufd. No wrapper for it,
as it's only supposed to be used by iommufd. Then, pass in invalidation
requests in form of a user data array conatining a number of invalidation
data entries.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 include/linux/iommu.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ec289c1016f5..0c1ff7fe4fa1 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -284,6 +284,24 @@ struct iommu_user_data {
 	size_t len;
 };
 
+/**
+ * struct iommu_user_data_array - iommu driver specific user space data array
+ * @type: The data type of all the entries in the user buffer array
+ * @uptr: Pointer to the user buffer array for copy_from_user()
+ * @entry_len: The fixed-width length of a entry in the array, in bytes
+ * @entry_num: The number of total entries in the array
+ *
+ * A array having a @entry_num number of @entry_len sized entries, each entry is
+ * user space data, an uAPI defined in include/uapi/linux/iommufd.h where @type
+ * is also defined as enum iommu_xyz_data_type.
+ */
+struct iommu_user_data_array {
+	unsigned int type;
+	void __user *uptr;
+	size_t entry_len;
+	int entry_num;
+};
+
 /**
  * __iommu_copy_struct_from_user - Copy iommu driver specific user space data
  * @dst_data: Pointer to an iommu driver specific user data that is defined in
@@ -440,6 +458,15 @@ struct iommu_ops {
  * @iotlb_sync_map: Sync mappings created recently using @map to the hardware
  * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
  *            queue
+ * @cache_invalidate_user: Flush hardware cache for user space IO page table.
+ *                         The @domain must be IOMMU_DOMAIN_NESTED. The @array
+ *                         passes in the cache invalidation requests, in form
+ *                         of a driver data structure. The driver must update
+ *                         array->entry_num to report the number of handled
+ *                         invalidation requests. The 32-bit @error_code can
+ *                         forward a driver specific error code to user space.
+ *                         Both the driver data structure and the error code
+ *                         must be defined in include/uapi/linux/iommufd.h
  * @iova_to_phys: translate iova to physical address
  * @enforce_cache_coherency: Prevent any kind of DMA from bypassing IOMMU_CACHE,
  *                           including no-snoop TLPs on PCIe or other platform
@@ -465,6 +492,9 @@ struct iommu_domain_ops {
 			      size_t size);
 	void (*iotlb_sync)(struct iommu_domain *domain,
 			   struct iommu_iotlb_gather *iotlb_gather);
+	int (*cache_invalidate_user)(struct iommu_domain *domain,
+				     struct iommu_user_data_array *array,
+				     u32 *error_code);
 
 	phys_addr_t (*iova_to_phys)(struct iommu_domain *domain,
 				    dma_addr_t iova);
-- 
2.34.1


  reply	other threads:[~2023-11-17 13:07 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 13:07 [PATCH v6 0/6] iommufd: Add nesting infrastructure (part 2/2) Yi Liu
2023-11-17 13:07 ` Yi Liu [this message]
2023-11-20  7:53   ` [PATCH v6 1/6] iommu: Add cache_invalidate_user op Tian, Kevin
2023-12-06 18:32   ` Jason Gunthorpe
2023-12-06 18:43     ` Nicolin Chen
2023-12-06 18:50       ` Jason Gunthorpe
2023-12-07  6:53         ` Yi Liu
2024-01-08  7:32   ` Binbin Wu
2023-11-17 13:07 ` [PATCH v6 2/6] iommufd: Add IOMMU_HWPT_INVALIDATE Yi Liu
2023-11-20  8:09   ` Tian, Kevin
2023-11-20  8:29     ` Yi Liu
2023-11-20  8:34       ` Tian, Kevin
2023-11-20 17:36         ` Nicolin Chen
2023-11-21  2:50           ` Tian, Kevin
2023-11-21  5:24             ` Nicolin Chen
2023-11-24  2:36               ` Tian, Kevin
2023-11-27 19:53                 ` Nicolin Chen
2023-11-28  6:01                   ` Yi Liu
2023-11-29  0:54                     ` Nicolin Chen
2023-11-28  8:03                   ` Tian, Kevin
2023-11-29  0:51                     ` Nicolin Chen
2023-11-29  0:57                       ` Jason Gunthorpe
2023-11-29  1:09                         ` Nicolin Chen
2023-11-29 19:58                           ` Jason Gunthorpe
2023-11-29 22:07                             ` Nicolin Chen
2023-11-30  0:08                               ` Jason Gunthorpe
2023-11-30 20:41                                 ` Nicolin Chen
2023-12-01  0:45                                   ` Jason Gunthorpe
2023-12-01  4:29                                     ` Nicolin Chen
2023-12-01 12:55                                       ` Jason Gunthorpe
2023-12-01 19:58                                         ` Nicolin Chen
2023-12-01 20:43                                           ` Jason Gunthorpe
2023-12-01 22:12                                             ` Nicolin Chen
2023-12-04 14:48                                               ` Jason Gunthorpe
2023-12-05 17:33                                                 ` Nicolin Chen
2023-12-06 12:48                                                   ` Jason Gunthorpe
2023-12-01  3:51                         ` Yi Liu
2023-12-01  4:50                           ` Nicolin Chen
2023-12-01  5:19                             ` Tian, Kevin
2023-12-01  7:05                               ` Yi Liu
2023-12-01  7:10                                 ` Tian, Kevin
2023-12-01  9:08                                   ` Yi Liu
2023-11-21  5:02   ` Baolu Lu
2023-11-21  5:19     ` Nicolin Chen
2023-11-28  5:54       ` Yi Liu
2023-12-06 18:33   ` Jason Gunthorpe
2023-12-07  6:59   ` Yi Liu
2023-12-07  9:04     ` Tian, Kevin
2023-12-07 14:42       ` Jason Gunthorpe
2023-12-11  7:53         ` Yi Liu
2023-12-11 13:21           ` Jason Gunthorpe
2023-12-12 13:45             ` Liu, Yi L
2023-12-12 14:40               ` Jason Gunthorpe
2023-12-13 13:47                 ` Liu, Yi L
2023-12-13 14:11                   ` Jason Gunthorpe
2023-12-11  7:49       ` Yi Liu
2023-11-17 13:07 ` [PATCH v6 3/6] iommu: Add iommu_copy_struct_from_user_array helper Yi Liu
2023-11-20  8:17   ` Tian, Kevin
2023-11-20 17:25     ` Nicolin Chen
2023-11-21  2:48       ` Tian, Kevin
2024-01-08  8:37   ` Binbin Wu
2023-11-17 13:07 ` [PATCH v6 4/6] iommufd/selftest: Add mock_domain_cache_invalidate_user support Yi Liu
2023-12-06 18:16   ` Jason Gunthorpe
2023-12-11 11:21     ` Yi Liu
2023-11-17 13:07 ` [PATCH v6 5/6] iommufd/selftest: Add IOMMU_TEST_OP_MD_CHECK_IOTLB test op Yi Liu
2023-11-17 13:07 ` [PATCH v6 6/6] iommufd/selftest: Add coverage for IOMMU_HWPT_INVALIDATE ioctl Yi Liu
2023-12-06 18:19   ` Jason Gunthorpe
2023-12-11 11:28     ` Yi Liu
2023-12-11 13:06       ` Jason Gunthorpe
2023-12-09  1:47 ` [PATCH v6 0/6] iommufd: Add nesting infrastructure (part 2/2) Jason Gunthorpe
2023-12-11  2:29   ` Tian, Kevin
2023-12-11 12:36     ` Yi Liu
2023-12-11 13:05       ` Jason Gunthorpe
2023-12-11 15:34         ` Suthikulpanit, Suravee
2023-12-11 16:06           ` Jason Gunthorpe
2023-12-11 12:35   ` Yi Liu
2023-12-11 13:20     ` Jason Gunthorpe
2023-12-11 20:11       ` Nicolin Chen
2023-12-11 21:48         ` Jason Gunthorpe
2023-12-11 17:35   ` Suthikulpanit, Suravee
2023-12-11 17:45     ` Jason Gunthorpe
2023-12-11 21:27   ` Nicolin Chen
2023-12-11 21:57     ` Jason Gunthorpe
2023-12-12  7:30       ` Nicolin Chen
2023-12-12 14:44         ` Jason Gunthorpe
2023-12-12 19:13           ` Nicolin Chen
2023-12-12 19:21             ` Jason Gunthorpe
2023-12-12 20:05               ` Nicolin Chen
2023-12-13 12:40                 ` Jason Gunthorpe
2023-12-13 19:54                   ` Nicolin Chen
     [not found] ` <CGME20231217215720eucas1p2a590aca62ce8eb5ba81df6bc8b1a785d@eucas1p2.samsung.com>
2023-12-17 11:21   ` Joel Granados
2023-12-19  9:26     ` Yi Liu
2023-12-20 11:23       ` Joel Granados

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231117130717.19875-2-yi.l.liu@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=joao.m.martins@oracle.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lulu@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=nicolinc@nvidia.com \
    --cc=peterx@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xin.zeng@intel.com \
    --cc=yan.y.zhao@intel.com \
    --cc=yi.y.sun@linux.intel.com \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).