linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm, writeback: prevent race when calculating dirty limits
@ 2014-07-17  0:36 David Rientjes
  2014-07-17  3:57 ` Johannes Weiner
  2014-07-18  6:54 ` Michal Hocko
  0 siblings, 2 replies; 3+ messages in thread
From: David Rientjes @ 2014-07-17  0:36 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Rik van Riel, stable, linux-kernel,
	linux-mm

Setting vm_dirty_bytes and dirty_background_bytes is not protected by any 
serialization.

Therefore, it's possible for either variable to change value after the 
test in global_dirty_limits() to determine whether available_memory needs 
to be initialized or not.

Always ensure that available_memory is properly initialized.

Cc: stable@vger.kernel.org
Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/page-writeback.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -261,14 +261,11 @@ static unsigned long global_dirtyable_memory(void)
  */
 void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty)
 {
+	const unsigned long available_memory = global_dirtyable_memory();
 	unsigned long background;
 	unsigned long dirty;
-	unsigned long uninitialized_var(available_memory);
 	struct task_struct *tsk;
 
-	if (!vm_dirty_bytes || !dirty_background_bytes)
-		available_memory = global_dirtyable_memory();
-
 	if (vm_dirty_bytes)
 		dirty = DIV_ROUND_UP(vm_dirty_bytes, PAGE_SIZE);
 	else

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm, writeback: prevent race when calculating dirty limits
  2014-07-17  0:36 [patch] mm, writeback: prevent race when calculating dirty limits David Rientjes
@ 2014-07-17  3:57 ` Johannes Weiner
  2014-07-18  6:54 ` Michal Hocko
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Weiner @ 2014-07-17  3:57 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Michal Hocko, Rik van Riel, stable, linux-kernel,
	linux-mm

On Wed, Jul 16, 2014 at 05:36:49PM -0700, David Rientjes wrote:
> Setting vm_dirty_bytes and dirty_background_bytes is not protected by any 
> serialization.
> 
> Therefore, it's possible for either variable to change value after the 
> test in global_dirty_limits() to determine whether available_memory needs 
> to be initialized or not.
> 
> Always ensure that available_memory is properly initialized.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: David Rientjes <rientjes@google.com>

Any such race should be barely noticable to the user, so I assume you
realized this while looking at the code?  The patch looks good, but I
don't see that it's stable material.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm, writeback: prevent race when calculating dirty limits
  2014-07-17  0:36 [patch] mm, writeback: prevent race when calculating dirty limits David Rientjes
  2014-07-17  3:57 ` Johannes Weiner
@ 2014-07-18  6:54 ` Michal Hocko
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2014-07-18  6:54 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Johannes Weiner, Rik van Riel, stable,
	linux-kernel, linux-mm

On Wed 16-07-14 17:36:49, David Rientjes wrote:
> Setting vm_dirty_bytes and dirty_background_bytes is not protected by any 
> serialization.
> 
> Therefore, it's possible for either variable to change value after the 
> test in global_dirty_limits() to determine whether available_memory needs 
> to be initialized or not.
> 
> Always ensure that available_memory is properly initialized.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: David Rientjes <rientjes@google.com>

Makes sense to me
Acked-by: Michal Hocko <mhocko@suse.cz>

> ---
>  mm/page-writeback.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -261,14 +261,11 @@ static unsigned long global_dirtyable_memory(void)
>   */
>  void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty)
>  {
> +	const unsigned long available_memory = global_dirtyable_memory();
>  	unsigned long background;
>  	unsigned long dirty;
> -	unsigned long uninitialized_var(available_memory);
>  	struct task_struct *tsk;
>  
> -	if (!vm_dirty_bytes || !dirty_background_bytes)
> -		available_memory = global_dirtyable_memory();
> -
>  	if (vm_dirty_bytes)
>  		dirty = DIV_ROUND_UP(vm_dirty_bytes, PAGE_SIZE);
>  	else

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2014-07-18  6:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-17  0:36 [patch] mm, writeback: prevent race when calculating dirty limits David Rientjes
2014-07-17  3:57 ` Johannes Weiner
2014-07-18  6:54 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).