diff mbox series

[linux-next] mm/huge_memory: mark racy access on huge_anon_orders_always

Message ID 20240511144436754EiKfJM4xjMSTyCbEExwcL@zte.com.cn (mailing list archive)
State New
Headers show
Series [linux-next] mm/huge_memory: mark racy access on huge_anon_orders_always | expand

Commit Message

xu.xin16@zte.com.cn May 11, 2024, 6:44 a.m. UTC
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>

huge_anon_orders_always and huge_anon_orders_always are accessed
lockless, it is better to use the READ_ONCE() wrapper.
This is not fixing any visible bug, hopefully this can cease some
KCSAN complains in the future.
Also do that for huge_anon_orders_madvise.

Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
 include/linux/huge_mm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

David Hildenbrand May 13, 2024, 4 p.m. UTC | #1
On 11.05.24 08:44, xu.xin16@zte.com.cn wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> 
> huge_anon_orders_always and huge_anon_orders_always are accessed

"huge_anon_orders_always" mentioned twice.

> lockless, it is better to use the READ_ONCE() wrapper.
> This is not fixing any visible bug, hopefully this can cease some
> KCSAN complains in the future.
> Also do that for huge_anon_orders_madvise.
> 
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
>   include/linux/huge_mm.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index de0c89105076..6573430ea600 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -122,8 +122,8 @@ static inline bool hugepage_flags_enabled(void)
>   	 * So we don't need to look at huge_anon_orders_inherit.
>   	 */
>   	return hugepage_global_enabled() ||
> -	       huge_anon_orders_always ||
> -	       huge_anon_orders_madvise;
> +			READ_ONCE(huge_anon_orders_always) ||
> +			READ_ONCE(huge_anon_orders_madvise);

Don't mess up the alignment please.

>   }
> 
>   static inline int highest_order(unsigned long orders)

Acked-by: David Hildenbrand <david@redhat.com>
Yang Shi May 13, 2024, 7:05 p.m. UTC | #2
On Sat, May 11, 2024 at 12:44 AM <xu.xin16@zte.com.cn> wrote:
>
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>
> huge_anon_orders_always and huge_anon_orders_always are accessed
> lockless, it is better to use the READ_ONCE() wrapper.
> This is not fixing any visible bug, hopefully this can cease some
> KCSAN complains in the future.

A little bit confused here. Did you see complaints from KCSAN?

> Also do that for huge_anon_orders_madvise.
>
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
>  include/linux/huge_mm.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index de0c89105076..6573430ea600 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -122,8 +122,8 @@ static inline bool hugepage_flags_enabled(void)
>          * So we don't need to look at huge_anon_orders_inherit.
>          */
>         return hugepage_global_enabled() ||
> -              huge_anon_orders_always ||
> -              huge_anon_orders_madvise;
> +                       READ_ONCE(huge_anon_orders_always) ||
> +                       READ_ONCE(huge_anon_orders_madvise);
>  }
>
>  static inline int highest_order(unsigned long orders)
> --
> 2.15.2
diff mbox series

Patch

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index de0c89105076..6573430ea600 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -122,8 +122,8 @@  static inline bool hugepage_flags_enabled(void)
 	 * So we don't need to look at huge_anon_orders_inherit.
 	 */
 	return hugepage_global_enabled() ||
-	       huge_anon_orders_always ||
-	       huge_anon_orders_madvise;
+			READ_ONCE(huge_anon_orders_always) ||
+			READ_ONCE(huge_anon_orders_madvise);
 }

 static inline int highest_order(unsigned long orders)