From patchwork Sat May 27 15:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 13257686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0E87C77B7C for ; Sat, 27 May 2023 15:31:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6248F900002; Sat, 27 May 2023 11:31:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ADD86B0072; Sat, 27 May 2023 11:31:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 428B3900002; Sat, 27 May 2023 11:31:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2FCA66B0071 for ; Sat, 27 May 2023 11:31:07 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E57DAC0270 for ; Sat, 27 May 2023 15:31:06 +0000 (UTC) X-FDA: 80836423332.20.16C795B Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf04.hostedemail.com (Postfix) with ESMTP id 9A6224000A for ; Sat, 27 May 2023 15:31:03 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=none (imf04.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685201464; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sLVYHbXLr/f1aU52ldro7ocetcpgnwpOHlnDhJtPcLE=; b=B0NCYqqlkdXqy6eeWGZPBTh80o3UWMYJ7cbdWRCil2i4LfG3+WDLHlcOXRawOvxqc6d9Z6 M2guU7NW8OZOnZe6UiwnU9WYeje6JdotAtl4kbDCf0rNGZMqkR81hkQXPY51BUVl+CVHkN O/O5SE9Ut9Y1iqqoaet0H15tPI2bKsU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=none; spf=none (imf04.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685201464; a=rsa-sha256; cv=none; b=EKXx43wTPCv4oco6uBVcOTc9yUFEPxRLmFelWdf76kiaP6Qa6hbBtrLyqokCxt9V8ztunk eu+MFSd2f6BGXwPl6FyetfzXvt9aFNZwPpE22oAXnNKL5hVzfkWxWlWwZpbf8dEZ5ObfUB 0KzibZTTZgPQcxzD++2Z46W9k38CD8U= Received: from fsav314.sakura.ne.jp (fsav314.sakura.ne.jp [153.120.85.145]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 34RFUZME078764; Sun, 28 May 2023 00:30:35 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav314.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp); Sun, 28 May 2023 00:30:35 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 34RFPWLC078150 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sun, 28 May 2023 00:25:32 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <656cb4f5-998b-c8d7-3c61-c2d37aa90f9a@I-love.SAKURA.ne.jp> Date: Sun, 28 May 2023 00:25:31 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: [PATCH] kasan,kmsan: remove __GFP_KSWAPD_RECLAIM usage from kasan/kmsan Content-Language: en-US From: Tetsuo Handa To: syzbot , syzkaller-bugs@googlegroups.com, Mel Gorman , "Huang, Ying" , Vlastimil Babka , Andrew Morton , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , Vincenzo Frascino , Marco Elver Cc: kasan-dev , linux-mm References: <000000000000cef3a005fc1bcc80@google.com> In-Reply-To: X-Rspamd-Queue-Id: 9A6224000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: twx91wushmmqan4k1mmo5izridxk83we X-HE-Tag: 1685201463-798663 X-HE-Meta: U2FsdGVkX1+MC+ps5LKman5ShoNS7Id3WCuf69o967HrYqe7CTd60UZGVp+IasR3FGnamvck6PPxcbMSD6pmUjhc7wSZLluTlFSWv0fT0rPwdCctjI0fX1P0O0UrXUiy4wnNyHBfI8hdX23MSMvmLO/sta2JrWkba9VxTDXUOEhUG1o9f1hNJxOVYOsO+j1TmOfHjTFWFmJ2L4LM3XvhjLOo2jjHH4eNGlBRKrx8AnrilUylwzei9fBanlA+8b7aPVaoTJrcTji1KO1p1e4MYDOefaAU+wtjJNeaZz1oiAE6fSO5k1ydSbADZLVDk0OenKIXc+IQRFfeVYJGPzYs6vp/YmE3FkLfiFTi2gSFim/F4LBt+zU5TTz1z/K9EUiWJpBWH4kgetkbbtY85U19E+pqg7+msroxNmNktdTEYZDcvZp/LUeJ4kbYjlRhR5/XFMKJOIe6nU+2PcGdReek3CRvA+4mvQedvlqVY+a+/wLzOtw6aCzcU+XAAuqzIPtDSeb867TJdM7zbO/DYXKLuaD6TDinQ/nMltHaSAtNwhoPgaB1HEau+QdK6/vsmGN5zHE6+whQDuON1FxLHFDf+ZoSnVGc0pXisSeeHD9N3VeRX2slKv7t8CQhanm0oGHvTji2SrmQEalTLlh9r/+/d8X8bwKdDHNBSUYEHf1DQwru7PZU71MSdfh3pPeN3j3qmLSaQaj8/K5nc3hG9pGFKKTwNhr9koKb+gKq7taTXxtdva+iPmEdJinQqaMZH2iO7n3z+b6JSHNaReDL0WS3nsbs5m53yLLNXS2uP9jl5a9e+3V8Ug/NxPNakW71kZ9jPOqT+KfG1f+SCzsaPLf00QWi4xFjwR44DMNwbxdtZ3JG4dv+PZiN3OyiPPxt+vBsGE1bTVN61xmWRyw1mLP4zvtYVimCXc63ECvG2edwlpOE26yLFGGYABLz57wYfM47fpjoKi14xQ2Jok0b0nH yYblmMNi A+BCUy/QnY5zr3k2BiUZnPAYqhinpOeO9lwJBzgnzcRIiJYStHn/weBHqe1vFsWGsTppag4oGGBeQfNAs8t+419opUlfvxgMM4DR9d8PkBwNy2/Y0eipfQJIBbw6R3YfHVQzaOpAy+n0x+aQh5Vm8kkyyiQLJGidcMIjjxLco7p76lymOHL3kcpvlP+PPQ7jSzCkH0+ysbs5WEekQJyOVF+NagcrwSDKNLut227XqpnrGCPoIpPSTDqLzGGacjP+lmbQHbO5EG/d04lVrYOucUi0fDMaORBxxTw6zCGstJ0vOhtGewyVFPRaKxpiawfCtiTsafVhiuEzubZ0B8LMRjum/Ypaca/rDVZmKhPtry7uS7eF/uwZs81JHoTNses5C0e9/9qyzhyD4RJ4Hdr9ARsPYSJbYUmaaftfHEuuWE+uhLcSszOSLmV6LNcah7zhmL5aGVy/75p33/UIKbVgebtQrCLSCHn89jSgpSf8HHoU02ZU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: syzbot is reporting lockdep warning in __stack_depot_save(), for the caller of __stack_depot_save() (i.e. __kasan_record_aux_stack() in this report) is responsible for masking __GFP_KSWAPD_RECLAIM flag in order not to wake kswapd which in turn wakes kcompactd. Since kasan/kmsan functions might be called with arbitrary locks held, mask __GFP_KSWAPD_RECLAIM flag from all GFP_NOWAIT/GFP_ATOMIC allocations in kasan/kmsan. Note that kmsan_save_stack_with_flags() is changed to mask both __GFP_DIRECT_RECLAIM flag and __GFP_KSWAPD_RECLAIM flag, for wakeup_kswapd() from wake_all_kswapds() from __alloc_pages_slowpath() calls wakeup_kcompactd() if __GFP_KSWAPD_RECLAIM flag is set and __GFP_DIRECT_RECLAIM flag is not set. Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=ece2915262061d6e0ac1 Signed-off-by: Tetsuo Handa Reviewed-by: "Huang, Ying" Reviewed-by: Alexander Potapenko --- mm/kasan/generic.c | 4 ++-- mm/kasan/tags.c | 2 +- mm/kmsan/core.c | 6 +++--- mm/kmsan/instrumentation.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index e5eef670735e..2c94f4943240 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -488,7 +488,7 @@ static void __kasan_record_aux_stack(void *addr, bool can_alloc) return; alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; - alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT, can_alloc); + alloc_meta->aux_stack[0] = kasan_save_stack(0, can_alloc); } void kasan_record_aux_stack(void *addr) @@ -518,7 +518,7 @@ void kasan_save_free_info(struct kmem_cache *cache, void *object) if (!free_meta) return; - kasan_set_track(&free_meta->free_track, GFP_NOWAIT); + kasan_set_track(&free_meta->free_track, 0); /* The object was freed and has free track set. */ *(u8 *)kasan_mem_to_shadow(object) = KASAN_SLAB_FREETRACK; } diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index 67a222586846..7dcfe341d48e 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -140,5 +140,5 @@ void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) void kasan_save_free_info(struct kmem_cache *cache, void *object) { - save_stack_info(cache, object, GFP_NOWAIT, true); + save_stack_info(cache, object, 0, true); } diff --git a/mm/kmsan/core.c b/mm/kmsan/core.c index 7d1e4aa30bae..3adb4c1d3b19 100644 --- a/mm/kmsan/core.c +++ b/mm/kmsan/core.c @@ -74,7 +74,7 @@ depot_stack_handle_t kmsan_save_stack_with_flags(gfp_t flags, nr_entries = stack_trace_save(entries, KMSAN_STACK_DEPTH, 0); /* Don't sleep. */ - flags &= ~__GFP_DIRECT_RECLAIM; + flags &= ~(__GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM); handle = __stack_depot_save(entries, nr_entries, flags, true); return stack_depot_set_extra_bits(handle, extra); @@ -245,7 +245,7 @@ depot_stack_handle_t kmsan_internal_chain_origin(depot_stack_handle_t id) extra_bits = kmsan_extra_bits(depth, uaf); entries[0] = KMSAN_CHAIN_MAGIC_ORIGIN; - entries[1] = kmsan_save_stack_with_flags(GFP_ATOMIC, 0); + entries[1] = kmsan_save_stack_with_flags(__GFP_HIGH, 0); entries[2] = id; /* * @entries is a local var in non-instrumented code, so KMSAN does not @@ -253,7 +253,7 @@ depot_stack_handle_t kmsan_internal_chain_origin(depot_stack_handle_t id) * positives when __stack_depot_save() passes it to instrumented code. */ kmsan_internal_unpoison_memory(entries, sizeof(entries), false); - handle = __stack_depot_save(entries, ARRAY_SIZE(entries), GFP_ATOMIC, + handle = __stack_depot_save(entries, ARRAY_SIZE(entries), __GFP_HIGH, true); return stack_depot_set_extra_bits(handle, extra_bits); } diff --git a/mm/kmsan/instrumentation.c b/mm/kmsan/instrumentation.c index cf12e9616b24..cc3907a9c33a 100644 --- a/mm/kmsan/instrumentation.c +++ b/mm/kmsan/instrumentation.c @@ -282,7 +282,7 @@ void __msan_poison_alloca(void *address, uintptr_t size, char *descr) /* stack_depot_save() may allocate memory. */ kmsan_enter_runtime(); - handle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_ATOMIC); + handle = stack_depot_save(entries, ARRAY_SIZE(entries), __GFP_HIGH); kmsan_leave_runtime(); kmsan_internal_set_shadow_origin(address, size, -1, handle,