Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1311718pxb; Tue, 8 Feb 2022 14:23:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBUd0FzM/YSOJo69SO8+CU94x3a+bef4Qae1PoNTlhTvFjgfadt/J11Kt34VTykl8FzEgE X-Received: by 2002:aa7:8081:: with SMTP id v1mr6414535pff.74.1644359012380; Tue, 08 Feb 2022 14:23:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644359012; cv=none; d=google.com; s=arc-20160816; b=L81sSr8V3QMj2xWMbupuX8Ahru9OkqcukhRDZyJHKucilu1r5h8IVQVN5qeZmgo02R lKbg5ttJ82U9eXegz9+aecDqDSBNPwEsi1Qzld/T1grDCFeDbiY0257z0zFgTnjYAqgr YTCIRdbW4R6docEOvjJKJRmWE6uBx0Mijls6nOCRqEKGrDK/I3NcLBbRKEifFNpdFKm6 2zk0MxOlKWRd66zbiukJXzJmw9i2WZGvSUAfKtIrsHhpbzpn6DjjgWpe2l+A7ISmZjKW IW0g52/zR+ELeyJ83d0DuqcfGbad5yA6evdKYQBTdxbGK1xNH1GFXTvsf6VDZKe7QvFs Wuuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kUapyPVdPoTHGeQDmk3wtWBy64Kc59eI+oAfsj8jIWc=; b=W293j+X30BH4WV4CjaVIscGOBfGAon5oP2iqaWFu2QLnaY0JmFkyY+iyQREHN+mRhb 50zG7AG3b61NcOcjQHzDtuxjz+09+76hlhLX2i/1UcAtuTIqatRwdfYQbxVAdPtQAHLq nvoU5A7CujL6WNs5idLbhSdcKlhq83WdKwPvJjGcCqLH2DAnkltfuuzwLmQc8BzYahE1 A694CpoxX+g5FD8CF/KRF3233I7gZkneMATptOt/7+U2qoalN1CZTU8GGsWt/s3pQ6FD cVQOpU4ECqTCxS8BDvmzIKsc8ZhZI6KNjmzNRNzTwd0fJEuCZ5eVhsCV4fPwgtXRfhvL /VkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g+oba4UU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n8si12780448pfu.176.2022.02.08.14.23.17; Tue, 08 Feb 2022 14:23:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g+oba4UU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388197AbiBGLnK (ORCPT + 99 others); Mon, 7 Feb 2022 06:43:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385674AbiBGLcF (ORCPT ); Mon, 7 Feb 2022 06:32:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4BC4C0401C9; Mon, 7 Feb 2022 03:31:39 -0800 (PST) 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 645C560A67; Mon, 7 Feb 2022 11:31:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59056C004E1; Mon, 7 Feb 2022 11:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233498; bh=/mdKNCS/v4khbOY4M1DC21Yj9S+GLexjOpKckihNDzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+oba4UUyt62SP5tlCY52jKeRqJ1CvlMZ0laSxfnAS7aoI8EsYXoRJC0qMeu7+K6a OzbnWJ8Lr9RaeKtgf/CS5aMLv//vBzxIMf5nmIcKJD9CNFOsfdlZIN7lE5sjncgf9j GWc7IT6MackzAj0+me3ccKQQ4sXFF3xBtnPFbWhM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lang Yu , David Hildenbrand , Catalin Marinas , Oscar Salvador , Andrew Morton , Linus Torvalds Subject: [PATCH 5.16 032/126] mm/kmemleak: avoid scanning potential huge holes Date: Mon, 7 Feb 2022 12:06:03 +0100 Message-Id: <20220207103805.249337543@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lang Yu commit c10a0f877fe007021d70f9cada240f42adc2b5db upstream. 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 Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/kmemleak.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1403,7 +1403,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; @@ -1443,9 +1444,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++) { @@ -1454,8 +1455,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)