Re: [RFC 2/2] page-flags: Catch the double setter of page flags

2019-02-11 Thread Linux Upstream


On 11/02/19 7:17 PM, Peter Zijlstra wrote:
> On Mon, Feb 11, 2019 at 12:53:55PM +, Chintan Pandya wrote:
>> Some of the page flags, like PG_locked is not supposed to
>> be set twice. Currently, there is no protection around this
>> and many callers directly tries to set this bit. Others
>> follow trylock_page() which is much safer version of the
>> same. But, for performance issues, we may not want to
>> implement wait-until-set. So, at least, find out who is
>> doing double setting and fix them.
>>
>> Change-Id: I1295fcb8527ce4b54d5d11c11287fc7516006cf0
>> Signed-off-by: Chintan Pandya 
>> ---
>>   include/linux/page-flags.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
>> index a56a9bd4bc6b..e307775c2b4a 100644
>> --- a/include/linux/page-flags.h
>> +++ b/include/linux/page-flags.h
>> @@ -208,7 +208,7 @@ static __always_inline int Page##uname(struct page 
>> *page)\
>>   
>>   #define SETPAGEFLAG(uname, lname, policy)  \
>>   static __always_inline void SetPage##uname(struct page *page)  
>> \
>> -{ set_bit(PG_##lname, &policy(page, 1)->flags); }
>> +{ WARN_ON(test_and_set_bit(PG_##lname, &policy(page, 1)->flags)); }
> 
> You forgot to make this depend on CONFIG_DEBUG_VM. Also, I'm not
> convinced this is always wrong, inefficient sure, but not wrong in
> general.

Okay. Will protect this under CONFIG_DEBUG_VM.



Re: [RFC 2/2] page-flags: Catch the double setter of page flags

2019-02-11 Thread Peter Zijlstra
On Mon, Feb 11, 2019 at 12:53:55PM +, Chintan Pandya wrote:
> Some of the page flags, like PG_locked is not supposed to
> be set twice. Currently, there is no protection around this
> and many callers directly tries to set this bit. Others
> follow trylock_page() which is much safer version of the
> same. But, for performance issues, we may not want to
> implement wait-until-set. So, at least, find out who is
> doing double setting and fix them.
> 
> Change-Id: I1295fcb8527ce4b54d5d11c11287fc7516006cf0
> Signed-off-by: Chintan Pandya 
> ---
>  include/linux/page-flags.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index a56a9bd4bc6b..e307775c2b4a 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -208,7 +208,7 @@ static __always_inline int Page##uname(struct page *page) 
> \
>  
>  #define SETPAGEFLAG(uname, lname, policy)\
>  static __always_inline void SetPage##uname(struct page *page)
> \
> - { set_bit(PG_##lname, &policy(page, 1)->flags); }
> + { WARN_ON(test_and_set_bit(PG_##lname, &policy(page, 1)->flags)); }

You forgot to make this depend on CONFIG_DEBUG_VM. Also, I'm not
convinced this is always wrong, inefficient sure, but not wrong in
general.


[RFC 2/2] page-flags: Catch the double setter of page flags

2019-02-11 Thread Chintan Pandya
Some of the page flags, like PG_locked is not supposed to
be set twice. Currently, there is no protection around this
and many callers directly tries to set this bit. Others
follow trylock_page() which is much safer version of the
same. But, for performance issues, we may not want to
implement wait-until-set. So, at least, find out who is
doing double setting and fix them.

Change-Id: I1295fcb8527ce4b54d5d11c11287fc7516006cf0
Signed-off-by: Chintan Pandya 
---
 include/linux/page-flags.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index a56a9bd4bc6b..e307775c2b4a 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -208,7 +208,7 @@ static __always_inline int Page##uname(struct page *page)   
\
 
 #define SETPAGEFLAG(uname, lname, policy)  \
 static __always_inline void SetPage##uname(struct page *page)  \
-   { set_bit(PG_##lname, &policy(page, 1)->flags); }
+   { WARN_ON(test_and_set_bit(PG_##lname, &policy(page, 1)->flags)); }
 
 #define CLEARPAGEFLAG(uname, lname, policy)\
 static __always_inline void ClearPage##uname(struct page *page)
\
-- 
2.17.1