From patchwork Fri Aug 13 23:54:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 467E6C4320A for ; Fri, 13 Aug 2021 23:54:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB723610F7 for ; Fri, 13 Aug 2021 23:54:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BB723610F7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 598168D0002; Fri, 13 Aug 2021 19:54:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56EFB6B0071; Fri, 13 Aug 2021 19:54:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45DC78D0002; Fri, 13 Aug 2021 19:54:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 2969D6B006C for ; Fri, 13 Aug 2021 19:54:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CC762180C1145 for ; Fri, 13 Aug 2021 23:54:26 +0000 (UTC) X-FDA: 78471714132.07.DFE5298 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf16.hostedemail.com (Postfix) with ESMTP id 82985F0000BE for ; Fri, 13 Aug 2021 23:54:26 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 1EDD2610C8; Fri, 13 Aug 2021 23:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898865; bh=FF2mzB8TSJXGhnbiCs2Dwo/+ozu69iMmCqQfZimxQcA=; h=Date:From:To:Subject:In-Reply-To:From; b=hcMtyWFor54sKKPJE8ztWkyuDFG34yMwtd6KMdAZCuhGx6VKINloaaog2wBMd2pyg +BieQqTms2rhbZ66y7jGBRV6MahWV8G816ZRhnZ89eKf25ilR+iM732uMJTd5yNBbK EZ0B/df+9hZFBC2NC26YZFqcWQL57d48yQOdYBXo= Date: Fri, 13 Aug 2021 16:54:24 -0700 From: Andrew Morton To: akpm@linux-foundation.org, andreyknvl@gmail.com, catalin.marinas@arm.com, chinwen.chang@mediatek.com, elver@google.com, glider@google.com, Kuan-Ying.Lee@mediatek.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, nicholas.tang@mediatek.com, ryabinin.a.a@gmail.com, torvalds@linux-foundation.org Subject: [patch 1/7] kasan, kmemleak: reset tags when scanning block Message-ID: <20210813235424.KwnvpFt9s%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 82985F0000BE Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=hcMtyWFo; dmarc=none; spf=pass (imf16.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam04 X-Stat-Signature: tuytoo7fdtrgp831exoggw73opah6qga X-HE-Tag: 1628898866-9750 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: From: Kuan-Ying Lee Subject: kasan, kmemleak: reset tags when scanning block Patch series "kasan, slub: reset tag when printing address", v3. With hardware tag-based kasan enabled, we reset the tag when we access metadata to avoid from false alarm. This patch (of 2): Kmemleak needs to scan kernel memory to check memory leak. With hardware tag-based kasan enabled, when it scans on the invalid slab and dereference, the issue will occur as below. Hardware tag-based KASAN doesn't use compiler instrumentation, we can not use kasan_disable_current() to ignore tag check. Based on the below report, there are 11 0xf7 granules, which amounts to 176 bytes, and the object is allocated from the kmalloc-256 cache. So when kmemleak accesses the last 256-176 bytes, it causes faults, as those are marked with KASAN_KMALLOC_REDZONE == KASAN_TAG_INVALID == 0xfe. Thus, we reset tags before accessing metadata to avoid from false positives. [ 151.905804] ================================================================== [ 151.907120] BUG: KASAN: out-of-bounds in scan_block+0x58/0x170 [ 151.908773] Read at addr f7ff0000c0074eb0 by task kmemleak/138 [ 151.909656] Pointer tag: [f7], memory tag: [fe] [ 151.910195] [ 151.910876] CPU: 7 PID: 138 Comm: kmemleak Not tainted 5.14.0-rc2-00001-g8cae8cd89f05-dirty #134 [ 151.912085] Hardware name: linux,dummy-virt (DT) [ 151.912868] Call trace: [ 151.913211] dump_backtrace+0x0/0x1b0 [ 151.913796] show_stack+0x1c/0x30 [ 151.914248] dump_stack_lvl+0x68/0x84 [ 151.914778] print_address_description+0x7c/0x2b4 [ 151.915340] kasan_report+0x138/0x38c [ 151.915804] __do_kernel_fault+0x190/0x1c4 [ 151.916386] do_tag_check_fault+0x78/0x90 [ 151.916856] do_mem_abort+0x44/0xb4 [ 151.917308] el1_abort+0x40/0x60 [ 151.917754] el1h_64_sync_handler+0xb4/0xd0 [ 151.918270] el1h_64_sync+0x78/0x7c [ 151.918714] scan_block+0x58/0x170 [ 151.919157] scan_gray_list+0xdc/0x1a0 [ 151.919626] kmemleak_scan+0x2ac/0x560 [ 151.920129] kmemleak_scan_thread+0xb0/0xe0 [ 151.920635] kthread+0x154/0x160 [ 151.921115] ret_from_fork+0x10/0x18 [ 151.921717] [ 151.922077] Allocated by task 0: [ 151.922523] kasan_save_stack+0x2c/0x60 [ 151.923099] __kasan_kmalloc+0xec/0x104 [ 151.923502] __kmalloc+0x224/0x3c4 [ 151.924172] __register_sysctl_paths+0x200/0x290 [ 151.924709] register_sysctl_table+0x2c/0x40 [ 151.925175] sysctl_init+0x20/0x34 [ 151.925665] proc_sys_init+0x3c/0x48 [ 151.926136] proc_root_init+0x80/0x9c [ 151.926547] start_kernel+0x648/0x6a4 [ 151.926987] __primary_switched+0xc0/0xc8 [ 151.927557] [ 151.927994] Freed by task 0: [ 151.928340] kasan_save_stack+0x2c/0x60 [ 151.928766] kasan_set_track+0x2c/0x40 [ 151.929173] kasan_set_free_info+0x44/0x54 [ 151.929568] ____kasan_slab_free.constprop.0+0x150/0x1b0 [ 151.930063] __kasan_slab_free+0x14/0x20 [ 151.930449] slab_free_freelist_hook+0xa4/0x1fc [ 151.930924] kfree+0x1e8/0x30c [ 151.931285] put_fs_context+0x124/0x220 [ 151.931731] vfs_kern_mount.part.0+0x60/0xd4 [ 151.932280] kern_mount+0x24/0x4c [ 151.932686] bdev_cache_init+0x70/0x9c [ 151.933122] vfs_caches_init+0xdc/0xf4 [ 151.933578] start_kernel+0x638/0x6a4 [ 151.934014] __primary_switched+0xc0/0xc8 [ 151.934478] [ 151.934757] The buggy address belongs to the object at ffff0000c0074e00 [ 151.934757] which belongs to the cache kmalloc-256 of size 256 [ 151.935744] The buggy address is located 176 bytes inside of [ 151.935744] 256-byte region [ffff0000c0074e00, ffff0000c0074f00) [ 151.936702] The buggy address belongs to the page: [ 151.937378] page:(____ptrval____) refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x100074 [ 151.938682] head:(____ptrval____) order:2 compound_mapcount:0 compound_pincount:0 [ 151.939440] flags: 0xbfffc0000010200(slab|head|node=0|zone=2|lastcpupid=0xffff|kasantag=0x0) [ 151.940886] raw: 0bfffc0000010200 0000000000000000 dead000000000122 f5ff0000c0002300 [ 151.941634] raw: 0000000000000000 0000000000200020 00000001ffffffff 0000000000000000 [ 151.942353] page dumped because: kasan: bad access detected [ 151.942923] [ 151.943214] Memory state around the buggy address: [ 151.943896] ffff0000c0074c00: f0 f0 f0 f0 f0 f0 f0 f0 f0 fe fe fe fe fe fe fe [ 151.944857] ffff0000c0074d00: fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe [ 151.945892] >ffff0000c0074e00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 fe fe fe fe fe [ 151.946407] ^ [ 151.946939] ffff0000c0074f00: fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe [ 151.947445] ffff0000c0075000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 151.947999] ================================================================== [ 151.948524] Disabling lock debugging due to kernel taint [ 156.434569] kmemleak: 181 new suspected memory leaks (see /sys/kernel/debug/kmemleak) Link: https://lkml.kernel.org/r/20210804090957.12393-1-Kuan-Ying.Lee@mediatek.com Link: https://lkml.kernel.org/r/20210804090957.12393-2-Kuan-Ying.Lee@mediatek.com Signed-off-by: Kuan-Ying Lee Acked-by: Catalin Marinas Reviewed-by: Andrey Konovalov Cc: Marco Elver Cc: Nicholas Tang Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Chinwen Chang Signed-off-by: Andrew Morton --- mm/kmemleak.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/mm/kmemleak.c~kasan-kmemleak-reset-tags-when-scanning-block +++ a/mm/kmemleak.c @@ -290,7 +290,7 @@ static void hex_dump_object(struct seq_f warn_or_seq_printf(seq, " hex dump (first %zu bytes):\n", len); kasan_disable_current(); warn_or_seq_hex_dump(seq, DUMP_PREFIX_NONE, HEX_ROW_SIZE, - HEX_GROUP_SIZE, ptr, len, HEX_ASCII); + HEX_GROUP_SIZE, kasan_reset_tag((void *)ptr), len, HEX_ASCII); kasan_enable_current(); } @@ -1171,7 +1171,7 @@ static bool update_checksum(struct kmeml kasan_disable_current(); kcsan_disable_current(); - object->checksum = crc32(0, (void *)object->pointer, object->size); + object->checksum = crc32(0, kasan_reset_tag((void *)object->pointer), object->size); kasan_enable_current(); kcsan_enable_current(); @@ -1246,7 +1246,7 @@ static void scan_block(void *_start, voi break; kasan_disable_current(); - pointer = *ptr; + pointer = *(unsigned long *)kasan_reset_tag((void *)ptr); kasan_enable_current(); untagged_ptr = (unsigned long)kasan_reset_tag((void *)pointer); From patchwork Fri Aug 13 23:54:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AC50C432BE for ; Fri, 13 Aug 2021 23:54:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8B8D4610EA for ; Fri, 13 Aug 2021 23:54:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8B8D4610EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 34E366B006C; Fri, 13 Aug 2021 19:54:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FD9F8D0003; Fri, 13 Aug 2021 19:54:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C5B46B0072; Fri, 13 Aug 2021 19:54:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 038986B006C for ; Fri, 13 Aug 2021 19:54:29 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8CFBA20318 for ; Fri, 13 Aug 2021 23:54:29 +0000 (UTC) X-FDA: 78471714258.33.687D207 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf21.hostedemail.com (Postfix) with ESMTP id 42EE3D016FBE for ; Fri, 13 Aug 2021 23:54:29 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F04E610FA; Fri, 13 Aug 2021 23:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898868; bh=dz5XDDA3S75zq01iHBJEYHrsivDjKVmSt4W6JkekY48=; h=Date:From:To:Subject:In-Reply-To:From; b=pe90HJvr0Z9T/0/BVzUk6RWGmyG9OkUFDI4g228mWkDzYIcZu7wRszClFGRwIJYZD dU/GbHHH3v7MyHGOItDGX+V0htqdcsw5K54VmAg0ljua6GfJ75i6GPSTYlYRLY58OZ y8mGgu7QWN8tEm0ukp+PFDGwKotzxuevJg8QtmOY= Date: Fri, 13 Aug 2021 16:54:27 -0700 From: Andrew Morton To: akpm@linux-foundation.org, andreyknvl@gmail.com, catalin.marinas@arm.com, chinwen.chang@mediatek.com, elver@google.com, glider@google.com, Kuan-Ying.Lee@mediatek.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, nicholas.tang@mediatek.com, ryabinin.a.a@gmail.com, torvalds@linux-foundation.org Subject: [patch 2/7] kasan, slub: reset tag when printing address Message-ID: <20210813235427.2ncjDFSFa%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=pe90HJvr; dmarc=none; spf=pass (imf21.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: k5yned9xxmuyxtrj8iapw77f93up68cj X-Rspamd-Queue-Id: 42EE3D016FBE X-Rspamd-Server: rspam05 X-HE-Tag: 1628898869-354323 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: From: Kuan-Ying Lee Subject: kasan, slub: reset tag when printing address The address still includes the tags when it is printed. With hardware tag-based kasan enabled, we will get a false positive KASAN issue when we access metadata. Reset the tag before we access the metadata. Link: https://lkml.kernel.org/r/20210804090957.12393-3-Kuan-Ying.Lee@mediatek.com Fixes: aa1ef4d7b3f6 ("kasan, mm: reset tags when accessing metadata") Signed-off-by: Kuan-Ying Lee Reviewed-by: Marco Elver Reviewed-by: Andrey Konovalov Cc: Alexander Potapenko Cc: Andrey Ryabinin Cc: Catalin Marinas Cc: Chinwen Chang Cc: Nicholas Tang Signed-off-by: Andrew Morton --- mm/slub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/slub.c~kasan-slub-reset-tag-when-printing-address +++ a/mm/slub.c @@ -576,8 +576,8 @@ static void print_section(char *level, c unsigned int length) { metadata_access_enable(); - print_hex_dump(level, kasan_reset_tag(text), DUMP_PREFIX_ADDRESS, - 16, 1, addr, length, 1); + print_hex_dump(level, text, DUMP_PREFIX_ADDRESS, + 16, 1, kasan_reset_tag((void *)addr), length, 1); metadata_access_disable(); } From patchwork Fri Aug 13 23:54:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF270C432BE for ; Fri, 13 Aug 2021 23:54:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 65B48610FA for ; Fri, 13 Aug 2021 23:54:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 65B48610FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0B5768D0005; Fri, 13 Aug 2021 19:54:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 065F98D0003; Fri, 13 Aug 2021 19:54:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E97888D0005; Fri, 13 Aug 2021 19:54:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id CFFA08D0003 for ; Fri, 13 Aug 2021 19:54:34 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 80BDAF041 for ; Fri, 13 Aug 2021 23:54:34 +0000 (UTC) X-FDA: 78471714468.25.1243141 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf06.hostedemail.com (Postfix) with ESMTP id 36BF6801AB3A for ; Fri, 13 Aug 2021 23:54:34 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 72084610EA; Fri, 13 Aug 2021 23:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898871; bh=etz95oe+xp50q4htYo96QIsnPjktrpsVnBZvbO2sYOk=; h=Date:From:To:Subject:In-Reply-To:From; b=MTGZd4M9o6KVxoNKZU8jsvTsNb79sXWWgMXCvk1ovMI0HR+LNHS9Lq3hf0SfYgCgq qJStXPuRYJdNPnqckj2kqP3br/WKXaa6Fa6Pvl1btp7f/X7a6UncTC1V8f2e5N21P3 h6YMx2qW0tN8q3VwIc5V3/UKwDn/H+lvjWMzvH9s= Date: Fri, 13 Aug 2021 16:54:31 -0700 From: Andrew Morton To: akpm@linux-foundation.org, cl@linux.com, guro@fb.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, nathan@kernel.org, penberg@kernel.org, rientjes@google.com, shakeelb@google.com, songmuchun@bytedance.com, torvalds@linux-foundation.org, vbabka@suse.cz Subject: [patch 3/7] slub: fix kmalloc_pagealloc_invalid_free unit test Message-ID: <20210813235431.BzXjs8Aqu%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 36BF6801AB3A Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=MTGZd4M9; dmarc=none; spf=pass (imf06.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam04 X-Stat-Signature: 7htumkrnu3smsj7si4jxbxgiyi9f3rec X-HE-Tag: 1628898874-429324 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: From: Shakeel Butt Subject: slub: fix kmalloc_pagealloc_invalid_free unit test The unit test kmalloc_pagealloc_invalid_free makes sure that for the higher order slub allocation which goes to page allocator, the free is called with the correct address i.e. the virtual address of the head page. The commit f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") unified the free code paths for page allocator based slub allocations but instead of using the address passed by the caller, it extracted the address from the page. Thus making the unit test kmalloc_pagealloc_invalid_free moot. So, fix this by using the address passed by the caller. Should we fix this? I think yes because dev expect kasan to catch these type of programming bugs. Link: https://lkml.kernel.org/r/20210802180819.1110165-1-shakeelb@google.com Fixes: f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") Signed-off-by: Shakeel Butt Reported-by: Nathan Chancellor Tested-by: Nathan Chancellor Acked-by: Roman Gushchin Cc: Michal Hocko Cc: Muchun Song Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/slub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/mm/slub.c~slub-fix-kmalloc_pagealloc_invalid_free-unit-test +++ a/mm/slub.c @@ -3236,12 +3236,12 @@ struct detached_freelist { struct kmem_cache *s; }; -static inline void free_nonslab_page(struct page *page) +static inline void free_nonslab_page(struct page *page, void *object) { unsigned int order = compound_order(page); VM_BUG_ON_PAGE(!PageCompound(page), page); - kfree_hook(page_address(page)); + kfree_hook(object); mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); __free_pages(page, order); } @@ -3282,7 +3282,7 @@ int build_detached_freelist(struct kmem_ if (!s) { /* Handle kalloc'ed objects */ if (unlikely(!PageSlab(page))) { - free_nonslab_page(page); + free_nonslab_page(page, object); p[size] = NULL; /* mark object processed */ return size; } @@ -4258,7 +4258,7 @@ void kfree(const void *x) page = virt_to_head_page(x); if (unlikely(!PageSlab(page))) { - free_nonslab_page(page); + free_nonslab_page(page, object); return; } slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); From patchwork Fri Aug 13 23:54:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71502C4338F for ; Fri, 13 Aug 2021 23:54:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A8BA610EA for ; Fri, 13 Aug 2021 23:54:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1A8BA610EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AF0BD8D0006; Fri, 13 Aug 2021 19:54:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9ECB8D0003; Fri, 13 Aug 2021 19:54:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98E7F8D0006; Fri, 13 Aug 2021 19:54:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 806658D0003 for ; Fri, 13 Aug 2021 19:54:36 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 192081816BB63 for ; Fri, 13 Aug 2021 23:54:36 +0000 (UTC) X-FDA: 78471714552.10.C65014E Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP id B63A59001AA3 for ; Fri, 13 Aug 2021 23:54:35 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id A5D55610F7; Fri, 13 Aug 2021 23:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898875; bh=fr14lSQkQ99+R/FsUh+9QNsz/PsbSgSiyqdCwuVq1ss=; h=Date:From:To:Subject:In-Reply-To:From; b=geC5F4h2f4+o5Zk8Eqm25dlNNXZXwUU7guN4hDuwjLqpvoxSGxN+nQHmp5fh+GS3t EVvJLUm7i3wQP9CJkMTPDMubgyzMaTiJrI/GkDyu5HQNFJ9mt7SJbfxvMd+wngyo+F jDb7JsxR6lLHB2lRKHOc8PsN3kbhE3OzjynZBSU4= Date: Fri, 13 Aug 2021 16:54:34 -0700 From: Andrew Morton To: akpm@linux-foundation.org, cl@linux.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, penberg@kernel.org, rientjes@google.com, torvalds@linux-foundation.org, vbabka@suse.cz, vinmenon@codeaurora.org, vjitta@codeaurora.org Subject: [patch 4/7] mm: slub: fix slub_debug disabling for list of slabs Message-ID: <20210813235434.x-KKmCj59%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: B63A59001AA3 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=geC5F4h2; dmarc=none; spf=pass (imf29.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam04 X-Stat-Signature: gbtm8ew9h14i8kyu9a8ajh61rkhd91sz X-HE-Tag: 1628898875-549314 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: From: Vlastimil Babka Subject: mm: slub: fix slub_debug disabling for list of slabs Vijayanand Jitta reports: Consider the scenario where CONFIG_SLUB_DEBUG_ON is set and we would want to disable slub_debug for few slabs. Using boot parameter with slub_debug=-,slab_name syntax doesn't work as expected i.e; only disabling debugging for the specified list of slabs. Instead it disables debugging for all slabs, which is wrong. This patch fixes it by delaying the moment when the global slub_debug flags variable is updated. In case a "slub_debug=-,slab_name" has been passed, the global flags remain as initialized (depending on CONFIG_SLUB_DEBUG_ON enabled or disabled) and are not simply reset to 0. Link: https://lkml.kernel.org/r/8a3d992a-473a-467b-28a0-4ad2ff60ab82@suse.cz Signed-off-by: Vlastimil Babka Reported-by: Vijayanand Jitta Reviewed-by: Vijayanand Jitta Acked-by: David Rientjes Cc: Christoph Lameter Cc: Pekka Enberg Cc: Joonsoo Kim Cc: Vinayak Menon Signed-off-by: Andrew Morton --- mm/slub.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/mm/slub.c~mm-slub-fix-slub_debug-disablement-for-list-of-slabs +++ a/mm/slub.c @@ -1400,12 +1400,13 @@ check_slabs: static int __init setup_slub_debug(char *str) { slab_flags_t flags; + slab_flags_t global_flags; char *saved_str; char *slab_list; bool global_slub_debug_changed = false; bool slab_list_specified = false; - slub_debug = DEBUG_DEFAULT_FLAGS; + global_flags = DEBUG_DEFAULT_FLAGS; if (*str++ != '=' || !*str) /* * No options specified. Switch on full debugging. @@ -1417,7 +1418,7 @@ static int __init setup_slub_debug(char str = parse_slub_debug_flags(str, &flags, &slab_list, true); if (!slab_list) { - slub_debug = flags; + global_flags = flags; global_slub_debug_changed = true; } else { slab_list_specified = true; @@ -1426,16 +1427,18 @@ static int __init setup_slub_debug(char /* * For backwards compatibility, a single list of flags with list of - * slabs means debugging is only enabled for those slabs, so the global - * slub_debug should be 0. We can extended that to multiple lists as + * slabs means debugging is only changed for those slabs, so the global + * slub_debug should be unchanged (0 or DEBUG_DEFAULT_FLAGS, depending + * on CONFIG_SLUB_DEBUG_ON). We can extended that to multiple lists as * long as there is no option specifying flags without a slab list. */ if (slab_list_specified) { if (!global_slub_debug_changed) - slub_debug = 0; + global_flags = slub_debug; slub_debug_string = saved_str; } out: + slub_debug = global_flags; if (slub_debug != 0 || slub_debug_string) static_branch_enable(&slub_debug_enabled); else From patchwork Fri Aug 13 23:54:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 617A1C432BE for ; Fri, 13 Aug 2021 23:54:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1592D610FA for ; Fri, 13 Aug 2021 23:54:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1592D610FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AC6F78D0007; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A77CF8D0003; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98DBE8D0007; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 7FF798D0003 for ; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 33EAD8249980 for ; Fri, 13 Aug 2021 23:54:40 +0000 (UTC) X-FDA: 78471714720.32.F83B33C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf13.hostedemail.com (Postfix) with ESMTP id D19141013C73 for ; Fri, 13 Aug 2021 23:54:39 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 2659F610F7; Fri, 13 Aug 2021 23:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898879; bh=NjQZrs+ymn1N+nS8UGQy8zm+/Gtdn8lVDmyEIRG5YNs=; h=Date:From:To:Subject:In-Reply-To:From; b=lUZv7W92e8FVCNZwU5YOyBZGutPKNEn5EwA1HP2L9VhFSn8JMx9+XU6SQ0I/mq+u2 /bsSZ+Tny8jULBQwpiQTblcMwQS6F0VT8jQZh550BUwjbL+kHRDQgdAdYEb0Yk6duc kwDdp+bh/BtUGj44JKyVn4RqitSkvc/T5bQ75f9Q= Date: Fri, 13 Aug 2021 16:54:37 -0700 From: Andrew Morton To: aarcange@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, chris@zankel.net, dave.hansen@intel.com, david@redhat.com, deller@gmx.de, eike-kernel@sf-tec.de, hughd@google.com, ink@jurassic.park.msu.ru, James.Bottomley@HansenPartnership.com, jannh@google.com, jcmvbkbc@gmail.com, jgg@ziepe.ca, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, linuxram@us.ibm.com, mattst88@gmail.com, mhocko@suse.com, mike.kravetz@oracle.com, minchan@kernel.org, mm-commits@vger.kernel.org, mst@redhat.com, osalvador@suse.de, peterx@redhat.com, riel@surriel.com, rth@twiddle.net, shuah@kernel.org, torvalds@linux-foundation.org, tsbogend@alpha.franken.de, vbabka@suse.cz, willy@infradead.org Subject: [patch 5/7] mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE) Message-ID: <20210813235437.jpdoEJdjF%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: D19141013C73 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=lUZv7W92; dmarc=none; spf=pass (imf13.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam04 X-Stat-Signature: 6wucuagine59zyj91185fihg19y6ijaq X-HE-Tag: 1628898879-861414 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: From: David Hildenbrand Subject: mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE) Doing some extended tests and polishing the man page update for MADV_POPULATE_(READ|WRITE), I realized that we end up converting also SIGBUS (via -EFAULT) to -EINVAL, making it look like yet another madvise() user error. We want to report only problematic mappings and permission problems that the user could have know as -EINVAL. Let's not convert -EFAULT arising due to SIGBUS (or SIGSEGV) to -EINVAL, but instead indicate -EFAULT to user space. While we could also convert it to -ENOMEM, using -EFAULT looks more helpful when user space might want to troubleshoot what's going wrong: MADV_POPULATE_(READ|WRITE) is not part of an final Linux release and we can still adjust the behavio= r. Link: https://lkml.kernel.org/r/20210726154932.102880-1-david@redhat.com Fixes: 4ca9b3859dac ("mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables") Signed-off-by: David Hildenbrand Cc: Arnd Bergmann Cc: Michal Hocko Cc: Oscar Salvador Cc: Matthew Wilcox (Oracle) Cc: Andrea Arcangeli Cc: Minchan Kim Cc: Jann Horn Cc: Jason Gunthorpe Cc: Dave Hansen Cc: Hugh Dickins Cc: Rik van Riel Cc: Michael S. Tsirkin Cc: Kirill A. Shutemov Cc: Vlastimil Babka Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Thomas Bogendoerfer Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: Chris Zankel Cc: Max Filippov Cc: Mike Kravetz Cc: Peter Xu Cc: Rolf Eike Beer Cc: Ram Pai Cc: Shuah Khan Signed-off-by: Andrew Morton --- mm/gup.c | 7 +++++-- mm/madvise.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) --- a/mm/gup.c~mm-madvise-report-sigbus-as-efault-for-madv_populate_readwrite +++ a/mm/gup.c @@ -1558,9 +1558,12 @@ long faultin_vma_page_range(struct vm_ar gup_flags |= FOLL_WRITE; /* - * See check_vma_flags(): Will return -EFAULT on incompatible mappings - * or with insufficient permissions. + * We want to report -EINVAL instead of -EFAULT for any permission + * problems or incompatible mappings. */ + if (check_vma_flags(vma, gup_flags)) + return -EINVAL; + return __get_user_pages(mm, start, nr_pages, gup_flags, NULL, NULL, locked); } --- a/mm/madvise.c~mm-madvise-report-sigbus-as-efault-for-madv_populate_readwrite +++ a/mm/madvise.c @@ -862,10 +862,12 @@ static long madvise_populate(struct vm_a switch (pages) { case -EINTR: return -EINTR; - case -EFAULT: /* Incompatible mappings / permissions. */ + case -EINVAL: /* Incompatible mappings / permissions. */ return -EINVAL; case -EHWPOISON: return -EHWPOISON; + case -EFAULT: /* VM_FAULT_SIGBUS or VM_FAULT_SIGSEGV */ + return -EFAULT; default: pr_warn_once("%s: unhandled return value: %ld\n", __func__, pages); From patchwork Fri Aug 13 23:54:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37E18C4320E for ; Fri, 13 Aug 2021 23:54:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B58AE610EA for ; Fri, 13 Aug 2021 23:54:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B58AE610EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5BE2F8D0008; Fri, 13 Aug 2021 19:54:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56E308D0003; Fri, 13 Aug 2021 19:54:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45D6A8D0008; Fri, 13 Aug 2021 19:54:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id 2B0508D0003 for ; Fri, 13 Aug 2021 19:54:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C826C8249980 for ; Fri, 13 Aug 2021 23:54:43 +0000 (UTC) X-FDA: 78471714846.29.D89D6C1 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf05.hostedemail.com (Postfix) with ESMTP id 7B6555029D69 for ; Fri, 13 Aug 2021 23:54:43 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 150E0610FC; Fri, 13 Aug 2021 23:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898882; bh=54r1TL585LlmFiGUPyCQ4Ab6mRQKDCBPHd9HTVWsoi4=; h=Date:From:To:Subject:In-Reply-To:From; b=FFpKhJAuffTHAJnKpDIxfGa55+P+u378YWhi1+BWexP2//xpT+E+tbA/K2cNOVwOL pxXRHWbMHUqb6JYdp83401rE/b8ATevHPR0lj+qWHoRMh+ScYAgja+JTdax6ClHic4 Av8oMO0dtLurU0z7pxWjk7m/BkJVyhBRPw0wPN2E= Date: Fri, 13 Aug 2021 16:54:41 -0700 From: Andrew Morton To: akpm@linux-foundation.org, alex.shi@linux.alibaba.com, chris@chrisdown.name, cl@linux.com, guro@fb.com, hannes@cmpxchg.org, iamjoonsoo.kim@lge.com, laoar.shao@gmail.com, linux-mm@kvack.org, longman@redhat.com, mhocko@suse.com, mm-commits@vger.kernel.org, msys.mizuma@gmail.com, penberg@kernel.org, richard.weiyang@gmail.com, rientjes@google.com, shakeelb@google.com, songmuchun@bytedance.com, tj@kernel.org, torvalds@linux-foundation.org, vbabka@suse.cz, vdavydov.dev@gmail.com, willy@infradead.org, zhengjun.xing@linux.intel.com Subject: [patch 6/7] mm/memcg: fix incorrect flushing of lruvec data in obj_stock Message-ID: <20210813235441.2QVRIvRYV%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=FFpKhJAu; dmarc=none; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: wi7jajp1fq5bm4r9acpczf5d78qw1qon X-Rspamd-Queue-Id: 7B6555029D69 X-Rspamd-Server: rspam05 X-HE-Tag: 1628898883-153121 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: From: Waiman Long Subject: mm/memcg: fix incorrect flushing of lruvec data in obj_stock When mod_objcg_state() is called with a pgdat that is different from that in the obj_stock, the old lruvec data cached in obj_stock are flushed out. Unfortunately, they were flushed to the new pgdat and so the data go to the wrong node. This will screw up the slab data reported in /sys/devices/system/node/node*/meminfo. Fix that by flushing the data to the cached pgdat instead. Link: https://lkml.kernel.org/r/20210802143834.30578-1-longman@redhat.com Fixes: 68ac5b3c8db2 ("mm/memcg: cache vmstat data in percpu memcg_stock_pcp") Signed-off-by: Waiman Long Acked-by: Michal Hocko Reviewed-by: Shakeel Butt Acked-by: Roman Gushchin Cc: Johannes Weiner Cc: Vladimir Davydov Cc: Tejun Heo Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Vlastimil Babka Cc: Muchun Song Cc: Alex Shi Cc: Chris Down Cc: Yafang Shao Cc: Wei Yang Cc: Masayoshi Mizuma Cc: Xing Zhengjun Cc: Matthew Wilcox Cc: Waiman Long Signed-off-by: Andrew Morton --- mm/memcontrol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/mm/memcontrol.c~mm-memcg-fix-incorrect-flushing-of-lruvec-data-in-obj_stock +++ a/mm/memcontrol.c @@ -3106,13 +3106,15 @@ void mod_objcg_state(struct obj_cgroup * stock->cached_pgdat = pgdat; } else if (stock->cached_pgdat != pgdat) { /* Flush the existing cached vmstat data */ + struct pglist_data *oldpg = stock->cached_pgdat; + if (stock->nr_slab_reclaimable_b) { - mod_objcg_mlstate(objcg, pgdat, NR_SLAB_RECLAIMABLE_B, + mod_objcg_mlstate(objcg, oldpg, NR_SLAB_RECLAIMABLE_B, stock->nr_slab_reclaimable_b); stock->nr_slab_reclaimable_b = 0; } if (stock->nr_slab_unreclaimable_b) { - mod_objcg_mlstate(objcg, pgdat, NR_SLAB_UNRECLAIMABLE_B, + mod_objcg_mlstate(objcg, oldpg, NR_SLAB_UNRECLAIMABLE_B, stock->nr_slab_unreclaimable_b); stock->nr_slab_unreclaimable_b = 0; } From patchwork Fri Aug 13 23:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39187C432BE for ; Fri, 13 Aug 2021 23:54:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD21E610FE for ; Fri, 13 Aug 2021 23:54:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD21E610FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8A4B88D0009; Fri, 13 Aug 2021 19:54:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 854CA8D0003; Fri, 13 Aug 2021 19:54:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 743438D0009; Fri, 13 Aug 2021 19:54:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 5A5008D0003 for ; Fri, 13 Aug 2021 19:54:47 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0854F1694D for ; Fri, 13 Aug 2021 23:54:47 +0000 (UTC) X-FDA: 78471715014.22.0AFDEEF Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP id B4B6510001FF for ; Fri, 13 Aug 2021 23:54:46 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 99DDE610C8; Fri, 13 Aug 2021 23:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898886; bh=xN7uDkzQLv00XCsVvFZ+jfprpbgZTkT5VePR68D5fjg=; h=Date:From:To:Subject:In-Reply-To:From; b=0Me4an+Bt+HDevKlYVe1zaS8IgnSZQuWWxz1J/wF6o6xoSX7A2Iq1cg9u87u63rur OIXy7smYGKQ3t6Hc3vKoewJ/36jr/ITAYJZGzvHuWLB1F0WYmg3InFngSvcTW54iI1 UzHxRkT45WPXKHRsxAvJSUyF9vFe+l8LMNuW1tSE= Date: Fri, 13 Aug 2021 16:54:45 -0700 From: Andrew Morton To: akpm@linux-foundation.org, gregkh@linuxfoundation.org, linux-mm@kvack.org, linux@armlinux.org.uk, mcgrof@kernel.org, mm-commits@vger.kernel.org, nixiaoming@huawei.com, palmerdabbelt@google.com, stable@vger.kernel.org, torvalds@linux-foundation.org, wangkefeng.wang@huawei.com, wangliang101@huawei.com Subject: [patch 7/7] lib: use PFN_PHYS() in devmem_is_allowed() Message-ID: <20210813235445.iSOZmfuWE%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: B4B6510001FF Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=0Me4an+B; spf=pass (imf07.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam01 X-Stat-Signature: p4utakho16c1tjsdoga3pjr65tirj9un X-HE-Tag: 1628898886-508130 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: From: Liang Wang Subject: lib: use PFN_PHYS() in devmem_is_allowed() The physical address may exceed 32 bits on 32-bit systems with more than 32 bits of physcial address. Use PFN_PHYS() in devmem_is_allowed(), or the physical address may overflow and be truncated. We found this bug when mapping a high addresses through devmem tool, when CONFIG_STRICT_DEVMEM is enabled on the ARM with ARM_LPAE and devmem is used to map a high address that is not in the iomem address range, an unexpected error indicating no permission is returned. This bug was initially introduced from v2.6.37, and the function was moved to lib when v5.11. Link: https://lkml.kernel.org/r/20210731025057.78825-1-wangliang101@huawei.com Fixes: 087aaffcdf9c ("ARM: implement CONFIG_STRICT_DEVMEM by disabling access to RAM via /dev/mem") Fixes: 527701eda5f1 ("lib: Add a generic version of devmem_is_allowed()") Signed-off-by: Liang Wang Reviewed-by: Luis Chamberlain Cc: Palmer Dabbelt Cc: Greg Kroah-Hartman Cc: Russell King Cc: Liang Wang Cc: Xiaoming Ni Cc: Kefeng Wang Cc: [2.6.37+] Signed-off-by: Andrew Morton --- lib/devmem_is_allowed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/lib/devmem_is_allowed.c~lib-use-pfn_phys-in-devmem_is_allowed +++ a/lib/devmem_is_allowed.c @@ -19,7 +19,7 @@ */ int devmem_is_allowed(unsigned long pfn) { - if (iomem_is_exclusive(pfn << PAGE_SHIFT)) + if (iomem_is_exclusive(PFN_PHYS(pfn))) return 0; if (!page_is_ram(pfn)) return 1;