Le 06/12/2021 à 11:32, Maxime Bizon a écrit : > > > On Mon, 2021-12-06 at 09:07 +0000, Christophe Leroy wrote: > > Hello, > >> Looks like you can win something if you take the patch I just sent >> and replace the memblock_phys_alloc(k_size, k_size) by >> memblock_phys_alloc_range(k_size, k_size, 0, MEMBLOCK_ALLOC_ANYWHERE) > > I tried your patch without your proposed modification and got something new: > > [ 0.000000] > ================================================================== > [ 0.000000] BUG: KASAN: unknown-crash in vprintk+0x30/0xe8 > [ 0.000000] Read of size 4 at addr 80ad0740 by task swapper/0 > [ 0.000000] > [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.15.0+ #415 > [ 0.000000] Call Trace: > [ 0.000000] [80cdfe50] [8017711c] > print_address_description.constprop.0+0x78/0x338 (unreliable) > [ 0.000000] [80cdfe80] [80176e48] kasan_report+0x1c0/0x1d4 > [ 0.000000] [80cdfec0] [80099a34] vprintk+0x30/0xe8 > [ 0.000000] [80cdfee0] [80099600] _printk+0x9c/0xbc > [ 0.000000] [80cdff60] [80999628] kasan_init+0x14c/0x164 > [ 0.000000] [80cdff90] [80995440] setup_arch+0x18/0x1c4 > [ 0.000000] [80cdffc0] [809910c8] start_kernel+0x60/0x2fc > [ 0.000000] [80cdfff0] [000033c0] 0x33c0 > [ 0.000000] > [ 0.000000] The buggy address belongs to the variable: > [ 0.000000] init_task+0x0/0xce0 > [ 0.000000] > [ 0.000000] Memory state around the buggy address: > [ 0.000000] 80ad0600: de ad be ef de ad be ef de ad be ef de ad be ef > [ 0.000000] 80ad0680: de ad be ef de ad be ef de ad be ef de ad be ef > [ 0.000000] >80ad0700: de ad be ef de ad be ef de ad be ef de ad be ef > [ 0.000000] ^ > [ 0.000000] 80ad0780: de ad be ef de ad be ef de ad be ef de ad be ef > [ 0.000000] 80ad0800: de ad be ef de ad be ef de ad be ef de ad be ef > [ 0.000000] > ================================================================== > [ 0.000000] Disabling lock debugging due to kernel taint > [ 0.000000] KASAN init done > > > Looking at the archive when you introduced KASAN, you had this kind of > bug, and the conclusion of the thread was: > >> Indeed the problem is in kasan_init() : memblock_phys_alloc() >> doesn't zeroize the allocated memory. I changed it to >> memblock_alloc() and now it works. > > since your patch uses memblock_phys_alloc() again, maybe that's the > same issue >
There was two issues: - The one you describe - The fallback part was allocating only the remaining memory required but was still using the total size for offset calculation so we were mapping memory outside of the allocated block. Fixed both in v2. Christophe