Re: [PATCH v4 01/17] iommu: Add hwpt_type with user_data for domain_alloc_user op

From: Baolu Lu
Date: Mon Sep 25 2023 - 04:02:12 EST


On 2023/9/25 14:22, Yi Liu wrote:
On 2023/9/21 20:10, Baolu Lu wrote:
On 2023/9/21 15:51, Yi Liu wrote:
+/**
+ * iommu_copy_user_data - Copy iommu driver specific user space data
+ * @dst_data: Pointer to an iommu driver specific user data that is defined in
+ *            include/uapi/linux/iommufd.h
+ * @src_data: Pointer to a struct iommu_user_data for user space data info
+ * @data_len: Length of current user data structure, i.e. sizeof(struct _dst)
+ * @min_len: Initial length of user data structure for backward compatibility.
+ *           This should be offsetofend using the last member in the user data
+ *           struct that was initially added to include/uapi/linux/iommufd.h
+ */
+static inline int iommu_copy_user_data(void *dst_data,
+                       const struct iommu_user_data *src_data,
+                       size_t data_len, size_t min_len)
+{
+    if (WARN_ON(!dst_data || !src_data))
+        return -EINVAL;
+    if (src_data->len < min_len || data_len < src_data->len)
+        return -EINVAL;
+    return copy_struct_from_user(dst_data, data_len,
+                     src_data->uptr, src_data->len);
+}

I am not sure that I understand the purpose of "min_len" correctly. It
seems like it would always be equal to data_len?

no, it will not be equal to data_len once there is extension in the
uAPI structure.

Or, it means the minimal data length that the iommu driver requires?

it is the minimal data length the uAPI requires. min_len is finalized
per the upstream of the first version of the uAPI.

So, it looks like a constant. Perhaps we should document it in the
uapi/iommuf.h and avoid using it as a parameter of a helper function?

Best regards,
baolu