[v4,4/6] mm: Add structure to keep sva information

Message ID 20230912125936.722348-5-tina.zhang@intel.com
State New
Headers
Series Share sva domains with all devices bound to a mm |

Commit Message

Zhang, Tina Sept. 12, 2023, 12:59 p.m. UTC
  Introduce iommu_mm_data structure to keep sva information (pasid and the
related sva domains). Add iommu_mm pointer, pointing to an instance of
iommu_mm_data structure, to mm.

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
---
 include/linux/iommu.h    | 5 +++++
 include/linux/mm_types.h | 2 ++
 2 files changed, 7 insertions(+)
  

Comments

Baolu Lu Sept. 13, 2023, 2:38 a.m. UTC | #1
On 9/12/23 8:59 PM, Tina Zhang wrote:
> Introduce iommu_mm_data structure to keep sva information (pasid and the
> related sva domains). Add iommu_mm pointer, pointing to an instance of
> iommu_mm_data structure, to mm.
> 
> Reviewed-by: Vasant Hegde<vasant.hegde@amd.com>
> Signed-off-by: Tina Zhang<tina.zhang@intel.com>
> ---
>   include/linux/iommu.h    | 5 +++++
>   include/linux/mm_types.h | 2 ++
>   2 files changed, 7 insertions(+)

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu
  
Jason Gunthorpe Sept. 21, 2023, 7:04 p.m. UTC | #2
On Tue, Sep 12, 2023 at 08:59:34PM +0800, Tina Zhang wrote:
> Introduce iommu_mm_data structure to keep sva information (pasid and the
> related sva domains). Add iommu_mm pointer, pointing to an instance of
> iommu_mm_data structure, to mm.
> 
> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
> Signed-off-by: Tina Zhang <tina.zhang@intel.com>
> ---
>  include/linux/iommu.h    | 5 +++++
>  include/linux/mm_types.h | 2 ++
>  2 files changed, 7 insertions(+)

This is not a great way to structure the patches

This patch should move the pasid into the struct and do all the
infrastructure to allocate/free the struct.

The next patch should just add the list head to the now existing struct:

> +struct iommu_mm_data {
> +	u32			pasid;
> +	struct list_head	sva_domains;
> +};

The code looks fine though

Jason
  
Zhang, Tina Sept. 22, 2023, 1:51 a.m. UTC | #3
On 9/22/23 03:04, Jason Gunthorpe wrote:
> On Tue, Sep 12, 2023 at 08:59:34PM +0800, Tina Zhang wrote:
>> Introduce iommu_mm_data structure to keep sva information (pasid and the
>> related sva domains). Add iommu_mm pointer, pointing to an instance of
>> iommu_mm_data structure, to mm.
>>
>> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
>> Signed-off-by: Tina Zhang <tina.zhang@intel.com>
>> ---
>>   include/linux/iommu.h    | 5 +++++
>>   include/linux/mm_types.h | 2 ++
>>   2 files changed, 7 insertions(+)
> 
> This is not a great way to structure the patches
> 
> This patch should move the pasid into the struct and do all the
> infrastructure to allocate/free the struct.
> 
> The next patch should just add the list head to the now existing struct:
Agree. It would be great if we can put a new filed adding and its 
related handing logic into one patch. It will be convenient not only for 
the author but also for the reviewers, as it can convey the intention of 
the code change more easily.

In this case, the reason we put new members' introduction into one patch 
and their handling logic into another patch, is that it seems an easy 
way to replace the old pasid field w/o involving extra temporary logic 
to keep everything work between patches. Fortunately, we only have two 
new fields, which might make this option not so ugly :)

Regards,
-Tina

> 
>> +struct iommu_mm_data {
>> +	u32			pasid;
>> +	struct list_head	sva_domains;
>> +};
> 
> The code looks fine though
> 
> Jason
  

Patch

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index db2510da28c1..b9c9f14a95cc 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -670,6 +670,11 @@  struct iommu_sva {
 	struct iommu_domain		*domain;
 };
 
+struct iommu_mm_data {
+	u32			pasid;
+	struct list_head	sva_domains;
+};
+
 int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
 		      const struct iommu_ops *ops);
 void iommu_fwspec_free(struct device *dev);
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 36c5b43999e6..9f4efed85f74 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -670,6 +670,7 @@  struct mm_cid {
 #endif
 
 struct kioctx_table;
+struct iommu_mm_data;
 struct mm_struct {
 	struct {
 		/*
@@ -883,6 +884,7 @@  struct mm_struct {
 
 #ifdef CONFIG_IOMMU_SVA
 		u32 pasid;
+		struct iommu_mm_data *iommu_mm;
 #endif
 #ifdef CONFIG_KSM
 		/*