linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -mm] mm: readahead: apply a default readahead size
@ 2020-12-29 21:26 Randy Dunlap
  2020-12-29 22:23 ` Matthew Wilcox
  0 siblings, 1 reply; 6+ messages in thread
From: Randy Dunlap @ 2020-12-29 21:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Randy Dunlap, Toralf Förster, Andrew Morton, Jens Axboe,
	Matthew Wilcox, linux-mm

UBSAN reports an invalid shift size:

mr-fox kernel: UBSAN: shift-out-of-bounds in ./include/linux/log2.h:57:13
mr-fox kernel: shift exponent 64 is too large for 64-bit type 'long unsigned int'

Original report:
https://lore.kernel.org/lkml/c6e5eb81-680f-dd5c-8a81-62041a5ce50c@gmx.de/

Follow-up report:
https://lore.kernel.org/lkml/0c283ea9-b446-0e40-6dc8-e9585ae171b4@gmx.de/T/#m9b604660925f9e8a544f7453130c31d083c1e5bb


Willy suggested that get_init_ra_size() was being called with a size of 0,
which would cause this (instead of some Huge value), so add a check in
that function for size == 0, and if 0, default it to 32 (pages).

Reported-by: Toralf Förster <toralf.foerster@gmx.de>
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org
---
 mm/readahead.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- linux-5.10.1.orig/mm/readahead.c
+++ linux-5.10.1/mm/readahead.c
@@ -310,7 +310,11 @@ void force_page_cache_ra(struct readahea
  */
 static unsigned long get_init_ra_size(unsigned long size, unsigned long max)
 {
-	unsigned long newsize = roundup_pow_of_two(size);
+	unsigned long newsize;
+
+	if (!size)
+		size = 32;
+	newsize = roundup_pow_of_two(size);
 
 	if (newsize <= max / 32)
 		newsize = newsize * 4;


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

end of thread, other threads:[~2021-01-03 22:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29 21:26 [PATCH -mm] mm: readahead: apply a default readahead size Randy Dunlap
2020-12-29 22:23 ` Matthew Wilcox
2020-12-29 22:55   ` Randy Dunlap
2020-12-30  9:05     ` Toralf Förster
2021-01-03 21:40       ` Toralf Förster
2021-01-03 22:32         ` Randy Dunlap

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).