On Fri, Feb 8, 2019 at 5:16 AM Qian Cai wrote: > > Kmemleak is totally busted with CONFIG_KASAN_SW_TAGS=y because most of tracking > object pointers passed to create_object() have the upper bits set by KASAN. Hi Qian, Yeah, the issue is that kmemleak performs a bunch of pointer comparisons that break when pointers are tagged. Try the attached patch, it should fix the issue. I don't like the way this patch does it though, I'll see if I can come up with something better. Thanks for the report! > However, even after applied this patch [1] to fix a few things, it still has > many errors during boot. > > https://git.sr.ht/~cai/linux-debug/tree/master/dmesg > > What I don't understand is that even the patch did call kasan_reset_tag() in > paint_ptr(), it still complained on objects with upper bits set which indicates > that this line did not run. > > return (__s64)(value << shift) >> shift; > > [ 42.462799] kmemleak: Trying to color unknown object at 0xffff80082df80000 as > Grey > [ 42.470524] CPU: 128 PID: 1 Comm: swapper/0 Not tainted 5.0.0-rc5+ #17 > [ 42.477153] Call trace: > [ 42.479639] dump_backtrace+0x0/0x450 > [ 42.483362] show_stack+0x20/0x2c > [ 42.486733] __dump_stack+0x20/0x28 > [ 42.490276] dump_stack+0xa0/0xfc > [ 42.493649] paint_ptr+0xa8/0xf4 > [ 42.496934] kmemleak_not_leak+0xa4/0x15c > [ 42.501013] init_section_page_ext+0x1bc/0x328 > [ 42.505528] page_ext_init+0x4dc/0x75c > [ 42.509336] kernel_init_freeable+0x684/0x1104 > [ 42.513857] kernel_init+0x18/0x2a4 > [ 42.517407] ret_from_fork+0x10/0x18 > > [1] > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index f9d9dc250428..70343d887f34 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -588,7 +588,7 @@ static struct kmemleak_object *create_object(unsigned long > ptr, size_t size, > spin_lock_init(&object->lock); > atomic_set(&object->use_count, 1); > object->flags = OBJECT_ALLOCATED; > - object->pointer = ptr; > + object->pointer = (unsigned long)kasan_reset_tag((void *)ptr); > object->size = size; > object->excess_ref = 0; > object->min_count = min_count; > @@ -748,11 +748,12 @@ static void paint_it(struct kmemleak_object *object, int > color) > static void paint_ptr(unsigned long ptr, int color) > { > struct kmemleak_object *object; > + unsigned long addr = (unsigned long)kasan_reset_tag((void *)ptr); > > - object = find_and_get_object(ptr, 0); > + object = find_and_get_object(addr, 0); > if (!object) { > kmemleak_warn("Trying to color unknown object at 0x%08lx as %s\n", > - ptr, > + addr, > (color == KMEMLEAK_GREY) ? "Grey" : > (color == KMEMLEAK_BLACK) ? "Black" : "Unknown"); > return; > >