[v5,13/17] mm: Add hmm_data to struct page
diff mbox

Message ID 20180504183318.14415-14-willy@infradead.org
State New
Headers show

Commit Message

Matthew Wilcox May 4, 2018, 6:33 p.m. UTC
From: Matthew Wilcox <mawilcox@microsoft.com>

Make hmm_data an explicit member of the struct page union.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
 include/linux/hmm.h      |  8 ++------
 include/linux/mm_types.h | 14 +++++++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)

Comments

Vlastimil Babka May 15, 2018, 9:32 a.m. UTC | #1
On 05/04/2018 08:33 PM, Matthew Wilcox wrote:
> From: Matthew Wilcox <mawilcox@microsoft.com>
> 
> Make hmm_data an explicit member of the struct page union.
> 
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> ---
>  include/linux/hmm.h      |  8 ++------
>  include/linux/mm_types.h | 14 +++++++++-----
>  2 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/include/linux/hmm.h b/include/linux/hmm.h
> index 39988924de3a..91c1b2dccbbb 100644
> --- a/include/linux/hmm.h
> +++ b/include/linux/hmm.h
> @@ -522,9 +522,7 @@ void hmm_devmem_remove(struct hmm_devmem *devmem);
>  static inline void hmm_devmem_page_set_drvdata(struct page *page,
>  					       unsigned long data)
>  {
> -	unsigned long *drvdata = (unsigned long *)&page->pgmap;
> -
> -	drvdata[1] = data;

Well, that was ugly :)

> +	page->hmm_data = data;
>  }
>  
>  /*
> @@ -535,9 +533,7 @@ static inline void hmm_devmem_page_set_drvdata(struct page *page,
>   */
>  static inline unsigned long hmm_devmem_page_get_drvdata(const struct page *page)
>  {
> -	const unsigned long *drvdata = (const unsigned long *)&page->pgmap;
> -
> -	return drvdata[1];
> +	return page->hmm_data;
>  }
>  
>  
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 5a519279dcd5..fa05e6ca31ed 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -150,11 +150,15 @@ struct page {
>  		/** @rcu_head: You can use this to free a page by RCU. */
>  		struct rcu_head rcu_head;
>  
> -		/**
> -		 * @pgmap: For ZONE_DEVICE pages, this points to the hosting
> -		 * device page map.
> -		 */
> -		struct dev_pagemap *pgmap;
> +		struct {
> +			/**
> +			 * @pgmap: For ZONE_DEVICE pages, this points to the
> +			 * hosting device page map.
> +			 */
> +			struct dev_pagemap *pgmap;
> +			unsigned long hmm_data;
> +			unsigned long _zd_pad_1;	/* uses mapping */
> +		};

Maybe move this above rcu_head and make the comments look more like for
the other union variants?

>  	};
>  
>  	union {		/* This union is 4 bytes in size. */
>
Vlastimil Babka May 15, 2018, 12:40 p.m. UTC | #2
On 05/15/2018 11:32 AM, Vlastimil Babka wrote:
>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
>> index 5a519279dcd5..fa05e6ca31ed 100644
>> --- a/include/linux/mm_types.h
>> +++ b/include/linux/mm_types.h
>> @@ -150,11 +150,15 @@ struct page {
>>  		/** @rcu_head: You can use this to free a page by RCU. */
>>  		struct rcu_head rcu_head;
>>  
>> -		/**
>> -		 * @pgmap: For ZONE_DEVICE pages, this points to the hosting
>> -		 * device page map.
>> -		 */
>> -		struct dev_pagemap *pgmap;
>> +		struct {
>> +			/**
>> +			 * @pgmap: For ZONE_DEVICE pages, this points to the
>> +			 * hosting device page map.
>> +			 */
>> +			struct dev_pagemap *pgmap;
>> +			unsigned long hmm_data;
>> +			unsigned long _zd_pad_1;	/* uses mapping */
>> +		};
> 
> Maybe move this above rcu_head and make the comments look more like for
> the other union variants?

With that you can add my acked-by as well, thanks.

> 
>>  	};
>>  
>>  	union {		/* This union is 4 bytes in size. */
>>
>

Patch
diff mbox

diff --git a/include/linux/hmm.h b/include/linux/hmm.h
index 39988924de3a..91c1b2dccbbb 100644
--- a/include/linux/hmm.h
+++ b/include/linux/hmm.h
@@ -522,9 +522,7 @@  void hmm_devmem_remove(struct hmm_devmem *devmem);
 static inline void hmm_devmem_page_set_drvdata(struct page *page,
 					       unsigned long data)
 {
-	unsigned long *drvdata = (unsigned long *)&page->pgmap;
-
-	drvdata[1] = data;
+	page->hmm_data = data;
 }
 
 /*
@@ -535,9 +533,7 @@  static inline void hmm_devmem_page_set_drvdata(struct page *page,
  */
 static inline unsigned long hmm_devmem_page_get_drvdata(const struct page *page)
 {
-	const unsigned long *drvdata = (const unsigned long *)&page->pgmap;
-
-	return drvdata[1];
+	return page->hmm_data;
 }
 
 
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 5a519279dcd5..fa05e6ca31ed 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -150,11 +150,15 @@  struct page {
 		/** @rcu_head: You can use this to free a page by RCU. */
 		struct rcu_head rcu_head;
 
-		/**
-		 * @pgmap: For ZONE_DEVICE pages, this points to the hosting
-		 * device page map.
-		 */
-		struct dev_pagemap *pgmap;
+		struct {
+			/**
+			 * @pgmap: For ZONE_DEVICE pages, this points to the
+			 * hosting device page map.
+			 */
+			struct dev_pagemap *pgmap;
+			unsigned long hmm_data;
+			unsigned long _zd_pad_1;	/* uses mapping */
+		};
 	};
 
 	union {		/* This union is 4 bytes in size. */