linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: simplify min_brk handling in brk()
@ 2025-07-10  2:58 Xuanye Liu
  2025-07-10  7:56 ` Pedro Falcato
  2025-07-10  8:24 ` Lorenzo Stoakes
  0 siblings, 2 replies; 3+ messages in thread
From: Xuanye Liu @ 2025-07-10  2:58 UTC (permalink / raw)
  To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes
  Cc: Xuanye Liu, Vlastimil Babka, Jann Horn, Pedro Falcato, linux-mm,
	linux-kernel

Set min_brk to mm->start_brk by default, and override it with
mm->end_data only when CONFIG_COMPAT_BRK is enabled and
brk_randomized is false.

This makes the logic clearer with no functional change.

Signed-off-by: Xuanye Liu <liuqiye2025@163.com>
---
 mm/mmap.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index d8fa373e4ac1..7306253cc3b5 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -127,18 +127,15 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 
 	origbrk = mm->brk;
 
+	min_brk = mm->start_brk;
 #ifdef CONFIG_COMPAT_BRK
 	/*
 	 * CONFIG_COMPAT_BRK can still be overridden by setting
 	 * randomize_va_space to 2, which will still cause mm->start_brk
 	 * to be arbitrarily shifted
 	 */
-	if (current->brk_randomized)
-		min_brk = mm->start_brk;
-	else
+	if (!current->brk_randomized)
 		min_brk = mm->end_data;
-#else
-	min_brk = mm->start_brk;
 #endif
 	if (brk < min_brk)
 		goto out;
-- 
2.43.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: simplify min_brk handling in brk()
  2025-07-10  2:58 [PATCH] mm: simplify min_brk handling in brk() Xuanye Liu
@ 2025-07-10  7:56 ` Pedro Falcato
  2025-07-10  8:24 ` Lorenzo Stoakes
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Falcato @ 2025-07-10  7:56 UTC (permalink / raw)
  To: Xuanye Liu
  Cc: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
	Jann Horn, linux-mm, linux-kernel

On Thu, Jul 10, 2025 at 10:58:58AM +0800, Xuanye Liu wrote:
> Set min_brk to mm->start_brk by default, and override it with
> mm->end_data only when CONFIG_COMPAT_BRK is enabled and
> brk_randomized is false.
> 
> This makes the logic clearer with no functional change.
> 
> Signed-off-by: Xuanye Liu <liuqiye2025@163.com>

Reviewed-by: Pedro Falcato <pfalcato@suse.de>

Small little simplification, looks good, thanks!

-- 
Pedro


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: simplify min_brk handling in brk()
  2025-07-10  2:58 [PATCH] mm: simplify min_brk handling in brk() Xuanye Liu
  2025-07-10  7:56 ` Pedro Falcato
@ 2025-07-10  8:24 ` Lorenzo Stoakes
  1 sibling, 0 replies; 3+ messages in thread
From: Lorenzo Stoakes @ 2025-07-10  8:24 UTC (permalink / raw)
  To: Xuanye Liu
  Cc: Andrew Morton, Liam R. Howlett, Vlastimil Babka, Jann Horn,
	Pedro Falcato, linux-mm, linux-kernel

On Thu, Jul 10, 2025 at 10:58:58AM +0800, Xuanye Liu wrote:
> Set min_brk to mm->start_brk by default, and override it with
> mm->end_data only when CONFIG_COMPAT_BRK is enabled and
> brk_randomized is false.
>
> This makes the logic clearer with no functional change.
>
> Signed-off-by: Xuanye Liu <liuqiye2025@163.com>

LGTM thanks, nice cleanup:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  mm/mmap.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d8fa373e4ac1..7306253cc3b5 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -127,18 +127,15 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
>
>  	origbrk = mm->brk;
>
> +	min_brk = mm->start_brk;
>  #ifdef CONFIG_COMPAT_BRK
>  	/*
>  	 * CONFIG_COMPAT_BRK can still be overridden by setting
>  	 * randomize_va_space to 2, which will still cause mm->start_brk
>  	 * to be arbitrarily shifted
>  	 */
> -	if (current->brk_randomized)
> -		min_brk = mm->start_brk;
> -	else
> +	if (!current->brk_randomized)
>  		min_brk = mm->end_data;
> -#else
> -	min_brk = mm->start_brk;
>  #endif
>  	if (brk < min_brk)
>  		goto out;
> --
> 2.43.0
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-10  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-10  2:58 [PATCH] mm: simplify min_brk handling in brk() Xuanye Liu
2025-07-10  7:56 ` Pedro Falcato
2025-07-10  8:24 ` Lorenzo Stoakes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox