Skip to content
  • Fengguang Wu's avatar
    writeback: fix negative bdi max pause · e3b6c655
    Fengguang Wu authored
    
    
    Toralf runs trinity on UML/i386.  After some time it hangs and the last
    message line is
    
    	BUG: soft lockup - CPU#0 stuck for 22s! [trinity-child0:1521]
    
    It's found that pages_dirtied becomes very large.  More than 1000000000
    pages in this case:
    
    	period = HZ * pages_dirtied / task_ratelimit;
    	BUG_ON(pages_dirtied > 2000000000);
    	BUG_ON(pages_dirtied > 1000000000);      <---------
    
    UML debug printf shows that we got negative pause here:
    
    	ick: pause : -984
    	ick: pages_dirtied : 0
    	ick: task_ratelimit: 0
    
    	 pause:
    	+       if (pause < 0)  {
    	+               extern int printf(char *, ...);
    	+               printf("ick : pause : %li\n", pause);
    	+               printf("ick: pages_dirtied : %lu\n", pages_dirtied);
    	+               printf("ick: task_ratelimit: %lu\n", task_ratelimit);
    	+               BUG_ON(1);
    	+       }
    	        trace_balance_dirty_pages(bdi,
    
    Since pause is bounded by [min_pause, max_pause] where min_pause is also
    bounded by max_pause.  It's suspected and demonstrated that the
    max_pause calculation goes wrong:
    
    	ick: pause : -717
    	ick: min_pause : -177
    	ick: max_pause : -717
    	ick: pages_dirtied : 14
    	ick: task_ratelimit: 0
    
    The problem lies in the two "long = unsigned long" assignments in
    bdi_max_pause() which might go negative if the highest bit is 1, and the
    min_t(long, ...) check failed to protect it falling under 0.  Fix all of
    them by using "unsigned long" throughout the function.
    
    Signed-off-by: default avatarFengguang Wu <fengguang.wu@intel.com>
    Reported-by: default avatarToralf Förster <toralf.foerster@gmx.de>
    Tested-by: default avatarToralf Förster <toralf.foerster@gmx.de>
    Reviewed-by: default avatarJan Kara <jack@suse.cz>
    Cc: Richard Weinberger <richard@nod.at>
    Cc: Geert Uytterhoeven <geert@linux-m68k.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    e3b6c655