Re: [PATCH v7 03/10] iommu/sva: Add iommu_sva_domain support

From: Baolu Lu
Date: Fri May 20 2022 - 00:56:31 EST


On 2022/5/20 00:33, Jean-Philippe Brucker wrote:
diff --git a/drivers/iommu/iommu-sva-lib.h b/drivers/iommu/iommu-sva-lib.h
index 8909ea1094e3..1be21e6b93ec 100644
--- a/drivers/iommu/iommu-sva-lib.h
+++ b/drivers/iommu/iommu-sva-lib.h
@@ -7,6 +7,7 @@
#include <linux/ioasid.h>
#include <linux/mm_types.h>
+#include <linux/iommu.h>
int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max);
struct mm_struct *iommu_sva_find(ioasid_t pasid);
@@ -16,6 +17,20 @@ struct device;
struct iommu_fault;
struct iopf_queue;
+struct iommu_sva_domain {
+ struct iommu_domain domain;
+ struct mm_struct *mm;
+};
+
+#define to_sva_domain(d) container_of_safe(d, struct iommu_sva_domain, domain)
Is there a reason to use the 'safe' version of container_of()? Callers of
to_sva_domain() don't check the return value before dereferencing it so
they would break anyway if someone passes an error pointer as domain. I
think it matters because there is no other user of container_of_safe() in
the kernel (the only user, lustre, went away in 2018) so someone will want
to remove it.

Fair enough. I wondered why there's no user in the tree. Thanks for the
explanation. I will replace it with container_of().


Apart from that

Reviewed-by: Jean-Philippe Brucker<jean-philippe@xxxxxxxxxx>


Thank you!

Best regards,
baolu