Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp7956265ybc; Fri, 29 Nov 2019 03:40:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxleYfwkUpSbVjV15KiYusuZ+Arz6QOLxQweZVMUQmWgUEECU8pbp905y3CXI1G3GGlGER7 X-Received: by 2002:a17:906:958e:: with SMTP id r14mr36387546ejx.228.1575027654966; Fri, 29 Nov 2019 03:40:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575027654; cv=none; d=google.com; s=arc-20160816; b=N5OLXcKk82uYuvryjsv3PD70eXHP7EUwjvaYvdMKix0Y9+PgDqHTRqtaL5pUa4CURl rjrlte/sF7aKw/s68LW7cifY8y+1cuXmyBv8o0KxQfzsvcFH5UoL66ha3OPZut+foHcu ToTku9f9kh1mKOjDcArHsQCPCmP5DnZmgFHSOeZ5+wj81z63xQ7Ma1ha8wgjaQyiTlDM ze7XJUYhSYow95Tha3ePZH6NwQsKRdTBgvvznpKes5y7gTgOU4+VlMEM9iczcPDXDnOv 9jEgnpvVp8rONQa4IYKzFCzUeHgcxYQc9bJXpc36X4OqPrq5evkAt3xo+hyx5k/WPTFY IAvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=YxvDxbuca6QEurx8I23suPpp9ZzZJEd8WIRSaSgu+fA=; b=cb5UtWaySNjDQVqKIo53EHyPIt9K66HJ9kcJq+wr5dEZJ28FrcfOQNKtHyiZjrEaPx aZ4L74oJRVI7lUpimbJu49qonRiN2FzDz1btHbMfm0Orx/ida7gUHNbmExd+/yvLqQJE MxoLuPicTOi2ggzxpVeQWmUSKUqM9UI87y2MNPlUHdfvo6McNOKgRId+0Avm+MC5bzAl qQ3ml+OA692d5adwGzgNUvxbtJVDNtpXtT8N+277MeSCQXRVqthdeyrsShT3rLIn+5pm Y5UPnSvaKpgml6farUNoXQo0CNS+qNKhLbZJ7mOC/CqcFtL2HUhSCm/A0PomwMRKD7yo tjSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si2657081edq.276.2019.11.29.03.40.30; Fri, 29 Nov 2019 03:40:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726780AbfK2Liv (ORCPT + 99 others); Fri, 29 Nov 2019 06:38:51 -0500 Received: from relay.sw.ru ([185.231.240.75]:46478 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726215AbfK2Liu (ORCPT ); Fri, 29 Nov 2019 06:38:50 -0500 Received: from dhcp-172-16-25-5.sw.ru ([172.16.25.5]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iaebJ-0001SW-HX; Fri, 29 Nov 2019 14:38:17 +0300 Subject: Re: [PATCH v11 1/4] kasan: support backing vmalloc space with real shadow memory To: Dmitry Vyukov Cc: Daniel Axtens , Qian Cai , kasan-dev , Linux-MM , the arch/x86 maintainers , Alexander Potapenko , Andy Lutomirski , LKML , Mark Rutland , Christophe Leroy , linuxppc-dev , Vasily Gorbik References: <20191031093909.9228-1-dja@axtens.net> <20191031093909.9228-2-dja@axtens.net> <1573835765.5937.130.camel@lca.pw> <871ru5hnfh.fsf@dja-thinkpad.axtens.net> <952ec26a-9492-6f71-bab1-c1def887e528@virtuozzo.com> From: Andrey Ryabinin Message-ID: <2297c356-0863-69ce-85b6-8608081295ed@virtuozzo.com> Date: Fri, 29 Nov 2019 14:38:03 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/29/19 2:02 PM, Dmitry Vyukov wrote: > On Fri, Nov 29, 2019 at 11:58 AM Dmitry Vyukov wrote: >> >> On Fri, Nov 29, 2019 at 11:43 AM Dmitry Vyukov wrote: >>> >>> On Tue, Nov 19, 2019 at 10:54 AM Andrey Ryabinin >>> wrote: >>>> On 11/18/19 6:29 AM, Daniel Axtens wrote: >>>>> Qian Cai writes: >>>>> >>>>>> On Thu, 2019-10-31 at 20:39 +1100, Daniel Axtens wrote: >>>>>>> /* >>>>>>> * In this function, newly allocated vm_struct has VM_UNINITIALIZED >>>>>>> * flag. It means that vm_struct is not fully initialized. >>>>>>> @@ -3377,6 +3411,9 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, >>>>>>> >>>>>>> setup_vmalloc_vm_locked(vms[area], vas[area], VM_ALLOC, >>>>>>> pcpu_get_vm_areas); >>>>>>> + >>>>>>> + /* assume success here */ >>>>>>> + kasan_populate_vmalloc(sizes[area], vms[area]); >>>>>>> } >>>>>>> spin_unlock(&vmap_area_lock); >>>>>> >>>>>> Here it is all wrong. GFP_KERNEL with in_atomic(). >>>>> >>>>> I think this fix will work, I will do a v12 with it included. >>>> >>>> You can send just the fix. Andrew will fold it into the original patch before sending it to Linus. >>>> >>>> >>>> >>>>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c >>>>> index a4b950a02d0b..bf030516258c 100644 >>>>> --- a/mm/vmalloc.c >>>>> +++ b/mm/vmalloc.c >>>>> @@ -3417,11 +3417,14 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, >>>>> >>>>> setup_vmalloc_vm_locked(vms[area], vas[area], VM_ALLOC, >>>>> pcpu_get_vm_areas); >>>>> + } >>>>> + spin_unlock(&vmap_area_lock); >>>>> >>>>> + /* populate the shadow space outside of the lock */ >>>>> + for (area = 0; area < nr_vms; area++) { >>>>> /* assume success here */ >>>>> kasan_populate_vmalloc(sizes[area], vms[area]); >>>>> } >>>>> - spin_unlock(&vmap_area_lock); >>>>> >>>>> kfree(vas); >>>>> return vms; >>> >>> Hi, >>> >>> I am testing this support on next-20191129 and seeing the following warnings: >>> >>> BUG: sleeping function called from invalid context at mm/page_alloc.c:4681 >>> in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 44, name: kworker/1:1 >>> 4 locks held by kworker/1:1/44: >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: >>> __write_once_size include/linux/compiler.h:247 [inline] >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: >>> arch_atomic64_set arch/x86/include/asm/atomic64_64.h:34 [inline] >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: atomic64_set >>> include/asm-generic/atomic-instrumented.h:868 [inline] >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: >>> atomic_long_set include/asm-generic/atomic-long.h:40 [inline] >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: set_work_data >>> kernel/workqueue.c:615 [inline] >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: >>> set_work_pool_and_clear_pending kernel/workqueue.c:642 [inline] >>> #0: ffff888067c26d28 ((wq_completion)events){+.+.}, at: >>> process_one_work+0x88b/0x1750 kernel/workqueue.c:2235 >>> #1: ffffc900002afdf0 (pcpu_balance_work){+.+.}, at: >>> process_one_work+0x8c0/0x1750 kernel/workqueue.c:2239 >>> #2: ffffffff8943f080 (pcpu_alloc_mutex){+.+.}, at: >>> pcpu_balance_workfn+0xcc/0x13e0 mm/percpu.c:1845 >>> #3: ffffffff89450c78 (vmap_area_lock){+.+.}, at: spin_lock >>> include/linux/spinlock.h:338 [inline] >>> #3: ffffffff89450c78 (vmap_area_lock){+.+.}, at: >>> pcpu_get_vm_areas+0x1449/0x3df0 mm/vmalloc.c:3431 >>> Preemption disabled at: >>> [] spin_lock include/linux/spinlock.h:338 [inline] >>> [] pcpu_get_vm_areas+0x1449/0x3df0 mm/vmalloc.c:3431 >>> CPU: 1 PID: 44 Comm: kworker/1:1 Not tainted 5.4.0-next-20191129+ #5 >>> Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.12.0-1 04/01/2014 >>> Workqueue: events pcpu_balance_workfn >>> Call Trace: >>> __dump_stack lib/dump_stack.c:77 [inline] >>> dump_stack+0x199/0x216 lib/dump_stack.c:118 >>> ___might_sleep.cold.97+0x1f5/0x238 kernel/sched/core.c:6800 >>> __might_sleep+0x95/0x190 kernel/sched/core.c:6753 >>> prepare_alloc_pages mm/page_alloc.c:4681 [inline] >>> __alloc_pages_nodemask+0x3cd/0x890 mm/page_alloc.c:4730 >>> alloc_pages_current+0x10c/0x210 mm/mempolicy.c:2211 >>> alloc_pages include/linux/gfp.h:532 [inline] >>> __get_free_pages+0xc/0x40 mm/page_alloc.c:4786 >>> kasan_populate_vmalloc_pte mm/kasan/common.c:762 [inline] >>> kasan_populate_vmalloc_pte+0x2f/0x1b0 mm/kasan/common.c:753 >>> apply_to_pte_range mm/memory.c:2041 [inline] >>> apply_to_pmd_range mm/memory.c:2068 [inline] >>> apply_to_pud_range mm/memory.c:2088 [inline] >>> apply_to_p4d_range mm/memory.c:2108 [inline] >>> apply_to_page_range+0x5ca/0xa00 mm/memory.c:2133 >>> kasan_populate_vmalloc+0x69/0xa0 mm/kasan/common.c:791 >>> pcpu_get_vm_areas+0x1596/0x3df0 mm/vmalloc.c:3439 >>> pcpu_create_chunk+0x240/0x7f0 mm/percpu-vm.c:340 >>> pcpu_balance_workfn+0x1033/0x13e0 mm/percpu.c:1934 >>> process_one_work+0x9b5/0x1750 kernel/workqueue.c:2264 >>> worker_thread+0x8b/0xd20 kernel/workqueue.c:2410 >>> kthread+0x365/0x450 kernel/kthread.c:255 >>> ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352 >>> >>> >>> Not sure if it's the same or not. Is it addressed by something in flight? >>> >>> My config: >>> https://gist.githubusercontent.com/dvyukov/36c7be311fdec9cd51c649f7c3cb2ddb/raw/39c6f864fdd0ffc53f0822b14c354a73c1695fa1/gistfile1.txt >> >> >> I've tried this fix for pcpu_get_vm_areas: >> https://groups.google.com/d/msg/kasan-dev/t_F2X1MWKwk/h152Z3q2AgAJ >> and it helps. But this will break syzbot on linux-next soon. > > > Can this be related as well? > Crashes on accesses to shadow on the ion memory... Nope, it's vm_map_ram() not being handled