From patchwork Fri Feb 4 04:49:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734788 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 1865DC433F5 for ; Fri, 4 Feb 2022 04:49:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C8556B0073; Thu, 3 Feb 2022 23:49:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 977BC6B0074; Thu, 3 Feb 2022 23:49:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83F7A6B0075; Thu, 3 Feb 2022 23:49:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 765C26B0073 for ; Thu, 3 Feb 2022 23:49:11 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2B7D3824C447 for ; Fri, 4 Feb 2022 04:49:11 +0000 (UTC) X-FDA: 79103868102.11.FF641B1 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf05.hostedemail.com (Postfix) with ESMTP id BD0DB100002 for ; Fri, 4 Feb 2022 04:49:10 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A8FA1B817E5; Fri, 4 Feb 2022 04:49:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B976C004E1; Fri, 4 Feb 2022 04:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950148; bh=ljC+ZB7/P+JNIOZfeDuwZx/G/aLrfvXi55fo2JuPMkc=; h=Date:To:From:In-Reply-To:Subject:From; b=16uofj9/66KjMZ6UkbUWHKdubwUpkyJSMTpx/nyhq2WX3yc5iQ8exyc8z82KCehIB yu7wi8N1JvXRFaaIpg82tWqFYejKbNKA9qSgpP9xCjRP5euYGjM/0gDf43npfQIr8j lGwOZ3SOI0JDxSZUI/eDobIsgeC/DngSMug7eUcE= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:06 -0800 Date: Thu, 03 Feb 2022 20:49:06 -0800 To: vbabka@suse.cz,linux@roeck-us.net,francesco.dolcini@toradex.com,david@redhat.com,bot@kernelci.org,aisheng.dong@nxp.com,chenwandun@huawei.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 01/10] Revert "mm/page_isolation: unset migratetype directly for non Buddy page" Message-Id: <20220204044907.2B976C004E1@smtp.kernel.org> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: BD0DB100002 X-Stat-Signature: 81ekqg9bk5o7o6pzi53x8nadztq769ck X-Rspam-User: nil Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="16uofj9/"; spf=pass (imf05.hostedemail.com: domain of akpm@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@kernel.org; dmarc=none X-HE-Tag: 1643950150-723195 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: Chen Wandun Subject: Revert "mm/page_isolation: unset migratetype directly for non Buddy page" This reverts commit 721fb891ad0b3956d5c168b2931e3e5e4fb7ca40. commit 721fb891ad0b ("mm/page_isolation: unset migratetype directly for non Buddy page") will result memory that should in buddy disappear by mistake. move_freepages_block move all pages in pageblock instead of pages indicated by input parameter, so if input pages is not in buddy but other pages in pageblock is in buddy, it will result in page out of control. Link: https://lkml.kernel.org/r/20220126024436.13921-1-chenwandun@huawei.com Fixes: 721fb891ad0b ("mm/page_isolation: unset migratetype directly for non Buddy page") Signed-off-by: Chen Wandun Reported-by: "kernelci.org bot" Acked-by: David Hildenbrand Tested-by: Dong Aisheng Tested-by: Francesco Dolcini Acked-by: Vlastimil Babka Tested-by: Guenter Roeck Signed-off-by: Andrew Morton --- mm/page_isolation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/page_isolation.c~revert-mm-page_isolation-unset-migratetype-directly-for-non-buddy-page +++ a/mm/page_isolation.c @@ -115,7 +115,7 @@ static void unset_migratetype_isolate(st * onlining - just onlined memory won't immediately be considered for * allocation. */ - if (!isolated_page && PageBuddy(page)) { + if (!isolated_page) { nr_pages = move_freepages_block(zone, page, migratetype, NULL); __mod_zone_freepage_state(zone, nr_pages, migratetype); } From patchwork Fri Feb 4 04:49:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734789 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 E5E1EC433EF for ; Fri, 4 Feb 2022 04:49:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 757CF6B0074; Thu, 3 Feb 2022 23:49:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 706336B0075; Thu, 3 Feb 2022 23:49:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CE426B0078; Thu, 3 Feb 2022 23:49:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0029.hostedemail.com [216.40.44.29]) by kanga.kvack.org (Postfix) with ESMTP id 4E08C6B0074 for ; Thu, 3 Feb 2022 23:49:16 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 007C596752 for ; Fri, 4 Feb 2022 04:49:15 +0000 (UTC) X-FDA: 79103868312.08.9425CC2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf01.hostedemail.com (Postfix) with ESMTP id 787CA40003 for ; Fri, 4 Feb 2022 04:49:15 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 57672B8366B; Fri, 4 Feb 2022 04:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75F58C004E1; Fri, 4 Feb 2022 04:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950153; bh=T6HZzuF9kGoCDs+xTHJbPxAXenTBHTFYjDOPtEfogn0=; h=Date:To:From:In-Reply-To:Subject:From; b=pRtMXnfQgDH4cec97TvEXBzcUrEgQdiqZrqQg/QlHoigq+4M++UcCfiip4dbAqczf ntmVRfvP+eM6ebJOTyUZPypJz7poKn/nOZhBPWSRvsZ96MZe31sCrSDBxd0sP+05vE wR15nCGANM54UIPLffV7Bwf8KhLvEileBO4Hrk0w= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:10 -0800 Date: Thu, 03 Feb 2022 20:49:10 -0800 To: ziy@nvidia.com,will@kernel.org,weixugc@google.com,stable@vger.kernel.org,songmuchun@bytedance.com,rppt@kernel.org,rientjes@google.com,pjt@google.com,mingo@redhat.com,jirislaby@kernel.org,hughd@google.com,hpa@zytor.com,gthelen@google.com,dave.hansen@linux.intel.com,anshuman.khandual@arm.com,aneesh.kumar@linux.ibm.com,pasha.tatashin@soleen.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 02/10] mm/debug_vm_pgtable: remove pte entry from the page table Message-Id: <20220204044911.75F58C004E1@smtp.kernel.org> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 787CA40003 X-Rspam-User: nil Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=pRtMXnfQ; dmarc=none; spf=pass (imf01.hostedemail.com: domain of akpm@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Stat-Signature: ksiod9gt4sk7xr1yodyxtrdwdynh4tmw X-HE-Tag: 1643950155-57000 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: Pasha Tatashin Subject: mm/debug_vm_pgtable: remove pte entry from the page table Patch series "page table check fixes and cleanups", v5. This patch (of 4): The pte entry that is used in pte_advanced_tests() is never removed from the page table at the end of the test. The issue is detected by page_table_check, to repro compile kernel with the following configs: CONFIG_DEBUG_VM_PGTABLE=y CONFIG_PAGE_TABLE_CHECK=y CONFIG_PAGE_TABLE_CHECK_ENFORCED=y During the boot the following BUG is printed: [ 2.262821] debug_vm_pgtable: [debug_vm_pgtable ]: Validating architecture page table helpers [ 2.276826] ------------[ cut here ]------------ [ 2.280426] kernel BUG at mm/page_table_check.c:162! [ 2.284118] invalid opcode: 0000 [#1] PREEMPT SMP PTI [ 2.287787] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.16.0-11413-g2c271fe77d52 #3 [ 2.293226] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 ... The entry should be properly removed from the page table before the page is released to the free list. Link: https://lkml.kernel.org/r/20220131203249.2832273-1-pasha.tatashin@soleen.com Link: https://lkml.kernel.org/r/20220131203249.2832273-2-pasha.tatashin@soleen.com Fixes: a5c3b9ffb0f4 ("mm/debug_vm_pgtable: add tests validating advanced arch page table helpers") Signed-off-by: Pasha Tatashin Reviewed-by: Zi Yan Tested-by: Zi Yan Acked-by: David Rientjes Reviewed-by: Anshuman Khandual Cc: Paul Turner Cc: Wei Xu Cc: Greg Thelen Cc: Ingo Molnar Cc: Will Deacon Cc: Mike Rapoport Cc: Dave Hansen Cc: H. Peter Anvin Cc: Aneesh Kumar K.V Cc: Jiri Slaby Cc: Muchun Song Cc: Hugh Dickins Cc: [5.9+] Signed-off-by: Andrew Morton --- mm/debug_vm_pgtable.c | 2 ++ 1 file changed, 2 insertions(+) --- a/mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-remove-pte-entry-from-the-page-table +++ a/mm/debug_vm_pgtable.c @@ -171,6 +171,8 @@ static void __init pte_advanced_tests(st ptep_test_and_clear_young(args->vma, args->vaddr, args->ptep); pte = ptep_get(args->ptep); WARN_ON(pte_young(pte)); + + ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1); } static void __init pte_savedwrite_tests(struct pgtable_debug_args *args) From patchwork Fri Feb 4 04:49:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734790 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 63407C4332F for ; Fri, 4 Feb 2022 04:49:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F20236B0075; Thu, 3 Feb 2022 23:49:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECEB66B0078; Thu, 3 Feb 2022 23:49:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D70F06B007B; Thu, 3 Feb 2022 23:49:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id C0F466B0075 for ; Thu, 3 Feb 2022 23:49:19 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 8F61F803D5 for ; Fri, 4 Feb 2022 04:49:19 +0000 (UTC) X-FDA: 79103868438.03.52EBBAE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 10D33140004 for ; Fri, 4 Feb 2022 04:49:18 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 467B461B4D; Fri, 4 Feb 2022 04:49:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06FECC004E1; Fri, 4 Feb 2022 04:49:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950157; bh=CwXvMW0kzg+EbExulgkv4VP+W8ZnB/a12489SOXC0sI=; h=Date:To:From:In-Reply-To:Subject:From; b=srG60j7NHHwdQIta+vPF4zTILUwqGwcC13W6AiTNar27nitn6oyxP23eiUHctYMLp Q9//bWGA75nkUkH7yENKzHQom43Cn9gbpCkuU54Sk7866MxkMvmkMWPvnJX2HSmuO1 gYH9O6VkV54BzuxksschF43IuAXmma3S8mWR+V+I= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:15 -0800 Date: Thu, 03 Feb 2022 20:49:15 -0800 To: ziy@nvidia.com,will@kernel.org,weixugc@google.com,songmuchun@bytedance.com,rppt@kernel.org,rientjes@google.com,pjt@google.com,mingo@redhat.com,jirislaby@kernel.org,hughd@google.com,hpa@zytor.com,gthelen@google.com,dave.hansen@linux.intel.com,anshuman.khandual@arm.com,aneesh.kumar@linux.ibm.com,pasha.tatashin@soleen.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 03/10] mm/page_table_check: use unsigned long for page counters and cleanup Message-Id: <20220204044916.06FECC004E1@smtp.kernel.org> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 10D33140004 X-Stat-Signature: 3p3ijw3tn73zs7h5qdo7b4wc4gg38a87 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=srG60j7N; dmarc=none; spf=pass (imf09.hostedemail.com: domain of akpm@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Rspam-User: nil X-HE-Tag: 1643950158-363539 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: Pasha Tatashin Subject: mm/page_table_check: use unsigned long for page counters and cleanup For consistency, use "unsigned long" for all page counters. Also, reduce code duplication by calling __page_table_check_*_clear() from __page_table_check_*_set() functions. Link: https://lkml.kernel.org/r/20220131203249.2832273-3-pasha.tatashin@soleen.com Signed-off-by: Pasha Tatashin Reviewed-by: Wei Xu Acked-by: David Rientjes Cc: Aneesh Kumar K.V Cc: Anshuman Khandual Cc: Dave Hansen Cc: Greg Thelen Cc: H. Peter Anvin Cc: Hugh Dickins Cc: Ingo Molnar Cc: Jiri Slaby Cc: Mike Rapoport Cc: Muchun Song Cc: Paul Turner Cc: Will Deacon Cc: Zi Yan Signed-off-by: Andrew Morton --- mm/page_table_check.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) --- a/mm/page_table_check.c~mm-page_table_check-use-unsigned-long-for-page-counters-and-cleanup +++ a/mm/page_table_check.c @@ -86,8 +86,8 @@ static void page_table_check_clear(struc { struct page_ext *page_ext; struct page *page; + unsigned long i; bool anon; - int i; if (!pfn_valid(pfn)) return; @@ -121,8 +121,8 @@ static void page_table_check_set(struct { struct page_ext *page_ext; struct page *page; + unsigned long i; bool anon; - int i; if (!pfn_valid(pfn)) return; @@ -152,10 +152,10 @@ static void page_table_check_set(struct void __page_table_check_zero(struct page *page, unsigned int order) { struct page_ext *page_ext = lookup_page_ext(page); - int i; + unsigned long i; BUG_ON(!page_ext); - for (i = 0; i < (1 << order); i++) { + for (i = 0; i < (1ul << order); i++) { struct page_table_check *ptc = get_page_table_check(page_ext); BUG_ON(atomic_read(&ptc->anon_map_count)); @@ -206,17 +206,10 @@ EXPORT_SYMBOL(__page_table_check_pud_cle void __page_table_check_pte_set(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) { - pte_t old_pte; - if (&init_mm == mm) return; - old_pte = *ptep; - if (pte_user_accessible_page(old_pte)) { - page_table_check_clear(mm, addr, pte_pfn(old_pte), - PAGE_SIZE >> PAGE_SHIFT); - } - + __page_table_check_pte_clear(mm, addr, *ptep); if (pte_user_accessible_page(pte)) { page_table_check_set(mm, addr, pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT, @@ -228,17 +221,10 @@ EXPORT_SYMBOL(__page_table_check_pte_set void __page_table_check_pmd_set(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd) { - pmd_t old_pmd; - if (&init_mm == mm) return; - old_pmd = *pmdp; - if (pmd_user_accessible_page(old_pmd)) { - page_table_check_clear(mm, addr, pmd_pfn(old_pmd), - PMD_PAGE_SIZE >> PAGE_SHIFT); - } - + __page_table_check_pmd_clear(mm, addr, *pmdp); if (pmd_user_accessible_page(pmd)) { page_table_check_set(mm, addr, pmd_pfn(pmd), PMD_PAGE_SIZE >> PAGE_SHIFT, @@ -250,17 +236,10 @@ EXPORT_SYMBOL(__page_table_check_pmd_set void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr, pud_t *pudp, pud_t pud) { - pud_t old_pud; - if (&init_mm == mm) return; - old_pud = *pudp; - if (pud_user_accessible_page(old_pud)) { - page_table_check_clear(mm, addr, pud_pfn(old_pud), - PUD_PAGE_SIZE >> PAGE_SHIFT); - } - + __page_table_check_pud_clear(mm, addr, *pudp); if (pud_user_accessible_page(pud)) { page_table_check_set(mm, addr, pud_pfn(pud), PUD_PAGE_SIZE >> PAGE_SHIFT, From patchwork Fri Feb 4 04:49:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734791 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 CE089C433F5 for ; Fri, 4 Feb 2022 04:49:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 692F86B0078; Thu, 3 Feb 2022 23:49:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 642846B007B; Thu, 3 Feb 2022 23:49:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E3BD6B007D; Thu, 3 Feb 2022 23:49:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 3E0BF6B0078 for ; Thu, 3 Feb 2022 23:49:25 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F172E181DB371 for ; Fri, 4 Feb 2022 04:49:24 +0000 (UTC) X-FDA: 79103868648.18.E1D7A25 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf28.hostedemail.com (Postfix) with ESMTP id 76FC2C0002 for ; Fri, 4 Feb 2022 04:49:24 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 626C3B83669; Fri, 4 Feb 2022 04:49:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B40AC340F0; Fri, 4 Feb 2022 04:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950162; bh=yjWNMIG51D1uSvIE77XEC6AgViA+/ifmW+Z1eUPIVfA=; h=Date:To:From:In-Reply-To:Subject:From; b=1DuAkZSr7pfJNuS0s7+4bR3QnWUCqoO692US7ZKJ692SI002cHVbyahk6SeQTkli3 0mruIDZcCDBsSvVnDIi8Ags7qQM/WsJ7OAMOb4oewhghQgDMxv+vdSVU/qn7Q1DlgQ ioQUuBrc5Djx+4MTXU6gDvjiRoMYXgsZM4b9ARwI= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:20 -0800 Date: Thu, 03 Feb 2022 20:49:20 -0800 To: ziy@nvidia.com,will@kernel.org,weixugc@google.com,songmuchun@bytedance.com,rppt@kernel.org,rientjes@google.com,pjt@google.com,mingo@redhat.com,jirislaby@kernel.org,hughd@google.com,hpa@zytor.com,gthelen@google.com,dave.hansen@linux.intel.com,anshuman.khandual@arm.com,aneesh.kumar@linux.ibm.com,pasha.tatashin@soleen.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 04/10] mm/khugepaged: unify collapse pmd clear, flush and free Message-Id: <20220204044920.8B40AC340F0@smtp.kernel.org> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 76FC2C0002 X-Stat-Signature: rd88mgeniufmcuuf89zukjtiy31tzpd8 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=1DuAkZSr; dmarc=none; spf=pass (imf28.hostedemail.com: domain of akpm@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Rspam-User: nil X-HE-Tag: 1643950164-487687 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: Pasha Tatashin Subject: mm/khugepaged: unify collapse pmd clear, flush and free Unify the code that flushes, clears pmd entry, and frees the PTE table level into a new function collapse_and_free_pmd(). This cleanup is useful as in the next patch we will add another call to this function to iterate through PTE prior to freeing the level for page table check. Link: https://lkml.kernel.org/r/20220131203249.2832273-4-pasha.tatashin@soleen.com Signed-off-by: Pasha Tatashin Acked-by: David Rientjes Cc: Aneesh Kumar K.V Cc: Anshuman Khandual Cc: Dave Hansen Cc: Greg Thelen Cc: H. Peter Anvin Cc: Hugh Dickins Cc: Ingo Molnar Cc: Jiri Slaby Cc: Mike Rapoport Cc: Muchun Song Cc: Paul Turner Cc: Wei Xu Cc: Will Deacon Cc: Zi Yan Signed-off-by: Andrew Morton --- mm/khugepaged.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) --- a/mm/khugepaged.c~mm-khugepaged-unify-collapse-pmd-clear-flush-and-free +++ a/mm/khugepaged.c @@ -1416,6 +1416,19 @@ static int khugepaged_add_pte_mapped_thp return 0; } +static void collapse_and_free_pmd(struct mm_struct *mm, struct vm_area_struct *vma, + unsigned long addr, pmd_t *pmdp) +{ + spinlock_t *ptl; + pmd_t pmd; + + ptl = pmd_lock(vma->vm_mm, pmdp); + pmd = pmdp_collapse_flush(vma, addr, pmdp); + spin_unlock(ptl); + mm_dec_nr_ptes(mm); + pte_free(mm, pmd_pgtable(pmd)); +} + /** * collapse_pte_mapped_thp - Try to collapse a pte-mapped THP for mm at * address haddr. @@ -1433,7 +1446,7 @@ void collapse_pte_mapped_thp(struct mm_s struct vm_area_struct *vma = find_vma(mm, haddr); struct page *hpage; pte_t *start_pte, *pte; - pmd_t *pmd, _pmd; + pmd_t *pmd; spinlock_t *ptl; int count = 0; int i; @@ -1509,12 +1522,7 @@ void collapse_pte_mapped_thp(struct mm_s } /* step 4: collapse pmd */ - ptl = pmd_lock(vma->vm_mm, pmd); - _pmd = pmdp_collapse_flush(vma, haddr, pmd); - spin_unlock(ptl); - mm_dec_nr_ptes(mm); - pte_free(mm, pmd_pgtable(_pmd)); - + collapse_and_free_pmd(mm, vma, haddr, pmd); drop_hpage: unlock_page(hpage); put_page(hpage); @@ -1552,7 +1560,7 @@ static void retract_page_tables(struct a struct vm_area_struct *vma; struct mm_struct *mm; unsigned long addr; - pmd_t *pmd, _pmd; + pmd_t *pmd; i_mmap_lock_write(mapping); vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { @@ -1591,14 +1599,8 @@ static void retract_page_tables(struct a * reverse order. Trylock is a way to avoid deadlock. */ if (mmap_write_trylock(mm)) { - if (!khugepaged_test_exit(mm)) { - spinlock_t *ptl = pmd_lock(mm, pmd); - /* assume page table is clear */ - _pmd = pmdp_collapse_flush(vma, addr, pmd); - spin_unlock(ptl); - mm_dec_nr_ptes(mm); - pte_free(mm, pmd_pgtable(_pmd)); - } + if (!khugepaged_test_exit(mm)) + collapse_and_free_pmd(mm, vma, addr, pmd); mmap_write_unlock(mm); } else { /* Try again later */ From patchwork Fri Feb 4 04:49:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734792 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 59F26C433F5 for ; Fri, 4 Feb 2022 04:49:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0E396B007B; Thu, 3 Feb 2022 23:49:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBE0C6B007D; Thu, 3 Feb 2022 23:49:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5E646B007E; Thu, 3 Feb 2022 23:49:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id B271D6B007B for ; Thu, 3 Feb 2022 23:49:28 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 90756603D5 for ; Fri, 4 Feb 2022 04:49:28 +0000 (UTC) X-FDA: 79103868816.01.52EA578 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 2335640003 for ; Fri, 4 Feb 2022 04:49:27 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6C83161B4A; Fri, 4 Feb 2022 04:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B2DDC004E1; Fri, 4 Feb 2022 04:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950166; bh=8UFjsBnLl8qSAQtuJHwjvJ7uYQLWhLEujT7ncgu71AM=; h=Date:To:From:In-Reply-To:Subject:From; b=AWO3ISE/Uyzn+L2KBFpv7w9PB7lgTFfpqfKRDWO2jc2yc43knxlOBfb7uv02wCxm7 219mjZuZobYp7SKW6ExL03/FwA4ERgi+ULvFcJxS9pypFVQMdTc5zBFZk7AYmjtwsV iZ/rN6on+sYqn5e0ag01vdUn2lSs8ryBqvN9fYM4= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:24 -0800 Date: Thu, 03 Feb 2022 20:49:24 -0800 To: ziy@nvidia.com,will@kernel.org,weixugc@google.com,songmuchun@bytedance.com,rppt@kernel.org,rientjes@google.com,pjt@google.com,mingo@redhat.com,jirislaby@kernel.org,hughd@google.com,hpa@zytor.com,gthelen@google.com,dave.hansen@linux.intel.com,anshuman.khandual@arm.com,aneesh.kumar@linux.ibm.com,pasha.tatashin@soleen.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 05/10] mm/page_table_check: check entries at pmd levels Message-Id: <20220204044925.3B2DDC004E1@smtp.kernel.org> X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2335640003 X-Stat-Signature: tmk8dkxgnru4szxj8jhi1mr69f93gsat Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="AWO3ISE/"; dmarc=none; spf=pass (imf12.hostedemail.com: domain of akpm@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@kernel.org X-HE-Tag: 1643950167-681632 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: Pasha Tatashin Subject: mm/page_table_check: check entries at pmd levels syzbot detected a case where the page table counters were not properly updated. syzkaller login: ------------[ cut here ]------------ kernel BUG at mm/page_table_check.c:162! invalid opcode: 0000 [#1] PREEMPT SMP KASAN CPU: 0 PID: 3099 Comm: pasha Not tainted 5.16.0+ #48 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIO4 RIP: 0010:__page_table_check_zero+0x159/0x1a0 Code: 7d 3a b2 ff 45 39 f5 74 2a e8 43 38 b2 ff 4d 85 e4 01 RSP: 0018:ffff888010667418 EFLAGS: 00010293 RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000 RDX: ffff88800cea8680 RSI: ffffffff81becaf9 RDI: 0000000003 RBP: ffff888010667450 R08: 0000000000000001 R09: 0000000000 R10: ffffffff81becaab R11: 0000000000000001 R12: ffff888008 R13: 0000000000000001 R14: 0000000000000200 R15: dffffc0000 FS: 0000000000000000(0000) GS:ffff888035e00000(0000) knlG0 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ffd875cad00 CR3: 00000000094ce000 CR4: 0000000000 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000 Call Trace: free_pcp_prepare+0x3be/0xaa0 free_unref_page+0x1c/0x650 ? trace_hardirqs_on+0x6a/0x1d0 free_compound_page+0xec/0x130 free_transhuge_page+0x1be/0x260 __put_compound_page+0x90/0xd0 release_pages+0x54c/0x1060 ? filemap_remove_folio+0x161/0x210 ? lock_downgrade+0x720/0x720 ? __put_page+0x150/0x150 ? filemap_free_folio+0x164/0x350 __pagevec_release+0x7c/0x110 shmem_undo_range+0x85e/0x1250 ... The repro involved having a huge page that is split due to uprobe event temporarily replacing one of the pages in the huge page. Later the huge page was combined again, but the counters were off, as the PTE level was not properly updated. Make sure that when PMD is cleared and prior to freeing the level the PTEs are updated. Link: https://lkml.kernel.org/r/20220131203249.2832273-5-pasha.tatashin@soleen.com Fixes: df4e817b7108 ("mm: page table check") Signed-off-by: Pasha Tatashin Acked-by: David Rientjes Cc: Aneesh Kumar K.V Cc: Anshuman Khandual Cc: Dave Hansen Cc: Greg Thelen Cc: H. Peter Anvin Cc: Hugh Dickins Cc: Ingo Molnar Cc: Jiri Slaby Cc: Mike Rapoport Cc: Muchun Song Cc: Paul Turner Cc: Wei Xu Cc: Will Deacon Cc: Zi Yan Signed-off-by: Andrew Morton --- include/linux/page_table_check.h | 19 +++++++++++++++++++ mm/khugepaged.c | 3 +++ mm/page_table_check.c | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) --- a/include/linux/page_table_check.h~mm-page_table_check-check-entries-at-pmd-levels +++ a/include/linux/page_table_check.h @@ -26,6 +26,9 @@ void __page_table_check_pmd_set(struct m pmd_t *pmdp, pmd_t pmd); void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr, pud_t *pudp, pud_t pud); +void __page_table_check_pte_clear_range(struct mm_struct *mm, + unsigned long addr, + pmd_t pmd); static inline void page_table_check_alloc(struct page *page, unsigned int order) { @@ -100,6 +103,16 @@ static inline void page_table_check_pud_ __page_table_check_pud_set(mm, addr, pudp, pud); } +static inline void page_table_check_pte_clear_range(struct mm_struct *mm, + unsigned long addr, + pmd_t pmd) +{ + if (static_branch_likely(&page_table_check_disabled)) + return; + + __page_table_check_pte_clear_range(mm, addr, pmd); +} + #else static inline void page_table_check_alloc(struct page *page, unsigned int order) @@ -143,5 +156,11 @@ static inline void page_table_check_pud_ { } +static inline void page_table_check_pte_clear_range(struct mm_struct *mm, + unsigned long addr, + pmd_t pmd) +{ +} + #endif /* CONFIG_PAGE_TABLE_CHECK */ #endif /* __LINUX_PAGE_TABLE_CHECK_H */ --- a/mm/khugepaged.c~mm-page_table_check-check-entries-at-pmd-levels +++ a/mm/khugepaged.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -1422,10 +1423,12 @@ static void collapse_and_free_pmd(struct spinlock_t *ptl; pmd_t pmd; + mmap_assert_write_locked(mm); ptl = pmd_lock(vma->vm_mm, pmdp); pmd = pmdp_collapse_flush(vma, addr, pmdp); spin_unlock(ptl); mm_dec_nr_ptes(mm); + page_table_check_pte_clear_range(mm, addr, pmd); pte_free(mm, pmd_pgtable(pmd)); } --- a/mm/page_table_check.c~mm-page_table_check-check-entries-at-pmd-levels +++ a/mm/page_table_check.c @@ -247,3 +247,23 @@ void __page_table_check_pud_set(struct m } } EXPORT_SYMBOL(__page_table_check_pud_set); + +void __page_table_check_pte_clear_range(struct mm_struct *mm, + unsigned long addr, + pmd_t pmd) +{ + if (&init_mm == mm) + return; + + if (!pmd_bad(pmd) && !pmd_leaf(pmd)) { + pte_t *ptep = pte_offset_map(&pmd, addr); + unsigned long i; + + pte_unmap(ptep); + for (i = 0; i < PTRS_PER_PTE; i++) { + __page_table_check_pte_clear(mm, addr, *ptep); + addr += PAGE_SIZE; + ptep++; + } + } +} From patchwork Fri Feb 4 04:49:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734793 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 5FFE0C433EF for ; Fri, 4 Feb 2022 04:49:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0EE56B007D; Thu, 3 Feb 2022 23:49:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBD6F6B007E; Thu, 3 Feb 2022 23:49:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C84CD6B0080; Thu, 3 Feb 2022 23:49:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id B927F6B007D for ; Thu, 3 Feb 2022 23:49:32 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 8FBC91206BD for ; Fri, 4 Feb 2022 04:49:32 +0000 (UTC) X-FDA: 79103868984.03.407CD6B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 36927100007 for ; Fri, 4 Feb 2022 04:49:32 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7E8C261B48; Fri, 4 Feb 2022 04:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB9A2C340E9; Fri, 4 Feb 2022 04:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950171; bh=MDHhps9eYNeO/cKBYWhXRHb++o+a0biupbPiV5wilT0=; h=Date:To:From:In-Reply-To:Subject:From; b=crYwElvQFciOg8RuzWOhmfqclGz4EBTbAuEdvFZUBL080dOqoSybOKInoV3z008Z9 Jor4bBOjackNplGGhhLVATKsk3Jf7iW7vfAxm6t87hgmcwn2CKwaxFa50JTmo2814u AhqAgNicTqKnJhlb+x5ttl1hNHbLtWqfTiesJcXs= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:29 -0800 Date: Thu, 03 Feb 2022 20:49:29 -0800 To: stettberger@dokucode.de,stable@vger.kernel.org,khalid.aziz@oracle.com,rppt@linux.ibm.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 06/10] mm/pgtable: define pte_index so that preprocessor could recognize it Message-Id: <20220204044929.AB9A2C340E9@smtp.kernel.org> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 36927100007 X-Stat-Signature: g7coqqn9suqtcpr4ijd6pqkx5smnfwmr Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=crYwElvQ; dmarc=none; spf=pass (imf05.hostedemail.com: domain of akpm@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Rspam-User: nil X-HE-Tag: 1643950172-620348 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: Mike Rapoport Subject: mm/pgtable: define pte_index so that preprocessor could recognize it Since commit 974b9b2c68f3 ("mm: consolidate pte_index() and pte_offset_*() definitions") pte_index is a static inline and there is no define for it that can be recognized by the preprocessor. As a result, vm_insert_pages() uses slower loop over vm_insert_page() instead of insert_pages() that amortizes the cost of spinlock operations when inserting multiple pages. Link: https://lkml.kernel.org/r/20220111145457.20748-1-rppt@kernel.org Fixes: 974b9b2c68f3 ("mm: consolidate pte_index() and pte_offset_*() definitions") Signed-off-by: Mike Rapoport Reported-by: Christian Dietrich Reviewed-by: Khalid Aziz Cc: Signed-off-by: Andrew Morton --- include/linux/pgtable.h | 1 + 1 file changed, 1 insertion(+) --- a/include/linux/pgtable.h~mm-pgtable-define-pte_index-so-that-preprocessor-could-recognize-it +++ a/include/linux/pgtable.h @@ -62,6 +62,7 @@ static inline unsigned long pte_index(un { return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1); } +#define pte_index pte_index #ifndef pmd_index static inline unsigned long pmd_index(unsigned long address) From patchwork Fri Feb 4 04:49:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734794 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 5FEB2C433EF for ; Fri, 4 Feb 2022 04:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA9B86B007E; Thu, 3 Feb 2022 23:49:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E58F06B0080; Thu, 3 Feb 2022 23:49:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D49136B0081; Thu, 3 Feb 2022 23:49:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id C48136B007E for ; Thu, 3 Feb 2022 23:49:36 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 75506998EE for ; Fri, 4 Feb 2022 04:49:36 +0000 (UTC) X-FDA: 79103869152.17.0FA5CD0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id 4E47840002 for ; Fri, 4 Feb 2022 04:49:36 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 79F3661AC9; Fri, 4 Feb 2022 04:49:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C68DBC340E9; Fri, 4 Feb 2022 04:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950175; bh=D1pLLIbAAt2KQpwLnzj66vfNlI8SvQaQIa3Kfuug6OQ=; h=Date:To:From:In-Reply-To:Subject:From; b=A7BibzfOSeUAAubSLnLl+QXzJpoD+MDHbV8zSaqItlo+iSlG4uqPhoLhfKprwbqgZ fF9HhAFGDdihO/Bs3ie2C330D2R6uNgK9Giqn0QP3CF/MgIABs5TIynEmEUjRHZT+C BLnawaTHP+LKN7noty6CD6qkayJG8rhwK3my3MHU= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:33 -0800 Date: Thu, 03 Feb 2022 20:49:33 -0800 To: zealci@zte.com.cn,vvs@virtuozzo.com,unixbhaskar@gmail.com,stable@vger.kernel.org,shakeelb@google.com,rdunlap@infradead.org,manfred@colorfullife.com,dbueso@suse.de,cgel.zte@gmail.com,arnd@arndb.de,chi.minghao@zte.com.cn,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 07/10] ipc/sem: do not sleep with a spin lock held Message-Id: <20220204044933.C68DBC340E9@smtp.kernel.org> X-Rspamd-Queue-Id: 4E47840002 X-Rspam-User: nil Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=A7BibzfO; dmarc=none; spf=pass (imf17.hostedemail.com: domain of akpm@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Stat-Signature: d6wxwnemi1g1hytx5b1dn1ord3ws8jim X-Rspamd-Server: rspam08 X-HE-Tag: 1643950176-747835 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: Minghao Chi Subject: ipc/sem: do not sleep with a spin lock held We can't call kvfree() with a spin lock held, so defer it. Link: https://lkml.kernel.org/r/20211223031207.556189-1-chi.minghao@zte.com.cn Fixes: fc37a3b8b438 ("[PATCH] ipc sem: use kvmalloc for sem_undo allocation") Reported-by: Zeal Robot Signed-off-by: Minghao Chi Reviewed-by: Shakeel Butt Reviewed-by: Manfred Spraul Cc: Arnd Bergmann Cc: Yang Guang Cc: Davidlohr Bueso Cc: Randy Dunlap Cc: Bhaskar Chowdhury Cc: Vasily Averin Cc: Signed-off-by: Andrew Morton --- ipc/sem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/ipc/sem.c~ipc-sem-do-not-sleep-with-a-spin-lock-held +++ a/ipc/sem.c @@ -1964,6 +1964,7 @@ static struct sem_undo *find_alloc_undo( */ un = lookup_undo(ulp, semid); if (un) { + spin_unlock(&ulp->lock); kvfree(new); goto success; } @@ -1976,9 +1977,8 @@ static struct sem_undo *find_alloc_undo( ipc_assert_locked_object(&sma->sem_perm); list_add(&new->list_id, &sma->list_id); un = new; - -success: spin_unlock(&ulp->lock); +success: sem_unlock(sma, -1); out: return un; From patchwork Fri Feb 4 04:49:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734795 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 974B9C433EF for ; Fri, 4 Feb 2022 04:49:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E8C66B0080; Thu, 3 Feb 2022 23:49:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29A306B0081; Thu, 3 Feb 2022 23:49:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 160C06B0082; Thu, 3 Feb 2022 23:49:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id 02FD16B0080 for ; Thu, 3 Feb 2022 23:49:41 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BA29F998D9 for ; Fri, 4 Feb 2022 04:49:40 +0000 (UTC) X-FDA: 79103869320.06.CD31234 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 56531A0002 for ; Fri, 4 Feb 2022 04:49:40 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A8C7E61B46; Fri, 4 Feb 2022 04:49:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34C78C340E9; Fri, 4 Feb 2022 04:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950179; bh=aD+SvPJUMV8qlmZmYGtEKh2tOLxDc46bz5C2+qUebYM=; h=Date:To:From:In-Reply-To:Subject:From; b=EuJnqzDU/mc3h2SNwevG49jvIM5GNjmlwwEaP2NiJ9TPU0ZUuWWMY8kPqjQYM8RY2 +L72WQL/6bs9K5D50vt786wdy4Qwa7fBnu0/V2dmlhlCrCKlpzRD/HT2oM847iTL8p hkKhJgM41h8oMPg7GrFeWyjgQQqduINYNc9QLRFI= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:37 -0800 Date: Thu, 03 Feb 2022 20:49:37 -0800 To: stable@vger.kernel.org,osalvador@suse.de,david@redhat.com,catalin.marinas@arm.com,lang.yu@amd.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 08/10] mm/kmemleak: avoid scanning potential huge holes Message-Id: <20220204044938.34C78C340E9@smtp.kernel.org> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 56531A0002 X-Stat-Signature: tfyff6c7s8cyr8e4nbrxaaazapw14c5u X-Rspam-User: nil Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=EuJnqzDU; spf=pass (imf15.hostedemail.com: domain of akpm@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@kernel.org; dmarc=none X-HE-Tag: 1643950180-674451 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: Lang Yu Subject: mm/kmemleak: avoid scanning potential huge holes When using devm_request_free_mem_region() and devm_memremap_pages() to add ZONE_DEVICE memory, if requested free mem region's end pfn were huge(e.g., 0x400000000), the node_end_pfn() will be also huge (see move_pfn_range_to_zone()). Thus it creates a huge hole between node_start_pfn() and node_end_pfn(). We found on some AMD APUs, amdkfd requested such a free mem region and created a huge hole. In such a case, following code snippet was just doing busy test_bit() looping on the huge hole. for (pfn = start_pfn; pfn < end_pfn; pfn++) { struct page *page = pfn_to_online_page(pfn); if (!page) continue; ... } So we got a soft lockup: watchdog: BUG: soft lockup - CPU#6 stuck for 26s! [bash:1221] CPU: 6 PID: 1221 Comm: bash Not tainted 5.15.0-custom #1 RIP: 0010:pfn_to_online_page+0x5/0xd0 Call Trace: ? kmemleak_scan+0x16a/0x440 kmemleak_write+0x306/0x3a0 ? common_file_perm+0x72/0x170 full_proxy_write+0x5c/0x90 vfs_write+0xb9/0x260 ksys_write+0x67/0xe0 __x64_sys_write+0x1a/0x20 do_syscall_64+0x3b/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae I did some tests with the patch. (1) amdgpu module unloaded before the patch: real 0m0.976s user 0m0.000s sys 0m0.968s after the patch: real 0m0.981s user 0m0.000s sys 0m0.973s (2) amdgpu module loaded before the patch: real 0m35.365s user 0m0.000s sys 0m35.354s after the patch: real 0m1.049s user 0m0.000s sys 0m1.042s Link: https://lkml.kernel.org/r/20211108140029.721144-1-lang.yu@amd.com Signed-off-by: Lang Yu Acked-by: David Hildenbrand Acked-by: Catalin Marinas Cc: Oscar Salvador Cc: Signed-off-by: Andrew Morton --- mm/kmemleak.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/mm/kmemleak.c~mm-kmemleak-avoid-scanning-potential-huge-holes +++ a/mm/kmemleak.c @@ -1410,7 +1410,8 @@ static void kmemleak_scan(void) { unsigned long flags; struct kmemleak_object *object; - int i; + struct zone *zone; + int __maybe_unused i; int new_leaks = 0; jiffies_last_scan = jiffies; @@ -1450,9 +1451,9 @@ static void kmemleak_scan(void) * Struct page scanning for each node. */ get_online_mems(); - for_each_online_node(i) { - unsigned long start_pfn = node_start_pfn(i); - unsigned long end_pfn = node_end_pfn(i); + for_each_populated_zone(zone) { + unsigned long start_pfn = zone->zone_start_pfn; + unsigned long end_pfn = zone_end_pfn(zone); unsigned long pfn; for (pfn = start_pfn; pfn < end_pfn; pfn++) { @@ -1461,8 +1462,8 @@ static void kmemleak_scan(void) if (!page) continue; - /* only scan pages belonging to this node */ - if (page_to_nid(page) != i) + /* only scan pages belonging to this zone */ + if (page_zone(page) != zone) continue; /* only scan if page is in use */ if (page_count(page) == 0) From patchwork Fri Feb 4 04:49:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734796 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 EC548C4332F for ; Fri, 4 Feb 2022 04:49:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77DDC6B0072; Thu, 3 Feb 2022 23:49:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72C806B0081; Thu, 3 Feb 2022 23:49:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61BF66B0082; Thu, 3 Feb 2022 23:49:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 531756B0072 for ; Thu, 3 Feb 2022 23:49:46 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0ED66181B5E8B for ; Fri, 4 Feb 2022 04:49:46 +0000 (UTC) X-FDA: 79103869572.14.B47F8E2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf22.hostedemail.com (Postfix) with ESMTP id B07B6C0003 for ; Fri, 4 Feb 2022 04:49:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B2EFEB817E5; Fri, 4 Feb 2022 04:49:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F6F2C340E9; Fri, 4 Feb 2022 04:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950183; bh=ZC4LeS+qrwW4Qth3uKchhgCgE1oEId3KHtX6V15jRjI=; h=Date:To:From:In-Reply-To:Subject:From; b=E7d4KWDjy4P9xpzOPVBHjeUbEuhLDbXW6Qup5bhT15RYVMB9UnEkzaF9zfw8rBqNQ 59a9xxanEEIk8aeRciBKeY24xOaXUO9nzSdEaFoxhprQb4Q8UQmZsGchPmjwehQJIO DrYjzOd7EUdHT7RGIF7dSRwVzEU8uR3kVH7u/hsE= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:41 -0800 Date: Thu, 03 Feb 2022 20:49:41 -0800 To: rppt@linux.ibm.com,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 09/10] MAINTAINERS: update rppt's email Message-Id: <20220204044942.3F6F2C340E9@smtp.kernel.org> X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: B07B6C0003 X-Stat-Signature: 8bnzjgdzrj7teydhmec9tg3967c3uokk Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=E7d4KWDj; dmarc=none; spf=pass (imf22.hostedemail.com: domain of akpm@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Rspam-User: nil X-HE-Tag: 1643950185-215950 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: Mike Rapoport Subject: MAINTAINERS: update rppt's email Use my @kernel.org address Link: https://lkml.kernel.org/r/20220203090324.3701774-1-rppt@kernel.org Signed-off-by: Mike Rapoport Signed-off-by: Andrew Morton --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/MAINTAINERS~maintainers-update-rppts-email +++ a/MAINTAINERS @@ -12400,7 +12400,7 @@ F: include/uapi/linux/membarrier.h F: kernel/sched/membarrier.c MEMBLOCK -M: Mike Rapoport +M: Mike Rapoport L: linux-mm@kvack.org S: Maintained F: Documentation/core-api/boot-time-mm.rst From patchwork Fri Feb 4 04:49:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12734797 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 24179C433F5 for ; Fri, 4 Feb 2022 04:49:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3BB56B0081; Thu, 3 Feb 2022 23:49:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EBD56B0082; Thu, 3 Feb 2022 23:49:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B32E6B0083; Thu, 3 Feb 2022 23:49:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 7A1126B0081 for ; Thu, 3 Feb 2022 23:49:49 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 18526824C447 for ; Fri, 4 Feb 2022 04:49:49 +0000 (UTC) X-FDA: 79103869698.05.F5EBDBF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id B0BBF80004 for ; Fri, 4 Feb 2022 04:49:48 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0510361B51; Fri, 4 Feb 2022 04:49:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31A87C004E1; Fri, 4 Feb 2022 04:49:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1643950187; bh=lF8DoC9XFDibW5PMa0160z5XrJHiPaP5hlSQbu4HXcI=; h=Date:To:From:In-Reply-To:Subject:From; b=N138r+8d3Csc3ShDsM/Y5qqS/cabwqiw1L2Fm8aehaasa/g/x+KcI1chDXnIs4aIa 7TCBlun3CXU64Q1vYk6oOL5TlferdC4EMEDpR2+s7SShQwoEwZvpurqiFl0ZkGAM0O Lnz8I6MK18yP8do9i2LwtaxGLkthZUNIOKalI4Nc= Received: by hp1 (sSMTP sendmail emulation); Thu, 03 Feb 2022 20:49:45 -0800 Date: Thu, 03 Feb 2022 20:49:45 -0800 To: shuah@kernel.org,chi.minghao@zte.com.cn,skhan@linuxfoundation.org,akpm@linux-foundation.org,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220203204836.88dcebe504f440686cc63a60@linux-foundation.org> Subject: [patch 10/10] kselftest/vm: revert "tools/testing/selftests/vm/userfaultfd.c: use swap() to make code cleaner" Message-Id: <20220204044946.31A87C004E1@smtp.kernel.org> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B0BBF80004 X-Stat-Signature: egaascsd96m17sk4xh7df1cuewij8xmk Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=N138r+8d; dmarc=none; spf=pass (imf30.hostedemail.com: domain of akpm@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@kernel.org X-Rspam-User: nil X-HE-Tag: 1643950188-734526 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: Shuah Khan Subject: kselftest/vm: revert "tools/testing/selftests/vm/userfaultfd.c: use swap() to make code cleaner" With this change, userfaultfd fails to build with undefined reference swap() error: userfaultfd.c: In function `userfaultfd_stress': userfaultfd.c:1530:17: warning: implicit declaration of function `swap'; did you mean `swab'? [-Wimplicit-function-declaration] 1530 | swap(area_src, area_dst); | ^~~~ | swab /usr/bin/ld: /tmp/ccDGOAdV.o: in function `userfaultfd_stress': userfaultfd.c:(.text+0x549e): undefined reference to `swap' /usr/bin/ld: userfaultfd.c:(.text+0x54bc): undefined reference to `swap' collect2: error: ld returned 1 exit status Revert the commit to fix the problem. Link: https://lkml.kernel.org/r/20220202003340.87195-1-skhan@linuxfoundation.org Fixes: 2c769ed7137a ("tools/testing/selftests/vm/userfaultfd.c: use swap() to make code cleaner") Signed-off-by: Shuah Khan Cc: Shuah Khan Cc: Minghao Chi Signed-off-by: Andrew Morton --- tools/testing/selftests/vm/userfaultfd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/tools/testing/selftests/vm/userfaultfd.c~kselftest-vm-revert-tools-testing-selftests-vm-userfaultfdc-use-swap-to-make-code-cleaner +++ a/tools/testing/selftests/vm/userfaultfd.c @@ -1417,6 +1417,7 @@ static void userfaultfd_pagemap_test(uns static int userfaultfd_stress(void) { void *area; + char *tmp_area; unsigned long nr; struct uffdio_register uffdio_register; struct uffd_stats uffd_stats[nr_cpus]; @@ -1527,9 +1528,13 @@ static int userfaultfd_stress(void) count_verify[nr], nr); /* prepare next bounce */ - swap(area_src, area_dst); - - swap(area_src_alias, area_dst_alias); + tmp_area = area_src; + area_src = area_dst; + area_dst = tmp_area; + + tmp_area = area_src_alias; + area_src_alias = area_dst_alias; + area_dst_alias = tmp_area; uffd_stats_report(uffd_stats, nr_cpus); }